@@ -17,4126 +17,4126 @@ |
||
| 17 | 17 | abstract class EE_Admin_Page extends EE_Base implements InterminableInterface |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @var LoaderInterface $loader |
|
| 22 | - */ |
|
| 23 | - protected $loader; |
|
| 20 | + /** |
|
| 21 | + * @var LoaderInterface $loader |
|
| 22 | + */ |
|
| 23 | + protected $loader; |
|
| 24 | 24 | |
| 25 | - // set in _init_page_props() |
|
| 26 | - public $page_slug; |
|
| 25 | + // set in _init_page_props() |
|
| 26 | + public $page_slug; |
|
| 27 | 27 | |
| 28 | - public $page_label; |
|
| 28 | + public $page_label; |
|
| 29 | 29 | |
| 30 | - public $page_folder; |
|
| 30 | + public $page_folder; |
|
| 31 | 31 | |
| 32 | - // set in define_page_props() |
|
| 33 | - protected $_admin_base_url; |
|
| 32 | + // set in define_page_props() |
|
| 33 | + protected $_admin_base_url; |
|
| 34 | 34 | |
| 35 | - protected $_admin_base_path; |
|
| 35 | + protected $_admin_base_path; |
|
| 36 | 36 | |
| 37 | - protected $_admin_page_title; |
|
| 37 | + protected $_admin_page_title; |
|
| 38 | 38 | |
| 39 | - protected $_labels; |
|
| 39 | + protected $_labels; |
|
| 40 | 40 | |
| 41 | 41 | |
| 42 | - // set early within EE_Admin_Init |
|
| 43 | - protected $_wp_page_slug; |
|
| 42 | + // set early within EE_Admin_Init |
|
| 43 | + protected $_wp_page_slug; |
|
| 44 | 44 | |
| 45 | - // navtabs |
|
| 46 | - protected $_nav_tabs; |
|
| 45 | + // navtabs |
|
| 46 | + protected $_nav_tabs; |
|
| 47 | 47 | |
| 48 | - protected $_default_nav_tab_name; |
|
| 48 | + protected $_default_nav_tab_name; |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @var array $_help_tour |
|
| 52 | - */ |
|
| 53 | - protected $_help_tour = array(); |
|
| 50 | + /** |
|
| 51 | + * @var array $_help_tour |
|
| 52 | + */ |
|
| 53 | + protected $_help_tour = array(); |
|
| 54 | 54 | |
| 55 | 55 | |
| 56 | - // template variables (used by templates) |
|
| 57 | - protected $_template_path; |
|
| 56 | + // template variables (used by templates) |
|
| 57 | + protected $_template_path; |
|
| 58 | 58 | |
| 59 | - protected $_column_template_path; |
|
| 59 | + protected $_column_template_path; |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * @var array $_template_args |
|
| 63 | - */ |
|
| 64 | - protected $_template_args = array(); |
|
| 61 | + /** |
|
| 62 | + * @var array $_template_args |
|
| 63 | + */ |
|
| 64 | + protected $_template_args = array(); |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * this will hold the list table object for a given view. |
|
| 68 | - * |
|
| 69 | - * @var EE_Admin_List_Table $_list_table_object |
|
| 70 | - */ |
|
| 71 | - protected $_list_table_object; |
|
| 66 | + /** |
|
| 67 | + * this will hold the list table object for a given view. |
|
| 68 | + * |
|
| 69 | + * @var EE_Admin_List_Table $_list_table_object |
|
| 70 | + */ |
|
| 71 | + protected $_list_table_object; |
|
| 72 | 72 | |
| 73 | - // bools |
|
| 74 | - protected $_is_UI_request = null; // this starts at null so we can have no header routes progress through two states. |
|
| 73 | + // bools |
|
| 74 | + protected $_is_UI_request = null; // this starts at null so we can have no header routes progress through two states. |
|
| 75 | 75 | |
| 76 | - protected $_routing; |
|
| 76 | + protected $_routing; |
|
| 77 | 77 | |
| 78 | - // list table args |
|
| 79 | - protected $_view; |
|
| 78 | + // list table args |
|
| 79 | + protected $_view; |
|
| 80 | 80 | |
| 81 | - protected $_views; |
|
| 81 | + protected $_views; |
|
| 82 | 82 | |
| 83 | 83 | |
| 84 | - // action => method pairs used for routing incoming requests |
|
| 85 | - protected $_page_routes; |
|
| 84 | + // action => method pairs used for routing incoming requests |
|
| 85 | + protected $_page_routes; |
|
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * @var array $_page_config |
|
| 89 | - */ |
|
| 90 | - protected $_page_config; |
|
| 87 | + /** |
|
| 88 | + * @var array $_page_config |
|
| 89 | + */ |
|
| 90 | + protected $_page_config; |
|
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * the current page route and route config |
|
| 94 | - * |
|
| 95 | - * @var string $_route |
|
| 96 | - */ |
|
| 97 | - protected $_route; |
|
| 92 | + /** |
|
| 93 | + * the current page route and route config |
|
| 94 | + * |
|
| 95 | + * @var string $_route |
|
| 96 | + */ |
|
| 97 | + protected $_route; |
|
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * @var string $_cpt_route |
|
| 101 | - */ |
|
| 102 | - protected $_cpt_route; |
|
| 99 | + /** |
|
| 100 | + * @var string $_cpt_route |
|
| 101 | + */ |
|
| 102 | + protected $_cpt_route; |
|
| 103 | 103 | |
| 104 | - /** |
|
| 105 | - * @var array $_route_config |
|
| 106 | - */ |
|
| 107 | - protected $_route_config; |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out |
|
| 111 | - * actions. |
|
| 112 | - * |
|
| 113 | - * @since 4.6.x |
|
| 114 | - * @var array. |
|
| 115 | - */ |
|
| 116 | - protected $_default_route_query_args; |
|
| 117 | - |
|
| 118 | - // set via request page and action args. |
|
| 119 | - protected $_current_page; |
|
| 120 | - |
|
| 121 | - protected $_current_view; |
|
| 122 | - |
|
| 123 | - protected $_current_page_view_url; |
|
| 124 | - |
|
| 125 | - // sanitized request action (and nonce) |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * @var string $_req_action |
|
| 129 | - */ |
|
| 130 | - protected $_req_action; |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * @var string $_req_nonce |
|
| 134 | - */ |
|
| 135 | - protected $_req_nonce; |
|
| 136 | - |
|
| 137 | - // search related |
|
| 138 | - protected $_search_btn_label; |
|
| 139 | - |
|
| 140 | - protected $_search_box_callback; |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * WP Current Screen object |
|
| 144 | - * |
|
| 145 | - * @var WP_Screen |
|
| 146 | - */ |
|
| 147 | - protected $_current_screen; |
|
| 148 | - |
|
| 149 | - // for holding EE_Admin_Hooks object when needed (set via set_hook_object()) |
|
| 150 | - protected $_hook_obj; |
|
| 151 | - |
|
| 152 | - // for holding incoming request data |
|
| 153 | - protected $_req_data; |
|
| 154 | - |
|
| 155 | - // yes / no array for admin form fields |
|
| 156 | - protected $_yes_no_values = array(); |
|
| 157 | - |
|
| 158 | - // some default things shared by all child classes |
|
| 159 | - protected $_default_espresso_metaboxes; |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * EE_Registry Object |
|
| 163 | - * |
|
| 164 | - * @var EE_Registry |
|
| 165 | - */ |
|
| 166 | - protected $EE = null; |
|
| 167 | - |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * This is just a property that flags whether the given route is a caffeinated route or not. |
|
| 171 | - * |
|
| 172 | - * @var boolean |
|
| 173 | - */ |
|
| 174 | - protected $_is_caf = false; |
|
| 175 | - |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * @Constructor |
|
| 179 | - * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
| 180 | - * @throws EE_Error |
|
| 181 | - * @throws InvalidArgumentException |
|
| 182 | - * @throws ReflectionException |
|
| 183 | - * @throws InvalidDataTypeException |
|
| 184 | - * @throws InvalidInterfaceException |
|
| 185 | - */ |
|
| 186 | - public function __construct($routing = true) |
|
| 187 | - { |
|
| 188 | - $this->loader = LoaderFactory::getLoader(); |
|
| 189 | - if (strpos($this->_get_dir(), 'caffeinated') !== false) { |
|
| 190 | - $this->_is_caf = true; |
|
| 191 | - } |
|
| 192 | - $this->_yes_no_values = array( |
|
| 193 | - array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')), |
|
| 194 | - array('id' => false, 'text' => esc_html__('No', 'event_espresso')), |
|
| 195 | - ); |
|
| 196 | - // set the _req_data property. |
|
| 197 | - $this->_req_data = array_merge($_GET, $_POST); |
|
| 198 | - // routing enabled? |
|
| 199 | - $this->_routing = $routing; |
|
| 200 | - // set initial page props (child method) |
|
| 201 | - $this->_init_page_props(); |
|
| 202 | - // set global defaults |
|
| 203 | - $this->_set_defaults(); |
|
| 204 | - // set early because incoming requests could be ajax related and we need to register those hooks. |
|
| 205 | - $this->_global_ajax_hooks(); |
|
| 206 | - $this->_ajax_hooks(); |
|
| 207 | - // other_page_hooks have to be early too. |
|
| 208 | - $this->_do_other_page_hooks(); |
|
| 209 | - // This just allows us to have extending classes do something specific |
|
| 210 | - // before the parent constructor runs _page_setup(). |
|
| 211 | - if (method_exists($this, '_before_page_setup')) { |
|
| 212 | - $this->_before_page_setup(); |
|
| 213 | - } |
|
| 214 | - // set up page dependencies |
|
| 215 | - $this->_page_setup(); |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - |
|
| 219 | - /** |
|
| 220 | - * _init_page_props |
|
| 221 | - * Child classes use to set at least the following properties: |
|
| 222 | - * $page_slug. |
|
| 223 | - * $page_label. |
|
| 224 | - * |
|
| 225 | - * @abstract |
|
| 226 | - * @return void |
|
| 227 | - */ |
|
| 228 | - abstract protected function _init_page_props(); |
|
| 229 | - |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * _ajax_hooks |
|
| 233 | - * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 234 | - * Note: within the ajax callback methods. |
|
| 235 | - * |
|
| 236 | - * @abstract |
|
| 237 | - * @return void |
|
| 238 | - */ |
|
| 239 | - abstract protected function _ajax_hooks(); |
|
| 240 | - |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * _define_page_props |
|
| 244 | - * child classes define page properties in here. Must include at least: |
|
| 245 | - * $_admin_base_url = base_url for all admin pages |
|
| 246 | - * $_admin_page_title = default admin_page_title for admin pages |
|
| 247 | - * $_labels = array of default labels for various automatically generated elements: |
|
| 248 | - * array( |
|
| 249 | - * 'buttons' => array( |
|
| 250 | - * 'add' => esc_html__('label for add new button'), |
|
| 251 | - * 'edit' => esc_html__('label for edit button'), |
|
| 252 | - * 'delete' => esc_html__('label for delete button') |
|
| 253 | - * ) |
|
| 254 | - * ) |
|
| 255 | - * |
|
| 256 | - * @abstract |
|
| 257 | - * @return void |
|
| 258 | - */ |
|
| 259 | - abstract protected function _define_page_props(); |
|
| 260 | - |
|
| 261 | - |
|
| 262 | - /** |
|
| 263 | - * _set_page_routes |
|
| 264 | - * child classes use this to define the page routes for all subpages handled by the class. Page routes are |
|
| 265 | - * assigned to a action => method pairs in an array and to the $_page_routes property. Each page route must also |
|
| 266 | - * have a 'default' route. Here's the format |
|
| 267 | - * $this->_page_routes = array( |
|
| 268 | - * 'default' => array( |
|
| 269 | - * 'func' => '_default_method_handling_route', |
|
| 270 | - * 'args' => array('array','of','args'), |
|
| 271 | - * 'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. |
|
| 272 | - * ajax request, backend processing) |
|
| 273 | - * 'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a |
|
| 274 | - * headers route after. The string you enter here should match the defined route reference for a |
|
| 275 | - * headers sent route. |
|
| 276 | - * 'capability' => 'route_capability', //indicate a string for minimum capability required to access |
|
| 277 | - * this route. |
|
| 278 | - * 'obj_id' => 10 // if this route has an object id, then this can include it (used for capability |
|
| 279 | - * checks). |
|
| 280 | - * ), |
|
| 281 | - * 'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a |
|
| 282 | - * handling method. |
|
| 283 | - * ) |
|
| 284 | - * ) |
|
| 285 | - * |
|
| 286 | - * @abstract |
|
| 287 | - * @return void |
|
| 288 | - */ |
|
| 289 | - abstract protected function _set_page_routes(); |
|
| 290 | - |
|
| 291 | - |
|
| 292 | - /** |
|
| 293 | - * _set_page_config |
|
| 294 | - * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the |
|
| 295 | - * array corresponds to the page_route for the loaded page. Format: |
|
| 296 | - * $this->_page_config = array( |
|
| 297 | - * 'default' => array( |
|
| 298 | - * 'labels' => array( |
|
| 299 | - * 'buttons' => array( |
|
| 300 | - * 'add' => esc_html__('label for adding item'), |
|
| 301 | - * 'edit' => esc_html__('label for editing item'), |
|
| 302 | - * 'delete' => esc_html__('label for deleting item') |
|
| 303 | - * ), |
|
| 304 | - * 'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso') |
|
| 305 | - * ), //optional an array of custom labels for various automatically generated elements to use on the |
|
| 306 | - * page. If this isn't present then the defaults will be used as set for the $this->_labels in |
|
| 307 | - * _define_page_props() method |
|
| 308 | - * 'nav' => array( |
|
| 309 | - * 'label' => esc_html__('Label for Tab', 'event_espresso'). |
|
| 310 | - * 'url' => 'http://someurl', //automatically generated UNLESS you define |
|
| 311 | - * 'css_class' => 'css-class', //automatically generated UNLESS you define |
|
| 312 | - * 'order' => 10, //required to indicate tab position. |
|
| 313 | - * 'persistent' => false //if you want the nav tab to ONLY display when the specific route is |
|
| 314 | - * displayed then add this parameter. |
|
| 315 | - * 'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page. |
|
| 316 | - * 'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load |
|
| 317 | - * metaboxes set for eventespresso admin pages. |
|
| 318 | - * 'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have |
|
| 319 | - * metaboxes. Typically this is used if the 'metaboxes' index is not used because metaboxes are added |
|
| 320 | - * later. We just use this flag to make sure the necessary js gets enqueued on page load. |
|
| 321 | - * 'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the |
|
| 322 | - * given route has help popups setup and if it does then we need to make sure thickbox is enqueued. |
|
| 323 | - * 'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes). The |
|
| 324 | - * array indicates the max number of columns (4) and the default number of columns on page load (2). |
|
| 325 | - * There is an option in the "screen_options" dropdown that is setup so users can pick what columns they |
|
| 326 | - * want to display. |
|
| 327 | - * 'help_tabs' => array( //this is used for adding help tabs to a page |
|
| 328 | - * 'tab_id' => array( |
|
| 329 | - * 'title' => 'tab_title', |
|
| 330 | - * 'filename' => 'name_of_file_containing_content', //this is the primary method for setting |
|
| 331 | - * help tab content. The fallback if it isn't present is to try a the callback. Filename |
|
| 332 | - * should match a file in the admin folder's "help_tabs" dir (ie.. |
|
| 333 | - * events/help_tabs/name_of_file_containing_content.help_tab.php) |
|
| 334 | - * 'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will |
|
| 335 | - * attempt to use the callback which should match the name of a method in the class |
|
| 336 | - * ), |
|
| 337 | - * 'tab2_id' => array( |
|
| 338 | - * 'title' => 'tab2 title', |
|
| 339 | - * 'filename' => 'file_name_2' |
|
| 340 | - * 'callback' => 'callback_method_for_content', |
|
| 341 | - * ), |
|
| 342 | - * 'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the |
|
| 343 | - * help tab area on an admin page. @link |
|
| 344 | - * http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/ |
|
| 345 | - * 'help_tour' => array( |
|
| 346 | - * 'name_of_help_tour_class', //all help tours shoudl be a child class of EE_Help_Tour and located |
|
| 347 | - * in a folder for this admin page named "help_tours", a file name matching the key given here |
|
| 348 | - * (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class) |
|
| 349 | - * ), |
|
| 350 | - * 'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default is |
|
| 351 | - * true if it isn't present). To remove the requirement for a nonce check when this route is visited |
|
| 352 | - * just set |
|
| 353 | - * 'require_nonce' to FALSE |
|
| 354 | - * ) |
|
| 355 | - * ) |
|
| 356 | - * |
|
| 357 | - * @abstract |
|
| 358 | - * @return void |
|
| 359 | - */ |
|
| 360 | - abstract protected function _set_page_config(); |
|
| 361 | - |
|
| 362 | - |
|
| 363 | - |
|
| 364 | - |
|
| 365 | - |
|
| 366 | - /** end sample help_tour methods **/ |
|
| 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', array($this, 'ajax_metabox_content'), 10); |
|
| 466 | - } |
|
| 467 | - |
|
| 468 | - |
|
| 469 | - public function ajax_metabox_content() |
|
| 470 | - { |
|
| 471 | - $contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : ''; |
|
| 472 | - $url = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : ''; |
|
| 473 | - self::cached_rss_display($contentid, $url); |
|
| 474 | - wp_die(); |
|
| 475 | - } |
|
| 476 | - |
|
| 477 | - |
|
| 478 | - /** |
|
| 479 | - * _page_setup |
|
| 480 | - * Makes sure any things that need to be loaded early get handled. We also escape early here if the page requested |
|
| 481 | - * doesn't match the object. |
|
| 482 | - * |
|
| 483 | - * @final |
|
| 484 | - * @return void |
|
| 485 | - * @throws EE_Error |
|
| 486 | - * @throws InvalidArgumentException |
|
| 487 | - * @throws ReflectionException |
|
| 488 | - * @throws InvalidDataTypeException |
|
| 489 | - * @throws InvalidInterfaceException |
|
| 490 | - */ |
|
| 491 | - final protected function _page_setup() |
|
| 492 | - { |
|
| 493 | - // requires? |
|
| 494 | - // admin_init stuff - global - we're setting this REALLY early so if EE_Admin pages have to hook into other WP pages they can. But keep in mind, not everything is available from the EE_Admin Page object at this point. |
|
| 495 | - add_action('admin_init', array($this, 'admin_init_global'), 5); |
|
| 496 | - // next verify if we need to load anything... |
|
| 497 | - $this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : ''; |
|
| 498 | - $this->page_folder = strtolower( |
|
| 499 | - str_replace(array('_Admin_Page', 'Extend_'), '', get_class($this)) |
|
| 500 | - ); |
|
| 501 | - global $ee_menu_slugs; |
|
| 502 | - $ee_menu_slugs = (array) $ee_menu_slugs; |
|
| 503 | - if (! defined('DOING_AJAX') && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ]))) { |
|
| 504 | - return; |
|
| 505 | - } |
|
| 506 | - // becuz WP List tables have two duplicate select inputs for choosing bulk actions, we need to copy the action from the second to the first |
|
| 507 | - if (isset($this->_req_data['action2']) && $this->_req_data['action'] === '-1') { |
|
| 508 | - $this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] !== '-1' |
|
| 509 | - ? $this->_req_data['action2'] |
|
| 510 | - : $this->_req_data['action']; |
|
| 511 | - } |
|
| 512 | - // then set blank or -1 action values to 'default' |
|
| 513 | - $this->_req_action = isset($this->_req_data['action']) |
|
| 514 | - && ! empty($this->_req_data['action']) |
|
| 515 | - && $this->_req_data['action'] !== '-1' |
|
| 516 | - ? sanitize_key($this->_req_data['action']) |
|
| 517 | - : 'default'; |
|
| 518 | - // if action is 'default' after the above BUT we have 'route' var set, then let's use the route as the action. |
|
| 519 | - // This covers cases where we're coming in from a list table that isn't on the default route. |
|
| 520 | - $this->_req_action = $this->_req_action === 'default' && isset($this->_req_data['route']) |
|
| 521 | - ? $this->_req_data['route'] : $this->_req_action; |
|
| 522 | - // however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be |
|
| 523 | - $this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route']) |
|
| 524 | - ? $this->_req_data['route'] |
|
| 525 | - : $this->_req_action; |
|
| 526 | - $this->_current_view = $this->_req_action; |
|
| 527 | - $this->_req_nonce = $this->_req_action . '_nonce'; |
|
| 528 | - $this->_define_page_props(); |
|
| 529 | - $this->_current_page_view_url = add_query_arg( |
|
| 530 | - array('page' => $this->_current_page, 'action' => $this->_current_view), |
|
| 531 | - $this->_admin_base_url |
|
| 532 | - ); |
|
| 533 | - // default things |
|
| 534 | - $this->_default_espresso_metaboxes = array( |
|
| 535 | - '_espresso_news_post_box', |
|
| 536 | - '_espresso_links_post_box', |
|
| 537 | - '_espresso_ratings_request', |
|
| 538 | - '_espresso_sponsors_post_box', |
|
| 539 | - ); |
|
| 540 | - // set page configs |
|
| 541 | - $this->_set_page_routes(); |
|
| 542 | - $this->_set_page_config(); |
|
| 543 | - // let's include any referrer data in our default_query_args for this route for "stickiness". |
|
| 544 | - if (isset($this->_req_data['wp_referer'])) { |
|
| 545 | - $this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer']; |
|
| 546 | - } |
|
| 547 | - // for caffeinated and other extended functionality. |
|
| 548 | - // If there is a _extend_page_config method |
|
| 549 | - // then let's run that to modify the all the various page configuration arrays |
|
| 550 | - if (method_exists($this, '_extend_page_config')) { |
|
| 551 | - $this->_extend_page_config(); |
|
| 552 | - } |
|
| 553 | - // for CPT and other extended functionality. |
|
| 554 | - // If there is an _extend_page_config_for_cpt |
|
| 555 | - // then let's run that to modify all the various page configuration arrays. |
|
| 556 | - if (method_exists($this, '_extend_page_config_for_cpt')) { |
|
| 557 | - $this->_extend_page_config_for_cpt(); |
|
| 558 | - } |
|
| 559 | - // filter routes and page_config so addons can add their stuff. Filtering done per class |
|
| 560 | - $this->_page_routes = apply_filters( |
|
| 561 | - 'FHEE__' . get_class($this) . '__page_setup__page_routes', |
|
| 562 | - $this->_page_routes, |
|
| 563 | - $this |
|
| 564 | - ); |
|
| 565 | - $this->_page_config = apply_filters( |
|
| 566 | - 'FHEE__' . get_class($this) . '__page_setup__page_config', |
|
| 567 | - $this->_page_config, |
|
| 568 | - $this |
|
| 569 | - ); |
|
| 570 | - // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present |
|
| 571 | - // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action |
|
| 572 | - if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) { |
|
| 573 | - add_action( |
|
| 574 | - 'AHEE__EE_Admin_Page__route_admin_request', |
|
| 575 | - array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view), |
|
| 576 | - 10, |
|
| 577 | - 2 |
|
| 578 | - ); |
|
| 579 | - } |
|
| 580 | - // next route only if routing enabled |
|
| 581 | - if ($this->_routing && ! defined('DOING_AJAX')) { |
|
| 582 | - $this->_verify_routes(); |
|
| 583 | - // next let's just check user_access and kill if no access |
|
| 584 | - $this->check_user_access(); |
|
| 585 | - if ($this->_is_UI_request) { |
|
| 586 | - // admin_init stuff - global, all views for this page class, specific view |
|
| 587 | - add_action('admin_init', array($this, 'admin_init'), 10); |
|
| 588 | - if (method_exists($this, 'admin_init_' . $this->_current_view)) { |
|
| 589 | - add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15); |
|
| 590 | - } |
|
| 591 | - } else { |
|
| 592 | - // hijack regular WP loading and route admin request immediately |
|
| 593 | - @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT)); |
|
| 594 | - $this->route_admin_request(); |
|
| 595 | - } |
|
| 596 | - } |
|
| 597 | - } |
|
| 598 | - |
|
| 599 | - |
|
| 600 | - /** |
|
| 601 | - * Provides a way for related child admin pages to load stuff on the loaded admin page. |
|
| 602 | - * |
|
| 603 | - * @return void |
|
| 604 | - * @throws ReflectionException |
|
| 605 | - * @throws EE_Error |
|
| 606 | - */ |
|
| 607 | - private function _do_other_page_hooks() |
|
| 608 | - { |
|
| 609 | - $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array()); |
|
| 610 | - foreach ($registered_pages as $page) { |
|
| 611 | - // now let's setup the file name and class that should be present |
|
| 612 | - $classname = str_replace('.class.php', '', $page); |
|
| 613 | - // autoloaders should take care of loading file |
|
| 614 | - if (! class_exists($classname)) { |
|
| 615 | - $error_msg[] = sprintf( |
|
| 616 | - esc_html__( |
|
| 617 | - 'Something went wrong with loading the %s admin hooks page.', |
|
| 618 | - 'event_espresso' |
|
| 619 | - ), |
|
| 620 | - $page |
|
| 621 | - ); |
|
| 622 | - $error_msg[] = $error_msg[0] |
|
| 623 | - . "\r\n" |
|
| 624 | - . sprintf( |
|
| 625 | - esc_html__( |
|
| 626 | - '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', |
|
| 627 | - 'event_espresso' |
|
| 628 | - ), |
|
| 629 | - $page, |
|
| 630 | - '<br />', |
|
| 631 | - '<strong>' . $classname . '</strong>' |
|
| 632 | - ); |
|
| 633 | - throw new EE_Error(implode('||', $error_msg)); |
|
| 634 | - } |
|
| 635 | - $a = new ReflectionClass($classname); |
|
| 636 | - // notice we are passing the instance of this class to the hook object. |
|
| 637 | - $hookobj[] = $a->newInstance($this); |
|
| 638 | - } |
|
| 639 | - } |
|
| 640 | - |
|
| 641 | - |
|
| 642 | - public function load_page_dependencies() |
|
| 643 | - { |
|
| 644 | - try { |
|
| 645 | - $this->_load_page_dependencies(); |
|
| 646 | - } catch (EE_Error $e) { |
|
| 647 | - $e->get_error(); |
|
| 648 | - } |
|
| 649 | - } |
|
| 650 | - |
|
| 651 | - |
|
| 652 | - /** |
|
| 653 | - * load_page_dependencies |
|
| 654 | - * loads things specific to this page class when its loaded. Really helps with efficiency. |
|
| 655 | - * |
|
| 656 | - * @return void |
|
| 657 | - * @throws DomainException |
|
| 658 | - * @throws EE_Error |
|
| 659 | - * @throws InvalidArgumentException |
|
| 660 | - * @throws InvalidDataTypeException |
|
| 661 | - * @throws InvalidInterfaceException |
|
| 662 | - * @throws ReflectionException |
|
| 663 | - */ |
|
| 664 | - protected function _load_page_dependencies() |
|
| 665 | - { |
|
| 666 | - // let's set the current_screen and screen options to override what WP set |
|
| 667 | - $this->_current_screen = get_current_screen(); |
|
| 668 | - // load admin_notices - global, page class, and view specific |
|
| 669 | - add_action('admin_notices', array($this, 'admin_notices_global'), 5); |
|
| 670 | - add_action('admin_notices', array($this, 'admin_notices'), 10); |
|
| 671 | - if (method_exists($this, 'admin_notices_' . $this->_current_view)) { |
|
| 672 | - add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15); |
|
| 673 | - } |
|
| 674 | - // load network admin_notices - global, page class, and view specific |
|
| 675 | - add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5); |
|
| 676 | - if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) { |
|
| 677 | - add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view)); |
|
| 678 | - } |
|
| 679 | - // this will save any per_page screen options if they are present |
|
| 680 | - $this->_set_per_page_screen_options(); |
|
| 681 | - // setup list table properties |
|
| 682 | - $this->_set_list_table(); |
|
| 683 | - // child classes can "register" a metabox to be automatically handled via the _page_config array property. |
|
| 684 | - // However in some cases the metaboxes will need to be added within a route handling callback. |
|
| 685 | - $this->_add_registered_meta_boxes(); |
|
| 686 | - $this->_add_screen_columns(); |
|
| 687 | - // add screen options - global, page child class, and view specific |
|
| 688 | - $this->_add_global_screen_options(); |
|
| 689 | - $this->_add_screen_options(); |
|
| 690 | - $add_screen_options = "_add_screen_options_{$this->_current_view}"; |
|
| 691 | - if (method_exists($this, $add_screen_options)) { |
|
| 692 | - $this->{$add_screen_options}(); |
|
| 693 | - } |
|
| 694 | - // add help tab(s) and tours- set via page_config and qtips. |
|
| 695 | - // $this->_add_help_tour(); |
|
| 696 | - $this->_add_help_tabs(); |
|
| 697 | - $this->_add_qtips(); |
|
| 698 | - // add feature_pointers - global, page child class, and view specific |
|
| 699 | - $this->_add_feature_pointers(); |
|
| 700 | - $this->_add_global_feature_pointers(); |
|
| 701 | - $add_feature_pointer = "_add_feature_pointer_{$this->_current_view}"; |
|
| 702 | - if (method_exists($this, $add_feature_pointer)) { |
|
| 703 | - $this->{$add_feature_pointer}(); |
|
| 704 | - } |
|
| 705 | - // enqueue scripts/styles - global, page class, and view specific |
|
| 706 | - add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5); |
|
| 707 | - add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10); |
|
| 708 | - if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) { |
|
| 709 | - add_action('admin_enqueue_scripts', array($this, "load_scripts_styles_{$this->_current_view}"), 15); |
|
| 710 | - } |
|
| 711 | - add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100); |
|
| 712 | - // admin_print_footer_scripts - global, page child class, and view specific. |
|
| 713 | - // NOTE, despite the name, whenever possible, scripts should NOT be loaded using this. |
|
| 714 | - // In most cases that's doing_it_wrong(). But adding hidden container elements etc. |
|
| 715 | - // is a good use case. Notice the late priority we're giving these |
|
| 716 | - add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99); |
|
| 717 | - add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100); |
|
| 718 | - if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) { |
|
| 719 | - add_action('admin_print_footer_scripts', array($this, "admin_footer_scripts_{$this->_current_view}"), 101); |
|
| 720 | - } |
|
| 721 | - // admin footer scripts |
|
| 722 | - add_action('admin_footer', array($this, 'admin_footer_global'), 99); |
|
| 723 | - add_action('admin_footer', array($this, 'admin_footer'), 100); |
|
| 724 | - if (method_exists($this, "admin_footer_{$this->_current_view}")) { |
|
| 725 | - add_action('admin_footer', array($this, "admin_footer_{$this->_current_view}"), 101); |
|
| 726 | - } |
|
| 727 | - do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug); |
|
| 728 | - // targeted hook |
|
| 729 | - do_action( |
|
| 730 | - "FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}" |
|
| 731 | - ); |
|
| 732 | - } |
|
| 733 | - |
|
| 734 | - |
|
| 735 | - /** |
|
| 736 | - * _set_defaults |
|
| 737 | - * This sets some global defaults for class properties. |
|
| 738 | - */ |
|
| 739 | - private function _set_defaults() |
|
| 740 | - { |
|
| 741 | - $this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null; |
|
| 742 | - $this->_event = $this->_template_path = $this->_column_template_path = null; |
|
| 743 | - $this->_nav_tabs = $this->_views = $this->_page_routes = array(); |
|
| 744 | - $this->_page_config = $this->_default_route_query_args = array(); |
|
| 745 | - $this->_default_nav_tab_name = 'overview'; |
|
| 746 | - // init template args |
|
| 747 | - $this->_template_args = array( |
|
| 748 | - 'admin_page_header' => '', |
|
| 749 | - 'admin_page_content' => '', |
|
| 750 | - 'post_body_content' => '', |
|
| 751 | - 'before_list_table' => '', |
|
| 752 | - 'after_list_table' => '', |
|
| 753 | - ); |
|
| 754 | - } |
|
| 755 | - |
|
| 756 | - |
|
| 757 | - /** |
|
| 758 | - * route_admin_request |
|
| 759 | - * |
|
| 760 | - * @see _route_admin_request() |
|
| 761 | - * @return exception|void error |
|
| 762 | - * @throws InvalidArgumentException |
|
| 763 | - * @throws InvalidInterfaceException |
|
| 764 | - * @throws InvalidDataTypeException |
|
| 765 | - * @throws EE_Error |
|
| 766 | - * @throws ReflectionException |
|
| 767 | - */ |
|
| 768 | - public function route_admin_request() |
|
| 769 | - { |
|
| 770 | - try { |
|
| 771 | - $this->_route_admin_request(); |
|
| 772 | - } catch (EE_Error $e) { |
|
| 773 | - $e->get_error(); |
|
| 774 | - } |
|
| 775 | - } |
|
| 776 | - |
|
| 777 | - |
|
| 778 | - public function set_wp_page_slug($wp_page_slug) |
|
| 779 | - { |
|
| 780 | - $this->_wp_page_slug = $wp_page_slug; |
|
| 781 | - // if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls... |
|
| 782 | - if (is_network_admin()) { |
|
| 783 | - $this->_wp_page_slug .= '-network'; |
|
| 784 | - } |
|
| 785 | - } |
|
| 786 | - |
|
| 787 | - |
|
| 788 | - /** |
|
| 789 | - * _verify_routes |
|
| 790 | - * All this method does is verify the incoming request and make sure that routes exist for it. We do this early so |
|
| 791 | - * we know if we need to drop out. |
|
| 792 | - * |
|
| 793 | - * @return bool |
|
| 794 | - * @throws EE_Error |
|
| 795 | - */ |
|
| 796 | - protected function _verify_routes() |
|
| 797 | - { |
|
| 798 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 799 | - if (! $this->_current_page && ! defined('DOING_AJAX')) { |
|
| 800 | - return false; |
|
| 801 | - } |
|
| 802 | - $this->_route = false; |
|
| 803 | - // check that the page_routes array is not empty |
|
| 804 | - if (empty($this->_page_routes)) { |
|
| 805 | - // user error msg |
|
| 806 | - $error_msg = sprintf( |
|
| 807 | - esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'), |
|
| 808 | - $this->_admin_page_title |
|
| 809 | - ); |
|
| 810 | - // developer error msg |
|
| 811 | - $error_msg .= '||' . $error_msg |
|
| 812 | - . esc_html__( |
|
| 813 | - ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', |
|
| 814 | - 'event_espresso' |
|
| 815 | - ); |
|
| 816 | - throw new EE_Error($error_msg); |
|
| 817 | - } |
|
| 818 | - // and that the requested page route exists |
|
| 819 | - if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 820 | - $this->_route = $this->_page_routes[ $this->_req_action ]; |
|
| 821 | - $this->_route_config = isset($this->_page_config[ $this->_req_action ]) |
|
| 822 | - ? $this->_page_config[ $this->_req_action ] : array(); |
|
| 823 | - } else { |
|
| 824 | - // user error msg |
|
| 825 | - $error_msg = sprintf( |
|
| 826 | - esc_html__( |
|
| 827 | - 'The requested page route does not exist for the %s admin page.', |
|
| 828 | - 'event_espresso' |
|
| 829 | - ), |
|
| 830 | - $this->_admin_page_title |
|
| 831 | - ); |
|
| 832 | - // developer error msg |
|
| 833 | - $error_msg .= '||' . $error_msg |
|
| 834 | - . sprintf( |
|
| 835 | - esc_html__( |
|
| 836 | - ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', |
|
| 837 | - 'event_espresso' |
|
| 838 | - ), |
|
| 839 | - $this->_req_action |
|
| 840 | - ); |
|
| 841 | - throw new EE_Error($error_msg); |
|
| 842 | - } |
|
| 843 | - // and that a default route exists |
|
| 844 | - if (! array_key_exists('default', $this->_page_routes)) { |
|
| 845 | - // user error msg |
|
| 846 | - $error_msg = sprintf( |
|
| 847 | - esc_html__( |
|
| 848 | - 'A default page route has not been set for the % admin page.', |
|
| 849 | - 'event_espresso' |
|
| 850 | - ), |
|
| 851 | - $this->_admin_page_title |
|
| 852 | - ); |
|
| 853 | - // developer error msg |
|
| 854 | - $error_msg .= '||' . $error_msg |
|
| 855 | - . esc_html__( |
|
| 856 | - ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', |
|
| 857 | - 'event_espresso' |
|
| 858 | - ); |
|
| 859 | - throw new EE_Error($error_msg); |
|
| 860 | - } |
|
| 861 | - // first lets' catch if the UI request has EVER been set. |
|
| 862 | - if ($this->_is_UI_request === null) { |
|
| 863 | - // lets set if this is a UI request or not. |
|
| 864 | - $this->_is_UI_request = ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true; |
|
| 865 | - // wait a minute... we might have a noheader in the route array |
|
| 866 | - $this->_is_UI_request = is_array($this->_route) |
|
| 867 | - && isset($this->_route['noheader']) |
|
| 868 | - && $this->_route['noheader'] ? false : $this->_is_UI_request; |
|
| 869 | - } |
|
| 870 | - $this->_set_current_labels(); |
|
| 871 | - return true; |
|
| 872 | - } |
|
| 873 | - |
|
| 874 | - |
|
| 875 | - /** |
|
| 876 | - * this method simply verifies a given route and makes sure its an actual route available for the loaded page |
|
| 877 | - * |
|
| 878 | - * @param string $route the route name we're verifying |
|
| 879 | - * @return mixed (bool|Exception) we'll throw an exception if this isn't a valid route. |
|
| 880 | - * @throws EE_Error |
|
| 881 | - */ |
|
| 882 | - protected function _verify_route($route) |
|
| 883 | - { |
|
| 884 | - if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 885 | - return true; |
|
| 886 | - } |
|
| 887 | - // user error msg |
|
| 888 | - $error_msg = sprintf( |
|
| 889 | - esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'), |
|
| 890 | - $this->_admin_page_title |
|
| 891 | - ); |
|
| 892 | - // developer error msg |
|
| 893 | - $error_msg .= '||' . $error_msg |
|
| 894 | - . sprintf( |
|
| 895 | - esc_html__( |
|
| 896 | - ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', |
|
| 897 | - 'event_espresso' |
|
| 898 | - ), |
|
| 899 | - $route |
|
| 900 | - ); |
|
| 901 | - throw new EE_Error($error_msg); |
|
| 902 | - } |
|
| 903 | - |
|
| 904 | - |
|
| 905 | - /** |
|
| 906 | - * perform nonce verification |
|
| 907 | - * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces |
|
| 908 | - * using this method (and save retyping!) |
|
| 909 | - * |
|
| 910 | - * @param string $nonce The nonce sent |
|
| 911 | - * @param string $nonce_ref The nonce reference string (name0) |
|
| 912 | - * @return void |
|
| 913 | - * @throws EE_Error |
|
| 914 | - */ |
|
| 915 | - protected function _verify_nonce($nonce, $nonce_ref) |
|
| 916 | - { |
|
| 917 | - // verify nonce against expected value |
|
| 918 | - if (! wp_verify_nonce($nonce, $nonce_ref)) { |
|
| 919 | - // these are not the droids you are looking for !!! |
|
| 920 | - $msg = sprintf( |
|
| 921 | - esc_html__('%sNonce Fail.%s', 'event_espresso'), |
|
| 922 | - '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">', |
|
| 923 | - '</a>' |
|
| 924 | - ); |
|
| 925 | - if (WP_DEBUG) { |
|
| 926 | - $msg .= "\n " |
|
| 927 | - . sprintf( |
|
| 928 | - esc_html__( |
|
| 929 | - 'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', |
|
| 930 | - 'event_espresso' |
|
| 931 | - ), |
|
| 932 | - __CLASS__ |
|
| 933 | - ); |
|
| 934 | - } |
|
| 935 | - if (! defined('DOING_AJAX')) { |
|
| 936 | - wp_die($msg); |
|
| 937 | - } else { |
|
| 938 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 939 | - $this->_return_json(); |
|
| 940 | - } |
|
| 941 | - } |
|
| 942 | - } |
|
| 943 | - |
|
| 944 | - |
|
| 945 | - /** |
|
| 946 | - * _route_admin_request() |
|
| 947 | - * Meat and potatoes of the class. Basically, this dude checks out what's being requested and sees if theres are |
|
| 948 | - * some doodads to work the magic and handle the flingjangy. Translation: Checks if the requested action is listed |
|
| 949 | - * in the page routes and then will try to load the corresponding method. |
|
| 950 | - * |
|
| 951 | - * @return void |
|
| 952 | - * @throws EE_Error |
|
| 953 | - * @throws InvalidArgumentException |
|
| 954 | - * @throws InvalidDataTypeException |
|
| 955 | - * @throws InvalidInterfaceException |
|
| 956 | - * @throws ReflectionException |
|
| 957 | - */ |
|
| 958 | - protected function _route_admin_request() |
|
| 959 | - { |
|
| 960 | - if (! $this->_is_UI_request) { |
|
| 961 | - $this->_verify_routes(); |
|
| 962 | - } |
|
| 963 | - $nonce_check = isset($this->_route_config['require_nonce']) |
|
| 964 | - ? $this->_route_config['require_nonce'] |
|
| 965 | - : true; |
|
| 966 | - if ($this->_req_action !== 'default' && $nonce_check) { |
|
| 967 | - // set nonce from post data |
|
| 968 | - $nonce = isset($this->_req_data[ $this->_req_nonce ]) |
|
| 969 | - ? sanitize_text_field($this->_req_data[ $this->_req_nonce ]) |
|
| 970 | - : ''; |
|
| 971 | - $this->_verify_nonce($nonce, $this->_req_nonce); |
|
| 972 | - } |
|
| 973 | - // set the nav_tabs array but ONLY if this is UI_request |
|
| 974 | - if ($this->_is_UI_request) { |
|
| 975 | - $this->_set_nav_tabs(); |
|
| 976 | - } |
|
| 977 | - // grab callback function |
|
| 978 | - $func = is_array($this->_route) ? $this->_route['func'] : $this->_route; |
|
| 979 | - // check if callback has args |
|
| 980 | - $args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array(); |
|
| 981 | - $error_msg = ''; |
|
| 982 | - // action right before calling route |
|
| 983 | - // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request') |
|
| 984 | - if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
| 985 | - do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this); |
|
| 986 | - } |
|
| 987 | - // right before calling the route, let's remove _wp_http_referer from the |
|
| 988 | - // $_SERVER[REQUEST_URI] global (its now in _req_data for route processing). |
|
| 989 | - $_SERVER['REQUEST_URI'] = remove_query_arg( |
|
| 990 | - '_wp_http_referer', |
|
| 991 | - wp_unslash($_SERVER['REQUEST_URI']) |
|
| 992 | - ); |
|
| 993 | - if (! empty($func)) { |
|
| 994 | - if (is_array($func)) { |
|
| 995 | - list($class, $method) = $func; |
|
| 996 | - } elseif (strpos($func, '::') !== false) { |
|
| 997 | - list($class, $method) = explode('::', $func); |
|
| 998 | - } else { |
|
| 999 | - $class = $this; |
|
| 1000 | - $method = $func; |
|
| 1001 | - } |
|
| 1002 | - if (! (is_object($class) && $class === $this)) { |
|
| 1003 | - // send along this admin page object for access by addons. |
|
| 1004 | - $args['admin_page_object'] = $this; |
|
| 1005 | - } |
|
| 1006 | - if (// is it a method on a class that doesn't work? |
|
| 1007 | - ( |
|
| 1008 | - ( |
|
| 1009 | - method_exists($class, $method) |
|
| 1010 | - && call_user_func_array(array($class, $method), $args) === false |
|
| 1011 | - ) |
|
| 1012 | - && ( |
|
| 1013 | - // is it a standalone function that doesn't work? |
|
| 1014 | - function_exists($method) |
|
| 1015 | - && call_user_func_array( |
|
| 1016 | - $func, |
|
| 1017 | - array_merge(array('admin_page_object' => $this), $args) |
|
| 1018 | - ) === false |
|
| 1019 | - ) |
|
| 1020 | - ) |
|
| 1021 | - || ( |
|
| 1022 | - // is it neither a class method NOR a standalone function? |
|
| 1023 | - ! method_exists($class, $method) |
|
| 1024 | - && ! function_exists($method) |
|
| 1025 | - ) |
|
| 1026 | - ) { |
|
| 1027 | - // user error msg |
|
| 1028 | - $error_msg = esc_html__( |
|
| 1029 | - 'An error occurred. The requested page route could not be found.', |
|
| 1030 | - 'event_espresso' |
|
| 1031 | - ); |
|
| 1032 | - // developer error msg |
|
| 1033 | - $error_msg .= '||'; |
|
| 1034 | - $error_msg .= sprintf( |
|
| 1035 | - esc_html__( |
|
| 1036 | - 'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.', |
|
| 1037 | - 'event_espresso' |
|
| 1038 | - ), |
|
| 1039 | - $method |
|
| 1040 | - ); |
|
| 1041 | - } |
|
| 1042 | - if (! empty($error_msg)) { |
|
| 1043 | - throw new EE_Error($error_msg); |
|
| 1044 | - } |
|
| 1045 | - } |
|
| 1046 | - // if we've routed and this route has a no headers route AND a sent_headers_route, |
|
| 1047 | - // then we need to reset the routing properties to the new route. |
|
| 1048 | - // 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. |
|
| 1049 | - if ($this->_is_UI_request === false |
|
| 1050 | - && is_array($this->_route) |
|
| 1051 | - && ! empty($this->_route['headers_sent_route']) |
|
| 1052 | - ) { |
|
| 1053 | - $this->_reset_routing_properties($this->_route['headers_sent_route']); |
|
| 1054 | - } |
|
| 1055 | - } |
|
| 1056 | - |
|
| 1057 | - |
|
| 1058 | - /** |
|
| 1059 | - * This method just allows the resetting of page properties in the case where a no headers |
|
| 1060 | - * route redirects to a headers route in its route config. |
|
| 1061 | - * |
|
| 1062 | - * @since 4.3.0 |
|
| 1063 | - * @param string $new_route New (non header) route to redirect to. |
|
| 1064 | - * @return void |
|
| 1065 | - * @throws ReflectionException |
|
| 1066 | - * @throws InvalidArgumentException |
|
| 1067 | - * @throws InvalidInterfaceException |
|
| 1068 | - * @throws InvalidDataTypeException |
|
| 1069 | - * @throws EE_Error |
|
| 1070 | - */ |
|
| 1071 | - protected function _reset_routing_properties($new_route) |
|
| 1072 | - { |
|
| 1073 | - $this->_is_UI_request = true; |
|
| 1074 | - // now we set the current route to whatever the headers_sent_route is set at |
|
| 1075 | - $this->_req_data['action'] = $new_route; |
|
| 1076 | - // rerun page setup |
|
| 1077 | - $this->_page_setup(); |
|
| 1078 | - } |
|
| 1079 | - |
|
| 1080 | - |
|
| 1081 | - /** |
|
| 1082 | - * _add_query_arg |
|
| 1083 | - * adds nonce to array of arguments then calls WP add_query_arg function |
|
| 1084 | - *(internally just uses EEH_URL's function with the same name) |
|
| 1085 | - * |
|
| 1086 | - * @param array $args |
|
| 1087 | - * @param string $url |
|
| 1088 | - * @param bool $sticky if true, then the existing Request params will be appended to the |
|
| 1089 | - * generated url in an associative array indexed by the key 'wp_referer'; |
|
| 1090 | - * Example usage: If the current page is: |
|
| 1091 | - * http://mydomain.com/wp-admin/admin.php?page=espresso_registrations |
|
| 1092 | - * &action=default&event_id=20&month_range=March%202015 |
|
| 1093 | - * &_wpnonce=5467821 |
|
| 1094 | - * and you call: |
|
| 1095 | - * EE_Admin_Page::add_query_args_and_nonce( |
|
| 1096 | - * array( |
|
| 1097 | - * 'action' => 'resend_something', |
|
| 1098 | - * 'page=>espresso_registrations' |
|
| 1099 | - * ), |
|
| 1100 | - * $some_url, |
|
| 1101 | - * true |
|
| 1102 | - * ); |
|
| 1103 | - * It will produce a url in this structure: |
|
| 1104 | - * http://{$some_url}/?page=espresso_registrations&action=resend_something |
|
| 1105 | - * &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[ |
|
| 1106 | - * month_range]=March%202015 |
|
| 1107 | - * @param bool $exclude_nonce If true, the the nonce will be excluded from the generated nonce. |
|
| 1108 | - * @return string |
|
| 1109 | - */ |
|
| 1110 | - public static function add_query_args_and_nonce( |
|
| 1111 | - $args = array(), |
|
| 1112 | - $url = false, |
|
| 1113 | - $sticky = false, |
|
| 1114 | - $exclude_nonce = false |
|
| 1115 | - ) { |
|
| 1116 | - // if there is a _wp_http_referer include the values from the request but only if sticky = true |
|
| 1117 | - if ($sticky) { |
|
| 1118 | - $request = $_REQUEST; |
|
| 1119 | - unset($request['_wp_http_referer']); |
|
| 1120 | - unset($request['wp_referer']); |
|
| 1121 | - foreach ($request as $key => $value) { |
|
| 1122 | - // do not add nonces |
|
| 1123 | - if (strpos($key, 'nonce') !== false) { |
|
| 1124 | - continue; |
|
| 1125 | - } |
|
| 1126 | - $args[ 'wp_referer[' . $key . ']' ] = $value; |
|
| 1127 | - } |
|
| 1128 | - } |
|
| 1129 | - return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce); |
|
| 1130 | - } |
|
| 1131 | - |
|
| 1132 | - |
|
| 1133 | - /** |
|
| 1134 | - * This returns a generated link that will load the related help tab. |
|
| 1135 | - * |
|
| 1136 | - * @param string $help_tab_id the id for the connected help tab |
|
| 1137 | - * @param string $icon_style (optional) include css class for the style you want to use for the help icon. |
|
| 1138 | - * @param string $help_text (optional) send help text you want to use for the link if default not to be used |
|
| 1139 | - * @uses EEH_Template::get_help_tab_link() |
|
| 1140 | - * @return string generated link |
|
| 1141 | - */ |
|
| 1142 | - protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '') |
|
| 1143 | - { |
|
| 1144 | - return EEH_Template::get_help_tab_link( |
|
| 1145 | - $help_tab_id, |
|
| 1146 | - $this->page_slug, |
|
| 1147 | - $this->_req_action, |
|
| 1148 | - $icon_style, |
|
| 1149 | - $help_text |
|
| 1150 | - ); |
|
| 1151 | - } |
|
| 1152 | - |
|
| 1153 | - |
|
| 1154 | - /** |
|
| 1155 | - * _add_help_tabs |
|
| 1156 | - * Note child classes define their help tabs within the page_config array. |
|
| 1157 | - * |
|
| 1158 | - * @link http://codex.wordpress.org/Function_Reference/add_help_tab |
|
| 1159 | - * @return void |
|
| 1160 | - * @throws DomainException |
|
| 1161 | - * @throws EE_Error |
|
| 1162 | - */ |
|
| 1163 | - protected function _add_help_tabs() |
|
| 1164 | - { |
|
| 1165 | - $tour_buttons = ''; |
|
| 1166 | - if (isset($this->_page_config[ $this->_req_action ])) { |
|
| 1167 | - $config = $this->_page_config[ $this->_req_action ]; |
|
| 1168 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 1169 | - // is there a help tour for the current route? if there is let's setup the tour buttons |
|
| 1170 | - // if (isset($this->_help_tour[ $this->_req_action ])) { |
|
| 1171 | - // $tb = array(); |
|
| 1172 | - // $tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">'; |
|
| 1173 | - // foreach ($this->_help_tour['tours'] as $tour) { |
|
| 1174 | - // // if this is the end tour then we don't need to setup a button |
|
| 1175 | - // if ($tour instanceof EE_Help_Tour_final_stop || ! $tour instanceof EE_Help_Tour) { |
|
| 1176 | - // continue; |
|
| 1177 | - // } |
|
| 1178 | - // $tb[] = '<button id="trigger-tour-' |
|
| 1179 | - // . $tour->get_slug() |
|
| 1180 | - // . '" class="button-primary trigger-ee-help-tour">' |
|
| 1181 | - // . $tour->get_label() |
|
| 1182 | - // . '</button>'; |
|
| 1183 | - // } |
|
| 1184 | - // $tour_buttons .= implode('<br />', $tb); |
|
| 1185 | - // $tour_buttons .= '</div></div>'; |
|
| 1186 | - // } |
|
| 1187 | - // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well. |
|
| 1188 | - if (is_array($config) && isset($config['help_sidebar'])) { |
|
| 1189 | - // check that the callback given is valid |
|
| 1190 | - if (! method_exists($this, $config['help_sidebar'])) { |
|
| 1191 | - throw new EE_Error( |
|
| 1192 | - sprintf( |
|
| 1193 | - esc_html__( |
|
| 1194 | - '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', |
|
| 1195 | - 'event_espresso' |
|
| 1196 | - ), |
|
| 1197 | - $config['help_sidebar'], |
|
| 1198 | - get_class($this) |
|
| 1199 | - ) |
|
| 1200 | - ); |
|
| 1201 | - } |
|
| 1202 | - $content = apply_filters( |
|
| 1203 | - 'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', |
|
| 1204 | - $this->{$config['help_sidebar']}() |
|
| 1205 | - ); |
|
| 1206 | - $content .= $tour_buttons; // add help tour buttons. |
|
| 1207 | - // do we have any help tours setup? Cause if we do we want to add the buttons |
|
| 1208 | - $this->_current_screen->set_help_sidebar($content); |
|
| 1209 | - } |
|
| 1210 | - // if we DON'T have config help sidebar and there ARE tour buttons then we'll just add the tour buttons to the sidebar. |
|
| 1211 | - if (! isset($config['help_sidebar']) && ! empty($tour_buttons)) { |
|
| 1212 | - $this->_current_screen->set_help_sidebar($tour_buttons); |
|
| 1213 | - } |
|
| 1214 | - // handle if no help_tabs are set so the sidebar will still show for the help tour buttons |
|
| 1215 | - if (! isset($config['help_tabs']) && ! empty($tour_buttons)) { |
|
| 1216 | - $_ht['id'] = $this->page_slug; |
|
| 1217 | - $_ht['title'] = esc_html__('Help Tours', 'event_espresso'); |
|
| 1218 | - $_ht['content'] = '<p>' |
|
| 1219 | - . esc_html__( |
|
| 1220 | - 'The buttons to the right allow you to start/restart any help tours available for this page', |
|
| 1221 | - 'event_espresso' |
|
| 1222 | - ) . '</p>'; |
|
| 1223 | - $this->_current_screen->add_help_tab($_ht); |
|
| 1224 | - } |
|
| 1225 | - if (! isset($config['help_tabs'])) { |
|
| 1226 | - return; |
|
| 1227 | - } //no help tabs for this route |
|
| 1228 | - foreach ((array) $config['help_tabs'] as $tab_id => $cfg) { |
|
| 1229 | - // we're here so there ARE help tabs! |
|
| 1230 | - // make sure we've got what we need |
|
| 1231 | - if (! isset($cfg['title'])) { |
|
| 1232 | - throw new EE_Error( |
|
| 1233 | - esc_html__( |
|
| 1234 | - 'The _page_config array is not set up properly for help tabs. It is missing a title', |
|
| 1235 | - 'event_espresso' |
|
| 1236 | - ) |
|
| 1237 | - ); |
|
| 1238 | - } |
|
| 1239 | - if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
| 1240 | - throw new EE_Error( |
|
| 1241 | - esc_html__( |
|
| 1242 | - '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', |
|
| 1243 | - 'event_espresso' |
|
| 1244 | - ) |
|
| 1245 | - ); |
|
| 1246 | - } |
|
| 1247 | - // first priority goes to content. |
|
| 1248 | - if (! empty($cfg['content'])) { |
|
| 1249 | - $content = ! empty($cfg['content']) ? $cfg['content'] : null; |
|
| 1250 | - // second priority goes to filename |
|
| 1251 | - } elseif (! empty($cfg['filename'])) { |
|
| 1252 | - $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php'; |
|
| 1253 | - // 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) |
|
| 1254 | - $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
|
| 1255 | - . basename($this->_get_dir()) |
|
| 1256 | - . '/help_tabs/' |
|
| 1257 | - . $cfg['filename'] |
|
| 1258 | - . '.help_tab.php' : $file_path; |
|
| 1259 | - // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
| 1260 | - if (! isset($cfg['callback']) && ! is_readable($file_path)) { |
|
| 1261 | - EE_Error::add_error( |
|
| 1262 | - sprintf( |
|
| 1263 | - esc_html__( |
|
| 1264 | - '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', |
|
| 1265 | - 'event_espresso' |
|
| 1266 | - ), |
|
| 1267 | - $tab_id, |
|
| 1268 | - key($config), |
|
| 1269 | - $file_path |
|
| 1270 | - ), |
|
| 1271 | - __FILE__, |
|
| 1272 | - __FUNCTION__, |
|
| 1273 | - __LINE__ |
|
| 1274 | - ); |
|
| 1275 | - return; |
|
| 1276 | - } |
|
| 1277 | - $template_args['admin_page_obj'] = $this; |
|
| 1278 | - $content = EEH_Template::display_template( |
|
| 1279 | - $file_path, |
|
| 1280 | - $template_args, |
|
| 1281 | - true |
|
| 1282 | - ); |
|
| 1283 | - } else { |
|
| 1284 | - $content = ''; |
|
| 1285 | - } |
|
| 1286 | - // check if callback is valid |
|
| 1287 | - if (empty($content) && ( |
|
| 1288 | - ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback']) |
|
| 1289 | - ) |
|
| 1290 | - ) { |
|
| 1291 | - EE_Error::add_error( |
|
| 1292 | - sprintf( |
|
| 1293 | - esc_html__( |
|
| 1294 | - '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.', |
|
| 1295 | - 'event_espresso' |
|
| 1296 | - ), |
|
| 1297 | - $cfg['title'] |
|
| 1298 | - ), |
|
| 1299 | - __FILE__, |
|
| 1300 | - __FUNCTION__, |
|
| 1301 | - __LINE__ |
|
| 1302 | - ); |
|
| 1303 | - return; |
|
| 1304 | - } |
|
| 1305 | - // setup config array for help tab method |
|
| 1306 | - $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id; |
|
| 1307 | - $_ht = array( |
|
| 1308 | - 'id' => $id, |
|
| 1309 | - 'title' => $cfg['title'], |
|
| 1310 | - 'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null, |
|
| 1311 | - 'content' => $content, |
|
| 1312 | - ); |
|
| 1313 | - $this->_current_screen->add_help_tab($_ht); |
|
| 1314 | - } |
|
| 1315 | - } |
|
| 1316 | - } |
|
| 1317 | - |
|
| 1318 | - |
|
| 1319 | - /** |
|
| 1320 | - * This basically checks loaded $_page_config property to see if there are any help_tours defined. "help_tours" is |
|
| 1321 | - * an array with properties for setting up usage of the joyride plugin |
|
| 1322 | - * |
|
| 1323 | - * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin |
|
| 1324 | - * @see instructions regarding the format and construction of the "help_tour" array element is found in the |
|
| 1325 | - * _set_page_config() comments |
|
| 1326 | - * @return void |
|
| 1327 | - * @throws EE_Error |
|
| 1328 | - * @throws InvalidArgumentException |
|
| 1329 | - * @throws InvalidDataTypeException |
|
| 1330 | - * @throws InvalidInterfaceException |
|
| 1331 | - */ |
|
| 1332 | - protected function _add_help_tour() |
|
| 1333 | - { |
|
| 1334 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 1335 | - // $tours = array(); |
|
| 1336 | - // $this->_help_tour = array(); |
|
| 1337 | - // // exit early if help tours are turned off globally |
|
| 1338 | - // if ((defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS) |
|
| 1339 | - // || ! EE_Registry::instance()->CFG->admin->help_tour_activation |
|
| 1340 | - // ) { |
|
| 1341 | - // return; |
|
| 1342 | - // } |
|
| 1343 | - // // loop through _page_config to find any help_tour defined |
|
| 1344 | - // foreach ($this->_page_config as $route => $config) { |
|
| 1345 | - // // we're only going to set things up for this route |
|
| 1346 | - // if ($route !== $this->_req_action) { |
|
| 1347 | - // continue; |
|
| 1348 | - // } |
|
| 1349 | - // if (isset($config['help_tour'])) { |
|
| 1350 | - // foreach ($config['help_tour'] as $tour) { |
|
| 1351 | - // $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php'; |
|
| 1352 | - // // let's see if we can get that file... |
|
| 1353 | - // // if not its possible this is a decaf route not set in caffeinated |
|
| 1354 | - // // so lets try and get the caffeinated equivalent |
|
| 1355 | - // $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
|
| 1356 | - // . basename($this->_get_dir()) |
|
| 1357 | - // . '/help_tours/' |
|
| 1358 | - // . $tour |
|
| 1359 | - // . '.class.php' : $file_path; |
|
| 1360 | - // // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
| 1361 | - // if (! is_readable($file_path)) { |
|
| 1362 | - // EE_Error::add_error( |
|
| 1363 | - // sprintf( |
|
| 1364 | - // esc_html__( |
|
| 1365 | - // 'The file path given for the help tour (%s) is not a valid path. Please check that the string you set for the help tour on this route (%s) is the correct spelling', |
|
| 1366 | - // 'event_espresso' |
|
| 1367 | - // ), |
|
| 1368 | - // $file_path, |
|
| 1369 | - // $tour |
|
| 1370 | - // ), |
|
| 1371 | - // __FILE__, |
|
| 1372 | - // __FUNCTION__, |
|
| 1373 | - // __LINE__ |
|
| 1374 | - // ); |
|
| 1375 | - // return; |
|
| 1376 | - // } |
|
| 1377 | - // require_once $file_path; |
|
| 1378 | - // if (! class_exists($tour)) { |
|
| 1379 | - // $error_msg[] = sprintf( |
|
| 1380 | - // esc_html__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'), |
|
| 1381 | - // $tour |
|
| 1382 | - // ); |
|
| 1383 | - // $error_msg[] = $error_msg[0] . "\r\n" |
|
| 1384 | - // . sprintf( |
|
| 1385 | - // esc_html__( |
|
| 1386 | - // 'There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.', |
|
| 1387 | - // 'event_espresso' |
|
| 1388 | - // ), |
|
| 1389 | - // $tour, |
|
| 1390 | - // '<br />', |
|
| 1391 | - // $tour, |
|
| 1392 | - // $this->_req_action, |
|
| 1393 | - // get_class($this) |
|
| 1394 | - // ); |
|
| 1395 | - // throw new EE_Error(implode('||', $error_msg)); |
|
| 1396 | - // } |
|
| 1397 | - // $tour_obj = new $tour($this->_is_caf); |
|
| 1398 | - // $tours[] = $tour_obj; |
|
| 1399 | - // $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($tour_obj); |
|
| 1400 | - // } |
|
| 1401 | - // // let's inject the end tour stop element common to all pages... this will only get seen once per machine. |
|
| 1402 | - // $end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf); |
|
| 1403 | - // $tours[] = $end_stop_tour; |
|
| 1404 | - // $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($end_stop_tour); |
|
| 1405 | - // } |
|
| 1406 | - // } |
|
| 1407 | - // |
|
| 1408 | - // if (! empty($tours)) { |
|
| 1409 | - // $this->_help_tour['tours'] = $tours; |
|
| 1410 | - // } |
|
| 1411 | - // // that's it! Now that the $_help_tours property is set (or not) |
|
| 1412 | - // // the scripts and html should be taken care of automatically. |
|
| 1413 | - // |
|
| 1414 | - // /** |
|
| 1415 | - // * Allow extending the help tours variable. |
|
| 1416 | - // * |
|
| 1417 | - // * @param Array $_help_tour The array containing all help tour information to be displayed. |
|
| 1418 | - // */ |
|
| 1419 | - // $this->_help_tour = apply_filters('FHEE__EE_Admin_Page___add_help_tour___help_tour', $this->_help_tour); |
|
| 1420 | - } |
|
| 1421 | - |
|
| 1422 | - |
|
| 1423 | - /** |
|
| 1424 | - * This simply sets up any qtips that have been defined in the page config |
|
| 1425 | - * |
|
| 1426 | - * @return void |
|
| 1427 | - */ |
|
| 1428 | - protected function _add_qtips() |
|
| 1429 | - { |
|
| 1430 | - if (isset($this->_route_config['qtips'])) { |
|
| 1431 | - $qtips = (array) $this->_route_config['qtips']; |
|
| 1432 | - // load qtip loader |
|
| 1433 | - $path = array( |
|
| 1434 | - $this->_get_dir() . '/qtips/', |
|
| 1435 | - EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/', |
|
| 1436 | - ); |
|
| 1437 | - EEH_Qtip_Loader::instance()->register($qtips, $path); |
|
| 1438 | - } |
|
| 1439 | - } |
|
| 1440 | - |
|
| 1441 | - |
|
| 1442 | - /** |
|
| 1443 | - * _set_nav_tabs |
|
| 1444 | - * This sets up the nav tabs from the page_routes array. This method can be overwritten by child classes if you |
|
| 1445 | - * wish to add additional tabs or modify accordingly. |
|
| 1446 | - * |
|
| 1447 | - * @return void |
|
| 1448 | - * @throws InvalidArgumentException |
|
| 1449 | - * @throws InvalidInterfaceException |
|
| 1450 | - * @throws InvalidDataTypeException |
|
| 1451 | - */ |
|
| 1452 | - protected function _set_nav_tabs() |
|
| 1453 | - { |
|
| 1454 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1455 | - $i = 0; |
|
| 1456 | - foreach ($this->_page_config as $slug => $config) { |
|
| 1457 | - if (! is_array($config) |
|
| 1458 | - || ( |
|
| 1459 | - is_array($config) |
|
| 1460 | - && ( |
|
| 1461 | - (isset($config['nav']) && ! $config['nav']) |
|
| 1462 | - || ! isset($config['nav']) |
|
| 1463 | - ) |
|
| 1464 | - ) |
|
| 1465 | - ) { |
|
| 1466 | - continue; |
|
| 1467 | - } |
|
| 1468 | - // no nav tab for this config |
|
| 1469 | - // check for persistent flag |
|
| 1470 | - if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) { |
|
| 1471 | - // nav tab is only to appear when route requested. |
|
| 1472 | - continue; |
|
| 1473 | - } |
|
| 1474 | - if (! $this->check_user_access($slug, true)) { |
|
| 1475 | - // no nav tab because current user does not have access. |
|
| 1476 | - continue; |
|
| 1477 | - } |
|
| 1478 | - $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : ''; |
|
| 1479 | - $this->_nav_tabs[ $slug ] = array( |
|
| 1480 | - 'url' => isset($config['nav']['url']) |
|
| 1481 | - ? $config['nav']['url'] |
|
| 1482 | - : self::add_query_args_and_nonce( |
|
| 1483 | - array('action' => $slug), |
|
| 1484 | - $this->_admin_base_url |
|
| 1485 | - ), |
|
| 1486 | - 'link_text' => isset($config['nav']['label']) |
|
| 1487 | - ? $config['nav']['label'] |
|
| 1488 | - : ucwords( |
|
| 1489 | - str_replace('_', ' ', $slug) |
|
| 1490 | - ), |
|
| 1491 | - 'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class, |
|
| 1492 | - 'order' => isset($config['nav']['order']) ? $config['nav']['order'] : $i, |
|
| 1493 | - ); |
|
| 1494 | - $i++; |
|
| 1495 | - } |
|
| 1496 | - // if $this->_nav_tabs is empty then lets set the default |
|
| 1497 | - if (empty($this->_nav_tabs)) { |
|
| 1498 | - $this->_nav_tabs[ $this->_default_nav_tab_name ] = array( |
|
| 1499 | - 'url' => $this->_admin_base_url, |
|
| 1500 | - 'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)), |
|
| 1501 | - 'css_class' => 'nav-tab-active', |
|
| 1502 | - 'order' => 10, |
|
| 1503 | - ); |
|
| 1504 | - } |
|
| 1505 | - // now let's sort the tabs according to order |
|
| 1506 | - usort($this->_nav_tabs, array($this, '_sort_nav_tabs')); |
|
| 1507 | - } |
|
| 1508 | - |
|
| 1509 | - |
|
| 1510 | - /** |
|
| 1511 | - * _set_current_labels |
|
| 1512 | - * This method modifies the _labels property with any optional specific labels indicated in the _page_routes |
|
| 1513 | - * property array |
|
| 1514 | - * |
|
| 1515 | - * @return void |
|
| 1516 | - */ |
|
| 1517 | - private function _set_current_labels() |
|
| 1518 | - { |
|
| 1519 | - if (is_array($this->_route_config) && isset($this->_route_config['labels'])) { |
|
| 1520 | - foreach ($this->_route_config['labels'] as $label => $text) { |
|
| 1521 | - if (is_array($text)) { |
|
| 1522 | - foreach ($text as $sublabel => $subtext) { |
|
| 1523 | - $this->_labels[ $label ][ $sublabel ] = $subtext; |
|
| 1524 | - } |
|
| 1525 | - } else { |
|
| 1526 | - $this->_labels[ $label ] = $text; |
|
| 1527 | - } |
|
| 1528 | - } |
|
| 1529 | - } |
|
| 1530 | - } |
|
| 1531 | - |
|
| 1532 | - |
|
| 1533 | - /** |
|
| 1534 | - * verifies user access for this admin page |
|
| 1535 | - * |
|
| 1536 | - * @param string $route_to_check if present then the capability for the route matching this string is checked. |
|
| 1537 | - * @param bool $verify_only Default is FALSE which means if user check fails then wp_die(). Otherwise just |
|
| 1538 | - * return false if verify fail. |
|
| 1539 | - * @return bool |
|
| 1540 | - * @throws InvalidArgumentException |
|
| 1541 | - * @throws InvalidDataTypeException |
|
| 1542 | - * @throws InvalidInterfaceException |
|
| 1543 | - */ |
|
| 1544 | - public function check_user_access($route_to_check = '', $verify_only = false) |
|
| 1545 | - { |
|
| 1546 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1547 | - $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check; |
|
| 1548 | - $capability = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ]) |
|
| 1549 | - && is_array( |
|
| 1550 | - $this->_page_routes[ $route_to_check ] |
|
| 1551 | - ) |
|
| 1552 | - && ! empty($this->_page_routes[ $route_to_check ]['capability']) |
|
| 1553 | - ? $this->_page_routes[ $route_to_check ]['capability'] : null; |
|
| 1554 | - if (empty($capability) && empty($route_to_check)) { |
|
| 1555 | - $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' |
|
| 1556 | - : $this->_route['capability']; |
|
| 1557 | - } else { |
|
| 1558 | - $capability = empty($capability) ? 'manage_options' : $capability; |
|
| 1559 | - } |
|
| 1560 | - $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0; |
|
| 1561 | - if (! defined('DOING_AJAX') |
|
| 1562 | - && ( |
|
| 1563 | - ! function_exists('is_admin') |
|
| 1564 | - || ! EE_Registry::instance()->CAP->current_user_can( |
|
| 1565 | - $capability, |
|
| 1566 | - $this->page_slug |
|
| 1567 | - . '_' |
|
| 1568 | - . $route_to_check, |
|
| 1569 | - $id |
|
| 1570 | - ) |
|
| 1571 | - ) |
|
| 1572 | - ) { |
|
| 1573 | - if ($verify_only) { |
|
| 1574 | - return false; |
|
| 1575 | - } |
|
| 1576 | - if (is_user_logged_in()) { |
|
| 1577 | - wp_die(__('You do not have access to this route.', 'event_espresso')); |
|
| 1578 | - } else { |
|
| 1579 | - return false; |
|
| 1580 | - } |
|
| 1581 | - } |
|
| 1582 | - return true; |
|
| 1583 | - } |
|
| 1584 | - |
|
| 1585 | - |
|
| 1586 | - /** |
|
| 1587 | - * admin_init_global |
|
| 1588 | - * This runs all the code that we want executed within the WP admin_init hook. |
|
| 1589 | - * This method executes for ALL EE Admin pages. |
|
| 1590 | - * |
|
| 1591 | - * @return void |
|
| 1592 | - */ |
|
| 1593 | - public function admin_init_global() |
|
| 1594 | - { |
|
| 1595 | - } |
|
| 1596 | - |
|
| 1597 | - |
|
| 1598 | - /** |
|
| 1599 | - * wp_loaded_global |
|
| 1600 | - * This runs all the code that we want executed within the WP wp_loaded hook. This method is optional for an |
|
| 1601 | - * EE_Admin page and will execute on every EE Admin Page load |
|
| 1602 | - * |
|
| 1603 | - * @return void |
|
| 1604 | - */ |
|
| 1605 | - public function wp_loaded() |
|
| 1606 | - { |
|
| 1607 | - } |
|
| 1608 | - |
|
| 1609 | - |
|
| 1610 | - /** |
|
| 1611 | - * admin_notices |
|
| 1612 | - * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply on |
|
| 1613 | - * ALL EE_Admin pages. |
|
| 1614 | - * |
|
| 1615 | - * @return void |
|
| 1616 | - */ |
|
| 1617 | - public function admin_notices_global() |
|
| 1618 | - { |
|
| 1619 | - $this->_display_no_javascript_warning(); |
|
| 1620 | - $this->_display_espresso_notices(); |
|
| 1621 | - } |
|
| 1622 | - |
|
| 1623 | - |
|
| 1624 | - public function network_admin_notices_global() |
|
| 1625 | - { |
|
| 1626 | - $this->_display_no_javascript_warning(); |
|
| 1627 | - $this->_display_espresso_notices(); |
|
| 1628 | - } |
|
| 1629 | - |
|
| 1630 | - |
|
| 1631 | - /** |
|
| 1632 | - * admin_footer_scripts_global |
|
| 1633 | - * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
| 1634 | - * will apply on ALL EE_Admin pages. |
|
| 1635 | - * |
|
| 1636 | - * @return void |
|
| 1637 | - */ |
|
| 1638 | - public function admin_footer_scripts_global() |
|
| 1639 | - { |
|
| 1640 | - $this->_add_admin_page_ajax_loading_img(); |
|
| 1641 | - $this->_add_admin_page_overlay(); |
|
| 1642 | - // if metaboxes are present we need to add the nonce field |
|
| 1643 | - if (isset($this->_route_config['metaboxes']) |
|
| 1644 | - || isset($this->_route_config['list_table']) |
|
| 1645 | - || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes']) |
|
| 1646 | - ) { |
|
| 1647 | - wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); |
|
| 1648 | - wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); |
|
| 1649 | - } |
|
| 1650 | - } |
|
| 1651 | - |
|
| 1652 | - |
|
| 1653 | - /** |
|
| 1654 | - * admin_footer_global |
|
| 1655 | - * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particular method will apply on |
|
| 1656 | - * ALL EE_Admin Pages. |
|
| 1657 | - * |
|
| 1658 | - * @return void |
|
| 1659 | - * @throws EE_Error |
|
| 1660 | - */ |
|
| 1661 | - public function admin_footer_global() |
|
| 1662 | - { |
|
| 1663 | - // dialog container for dialog helper |
|
| 1664 | - $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n"; |
|
| 1665 | - $d_cont .= '<div class="ee-notices"></div>'; |
|
| 1666 | - $d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>'; |
|
| 1667 | - $d_cont .= '</div>'; |
|
| 1668 | - echo $d_cont; |
|
| 1669 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 1670 | - // help tour stuff? |
|
| 1671 | - // if (isset($this->_help_tour[ $this->_req_action ])) { |
|
| 1672 | - // echo implode('<br />', $this->_help_tour[ $this->_req_action ]); |
|
| 1673 | - // } |
|
| 1674 | - // current set timezone for timezone js |
|
| 1675 | - echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>'; |
|
| 1676 | - } |
|
| 1677 | - |
|
| 1678 | - |
|
| 1679 | - /** |
|
| 1680 | - * This function sees if there is a method for help popup content existing for the given route. If there is then |
|
| 1681 | - * we'll use the retrieved array to output the content using the template. For child classes: If you want to have |
|
| 1682 | - * help popups then in your templates or your content you set "triggers" for the content using the |
|
| 1683 | - * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method |
|
| 1684 | - * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup |
|
| 1685 | - * method for the content in the format "_help_popup_content_{route_name}()" So if you are setting help content |
|
| 1686 | - * for the |
|
| 1687 | - * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined |
|
| 1688 | - * "help_popup_content_..." method. You must prepare and return an array in the following format array( |
|
| 1689 | - * 'help_trigger_id' => array( |
|
| 1690 | - * 'title' => esc_html__('localized title for popup', 'event_espresso'), |
|
| 1691 | - * 'content' => esc_html__('localized content for popup', 'event_espresso') |
|
| 1692 | - * ) |
|
| 1693 | - * ); |
|
| 1694 | - * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route. |
|
| 1695 | - * |
|
| 1696 | - * @param array $help_array |
|
| 1697 | - * @param bool $display |
|
| 1698 | - * @return string content |
|
| 1699 | - * @throws DomainException |
|
| 1700 | - * @throws EE_Error |
|
| 1701 | - */ |
|
| 1702 | - protected function _set_help_popup_content($help_array = array(), $display = false) |
|
| 1703 | - { |
|
| 1704 | - $content = ''; |
|
| 1705 | - $help_array = empty($help_array) ? $this->_get_help_content() : $help_array; |
|
| 1706 | - // loop through the array and setup content |
|
| 1707 | - foreach ($help_array as $trigger => $help) { |
|
| 1708 | - // make sure the array is setup properly |
|
| 1709 | - if (! isset($help['title']) || ! isset($help['content'])) { |
|
| 1710 | - throw new EE_Error( |
|
| 1711 | - esc_html__( |
|
| 1712 | - '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', |
|
| 1713 | - 'event_espresso' |
|
| 1714 | - ) |
|
| 1715 | - ); |
|
| 1716 | - } |
|
| 1717 | - // we're good so let'd setup the template vars and then assign parsed template content to our content. |
|
| 1718 | - $template_args = array( |
|
| 1719 | - 'help_popup_id' => $trigger, |
|
| 1720 | - 'help_popup_title' => $help['title'], |
|
| 1721 | - 'help_popup_content' => $help['content'], |
|
| 1722 | - ); |
|
| 1723 | - $content .= EEH_Template::display_template( |
|
| 1724 | - EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php', |
|
| 1725 | - $template_args, |
|
| 1726 | - true |
|
| 1727 | - ); |
|
| 1728 | - } |
|
| 1729 | - if ($display) { |
|
| 1730 | - echo $content; |
|
| 1731 | - return ''; |
|
| 1732 | - } |
|
| 1733 | - return $content; |
|
| 1734 | - } |
|
| 1735 | - |
|
| 1736 | - |
|
| 1737 | - /** |
|
| 1738 | - * All this does is retrieve the help content array if set by the EE_Admin_Page child |
|
| 1739 | - * |
|
| 1740 | - * @return array properly formatted array for help popup content |
|
| 1741 | - * @throws EE_Error |
|
| 1742 | - */ |
|
| 1743 | - private function _get_help_content() |
|
| 1744 | - { |
|
| 1745 | - // what is the method we're looking for? |
|
| 1746 | - $method_name = '_help_popup_content_' . $this->_req_action; |
|
| 1747 | - // if method doesn't exist let's get out. |
|
| 1748 | - if (! method_exists($this, $method_name)) { |
|
| 1749 | - return array(); |
|
| 1750 | - } |
|
| 1751 | - // k we're good to go let's retrieve the help array |
|
| 1752 | - $help_array = call_user_func(array($this, $method_name)); |
|
| 1753 | - // make sure we've got an array! |
|
| 1754 | - if (! is_array($help_array)) { |
|
| 1755 | - throw new EE_Error( |
|
| 1756 | - esc_html__( |
|
| 1757 | - 'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', |
|
| 1758 | - 'event_espresso' |
|
| 1759 | - ) |
|
| 1760 | - ); |
|
| 1761 | - } |
|
| 1762 | - return $help_array; |
|
| 1763 | - } |
|
| 1764 | - |
|
| 1765 | - |
|
| 1766 | - /** |
|
| 1767 | - * EE Admin Pages can use this to set a properly formatted trigger for a help popup. |
|
| 1768 | - * By default the trigger html is printed. Otherwise it can be returned if the $display flag is set "false" |
|
| 1769 | - * See comments made on the _set_help_content method for understanding other parts to the help popup tool. |
|
| 1770 | - * |
|
| 1771 | - * @param string $trigger_id reference for retrieving the trigger content for the popup |
|
| 1772 | - * @param boolean $display if false then we return the trigger string |
|
| 1773 | - * @param array $dimensions an array of dimensions for the box (array(h,w)) |
|
| 1774 | - * @return string |
|
| 1775 | - * @throws DomainException |
|
| 1776 | - * @throws EE_Error |
|
| 1777 | - */ |
|
| 1778 | - protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640')) |
|
| 1779 | - { |
|
| 1780 | - if (defined('DOING_AJAX')) { |
|
| 1781 | - return ''; |
|
| 1782 | - } |
|
| 1783 | - // 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 |
|
| 1784 | - $help_array = $this->_get_help_content(); |
|
| 1785 | - $help_content = ''; |
|
| 1786 | - if (empty($help_array) || ! isset($help_array[ $trigger_id ])) { |
|
| 1787 | - $help_array[ $trigger_id ] = array( |
|
| 1788 | - 'title' => esc_html__('Missing Content', 'event_espresso'), |
|
| 1789 | - 'content' => esc_html__( |
|
| 1790 | - '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.)', |
|
| 1791 | - 'event_espresso' |
|
| 1792 | - ), |
|
| 1793 | - ); |
|
| 1794 | - $help_content = $this->_set_help_popup_content($help_array, false); |
|
| 1795 | - } |
|
| 1796 | - // let's setup the trigger |
|
| 1797 | - $content = '<a class="ee-dialog" href="?height=' |
|
| 1798 | - . $dimensions[0] |
|
| 1799 | - . '&width=' |
|
| 1800 | - . $dimensions[1] |
|
| 1801 | - . '&inlineId=' |
|
| 1802 | - . $trigger_id |
|
| 1803 | - . '" target="_blank"><span class="question ee-help-popup-question"></span></a>'; |
|
| 1804 | - $content .= $help_content; |
|
| 1805 | - if ($display) { |
|
| 1806 | - echo $content; |
|
| 1807 | - return ''; |
|
| 1808 | - } |
|
| 1809 | - return $content; |
|
| 1810 | - } |
|
| 1811 | - |
|
| 1812 | - |
|
| 1813 | - /** |
|
| 1814 | - * _add_global_screen_options |
|
| 1815 | - * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so. |
|
| 1816 | - * This particular method will add_screen_options on ALL EE_Admin Pages |
|
| 1817 | - * |
|
| 1818 | - * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 1819 | - * see also WP_Screen object documents... |
|
| 1820 | - * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 1821 | - * @abstract |
|
| 1822 | - * @return void |
|
| 1823 | - */ |
|
| 1824 | - private function _add_global_screen_options() |
|
| 1825 | - { |
|
| 1826 | - } |
|
| 1827 | - |
|
| 1828 | - |
|
| 1829 | - /** |
|
| 1830 | - * _add_global_feature_pointers |
|
| 1831 | - * This method is used for implementing any "feature pointers" (using built-in WP styling js). |
|
| 1832 | - * This particular method will implement feature pointers for ALL EE_Admin pages. |
|
| 1833 | - * Note: this is just a placeholder for now. Implementation will come down the road |
|
| 1834 | - * |
|
| 1835 | - * @see WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
| 1836 | - * extended) also see: |
|
| 1837 | - * @link http://eamann.com/tech/wordpress-portland/ |
|
| 1838 | - * @abstract |
|
| 1839 | - * @return void |
|
| 1840 | - */ |
|
| 1841 | - private function _add_global_feature_pointers() |
|
| 1842 | - { |
|
| 1843 | - } |
|
| 1844 | - |
|
| 1845 | - |
|
| 1846 | - /** |
|
| 1847 | - * load_global_scripts_styles |
|
| 1848 | - * The scripts and styles enqueued in here will be loaded on every EE Admin page |
|
| 1849 | - * |
|
| 1850 | - * @return void |
|
| 1851 | - * @throws EE_Error |
|
| 1852 | - */ |
|
| 1853 | - public function load_global_scripts_styles() |
|
| 1854 | - { |
|
| 1855 | - /** STYLES **/ |
|
| 1856 | - // add debugging styles |
|
| 1857 | - if (WP_DEBUG) { |
|
| 1858 | - add_action('admin_head', array($this, 'add_xdebug_style')); |
|
| 1859 | - } |
|
| 1860 | - // register all styles |
|
| 1861 | - wp_register_style( |
|
| 1862 | - 'espresso-ui-theme', |
|
| 1863 | - EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', |
|
| 1864 | - array(), |
|
| 1865 | - EVENT_ESPRESSO_VERSION |
|
| 1866 | - ); |
|
| 1867 | - wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1868 | - // helpers styles |
|
| 1869 | - wp_register_style( |
|
| 1870 | - 'ee-text-links', |
|
| 1871 | - EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', |
|
| 1872 | - array(), |
|
| 1873 | - EVENT_ESPRESSO_VERSION |
|
| 1874 | - ); |
|
| 1875 | - /** SCRIPTS **/ |
|
| 1876 | - // register all scripts |
|
| 1877 | - wp_register_script( |
|
| 1878 | - 'ee-dialog', |
|
| 1879 | - EE_ADMIN_URL . 'assets/ee-dialog-helper.js', |
|
| 1880 | - array('jquery', 'jquery-ui-draggable'), |
|
| 1881 | - EVENT_ESPRESSO_VERSION, |
|
| 1882 | - true |
|
| 1883 | - ); |
|
| 1884 | - wp_register_script( |
|
| 1885 | - 'ee_admin_js', |
|
| 1886 | - EE_ADMIN_URL . 'assets/ee-admin-page.js', |
|
| 1887 | - array('espresso_core', 'ee-parse-uri', 'ee-dialog'), |
|
| 1888 | - EVENT_ESPRESSO_VERSION, |
|
| 1889 | - true |
|
| 1890 | - ); |
|
| 1891 | - wp_register_script( |
|
| 1892 | - 'jquery-ui-timepicker-addon', |
|
| 1893 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', |
|
| 1894 | - array('jquery-ui-datepicker', 'jquery-ui-slider'), |
|
| 1895 | - EVENT_ESPRESSO_VERSION, |
|
| 1896 | - true |
|
| 1897 | - ); |
|
| 1898 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 1899 | - // if (EE_Registry::instance()->CFG->admin->help_tour_activation) { |
|
| 1900 | - // add_filter('FHEE_load_joyride', '__return_true'); |
|
| 1901 | - // } |
|
| 1902 | - // script for sorting tables |
|
| 1903 | - wp_register_script( |
|
| 1904 | - 'espresso_ajax_table_sorting', |
|
| 1905 | - EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js', |
|
| 1906 | - array('ee_admin_js', 'jquery-ui-sortable'), |
|
| 1907 | - EVENT_ESPRESSO_VERSION, |
|
| 1908 | - true |
|
| 1909 | - ); |
|
| 1910 | - // script for parsing uri's |
|
| 1911 | - wp_register_script( |
|
| 1912 | - 'ee-parse-uri', |
|
| 1913 | - EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', |
|
| 1914 | - array(), |
|
| 1915 | - EVENT_ESPRESSO_VERSION, |
|
| 1916 | - true |
|
| 1917 | - ); |
|
| 1918 | - // and parsing associative serialized form elements |
|
| 1919 | - wp_register_script( |
|
| 1920 | - 'ee-serialize-full-array', |
|
| 1921 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', |
|
| 1922 | - array('jquery'), |
|
| 1923 | - EVENT_ESPRESSO_VERSION, |
|
| 1924 | - true |
|
| 1925 | - ); |
|
| 1926 | - // helpers scripts |
|
| 1927 | - wp_register_script( |
|
| 1928 | - 'ee-text-links', |
|
| 1929 | - EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', |
|
| 1930 | - array('jquery'), |
|
| 1931 | - EVENT_ESPRESSO_VERSION, |
|
| 1932 | - true |
|
| 1933 | - ); |
|
| 1934 | - wp_register_script( |
|
| 1935 | - 'ee-moment-core', |
|
| 1936 | - EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', |
|
| 1937 | - array(), |
|
| 1938 | - EVENT_ESPRESSO_VERSION, |
|
| 1939 | - true |
|
| 1940 | - ); |
|
| 1941 | - wp_register_script( |
|
| 1942 | - 'ee-moment', |
|
| 1943 | - EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', |
|
| 1944 | - array('ee-moment-core'), |
|
| 1945 | - EVENT_ESPRESSO_VERSION, |
|
| 1946 | - true |
|
| 1947 | - ); |
|
| 1948 | - wp_register_script( |
|
| 1949 | - 'ee-datepicker', |
|
| 1950 | - EE_ADMIN_URL . 'assets/ee-datepicker.js', |
|
| 1951 | - array('jquery-ui-timepicker-addon', 'ee-moment'), |
|
| 1952 | - EVENT_ESPRESSO_VERSION, |
|
| 1953 | - true |
|
| 1954 | - ); |
|
| 1955 | - // google charts |
|
| 1956 | - wp_register_script( |
|
| 1957 | - 'google-charts', |
|
| 1958 | - 'https://www.gstatic.com/charts/loader.js', |
|
| 1959 | - array(), |
|
| 1960 | - EVENT_ESPRESSO_VERSION, |
|
| 1961 | - false |
|
| 1962 | - ); |
|
| 1963 | - // ENQUEUE ALL BASICS BY DEFAULT |
|
| 1964 | - wp_enqueue_style('ee-admin-css'); |
|
| 1965 | - wp_enqueue_script('ee_admin_js'); |
|
| 1966 | - wp_enqueue_script('ee-accounting'); |
|
| 1967 | - wp_enqueue_script('jquery-validate'); |
|
| 1968 | - // taking care of metaboxes |
|
| 1969 | - if (empty($this->_cpt_route) |
|
| 1970 | - && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes'])) |
|
| 1971 | - ) { |
|
| 1972 | - wp_enqueue_script('dashboard'); |
|
| 1973 | - } |
|
| 1974 | - // LOCALIZED DATA |
|
| 1975 | - // localize script for ajax lazy loading |
|
| 1976 | - $lazy_loader_container_ids = apply_filters( |
|
| 1977 | - 'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', |
|
| 1978 | - array('espresso_news_post_box_content') |
|
| 1979 | - ); |
|
| 1980 | - wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids); |
|
| 1981 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 1982 | - // /** |
|
| 1983 | - // * help tour stuff |
|
| 1984 | - // */ |
|
| 1985 | - // if (! empty($this->_help_tour)) { |
|
| 1986 | - // // register the js for kicking things off |
|
| 1987 | - // wp_enqueue_script( |
|
| 1988 | - // 'ee-help-tour', |
|
| 1989 | - // EE_ADMIN_URL . 'assets/ee-help-tour.js', |
|
| 1990 | - // array('jquery-joyride'), |
|
| 1991 | - // EVENT_ESPRESSO_VERSION, |
|
| 1992 | - // true |
|
| 1993 | - // ); |
|
| 1994 | - // $tours = array(); |
|
| 1995 | - // // setup tours for the js tour object |
|
| 1996 | - // foreach ($this->_help_tour['tours'] as $tour) { |
|
| 1997 | - // if ($tour instanceof EE_Help_Tour) { |
|
| 1998 | - // $tours[] = array( |
|
| 1999 | - // 'id' => $tour->get_slug(), |
|
| 2000 | - // 'options' => $tour->get_options(), |
|
| 2001 | - // ); |
|
| 2002 | - // } |
|
| 2003 | - // } |
|
| 2004 | - // wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours)); |
|
| 2005 | - // // admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour |
|
| 2006 | - // } |
|
| 2007 | - } |
|
| 2008 | - |
|
| 2009 | - |
|
| 2010 | - /** |
|
| 2011 | - * admin_footer_scripts_eei18n_js_strings |
|
| 2012 | - * |
|
| 2013 | - * @return void |
|
| 2014 | - */ |
|
| 2015 | - public function admin_footer_scripts_eei18n_js_strings() |
|
| 2016 | - { |
|
| 2017 | - EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL; |
|
| 2018 | - EE_Registry::$i18n_js_strings['confirm_delete'] = esc_html__( |
|
| 2019 | - '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!!!', |
|
| 2020 | - 'event_espresso' |
|
| 2021 | - ); |
|
| 2022 | - EE_Registry::$i18n_js_strings['January'] = esc_html__('January', 'event_espresso'); |
|
| 2023 | - EE_Registry::$i18n_js_strings['February'] = esc_html__('February', 'event_espresso'); |
|
| 2024 | - EE_Registry::$i18n_js_strings['March'] = esc_html__('March', 'event_espresso'); |
|
| 2025 | - EE_Registry::$i18n_js_strings['April'] = esc_html__('April', 'event_espresso'); |
|
| 2026 | - EE_Registry::$i18n_js_strings['May'] = esc_html__('May', 'event_espresso'); |
|
| 2027 | - EE_Registry::$i18n_js_strings['June'] = esc_html__('June', 'event_espresso'); |
|
| 2028 | - EE_Registry::$i18n_js_strings['July'] = esc_html__('July', 'event_espresso'); |
|
| 2029 | - EE_Registry::$i18n_js_strings['August'] = esc_html__('August', 'event_espresso'); |
|
| 2030 | - EE_Registry::$i18n_js_strings['September'] = esc_html__('September', 'event_espresso'); |
|
| 2031 | - EE_Registry::$i18n_js_strings['October'] = esc_html__('October', 'event_espresso'); |
|
| 2032 | - EE_Registry::$i18n_js_strings['November'] = esc_html__('November', 'event_espresso'); |
|
| 2033 | - EE_Registry::$i18n_js_strings['December'] = esc_html__('December', 'event_espresso'); |
|
| 2034 | - EE_Registry::$i18n_js_strings['Jan'] = esc_html__('Jan', 'event_espresso'); |
|
| 2035 | - EE_Registry::$i18n_js_strings['Feb'] = esc_html__('Feb', 'event_espresso'); |
|
| 2036 | - EE_Registry::$i18n_js_strings['Mar'] = esc_html__('Mar', 'event_espresso'); |
|
| 2037 | - EE_Registry::$i18n_js_strings['Apr'] = esc_html__('Apr', 'event_espresso'); |
|
| 2038 | - EE_Registry::$i18n_js_strings['May'] = esc_html__('May', 'event_espresso'); |
|
| 2039 | - EE_Registry::$i18n_js_strings['Jun'] = esc_html__('Jun', 'event_espresso'); |
|
| 2040 | - EE_Registry::$i18n_js_strings['Jul'] = esc_html__('Jul', 'event_espresso'); |
|
| 2041 | - EE_Registry::$i18n_js_strings['Aug'] = esc_html__('Aug', 'event_espresso'); |
|
| 2042 | - EE_Registry::$i18n_js_strings['Sep'] = esc_html__('Sep', 'event_espresso'); |
|
| 2043 | - EE_Registry::$i18n_js_strings['Oct'] = esc_html__('Oct', 'event_espresso'); |
|
| 2044 | - EE_Registry::$i18n_js_strings['Nov'] = esc_html__('Nov', 'event_espresso'); |
|
| 2045 | - EE_Registry::$i18n_js_strings['Dec'] = esc_html__('Dec', 'event_espresso'); |
|
| 2046 | - EE_Registry::$i18n_js_strings['Sunday'] = esc_html__('Sunday', 'event_espresso'); |
|
| 2047 | - EE_Registry::$i18n_js_strings['Monday'] = esc_html__('Monday', 'event_espresso'); |
|
| 2048 | - EE_Registry::$i18n_js_strings['Tuesday'] = esc_html__('Tuesday', 'event_espresso'); |
|
| 2049 | - EE_Registry::$i18n_js_strings['Wednesday'] = esc_html__('Wednesday', 'event_espresso'); |
|
| 2050 | - EE_Registry::$i18n_js_strings['Thursday'] = esc_html__('Thursday', 'event_espresso'); |
|
| 2051 | - EE_Registry::$i18n_js_strings['Friday'] = esc_html__('Friday', 'event_espresso'); |
|
| 2052 | - EE_Registry::$i18n_js_strings['Saturday'] = esc_html__('Saturday', 'event_espresso'); |
|
| 2053 | - EE_Registry::$i18n_js_strings['Sun'] = esc_html__('Sun', 'event_espresso'); |
|
| 2054 | - EE_Registry::$i18n_js_strings['Mon'] = esc_html__('Mon', 'event_espresso'); |
|
| 2055 | - EE_Registry::$i18n_js_strings['Tue'] = esc_html__('Tue', 'event_espresso'); |
|
| 2056 | - EE_Registry::$i18n_js_strings['Wed'] = esc_html__('Wed', 'event_espresso'); |
|
| 2057 | - EE_Registry::$i18n_js_strings['Thu'] = esc_html__('Thu', 'event_espresso'); |
|
| 2058 | - EE_Registry::$i18n_js_strings['Fri'] = esc_html__('Fri', 'event_espresso'); |
|
| 2059 | - EE_Registry::$i18n_js_strings['Sat'] = esc_html__('Sat', 'event_espresso'); |
|
| 2060 | - } |
|
| 2061 | - |
|
| 2062 | - |
|
| 2063 | - /** |
|
| 2064 | - * load enhanced xdebug styles for ppl with failing eyesight |
|
| 2065 | - * |
|
| 2066 | - * @return void |
|
| 2067 | - */ |
|
| 2068 | - public function add_xdebug_style() |
|
| 2069 | - { |
|
| 2070 | - echo '<style>.xdebug-error { font-size:1.5em; }</style>'; |
|
| 2071 | - } |
|
| 2072 | - |
|
| 2073 | - |
|
| 2074 | - /************************/ |
|
| 2075 | - /** LIST TABLE METHODS **/ |
|
| 2076 | - /************************/ |
|
| 2077 | - /** |
|
| 2078 | - * this sets up the list table if the current view requires it. |
|
| 2079 | - * |
|
| 2080 | - * @return void |
|
| 2081 | - * @throws EE_Error |
|
| 2082 | - */ |
|
| 2083 | - protected function _set_list_table() |
|
| 2084 | - { |
|
| 2085 | - // first is this a list_table view? |
|
| 2086 | - if (! isset($this->_route_config['list_table'])) { |
|
| 2087 | - return; |
|
| 2088 | - } //not a list_table view so get out. |
|
| 2089 | - // list table functions are per view specific (because some admin pages might have more than one list table!) |
|
| 2090 | - $list_table_view = '_set_list_table_views_' . $this->_req_action; |
|
| 2091 | - if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) { |
|
| 2092 | - // user error msg |
|
| 2093 | - $error_msg = esc_html__( |
|
| 2094 | - 'An error occurred. The requested list table views could not be found.', |
|
| 2095 | - 'event_espresso' |
|
| 2096 | - ); |
|
| 2097 | - // developer error msg |
|
| 2098 | - $error_msg .= '||' |
|
| 2099 | - . sprintf( |
|
| 2100 | - esc_html__( |
|
| 2101 | - '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.', |
|
| 2102 | - 'event_espresso' |
|
| 2103 | - ), |
|
| 2104 | - $this->_req_action, |
|
| 2105 | - $list_table_view |
|
| 2106 | - ); |
|
| 2107 | - throw new EE_Error($error_msg); |
|
| 2108 | - } |
|
| 2109 | - // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally |
|
| 2110 | - $this->_views = apply_filters( |
|
| 2111 | - 'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, |
|
| 2112 | - $this->_views |
|
| 2113 | - ); |
|
| 2114 | - $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views); |
|
| 2115 | - $this->_views = apply_filters('FHEE_list_table_views', $this->_views); |
|
| 2116 | - $this->_set_list_table_view(); |
|
| 2117 | - $this->_set_list_table_object(); |
|
| 2118 | - } |
|
| 2119 | - |
|
| 2120 | - |
|
| 2121 | - /** |
|
| 2122 | - * set current view for List Table |
|
| 2123 | - * |
|
| 2124 | - * @return void |
|
| 2125 | - */ |
|
| 2126 | - protected function _set_list_table_view() |
|
| 2127 | - { |
|
| 2128 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2129 | - // looking at active items or dumpster diving ? |
|
| 2130 | - if (! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) { |
|
| 2131 | - $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all'; |
|
| 2132 | - } else { |
|
| 2133 | - $this->_view = sanitize_key($this->_req_data['status']); |
|
| 2134 | - } |
|
| 2135 | - } |
|
| 2136 | - |
|
| 2137 | - |
|
| 2138 | - /** |
|
| 2139 | - * _set_list_table_object |
|
| 2140 | - * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of. |
|
| 2141 | - * |
|
| 2142 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2143 | - * @throws \InvalidArgumentException |
|
| 2144 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2145 | - * @throws EE_Error |
|
| 2146 | - * @throws InvalidInterfaceException |
|
| 2147 | - */ |
|
| 2148 | - protected function _set_list_table_object() |
|
| 2149 | - { |
|
| 2150 | - if (isset($this->_route_config['list_table'])) { |
|
| 2151 | - if (! class_exists($this->_route_config['list_table'])) { |
|
| 2152 | - throw new EE_Error( |
|
| 2153 | - sprintf( |
|
| 2154 | - esc_html__( |
|
| 2155 | - '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.', |
|
| 2156 | - 'event_espresso' |
|
| 2157 | - ), |
|
| 2158 | - $this->_route_config['list_table'], |
|
| 2159 | - get_class($this) |
|
| 2160 | - ) |
|
| 2161 | - ); |
|
| 2162 | - } |
|
| 2163 | - $this->_list_table_object = $this->loader->getShared( |
|
| 2164 | - $this->_route_config['list_table'], |
|
| 2165 | - array($this) |
|
| 2166 | - ); |
|
| 2167 | - } |
|
| 2168 | - } |
|
| 2169 | - |
|
| 2170 | - |
|
| 2171 | - /** |
|
| 2172 | - * get_list_table_view_RLs - get it? View RL ?? VU-RL??? URL ?? |
|
| 2173 | - * |
|
| 2174 | - * @param array $extra_query_args Optional. An array of extra query args to add to the generated |
|
| 2175 | - * urls. The array should be indexed by the view it is being |
|
| 2176 | - * added to. |
|
| 2177 | - * @return array |
|
| 2178 | - */ |
|
| 2179 | - public function get_list_table_view_RLs($extra_query_args = array()) |
|
| 2180 | - { |
|
| 2181 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2182 | - if (empty($this->_views)) { |
|
| 2183 | - $this->_views = array(); |
|
| 2184 | - } |
|
| 2185 | - // cycle thru views |
|
| 2186 | - foreach ($this->_views as $key => $view) { |
|
| 2187 | - $query_args = array(); |
|
| 2188 | - // check for current view |
|
| 2189 | - $this->_views[ $key ]['class'] = $this->_view === $view['slug'] ? 'current' : ''; |
|
| 2190 | - $query_args['action'] = $this->_req_action; |
|
| 2191 | - $query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 2192 | - $query_args['status'] = $view['slug']; |
|
| 2193 | - // merge any other arguments sent in. |
|
| 2194 | - if (isset($extra_query_args[ $view['slug'] ])) { |
|
| 2195 | - $query_args = array_merge($query_args, $extra_query_args[ $view['slug'] ]); |
|
| 2196 | - } |
|
| 2197 | - $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 2198 | - } |
|
| 2199 | - return $this->_views; |
|
| 2200 | - } |
|
| 2201 | - |
|
| 2202 | - |
|
| 2203 | - /** |
|
| 2204 | - * _entries_per_page_dropdown |
|
| 2205 | - * generates a drop down box for selecting the number of visible rows in an admin page list table |
|
| 2206 | - * |
|
| 2207 | - * @todo : Note: ideally this should be added to the screen options dropdown as that would be consistent with how |
|
| 2208 | - * WP does it. |
|
| 2209 | - * @param int $max_entries total number of rows in the table |
|
| 2210 | - * @return string |
|
| 2211 | - */ |
|
| 2212 | - protected function _entries_per_page_dropdown($max_entries = 0) |
|
| 2213 | - { |
|
| 2214 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2215 | - $values = array(10, 25, 50, 100); |
|
| 2216 | - $per_page = (! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10; |
|
| 2217 | - if ($max_entries) { |
|
| 2218 | - $values[] = $max_entries; |
|
| 2219 | - sort($values); |
|
| 2220 | - } |
|
| 2221 | - $entries_per_page_dropdown = ' |
|
| 104 | + /** |
|
| 105 | + * @var array $_route_config |
|
| 106 | + */ |
|
| 107 | + protected $_route_config; |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out |
|
| 111 | + * actions. |
|
| 112 | + * |
|
| 113 | + * @since 4.6.x |
|
| 114 | + * @var array. |
|
| 115 | + */ |
|
| 116 | + protected $_default_route_query_args; |
|
| 117 | + |
|
| 118 | + // set via request page and action args. |
|
| 119 | + protected $_current_page; |
|
| 120 | + |
|
| 121 | + protected $_current_view; |
|
| 122 | + |
|
| 123 | + protected $_current_page_view_url; |
|
| 124 | + |
|
| 125 | + // sanitized request action (and nonce) |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * @var string $_req_action |
|
| 129 | + */ |
|
| 130 | + protected $_req_action; |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * @var string $_req_nonce |
|
| 134 | + */ |
|
| 135 | + protected $_req_nonce; |
|
| 136 | + |
|
| 137 | + // search related |
|
| 138 | + protected $_search_btn_label; |
|
| 139 | + |
|
| 140 | + protected $_search_box_callback; |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * WP Current Screen object |
|
| 144 | + * |
|
| 145 | + * @var WP_Screen |
|
| 146 | + */ |
|
| 147 | + protected $_current_screen; |
|
| 148 | + |
|
| 149 | + // for holding EE_Admin_Hooks object when needed (set via set_hook_object()) |
|
| 150 | + protected $_hook_obj; |
|
| 151 | + |
|
| 152 | + // for holding incoming request data |
|
| 153 | + protected $_req_data; |
|
| 154 | + |
|
| 155 | + // yes / no array for admin form fields |
|
| 156 | + protected $_yes_no_values = array(); |
|
| 157 | + |
|
| 158 | + // some default things shared by all child classes |
|
| 159 | + protected $_default_espresso_metaboxes; |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * EE_Registry Object |
|
| 163 | + * |
|
| 164 | + * @var EE_Registry |
|
| 165 | + */ |
|
| 166 | + protected $EE = null; |
|
| 167 | + |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * This is just a property that flags whether the given route is a caffeinated route or not. |
|
| 171 | + * |
|
| 172 | + * @var boolean |
|
| 173 | + */ |
|
| 174 | + protected $_is_caf = false; |
|
| 175 | + |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * @Constructor |
|
| 179 | + * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
| 180 | + * @throws EE_Error |
|
| 181 | + * @throws InvalidArgumentException |
|
| 182 | + * @throws ReflectionException |
|
| 183 | + * @throws InvalidDataTypeException |
|
| 184 | + * @throws InvalidInterfaceException |
|
| 185 | + */ |
|
| 186 | + public function __construct($routing = true) |
|
| 187 | + { |
|
| 188 | + $this->loader = LoaderFactory::getLoader(); |
|
| 189 | + if (strpos($this->_get_dir(), 'caffeinated') !== false) { |
|
| 190 | + $this->_is_caf = true; |
|
| 191 | + } |
|
| 192 | + $this->_yes_no_values = array( |
|
| 193 | + array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')), |
|
| 194 | + array('id' => false, 'text' => esc_html__('No', 'event_espresso')), |
|
| 195 | + ); |
|
| 196 | + // set the _req_data property. |
|
| 197 | + $this->_req_data = array_merge($_GET, $_POST); |
|
| 198 | + // routing enabled? |
|
| 199 | + $this->_routing = $routing; |
|
| 200 | + // set initial page props (child method) |
|
| 201 | + $this->_init_page_props(); |
|
| 202 | + // set global defaults |
|
| 203 | + $this->_set_defaults(); |
|
| 204 | + // set early because incoming requests could be ajax related and we need to register those hooks. |
|
| 205 | + $this->_global_ajax_hooks(); |
|
| 206 | + $this->_ajax_hooks(); |
|
| 207 | + // other_page_hooks have to be early too. |
|
| 208 | + $this->_do_other_page_hooks(); |
|
| 209 | + // This just allows us to have extending classes do something specific |
|
| 210 | + // before the parent constructor runs _page_setup(). |
|
| 211 | + if (method_exists($this, '_before_page_setup')) { |
|
| 212 | + $this->_before_page_setup(); |
|
| 213 | + } |
|
| 214 | + // set up page dependencies |
|
| 215 | + $this->_page_setup(); |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + |
|
| 219 | + /** |
|
| 220 | + * _init_page_props |
|
| 221 | + * Child classes use to set at least the following properties: |
|
| 222 | + * $page_slug. |
|
| 223 | + * $page_label. |
|
| 224 | + * |
|
| 225 | + * @abstract |
|
| 226 | + * @return void |
|
| 227 | + */ |
|
| 228 | + abstract protected function _init_page_props(); |
|
| 229 | + |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * _ajax_hooks |
|
| 233 | + * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 234 | + * Note: within the ajax callback methods. |
|
| 235 | + * |
|
| 236 | + * @abstract |
|
| 237 | + * @return void |
|
| 238 | + */ |
|
| 239 | + abstract protected function _ajax_hooks(); |
|
| 240 | + |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * _define_page_props |
|
| 244 | + * child classes define page properties in here. Must include at least: |
|
| 245 | + * $_admin_base_url = base_url for all admin pages |
|
| 246 | + * $_admin_page_title = default admin_page_title for admin pages |
|
| 247 | + * $_labels = array of default labels for various automatically generated elements: |
|
| 248 | + * array( |
|
| 249 | + * 'buttons' => array( |
|
| 250 | + * 'add' => esc_html__('label for add new button'), |
|
| 251 | + * 'edit' => esc_html__('label for edit button'), |
|
| 252 | + * 'delete' => esc_html__('label for delete button') |
|
| 253 | + * ) |
|
| 254 | + * ) |
|
| 255 | + * |
|
| 256 | + * @abstract |
|
| 257 | + * @return void |
|
| 258 | + */ |
|
| 259 | + abstract protected function _define_page_props(); |
|
| 260 | + |
|
| 261 | + |
|
| 262 | + /** |
|
| 263 | + * _set_page_routes |
|
| 264 | + * child classes use this to define the page routes for all subpages handled by the class. Page routes are |
|
| 265 | + * assigned to a action => method pairs in an array and to the $_page_routes property. Each page route must also |
|
| 266 | + * have a 'default' route. Here's the format |
|
| 267 | + * $this->_page_routes = array( |
|
| 268 | + * 'default' => array( |
|
| 269 | + * 'func' => '_default_method_handling_route', |
|
| 270 | + * 'args' => array('array','of','args'), |
|
| 271 | + * 'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. |
|
| 272 | + * ajax request, backend processing) |
|
| 273 | + * 'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a |
|
| 274 | + * headers route after. The string you enter here should match the defined route reference for a |
|
| 275 | + * headers sent route. |
|
| 276 | + * 'capability' => 'route_capability', //indicate a string for minimum capability required to access |
|
| 277 | + * this route. |
|
| 278 | + * 'obj_id' => 10 // if this route has an object id, then this can include it (used for capability |
|
| 279 | + * checks). |
|
| 280 | + * ), |
|
| 281 | + * 'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a |
|
| 282 | + * handling method. |
|
| 283 | + * ) |
|
| 284 | + * ) |
|
| 285 | + * |
|
| 286 | + * @abstract |
|
| 287 | + * @return void |
|
| 288 | + */ |
|
| 289 | + abstract protected function _set_page_routes(); |
|
| 290 | + |
|
| 291 | + |
|
| 292 | + /** |
|
| 293 | + * _set_page_config |
|
| 294 | + * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the |
|
| 295 | + * array corresponds to the page_route for the loaded page. Format: |
|
| 296 | + * $this->_page_config = array( |
|
| 297 | + * 'default' => array( |
|
| 298 | + * 'labels' => array( |
|
| 299 | + * 'buttons' => array( |
|
| 300 | + * 'add' => esc_html__('label for adding item'), |
|
| 301 | + * 'edit' => esc_html__('label for editing item'), |
|
| 302 | + * 'delete' => esc_html__('label for deleting item') |
|
| 303 | + * ), |
|
| 304 | + * 'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso') |
|
| 305 | + * ), //optional an array of custom labels for various automatically generated elements to use on the |
|
| 306 | + * page. If this isn't present then the defaults will be used as set for the $this->_labels in |
|
| 307 | + * _define_page_props() method |
|
| 308 | + * 'nav' => array( |
|
| 309 | + * 'label' => esc_html__('Label for Tab', 'event_espresso'). |
|
| 310 | + * 'url' => 'http://someurl', //automatically generated UNLESS you define |
|
| 311 | + * 'css_class' => 'css-class', //automatically generated UNLESS you define |
|
| 312 | + * 'order' => 10, //required to indicate tab position. |
|
| 313 | + * 'persistent' => false //if you want the nav tab to ONLY display when the specific route is |
|
| 314 | + * displayed then add this parameter. |
|
| 315 | + * 'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page. |
|
| 316 | + * 'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load |
|
| 317 | + * metaboxes set for eventespresso admin pages. |
|
| 318 | + * 'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have |
|
| 319 | + * metaboxes. Typically this is used if the 'metaboxes' index is not used because metaboxes are added |
|
| 320 | + * later. We just use this flag to make sure the necessary js gets enqueued on page load. |
|
| 321 | + * 'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the |
|
| 322 | + * given route has help popups setup and if it does then we need to make sure thickbox is enqueued. |
|
| 323 | + * 'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes). The |
|
| 324 | + * array indicates the max number of columns (4) and the default number of columns on page load (2). |
|
| 325 | + * There is an option in the "screen_options" dropdown that is setup so users can pick what columns they |
|
| 326 | + * want to display. |
|
| 327 | + * 'help_tabs' => array( //this is used for adding help tabs to a page |
|
| 328 | + * 'tab_id' => array( |
|
| 329 | + * 'title' => 'tab_title', |
|
| 330 | + * 'filename' => 'name_of_file_containing_content', //this is the primary method for setting |
|
| 331 | + * help tab content. The fallback if it isn't present is to try a the callback. Filename |
|
| 332 | + * should match a file in the admin folder's "help_tabs" dir (ie.. |
|
| 333 | + * events/help_tabs/name_of_file_containing_content.help_tab.php) |
|
| 334 | + * 'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will |
|
| 335 | + * attempt to use the callback which should match the name of a method in the class |
|
| 336 | + * ), |
|
| 337 | + * 'tab2_id' => array( |
|
| 338 | + * 'title' => 'tab2 title', |
|
| 339 | + * 'filename' => 'file_name_2' |
|
| 340 | + * 'callback' => 'callback_method_for_content', |
|
| 341 | + * ), |
|
| 342 | + * 'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the |
|
| 343 | + * help tab area on an admin page. @link |
|
| 344 | + * http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/ |
|
| 345 | + * 'help_tour' => array( |
|
| 346 | + * 'name_of_help_tour_class', //all help tours shoudl be a child class of EE_Help_Tour and located |
|
| 347 | + * in a folder for this admin page named "help_tours", a file name matching the key given here |
|
| 348 | + * (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class) |
|
| 349 | + * ), |
|
| 350 | + * 'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default is |
|
| 351 | + * true if it isn't present). To remove the requirement for a nonce check when this route is visited |
|
| 352 | + * just set |
|
| 353 | + * 'require_nonce' to FALSE |
|
| 354 | + * ) |
|
| 355 | + * ) |
|
| 356 | + * |
|
| 357 | + * @abstract |
|
| 358 | + * @return void |
|
| 359 | + */ |
|
| 360 | + abstract protected function _set_page_config(); |
|
| 361 | + |
|
| 362 | + |
|
| 363 | + |
|
| 364 | + |
|
| 365 | + |
|
| 366 | + /** end sample help_tour methods **/ |
|
| 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', array($this, 'ajax_metabox_content'), 10); |
|
| 466 | + } |
|
| 467 | + |
|
| 468 | + |
|
| 469 | + public function ajax_metabox_content() |
|
| 470 | + { |
|
| 471 | + $contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : ''; |
|
| 472 | + $url = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : ''; |
|
| 473 | + self::cached_rss_display($contentid, $url); |
|
| 474 | + wp_die(); |
|
| 475 | + } |
|
| 476 | + |
|
| 477 | + |
|
| 478 | + /** |
|
| 479 | + * _page_setup |
|
| 480 | + * Makes sure any things that need to be loaded early get handled. We also escape early here if the page requested |
|
| 481 | + * doesn't match the object. |
|
| 482 | + * |
|
| 483 | + * @final |
|
| 484 | + * @return void |
|
| 485 | + * @throws EE_Error |
|
| 486 | + * @throws InvalidArgumentException |
|
| 487 | + * @throws ReflectionException |
|
| 488 | + * @throws InvalidDataTypeException |
|
| 489 | + * @throws InvalidInterfaceException |
|
| 490 | + */ |
|
| 491 | + final protected function _page_setup() |
|
| 492 | + { |
|
| 493 | + // requires? |
|
| 494 | + // admin_init stuff - global - we're setting this REALLY early so if EE_Admin pages have to hook into other WP pages they can. But keep in mind, not everything is available from the EE_Admin Page object at this point. |
|
| 495 | + add_action('admin_init', array($this, 'admin_init_global'), 5); |
|
| 496 | + // next verify if we need to load anything... |
|
| 497 | + $this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : ''; |
|
| 498 | + $this->page_folder = strtolower( |
|
| 499 | + str_replace(array('_Admin_Page', 'Extend_'), '', get_class($this)) |
|
| 500 | + ); |
|
| 501 | + global $ee_menu_slugs; |
|
| 502 | + $ee_menu_slugs = (array) $ee_menu_slugs; |
|
| 503 | + if (! defined('DOING_AJAX') && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ]))) { |
|
| 504 | + return; |
|
| 505 | + } |
|
| 506 | + // becuz WP List tables have two duplicate select inputs for choosing bulk actions, we need to copy the action from the second to the first |
|
| 507 | + if (isset($this->_req_data['action2']) && $this->_req_data['action'] === '-1') { |
|
| 508 | + $this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] !== '-1' |
|
| 509 | + ? $this->_req_data['action2'] |
|
| 510 | + : $this->_req_data['action']; |
|
| 511 | + } |
|
| 512 | + // then set blank or -1 action values to 'default' |
|
| 513 | + $this->_req_action = isset($this->_req_data['action']) |
|
| 514 | + && ! empty($this->_req_data['action']) |
|
| 515 | + && $this->_req_data['action'] !== '-1' |
|
| 516 | + ? sanitize_key($this->_req_data['action']) |
|
| 517 | + : 'default'; |
|
| 518 | + // if action is 'default' after the above BUT we have 'route' var set, then let's use the route as the action. |
|
| 519 | + // This covers cases where we're coming in from a list table that isn't on the default route. |
|
| 520 | + $this->_req_action = $this->_req_action === 'default' && isset($this->_req_data['route']) |
|
| 521 | + ? $this->_req_data['route'] : $this->_req_action; |
|
| 522 | + // however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be |
|
| 523 | + $this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route']) |
|
| 524 | + ? $this->_req_data['route'] |
|
| 525 | + : $this->_req_action; |
|
| 526 | + $this->_current_view = $this->_req_action; |
|
| 527 | + $this->_req_nonce = $this->_req_action . '_nonce'; |
|
| 528 | + $this->_define_page_props(); |
|
| 529 | + $this->_current_page_view_url = add_query_arg( |
|
| 530 | + array('page' => $this->_current_page, 'action' => $this->_current_view), |
|
| 531 | + $this->_admin_base_url |
|
| 532 | + ); |
|
| 533 | + // default things |
|
| 534 | + $this->_default_espresso_metaboxes = array( |
|
| 535 | + '_espresso_news_post_box', |
|
| 536 | + '_espresso_links_post_box', |
|
| 537 | + '_espresso_ratings_request', |
|
| 538 | + '_espresso_sponsors_post_box', |
|
| 539 | + ); |
|
| 540 | + // set page configs |
|
| 541 | + $this->_set_page_routes(); |
|
| 542 | + $this->_set_page_config(); |
|
| 543 | + // let's include any referrer data in our default_query_args for this route for "stickiness". |
|
| 544 | + if (isset($this->_req_data['wp_referer'])) { |
|
| 545 | + $this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer']; |
|
| 546 | + } |
|
| 547 | + // for caffeinated and other extended functionality. |
|
| 548 | + // If there is a _extend_page_config method |
|
| 549 | + // then let's run that to modify the all the various page configuration arrays |
|
| 550 | + if (method_exists($this, '_extend_page_config')) { |
|
| 551 | + $this->_extend_page_config(); |
|
| 552 | + } |
|
| 553 | + // for CPT and other extended functionality. |
|
| 554 | + // If there is an _extend_page_config_for_cpt |
|
| 555 | + // then let's run that to modify all the various page configuration arrays. |
|
| 556 | + if (method_exists($this, '_extend_page_config_for_cpt')) { |
|
| 557 | + $this->_extend_page_config_for_cpt(); |
|
| 558 | + } |
|
| 559 | + // filter routes and page_config so addons can add their stuff. Filtering done per class |
|
| 560 | + $this->_page_routes = apply_filters( |
|
| 561 | + 'FHEE__' . get_class($this) . '__page_setup__page_routes', |
|
| 562 | + $this->_page_routes, |
|
| 563 | + $this |
|
| 564 | + ); |
|
| 565 | + $this->_page_config = apply_filters( |
|
| 566 | + 'FHEE__' . get_class($this) . '__page_setup__page_config', |
|
| 567 | + $this->_page_config, |
|
| 568 | + $this |
|
| 569 | + ); |
|
| 570 | + // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present |
|
| 571 | + // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action |
|
| 572 | + if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) { |
|
| 573 | + add_action( |
|
| 574 | + 'AHEE__EE_Admin_Page__route_admin_request', |
|
| 575 | + array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view), |
|
| 576 | + 10, |
|
| 577 | + 2 |
|
| 578 | + ); |
|
| 579 | + } |
|
| 580 | + // next route only if routing enabled |
|
| 581 | + if ($this->_routing && ! defined('DOING_AJAX')) { |
|
| 582 | + $this->_verify_routes(); |
|
| 583 | + // next let's just check user_access and kill if no access |
|
| 584 | + $this->check_user_access(); |
|
| 585 | + if ($this->_is_UI_request) { |
|
| 586 | + // admin_init stuff - global, all views for this page class, specific view |
|
| 587 | + add_action('admin_init', array($this, 'admin_init'), 10); |
|
| 588 | + if (method_exists($this, 'admin_init_' . $this->_current_view)) { |
|
| 589 | + add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15); |
|
| 590 | + } |
|
| 591 | + } else { |
|
| 592 | + // hijack regular WP loading and route admin request immediately |
|
| 593 | + @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT)); |
|
| 594 | + $this->route_admin_request(); |
|
| 595 | + } |
|
| 596 | + } |
|
| 597 | + } |
|
| 598 | + |
|
| 599 | + |
|
| 600 | + /** |
|
| 601 | + * Provides a way for related child admin pages to load stuff on the loaded admin page. |
|
| 602 | + * |
|
| 603 | + * @return void |
|
| 604 | + * @throws ReflectionException |
|
| 605 | + * @throws EE_Error |
|
| 606 | + */ |
|
| 607 | + private function _do_other_page_hooks() |
|
| 608 | + { |
|
| 609 | + $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array()); |
|
| 610 | + foreach ($registered_pages as $page) { |
|
| 611 | + // now let's setup the file name and class that should be present |
|
| 612 | + $classname = str_replace('.class.php', '', $page); |
|
| 613 | + // autoloaders should take care of loading file |
|
| 614 | + if (! class_exists($classname)) { |
|
| 615 | + $error_msg[] = sprintf( |
|
| 616 | + esc_html__( |
|
| 617 | + 'Something went wrong with loading the %s admin hooks page.', |
|
| 618 | + 'event_espresso' |
|
| 619 | + ), |
|
| 620 | + $page |
|
| 621 | + ); |
|
| 622 | + $error_msg[] = $error_msg[0] |
|
| 623 | + . "\r\n" |
|
| 624 | + . sprintf( |
|
| 625 | + esc_html__( |
|
| 626 | + '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', |
|
| 627 | + 'event_espresso' |
|
| 628 | + ), |
|
| 629 | + $page, |
|
| 630 | + '<br />', |
|
| 631 | + '<strong>' . $classname . '</strong>' |
|
| 632 | + ); |
|
| 633 | + throw new EE_Error(implode('||', $error_msg)); |
|
| 634 | + } |
|
| 635 | + $a = new ReflectionClass($classname); |
|
| 636 | + // notice we are passing the instance of this class to the hook object. |
|
| 637 | + $hookobj[] = $a->newInstance($this); |
|
| 638 | + } |
|
| 639 | + } |
|
| 640 | + |
|
| 641 | + |
|
| 642 | + public function load_page_dependencies() |
|
| 643 | + { |
|
| 644 | + try { |
|
| 645 | + $this->_load_page_dependencies(); |
|
| 646 | + } catch (EE_Error $e) { |
|
| 647 | + $e->get_error(); |
|
| 648 | + } |
|
| 649 | + } |
|
| 650 | + |
|
| 651 | + |
|
| 652 | + /** |
|
| 653 | + * load_page_dependencies |
|
| 654 | + * loads things specific to this page class when its loaded. Really helps with efficiency. |
|
| 655 | + * |
|
| 656 | + * @return void |
|
| 657 | + * @throws DomainException |
|
| 658 | + * @throws EE_Error |
|
| 659 | + * @throws InvalidArgumentException |
|
| 660 | + * @throws InvalidDataTypeException |
|
| 661 | + * @throws InvalidInterfaceException |
|
| 662 | + * @throws ReflectionException |
|
| 663 | + */ |
|
| 664 | + protected function _load_page_dependencies() |
|
| 665 | + { |
|
| 666 | + // let's set the current_screen and screen options to override what WP set |
|
| 667 | + $this->_current_screen = get_current_screen(); |
|
| 668 | + // load admin_notices - global, page class, and view specific |
|
| 669 | + add_action('admin_notices', array($this, 'admin_notices_global'), 5); |
|
| 670 | + add_action('admin_notices', array($this, 'admin_notices'), 10); |
|
| 671 | + if (method_exists($this, 'admin_notices_' . $this->_current_view)) { |
|
| 672 | + add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15); |
|
| 673 | + } |
|
| 674 | + // load network admin_notices - global, page class, and view specific |
|
| 675 | + add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5); |
|
| 676 | + if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) { |
|
| 677 | + add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view)); |
|
| 678 | + } |
|
| 679 | + // this will save any per_page screen options if they are present |
|
| 680 | + $this->_set_per_page_screen_options(); |
|
| 681 | + // setup list table properties |
|
| 682 | + $this->_set_list_table(); |
|
| 683 | + // child classes can "register" a metabox to be automatically handled via the _page_config array property. |
|
| 684 | + // However in some cases the metaboxes will need to be added within a route handling callback. |
|
| 685 | + $this->_add_registered_meta_boxes(); |
|
| 686 | + $this->_add_screen_columns(); |
|
| 687 | + // add screen options - global, page child class, and view specific |
|
| 688 | + $this->_add_global_screen_options(); |
|
| 689 | + $this->_add_screen_options(); |
|
| 690 | + $add_screen_options = "_add_screen_options_{$this->_current_view}"; |
|
| 691 | + if (method_exists($this, $add_screen_options)) { |
|
| 692 | + $this->{$add_screen_options}(); |
|
| 693 | + } |
|
| 694 | + // add help tab(s) and tours- set via page_config and qtips. |
|
| 695 | + // $this->_add_help_tour(); |
|
| 696 | + $this->_add_help_tabs(); |
|
| 697 | + $this->_add_qtips(); |
|
| 698 | + // add feature_pointers - global, page child class, and view specific |
|
| 699 | + $this->_add_feature_pointers(); |
|
| 700 | + $this->_add_global_feature_pointers(); |
|
| 701 | + $add_feature_pointer = "_add_feature_pointer_{$this->_current_view}"; |
|
| 702 | + if (method_exists($this, $add_feature_pointer)) { |
|
| 703 | + $this->{$add_feature_pointer}(); |
|
| 704 | + } |
|
| 705 | + // enqueue scripts/styles - global, page class, and view specific |
|
| 706 | + add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5); |
|
| 707 | + add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10); |
|
| 708 | + if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) { |
|
| 709 | + add_action('admin_enqueue_scripts', array($this, "load_scripts_styles_{$this->_current_view}"), 15); |
|
| 710 | + } |
|
| 711 | + add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100); |
|
| 712 | + // admin_print_footer_scripts - global, page child class, and view specific. |
|
| 713 | + // NOTE, despite the name, whenever possible, scripts should NOT be loaded using this. |
|
| 714 | + // In most cases that's doing_it_wrong(). But adding hidden container elements etc. |
|
| 715 | + // is a good use case. Notice the late priority we're giving these |
|
| 716 | + add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99); |
|
| 717 | + add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100); |
|
| 718 | + if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) { |
|
| 719 | + add_action('admin_print_footer_scripts', array($this, "admin_footer_scripts_{$this->_current_view}"), 101); |
|
| 720 | + } |
|
| 721 | + // admin footer scripts |
|
| 722 | + add_action('admin_footer', array($this, 'admin_footer_global'), 99); |
|
| 723 | + add_action('admin_footer', array($this, 'admin_footer'), 100); |
|
| 724 | + if (method_exists($this, "admin_footer_{$this->_current_view}")) { |
|
| 725 | + add_action('admin_footer', array($this, "admin_footer_{$this->_current_view}"), 101); |
|
| 726 | + } |
|
| 727 | + do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug); |
|
| 728 | + // targeted hook |
|
| 729 | + do_action( |
|
| 730 | + "FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}" |
|
| 731 | + ); |
|
| 732 | + } |
|
| 733 | + |
|
| 734 | + |
|
| 735 | + /** |
|
| 736 | + * _set_defaults |
|
| 737 | + * This sets some global defaults for class properties. |
|
| 738 | + */ |
|
| 739 | + private function _set_defaults() |
|
| 740 | + { |
|
| 741 | + $this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null; |
|
| 742 | + $this->_event = $this->_template_path = $this->_column_template_path = null; |
|
| 743 | + $this->_nav_tabs = $this->_views = $this->_page_routes = array(); |
|
| 744 | + $this->_page_config = $this->_default_route_query_args = array(); |
|
| 745 | + $this->_default_nav_tab_name = 'overview'; |
|
| 746 | + // init template args |
|
| 747 | + $this->_template_args = array( |
|
| 748 | + 'admin_page_header' => '', |
|
| 749 | + 'admin_page_content' => '', |
|
| 750 | + 'post_body_content' => '', |
|
| 751 | + 'before_list_table' => '', |
|
| 752 | + 'after_list_table' => '', |
|
| 753 | + ); |
|
| 754 | + } |
|
| 755 | + |
|
| 756 | + |
|
| 757 | + /** |
|
| 758 | + * route_admin_request |
|
| 759 | + * |
|
| 760 | + * @see _route_admin_request() |
|
| 761 | + * @return exception|void error |
|
| 762 | + * @throws InvalidArgumentException |
|
| 763 | + * @throws InvalidInterfaceException |
|
| 764 | + * @throws InvalidDataTypeException |
|
| 765 | + * @throws EE_Error |
|
| 766 | + * @throws ReflectionException |
|
| 767 | + */ |
|
| 768 | + public function route_admin_request() |
|
| 769 | + { |
|
| 770 | + try { |
|
| 771 | + $this->_route_admin_request(); |
|
| 772 | + } catch (EE_Error $e) { |
|
| 773 | + $e->get_error(); |
|
| 774 | + } |
|
| 775 | + } |
|
| 776 | + |
|
| 777 | + |
|
| 778 | + public function set_wp_page_slug($wp_page_slug) |
|
| 779 | + { |
|
| 780 | + $this->_wp_page_slug = $wp_page_slug; |
|
| 781 | + // if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls... |
|
| 782 | + if (is_network_admin()) { |
|
| 783 | + $this->_wp_page_slug .= '-network'; |
|
| 784 | + } |
|
| 785 | + } |
|
| 786 | + |
|
| 787 | + |
|
| 788 | + /** |
|
| 789 | + * _verify_routes |
|
| 790 | + * All this method does is verify the incoming request and make sure that routes exist for it. We do this early so |
|
| 791 | + * we know if we need to drop out. |
|
| 792 | + * |
|
| 793 | + * @return bool |
|
| 794 | + * @throws EE_Error |
|
| 795 | + */ |
|
| 796 | + protected function _verify_routes() |
|
| 797 | + { |
|
| 798 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 799 | + if (! $this->_current_page && ! defined('DOING_AJAX')) { |
|
| 800 | + return false; |
|
| 801 | + } |
|
| 802 | + $this->_route = false; |
|
| 803 | + // check that the page_routes array is not empty |
|
| 804 | + if (empty($this->_page_routes)) { |
|
| 805 | + // user error msg |
|
| 806 | + $error_msg = sprintf( |
|
| 807 | + esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'), |
|
| 808 | + $this->_admin_page_title |
|
| 809 | + ); |
|
| 810 | + // developer error msg |
|
| 811 | + $error_msg .= '||' . $error_msg |
|
| 812 | + . esc_html__( |
|
| 813 | + ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', |
|
| 814 | + 'event_espresso' |
|
| 815 | + ); |
|
| 816 | + throw new EE_Error($error_msg); |
|
| 817 | + } |
|
| 818 | + // and that the requested page route exists |
|
| 819 | + if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 820 | + $this->_route = $this->_page_routes[ $this->_req_action ]; |
|
| 821 | + $this->_route_config = isset($this->_page_config[ $this->_req_action ]) |
|
| 822 | + ? $this->_page_config[ $this->_req_action ] : array(); |
|
| 823 | + } else { |
|
| 824 | + // user error msg |
|
| 825 | + $error_msg = sprintf( |
|
| 826 | + esc_html__( |
|
| 827 | + 'The requested page route does not exist for the %s admin page.', |
|
| 828 | + 'event_espresso' |
|
| 829 | + ), |
|
| 830 | + $this->_admin_page_title |
|
| 831 | + ); |
|
| 832 | + // developer error msg |
|
| 833 | + $error_msg .= '||' . $error_msg |
|
| 834 | + . sprintf( |
|
| 835 | + esc_html__( |
|
| 836 | + ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', |
|
| 837 | + 'event_espresso' |
|
| 838 | + ), |
|
| 839 | + $this->_req_action |
|
| 840 | + ); |
|
| 841 | + throw new EE_Error($error_msg); |
|
| 842 | + } |
|
| 843 | + // and that a default route exists |
|
| 844 | + if (! array_key_exists('default', $this->_page_routes)) { |
|
| 845 | + // user error msg |
|
| 846 | + $error_msg = sprintf( |
|
| 847 | + esc_html__( |
|
| 848 | + 'A default page route has not been set for the % admin page.', |
|
| 849 | + 'event_espresso' |
|
| 850 | + ), |
|
| 851 | + $this->_admin_page_title |
|
| 852 | + ); |
|
| 853 | + // developer error msg |
|
| 854 | + $error_msg .= '||' . $error_msg |
|
| 855 | + . esc_html__( |
|
| 856 | + ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', |
|
| 857 | + 'event_espresso' |
|
| 858 | + ); |
|
| 859 | + throw new EE_Error($error_msg); |
|
| 860 | + } |
|
| 861 | + // first lets' catch if the UI request has EVER been set. |
|
| 862 | + if ($this->_is_UI_request === null) { |
|
| 863 | + // lets set if this is a UI request or not. |
|
| 864 | + $this->_is_UI_request = ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true; |
|
| 865 | + // wait a minute... we might have a noheader in the route array |
|
| 866 | + $this->_is_UI_request = is_array($this->_route) |
|
| 867 | + && isset($this->_route['noheader']) |
|
| 868 | + && $this->_route['noheader'] ? false : $this->_is_UI_request; |
|
| 869 | + } |
|
| 870 | + $this->_set_current_labels(); |
|
| 871 | + return true; |
|
| 872 | + } |
|
| 873 | + |
|
| 874 | + |
|
| 875 | + /** |
|
| 876 | + * this method simply verifies a given route and makes sure its an actual route available for the loaded page |
|
| 877 | + * |
|
| 878 | + * @param string $route the route name we're verifying |
|
| 879 | + * @return mixed (bool|Exception) we'll throw an exception if this isn't a valid route. |
|
| 880 | + * @throws EE_Error |
|
| 881 | + */ |
|
| 882 | + protected function _verify_route($route) |
|
| 883 | + { |
|
| 884 | + if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 885 | + return true; |
|
| 886 | + } |
|
| 887 | + // user error msg |
|
| 888 | + $error_msg = sprintf( |
|
| 889 | + esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'), |
|
| 890 | + $this->_admin_page_title |
|
| 891 | + ); |
|
| 892 | + // developer error msg |
|
| 893 | + $error_msg .= '||' . $error_msg |
|
| 894 | + . sprintf( |
|
| 895 | + esc_html__( |
|
| 896 | + ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', |
|
| 897 | + 'event_espresso' |
|
| 898 | + ), |
|
| 899 | + $route |
|
| 900 | + ); |
|
| 901 | + throw new EE_Error($error_msg); |
|
| 902 | + } |
|
| 903 | + |
|
| 904 | + |
|
| 905 | + /** |
|
| 906 | + * perform nonce verification |
|
| 907 | + * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces |
|
| 908 | + * using this method (and save retyping!) |
|
| 909 | + * |
|
| 910 | + * @param string $nonce The nonce sent |
|
| 911 | + * @param string $nonce_ref The nonce reference string (name0) |
|
| 912 | + * @return void |
|
| 913 | + * @throws EE_Error |
|
| 914 | + */ |
|
| 915 | + protected function _verify_nonce($nonce, $nonce_ref) |
|
| 916 | + { |
|
| 917 | + // verify nonce against expected value |
|
| 918 | + if (! wp_verify_nonce($nonce, $nonce_ref)) { |
|
| 919 | + // these are not the droids you are looking for !!! |
|
| 920 | + $msg = sprintf( |
|
| 921 | + esc_html__('%sNonce Fail.%s', 'event_espresso'), |
|
| 922 | + '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">', |
|
| 923 | + '</a>' |
|
| 924 | + ); |
|
| 925 | + if (WP_DEBUG) { |
|
| 926 | + $msg .= "\n " |
|
| 927 | + . sprintf( |
|
| 928 | + esc_html__( |
|
| 929 | + 'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', |
|
| 930 | + 'event_espresso' |
|
| 931 | + ), |
|
| 932 | + __CLASS__ |
|
| 933 | + ); |
|
| 934 | + } |
|
| 935 | + if (! defined('DOING_AJAX')) { |
|
| 936 | + wp_die($msg); |
|
| 937 | + } else { |
|
| 938 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 939 | + $this->_return_json(); |
|
| 940 | + } |
|
| 941 | + } |
|
| 942 | + } |
|
| 943 | + |
|
| 944 | + |
|
| 945 | + /** |
|
| 946 | + * _route_admin_request() |
|
| 947 | + * Meat and potatoes of the class. Basically, this dude checks out what's being requested and sees if theres are |
|
| 948 | + * some doodads to work the magic and handle the flingjangy. Translation: Checks if the requested action is listed |
|
| 949 | + * in the page routes and then will try to load the corresponding method. |
|
| 950 | + * |
|
| 951 | + * @return void |
|
| 952 | + * @throws EE_Error |
|
| 953 | + * @throws InvalidArgumentException |
|
| 954 | + * @throws InvalidDataTypeException |
|
| 955 | + * @throws InvalidInterfaceException |
|
| 956 | + * @throws ReflectionException |
|
| 957 | + */ |
|
| 958 | + protected function _route_admin_request() |
|
| 959 | + { |
|
| 960 | + if (! $this->_is_UI_request) { |
|
| 961 | + $this->_verify_routes(); |
|
| 962 | + } |
|
| 963 | + $nonce_check = isset($this->_route_config['require_nonce']) |
|
| 964 | + ? $this->_route_config['require_nonce'] |
|
| 965 | + : true; |
|
| 966 | + if ($this->_req_action !== 'default' && $nonce_check) { |
|
| 967 | + // set nonce from post data |
|
| 968 | + $nonce = isset($this->_req_data[ $this->_req_nonce ]) |
|
| 969 | + ? sanitize_text_field($this->_req_data[ $this->_req_nonce ]) |
|
| 970 | + : ''; |
|
| 971 | + $this->_verify_nonce($nonce, $this->_req_nonce); |
|
| 972 | + } |
|
| 973 | + // set the nav_tabs array but ONLY if this is UI_request |
|
| 974 | + if ($this->_is_UI_request) { |
|
| 975 | + $this->_set_nav_tabs(); |
|
| 976 | + } |
|
| 977 | + // grab callback function |
|
| 978 | + $func = is_array($this->_route) ? $this->_route['func'] : $this->_route; |
|
| 979 | + // check if callback has args |
|
| 980 | + $args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array(); |
|
| 981 | + $error_msg = ''; |
|
| 982 | + // action right before calling route |
|
| 983 | + // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request') |
|
| 984 | + if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
| 985 | + do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this); |
|
| 986 | + } |
|
| 987 | + // right before calling the route, let's remove _wp_http_referer from the |
|
| 988 | + // $_SERVER[REQUEST_URI] global (its now in _req_data for route processing). |
|
| 989 | + $_SERVER['REQUEST_URI'] = remove_query_arg( |
|
| 990 | + '_wp_http_referer', |
|
| 991 | + wp_unslash($_SERVER['REQUEST_URI']) |
|
| 992 | + ); |
|
| 993 | + if (! empty($func)) { |
|
| 994 | + if (is_array($func)) { |
|
| 995 | + list($class, $method) = $func; |
|
| 996 | + } elseif (strpos($func, '::') !== false) { |
|
| 997 | + list($class, $method) = explode('::', $func); |
|
| 998 | + } else { |
|
| 999 | + $class = $this; |
|
| 1000 | + $method = $func; |
|
| 1001 | + } |
|
| 1002 | + if (! (is_object($class) && $class === $this)) { |
|
| 1003 | + // send along this admin page object for access by addons. |
|
| 1004 | + $args['admin_page_object'] = $this; |
|
| 1005 | + } |
|
| 1006 | + if (// is it a method on a class that doesn't work? |
|
| 1007 | + ( |
|
| 1008 | + ( |
|
| 1009 | + method_exists($class, $method) |
|
| 1010 | + && call_user_func_array(array($class, $method), $args) === false |
|
| 1011 | + ) |
|
| 1012 | + && ( |
|
| 1013 | + // is it a standalone function that doesn't work? |
|
| 1014 | + function_exists($method) |
|
| 1015 | + && call_user_func_array( |
|
| 1016 | + $func, |
|
| 1017 | + array_merge(array('admin_page_object' => $this), $args) |
|
| 1018 | + ) === false |
|
| 1019 | + ) |
|
| 1020 | + ) |
|
| 1021 | + || ( |
|
| 1022 | + // is it neither a class method NOR a standalone function? |
|
| 1023 | + ! method_exists($class, $method) |
|
| 1024 | + && ! function_exists($method) |
|
| 1025 | + ) |
|
| 1026 | + ) { |
|
| 1027 | + // user error msg |
|
| 1028 | + $error_msg = esc_html__( |
|
| 1029 | + 'An error occurred. The requested page route could not be found.', |
|
| 1030 | + 'event_espresso' |
|
| 1031 | + ); |
|
| 1032 | + // developer error msg |
|
| 1033 | + $error_msg .= '||'; |
|
| 1034 | + $error_msg .= sprintf( |
|
| 1035 | + esc_html__( |
|
| 1036 | + 'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.', |
|
| 1037 | + 'event_espresso' |
|
| 1038 | + ), |
|
| 1039 | + $method |
|
| 1040 | + ); |
|
| 1041 | + } |
|
| 1042 | + if (! empty($error_msg)) { |
|
| 1043 | + throw new EE_Error($error_msg); |
|
| 1044 | + } |
|
| 1045 | + } |
|
| 1046 | + // if we've routed and this route has a no headers route AND a sent_headers_route, |
|
| 1047 | + // then we need to reset the routing properties to the new route. |
|
| 1048 | + // 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. |
|
| 1049 | + if ($this->_is_UI_request === false |
|
| 1050 | + && is_array($this->_route) |
|
| 1051 | + && ! empty($this->_route['headers_sent_route']) |
|
| 1052 | + ) { |
|
| 1053 | + $this->_reset_routing_properties($this->_route['headers_sent_route']); |
|
| 1054 | + } |
|
| 1055 | + } |
|
| 1056 | + |
|
| 1057 | + |
|
| 1058 | + /** |
|
| 1059 | + * This method just allows the resetting of page properties in the case where a no headers |
|
| 1060 | + * route redirects to a headers route in its route config. |
|
| 1061 | + * |
|
| 1062 | + * @since 4.3.0 |
|
| 1063 | + * @param string $new_route New (non header) route to redirect to. |
|
| 1064 | + * @return void |
|
| 1065 | + * @throws ReflectionException |
|
| 1066 | + * @throws InvalidArgumentException |
|
| 1067 | + * @throws InvalidInterfaceException |
|
| 1068 | + * @throws InvalidDataTypeException |
|
| 1069 | + * @throws EE_Error |
|
| 1070 | + */ |
|
| 1071 | + protected function _reset_routing_properties($new_route) |
|
| 1072 | + { |
|
| 1073 | + $this->_is_UI_request = true; |
|
| 1074 | + // now we set the current route to whatever the headers_sent_route is set at |
|
| 1075 | + $this->_req_data['action'] = $new_route; |
|
| 1076 | + // rerun page setup |
|
| 1077 | + $this->_page_setup(); |
|
| 1078 | + } |
|
| 1079 | + |
|
| 1080 | + |
|
| 1081 | + /** |
|
| 1082 | + * _add_query_arg |
|
| 1083 | + * adds nonce to array of arguments then calls WP add_query_arg function |
|
| 1084 | + *(internally just uses EEH_URL's function with the same name) |
|
| 1085 | + * |
|
| 1086 | + * @param array $args |
|
| 1087 | + * @param string $url |
|
| 1088 | + * @param bool $sticky if true, then the existing Request params will be appended to the |
|
| 1089 | + * generated url in an associative array indexed by the key 'wp_referer'; |
|
| 1090 | + * Example usage: If the current page is: |
|
| 1091 | + * http://mydomain.com/wp-admin/admin.php?page=espresso_registrations |
|
| 1092 | + * &action=default&event_id=20&month_range=March%202015 |
|
| 1093 | + * &_wpnonce=5467821 |
|
| 1094 | + * and you call: |
|
| 1095 | + * EE_Admin_Page::add_query_args_and_nonce( |
|
| 1096 | + * array( |
|
| 1097 | + * 'action' => 'resend_something', |
|
| 1098 | + * 'page=>espresso_registrations' |
|
| 1099 | + * ), |
|
| 1100 | + * $some_url, |
|
| 1101 | + * true |
|
| 1102 | + * ); |
|
| 1103 | + * It will produce a url in this structure: |
|
| 1104 | + * http://{$some_url}/?page=espresso_registrations&action=resend_something |
|
| 1105 | + * &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[ |
|
| 1106 | + * month_range]=March%202015 |
|
| 1107 | + * @param bool $exclude_nonce If true, the the nonce will be excluded from the generated nonce. |
|
| 1108 | + * @return string |
|
| 1109 | + */ |
|
| 1110 | + public static function add_query_args_and_nonce( |
|
| 1111 | + $args = array(), |
|
| 1112 | + $url = false, |
|
| 1113 | + $sticky = false, |
|
| 1114 | + $exclude_nonce = false |
|
| 1115 | + ) { |
|
| 1116 | + // if there is a _wp_http_referer include the values from the request but only if sticky = true |
|
| 1117 | + if ($sticky) { |
|
| 1118 | + $request = $_REQUEST; |
|
| 1119 | + unset($request['_wp_http_referer']); |
|
| 1120 | + unset($request['wp_referer']); |
|
| 1121 | + foreach ($request as $key => $value) { |
|
| 1122 | + // do not add nonces |
|
| 1123 | + if (strpos($key, 'nonce') !== false) { |
|
| 1124 | + continue; |
|
| 1125 | + } |
|
| 1126 | + $args[ 'wp_referer[' . $key . ']' ] = $value; |
|
| 1127 | + } |
|
| 1128 | + } |
|
| 1129 | + return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce); |
|
| 1130 | + } |
|
| 1131 | + |
|
| 1132 | + |
|
| 1133 | + /** |
|
| 1134 | + * This returns a generated link that will load the related help tab. |
|
| 1135 | + * |
|
| 1136 | + * @param string $help_tab_id the id for the connected help tab |
|
| 1137 | + * @param string $icon_style (optional) include css class for the style you want to use for the help icon. |
|
| 1138 | + * @param string $help_text (optional) send help text you want to use for the link if default not to be used |
|
| 1139 | + * @uses EEH_Template::get_help_tab_link() |
|
| 1140 | + * @return string generated link |
|
| 1141 | + */ |
|
| 1142 | + protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '') |
|
| 1143 | + { |
|
| 1144 | + return EEH_Template::get_help_tab_link( |
|
| 1145 | + $help_tab_id, |
|
| 1146 | + $this->page_slug, |
|
| 1147 | + $this->_req_action, |
|
| 1148 | + $icon_style, |
|
| 1149 | + $help_text |
|
| 1150 | + ); |
|
| 1151 | + } |
|
| 1152 | + |
|
| 1153 | + |
|
| 1154 | + /** |
|
| 1155 | + * _add_help_tabs |
|
| 1156 | + * Note child classes define their help tabs within the page_config array. |
|
| 1157 | + * |
|
| 1158 | + * @link http://codex.wordpress.org/Function_Reference/add_help_tab |
|
| 1159 | + * @return void |
|
| 1160 | + * @throws DomainException |
|
| 1161 | + * @throws EE_Error |
|
| 1162 | + */ |
|
| 1163 | + protected function _add_help_tabs() |
|
| 1164 | + { |
|
| 1165 | + $tour_buttons = ''; |
|
| 1166 | + if (isset($this->_page_config[ $this->_req_action ])) { |
|
| 1167 | + $config = $this->_page_config[ $this->_req_action ]; |
|
| 1168 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 1169 | + // is there a help tour for the current route? if there is let's setup the tour buttons |
|
| 1170 | + // if (isset($this->_help_tour[ $this->_req_action ])) { |
|
| 1171 | + // $tb = array(); |
|
| 1172 | + // $tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">'; |
|
| 1173 | + // foreach ($this->_help_tour['tours'] as $tour) { |
|
| 1174 | + // // if this is the end tour then we don't need to setup a button |
|
| 1175 | + // if ($tour instanceof EE_Help_Tour_final_stop || ! $tour instanceof EE_Help_Tour) { |
|
| 1176 | + // continue; |
|
| 1177 | + // } |
|
| 1178 | + // $tb[] = '<button id="trigger-tour-' |
|
| 1179 | + // . $tour->get_slug() |
|
| 1180 | + // . '" class="button-primary trigger-ee-help-tour">' |
|
| 1181 | + // . $tour->get_label() |
|
| 1182 | + // . '</button>'; |
|
| 1183 | + // } |
|
| 1184 | + // $tour_buttons .= implode('<br />', $tb); |
|
| 1185 | + // $tour_buttons .= '</div></div>'; |
|
| 1186 | + // } |
|
| 1187 | + // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well. |
|
| 1188 | + if (is_array($config) && isset($config['help_sidebar'])) { |
|
| 1189 | + // check that the callback given is valid |
|
| 1190 | + if (! method_exists($this, $config['help_sidebar'])) { |
|
| 1191 | + throw new EE_Error( |
|
| 1192 | + sprintf( |
|
| 1193 | + esc_html__( |
|
| 1194 | + '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', |
|
| 1195 | + 'event_espresso' |
|
| 1196 | + ), |
|
| 1197 | + $config['help_sidebar'], |
|
| 1198 | + get_class($this) |
|
| 1199 | + ) |
|
| 1200 | + ); |
|
| 1201 | + } |
|
| 1202 | + $content = apply_filters( |
|
| 1203 | + 'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', |
|
| 1204 | + $this->{$config['help_sidebar']}() |
|
| 1205 | + ); |
|
| 1206 | + $content .= $tour_buttons; // add help tour buttons. |
|
| 1207 | + // do we have any help tours setup? Cause if we do we want to add the buttons |
|
| 1208 | + $this->_current_screen->set_help_sidebar($content); |
|
| 1209 | + } |
|
| 1210 | + // if we DON'T have config help sidebar and there ARE tour buttons then we'll just add the tour buttons to the sidebar. |
|
| 1211 | + if (! isset($config['help_sidebar']) && ! empty($tour_buttons)) { |
|
| 1212 | + $this->_current_screen->set_help_sidebar($tour_buttons); |
|
| 1213 | + } |
|
| 1214 | + // handle if no help_tabs are set so the sidebar will still show for the help tour buttons |
|
| 1215 | + if (! isset($config['help_tabs']) && ! empty($tour_buttons)) { |
|
| 1216 | + $_ht['id'] = $this->page_slug; |
|
| 1217 | + $_ht['title'] = esc_html__('Help Tours', 'event_espresso'); |
|
| 1218 | + $_ht['content'] = '<p>' |
|
| 1219 | + . esc_html__( |
|
| 1220 | + 'The buttons to the right allow you to start/restart any help tours available for this page', |
|
| 1221 | + 'event_espresso' |
|
| 1222 | + ) . '</p>'; |
|
| 1223 | + $this->_current_screen->add_help_tab($_ht); |
|
| 1224 | + } |
|
| 1225 | + if (! isset($config['help_tabs'])) { |
|
| 1226 | + return; |
|
| 1227 | + } //no help tabs for this route |
|
| 1228 | + foreach ((array) $config['help_tabs'] as $tab_id => $cfg) { |
|
| 1229 | + // we're here so there ARE help tabs! |
|
| 1230 | + // make sure we've got what we need |
|
| 1231 | + if (! isset($cfg['title'])) { |
|
| 1232 | + throw new EE_Error( |
|
| 1233 | + esc_html__( |
|
| 1234 | + 'The _page_config array is not set up properly for help tabs. It is missing a title', |
|
| 1235 | + 'event_espresso' |
|
| 1236 | + ) |
|
| 1237 | + ); |
|
| 1238 | + } |
|
| 1239 | + if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
| 1240 | + throw new EE_Error( |
|
| 1241 | + esc_html__( |
|
| 1242 | + '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', |
|
| 1243 | + 'event_espresso' |
|
| 1244 | + ) |
|
| 1245 | + ); |
|
| 1246 | + } |
|
| 1247 | + // first priority goes to content. |
|
| 1248 | + if (! empty($cfg['content'])) { |
|
| 1249 | + $content = ! empty($cfg['content']) ? $cfg['content'] : null; |
|
| 1250 | + // second priority goes to filename |
|
| 1251 | + } elseif (! empty($cfg['filename'])) { |
|
| 1252 | + $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php'; |
|
| 1253 | + // 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) |
|
| 1254 | + $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
|
| 1255 | + . basename($this->_get_dir()) |
|
| 1256 | + . '/help_tabs/' |
|
| 1257 | + . $cfg['filename'] |
|
| 1258 | + . '.help_tab.php' : $file_path; |
|
| 1259 | + // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
| 1260 | + if (! isset($cfg['callback']) && ! is_readable($file_path)) { |
|
| 1261 | + EE_Error::add_error( |
|
| 1262 | + sprintf( |
|
| 1263 | + esc_html__( |
|
| 1264 | + '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', |
|
| 1265 | + 'event_espresso' |
|
| 1266 | + ), |
|
| 1267 | + $tab_id, |
|
| 1268 | + key($config), |
|
| 1269 | + $file_path |
|
| 1270 | + ), |
|
| 1271 | + __FILE__, |
|
| 1272 | + __FUNCTION__, |
|
| 1273 | + __LINE__ |
|
| 1274 | + ); |
|
| 1275 | + return; |
|
| 1276 | + } |
|
| 1277 | + $template_args['admin_page_obj'] = $this; |
|
| 1278 | + $content = EEH_Template::display_template( |
|
| 1279 | + $file_path, |
|
| 1280 | + $template_args, |
|
| 1281 | + true |
|
| 1282 | + ); |
|
| 1283 | + } else { |
|
| 1284 | + $content = ''; |
|
| 1285 | + } |
|
| 1286 | + // check if callback is valid |
|
| 1287 | + if (empty($content) && ( |
|
| 1288 | + ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback']) |
|
| 1289 | + ) |
|
| 1290 | + ) { |
|
| 1291 | + EE_Error::add_error( |
|
| 1292 | + sprintf( |
|
| 1293 | + esc_html__( |
|
| 1294 | + '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.', |
|
| 1295 | + 'event_espresso' |
|
| 1296 | + ), |
|
| 1297 | + $cfg['title'] |
|
| 1298 | + ), |
|
| 1299 | + __FILE__, |
|
| 1300 | + __FUNCTION__, |
|
| 1301 | + __LINE__ |
|
| 1302 | + ); |
|
| 1303 | + return; |
|
| 1304 | + } |
|
| 1305 | + // setup config array for help tab method |
|
| 1306 | + $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id; |
|
| 1307 | + $_ht = array( |
|
| 1308 | + 'id' => $id, |
|
| 1309 | + 'title' => $cfg['title'], |
|
| 1310 | + 'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null, |
|
| 1311 | + 'content' => $content, |
|
| 1312 | + ); |
|
| 1313 | + $this->_current_screen->add_help_tab($_ht); |
|
| 1314 | + } |
|
| 1315 | + } |
|
| 1316 | + } |
|
| 1317 | + |
|
| 1318 | + |
|
| 1319 | + /** |
|
| 1320 | + * This basically checks loaded $_page_config property to see if there are any help_tours defined. "help_tours" is |
|
| 1321 | + * an array with properties for setting up usage of the joyride plugin |
|
| 1322 | + * |
|
| 1323 | + * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin |
|
| 1324 | + * @see instructions regarding the format and construction of the "help_tour" array element is found in the |
|
| 1325 | + * _set_page_config() comments |
|
| 1326 | + * @return void |
|
| 1327 | + * @throws EE_Error |
|
| 1328 | + * @throws InvalidArgumentException |
|
| 1329 | + * @throws InvalidDataTypeException |
|
| 1330 | + * @throws InvalidInterfaceException |
|
| 1331 | + */ |
|
| 1332 | + protected function _add_help_tour() |
|
| 1333 | + { |
|
| 1334 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 1335 | + // $tours = array(); |
|
| 1336 | + // $this->_help_tour = array(); |
|
| 1337 | + // // exit early if help tours are turned off globally |
|
| 1338 | + // if ((defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS) |
|
| 1339 | + // || ! EE_Registry::instance()->CFG->admin->help_tour_activation |
|
| 1340 | + // ) { |
|
| 1341 | + // return; |
|
| 1342 | + // } |
|
| 1343 | + // // loop through _page_config to find any help_tour defined |
|
| 1344 | + // foreach ($this->_page_config as $route => $config) { |
|
| 1345 | + // // we're only going to set things up for this route |
|
| 1346 | + // if ($route !== $this->_req_action) { |
|
| 1347 | + // continue; |
|
| 1348 | + // } |
|
| 1349 | + // if (isset($config['help_tour'])) { |
|
| 1350 | + // foreach ($config['help_tour'] as $tour) { |
|
| 1351 | + // $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php'; |
|
| 1352 | + // // let's see if we can get that file... |
|
| 1353 | + // // if not its possible this is a decaf route not set in caffeinated |
|
| 1354 | + // // so lets try and get the caffeinated equivalent |
|
| 1355 | + // $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
|
| 1356 | + // . basename($this->_get_dir()) |
|
| 1357 | + // . '/help_tours/' |
|
| 1358 | + // . $tour |
|
| 1359 | + // . '.class.php' : $file_path; |
|
| 1360 | + // // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
| 1361 | + // if (! is_readable($file_path)) { |
|
| 1362 | + // EE_Error::add_error( |
|
| 1363 | + // sprintf( |
|
| 1364 | + // esc_html__( |
|
| 1365 | + // 'The file path given for the help tour (%s) is not a valid path. Please check that the string you set for the help tour on this route (%s) is the correct spelling', |
|
| 1366 | + // 'event_espresso' |
|
| 1367 | + // ), |
|
| 1368 | + // $file_path, |
|
| 1369 | + // $tour |
|
| 1370 | + // ), |
|
| 1371 | + // __FILE__, |
|
| 1372 | + // __FUNCTION__, |
|
| 1373 | + // __LINE__ |
|
| 1374 | + // ); |
|
| 1375 | + // return; |
|
| 1376 | + // } |
|
| 1377 | + // require_once $file_path; |
|
| 1378 | + // if (! class_exists($tour)) { |
|
| 1379 | + // $error_msg[] = sprintf( |
|
| 1380 | + // esc_html__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'), |
|
| 1381 | + // $tour |
|
| 1382 | + // ); |
|
| 1383 | + // $error_msg[] = $error_msg[0] . "\r\n" |
|
| 1384 | + // . sprintf( |
|
| 1385 | + // esc_html__( |
|
| 1386 | + // 'There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.', |
|
| 1387 | + // 'event_espresso' |
|
| 1388 | + // ), |
|
| 1389 | + // $tour, |
|
| 1390 | + // '<br />', |
|
| 1391 | + // $tour, |
|
| 1392 | + // $this->_req_action, |
|
| 1393 | + // get_class($this) |
|
| 1394 | + // ); |
|
| 1395 | + // throw new EE_Error(implode('||', $error_msg)); |
|
| 1396 | + // } |
|
| 1397 | + // $tour_obj = new $tour($this->_is_caf); |
|
| 1398 | + // $tours[] = $tour_obj; |
|
| 1399 | + // $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($tour_obj); |
|
| 1400 | + // } |
|
| 1401 | + // // let's inject the end tour stop element common to all pages... this will only get seen once per machine. |
|
| 1402 | + // $end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf); |
|
| 1403 | + // $tours[] = $end_stop_tour; |
|
| 1404 | + // $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($end_stop_tour); |
|
| 1405 | + // } |
|
| 1406 | + // } |
|
| 1407 | + // |
|
| 1408 | + // if (! empty($tours)) { |
|
| 1409 | + // $this->_help_tour['tours'] = $tours; |
|
| 1410 | + // } |
|
| 1411 | + // // that's it! Now that the $_help_tours property is set (or not) |
|
| 1412 | + // // the scripts and html should be taken care of automatically. |
|
| 1413 | + // |
|
| 1414 | + // /** |
|
| 1415 | + // * Allow extending the help tours variable. |
|
| 1416 | + // * |
|
| 1417 | + // * @param Array $_help_tour The array containing all help tour information to be displayed. |
|
| 1418 | + // */ |
|
| 1419 | + // $this->_help_tour = apply_filters('FHEE__EE_Admin_Page___add_help_tour___help_tour', $this->_help_tour); |
|
| 1420 | + } |
|
| 1421 | + |
|
| 1422 | + |
|
| 1423 | + /** |
|
| 1424 | + * This simply sets up any qtips that have been defined in the page config |
|
| 1425 | + * |
|
| 1426 | + * @return void |
|
| 1427 | + */ |
|
| 1428 | + protected function _add_qtips() |
|
| 1429 | + { |
|
| 1430 | + if (isset($this->_route_config['qtips'])) { |
|
| 1431 | + $qtips = (array) $this->_route_config['qtips']; |
|
| 1432 | + // load qtip loader |
|
| 1433 | + $path = array( |
|
| 1434 | + $this->_get_dir() . '/qtips/', |
|
| 1435 | + EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/', |
|
| 1436 | + ); |
|
| 1437 | + EEH_Qtip_Loader::instance()->register($qtips, $path); |
|
| 1438 | + } |
|
| 1439 | + } |
|
| 1440 | + |
|
| 1441 | + |
|
| 1442 | + /** |
|
| 1443 | + * _set_nav_tabs |
|
| 1444 | + * This sets up the nav tabs from the page_routes array. This method can be overwritten by child classes if you |
|
| 1445 | + * wish to add additional tabs or modify accordingly. |
|
| 1446 | + * |
|
| 1447 | + * @return void |
|
| 1448 | + * @throws InvalidArgumentException |
|
| 1449 | + * @throws InvalidInterfaceException |
|
| 1450 | + * @throws InvalidDataTypeException |
|
| 1451 | + */ |
|
| 1452 | + protected function _set_nav_tabs() |
|
| 1453 | + { |
|
| 1454 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1455 | + $i = 0; |
|
| 1456 | + foreach ($this->_page_config as $slug => $config) { |
|
| 1457 | + if (! is_array($config) |
|
| 1458 | + || ( |
|
| 1459 | + is_array($config) |
|
| 1460 | + && ( |
|
| 1461 | + (isset($config['nav']) && ! $config['nav']) |
|
| 1462 | + || ! isset($config['nav']) |
|
| 1463 | + ) |
|
| 1464 | + ) |
|
| 1465 | + ) { |
|
| 1466 | + continue; |
|
| 1467 | + } |
|
| 1468 | + // no nav tab for this config |
|
| 1469 | + // check for persistent flag |
|
| 1470 | + if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) { |
|
| 1471 | + // nav tab is only to appear when route requested. |
|
| 1472 | + continue; |
|
| 1473 | + } |
|
| 1474 | + if (! $this->check_user_access($slug, true)) { |
|
| 1475 | + // no nav tab because current user does not have access. |
|
| 1476 | + continue; |
|
| 1477 | + } |
|
| 1478 | + $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : ''; |
|
| 1479 | + $this->_nav_tabs[ $slug ] = array( |
|
| 1480 | + 'url' => isset($config['nav']['url']) |
|
| 1481 | + ? $config['nav']['url'] |
|
| 1482 | + : self::add_query_args_and_nonce( |
|
| 1483 | + array('action' => $slug), |
|
| 1484 | + $this->_admin_base_url |
|
| 1485 | + ), |
|
| 1486 | + 'link_text' => isset($config['nav']['label']) |
|
| 1487 | + ? $config['nav']['label'] |
|
| 1488 | + : ucwords( |
|
| 1489 | + str_replace('_', ' ', $slug) |
|
| 1490 | + ), |
|
| 1491 | + 'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class, |
|
| 1492 | + 'order' => isset($config['nav']['order']) ? $config['nav']['order'] : $i, |
|
| 1493 | + ); |
|
| 1494 | + $i++; |
|
| 1495 | + } |
|
| 1496 | + // if $this->_nav_tabs is empty then lets set the default |
|
| 1497 | + if (empty($this->_nav_tabs)) { |
|
| 1498 | + $this->_nav_tabs[ $this->_default_nav_tab_name ] = array( |
|
| 1499 | + 'url' => $this->_admin_base_url, |
|
| 1500 | + 'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)), |
|
| 1501 | + 'css_class' => 'nav-tab-active', |
|
| 1502 | + 'order' => 10, |
|
| 1503 | + ); |
|
| 1504 | + } |
|
| 1505 | + // now let's sort the tabs according to order |
|
| 1506 | + usort($this->_nav_tabs, array($this, '_sort_nav_tabs')); |
|
| 1507 | + } |
|
| 1508 | + |
|
| 1509 | + |
|
| 1510 | + /** |
|
| 1511 | + * _set_current_labels |
|
| 1512 | + * This method modifies the _labels property with any optional specific labels indicated in the _page_routes |
|
| 1513 | + * property array |
|
| 1514 | + * |
|
| 1515 | + * @return void |
|
| 1516 | + */ |
|
| 1517 | + private function _set_current_labels() |
|
| 1518 | + { |
|
| 1519 | + if (is_array($this->_route_config) && isset($this->_route_config['labels'])) { |
|
| 1520 | + foreach ($this->_route_config['labels'] as $label => $text) { |
|
| 1521 | + if (is_array($text)) { |
|
| 1522 | + foreach ($text as $sublabel => $subtext) { |
|
| 1523 | + $this->_labels[ $label ][ $sublabel ] = $subtext; |
|
| 1524 | + } |
|
| 1525 | + } else { |
|
| 1526 | + $this->_labels[ $label ] = $text; |
|
| 1527 | + } |
|
| 1528 | + } |
|
| 1529 | + } |
|
| 1530 | + } |
|
| 1531 | + |
|
| 1532 | + |
|
| 1533 | + /** |
|
| 1534 | + * verifies user access for this admin page |
|
| 1535 | + * |
|
| 1536 | + * @param string $route_to_check if present then the capability for the route matching this string is checked. |
|
| 1537 | + * @param bool $verify_only Default is FALSE which means if user check fails then wp_die(). Otherwise just |
|
| 1538 | + * return false if verify fail. |
|
| 1539 | + * @return bool |
|
| 1540 | + * @throws InvalidArgumentException |
|
| 1541 | + * @throws InvalidDataTypeException |
|
| 1542 | + * @throws InvalidInterfaceException |
|
| 1543 | + */ |
|
| 1544 | + public function check_user_access($route_to_check = '', $verify_only = false) |
|
| 1545 | + { |
|
| 1546 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1547 | + $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check; |
|
| 1548 | + $capability = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ]) |
|
| 1549 | + && is_array( |
|
| 1550 | + $this->_page_routes[ $route_to_check ] |
|
| 1551 | + ) |
|
| 1552 | + && ! empty($this->_page_routes[ $route_to_check ]['capability']) |
|
| 1553 | + ? $this->_page_routes[ $route_to_check ]['capability'] : null; |
|
| 1554 | + if (empty($capability) && empty($route_to_check)) { |
|
| 1555 | + $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' |
|
| 1556 | + : $this->_route['capability']; |
|
| 1557 | + } else { |
|
| 1558 | + $capability = empty($capability) ? 'manage_options' : $capability; |
|
| 1559 | + } |
|
| 1560 | + $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0; |
|
| 1561 | + if (! defined('DOING_AJAX') |
|
| 1562 | + && ( |
|
| 1563 | + ! function_exists('is_admin') |
|
| 1564 | + || ! EE_Registry::instance()->CAP->current_user_can( |
|
| 1565 | + $capability, |
|
| 1566 | + $this->page_slug |
|
| 1567 | + . '_' |
|
| 1568 | + . $route_to_check, |
|
| 1569 | + $id |
|
| 1570 | + ) |
|
| 1571 | + ) |
|
| 1572 | + ) { |
|
| 1573 | + if ($verify_only) { |
|
| 1574 | + return false; |
|
| 1575 | + } |
|
| 1576 | + if (is_user_logged_in()) { |
|
| 1577 | + wp_die(__('You do not have access to this route.', 'event_espresso')); |
|
| 1578 | + } else { |
|
| 1579 | + return false; |
|
| 1580 | + } |
|
| 1581 | + } |
|
| 1582 | + return true; |
|
| 1583 | + } |
|
| 1584 | + |
|
| 1585 | + |
|
| 1586 | + /** |
|
| 1587 | + * admin_init_global |
|
| 1588 | + * This runs all the code that we want executed within the WP admin_init hook. |
|
| 1589 | + * This method executes for ALL EE Admin pages. |
|
| 1590 | + * |
|
| 1591 | + * @return void |
|
| 1592 | + */ |
|
| 1593 | + public function admin_init_global() |
|
| 1594 | + { |
|
| 1595 | + } |
|
| 1596 | + |
|
| 1597 | + |
|
| 1598 | + /** |
|
| 1599 | + * wp_loaded_global |
|
| 1600 | + * This runs all the code that we want executed within the WP wp_loaded hook. This method is optional for an |
|
| 1601 | + * EE_Admin page and will execute on every EE Admin Page load |
|
| 1602 | + * |
|
| 1603 | + * @return void |
|
| 1604 | + */ |
|
| 1605 | + public function wp_loaded() |
|
| 1606 | + { |
|
| 1607 | + } |
|
| 1608 | + |
|
| 1609 | + |
|
| 1610 | + /** |
|
| 1611 | + * admin_notices |
|
| 1612 | + * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply on |
|
| 1613 | + * ALL EE_Admin pages. |
|
| 1614 | + * |
|
| 1615 | + * @return void |
|
| 1616 | + */ |
|
| 1617 | + public function admin_notices_global() |
|
| 1618 | + { |
|
| 1619 | + $this->_display_no_javascript_warning(); |
|
| 1620 | + $this->_display_espresso_notices(); |
|
| 1621 | + } |
|
| 1622 | + |
|
| 1623 | + |
|
| 1624 | + public function network_admin_notices_global() |
|
| 1625 | + { |
|
| 1626 | + $this->_display_no_javascript_warning(); |
|
| 1627 | + $this->_display_espresso_notices(); |
|
| 1628 | + } |
|
| 1629 | + |
|
| 1630 | + |
|
| 1631 | + /** |
|
| 1632 | + * admin_footer_scripts_global |
|
| 1633 | + * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
| 1634 | + * will apply on ALL EE_Admin pages. |
|
| 1635 | + * |
|
| 1636 | + * @return void |
|
| 1637 | + */ |
|
| 1638 | + public function admin_footer_scripts_global() |
|
| 1639 | + { |
|
| 1640 | + $this->_add_admin_page_ajax_loading_img(); |
|
| 1641 | + $this->_add_admin_page_overlay(); |
|
| 1642 | + // if metaboxes are present we need to add the nonce field |
|
| 1643 | + if (isset($this->_route_config['metaboxes']) |
|
| 1644 | + || isset($this->_route_config['list_table']) |
|
| 1645 | + || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes']) |
|
| 1646 | + ) { |
|
| 1647 | + wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); |
|
| 1648 | + wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); |
|
| 1649 | + } |
|
| 1650 | + } |
|
| 1651 | + |
|
| 1652 | + |
|
| 1653 | + /** |
|
| 1654 | + * admin_footer_global |
|
| 1655 | + * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particular method will apply on |
|
| 1656 | + * ALL EE_Admin Pages. |
|
| 1657 | + * |
|
| 1658 | + * @return void |
|
| 1659 | + * @throws EE_Error |
|
| 1660 | + */ |
|
| 1661 | + public function admin_footer_global() |
|
| 1662 | + { |
|
| 1663 | + // dialog container for dialog helper |
|
| 1664 | + $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n"; |
|
| 1665 | + $d_cont .= '<div class="ee-notices"></div>'; |
|
| 1666 | + $d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>'; |
|
| 1667 | + $d_cont .= '</div>'; |
|
| 1668 | + echo $d_cont; |
|
| 1669 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 1670 | + // help tour stuff? |
|
| 1671 | + // if (isset($this->_help_tour[ $this->_req_action ])) { |
|
| 1672 | + // echo implode('<br />', $this->_help_tour[ $this->_req_action ]); |
|
| 1673 | + // } |
|
| 1674 | + // current set timezone for timezone js |
|
| 1675 | + echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>'; |
|
| 1676 | + } |
|
| 1677 | + |
|
| 1678 | + |
|
| 1679 | + /** |
|
| 1680 | + * This function sees if there is a method for help popup content existing for the given route. If there is then |
|
| 1681 | + * we'll use the retrieved array to output the content using the template. For child classes: If you want to have |
|
| 1682 | + * help popups then in your templates or your content you set "triggers" for the content using the |
|
| 1683 | + * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method |
|
| 1684 | + * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup |
|
| 1685 | + * method for the content in the format "_help_popup_content_{route_name}()" So if you are setting help content |
|
| 1686 | + * for the |
|
| 1687 | + * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined |
|
| 1688 | + * "help_popup_content_..." method. You must prepare and return an array in the following format array( |
|
| 1689 | + * 'help_trigger_id' => array( |
|
| 1690 | + * 'title' => esc_html__('localized title for popup', 'event_espresso'), |
|
| 1691 | + * 'content' => esc_html__('localized content for popup', 'event_espresso') |
|
| 1692 | + * ) |
|
| 1693 | + * ); |
|
| 1694 | + * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route. |
|
| 1695 | + * |
|
| 1696 | + * @param array $help_array |
|
| 1697 | + * @param bool $display |
|
| 1698 | + * @return string content |
|
| 1699 | + * @throws DomainException |
|
| 1700 | + * @throws EE_Error |
|
| 1701 | + */ |
|
| 1702 | + protected function _set_help_popup_content($help_array = array(), $display = false) |
|
| 1703 | + { |
|
| 1704 | + $content = ''; |
|
| 1705 | + $help_array = empty($help_array) ? $this->_get_help_content() : $help_array; |
|
| 1706 | + // loop through the array and setup content |
|
| 1707 | + foreach ($help_array as $trigger => $help) { |
|
| 1708 | + // make sure the array is setup properly |
|
| 1709 | + if (! isset($help['title']) || ! isset($help['content'])) { |
|
| 1710 | + throw new EE_Error( |
|
| 1711 | + esc_html__( |
|
| 1712 | + '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', |
|
| 1713 | + 'event_espresso' |
|
| 1714 | + ) |
|
| 1715 | + ); |
|
| 1716 | + } |
|
| 1717 | + // we're good so let'd setup the template vars and then assign parsed template content to our content. |
|
| 1718 | + $template_args = array( |
|
| 1719 | + 'help_popup_id' => $trigger, |
|
| 1720 | + 'help_popup_title' => $help['title'], |
|
| 1721 | + 'help_popup_content' => $help['content'], |
|
| 1722 | + ); |
|
| 1723 | + $content .= EEH_Template::display_template( |
|
| 1724 | + EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php', |
|
| 1725 | + $template_args, |
|
| 1726 | + true |
|
| 1727 | + ); |
|
| 1728 | + } |
|
| 1729 | + if ($display) { |
|
| 1730 | + echo $content; |
|
| 1731 | + return ''; |
|
| 1732 | + } |
|
| 1733 | + return $content; |
|
| 1734 | + } |
|
| 1735 | + |
|
| 1736 | + |
|
| 1737 | + /** |
|
| 1738 | + * All this does is retrieve the help content array if set by the EE_Admin_Page child |
|
| 1739 | + * |
|
| 1740 | + * @return array properly formatted array for help popup content |
|
| 1741 | + * @throws EE_Error |
|
| 1742 | + */ |
|
| 1743 | + private function _get_help_content() |
|
| 1744 | + { |
|
| 1745 | + // what is the method we're looking for? |
|
| 1746 | + $method_name = '_help_popup_content_' . $this->_req_action; |
|
| 1747 | + // if method doesn't exist let's get out. |
|
| 1748 | + if (! method_exists($this, $method_name)) { |
|
| 1749 | + return array(); |
|
| 1750 | + } |
|
| 1751 | + // k we're good to go let's retrieve the help array |
|
| 1752 | + $help_array = call_user_func(array($this, $method_name)); |
|
| 1753 | + // make sure we've got an array! |
|
| 1754 | + if (! is_array($help_array)) { |
|
| 1755 | + throw new EE_Error( |
|
| 1756 | + esc_html__( |
|
| 1757 | + 'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', |
|
| 1758 | + 'event_espresso' |
|
| 1759 | + ) |
|
| 1760 | + ); |
|
| 1761 | + } |
|
| 1762 | + return $help_array; |
|
| 1763 | + } |
|
| 1764 | + |
|
| 1765 | + |
|
| 1766 | + /** |
|
| 1767 | + * EE Admin Pages can use this to set a properly formatted trigger for a help popup. |
|
| 1768 | + * By default the trigger html is printed. Otherwise it can be returned if the $display flag is set "false" |
|
| 1769 | + * See comments made on the _set_help_content method for understanding other parts to the help popup tool. |
|
| 1770 | + * |
|
| 1771 | + * @param string $trigger_id reference for retrieving the trigger content for the popup |
|
| 1772 | + * @param boolean $display if false then we return the trigger string |
|
| 1773 | + * @param array $dimensions an array of dimensions for the box (array(h,w)) |
|
| 1774 | + * @return string |
|
| 1775 | + * @throws DomainException |
|
| 1776 | + * @throws EE_Error |
|
| 1777 | + */ |
|
| 1778 | + protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640')) |
|
| 1779 | + { |
|
| 1780 | + if (defined('DOING_AJAX')) { |
|
| 1781 | + return ''; |
|
| 1782 | + } |
|
| 1783 | + // 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 |
|
| 1784 | + $help_array = $this->_get_help_content(); |
|
| 1785 | + $help_content = ''; |
|
| 1786 | + if (empty($help_array) || ! isset($help_array[ $trigger_id ])) { |
|
| 1787 | + $help_array[ $trigger_id ] = array( |
|
| 1788 | + 'title' => esc_html__('Missing Content', 'event_espresso'), |
|
| 1789 | + 'content' => esc_html__( |
|
| 1790 | + '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.)', |
|
| 1791 | + 'event_espresso' |
|
| 1792 | + ), |
|
| 1793 | + ); |
|
| 1794 | + $help_content = $this->_set_help_popup_content($help_array, false); |
|
| 1795 | + } |
|
| 1796 | + // let's setup the trigger |
|
| 1797 | + $content = '<a class="ee-dialog" href="?height=' |
|
| 1798 | + . $dimensions[0] |
|
| 1799 | + . '&width=' |
|
| 1800 | + . $dimensions[1] |
|
| 1801 | + . '&inlineId=' |
|
| 1802 | + . $trigger_id |
|
| 1803 | + . '" target="_blank"><span class="question ee-help-popup-question"></span></a>'; |
|
| 1804 | + $content .= $help_content; |
|
| 1805 | + if ($display) { |
|
| 1806 | + echo $content; |
|
| 1807 | + return ''; |
|
| 1808 | + } |
|
| 1809 | + return $content; |
|
| 1810 | + } |
|
| 1811 | + |
|
| 1812 | + |
|
| 1813 | + /** |
|
| 1814 | + * _add_global_screen_options |
|
| 1815 | + * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so. |
|
| 1816 | + * This particular method will add_screen_options on ALL EE_Admin Pages |
|
| 1817 | + * |
|
| 1818 | + * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 1819 | + * see also WP_Screen object documents... |
|
| 1820 | + * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 1821 | + * @abstract |
|
| 1822 | + * @return void |
|
| 1823 | + */ |
|
| 1824 | + private function _add_global_screen_options() |
|
| 1825 | + { |
|
| 1826 | + } |
|
| 1827 | + |
|
| 1828 | + |
|
| 1829 | + /** |
|
| 1830 | + * _add_global_feature_pointers |
|
| 1831 | + * This method is used for implementing any "feature pointers" (using built-in WP styling js). |
|
| 1832 | + * This particular method will implement feature pointers for ALL EE_Admin pages. |
|
| 1833 | + * Note: this is just a placeholder for now. Implementation will come down the road |
|
| 1834 | + * |
|
| 1835 | + * @see WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
| 1836 | + * extended) also see: |
|
| 1837 | + * @link http://eamann.com/tech/wordpress-portland/ |
|
| 1838 | + * @abstract |
|
| 1839 | + * @return void |
|
| 1840 | + */ |
|
| 1841 | + private function _add_global_feature_pointers() |
|
| 1842 | + { |
|
| 1843 | + } |
|
| 1844 | + |
|
| 1845 | + |
|
| 1846 | + /** |
|
| 1847 | + * load_global_scripts_styles |
|
| 1848 | + * The scripts and styles enqueued in here will be loaded on every EE Admin page |
|
| 1849 | + * |
|
| 1850 | + * @return void |
|
| 1851 | + * @throws EE_Error |
|
| 1852 | + */ |
|
| 1853 | + public function load_global_scripts_styles() |
|
| 1854 | + { |
|
| 1855 | + /** STYLES **/ |
|
| 1856 | + // add debugging styles |
|
| 1857 | + if (WP_DEBUG) { |
|
| 1858 | + add_action('admin_head', array($this, 'add_xdebug_style')); |
|
| 1859 | + } |
|
| 1860 | + // register all styles |
|
| 1861 | + wp_register_style( |
|
| 1862 | + 'espresso-ui-theme', |
|
| 1863 | + EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', |
|
| 1864 | + array(), |
|
| 1865 | + EVENT_ESPRESSO_VERSION |
|
| 1866 | + ); |
|
| 1867 | + wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1868 | + // helpers styles |
|
| 1869 | + wp_register_style( |
|
| 1870 | + 'ee-text-links', |
|
| 1871 | + EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', |
|
| 1872 | + array(), |
|
| 1873 | + EVENT_ESPRESSO_VERSION |
|
| 1874 | + ); |
|
| 1875 | + /** SCRIPTS **/ |
|
| 1876 | + // register all scripts |
|
| 1877 | + wp_register_script( |
|
| 1878 | + 'ee-dialog', |
|
| 1879 | + EE_ADMIN_URL . 'assets/ee-dialog-helper.js', |
|
| 1880 | + array('jquery', 'jquery-ui-draggable'), |
|
| 1881 | + EVENT_ESPRESSO_VERSION, |
|
| 1882 | + true |
|
| 1883 | + ); |
|
| 1884 | + wp_register_script( |
|
| 1885 | + 'ee_admin_js', |
|
| 1886 | + EE_ADMIN_URL . 'assets/ee-admin-page.js', |
|
| 1887 | + array('espresso_core', 'ee-parse-uri', 'ee-dialog'), |
|
| 1888 | + EVENT_ESPRESSO_VERSION, |
|
| 1889 | + true |
|
| 1890 | + ); |
|
| 1891 | + wp_register_script( |
|
| 1892 | + 'jquery-ui-timepicker-addon', |
|
| 1893 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', |
|
| 1894 | + array('jquery-ui-datepicker', 'jquery-ui-slider'), |
|
| 1895 | + EVENT_ESPRESSO_VERSION, |
|
| 1896 | + true |
|
| 1897 | + ); |
|
| 1898 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 1899 | + // if (EE_Registry::instance()->CFG->admin->help_tour_activation) { |
|
| 1900 | + // add_filter('FHEE_load_joyride', '__return_true'); |
|
| 1901 | + // } |
|
| 1902 | + // script for sorting tables |
|
| 1903 | + wp_register_script( |
|
| 1904 | + 'espresso_ajax_table_sorting', |
|
| 1905 | + EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js', |
|
| 1906 | + array('ee_admin_js', 'jquery-ui-sortable'), |
|
| 1907 | + EVENT_ESPRESSO_VERSION, |
|
| 1908 | + true |
|
| 1909 | + ); |
|
| 1910 | + // script for parsing uri's |
|
| 1911 | + wp_register_script( |
|
| 1912 | + 'ee-parse-uri', |
|
| 1913 | + EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', |
|
| 1914 | + array(), |
|
| 1915 | + EVENT_ESPRESSO_VERSION, |
|
| 1916 | + true |
|
| 1917 | + ); |
|
| 1918 | + // and parsing associative serialized form elements |
|
| 1919 | + wp_register_script( |
|
| 1920 | + 'ee-serialize-full-array', |
|
| 1921 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', |
|
| 1922 | + array('jquery'), |
|
| 1923 | + EVENT_ESPRESSO_VERSION, |
|
| 1924 | + true |
|
| 1925 | + ); |
|
| 1926 | + // helpers scripts |
|
| 1927 | + wp_register_script( |
|
| 1928 | + 'ee-text-links', |
|
| 1929 | + EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', |
|
| 1930 | + array('jquery'), |
|
| 1931 | + EVENT_ESPRESSO_VERSION, |
|
| 1932 | + true |
|
| 1933 | + ); |
|
| 1934 | + wp_register_script( |
|
| 1935 | + 'ee-moment-core', |
|
| 1936 | + EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', |
|
| 1937 | + array(), |
|
| 1938 | + EVENT_ESPRESSO_VERSION, |
|
| 1939 | + true |
|
| 1940 | + ); |
|
| 1941 | + wp_register_script( |
|
| 1942 | + 'ee-moment', |
|
| 1943 | + EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', |
|
| 1944 | + array('ee-moment-core'), |
|
| 1945 | + EVENT_ESPRESSO_VERSION, |
|
| 1946 | + true |
|
| 1947 | + ); |
|
| 1948 | + wp_register_script( |
|
| 1949 | + 'ee-datepicker', |
|
| 1950 | + EE_ADMIN_URL . 'assets/ee-datepicker.js', |
|
| 1951 | + array('jquery-ui-timepicker-addon', 'ee-moment'), |
|
| 1952 | + EVENT_ESPRESSO_VERSION, |
|
| 1953 | + true |
|
| 1954 | + ); |
|
| 1955 | + // google charts |
|
| 1956 | + wp_register_script( |
|
| 1957 | + 'google-charts', |
|
| 1958 | + 'https://www.gstatic.com/charts/loader.js', |
|
| 1959 | + array(), |
|
| 1960 | + EVENT_ESPRESSO_VERSION, |
|
| 1961 | + false |
|
| 1962 | + ); |
|
| 1963 | + // ENQUEUE ALL BASICS BY DEFAULT |
|
| 1964 | + wp_enqueue_style('ee-admin-css'); |
|
| 1965 | + wp_enqueue_script('ee_admin_js'); |
|
| 1966 | + wp_enqueue_script('ee-accounting'); |
|
| 1967 | + wp_enqueue_script('jquery-validate'); |
|
| 1968 | + // taking care of metaboxes |
|
| 1969 | + if (empty($this->_cpt_route) |
|
| 1970 | + && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes'])) |
|
| 1971 | + ) { |
|
| 1972 | + wp_enqueue_script('dashboard'); |
|
| 1973 | + } |
|
| 1974 | + // LOCALIZED DATA |
|
| 1975 | + // localize script for ajax lazy loading |
|
| 1976 | + $lazy_loader_container_ids = apply_filters( |
|
| 1977 | + 'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', |
|
| 1978 | + array('espresso_news_post_box_content') |
|
| 1979 | + ); |
|
| 1980 | + wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids); |
|
| 1981 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 1982 | + // /** |
|
| 1983 | + // * help tour stuff |
|
| 1984 | + // */ |
|
| 1985 | + // if (! empty($this->_help_tour)) { |
|
| 1986 | + // // register the js for kicking things off |
|
| 1987 | + // wp_enqueue_script( |
|
| 1988 | + // 'ee-help-tour', |
|
| 1989 | + // EE_ADMIN_URL . 'assets/ee-help-tour.js', |
|
| 1990 | + // array('jquery-joyride'), |
|
| 1991 | + // EVENT_ESPRESSO_VERSION, |
|
| 1992 | + // true |
|
| 1993 | + // ); |
|
| 1994 | + // $tours = array(); |
|
| 1995 | + // // setup tours for the js tour object |
|
| 1996 | + // foreach ($this->_help_tour['tours'] as $tour) { |
|
| 1997 | + // if ($tour instanceof EE_Help_Tour) { |
|
| 1998 | + // $tours[] = array( |
|
| 1999 | + // 'id' => $tour->get_slug(), |
|
| 2000 | + // 'options' => $tour->get_options(), |
|
| 2001 | + // ); |
|
| 2002 | + // } |
|
| 2003 | + // } |
|
| 2004 | + // wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours)); |
|
| 2005 | + // // admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour |
|
| 2006 | + // } |
|
| 2007 | + } |
|
| 2008 | + |
|
| 2009 | + |
|
| 2010 | + /** |
|
| 2011 | + * admin_footer_scripts_eei18n_js_strings |
|
| 2012 | + * |
|
| 2013 | + * @return void |
|
| 2014 | + */ |
|
| 2015 | + public function admin_footer_scripts_eei18n_js_strings() |
|
| 2016 | + { |
|
| 2017 | + EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL; |
|
| 2018 | + EE_Registry::$i18n_js_strings['confirm_delete'] = esc_html__( |
|
| 2019 | + '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!!!', |
|
| 2020 | + 'event_espresso' |
|
| 2021 | + ); |
|
| 2022 | + EE_Registry::$i18n_js_strings['January'] = esc_html__('January', 'event_espresso'); |
|
| 2023 | + EE_Registry::$i18n_js_strings['February'] = esc_html__('February', 'event_espresso'); |
|
| 2024 | + EE_Registry::$i18n_js_strings['March'] = esc_html__('March', 'event_espresso'); |
|
| 2025 | + EE_Registry::$i18n_js_strings['April'] = esc_html__('April', 'event_espresso'); |
|
| 2026 | + EE_Registry::$i18n_js_strings['May'] = esc_html__('May', 'event_espresso'); |
|
| 2027 | + EE_Registry::$i18n_js_strings['June'] = esc_html__('June', 'event_espresso'); |
|
| 2028 | + EE_Registry::$i18n_js_strings['July'] = esc_html__('July', 'event_espresso'); |
|
| 2029 | + EE_Registry::$i18n_js_strings['August'] = esc_html__('August', 'event_espresso'); |
|
| 2030 | + EE_Registry::$i18n_js_strings['September'] = esc_html__('September', 'event_espresso'); |
|
| 2031 | + EE_Registry::$i18n_js_strings['October'] = esc_html__('October', 'event_espresso'); |
|
| 2032 | + EE_Registry::$i18n_js_strings['November'] = esc_html__('November', 'event_espresso'); |
|
| 2033 | + EE_Registry::$i18n_js_strings['December'] = esc_html__('December', 'event_espresso'); |
|
| 2034 | + EE_Registry::$i18n_js_strings['Jan'] = esc_html__('Jan', 'event_espresso'); |
|
| 2035 | + EE_Registry::$i18n_js_strings['Feb'] = esc_html__('Feb', 'event_espresso'); |
|
| 2036 | + EE_Registry::$i18n_js_strings['Mar'] = esc_html__('Mar', 'event_espresso'); |
|
| 2037 | + EE_Registry::$i18n_js_strings['Apr'] = esc_html__('Apr', 'event_espresso'); |
|
| 2038 | + EE_Registry::$i18n_js_strings['May'] = esc_html__('May', 'event_espresso'); |
|
| 2039 | + EE_Registry::$i18n_js_strings['Jun'] = esc_html__('Jun', 'event_espresso'); |
|
| 2040 | + EE_Registry::$i18n_js_strings['Jul'] = esc_html__('Jul', 'event_espresso'); |
|
| 2041 | + EE_Registry::$i18n_js_strings['Aug'] = esc_html__('Aug', 'event_espresso'); |
|
| 2042 | + EE_Registry::$i18n_js_strings['Sep'] = esc_html__('Sep', 'event_espresso'); |
|
| 2043 | + EE_Registry::$i18n_js_strings['Oct'] = esc_html__('Oct', 'event_espresso'); |
|
| 2044 | + EE_Registry::$i18n_js_strings['Nov'] = esc_html__('Nov', 'event_espresso'); |
|
| 2045 | + EE_Registry::$i18n_js_strings['Dec'] = esc_html__('Dec', 'event_espresso'); |
|
| 2046 | + EE_Registry::$i18n_js_strings['Sunday'] = esc_html__('Sunday', 'event_espresso'); |
|
| 2047 | + EE_Registry::$i18n_js_strings['Monday'] = esc_html__('Monday', 'event_espresso'); |
|
| 2048 | + EE_Registry::$i18n_js_strings['Tuesday'] = esc_html__('Tuesday', 'event_espresso'); |
|
| 2049 | + EE_Registry::$i18n_js_strings['Wednesday'] = esc_html__('Wednesday', 'event_espresso'); |
|
| 2050 | + EE_Registry::$i18n_js_strings['Thursday'] = esc_html__('Thursday', 'event_espresso'); |
|
| 2051 | + EE_Registry::$i18n_js_strings['Friday'] = esc_html__('Friday', 'event_espresso'); |
|
| 2052 | + EE_Registry::$i18n_js_strings['Saturday'] = esc_html__('Saturday', 'event_espresso'); |
|
| 2053 | + EE_Registry::$i18n_js_strings['Sun'] = esc_html__('Sun', 'event_espresso'); |
|
| 2054 | + EE_Registry::$i18n_js_strings['Mon'] = esc_html__('Mon', 'event_espresso'); |
|
| 2055 | + EE_Registry::$i18n_js_strings['Tue'] = esc_html__('Tue', 'event_espresso'); |
|
| 2056 | + EE_Registry::$i18n_js_strings['Wed'] = esc_html__('Wed', 'event_espresso'); |
|
| 2057 | + EE_Registry::$i18n_js_strings['Thu'] = esc_html__('Thu', 'event_espresso'); |
|
| 2058 | + EE_Registry::$i18n_js_strings['Fri'] = esc_html__('Fri', 'event_espresso'); |
|
| 2059 | + EE_Registry::$i18n_js_strings['Sat'] = esc_html__('Sat', 'event_espresso'); |
|
| 2060 | + } |
|
| 2061 | + |
|
| 2062 | + |
|
| 2063 | + /** |
|
| 2064 | + * load enhanced xdebug styles for ppl with failing eyesight |
|
| 2065 | + * |
|
| 2066 | + * @return void |
|
| 2067 | + */ |
|
| 2068 | + public function add_xdebug_style() |
|
| 2069 | + { |
|
| 2070 | + echo '<style>.xdebug-error { font-size:1.5em; }</style>'; |
|
| 2071 | + } |
|
| 2072 | + |
|
| 2073 | + |
|
| 2074 | + /************************/ |
|
| 2075 | + /** LIST TABLE METHODS **/ |
|
| 2076 | + /************************/ |
|
| 2077 | + /** |
|
| 2078 | + * this sets up the list table if the current view requires it. |
|
| 2079 | + * |
|
| 2080 | + * @return void |
|
| 2081 | + * @throws EE_Error |
|
| 2082 | + */ |
|
| 2083 | + protected function _set_list_table() |
|
| 2084 | + { |
|
| 2085 | + // first is this a list_table view? |
|
| 2086 | + if (! isset($this->_route_config['list_table'])) { |
|
| 2087 | + return; |
|
| 2088 | + } //not a list_table view so get out. |
|
| 2089 | + // list table functions are per view specific (because some admin pages might have more than one list table!) |
|
| 2090 | + $list_table_view = '_set_list_table_views_' . $this->_req_action; |
|
| 2091 | + if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) { |
|
| 2092 | + // user error msg |
|
| 2093 | + $error_msg = esc_html__( |
|
| 2094 | + 'An error occurred. The requested list table views could not be found.', |
|
| 2095 | + 'event_espresso' |
|
| 2096 | + ); |
|
| 2097 | + // developer error msg |
|
| 2098 | + $error_msg .= '||' |
|
| 2099 | + . sprintf( |
|
| 2100 | + esc_html__( |
|
| 2101 | + '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.', |
|
| 2102 | + 'event_espresso' |
|
| 2103 | + ), |
|
| 2104 | + $this->_req_action, |
|
| 2105 | + $list_table_view |
|
| 2106 | + ); |
|
| 2107 | + throw new EE_Error($error_msg); |
|
| 2108 | + } |
|
| 2109 | + // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally |
|
| 2110 | + $this->_views = apply_filters( |
|
| 2111 | + 'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, |
|
| 2112 | + $this->_views |
|
| 2113 | + ); |
|
| 2114 | + $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views); |
|
| 2115 | + $this->_views = apply_filters('FHEE_list_table_views', $this->_views); |
|
| 2116 | + $this->_set_list_table_view(); |
|
| 2117 | + $this->_set_list_table_object(); |
|
| 2118 | + } |
|
| 2119 | + |
|
| 2120 | + |
|
| 2121 | + /** |
|
| 2122 | + * set current view for List Table |
|
| 2123 | + * |
|
| 2124 | + * @return void |
|
| 2125 | + */ |
|
| 2126 | + protected function _set_list_table_view() |
|
| 2127 | + { |
|
| 2128 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2129 | + // looking at active items or dumpster diving ? |
|
| 2130 | + if (! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) { |
|
| 2131 | + $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all'; |
|
| 2132 | + } else { |
|
| 2133 | + $this->_view = sanitize_key($this->_req_data['status']); |
|
| 2134 | + } |
|
| 2135 | + } |
|
| 2136 | + |
|
| 2137 | + |
|
| 2138 | + /** |
|
| 2139 | + * _set_list_table_object |
|
| 2140 | + * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of. |
|
| 2141 | + * |
|
| 2142 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2143 | + * @throws \InvalidArgumentException |
|
| 2144 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2145 | + * @throws EE_Error |
|
| 2146 | + * @throws InvalidInterfaceException |
|
| 2147 | + */ |
|
| 2148 | + protected function _set_list_table_object() |
|
| 2149 | + { |
|
| 2150 | + if (isset($this->_route_config['list_table'])) { |
|
| 2151 | + if (! class_exists($this->_route_config['list_table'])) { |
|
| 2152 | + throw new EE_Error( |
|
| 2153 | + sprintf( |
|
| 2154 | + esc_html__( |
|
| 2155 | + '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.', |
|
| 2156 | + 'event_espresso' |
|
| 2157 | + ), |
|
| 2158 | + $this->_route_config['list_table'], |
|
| 2159 | + get_class($this) |
|
| 2160 | + ) |
|
| 2161 | + ); |
|
| 2162 | + } |
|
| 2163 | + $this->_list_table_object = $this->loader->getShared( |
|
| 2164 | + $this->_route_config['list_table'], |
|
| 2165 | + array($this) |
|
| 2166 | + ); |
|
| 2167 | + } |
|
| 2168 | + } |
|
| 2169 | + |
|
| 2170 | + |
|
| 2171 | + /** |
|
| 2172 | + * get_list_table_view_RLs - get it? View RL ?? VU-RL??? URL ?? |
|
| 2173 | + * |
|
| 2174 | + * @param array $extra_query_args Optional. An array of extra query args to add to the generated |
|
| 2175 | + * urls. The array should be indexed by the view it is being |
|
| 2176 | + * added to. |
|
| 2177 | + * @return array |
|
| 2178 | + */ |
|
| 2179 | + public function get_list_table_view_RLs($extra_query_args = array()) |
|
| 2180 | + { |
|
| 2181 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2182 | + if (empty($this->_views)) { |
|
| 2183 | + $this->_views = array(); |
|
| 2184 | + } |
|
| 2185 | + // cycle thru views |
|
| 2186 | + foreach ($this->_views as $key => $view) { |
|
| 2187 | + $query_args = array(); |
|
| 2188 | + // check for current view |
|
| 2189 | + $this->_views[ $key ]['class'] = $this->_view === $view['slug'] ? 'current' : ''; |
|
| 2190 | + $query_args['action'] = $this->_req_action; |
|
| 2191 | + $query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 2192 | + $query_args['status'] = $view['slug']; |
|
| 2193 | + // merge any other arguments sent in. |
|
| 2194 | + if (isset($extra_query_args[ $view['slug'] ])) { |
|
| 2195 | + $query_args = array_merge($query_args, $extra_query_args[ $view['slug'] ]); |
|
| 2196 | + } |
|
| 2197 | + $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 2198 | + } |
|
| 2199 | + return $this->_views; |
|
| 2200 | + } |
|
| 2201 | + |
|
| 2202 | + |
|
| 2203 | + /** |
|
| 2204 | + * _entries_per_page_dropdown |
|
| 2205 | + * generates a drop down box for selecting the number of visible rows in an admin page list table |
|
| 2206 | + * |
|
| 2207 | + * @todo : Note: ideally this should be added to the screen options dropdown as that would be consistent with how |
|
| 2208 | + * WP does it. |
|
| 2209 | + * @param int $max_entries total number of rows in the table |
|
| 2210 | + * @return string |
|
| 2211 | + */ |
|
| 2212 | + protected function _entries_per_page_dropdown($max_entries = 0) |
|
| 2213 | + { |
|
| 2214 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2215 | + $values = array(10, 25, 50, 100); |
|
| 2216 | + $per_page = (! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10; |
|
| 2217 | + if ($max_entries) { |
|
| 2218 | + $values[] = $max_entries; |
|
| 2219 | + sort($values); |
|
| 2220 | + } |
|
| 2221 | + $entries_per_page_dropdown = ' |
|
| 2222 | 2222 | <div id="entries-per-page-dv" class="alignleft actions"> |
| 2223 | 2223 | <label class="hide-if-no-js"> |
| 2224 | 2224 | Show |
| 2225 | 2225 | <select id="entries-per-page-slct" name="entries-per-page-slct">'; |
| 2226 | - foreach ($values as $value) { |
|
| 2227 | - if ($value < $max_entries) { |
|
| 2228 | - $selected = $value === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2229 | - $entries_per_page_dropdown .= ' |
|
| 2226 | + foreach ($values as $value) { |
|
| 2227 | + if ($value < $max_entries) { |
|
| 2228 | + $selected = $value === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2229 | + $entries_per_page_dropdown .= ' |
|
| 2230 | 2230 | <option value="' . $value . '"' . $selected . '>' . $value . ' </option>'; |
| 2231 | - } |
|
| 2232 | - } |
|
| 2233 | - $selected = $max_entries === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2234 | - $entries_per_page_dropdown .= ' |
|
| 2231 | + } |
|
| 2232 | + } |
|
| 2233 | + $selected = $max_entries === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2234 | + $entries_per_page_dropdown .= ' |
|
| 2235 | 2235 | <option value="' . $max_entries . '"' . $selected . '>All </option>'; |
| 2236 | - $entries_per_page_dropdown .= ' |
|
| 2236 | + $entries_per_page_dropdown .= ' |
|
| 2237 | 2237 | </select> |
| 2238 | 2238 | entries |
| 2239 | 2239 | </label> |
| 2240 | 2240 | <input id="entries-per-page-btn" class="button-secondary" type="submit" value="Go" > |
| 2241 | 2241 | </div> |
| 2242 | 2242 | '; |
| 2243 | - return $entries_per_page_dropdown; |
|
| 2244 | - } |
|
| 2245 | - |
|
| 2246 | - |
|
| 2247 | - /** |
|
| 2248 | - * _set_search_attributes |
|
| 2249 | - * |
|
| 2250 | - * @return void |
|
| 2251 | - */ |
|
| 2252 | - public function _set_search_attributes() |
|
| 2253 | - { |
|
| 2254 | - $this->_template_args['search']['btn_label'] = sprintf( |
|
| 2255 | - esc_html__('Search %s', 'event_espresso'), |
|
| 2256 | - empty($this->_search_btn_label) ? $this->page_label |
|
| 2257 | - : $this->_search_btn_label |
|
| 2258 | - ); |
|
| 2259 | - $this->_template_args['search']['callback'] = 'search_' . $this->page_slug; |
|
| 2260 | - } |
|
| 2261 | - |
|
| 2262 | - |
|
| 2263 | - |
|
| 2264 | - /*** END LIST TABLE METHODS **/ |
|
| 2265 | - |
|
| 2266 | - |
|
| 2267 | - /** |
|
| 2268 | - * _add_registered_metaboxes |
|
| 2269 | - * this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array. |
|
| 2270 | - * |
|
| 2271 | - * @link http://codex.wordpress.org/Function_Reference/add_meta_box |
|
| 2272 | - * @return void |
|
| 2273 | - * @throws EE_Error |
|
| 2274 | - */ |
|
| 2275 | - private function _add_registered_meta_boxes() |
|
| 2276 | - { |
|
| 2277 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2278 | - // we only add meta boxes if the page_route calls for it |
|
| 2279 | - if (is_array($this->_route_config) && isset($this->_route_config['metaboxes']) |
|
| 2280 | - && is_array( |
|
| 2281 | - $this->_route_config['metaboxes'] |
|
| 2282 | - ) |
|
| 2283 | - ) { |
|
| 2284 | - // this simply loops through the callbacks provided |
|
| 2285 | - // and checks if there is a corresponding callback registered by the child |
|
| 2286 | - // if there is then we go ahead and process the metabox loader. |
|
| 2287 | - foreach ($this->_route_config['metaboxes'] as $metabox_callback) { |
|
| 2288 | - // first check for Closures |
|
| 2289 | - if ($metabox_callback instanceof Closure) { |
|
| 2290 | - $result = $metabox_callback(); |
|
| 2291 | - } elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) { |
|
| 2292 | - $result = call_user_func(array($metabox_callback[0], $metabox_callback[1])); |
|
| 2293 | - } else { |
|
| 2294 | - $result = call_user_func(array($this, &$metabox_callback)); |
|
| 2295 | - } |
|
| 2296 | - if ($result === false) { |
|
| 2297 | - // user error msg |
|
| 2298 | - $error_msg = esc_html__( |
|
| 2299 | - 'An error occurred. The requested metabox could not be found.', |
|
| 2300 | - 'event_espresso' |
|
| 2301 | - ); |
|
| 2302 | - // developer error msg |
|
| 2303 | - $error_msg .= '||' |
|
| 2304 | - . sprintf( |
|
| 2305 | - esc_html__( |
|
| 2306 | - '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.', |
|
| 2307 | - 'event_espresso' |
|
| 2308 | - ), |
|
| 2309 | - $metabox_callback |
|
| 2310 | - ); |
|
| 2311 | - throw new EE_Error($error_msg); |
|
| 2312 | - } |
|
| 2313 | - } |
|
| 2314 | - } |
|
| 2315 | - } |
|
| 2316 | - |
|
| 2317 | - |
|
| 2318 | - /** |
|
| 2319 | - * _add_screen_columns |
|
| 2320 | - * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as |
|
| 2321 | - * the dynamic column template and we'll setup the column options for the page. |
|
| 2322 | - * |
|
| 2323 | - * @return void |
|
| 2324 | - */ |
|
| 2325 | - private function _add_screen_columns() |
|
| 2326 | - { |
|
| 2327 | - if (is_array($this->_route_config) |
|
| 2328 | - && isset($this->_route_config['columns']) |
|
| 2329 | - && is_array($this->_route_config['columns']) |
|
| 2330 | - && count($this->_route_config['columns']) === 2 |
|
| 2331 | - ) { |
|
| 2332 | - add_screen_option( |
|
| 2333 | - 'layout_columns', |
|
| 2334 | - array( |
|
| 2335 | - 'max' => (int) $this->_route_config['columns'][0], |
|
| 2336 | - 'default' => (int) $this->_route_config['columns'][1], |
|
| 2337 | - ) |
|
| 2338 | - ); |
|
| 2339 | - $this->_template_args['num_columns'] = $this->_route_config['columns'][0]; |
|
| 2340 | - $screen_id = $this->_current_screen->id; |
|
| 2341 | - $screen_columns = (int) get_user_option("screen_layout_{$screen_id}"); |
|
| 2342 | - $total_columns = ! empty($screen_columns) |
|
| 2343 | - ? $screen_columns |
|
| 2344 | - : $this->_route_config['columns'][1]; |
|
| 2345 | - $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns; |
|
| 2346 | - $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2347 | - $this->_template_args['screen'] = $this->_current_screen; |
|
| 2348 | - $this->_column_template_path = EE_ADMIN_TEMPLATE |
|
| 2349 | - . 'admin_details_metabox_column_wrapper.template.php'; |
|
| 2350 | - // finally if we don't have has_metaboxes set in the route config |
|
| 2351 | - // let's make sure it IS set other wise the necessary hidden fields for this won't be loaded. |
|
| 2352 | - $this->_route_config['has_metaboxes'] = true; |
|
| 2353 | - } |
|
| 2354 | - } |
|
| 2355 | - |
|
| 2356 | - |
|
| 2357 | - |
|
| 2358 | - /** GLOBALLY AVAILABLE METABOXES **/ |
|
| 2359 | - |
|
| 2360 | - |
|
| 2361 | - /** |
|
| 2362 | - * In this section we put any globally available EE metaboxes for all EE Admin pages. They are called by simply |
|
| 2363 | - * referencing the callback in the _page_config array property. This way you can be very specific about what pages |
|
| 2364 | - * these get loaded on. |
|
| 2365 | - */ |
|
| 2366 | - private function _espresso_news_post_box() |
|
| 2367 | - { |
|
| 2368 | - $news_box_title = apply_filters( |
|
| 2369 | - 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
| 2370 | - esc_html__('New @ Event Espresso', 'event_espresso') |
|
| 2371 | - ); |
|
| 2372 | - add_meta_box( |
|
| 2373 | - 'espresso_news_post_box', |
|
| 2374 | - $news_box_title, |
|
| 2375 | - array( |
|
| 2376 | - $this, |
|
| 2377 | - 'espresso_news_post_box', |
|
| 2378 | - ), |
|
| 2379 | - $this->_wp_page_slug, |
|
| 2380 | - 'side' |
|
| 2381 | - ); |
|
| 2382 | - } |
|
| 2383 | - |
|
| 2384 | - |
|
| 2385 | - /** |
|
| 2386 | - * Code for setting up espresso ratings request metabox. |
|
| 2387 | - */ |
|
| 2388 | - protected function _espresso_ratings_request() |
|
| 2389 | - { |
|
| 2390 | - if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
| 2391 | - return; |
|
| 2392 | - } |
|
| 2393 | - $ratings_box_title = apply_filters( |
|
| 2394 | - 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
| 2395 | - esc_html__('Keep Event Espresso Decaf Free', 'event_espresso') |
|
| 2396 | - ); |
|
| 2397 | - add_meta_box( |
|
| 2398 | - 'espresso_ratings_request', |
|
| 2399 | - $ratings_box_title, |
|
| 2400 | - array( |
|
| 2401 | - $this, |
|
| 2402 | - 'espresso_ratings_request', |
|
| 2403 | - ), |
|
| 2404 | - $this->_wp_page_slug, |
|
| 2405 | - 'side' |
|
| 2406 | - ); |
|
| 2407 | - } |
|
| 2408 | - |
|
| 2409 | - |
|
| 2410 | - /** |
|
| 2411 | - * Code for setting up espresso ratings request metabox content. |
|
| 2412 | - * |
|
| 2413 | - * @throws DomainException |
|
| 2414 | - */ |
|
| 2415 | - public function espresso_ratings_request() |
|
| 2416 | - { |
|
| 2417 | - EEH_Template::display_template( |
|
| 2418 | - EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php', |
|
| 2419 | - array() |
|
| 2420 | - ); |
|
| 2421 | - } |
|
| 2422 | - |
|
| 2423 | - |
|
| 2424 | - public static function cached_rss_display($rss_id, $url) |
|
| 2425 | - { |
|
| 2426 | - $loading = '<p class="widget-loading hide-if-no-js">' |
|
| 2427 | - . __('Loading…', 'event_espresso') |
|
| 2428 | - . '</p><p class="hide-if-js">' |
|
| 2429 | - . esc_html__('This widget requires JavaScript.', 'event_espresso') |
|
| 2430 | - . '</p>'; |
|
| 2431 | - $pre = '<div class="espresso-rss-display">' . "\n\t"; |
|
| 2432 | - $pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>'; |
|
| 2433 | - $post = '</div>' . "\n"; |
|
| 2434 | - $cache_key = 'ee_rss_' . md5($rss_id); |
|
| 2435 | - $output = get_transient($cache_key); |
|
| 2436 | - if ($output !== false) { |
|
| 2437 | - echo $pre . $output . $post; |
|
| 2438 | - return true; |
|
| 2439 | - } |
|
| 2440 | - if (! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 2441 | - echo $pre . $loading . $post; |
|
| 2442 | - return false; |
|
| 2443 | - } |
|
| 2444 | - ob_start(); |
|
| 2445 | - wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5)); |
|
| 2446 | - set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS); |
|
| 2447 | - return true; |
|
| 2448 | - } |
|
| 2449 | - |
|
| 2450 | - |
|
| 2451 | - public function espresso_news_post_box() |
|
| 2452 | - { |
|
| 2453 | - ?> |
|
| 2243 | + return $entries_per_page_dropdown; |
|
| 2244 | + } |
|
| 2245 | + |
|
| 2246 | + |
|
| 2247 | + /** |
|
| 2248 | + * _set_search_attributes |
|
| 2249 | + * |
|
| 2250 | + * @return void |
|
| 2251 | + */ |
|
| 2252 | + public function _set_search_attributes() |
|
| 2253 | + { |
|
| 2254 | + $this->_template_args['search']['btn_label'] = sprintf( |
|
| 2255 | + esc_html__('Search %s', 'event_espresso'), |
|
| 2256 | + empty($this->_search_btn_label) ? $this->page_label |
|
| 2257 | + : $this->_search_btn_label |
|
| 2258 | + ); |
|
| 2259 | + $this->_template_args['search']['callback'] = 'search_' . $this->page_slug; |
|
| 2260 | + } |
|
| 2261 | + |
|
| 2262 | + |
|
| 2263 | + |
|
| 2264 | + /*** END LIST TABLE METHODS **/ |
|
| 2265 | + |
|
| 2266 | + |
|
| 2267 | + /** |
|
| 2268 | + * _add_registered_metaboxes |
|
| 2269 | + * this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array. |
|
| 2270 | + * |
|
| 2271 | + * @link http://codex.wordpress.org/Function_Reference/add_meta_box |
|
| 2272 | + * @return void |
|
| 2273 | + * @throws EE_Error |
|
| 2274 | + */ |
|
| 2275 | + private function _add_registered_meta_boxes() |
|
| 2276 | + { |
|
| 2277 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2278 | + // we only add meta boxes if the page_route calls for it |
|
| 2279 | + if (is_array($this->_route_config) && isset($this->_route_config['metaboxes']) |
|
| 2280 | + && is_array( |
|
| 2281 | + $this->_route_config['metaboxes'] |
|
| 2282 | + ) |
|
| 2283 | + ) { |
|
| 2284 | + // this simply loops through the callbacks provided |
|
| 2285 | + // and checks if there is a corresponding callback registered by the child |
|
| 2286 | + // if there is then we go ahead and process the metabox loader. |
|
| 2287 | + foreach ($this->_route_config['metaboxes'] as $metabox_callback) { |
|
| 2288 | + // first check for Closures |
|
| 2289 | + if ($metabox_callback instanceof Closure) { |
|
| 2290 | + $result = $metabox_callback(); |
|
| 2291 | + } elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) { |
|
| 2292 | + $result = call_user_func(array($metabox_callback[0], $metabox_callback[1])); |
|
| 2293 | + } else { |
|
| 2294 | + $result = call_user_func(array($this, &$metabox_callback)); |
|
| 2295 | + } |
|
| 2296 | + if ($result === false) { |
|
| 2297 | + // user error msg |
|
| 2298 | + $error_msg = esc_html__( |
|
| 2299 | + 'An error occurred. The requested metabox could not be found.', |
|
| 2300 | + 'event_espresso' |
|
| 2301 | + ); |
|
| 2302 | + // developer error msg |
|
| 2303 | + $error_msg .= '||' |
|
| 2304 | + . sprintf( |
|
| 2305 | + esc_html__( |
|
| 2306 | + '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.', |
|
| 2307 | + 'event_espresso' |
|
| 2308 | + ), |
|
| 2309 | + $metabox_callback |
|
| 2310 | + ); |
|
| 2311 | + throw new EE_Error($error_msg); |
|
| 2312 | + } |
|
| 2313 | + } |
|
| 2314 | + } |
|
| 2315 | + } |
|
| 2316 | + |
|
| 2317 | + |
|
| 2318 | + /** |
|
| 2319 | + * _add_screen_columns |
|
| 2320 | + * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as |
|
| 2321 | + * the dynamic column template and we'll setup the column options for the page. |
|
| 2322 | + * |
|
| 2323 | + * @return void |
|
| 2324 | + */ |
|
| 2325 | + private function _add_screen_columns() |
|
| 2326 | + { |
|
| 2327 | + if (is_array($this->_route_config) |
|
| 2328 | + && isset($this->_route_config['columns']) |
|
| 2329 | + && is_array($this->_route_config['columns']) |
|
| 2330 | + && count($this->_route_config['columns']) === 2 |
|
| 2331 | + ) { |
|
| 2332 | + add_screen_option( |
|
| 2333 | + 'layout_columns', |
|
| 2334 | + array( |
|
| 2335 | + 'max' => (int) $this->_route_config['columns'][0], |
|
| 2336 | + 'default' => (int) $this->_route_config['columns'][1], |
|
| 2337 | + ) |
|
| 2338 | + ); |
|
| 2339 | + $this->_template_args['num_columns'] = $this->_route_config['columns'][0]; |
|
| 2340 | + $screen_id = $this->_current_screen->id; |
|
| 2341 | + $screen_columns = (int) get_user_option("screen_layout_{$screen_id}"); |
|
| 2342 | + $total_columns = ! empty($screen_columns) |
|
| 2343 | + ? $screen_columns |
|
| 2344 | + : $this->_route_config['columns'][1]; |
|
| 2345 | + $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns; |
|
| 2346 | + $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2347 | + $this->_template_args['screen'] = $this->_current_screen; |
|
| 2348 | + $this->_column_template_path = EE_ADMIN_TEMPLATE |
|
| 2349 | + . 'admin_details_metabox_column_wrapper.template.php'; |
|
| 2350 | + // finally if we don't have has_metaboxes set in the route config |
|
| 2351 | + // let's make sure it IS set other wise the necessary hidden fields for this won't be loaded. |
|
| 2352 | + $this->_route_config['has_metaboxes'] = true; |
|
| 2353 | + } |
|
| 2354 | + } |
|
| 2355 | + |
|
| 2356 | + |
|
| 2357 | + |
|
| 2358 | + /** GLOBALLY AVAILABLE METABOXES **/ |
|
| 2359 | + |
|
| 2360 | + |
|
| 2361 | + /** |
|
| 2362 | + * In this section we put any globally available EE metaboxes for all EE Admin pages. They are called by simply |
|
| 2363 | + * referencing the callback in the _page_config array property. This way you can be very specific about what pages |
|
| 2364 | + * these get loaded on. |
|
| 2365 | + */ |
|
| 2366 | + private function _espresso_news_post_box() |
|
| 2367 | + { |
|
| 2368 | + $news_box_title = apply_filters( |
|
| 2369 | + 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
| 2370 | + esc_html__('New @ Event Espresso', 'event_espresso') |
|
| 2371 | + ); |
|
| 2372 | + add_meta_box( |
|
| 2373 | + 'espresso_news_post_box', |
|
| 2374 | + $news_box_title, |
|
| 2375 | + array( |
|
| 2376 | + $this, |
|
| 2377 | + 'espresso_news_post_box', |
|
| 2378 | + ), |
|
| 2379 | + $this->_wp_page_slug, |
|
| 2380 | + 'side' |
|
| 2381 | + ); |
|
| 2382 | + } |
|
| 2383 | + |
|
| 2384 | + |
|
| 2385 | + /** |
|
| 2386 | + * Code for setting up espresso ratings request metabox. |
|
| 2387 | + */ |
|
| 2388 | + protected function _espresso_ratings_request() |
|
| 2389 | + { |
|
| 2390 | + if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
| 2391 | + return; |
|
| 2392 | + } |
|
| 2393 | + $ratings_box_title = apply_filters( |
|
| 2394 | + 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
| 2395 | + esc_html__('Keep Event Espresso Decaf Free', 'event_espresso') |
|
| 2396 | + ); |
|
| 2397 | + add_meta_box( |
|
| 2398 | + 'espresso_ratings_request', |
|
| 2399 | + $ratings_box_title, |
|
| 2400 | + array( |
|
| 2401 | + $this, |
|
| 2402 | + 'espresso_ratings_request', |
|
| 2403 | + ), |
|
| 2404 | + $this->_wp_page_slug, |
|
| 2405 | + 'side' |
|
| 2406 | + ); |
|
| 2407 | + } |
|
| 2408 | + |
|
| 2409 | + |
|
| 2410 | + /** |
|
| 2411 | + * Code for setting up espresso ratings request metabox content. |
|
| 2412 | + * |
|
| 2413 | + * @throws DomainException |
|
| 2414 | + */ |
|
| 2415 | + public function espresso_ratings_request() |
|
| 2416 | + { |
|
| 2417 | + EEH_Template::display_template( |
|
| 2418 | + EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php', |
|
| 2419 | + array() |
|
| 2420 | + ); |
|
| 2421 | + } |
|
| 2422 | + |
|
| 2423 | + |
|
| 2424 | + public static function cached_rss_display($rss_id, $url) |
|
| 2425 | + { |
|
| 2426 | + $loading = '<p class="widget-loading hide-if-no-js">' |
|
| 2427 | + . __('Loading…', 'event_espresso') |
|
| 2428 | + . '</p><p class="hide-if-js">' |
|
| 2429 | + . esc_html__('This widget requires JavaScript.', 'event_espresso') |
|
| 2430 | + . '</p>'; |
|
| 2431 | + $pre = '<div class="espresso-rss-display">' . "\n\t"; |
|
| 2432 | + $pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>'; |
|
| 2433 | + $post = '</div>' . "\n"; |
|
| 2434 | + $cache_key = 'ee_rss_' . md5($rss_id); |
|
| 2435 | + $output = get_transient($cache_key); |
|
| 2436 | + if ($output !== false) { |
|
| 2437 | + echo $pre . $output . $post; |
|
| 2438 | + return true; |
|
| 2439 | + } |
|
| 2440 | + if (! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 2441 | + echo $pre . $loading . $post; |
|
| 2442 | + return false; |
|
| 2443 | + } |
|
| 2444 | + ob_start(); |
|
| 2445 | + wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5)); |
|
| 2446 | + set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS); |
|
| 2447 | + return true; |
|
| 2448 | + } |
|
| 2449 | + |
|
| 2450 | + |
|
| 2451 | + public function espresso_news_post_box() |
|
| 2452 | + { |
|
| 2453 | + ?> |
|
| 2454 | 2454 | <div class="padding"> |
| 2455 | 2455 | <div id="espresso_news_post_box_content" class="infolinks"> |
| 2456 | 2456 | <?php |
| 2457 | - // Get RSS Feed(s) |
|
| 2458 | - self::cached_rss_display( |
|
| 2459 | - 'espresso_news_post_box_content', |
|
| 2460 | - urlencode( |
|
| 2461 | - apply_filters( |
|
| 2462 | - 'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url', |
|
| 2463 | - 'http://eventespresso.com/feed/' |
|
| 2464 | - ) |
|
| 2465 | - ) |
|
| 2466 | - ); |
|
| 2467 | - ?> |
|
| 2457 | + // Get RSS Feed(s) |
|
| 2458 | + self::cached_rss_display( |
|
| 2459 | + 'espresso_news_post_box_content', |
|
| 2460 | + urlencode( |
|
| 2461 | + apply_filters( |
|
| 2462 | + 'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url', |
|
| 2463 | + 'http://eventespresso.com/feed/' |
|
| 2464 | + ) |
|
| 2465 | + ) |
|
| 2466 | + ); |
|
| 2467 | + ?> |
|
| 2468 | 2468 | </div> |
| 2469 | 2469 | <?php do_action('AHEE__EE_Admin_Page__espresso_news_post_box__after_content'); ?> |
| 2470 | 2470 | </div> |
| 2471 | 2471 | <?php |
| 2472 | - } |
|
| 2473 | - |
|
| 2474 | - |
|
| 2475 | - private function _espresso_links_post_box() |
|
| 2476 | - { |
|
| 2477 | - // Hiding until we actually have content to put in here... |
|
| 2478 | - // 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'); |
|
| 2479 | - } |
|
| 2480 | - |
|
| 2481 | - |
|
| 2482 | - public function espresso_links_post_box() |
|
| 2483 | - { |
|
| 2484 | - // Hiding until we actually have content to put in here... |
|
| 2485 | - // EEH_Template::display_template( |
|
| 2486 | - // EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php' |
|
| 2487 | - // ); |
|
| 2488 | - } |
|
| 2489 | - |
|
| 2490 | - |
|
| 2491 | - protected function _espresso_sponsors_post_box() |
|
| 2492 | - { |
|
| 2493 | - if (apply_filters('FHEE_show_sponsors_meta_box', true)) { |
|
| 2494 | - add_meta_box( |
|
| 2495 | - 'espresso_sponsors_post_box', |
|
| 2496 | - esc_html__('Event Espresso Highlights', 'event_espresso'), |
|
| 2497 | - array($this, 'espresso_sponsors_post_box'), |
|
| 2498 | - $this->_wp_page_slug, |
|
| 2499 | - 'side' |
|
| 2500 | - ); |
|
| 2501 | - } |
|
| 2502 | - } |
|
| 2503 | - |
|
| 2504 | - |
|
| 2505 | - public function espresso_sponsors_post_box() |
|
| 2506 | - { |
|
| 2507 | - EEH_Template::display_template( |
|
| 2508 | - EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php' |
|
| 2509 | - ); |
|
| 2510 | - } |
|
| 2511 | - |
|
| 2512 | - |
|
| 2513 | - private function _publish_post_box() |
|
| 2514 | - { |
|
| 2515 | - $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview'; |
|
| 2516 | - // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array |
|
| 2517 | - // then we'll use that for the metabox label. |
|
| 2518 | - // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes) |
|
| 2519 | - if (! empty($this->_labels['publishbox'])) { |
|
| 2520 | - $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ] |
|
| 2521 | - : $this->_labels['publishbox']; |
|
| 2522 | - } else { |
|
| 2523 | - $box_label = esc_html__('Publish', 'event_espresso'); |
|
| 2524 | - } |
|
| 2525 | - $box_label = apply_filters( |
|
| 2526 | - 'FHEE__EE_Admin_Page___publish_post_box__box_label', |
|
| 2527 | - $box_label, |
|
| 2528 | - $this->_req_action, |
|
| 2529 | - $this |
|
| 2530 | - ); |
|
| 2531 | - add_meta_box( |
|
| 2532 | - $meta_box_ref, |
|
| 2533 | - $box_label, |
|
| 2534 | - array($this, 'editor_overview'), |
|
| 2535 | - $this->_current_screen->id, |
|
| 2536 | - 'side', |
|
| 2537 | - 'high' |
|
| 2538 | - ); |
|
| 2539 | - } |
|
| 2540 | - |
|
| 2541 | - |
|
| 2542 | - public function editor_overview() |
|
| 2543 | - { |
|
| 2544 | - // if we have extra content set let's add it in if not make sure its empty |
|
| 2545 | - $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) |
|
| 2546 | - ? $this->_template_args['publish_box_extra_content'] |
|
| 2547 | - : ''; |
|
| 2548 | - echo EEH_Template::display_template( |
|
| 2549 | - EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php', |
|
| 2550 | - $this->_template_args, |
|
| 2551 | - true |
|
| 2552 | - ); |
|
| 2553 | - } |
|
| 2554 | - |
|
| 2555 | - |
|
| 2556 | - /** end of globally available metaboxes section **/ |
|
| 2557 | - |
|
| 2558 | - |
|
| 2559 | - /** |
|
| 2560 | - * Public wrapper for the protected method. Allows plugins/addons to externally call the |
|
| 2561 | - * protected method. |
|
| 2562 | - * |
|
| 2563 | - * @see $this->_set_publish_post_box_vars for param details |
|
| 2564 | - * @since 4.6.0 |
|
| 2565 | - * @param string $name |
|
| 2566 | - * @param int $id |
|
| 2567 | - * @param bool $delete |
|
| 2568 | - * @param string $save_close_redirect_URL |
|
| 2569 | - * @param bool $both_btns |
|
| 2570 | - * @throws EE_Error |
|
| 2571 | - * @throws InvalidArgumentException |
|
| 2572 | - * @throws InvalidDataTypeException |
|
| 2573 | - * @throws InvalidInterfaceException |
|
| 2574 | - */ |
|
| 2575 | - public function set_publish_post_box_vars( |
|
| 2576 | - $name = '', |
|
| 2577 | - $id = 0, |
|
| 2578 | - $delete = false, |
|
| 2579 | - $save_close_redirect_URL = '', |
|
| 2580 | - $both_btns = true |
|
| 2581 | - ) { |
|
| 2582 | - $this->_set_publish_post_box_vars( |
|
| 2583 | - $name, |
|
| 2584 | - $id, |
|
| 2585 | - $delete, |
|
| 2586 | - $save_close_redirect_URL, |
|
| 2587 | - $both_btns |
|
| 2588 | - ); |
|
| 2589 | - } |
|
| 2590 | - |
|
| 2591 | - |
|
| 2592 | - /** |
|
| 2593 | - * Sets the _template_args arguments used by the _publish_post_box shortcut |
|
| 2594 | - * Note: currently there is no validation for this. However if you want the delete button, the |
|
| 2595 | - * save, and save and close buttons to work properly, then you will want to include a |
|
| 2596 | - * values for the name and id arguments. |
|
| 2597 | - * |
|
| 2598 | - * @todo Add in validation for name/id arguments. |
|
| 2599 | - * @param string $name key used for the action ID (i.e. event_id) |
|
| 2600 | - * @param int $id id attached to the item published |
|
| 2601 | - * @param string $delete page route callback for the delete action |
|
| 2602 | - * @param string $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed |
|
| 2603 | - * @param boolean $both_btns whether to display BOTH the "Save & Close" and "Save" buttons or just |
|
| 2604 | - * the Save button |
|
| 2605 | - * @throws EE_Error |
|
| 2606 | - * @throws InvalidArgumentException |
|
| 2607 | - * @throws InvalidDataTypeException |
|
| 2608 | - * @throws InvalidInterfaceException |
|
| 2609 | - */ |
|
| 2610 | - protected function _set_publish_post_box_vars( |
|
| 2611 | - $name = '', |
|
| 2612 | - $id = 0, |
|
| 2613 | - $delete = '', |
|
| 2614 | - $save_close_redirect_URL = '', |
|
| 2615 | - $both_btns = true |
|
| 2616 | - ) { |
|
| 2617 | - // if Save & Close, use a custom redirect URL or default to the main page? |
|
| 2618 | - $save_close_redirect_URL = ! empty($save_close_redirect_URL) |
|
| 2619 | - ? $save_close_redirect_URL |
|
| 2620 | - : $this->_admin_base_url; |
|
| 2621 | - // create the Save & Close and Save buttons |
|
| 2622 | - $this->_set_save_buttons($both_btns, array(), array(), $save_close_redirect_URL); |
|
| 2623 | - // if we have extra content set let's add it in if not make sure its empty |
|
| 2624 | - $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) |
|
| 2625 | - ? $this->_template_args['publish_box_extra_content'] |
|
| 2626 | - : ''; |
|
| 2627 | - if ($delete && ! empty($id)) { |
|
| 2628 | - // make sure we have a default if just true is sent. |
|
| 2629 | - $delete = ! empty($delete) ? $delete : 'delete'; |
|
| 2630 | - $delete_link_args = array($name => $id); |
|
| 2631 | - $delete = $this->get_action_link_or_button( |
|
| 2632 | - $delete, |
|
| 2633 | - $delete, |
|
| 2634 | - $delete_link_args, |
|
| 2635 | - 'submitdelete deletion', |
|
| 2636 | - '', |
|
| 2637 | - false |
|
| 2638 | - ); |
|
| 2639 | - } |
|
| 2640 | - $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : ''; |
|
| 2641 | - if (! empty($name) && ! empty($id)) { |
|
| 2642 | - $hidden_field_arr[ $name ] = array( |
|
| 2643 | - 'type' => 'hidden', |
|
| 2644 | - 'value' => $id, |
|
| 2645 | - ); |
|
| 2646 | - $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array'); |
|
| 2647 | - } else { |
|
| 2648 | - $hf = ''; |
|
| 2649 | - } |
|
| 2650 | - // add hidden field |
|
| 2651 | - $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name) |
|
| 2652 | - ? $hf[ $name ]['field'] |
|
| 2653 | - : $hf; |
|
| 2654 | - } |
|
| 2655 | - |
|
| 2656 | - |
|
| 2657 | - /** |
|
| 2658 | - * displays an error message to ppl who have javascript disabled |
|
| 2659 | - * |
|
| 2660 | - * @return void |
|
| 2661 | - */ |
|
| 2662 | - private function _display_no_javascript_warning() |
|
| 2663 | - { |
|
| 2664 | - ?> |
|
| 2472 | + } |
|
| 2473 | + |
|
| 2474 | + |
|
| 2475 | + private function _espresso_links_post_box() |
|
| 2476 | + { |
|
| 2477 | + // Hiding until we actually have content to put in here... |
|
| 2478 | + // 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'); |
|
| 2479 | + } |
|
| 2480 | + |
|
| 2481 | + |
|
| 2482 | + public function espresso_links_post_box() |
|
| 2483 | + { |
|
| 2484 | + // Hiding until we actually have content to put in here... |
|
| 2485 | + // EEH_Template::display_template( |
|
| 2486 | + // EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php' |
|
| 2487 | + // ); |
|
| 2488 | + } |
|
| 2489 | + |
|
| 2490 | + |
|
| 2491 | + protected function _espresso_sponsors_post_box() |
|
| 2492 | + { |
|
| 2493 | + if (apply_filters('FHEE_show_sponsors_meta_box', true)) { |
|
| 2494 | + add_meta_box( |
|
| 2495 | + 'espresso_sponsors_post_box', |
|
| 2496 | + esc_html__('Event Espresso Highlights', 'event_espresso'), |
|
| 2497 | + array($this, 'espresso_sponsors_post_box'), |
|
| 2498 | + $this->_wp_page_slug, |
|
| 2499 | + 'side' |
|
| 2500 | + ); |
|
| 2501 | + } |
|
| 2502 | + } |
|
| 2503 | + |
|
| 2504 | + |
|
| 2505 | + public function espresso_sponsors_post_box() |
|
| 2506 | + { |
|
| 2507 | + EEH_Template::display_template( |
|
| 2508 | + EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php' |
|
| 2509 | + ); |
|
| 2510 | + } |
|
| 2511 | + |
|
| 2512 | + |
|
| 2513 | + private function _publish_post_box() |
|
| 2514 | + { |
|
| 2515 | + $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview'; |
|
| 2516 | + // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array |
|
| 2517 | + // then we'll use that for the metabox label. |
|
| 2518 | + // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes) |
|
| 2519 | + if (! empty($this->_labels['publishbox'])) { |
|
| 2520 | + $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ] |
|
| 2521 | + : $this->_labels['publishbox']; |
|
| 2522 | + } else { |
|
| 2523 | + $box_label = esc_html__('Publish', 'event_espresso'); |
|
| 2524 | + } |
|
| 2525 | + $box_label = apply_filters( |
|
| 2526 | + 'FHEE__EE_Admin_Page___publish_post_box__box_label', |
|
| 2527 | + $box_label, |
|
| 2528 | + $this->_req_action, |
|
| 2529 | + $this |
|
| 2530 | + ); |
|
| 2531 | + add_meta_box( |
|
| 2532 | + $meta_box_ref, |
|
| 2533 | + $box_label, |
|
| 2534 | + array($this, 'editor_overview'), |
|
| 2535 | + $this->_current_screen->id, |
|
| 2536 | + 'side', |
|
| 2537 | + 'high' |
|
| 2538 | + ); |
|
| 2539 | + } |
|
| 2540 | + |
|
| 2541 | + |
|
| 2542 | + public function editor_overview() |
|
| 2543 | + { |
|
| 2544 | + // if we have extra content set let's add it in if not make sure its empty |
|
| 2545 | + $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) |
|
| 2546 | + ? $this->_template_args['publish_box_extra_content'] |
|
| 2547 | + : ''; |
|
| 2548 | + echo EEH_Template::display_template( |
|
| 2549 | + EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php', |
|
| 2550 | + $this->_template_args, |
|
| 2551 | + true |
|
| 2552 | + ); |
|
| 2553 | + } |
|
| 2554 | + |
|
| 2555 | + |
|
| 2556 | + /** end of globally available metaboxes section **/ |
|
| 2557 | + |
|
| 2558 | + |
|
| 2559 | + /** |
|
| 2560 | + * Public wrapper for the protected method. Allows plugins/addons to externally call the |
|
| 2561 | + * protected method. |
|
| 2562 | + * |
|
| 2563 | + * @see $this->_set_publish_post_box_vars for param details |
|
| 2564 | + * @since 4.6.0 |
|
| 2565 | + * @param string $name |
|
| 2566 | + * @param int $id |
|
| 2567 | + * @param bool $delete |
|
| 2568 | + * @param string $save_close_redirect_URL |
|
| 2569 | + * @param bool $both_btns |
|
| 2570 | + * @throws EE_Error |
|
| 2571 | + * @throws InvalidArgumentException |
|
| 2572 | + * @throws InvalidDataTypeException |
|
| 2573 | + * @throws InvalidInterfaceException |
|
| 2574 | + */ |
|
| 2575 | + public function set_publish_post_box_vars( |
|
| 2576 | + $name = '', |
|
| 2577 | + $id = 0, |
|
| 2578 | + $delete = false, |
|
| 2579 | + $save_close_redirect_URL = '', |
|
| 2580 | + $both_btns = true |
|
| 2581 | + ) { |
|
| 2582 | + $this->_set_publish_post_box_vars( |
|
| 2583 | + $name, |
|
| 2584 | + $id, |
|
| 2585 | + $delete, |
|
| 2586 | + $save_close_redirect_URL, |
|
| 2587 | + $both_btns |
|
| 2588 | + ); |
|
| 2589 | + } |
|
| 2590 | + |
|
| 2591 | + |
|
| 2592 | + /** |
|
| 2593 | + * Sets the _template_args arguments used by the _publish_post_box shortcut |
|
| 2594 | + * Note: currently there is no validation for this. However if you want the delete button, the |
|
| 2595 | + * save, and save and close buttons to work properly, then you will want to include a |
|
| 2596 | + * values for the name and id arguments. |
|
| 2597 | + * |
|
| 2598 | + * @todo Add in validation for name/id arguments. |
|
| 2599 | + * @param string $name key used for the action ID (i.e. event_id) |
|
| 2600 | + * @param int $id id attached to the item published |
|
| 2601 | + * @param string $delete page route callback for the delete action |
|
| 2602 | + * @param string $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed |
|
| 2603 | + * @param boolean $both_btns whether to display BOTH the "Save & Close" and "Save" buttons or just |
|
| 2604 | + * the Save button |
|
| 2605 | + * @throws EE_Error |
|
| 2606 | + * @throws InvalidArgumentException |
|
| 2607 | + * @throws InvalidDataTypeException |
|
| 2608 | + * @throws InvalidInterfaceException |
|
| 2609 | + */ |
|
| 2610 | + protected function _set_publish_post_box_vars( |
|
| 2611 | + $name = '', |
|
| 2612 | + $id = 0, |
|
| 2613 | + $delete = '', |
|
| 2614 | + $save_close_redirect_URL = '', |
|
| 2615 | + $both_btns = true |
|
| 2616 | + ) { |
|
| 2617 | + // if Save & Close, use a custom redirect URL or default to the main page? |
|
| 2618 | + $save_close_redirect_URL = ! empty($save_close_redirect_URL) |
|
| 2619 | + ? $save_close_redirect_URL |
|
| 2620 | + : $this->_admin_base_url; |
|
| 2621 | + // create the Save & Close and Save buttons |
|
| 2622 | + $this->_set_save_buttons($both_btns, array(), array(), $save_close_redirect_URL); |
|
| 2623 | + // if we have extra content set let's add it in if not make sure its empty |
|
| 2624 | + $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) |
|
| 2625 | + ? $this->_template_args['publish_box_extra_content'] |
|
| 2626 | + : ''; |
|
| 2627 | + if ($delete && ! empty($id)) { |
|
| 2628 | + // make sure we have a default if just true is sent. |
|
| 2629 | + $delete = ! empty($delete) ? $delete : 'delete'; |
|
| 2630 | + $delete_link_args = array($name => $id); |
|
| 2631 | + $delete = $this->get_action_link_or_button( |
|
| 2632 | + $delete, |
|
| 2633 | + $delete, |
|
| 2634 | + $delete_link_args, |
|
| 2635 | + 'submitdelete deletion', |
|
| 2636 | + '', |
|
| 2637 | + false |
|
| 2638 | + ); |
|
| 2639 | + } |
|
| 2640 | + $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : ''; |
|
| 2641 | + if (! empty($name) && ! empty($id)) { |
|
| 2642 | + $hidden_field_arr[ $name ] = array( |
|
| 2643 | + 'type' => 'hidden', |
|
| 2644 | + 'value' => $id, |
|
| 2645 | + ); |
|
| 2646 | + $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array'); |
|
| 2647 | + } else { |
|
| 2648 | + $hf = ''; |
|
| 2649 | + } |
|
| 2650 | + // add hidden field |
|
| 2651 | + $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name) |
|
| 2652 | + ? $hf[ $name ]['field'] |
|
| 2653 | + : $hf; |
|
| 2654 | + } |
|
| 2655 | + |
|
| 2656 | + |
|
| 2657 | + /** |
|
| 2658 | + * displays an error message to ppl who have javascript disabled |
|
| 2659 | + * |
|
| 2660 | + * @return void |
|
| 2661 | + */ |
|
| 2662 | + private function _display_no_javascript_warning() |
|
| 2663 | + { |
|
| 2664 | + ?> |
|
| 2665 | 2665 | <noscript> |
| 2666 | 2666 | <div id="no-js-message" class="error"> |
| 2667 | 2667 | <p style="font-size:1.3em;"> |
| 2668 | 2668 | <span style="color:red;"><?php esc_html_e('Warning!', 'event_espresso'); ?></span> |
| 2669 | 2669 | <?php esc_html_e( |
| 2670 | - '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.', |
|
| 2671 | - 'event_espresso' |
|
| 2672 | - ); ?> |
|
| 2670 | + '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.', |
|
| 2671 | + 'event_espresso' |
|
| 2672 | + ); ?> |
|
| 2673 | 2673 | </p> |
| 2674 | 2674 | </div> |
| 2675 | 2675 | </noscript> |
| 2676 | 2676 | <?php |
| 2677 | - } |
|
| 2678 | - |
|
| 2679 | - |
|
| 2680 | - /** |
|
| 2681 | - * displays espresso success and/or error notices |
|
| 2682 | - * |
|
| 2683 | - * @return void |
|
| 2684 | - */ |
|
| 2685 | - private function _display_espresso_notices() |
|
| 2686 | - { |
|
| 2687 | - $notices = $this->_get_transient(true); |
|
| 2688 | - echo stripslashes($notices); |
|
| 2689 | - } |
|
| 2690 | - |
|
| 2691 | - |
|
| 2692 | - /** |
|
| 2693 | - * spinny things pacify the masses |
|
| 2694 | - * |
|
| 2695 | - * @return void |
|
| 2696 | - */ |
|
| 2697 | - protected function _add_admin_page_ajax_loading_img() |
|
| 2698 | - { |
|
| 2699 | - ?> |
|
| 2677 | + } |
|
| 2678 | + |
|
| 2679 | + |
|
| 2680 | + /** |
|
| 2681 | + * displays espresso success and/or error notices |
|
| 2682 | + * |
|
| 2683 | + * @return void |
|
| 2684 | + */ |
|
| 2685 | + private function _display_espresso_notices() |
|
| 2686 | + { |
|
| 2687 | + $notices = $this->_get_transient(true); |
|
| 2688 | + echo stripslashes($notices); |
|
| 2689 | + } |
|
| 2690 | + |
|
| 2691 | + |
|
| 2692 | + /** |
|
| 2693 | + * spinny things pacify the masses |
|
| 2694 | + * |
|
| 2695 | + * @return void |
|
| 2696 | + */ |
|
| 2697 | + protected function _add_admin_page_ajax_loading_img() |
|
| 2698 | + { |
|
| 2699 | + ?> |
|
| 2700 | 2700 | <div id="espresso-ajax-loading" class="ajax-loading-grey"> |
| 2701 | 2701 | <span class="ee-spinner ee-spin"></span><span class="hidden"><?php |
| 2702 | - esc_html_e('loading...', 'event_espresso'); ?></span> |
|
| 2702 | + esc_html_e('loading...', 'event_espresso'); ?></span> |
|
| 2703 | 2703 | </div> |
| 2704 | 2704 | <?php |
| 2705 | - } |
|
| 2705 | + } |
|
| 2706 | 2706 | |
| 2707 | 2707 | |
| 2708 | - /** |
|
| 2709 | - * add admin page overlay for modal boxes |
|
| 2710 | - * |
|
| 2711 | - * @return void |
|
| 2712 | - */ |
|
| 2713 | - protected function _add_admin_page_overlay() |
|
| 2714 | - { |
|
| 2715 | - ?> |
|
| 2708 | + /** |
|
| 2709 | + * add admin page overlay for modal boxes |
|
| 2710 | + * |
|
| 2711 | + * @return void |
|
| 2712 | + */ |
|
| 2713 | + protected function _add_admin_page_overlay() |
|
| 2714 | + { |
|
| 2715 | + ?> |
|
| 2716 | 2716 | <div id="espresso-admin-page-overlay-dv" class=""></div> |
| 2717 | 2717 | <?php |
| 2718 | - } |
|
| 2719 | - |
|
| 2720 | - |
|
| 2721 | - /** |
|
| 2722 | - * facade for add_meta_box |
|
| 2723 | - * |
|
| 2724 | - * @param string $action where the metabox get's displayed |
|
| 2725 | - * @param string $title Title of Metabox (output in metabox header) |
|
| 2726 | - * @param string $callback If not empty and $create_fun is set to false then we'll use a custom callback |
|
| 2727 | - * instead of the one created in here. |
|
| 2728 | - * @param array $callback_args an array of args supplied for the metabox |
|
| 2729 | - * @param string $column what metabox column |
|
| 2730 | - * @param string $priority give this metabox a priority (using accepted priorities for wp meta boxes) |
|
| 2731 | - * @param boolean $create_func default is true. Basically we can say we don't WANT to have the runtime function |
|
| 2732 | - * created but just set our own callback for wp's add_meta_box. |
|
| 2733 | - * @throws \DomainException |
|
| 2734 | - */ |
|
| 2735 | - public function _add_admin_page_meta_box( |
|
| 2736 | - $action, |
|
| 2737 | - $title, |
|
| 2738 | - $callback, |
|
| 2739 | - $callback_args, |
|
| 2740 | - $column = 'normal', |
|
| 2741 | - $priority = 'high', |
|
| 2742 | - $create_func = true |
|
| 2743 | - ) { |
|
| 2744 | - do_action('AHEE_log', __FILE__, __FUNCTION__, $callback); |
|
| 2745 | - // 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. |
|
| 2746 | - if (empty($callback_args) && $create_func) { |
|
| 2747 | - $callback_args = array( |
|
| 2748 | - 'template_path' => $this->_template_path, |
|
| 2749 | - 'template_args' => $this->_template_args, |
|
| 2750 | - ); |
|
| 2751 | - } |
|
| 2752 | - // 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) |
|
| 2753 | - $call_back_func = $create_func |
|
| 2754 | - ? function ($post, $metabox) { |
|
| 2755 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2756 | - echo EEH_Template::display_template( |
|
| 2757 | - $metabox['args']['template_path'], |
|
| 2758 | - $metabox['args']['template_args'], |
|
| 2759 | - true |
|
| 2760 | - ); |
|
| 2761 | - } |
|
| 2762 | - : $callback; |
|
| 2763 | - add_meta_box( |
|
| 2764 | - str_replace('_', '-', $action) . '-mbox', |
|
| 2765 | - $title, |
|
| 2766 | - $call_back_func, |
|
| 2767 | - $this->_wp_page_slug, |
|
| 2768 | - $column, |
|
| 2769 | - $priority, |
|
| 2770 | - $callback_args |
|
| 2771 | - ); |
|
| 2772 | - } |
|
| 2773 | - |
|
| 2774 | - |
|
| 2775 | - /** |
|
| 2776 | - * generates HTML wrapper for and admin details page that contains metaboxes in columns |
|
| 2777 | - * |
|
| 2778 | - * @throws DomainException |
|
| 2779 | - * @throws EE_Error |
|
| 2780 | - */ |
|
| 2781 | - public function display_admin_page_with_metabox_columns() |
|
| 2782 | - { |
|
| 2783 | - $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content']; |
|
| 2784 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2785 | - $this->_column_template_path, |
|
| 2786 | - $this->_template_args, |
|
| 2787 | - true |
|
| 2788 | - ); |
|
| 2789 | - // the final wrapper |
|
| 2790 | - $this->admin_page_wrapper(); |
|
| 2791 | - } |
|
| 2792 | - |
|
| 2793 | - |
|
| 2794 | - /** |
|
| 2795 | - * generates HTML wrapper for an admin details page |
|
| 2796 | - * |
|
| 2797 | - * @return void |
|
| 2798 | - * @throws EE_Error |
|
| 2799 | - * @throws DomainException |
|
| 2800 | - */ |
|
| 2801 | - public function display_admin_page_with_sidebar() |
|
| 2802 | - { |
|
| 2803 | - $this->_display_admin_page(true); |
|
| 2804 | - } |
|
| 2805 | - |
|
| 2806 | - |
|
| 2807 | - /** |
|
| 2808 | - * generates HTML wrapper for an admin details page (except no sidebar) |
|
| 2809 | - * |
|
| 2810 | - * @return void |
|
| 2811 | - * @throws EE_Error |
|
| 2812 | - * @throws DomainException |
|
| 2813 | - */ |
|
| 2814 | - public function display_admin_page_with_no_sidebar() |
|
| 2815 | - { |
|
| 2816 | - $this->_display_admin_page(); |
|
| 2817 | - } |
|
| 2818 | - |
|
| 2819 | - |
|
| 2820 | - /** |
|
| 2821 | - * generates HTML wrapper for an EE about admin page (no sidebar) |
|
| 2822 | - * |
|
| 2823 | - * @return void |
|
| 2824 | - * @throws EE_Error |
|
| 2825 | - * @throws DomainException |
|
| 2826 | - */ |
|
| 2827 | - public function display_about_admin_page() |
|
| 2828 | - { |
|
| 2829 | - $this->_display_admin_page(false, true); |
|
| 2830 | - } |
|
| 2831 | - |
|
| 2832 | - |
|
| 2833 | - /** |
|
| 2834 | - * display_admin_page |
|
| 2835 | - * contains the code for actually displaying an admin page |
|
| 2836 | - * |
|
| 2837 | - * @param boolean $sidebar true with sidebar, false without |
|
| 2838 | - * @param boolean $about use the about admin wrapper instead of the default. |
|
| 2839 | - * @return void |
|
| 2840 | - * @throws DomainException |
|
| 2841 | - * @throws EE_Error |
|
| 2842 | - */ |
|
| 2843 | - private function _display_admin_page($sidebar = false, $about = false) |
|
| 2844 | - { |
|
| 2845 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2846 | - // custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages. |
|
| 2847 | - do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes'); |
|
| 2848 | - // set current wp page slug - looks like: event-espresso_page_event_categories |
|
| 2849 | - // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated. |
|
| 2850 | - $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2851 | - $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route |
|
| 2852 | - ? 'poststuff' |
|
| 2853 | - : 'espresso-default-admin'; |
|
| 2854 | - $template_path = $sidebar |
|
| 2855 | - ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php' |
|
| 2856 | - : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2857 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2858 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2859 | - } |
|
| 2860 | - $template_path = ! empty($this->_column_template_path) |
|
| 2861 | - ? $this->_column_template_path : $template_path; |
|
| 2862 | - $this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content']) |
|
| 2863 | - ? $this->_template_args['admin_page_content'] |
|
| 2864 | - : ''; |
|
| 2865 | - $this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content']) |
|
| 2866 | - ? $this->_template_args['before_admin_page_content'] |
|
| 2867 | - : ''; |
|
| 2868 | - $this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content']) |
|
| 2869 | - ? $this->_template_args['after_admin_page_content'] |
|
| 2870 | - : ''; |
|
| 2871 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2872 | - $template_path, |
|
| 2873 | - $this->_template_args, |
|
| 2874 | - true |
|
| 2875 | - ); |
|
| 2876 | - // the final template wrapper |
|
| 2877 | - $this->admin_page_wrapper($about); |
|
| 2878 | - } |
|
| 2879 | - |
|
| 2880 | - |
|
| 2881 | - /** |
|
| 2882 | - * This is used to display caf preview pages. |
|
| 2883 | - * |
|
| 2884 | - * @since 4.3.2 |
|
| 2885 | - * @param string $utm_campaign_source what is the key used for google analytics link |
|
| 2886 | - * @param bool $display_sidebar whether to use the sidebar template or the full template for the page. TRUE |
|
| 2887 | - * = SHOW sidebar, FALSE = no sidebar. Default no sidebar. |
|
| 2888 | - * @return void |
|
| 2889 | - * @throws DomainException |
|
| 2890 | - * @throws EE_Error |
|
| 2891 | - * @throws InvalidArgumentException |
|
| 2892 | - * @throws InvalidDataTypeException |
|
| 2893 | - * @throws InvalidInterfaceException |
|
| 2894 | - */ |
|
| 2895 | - public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true) |
|
| 2896 | - { |
|
| 2897 | - // let's generate a default preview action button if there isn't one already present. |
|
| 2898 | - $this->_labels['buttons']['buy_now'] = esc_html__( |
|
| 2899 | - 'Upgrade to Event Espresso 4 Right Now', |
|
| 2900 | - 'event_espresso' |
|
| 2901 | - ); |
|
| 2902 | - $buy_now_url = add_query_arg( |
|
| 2903 | - array( |
|
| 2904 | - 'ee_ver' => 'ee4', |
|
| 2905 | - 'utm_source' => 'ee4_plugin_admin', |
|
| 2906 | - 'utm_medium' => 'link', |
|
| 2907 | - 'utm_campaign' => $utm_campaign_source, |
|
| 2908 | - 'utm_content' => 'buy_now_button', |
|
| 2909 | - ), |
|
| 2910 | - 'http://eventespresso.com/pricing/' |
|
| 2911 | - ); |
|
| 2912 | - $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button']) |
|
| 2913 | - ? $this->get_action_link_or_button( |
|
| 2914 | - '', |
|
| 2915 | - 'buy_now', |
|
| 2916 | - array(), |
|
| 2917 | - 'button-primary button-large', |
|
| 2918 | - $buy_now_url, |
|
| 2919 | - true |
|
| 2920 | - ) |
|
| 2921 | - : $this->_template_args['preview_action_button']; |
|
| 2922 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2923 | - EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php', |
|
| 2924 | - $this->_template_args, |
|
| 2925 | - true |
|
| 2926 | - ); |
|
| 2927 | - $this->_display_admin_page($display_sidebar); |
|
| 2928 | - } |
|
| 2929 | - |
|
| 2930 | - |
|
| 2931 | - /** |
|
| 2932 | - * display_admin_list_table_page_with_sidebar |
|
| 2933 | - * generates HTML wrapper for an admin_page with list_table |
|
| 2934 | - * |
|
| 2935 | - * @return void |
|
| 2936 | - * @throws EE_Error |
|
| 2937 | - * @throws DomainException |
|
| 2938 | - */ |
|
| 2939 | - public function display_admin_list_table_page_with_sidebar() |
|
| 2940 | - { |
|
| 2941 | - $this->_display_admin_list_table_page(true); |
|
| 2942 | - } |
|
| 2943 | - |
|
| 2944 | - |
|
| 2945 | - /** |
|
| 2946 | - * display_admin_list_table_page_with_no_sidebar |
|
| 2947 | - * generates HTML wrapper for an admin_page with list_table (but with no sidebar) |
|
| 2948 | - * |
|
| 2949 | - * @return void |
|
| 2950 | - * @throws EE_Error |
|
| 2951 | - * @throws DomainException |
|
| 2952 | - */ |
|
| 2953 | - public function display_admin_list_table_page_with_no_sidebar() |
|
| 2954 | - { |
|
| 2955 | - $this->_display_admin_list_table_page(); |
|
| 2956 | - } |
|
| 2957 | - |
|
| 2958 | - |
|
| 2959 | - /** |
|
| 2960 | - * generates html wrapper for an admin_list_table page |
|
| 2961 | - * |
|
| 2962 | - * @param boolean $sidebar whether to display with sidebar or not. |
|
| 2963 | - * @return void |
|
| 2964 | - * @throws DomainException |
|
| 2965 | - * @throws EE_Error |
|
| 2966 | - */ |
|
| 2967 | - private function _display_admin_list_table_page($sidebar = false) |
|
| 2968 | - { |
|
| 2969 | - // setup search attributes |
|
| 2970 | - $this->_set_search_attributes(); |
|
| 2971 | - $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2972 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php'; |
|
| 2973 | - $this->_template_args['table_url'] = defined('DOING_AJAX') |
|
| 2974 | - ? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url) |
|
| 2975 | - : add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url); |
|
| 2976 | - $this->_template_args['list_table'] = $this->_list_table_object; |
|
| 2977 | - $this->_template_args['current_route'] = $this->_req_action; |
|
| 2978 | - $this->_template_args['list_table_class'] = get_class($this->_list_table_object); |
|
| 2979 | - $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback(); |
|
| 2980 | - if (! empty($ajax_sorting_callback)) { |
|
| 2981 | - $sortable_list_table_form_fields = wp_nonce_field( |
|
| 2982 | - $ajax_sorting_callback . '_nonce', |
|
| 2983 | - $ajax_sorting_callback . '_nonce', |
|
| 2984 | - false, |
|
| 2985 | - false |
|
| 2986 | - ); |
|
| 2987 | - $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' |
|
| 2988 | - . $this->page_slug |
|
| 2989 | - . '" />'; |
|
| 2990 | - $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' |
|
| 2991 | - . $ajax_sorting_callback |
|
| 2992 | - . '" />'; |
|
| 2993 | - } else { |
|
| 2994 | - $sortable_list_table_form_fields = ''; |
|
| 2995 | - } |
|
| 2996 | - $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields; |
|
| 2997 | - $hidden_form_fields = isset($this->_template_args['list_table_hidden_fields']) |
|
| 2998 | - ? $this->_template_args['list_table_hidden_fields'] |
|
| 2999 | - : ''; |
|
| 3000 | - $nonce_ref = $this->_req_action . '_nonce'; |
|
| 3001 | - $hidden_form_fields .= '<input type="hidden" name="' |
|
| 3002 | - . $nonce_ref |
|
| 3003 | - . '" value="' |
|
| 3004 | - . wp_create_nonce($nonce_ref) |
|
| 3005 | - . '">'; |
|
| 3006 | - $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
|
| 3007 | - // display message about search results? |
|
| 3008 | - $this->_template_args['before_list_table'] .= ! empty($this->_req_data['s']) |
|
| 3009 | - ? '<p class="ee-search-results">' . sprintf( |
|
| 3010 | - esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'), |
|
| 3011 | - trim($this->_req_data['s'], '%') |
|
| 3012 | - ) . '</p>' |
|
| 3013 | - : ''; |
|
| 3014 | - // filter before_list_table template arg |
|
| 3015 | - $this->_template_args['before_list_table'] = apply_filters( |
|
| 3016 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg', |
|
| 3017 | - $this->_template_args['before_list_table'], |
|
| 3018 | - $this->page_slug, |
|
| 3019 | - $this->_req_data, |
|
| 3020 | - $this->_req_action |
|
| 3021 | - ); |
|
| 3022 | - // convert to array and filter again |
|
| 3023 | - // arrays are easier to inject new items in a specific location, |
|
| 3024 | - // but would not be backwards compatible, so we have to add a new filter |
|
| 3025 | - $this->_template_args['before_list_table'] = implode( |
|
| 3026 | - " \n", |
|
| 3027 | - (array) apply_filters( |
|
| 3028 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array', |
|
| 3029 | - (array) $this->_template_args['before_list_table'], |
|
| 3030 | - $this->page_slug, |
|
| 3031 | - $this->_req_data, |
|
| 3032 | - $this->_req_action |
|
| 3033 | - ) |
|
| 3034 | - ); |
|
| 3035 | - // filter after_list_table template arg |
|
| 3036 | - $this->_template_args['after_list_table'] = apply_filters( |
|
| 3037 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg', |
|
| 3038 | - $this->_template_args['after_list_table'], |
|
| 3039 | - $this->page_slug, |
|
| 3040 | - $this->_req_data, |
|
| 3041 | - $this->_req_action |
|
| 3042 | - ); |
|
| 3043 | - // convert to array and filter again |
|
| 3044 | - // arrays are easier to inject new items in a specific location, |
|
| 3045 | - // but would not be backwards compatible, so we have to add a new filter |
|
| 3046 | - $this->_template_args['after_list_table'] = implode( |
|
| 3047 | - " \n", |
|
| 3048 | - (array) apply_filters( |
|
| 3049 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array', |
|
| 3050 | - (array) $this->_template_args['after_list_table'], |
|
| 3051 | - $this->page_slug, |
|
| 3052 | - $this->_req_data, |
|
| 3053 | - $this->_req_action |
|
| 3054 | - ) |
|
| 3055 | - ); |
|
| 3056 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 3057 | - $template_path, |
|
| 3058 | - $this->_template_args, |
|
| 3059 | - true |
|
| 3060 | - ); |
|
| 3061 | - // the final template wrapper |
|
| 3062 | - if ($sidebar) { |
|
| 3063 | - $this->display_admin_page_with_sidebar(); |
|
| 3064 | - } else { |
|
| 3065 | - $this->display_admin_page_with_no_sidebar(); |
|
| 3066 | - } |
|
| 3067 | - } |
|
| 3068 | - |
|
| 3069 | - |
|
| 3070 | - /** |
|
| 3071 | - * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the |
|
| 3072 | - * html string for the legend. |
|
| 3073 | - * $items are expected in an array in the following format: |
|
| 3074 | - * $legend_items = array( |
|
| 3075 | - * 'item_id' => array( |
|
| 3076 | - * 'icon' => 'http://url_to_icon_being_described.png', |
|
| 3077 | - * 'desc' => esc_html__('localized description of item'); |
|
| 3078 | - * ) |
|
| 3079 | - * ); |
|
| 3080 | - * |
|
| 3081 | - * @param array $items see above for format of array |
|
| 3082 | - * @return string html string of legend |
|
| 3083 | - * @throws DomainException |
|
| 3084 | - */ |
|
| 3085 | - protected function _display_legend($items) |
|
| 3086 | - { |
|
| 3087 | - $this->_template_args['items'] = apply_filters( |
|
| 3088 | - 'FHEE__EE_Admin_Page___display_legend__items', |
|
| 3089 | - (array) $items, |
|
| 3090 | - $this |
|
| 3091 | - ); |
|
| 3092 | - return EEH_Template::display_template( |
|
| 3093 | - EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php', |
|
| 3094 | - $this->_template_args, |
|
| 3095 | - true |
|
| 3096 | - ); |
|
| 3097 | - } |
|
| 3098 | - |
|
| 3099 | - |
|
| 3100 | - /** |
|
| 3101 | - * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect |
|
| 3102 | - * The returned json object is created from an array in the following format: |
|
| 3103 | - * array( |
|
| 3104 | - * 'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early), |
|
| 3105 | - * 'success' => FALSE, //(default FALSE) - contains any special success message. |
|
| 3106 | - * 'notices' => '', // - contains any EE_Error formatted notices |
|
| 3107 | - * 'content' => 'string can be html', //this is a string of formatted content (can be html) |
|
| 3108 | - * 'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. |
|
| 3109 | - * We're also going to include the template args with every package (so js can pick out any specific template args |
|
| 3110 | - * that might be included in here) |
|
| 3111 | - * ) |
|
| 3112 | - * The json object is populated by whatever is set in the $_template_args property. |
|
| 3113 | - * |
|
| 3114 | - * @param bool $sticky_notices Used to indicate whether you want to ensure notices are added to a transient |
|
| 3115 | - * instead of displayed. |
|
| 3116 | - * @param array $notices_arguments Use this to pass any additional args on to the _process_notices. |
|
| 3117 | - * @return void |
|
| 3118 | - * @throws EE_Error |
|
| 3119 | - */ |
|
| 3120 | - protected function _return_json($sticky_notices = false, $notices_arguments = array()) |
|
| 3121 | - { |
|
| 3122 | - // make sure any EE_Error notices have been handled. |
|
| 3123 | - $this->_process_notices($notices_arguments, true, $sticky_notices); |
|
| 3124 | - $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array(); |
|
| 3125 | - unset($this->_template_args['data']); |
|
| 3126 | - $json = array( |
|
| 3127 | - 'error' => isset($this->_template_args['error']) ? $this->_template_args['error'] : false, |
|
| 3128 | - 'success' => isset($this->_template_args['success']) ? $this->_template_args['success'] : false, |
|
| 3129 | - 'errors' => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false, |
|
| 3130 | - 'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false, |
|
| 3131 | - 'notices' => EE_Error::get_notices(), |
|
| 3132 | - 'content' => isset($this->_template_args['admin_page_content']) |
|
| 3133 | - ? $this->_template_args['admin_page_content'] : '', |
|
| 3134 | - 'data' => array_merge($data, array('template_args' => $this->_template_args)), |
|
| 3135 | - 'isEEajax' => true |
|
| 3136 | - // special flag so any ajax.Success methods in js can identify this return package as a EEajax package. |
|
| 3137 | - ); |
|
| 3138 | - // make sure there are no php errors or headers_sent. Then we can set correct json header. |
|
| 3139 | - if (null === error_get_last() || ! headers_sent()) { |
|
| 3140 | - header('Content-Type: application/json; charset=UTF-8'); |
|
| 3141 | - } |
|
| 3142 | - echo wp_json_encode($json); |
|
| 3143 | - exit(); |
|
| 3144 | - } |
|
| 3145 | - |
|
| 3146 | - |
|
| 3147 | - /** |
|
| 3148 | - * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax) |
|
| 3149 | - * |
|
| 3150 | - * @return void |
|
| 3151 | - * @throws EE_Error |
|
| 3152 | - */ |
|
| 3153 | - public function return_json() |
|
| 3154 | - { |
|
| 3155 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 3156 | - $this->_return_json(); |
|
| 3157 | - } else { |
|
| 3158 | - throw new EE_Error( |
|
| 3159 | - sprintf( |
|
| 3160 | - esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), |
|
| 3161 | - __FUNCTION__ |
|
| 3162 | - ) |
|
| 3163 | - ); |
|
| 3164 | - } |
|
| 3165 | - } |
|
| 3166 | - |
|
| 3167 | - |
|
| 3168 | - /** |
|
| 3169 | - * This provides a way for child hook classes to send along themselves by reference so methods/properties within |
|
| 3170 | - * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property. |
|
| 3171 | - * |
|
| 3172 | - * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child |
|
| 3173 | - */ |
|
| 3174 | - public function set_hook_object(EE_Admin_Hooks $hook_obj) |
|
| 3175 | - { |
|
| 3176 | - $this->_hook_obj = $hook_obj; |
|
| 3177 | - } |
|
| 3178 | - |
|
| 3179 | - |
|
| 3180 | - /** |
|
| 3181 | - * generates HTML wrapper with Tabbed nav for an admin page |
|
| 3182 | - * |
|
| 3183 | - * @param boolean $about whether to use the special about page wrapper or default. |
|
| 3184 | - * @return void |
|
| 3185 | - * @throws DomainException |
|
| 3186 | - * @throws EE_Error |
|
| 3187 | - */ |
|
| 3188 | - public function admin_page_wrapper($about = false) |
|
| 3189 | - { |
|
| 3190 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3191 | - $this->_nav_tabs = $this->_get_main_nav_tabs(); |
|
| 3192 | - $this->_template_args['nav_tabs'] = $this->_nav_tabs; |
|
| 3193 | - $this->_template_args['admin_page_title'] = $this->_admin_page_title; |
|
| 3194 | - $this->_template_args['before_admin_page_content'] = apply_filters( |
|
| 3195 | - "FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}", |
|
| 3196 | - isset($this->_template_args['before_admin_page_content']) |
|
| 3197 | - ? $this->_template_args['before_admin_page_content'] |
|
| 3198 | - : '' |
|
| 3199 | - ); |
|
| 3200 | - $this->_template_args['after_admin_page_content'] = apply_filters( |
|
| 3201 | - "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}", |
|
| 3202 | - isset($this->_template_args['after_admin_page_content']) |
|
| 3203 | - ? $this->_template_args['after_admin_page_content'] |
|
| 3204 | - : '' |
|
| 3205 | - ); |
|
| 3206 | - $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content(); |
|
| 3207 | - // load settings page wrapper template |
|
| 3208 | - $template_path = ! defined('DOING_AJAX') |
|
| 3209 | - ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' |
|
| 3210 | - : EE_ADMIN_TEMPLATE |
|
| 3211 | - . 'admin_wrapper_ajax.template.php'; |
|
| 3212 | - // about page? |
|
| 3213 | - $template_path = $about |
|
| 3214 | - ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' |
|
| 3215 | - : $template_path; |
|
| 3216 | - if (defined('DOING_AJAX')) { |
|
| 3217 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 3218 | - $template_path, |
|
| 3219 | - $this->_template_args, |
|
| 3220 | - true |
|
| 3221 | - ); |
|
| 3222 | - $this->_return_json(); |
|
| 3223 | - } else { |
|
| 3224 | - EEH_Template::display_template($template_path, $this->_template_args); |
|
| 3225 | - } |
|
| 3226 | - } |
|
| 3227 | - |
|
| 3228 | - |
|
| 3229 | - /** |
|
| 3230 | - * This returns the admin_nav tabs html using the configuration in the _nav_tabs property |
|
| 3231 | - * |
|
| 3232 | - * @return string html |
|
| 3233 | - * @throws EE_Error |
|
| 3234 | - */ |
|
| 3235 | - protected function _get_main_nav_tabs() |
|
| 3236 | - { |
|
| 3237 | - // let's generate the html using the EEH_Tabbed_Content helper. |
|
| 3238 | - // We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute |
|
| 3239 | - // (rather than setting in the page_routes array) |
|
| 3240 | - return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs); |
|
| 3241 | - } |
|
| 3242 | - |
|
| 3243 | - |
|
| 3244 | - /** |
|
| 3245 | - * sort nav tabs |
|
| 3246 | - * |
|
| 3247 | - * @param $a |
|
| 3248 | - * @param $b |
|
| 3249 | - * @return int |
|
| 3250 | - */ |
|
| 3251 | - private function _sort_nav_tabs($a, $b) |
|
| 3252 | - { |
|
| 3253 | - if ($a['order'] === $b['order']) { |
|
| 3254 | - return 0; |
|
| 3255 | - } |
|
| 3256 | - return ($a['order'] < $b['order']) ? -1 : 1; |
|
| 3257 | - } |
|
| 3258 | - |
|
| 3259 | - |
|
| 3260 | - /** |
|
| 3261 | - * generates HTML for the forms used on admin pages |
|
| 3262 | - * |
|
| 3263 | - * @param array $input_vars - array of input field details |
|
| 3264 | - * @param string $generator (options are 'string' or 'array', basically use this to indicate which generator to |
|
| 3265 | - * use) |
|
| 3266 | - * @param bool $id |
|
| 3267 | - * @return string |
|
| 3268 | - * @uses EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php) |
|
| 3269 | - * @uses EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php) |
|
| 3270 | - */ |
|
| 3271 | - protected function _generate_admin_form_fields($input_vars = array(), $generator = 'string', $id = false) |
|
| 3272 | - { |
|
| 3273 | - $content = $generator === 'string' |
|
| 3274 | - ? EEH_Form_Fields::get_form_fields($input_vars, $id) |
|
| 3275 | - : EEH_Form_Fields::get_form_fields_array($input_vars); |
|
| 3276 | - return $content; |
|
| 3277 | - } |
|
| 3278 | - |
|
| 3279 | - |
|
| 3280 | - /** |
|
| 3281 | - * generates the "Save" and "Save & Close" buttons for edit forms |
|
| 3282 | - * |
|
| 3283 | - * @param bool $both if true then both buttons will be generated. If false then just the "Save & |
|
| 3284 | - * Close" button. |
|
| 3285 | - * @param array $text if included, generator will use the given text for the buttons ( array([0] => |
|
| 3286 | - * 'Save', [1] => 'save & close') |
|
| 3287 | - * @param array $actions if included allows us to set the actions that each button will carry out (i.e. |
|
| 3288 | - * via the "name" value in the button). We can also use this to just dump |
|
| 3289 | - * default actions by submitting some other value. |
|
| 3290 | - * @param bool|string|null $referrer if false then we just do the default action on save and close. Other wise it |
|
| 3291 | - * will use the $referrer string. IF null, then we don't do ANYTHING on save and |
|
| 3292 | - * close (normal form handling). |
|
| 3293 | - */ |
|
| 3294 | - protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null) |
|
| 3295 | - { |
|
| 3296 | - // make sure $text and $actions are in an array |
|
| 3297 | - $text = (array) $text; |
|
| 3298 | - $actions = (array) $actions; |
|
| 3299 | - $referrer_url = empty($referrer) |
|
| 3300 | - ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' |
|
| 3301 | - . $_SERVER['REQUEST_URI'] |
|
| 3302 | - . '" />' |
|
| 3303 | - : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' |
|
| 3304 | - . $referrer |
|
| 3305 | - . '" />'; |
|
| 3306 | - $button_text = ! empty($text) |
|
| 3307 | - ? $text |
|
| 3308 | - : array( |
|
| 3309 | - esc_html__('Save', 'event_espresso'), |
|
| 3310 | - esc_html__('Save and Close', 'event_espresso'), |
|
| 3311 | - ); |
|
| 3312 | - $default_names = array('save', 'save_and_close'); |
|
| 3313 | - // add in a hidden index for the current page (so save and close redirects properly) |
|
| 3314 | - $this->_template_args['save_buttons'] = $referrer_url; |
|
| 3315 | - foreach ($button_text as $key => $button) { |
|
| 3316 | - $ref = $default_names[ $key ]; |
|
| 3317 | - $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' |
|
| 3318 | - . $ref |
|
| 3319 | - . '" value="' |
|
| 3320 | - . $button |
|
| 3321 | - . '" name="' |
|
| 3322 | - . (! empty($actions) ? $actions[ $key ] : $ref) |
|
| 3323 | - . '" id="' |
|
| 3324 | - . $this->_current_view . '_' . $ref |
|
| 3325 | - . '" />'; |
|
| 3326 | - if (! $both) { |
|
| 3327 | - break; |
|
| 3328 | - } |
|
| 3329 | - } |
|
| 3330 | - } |
|
| 3331 | - |
|
| 3332 | - |
|
| 3333 | - /** |
|
| 3334 | - * Wrapper for the protected function. Allows plugins/addons to call this to set the form tags. |
|
| 3335 | - * |
|
| 3336 | - * @see $this->_set_add_edit_form_tags() for details on params |
|
| 3337 | - * @since 4.6.0 |
|
| 3338 | - * @param string $route |
|
| 3339 | - * @param array $additional_hidden_fields |
|
| 3340 | - */ |
|
| 3341 | - public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array()) |
|
| 3342 | - { |
|
| 3343 | - $this->_set_add_edit_form_tags($route, $additional_hidden_fields); |
|
| 3344 | - } |
|
| 3345 | - |
|
| 3346 | - |
|
| 3347 | - /** |
|
| 3348 | - * set form open and close tags on add/edit pages. |
|
| 3349 | - * |
|
| 3350 | - * @param string $route the route you want the form to direct to |
|
| 3351 | - * @param array $additional_hidden_fields any additional hidden fields required in the form header |
|
| 3352 | - * @return void |
|
| 3353 | - */ |
|
| 3354 | - protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array()) |
|
| 3355 | - { |
|
| 3356 | - if (empty($route)) { |
|
| 3357 | - $user_msg = esc_html__( |
|
| 3358 | - 'An error occurred. No action was set for this page\'s form.', |
|
| 3359 | - 'event_espresso' |
|
| 3360 | - ); |
|
| 3361 | - $dev_msg = $user_msg . "\n" |
|
| 3362 | - . sprintf( |
|
| 3363 | - esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'), |
|
| 3364 | - __FUNCTION__, |
|
| 3365 | - __CLASS__ |
|
| 3366 | - ); |
|
| 3367 | - EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 3368 | - } |
|
| 3369 | - // open form |
|
| 3370 | - $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' |
|
| 3371 | - . $this->_admin_base_url |
|
| 3372 | - . '" id="' |
|
| 3373 | - . $route |
|
| 3374 | - . '_event_form" >'; |
|
| 3375 | - // add nonce |
|
| 3376 | - $nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false); |
|
| 3377 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce; |
|
| 3378 | - // add REQUIRED form action |
|
| 3379 | - $hidden_fields = array( |
|
| 3380 | - 'action' => array('type' => 'hidden', 'value' => $route), |
|
| 3381 | - ); |
|
| 3382 | - // merge arrays |
|
| 3383 | - $hidden_fields = is_array($additional_hidden_fields) |
|
| 3384 | - ? array_merge($hidden_fields, $additional_hidden_fields) |
|
| 3385 | - : $hidden_fields; |
|
| 3386 | - // generate form fields |
|
| 3387 | - $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array'); |
|
| 3388 | - // add fields to form |
|
| 3389 | - foreach ((array) $form_fields as $field_name => $form_field) { |
|
| 3390 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field']; |
|
| 3391 | - } |
|
| 3392 | - // close form |
|
| 3393 | - $this->_template_args['after_admin_page_content'] = '</form>'; |
|
| 3394 | - } |
|
| 3395 | - |
|
| 3396 | - |
|
| 3397 | - /** |
|
| 3398 | - * Public Wrapper for _redirect_after_action() method since its |
|
| 3399 | - * discovered it would be useful for external code to have access. |
|
| 3400 | - * |
|
| 3401 | - * @see EE_Admin_Page::_redirect_after_action() for params. |
|
| 3402 | - * @since 4.5.0 |
|
| 3403 | - * @param bool $success |
|
| 3404 | - * @param string $what |
|
| 3405 | - * @param string $action_desc |
|
| 3406 | - * @param array $query_args |
|
| 3407 | - * @param bool $override_overwrite |
|
| 3408 | - * @throws EE_Error |
|
| 3409 | - */ |
|
| 3410 | - public function redirect_after_action( |
|
| 3411 | - $success = false, |
|
| 3412 | - $what = 'item', |
|
| 3413 | - $action_desc = 'processed', |
|
| 3414 | - $query_args = array(), |
|
| 3415 | - $override_overwrite = false |
|
| 3416 | - ) { |
|
| 3417 | - $this->_redirect_after_action( |
|
| 3418 | - $success, |
|
| 3419 | - $what, |
|
| 3420 | - $action_desc, |
|
| 3421 | - $query_args, |
|
| 3422 | - $override_overwrite |
|
| 3423 | - ); |
|
| 3424 | - } |
|
| 3425 | - |
|
| 3426 | - |
|
| 3427 | - /** |
|
| 3428 | - * Helper method for merging existing request data with the returned redirect url. |
|
| 3429 | - * |
|
| 3430 | - * This is typically used for redirects after an action so that if the original view was a filtered view those |
|
| 3431 | - * filters are still applied. |
|
| 3432 | - * |
|
| 3433 | - * @param array $new_route_data |
|
| 3434 | - * @return array |
|
| 3435 | - */ |
|
| 3436 | - protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data) |
|
| 3437 | - { |
|
| 3438 | - foreach ($this->_req_data as $ref => $value) { |
|
| 3439 | - // unset nonces |
|
| 3440 | - if (strpos($ref, 'nonce') !== false) { |
|
| 3441 | - unset($this->_req_data[ $ref ]); |
|
| 3442 | - continue; |
|
| 3443 | - } |
|
| 3444 | - // urlencode values. |
|
| 3445 | - $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value); |
|
| 3446 | - $this->_req_data[ $ref ] = $value; |
|
| 3447 | - } |
|
| 3448 | - return array_merge($this->_req_data, $new_route_data); |
|
| 3449 | - } |
|
| 3450 | - |
|
| 3451 | - |
|
| 3452 | - /** |
|
| 3453 | - * _redirect_after_action |
|
| 3454 | - * |
|
| 3455 | - * @param int $success - whether success was for two or more records, or just one, or none |
|
| 3456 | - * @param string $what - what the action was performed on |
|
| 3457 | - * @param string $action_desc - what was done ie: updated, deleted, etc |
|
| 3458 | - * @param array $query_args - an array of query_args to be added to the URL to redirect to after the admin |
|
| 3459 | - * action is completed |
|
| 3460 | - * @param BOOL $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to |
|
| 3461 | - * override this so that they show. |
|
| 3462 | - * @return void |
|
| 3463 | - * @throws EE_Error |
|
| 3464 | - */ |
|
| 3465 | - protected function _redirect_after_action( |
|
| 3466 | - $success = 0, |
|
| 3467 | - $what = 'item', |
|
| 3468 | - $action_desc = 'processed', |
|
| 3469 | - $query_args = array(), |
|
| 3470 | - $override_overwrite = false |
|
| 3471 | - ) { |
|
| 3472 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3473 | - // class name for actions/filters. |
|
| 3474 | - $classname = get_class($this); |
|
| 3475 | - // set redirect url. |
|
| 3476 | - // Note if there is a "page" index in the $query_args then we go with vanilla admin.php route, |
|
| 3477 | - // otherwise we go with whatever is set as the _admin_base_url |
|
| 3478 | - $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url; |
|
| 3479 | - $notices = EE_Error::get_notices(false); |
|
| 3480 | - // overwrite default success messages //BUT ONLY if overwrite not overridden |
|
| 3481 | - if (! $override_overwrite || ! empty($notices['errors'])) { |
|
| 3482 | - EE_Error::overwrite_success(); |
|
| 3483 | - } |
|
| 3484 | - if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) { |
|
| 3485 | - // how many records affected ? more than one record ? or just one ? |
|
| 3486 | - if ($success > 1) { |
|
| 3487 | - // set plural msg |
|
| 3488 | - EE_Error::add_success( |
|
| 3489 | - sprintf( |
|
| 3490 | - esc_html__('The "%s" have been successfully %s.', 'event_espresso'), |
|
| 3491 | - $what, |
|
| 3492 | - $action_desc |
|
| 3493 | - ), |
|
| 3494 | - __FILE__, |
|
| 3495 | - __FUNCTION__, |
|
| 3496 | - __LINE__ |
|
| 3497 | - ); |
|
| 3498 | - } elseif ($success === 1) { |
|
| 3499 | - // set singular msg |
|
| 3500 | - EE_Error::add_success( |
|
| 3501 | - sprintf( |
|
| 3502 | - esc_html__('The "%s" has been successfully %s.', 'event_espresso'), |
|
| 3503 | - $what, |
|
| 3504 | - $action_desc |
|
| 3505 | - ), |
|
| 3506 | - __FILE__, |
|
| 3507 | - __FUNCTION__, |
|
| 3508 | - __LINE__ |
|
| 3509 | - ); |
|
| 3510 | - } |
|
| 3511 | - } |
|
| 3512 | - // check that $query_args isn't something crazy |
|
| 3513 | - if (! is_array($query_args)) { |
|
| 3514 | - $query_args = array(); |
|
| 3515 | - } |
|
| 3516 | - /** |
|
| 3517 | - * Allow injecting actions before the query_args are modified for possible different |
|
| 3518 | - * redirections on save and close actions |
|
| 3519 | - * |
|
| 3520 | - * @since 4.2.0 |
|
| 3521 | - * @param array $query_args The original query_args array coming into the |
|
| 3522 | - * method. |
|
| 3523 | - */ |
|
| 3524 | - do_action( |
|
| 3525 | - "AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}", |
|
| 3526 | - $query_args |
|
| 3527 | - ); |
|
| 3528 | - // calculate where we're going (if we have a "save and close" button pushed) |
|
| 3529 | - if (isset($this->_req_data['save_and_close'], $this->_req_data['save_and_close_referrer'])) { |
|
| 3530 | - // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce |
|
| 3531 | - $parsed_url = parse_url($this->_req_data['save_and_close_referrer']); |
|
| 3532 | - // regenerate query args array from referrer URL |
|
| 3533 | - parse_str($parsed_url['query'], $query_args); |
|
| 3534 | - // correct page and action will be in the query args now |
|
| 3535 | - $redirect_url = admin_url('admin.php'); |
|
| 3536 | - } |
|
| 3537 | - // merge any default query_args set in _default_route_query_args property |
|
| 3538 | - if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
| 3539 | - $args_to_merge = array(); |
|
| 3540 | - foreach ($this->_default_route_query_args as $query_param => $query_value) { |
|
| 3541 | - // is there a wp_referer array in our _default_route_query_args property? |
|
| 3542 | - if ($query_param === 'wp_referer') { |
|
| 3543 | - $query_value = (array) $query_value; |
|
| 3544 | - foreach ($query_value as $reference => $value) { |
|
| 3545 | - if (strpos($reference, 'nonce') !== false) { |
|
| 3546 | - continue; |
|
| 3547 | - } |
|
| 3548 | - // finally we will override any arguments in the referer with |
|
| 3549 | - // what might be set on the _default_route_query_args array. |
|
| 3550 | - if (isset($this->_default_route_query_args[ $reference ])) { |
|
| 3551 | - $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]); |
|
| 3552 | - } else { |
|
| 3553 | - $args_to_merge[ $reference ] = urlencode($value); |
|
| 3554 | - } |
|
| 3555 | - } |
|
| 3556 | - continue; |
|
| 3557 | - } |
|
| 3558 | - $args_to_merge[ $query_param ] = $query_value; |
|
| 3559 | - } |
|
| 3560 | - // now let's merge these arguments but override with what was specifically sent in to the |
|
| 3561 | - // redirect. |
|
| 3562 | - $query_args = array_merge($args_to_merge, $query_args); |
|
| 3563 | - } |
|
| 3564 | - $this->_process_notices($query_args); |
|
| 3565 | - // generate redirect url |
|
| 3566 | - // if redirecting to anything other than the main page, add a nonce |
|
| 3567 | - if (isset($query_args['action'])) { |
|
| 3568 | - // manually generate wp_nonce and merge that with the query vars |
|
| 3569 | - // becuz the wp_nonce_url function wrecks havoc on some vars |
|
| 3570 | - $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 3571 | - } |
|
| 3572 | - // we're adding some hooks and filters in here for processing any things just before redirects |
|
| 3573 | - // (example: an admin page has done an insert or update and we want to run something after that). |
|
| 3574 | - do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args); |
|
| 3575 | - $redirect_url = apply_filters( |
|
| 3576 | - 'FHEE_redirect_' . $classname . $this->_req_action, |
|
| 3577 | - self::add_query_args_and_nonce($query_args, $redirect_url), |
|
| 3578 | - $query_args |
|
| 3579 | - ); |
|
| 3580 | - // check if we're doing ajax. If we are then lets just return the results and js can handle how it wants. |
|
| 3581 | - if (defined('DOING_AJAX')) { |
|
| 3582 | - $default_data = array( |
|
| 3583 | - 'close' => true, |
|
| 3584 | - 'redirect_url' => $redirect_url, |
|
| 3585 | - 'where' => 'main', |
|
| 3586 | - 'what' => 'append', |
|
| 3587 | - ); |
|
| 3588 | - $this->_template_args['success'] = $success; |
|
| 3589 | - $this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge( |
|
| 3590 | - $default_data, |
|
| 3591 | - $this->_template_args['data'] |
|
| 3592 | - ) : $default_data; |
|
| 3593 | - $this->_return_json(); |
|
| 3594 | - } |
|
| 3595 | - wp_safe_redirect($redirect_url); |
|
| 3596 | - exit(); |
|
| 3597 | - } |
|
| 3598 | - |
|
| 3599 | - |
|
| 3600 | - /** |
|
| 3601 | - * process any notices before redirecting (or returning ajax request) |
|
| 3602 | - * This method sets the $this->_template_args['notices'] attribute; |
|
| 3603 | - * |
|
| 3604 | - * @param array $query_args any query args that need to be used for notice transient ('action') |
|
| 3605 | - * @param bool $skip_route_verify This is typically used when we are processing notices REALLY early and |
|
| 3606 | - * page_routes haven't been defined yet. |
|
| 3607 | - * @param bool $sticky_notices This is used to flag that regardless of whether this is doing_ajax or not, we |
|
| 3608 | - * still save a transient for the notice. |
|
| 3609 | - * @return void |
|
| 3610 | - * @throws EE_Error |
|
| 3611 | - */ |
|
| 3612 | - protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true) |
|
| 3613 | - { |
|
| 3614 | - // first let's set individual error properties if doing_ajax and the properties aren't already set. |
|
| 3615 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 3616 | - $notices = EE_Error::get_notices(false); |
|
| 3617 | - if (empty($this->_template_args['success'])) { |
|
| 3618 | - $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false; |
|
| 3619 | - } |
|
| 3620 | - if (empty($this->_template_args['errors'])) { |
|
| 3621 | - $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false; |
|
| 3622 | - } |
|
| 3623 | - if (empty($this->_template_args['attention'])) { |
|
| 3624 | - $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false; |
|
| 3625 | - } |
|
| 3626 | - } |
|
| 3627 | - $this->_template_args['notices'] = EE_Error::get_notices(); |
|
| 3628 | - // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true) |
|
| 3629 | - if (! defined('DOING_AJAX') || $sticky_notices) { |
|
| 3630 | - $route = isset($query_args['action']) ? $query_args['action'] : 'default'; |
|
| 3631 | - $this->_add_transient( |
|
| 3632 | - $route, |
|
| 3633 | - $this->_template_args['notices'], |
|
| 3634 | - true, |
|
| 3635 | - $skip_route_verify |
|
| 3636 | - ); |
|
| 3637 | - } |
|
| 3638 | - } |
|
| 3639 | - |
|
| 3640 | - |
|
| 3641 | - /** |
|
| 3642 | - * get_action_link_or_button |
|
| 3643 | - * returns the button html for adding, editing, or deleting an item (depending on given type) |
|
| 3644 | - * |
|
| 3645 | - * @param string $action use this to indicate which action the url is generated with. |
|
| 3646 | - * @param string $type accepted strings must be defined in the $_labels['button'] array(as the key) |
|
| 3647 | - * property. |
|
| 3648 | - * @param array $extra_request if the button requires extra params you can include them in $key=>$value pairs. |
|
| 3649 | - * @param string $class Use this to give the class for the button. Defaults to 'button-primary' |
|
| 3650 | - * @param string $base_url If this is not provided |
|
| 3651 | - * the _admin_base_url will be used as the default for the button base_url. |
|
| 3652 | - * Otherwise this value will be used. |
|
| 3653 | - * @param bool $exclude_nonce If true then no nonce will be in the generated button link. |
|
| 3654 | - * @return string |
|
| 3655 | - * @throws InvalidArgumentException |
|
| 3656 | - * @throws InvalidInterfaceException |
|
| 3657 | - * @throws InvalidDataTypeException |
|
| 3658 | - * @throws EE_Error |
|
| 3659 | - */ |
|
| 3660 | - public function get_action_link_or_button( |
|
| 3661 | - $action, |
|
| 3662 | - $type = 'add', |
|
| 3663 | - $extra_request = array(), |
|
| 3664 | - $class = 'button-primary', |
|
| 3665 | - $base_url = '', |
|
| 3666 | - $exclude_nonce = false |
|
| 3667 | - ) { |
|
| 3668 | - // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along) |
|
| 3669 | - if (empty($base_url) && ! isset($this->_page_routes[ $action ])) { |
|
| 3670 | - throw new EE_Error( |
|
| 3671 | - sprintf( |
|
| 3672 | - esc_html__( |
|
| 3673 | - 'There is no page route for given action for the button. This action was given: %s', |
|
| 3674 | - 'event_espresso' |
|
| 3675 | - ), |
|
| 3676 | - $action |
|
| 3677 | - ) |
|
| 3678 | - ); |
|
| 3679 | - } |
|
| 3680 | - if (! isset($this->_labels['buttons'][ $type ])) { |
|
| 3681 | - throw new EE_Error( |
|
| 3682 | - sprintf( |
|
| 3683 | - __( |
|
| 3684 | - 'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.', |
|
| 3685 | - 'event_espresso' |
|
| 3686 | - ), |
|
| 3687 | - $type |
|
| 3688 | - ) |
|
| 3689 | - ); |
|
| 3690 | - } |
|
| 3691 | - // finally check user access for this button. |
|
| 3692 | - $has_access = $this->check_user_access($action, true); |
|
| 3693 | - if (! $has_access) { |
|
| 3694 | - return ''; |
|
| 3695 | - } |
|
| 3696 | - $_base_url = ! $base_url ? $this->_admin_base_url : $base_url; |
|
| 3697 | - $query_args = array( |
|
| 3698 | - 'action' => $action, |
|
| 3699 | - ); |
|
| 3700 | - // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten. |
|
| 3701 | - if (! empty($extra_request)) { |
|
| 3702 | - $query_args = array_merge($extra_request, $query_args); |
|
| 3703 | - } |
|
| 3704 | - $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce); |
|
| 3705 | - return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class); |
|
| 3706 | - } |
|
| 3707 | - |
|
| 3708 | - |
|
| 3709 | - /** |
|
| 3710 | - * _per_page_screen_option |
|
| 3711 | - * Utility function for adding in a per_page_option in the screen_options_dropdown. |
|
| 3712 | - * |
|
| 3713 | - * @return void |
|
| 3714 | - * @throws InvalidArgumentException |
|
| 3715 | - * @throws InvalidInterfaceException |
|
| 3716 | - * @throws InvalidDataTypeException |
|
| 3717 | - */ |
|
| 3718 | - protected function _per_page_screen_option() |
|
| 3719 | - { |
|
| 3720 | - $option = 'per_page'; |
|
| 3721 | - $args = array( |
|
| 3722 | - 'label' => apply_filters( |
|
| 3723 | - 'FHEE__EE_Admin_Page___per_page_screen_options___label', |
|
| 3724 | - $this->_admin_page_title, |
|
| 3725 | - $this |
|
| 3726 | - ), |
|
| 3727 | - 'default' => (int) apply_filters( |
|
| 3728 | - 'FHEE__EE_Admin_Page___per_page_screen_options__default', |
|
| 3729 | - 20 |
|
| 3730 | - ), |
|
| 3731 | - 'option' => $this->_current_page . '_' . $this->_current_view . '_per_page', |
|
| 3732 | - ); |
|
| 3733 | - // ONLY add the screen option if the user has access to it. |
|
| 3734 | - if ($this->check_user_access($this->_current_view, true)) { |
|
| 3735 | - add_screen_option($option, $args); |
|
| 3736 | - } |
|
| 3737 | - } |
|
| 3738 | - |
|
| 3739 | - |
|
| 3740 | - /** |
|
| 3741 | - * set_per_page_screen_option |
|
| 3742 | - * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page. |
|
| 3743 | - * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than |
|
| 3744 | - * admin_menu. |
|
| 3745 | - * |
|
| 3746 | - * @return void |
|
| 3747 | - */ |
|
| 3748 | - private function _set_per_page_screen_options() |
|
| 3749 | - { |
|
| 3750 | - if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) { |
|
| 3751 | - check_admin_referer('screen-options-nonce', 'screenoptionnonce'); |
|
| 3752 | - if (! $user = wp_get_current_user()) { |
|
| 3753 | - return; |
|
| 3754 | - } |
|
| 3755 | - $option = $_POST['wp_screen_options']['option']; |
|
| 3756 | - $value = $_POST['wp_screen_options']['value']; |
|
| 3757 | - if ($option != sanitize_key($option)) { |
|
| 3758 | - return; |
|
| 3759 | - } |
|
| 3760 | - $map_option = $option; |
|
| 3761 | - $option = str_replace('-', '_', $option); |
|
| 3762 | - switch ($map_option) { |
|
| 3763 | - case $this->_current_page . '_' . $this->_current_view . '_per_page': |
|
| 3764 | - $value = (int) $value; |
|
| 3765 | - $max_value = apply_filters( |
|
| 3766 | - 'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value', |
|
| 3767 | - 999, |
|
| 3768 | - $this->_current_page, |
|
| 3769 | - $this->_current_view |
|
| 3770 | - ); |
|
| 3771 | - if ($value < 1) { |
|
| 3772 | - return; |
|
| 3773 | - } |
|
| 3774 | - $value = min($value, $max_value); |
|
| 3775 | - break; |
|
| 3776 | - default: |
|
| 3777 | - $value = apply_filters( |
|
| 3778 | - 'FHEE__EE_Admin_Page___set_per_page_screen_options__value', |
|
| 3779 | - false, |
|
| 3780 | - $option, |
|
| 3781 | - $value |
|
| 3782 | - ); |
|
| 3783 | - if (false === $value) { |
|
| 3784 | - return; |
|
| 3785 | - } |
|
| 3786 | - break; |
|
| 3787 | - } |
|
| 3788 | - update_user_meta($user->ID, $option, $value); |
|
| 3789 | - wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer())); |
|
| 3790 | - exit; |
|
| 3791 | - } |
|
| 3792 | - } |
|
| 3793 | - |
|
| 3794 | - |
|
| 3795 | - /** |
|
| 3796 | - * This just allows for setting the $_template_args property if it needs to be set outside the object |
|
| 3797 | - * |
|
| 3798 | - * @param array $data array that will be assigned to template args. |
|
| 3799 | - */ |
|
| 3800 | - public function set_template_args($data) |
|
| 3801 | - { |
|
| 3802 | - $this->_template_args = array_merge($this->_template_args, (array) $data); |
|
| 3803 | - } |
|
| 3804 | - |
|
| 3805 | - |
|
| 3806 | - /** |
|
| 3807 | - * This makes available the WP transient system for temporarily moving data between routes |
|
| 3808 | - * |
|
| 3809 | - * @param string $route the route that should receive the transient |
|
| 3810 | - * @param array $data the data that gets sent |
|
| 3811 | - * @param bool $notices If this is for notices then we use this to indicate so, otherwise its just a |
|
| 3812 | - * normal route transient. |
|
| 3813 | - * @param bool $skip_route_verify Used to indicate we want to skip route verification. This is usually ONLY used |
|
| 3814 | - * when we are adding a transient before page_routes have been defined. |
|
| 3815 | - * @return void |
|
| 3816 | - * @throws EE_Error |
|
| 3817 | - */ |
|
| 3818 | - protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false) |
|
| 3819 | - { |
|
| 3820 | - $user_id = get_current_user_id(); |
|
| 3821 | - if (! $skip_route_verify) { |
|
| 3822 | - $this->_verify_route($route); |
|
| 3823 | - } |
|
| 3824 | - // now let's set the string for what kind of transient we're setting |
|
| 3825 | - $transient = $notices |
|
| 3826 | - ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3827 | - : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3828 | - $data = $notices ? array('notices' => $data) : $data; |
|
| 3829 | - // is there already a transient for this route? If there is then let's ADD to that transient |
|
| 3830 | - $existing = is_multisite() && is_network_admin() |
|
| 3831 | - ? get_site_transient($transient) |
|
| 3832 | - : get_transient($transient); |
|
| 3833 | - if ($existing) { |
|
| 3834 | - $data = array_merge((array) $data, (array) $existing); |
|
| 3835 | - } |
|
| 3836 | - if (is_multisite() && is_network_admin()) { |
|
| 3837 | - set_site_transient($transient, $data, 8); |
|
| 3838 | - } else { |
|
| 3839 | - set_transient($transient, $data, 8); |
|
| 3840 | - } |
|
| 3841 | - } |
|
| 3842 | - |
|
| 3843 | - |
|
| 3844 | - /** |
|
| 3845 | - * this retrieves the temporary transient that has been set for moving data between routes. |
|
| 3846 | - * |
|
| 3847 | - * @param bool $notices true we get notices transient. False we just return normal route transient |
|
| 3848 | - * @param string $route |
|
| 3849 | - * @return mixed data |
|
| 3850 | - */ |
|
| 3851 | - protected function _get_transient($notices = false, $route = '') |
|
| 3852 | - { |
|
| 3853 | - $user_id = get_current_user_id(); |
|
| 3854 | - $route = ! $route ? $this->_req_action : $route; |
|
| 3855 | - $transient = $notices |
|
| 3856 | - ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3857 | - : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3858 | - $data = is_multisite() && is_network_admin() |
|
| 3859 | - ? get_site_transient($transient) |
|
| 3860 | - : get_transient($transient); |
|
| 3861 | - // delete transient after retrieval (just in case it hasn't expired); |
|
| 3862 | - if (is_multisite() && is_network_admin()) { |
|
| 3863 | - delete_site_transient($transient); |
|
| 3864 | - } else { |
|
| 3865 | - delete_transient($transient); |
|
| 3866 | - } |
|
| 3867 | - return $notices && isset($data['notices']) ? $data['notices'] : $data; |
|
| 3868 | - } |
|
| 3869 | - |
|
| 3870 | - |
|
| 3871 | - /** |
|
| 3872 | - * The purpose of this method is just to run garbage collection on any EE transients that might have expired but |
|
| 3873 | - * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the |
|
| 3874 | - * default route callback on the EE_Admin page you want it run.) |
|
| 3875 | - * |
|
| 3876 | - * @return void |
|
| 3877 | - */ |
|
| 3878 | - protected function _transient_garbage_collection() |
|
| 3879 | - { |
|
| 3880 | - global $wpdb; |
|
| 3881 | - // retrieve all existing transients |
|
| 3882 | - $query = "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'"; |
|
| 3883 | - if ($results = $wpdb->get_results($query)) { |
|
| 3884 | - foreach ($results as $result) { |
|
| 3885 | - $transient = str_replace('_transient_', '', $result->option_name); |
|
| 3886 | - get_transient($transient); |
|
| 3887 | - if (is_multisite() && is_network_admin()) { |
|
| 3888 | - get_site_transient($transient); |
|
| 3889 | - } |
|
| 3890 | - } |
|
| 3891 | - } |
|
| 3892 | - } |
|
| 3893 | - |
|
| 3894 | - |
|
| 3895 | - /** |
|
| 3896 | - * get_view |
|
| 3897 | - * |
|
| 3898 | - * @return string content of _view property |
|
| 3899 | - */ |
|
| 3900 | - public function get_view() |
|
| 3901 | - { |
|
| 3902 | - return $this->_view; |
|
| 3903 | - } |
|
| 3904 | - |
|
| 3905 | - |
|
| 3906 | - /** |
|
| 3907 | - * getter for the protected $_views property |
|
| 3908 | - * |
|
| 3909 | - * @return array |
|
| 3910 | - */ |
|
| 3911 | - public function get_views() |
|
| 3912 | - { |
|
| 3913 | - return $this->_views; |
|
| 3914 | - } |
|
| 3915 | - |
|
| 3916 | - |
|
| 3917 | - /** |
|
| 3918 | - * get_current_page |
|
| 3919 | - * |
|
| 3920 | - * @return string _current_page property value |
|
| 3921 | - */ |
|
| 3922 | - public function get_current_page() |
|
| 3923 | - { |
|
| 3924 | - return $this->_current_page; |
|
| 3925 | - } |
|
| 3926 | - |
|
| 3927 | - |
|
| 3928 | - /** |
|
| 3929 | - * get_current_view |
|
| 3930 | - * |
|
| 3931 | - * @return string _current_view property value |
|
| 3932 | - */ |
|
| 3933 | - public function get_current_view() |
|
| 3934 | - { |
|
| 3935 | - return $this->_current_view; |
|
| 3936 | - } |
|
| 3937 | - |
|
| 3938 | - |
|
| 3939 | - /** |
|
| 3940 | - * get_current_screen |
|
| 3941 | - * |
|
| 3942 | - * @return object The current WP_Screen object |
|
| 3943 | - */ |
|
| 3944 | - public function get_current_screen() |
|
| 3945 | - { |
|
| 3946 | - return $this->_current_screen; |
|
| 3947 | - } |
|
| 3948 | - |
|
| 3949 | - |
|
| 3950 | - /** |
|
| 3951 | - * get_current_page_view_url |
|
| 3952 | - * |
|
| 3953 | - * @return string This returns the url for the current_page_view. |
|
| 3954 | - */ |
|
| 3955 | - public function get_current_page_view_url() |
|
| 3956 | - { |
|
| 3957 | - return $this->_current_page_view_url; |
|
| 3958 | - } |
|
| 3959 | - |
|
| 3960 | - |
|
| 3961 | - /** |
|
| 3962 | - * just returns the _req_data property |
|
| 3963 | - * |
|
| 3964 | - * @return array |
|
| 3965 | - */ |
|
| 3966 | - public function get_request_data() |
|
| 3967 | - { |
|
| 3968 | - return $this->_req_data; |
|
| 3969 | - } |
|
| 3970 | - |
|
| 3971 | - |
|
| 3972 | - /** |
|
| 3973 | - * returns the _req_data protected property |
|
| 3974 | - * |
|
| 3975 | - * @return string |
|
| 3976 | - */ |
|
| 3977 | - public function get_req_action() |
|
| 3978 | - { |
|
| 3979 | - return $this->_req_action; |
|
| 3980 | - } |
|
| 3981 | - |
|
| 3982 | - |
|
| 3983 | - /** |
|
| 3984 | - * @return bool value of $_is_caf property |
|
| 3985 | - */ |
|
| 3986 | - public function is_caf() |
|
| 3987 | - { |
|
| 3988 | - return $this->_is_caf; |
|
| 3989 | - } |
|
| 3990 | - |
|
| 3991 | - |
|
| 3992 | - /** |
|
| 3993 | - * @return mixed |
|
| 3994 | - */ |
|
| 3995 | - public function default_espresso_metaboxes() |
|
| 3996 | - { |
|
| 3997 | - return $this->_default_espresso_metaboxes; |
|
| 3998 | - } |
|
| 3999 | - |
|
| 4000 | - |
|
| 4001 | - /** |
|
| 4002 | - * @return mixed |
|
| 4003 | - */ |
|
| 4004 | - public function admin_base_url() |
|
| 4005 | - { |
|
| 4006 | - return $this->_admin_base_url; |
|
| 4007 | - } |
|
| 4008 | - |
|
| 4009 | - |
|
| 4010 | - /** |
|
| 4011 | - * @return mixed |
|
| 4012 | - */ |
|
| 4013 | - public function wp_page_slug() |
|
| 4014 | - { |
|
| 4015 | - return $this->_wp_page_slug; |
|
| 4016 | - } |
|
| 4017 | - |
|
| 4018 | - |
|
| 4019 | - /** |
|
| 4020 | - * updates espresso configuration settings |
|
| 4021 | - * |
|
| 4022 | - * @param string $tab |
|
| 4023 | - * @param EE_Config_Base|EE_Config $config |
|
| 4024 | - * @param string $file file where error occurred |
|
| 4025 | - * @param string $func function where error occurred |
|
| 4026 | - * @param string $line line no where error occurred |
|
| 4027 | - * @return boolean |
|
| 4028 | - */ |
|
| 4029 | - protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '') |
|
| 4030 | - { |
|
| 4031 | - // remove any options that are NOT going to be saved with the config settings. |
|
| 4032 | - if (isset($config->core->ee_ueip_optin)) { |
|
| 4033 | - // TODO: remove the following two lines and make sure values are migrated from 3.1 |
|
| 4034 | - update_option('ee_ueip_optin', $config->core->ee_ueip_optin); |
|
| 4035 | - update_option('ee_ueip_has_notified', true); |
|
| 4036 | - } |
|
| 4037 | - // and save it (note we're also doing the network save here) |
|
| 4038 | - $net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true; |
|
| 4039 | - $config_saved = EE_Config::instance()->update_espresso_config(false, false); |
|
| 4040 | - if ($config_saved && $net_saved) { |
|
| 4041 | - EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab)); |
|
| 4042 | - return true; |
|
| 4043 | - } |
|
| 4044 | - EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line); |
|
| 4045 | - return false; |
|
| 4046 | - } |
|
| 4047 | - |
|
| 4048 | - |
|
| 4049 | - /** |
|
| 4050 | - * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument. |
|
| 4051 | - * |
|
| 4052 | - * @return array |
|
| 4053 | - */ |
|
| 4054 | - public function get_yes_no_values() |
|
| 4055 | - { |
|
| 4056 | - return $this->_yes_no_values; |
|
| 4057 | - } |
|
| 4058 | - |
|
| 4059 | - |
|
| 4060 | - protected function _get_dir() |
|
| 4061 | - { |
|
| 4062 | - $reflector = new ReflectionClass(get_class($this)); |
|
| 4063 | - return dirname($reflector->getFileName()); |
|
| 4064 | - } |
|
| 4065 | - |
|
| 4066 | - |
|
| 4067 | - /** |
|
| 4068 | - * A helper for getting a "next link". |
|
| 4069 | - * |
|
| 4070 | - * @param string $url The url to link to |
|
| 4071 | - * @param string $class The class to use. |
|
| 4072 | - * @return string |
|
| 4073 | - */ |
|
| 4074 | - protected function _next_link($url, $class = 'dashicons dashicons-arrow-right') |
|
| 4075 | - { |
|
| 4076 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4077 | - } |
|
| 4078 | - |
|
| 4079 | - |
|
| 4080 | - /** |
|
| 4081 | - * A helper for getting a "previous link". |
|
| 4082 | - * |
|
| 4083 | - * @param string $url The url to link to |
|
| 4084 | - * @param string $class The class to use. |
|
| 4085 | - * @return string |
|
| 4086 | - */ |
|
| 4087 | - protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left') |
|
| 4088 | - { |
|
| 4089 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4090 | - } |
|
| 4091 | - |
|
| 4092 | - |
|
| 4093 | - |
|
| 4094 | - |
|
| 4095 | - |
|
| 4096 | - |
|
| 4097 | - |
|
| 4098 | - // below are some messages related methods that should be available across the EE_Admin system. Note, these methods are NOT page specific |
|
| 4099 | - |
|
| 4100 | - |
|
| 4101 | - /** |
|
| 4102 | - * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller |
|
| 4103 | - * 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 |
|
| 4104 | - * _req_data array. |
|
| 4105 | - * |
|
| 4106 | - * @return bool success/fail |
|
| 4107 | - * @throws EE_Error |
|
| 4108 | - * @throws InvalidArgumentException |
|
| 4109 | - * @throws ReflectionException |
|
| 4110 | - * @throws InvalidDataTypeException |
|
| 4111 | - * @throws InvalidInterfaceException |
|
| 4112 | - */ |
|
| 4113 | - protected function _process_resend_registration() |
|
| 4114 | - { |
|
| 4115 | - $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data); |
|
| 4116 | - do_action( |
|
| 4117 | - 'AHEE__EE_Admin_Page___process_resend_registration', |
|
| 4118 | - $this->_template_args['success'], |
|
| 4119 | - $this->_req_data |
|
| 4120 | - ); |
|
| 4121 | - return $this->_template_args['success']; |
|
| 4122 | - } |
|
| 4123 | - |
|
| 4124 | - |
|
| 4125 | - /** |
|
| 4126 | - * This automatically processes any payment message notifications when manual payment has been applied. |
|
| 4127 | - * |
|
| 4128 | - * @param \EE_Payment $payment |
|
| 4129 | - * @return bool success/fail |
|
| 4130 | - */ |
|
| 4131 | - protected function _process_payment_notification(EE_Payment $payment) |
|
| 4132 | - { |
|
| 4133 | - add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true'); |
|
| 4134 | - do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment); |
|
| 4135 | - $this->_template_args['success'] = apply_filters( |
|
| 4136 | - 'FHEE__EE_Admin_Page___process_admin_payment_notification__success', |
|
| 4137 | - false, |
|
| 4138 | - $payment |
|
| 4139 | - ); |
|
| 4140 | - return $this->_template_args['success']; |
|
| 4141 | - } |
|
| 2718 | + } |
|
| 2719 | + |
|
| 2720 | + |
|
| 2721 | + /** |
|
| 2722 | + * facade for add_meta_box |
|
| 2723 | + * |
|
| 2724 | + * @param string $action where the metabox get's displayed |
|
| 2725 | + * @param string $title Title of Metabox (output in metabox header) |
|
| 2726 | + * @param string $callback If not empty and $create_fun is set to false then we'll use a custom callback |
|
| 2727 | + * instead of the one created in here. |
|
| 2728 | + * @param array $callback_args an array of args supplied for the metabox |
|
| 2729 | + * @param string $column what metabox column |
|
| 2730 | + * @param string $priority give this metabox a priority (using accepted priorities for wp meta boxes) |
|
| 2731 | + * @param boolean $create_func default is true. Basically we can say we don't WANT to have the runtime function |
|
| 2732 | + * created but just set our own callback for wp's add_meta_box. |
|
| 2733 | + * @throws \DomainException |
|
| 2734 | + */ |
|
| 2735 | + public function _add_admin_page_meta_box( |
|
| 2736 | + $action, |
|
| 2737 | + $title, |
|
| 2738 | + $callback, |
|
| 2739 | + $callback_args, |
|
| 2740 | + $column = 'normal', |
|
| 2741 | + $priority = 'high', |
|
| 2742 | + $create_func = true |
|
| 2743 | + ) { |
|
| 2744 | + do_action('AHEE_log', __FILE__, __FUNCTION__, $callback); |
|
| 2745 | + // 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. |
|
| 2746 | + if (empty($callback_args) && $create_func) { |
|
| 2747 | + $callback_args = array( |
|
| 2748 | + 'template_path' => $this->_template_path, |
|
| 2749 | + 'template_args' => $this->_template_args, |
|
| 2750 | + ); |
|
| 2751 | + } |
|
| 2752 | + // 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) |
|
| 2753 | + $call_back_func = $create_func |
|
| 2754 | + ? function ($post, $metabox) { |
|
| 2755 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2756 | + echo EEH_Template::display_template( |
|
| 2757 | + $metabox['args']['template_path'], |
|
| 2758 | + $metabox['args']['template_args'], |
|
| 2759 | + true |
|
| 2760 | + ); |
|
| 2761 | + } |
|
| 2762 | + : $callback; |
|
| 2763 | + add_meta_box( |
|
| 2764 | + str_replace('_', '-', $action) . '-mbox', |
|
| 2765 | + $title, |
|
| 2766 | + $call_back_func, |
|
| 2767 | + $this->_wp_page_slug, |
|
| 2768 | + $column, |
|
| 2769 | + $priority, |
|
| 2770 | + $callback_args |
|
| 2771 | + ); |
|
| 2772 | + } |
|
| 2773 | + |
|
| 2774 | + |
|
| 2775 | + /** |
|
| 2776 | + * generates HTML wrapper for and admin details page that contains metaboxes in columns |
|
| 2777 | + * |
|
| 2778 | + * @throws DomainException |
|
| 2779 | + * @throws EE_Error |
|
| 2780 | + */ |
|
| 2781 | + public function display_admin_page_with_metabox_columns() |
|
| 2782 | + { |
|
| 2783 | + $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content']; |
|
| 2784 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2785 | + $this->_column_template_path, |
|
| 2786 | + $this->_template_args, |
|
| 2787 | + true |
|
| 2788 | + ); |
|
| 2789 | + // the final wrapper |
|
| 2790 | + $this->admin_page_wrapper(); |
|
| 2791 | + } |
|
| 2792 | + |
|
| 2793 | + |
|
| 2794 | + /** |
|
| 2795 | + * generates HTML wrapper for an admin details page |
|
| 2796 | + * |
|
| 2797 | + * @return void |
|
| 2798 | + * @throws EE_Error |
|
| 2799 | + * @throws DomainException |
|
| 2800 | + */ |
|
| 2801 | + public function display_admin_page_with_sidebar() |
|
| 2802 | + { |
|
| 2803 | + $this->_display_admin_page(true); |
|
| 2804 | + } |
|
| 2805 | + |
|
| 2806 | + |
|
| 2807 | + /** |
|
| 2808 | + * generates HTML wrapper for an admin details page (except no sidebar) |
|
| 2809 | + * |
|
| 2810 | + * @return void |
|
| 2811 | + * @throws EE_Error |
|
| 2812 | + * @throws DomainException |
|
| 2813 | + */ |
|
| 2814 | + public function display_admin_page_with_no_sidebar() |
|
| 2815 | + { |
|
| 2816 | + $this->_display_admin_page(); |
|
| 2817 | + } |
|
| 2818 | + |
|
| 2819 | + |
|
| 2820 | + /** |
|
| 2821 | + * generates HTML wrapper for an EE about admin page (no sidebar) |
|
| 2822 | + * |
|
| 2823 | + * @return void |
|
| 2824 | + * @throws EE_Error |
|
| 2825 | + * @throws DomainException |
|
| 2826 | + */ |
|
| 2827 | + public function display_about_admin_page() |
|
| 2828 | + { |
|
| 2829 | + $this->_display_admin_page(false, true); |
|
| 2830 | + } |
|
| 2831 | + |
|
| 2832 | + |
|
| 2833 | + /** |
|
| 2834 | + * display_admin_page |
|
| 2835 | + * contains the code for actually displaying an admin page |
|
| 2836 | + * |
|
| 2837 | + * @param boolean $sidebar true with sidebar, false without |
|
| 2838 | + * @param boolean $about use the about admin wrapper instead of the default. |
|
| 2839 | + * @return void |
|
| 2840 | + * @throws DomainException |
|
| 2841 | + * @throws EE_Error |
|
| 2842 | + */ |
|
| 2843 | + private function _display_admin_page($sidebar = false, $about = false) |
|
| 2844 | + { |
|
| 2845 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2846 | + // custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages. |
|
| 2847 | + do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes'); |
|
| 2848 | + // set current wp page slug - looks like: event-espresso_page_event_categories |
|
| 2849 | + // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated. |
|
| 2850 | + $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2851 | + $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route |
|
| 2852 | + ? 'poststuff' |
|
| 2853 | + : 'espresso-default-admin'; |
|
| 2854 | + $template_path = $sidebar |
|
| 2855 | + ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php' |
|
| 2856 | + : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2857 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2858 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2859 | + } |
|
| 2860 | + $template_path = ! empty($this->_column_template_path) |
|
| 2861 | + ? $this->_column_template_path : $template_path; |
|
| 2862 | + $this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content']) |
|
| 2863 | + ? $this->_template_args['admin_page_content'] |
|
| 2864 | + : ''; |
|
| 2865 | + $this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content']) |
|
| 2866 | + ? $this->_template_args['before_admin_page_content'] |
|
| 2867 | + : ''; |
|
| 2868 | + $this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content']) |
|
| 2869 | + ? $this->_template_args['after_admin_page_content'] |
|
| 2870 | + : ''; |
|
| 2871 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2872 | + $template_path, |
|
| 2873 | + $this->_template_args, |
|
| 2874 | + true |
|
| 2875 | + ); |
|
| 2876 | + // the final template wrapper |
|
| 2877 | + $this->admin_page_wrapper($about); |
|
| 2878 | + } |
|
| 2879 | + |
|
| 2880 | + |
|
| 2881 | + /** |
|
| 2882 | + * This is used to display caf preview pages. |
|
| 2883 | + * |
|
| 2884 | + * @since 4.3.2 |
|
| 2885 | + * @param string $utm_campaign_source what is the key used for google analytics link |
|
| 2886 | + * @param bool $display_sidebar whether to use the sidebar template or the full template for the page. TRUE |
|
| 2887 | + * = SHOW sidebar, FALSE = no sidebar. Default no sidebar. |
|
| 2888 | + * @return void |
|
| 2889 | + * @throws DomainException |
|
| 2890 | + * @throws EE_Error |
|
| 2891 | + * @throws InvalidArgumentException |
|
| 2892 | + * @throws InvalidDataTypeException |
|
| 2893 | + * @throws InvalidInterfaceException |
|
| 2894 | + */ |
|
| 2895 | + public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true) |
|
| 2896 | + { |
|
| 2897 | + // let's generate a default preview action button if there isn't one already present. |
|
| 2898 | + $this->_labels['buttons']['buy_now'] = esc_html__( |
|
| 2899 | + 'Upgrade to Event Espresso 4 Right Now', |
|
| 2900 | + 'event_espresso' |
|
| 2901 | + ); |
|
| 2902 | + $buy_now_url = add_query_arg( |
|
| 2903 | + array( |
|
| 2904 | + 'ee_ver' => 'ee4', |
|
| 2905 | + 'utm_source' => 'ee4_plugin_admin', |
|
| 2906 | + 'utm_medium' => 'link', |
|
| 2907 | + 'utm_campaign' => $utm_campaign_source, |
|
| 2908 | + 'utm_content' => 'buy_now_button', |
|
| 2909 | + ), |
|
| 2910 | + 'http://eventespresso.com/pricing/' |
|
| 2911 | + ); |
|
| 2912 | + $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button']) |
|
| 2913 | + ? $this->get_action_link_or_button( |
|
| 2914 | + '', |
|
| 2915 | + 'buy_now', |
|
| 2916 | + array(), |
|
| 2917 | + 'button-primary button-large', |
|
| 2918 | + $buy_now_url, |
|
| 2919 | + true |
|
| 2920 | + ) |
|
| 2921 | + : $this->_template_args['preview_action_button']; |
|
| 2922 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2923 | + EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php', |
|
| 2924 | + $this->_template_args, |
|
| 2925 | + true |
|
| 2926 | + ); |
|
| 2927 | + $this->_display_admin_page($display_sidebar); |
|
| 2928 | + } |
|
| 2929 | + |
|
| 2930 | + |
|
| 2931 | + /** |
|
| 2932 | + * display_admin_list_table_page_with_sidebar |
|
| 2933 | + * generates HTML wrapper for an admin_page with list_table |
|
| 2934 | + * |
|
| 2935 | + * @return void |
|
| 2936 | + * @throws EE_Error |
|
| 2937 | + * @throws DomainException |
|
| 2938 | + */ |
|
| 2939 | + public function display_admin_list_table_page_with_sidebar() |
|
| 2940 | + { |
|
| 2941 | + $this->_display_admin_list_table_page(true); |
|
| 2942 | + } |
|
| 2943 | + |
|
| 2944 | + |
|
| 2945 | + /** |
|
| 2946 | + * display_admin_list_table_page_with_no_sidebar |
|
| 2947 | + * generates HTML wrapper for an admin_page with list_table (but with no sidebar) |
|
| 2948 | + * |
|
| 2949 | + * @return void |
|
| 2950 | + * @throws EE_Error |
|
| 2951 | + * @throws DomainException |
|
| 2952 | + */ |
|
| 2953 | + public function display_admin_list_table_page_with_no_sidebar() |
|
| 2954 | + { |
|
| 2955 | + $this->_display_admin_list_table_page(); |
|
| 2956 | + } |
|
| 2957 | + |
|
| 2958 | + |
|
| 2959 | + /** |
|
| 2960 | + * generates html wrapper for an admin_list_table page |
|
| 2961 | + * |
|
| 2962 | + * @param boolean $sidebar whether to display with sidebar or not. |
|
| 2963 | + * @return void |
|
| 2964 | + * @throws DomainException |
|
| 2965 | + * @throws EE_Error |
|
| 2966 | + */ |
|
| 2967 | + private function _display_admin_list_table_page($sidebar = false) |
|
| 2968 | + { |
|
| 2969 | + // setup search attributes |
|
| 2970 | + $this->_set_search_attributes(); |
|
| 2971 | + $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2972 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php'; |
|
| 2973 | + $this->_template_args['table_url'] = defined('DOING_AJAX') |
|
| 2974 | + ? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url) |
|
| 2975 | + : add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url); |
|
| 2976 | + $this->_template_args['list_table'] = $this->_list_table_object; |
|
| 2977 | + $this->_template_args['current_route'] = $this->_req_action; |
|
| 2978 | + $this->_template_args['list_table_class'] = get_class($this->_list_table_object); |
|
| 2979 | + $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback(); |
|
| 2980 | + if (! empty($ajax_sorting_callback)) { |
|
| 2981 | + $sortable_list_table_form_fields = wp_nonce_field( |
|
| 2982 | + $ajax_sorting_callback . '_nonce', |
|
| 2983 | + $ajax_sorting_callback . '_nonce', |
|
| 2984 | + false, |
|
| 2985 | + false |
|
| 2986 | + ); |
|
| 2987 | + $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' |
|
| 2988 | + . $this->page_slug |
|
| 2989 | + . '" />'; |
|
| 2990 | + $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' |
|
| 2991 | + . $ajax_sorting_callback |
|
| 2992 | + . '" />'; |
|
| 2993 | + } else { |
|
| 2994 | + $sortable_list_table_form_fields = ''; |
|
| 2995 | + } |
|
| 2996 | + $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields; |
|
| 2997 | + $hidden_form_fields = isset($this->_template_args['list_table_hidden_fields']) |
|
| 2998 | + ? $this->_template_args['list_table_hidden_fields'] |
|
| 2999 | + : ''; |
|
| 3000 | + $nonce_ref = $this->_req_action . '_nonce'; |
|
| 3001 | + $hidden_form_fields .= '<input type="hidden" name="' |
|
| 3002 | + . $nonce_ref |
|
| 3003 | + . '" value="' |
|
| 3004 | + . wp_create_nonce($nonce_ref) |
|
| 3005 | + . '">'; |
|
| 3006 | + $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
|
| 3007 | + // display message about search results? |
|
| 3008 | + $this->_template_args['before_list_table'] .= ! empty($this->_req_data['s']) |
|
| 3009 | + ? '<p class="ee-search-results">' . sprintf( |
|
| 3010 | + esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'), |
|
| 3011 | + trim($this->_req_data['s'], '%') |
|
| 3012 | + ) . '</p>' |
|
| 3013 | + : ''; |
|
| 3014 | + // filter before_list_table template arg |
|
| 3015 | + $this->_template_args['before_list_table'] = apply_filters( |
|
| 3016 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg', |
|
| 3017 | + $this->_template_args['before_list_table'], |
|
| 3018 | + $this->page_slug, |
|
| 3019 | + $this->_req_data, |
|
| 3020 | + $this->_req_action |
|
| 3021 | + ); |
|
| 3022 | + // convert to array and filter again |
|
| 3023 | + // arrays are easier to inject new items in a specific location, |
|
| 3024 | + // but would not be backwards compatible, so we have to add a new filter |
|
| 3025 | + $this->_template_args['before_list_table'] = implode( |
|
| 3026 | + " \n", |
|
| 3027 | + (array) apply_filters( |
|
| 3028 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array', |
|
| 3029 | + (array) $this->_template_args['before_list_table'], |
|
| 3030 | + $this->page_slug, |
|
| 3031 | + $this->_req_data, |
|
| 3032 | + $this->_req_action |
|
| 3033 | + ) |
|
| 3034 | + ); |
|
| 3035 | + // filter after_list_table template arg |
|
| 3036 | + $this->_template_args['after_list_table'] = apply_filters( |
|
| 3037 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg', |
|
| 3038 | + $this->_template_args['after_list_table'], |
|
| 3039 | + $this->page_slug, |
|
| 3040 | + $this->_req_data, |
|
| 3041 | + $this->_req_action |
|
| 3042 | + ); |
|
| 3043 | + // convert to array and filter again |
|
| 3044 | + // arrays are easier to inject new items in a specific location, |
|
| 3045 | + // but would not be backwards compatible, so we have to add a new filter |
|
| 3046 | + $this->_template_args['after_list_table'] = implode( |
|
| 3047 | + " \n", |
|
| 3048 | + (array) apply_filters( |
|
| 3049 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array', |
|
| 3050 | + (array) $this->_template_args['after_list_table'], |
|
| 3051 | + $this->page_slug, |
|
| 3052 | + $this->_req_data, |
|
| 3053 | + $this->_req_action |
|
| 3054 | + ) |
|
| 3055 | + ); |
|
| 3056 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 3057 | + $template_path, |
|
| 3058 | + $this->_template_args, |
|
| 3059 | + true |
|
| 3060 | + ); |
|
| 3061 | + // the final template wrapper |
|
| 3062 | + if ($sidebar) { |
|
| 3063 | + $this->display_admin_page_with_sidebar(); |
|
| 3064 | + } else { |
|
| 3065 | + $this->display_admin_page_with_no_sidebar(); |
|
| 3066 | + } |
|
| 3067 | + } |
|
| 3068 | + |
|
| 3069 | + |
|
| 3070 | + /** |
|
| 3071 | + * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the |
|
| 3072 | + * html string for the legend. |
|
| 3073 | + * $items are expected in an array in the following format: |
|
| 3074 | + * $legend_items = array( |
|
| 3075 | + * 'item_id' => array( |
|
| 3076 | + * 'icon' => 'http://url_to_icon_being_described.png', |
|
| 3077 | + * 'desc' => esc_html__('localized description of item'); |
|
| 3078 | + * ) |
|
| 3079 | + * ); |
|
| 3080 | + * |
|
| 3081 | + * @param array $items see above for format of array |
|
| 3082 | + * @return string html string of legend |
|
| 3083 | + * @throws DomainException |
|
| 3084 | + */ |
|
| 3085 | + protected function _display_legend($items) |
|
| 3086 | + { |
|
| 3087 | + $this->_template_args['items'] = apply_filters( |
|
| 3088 | + 'FHEE__EE_Admin_Page___display_legend__items', |
|
| 3089 | + (array) $items, |
|
| 3090 | + $this |
|
| 3091 | + ); |
|
| 3092 | + return EEH_Template::display_template( |
|
| 3093 | + EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php', |
|
| 3094 | + $this->_template_args, |
|
| 3095 | + true |
|
| 3096 | + ); |
|
| 3097 | + } |
|
| 3098 | + |
|
| 3099 | + |
|
| 3100 | + /** |
|
| 3101 | + * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect |
|
| 3102 | + * The returned json object is created from an array in the following format: |
|
| 3103 | + * array( |
|
| 3104 | + * 'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early), |
|
| 3105 | + * 'success' => FALSE, //(default FALSE) - contains any special success message. |
|
| 3106 | + * 'notices' => '', // - contains any EE_Error formatted notices |
|
| 3107 | + * 'content' => 'string can be html', //this is a string of formatted content (can be html) |
|
| 3108 | + * 'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. |
|
| 3109 | + * We're also going to include the template args with every package (so js can pick out any specific template args |
|
| 3110 | + * that might be included in here) |
|
| 3111 | + * ) |
|
| 3112 | + * The json object is populated by whatever is set in the $_template_args property. |
|
| 3113 | + * |
|
| 3114 | + * @param bool $sticky_notices Used to indicate whether you want to ensure notices are added to a transient |
|
| 3115 | + * instead of displayed. |
|
| 3116 | + * @param array $notices_arguments Use this to pass any additional args on to the _process_notices. |
|
| 3117 | + * @return void |
|
| 3118 | + * @throws EE_Error |
|
| 3119 | + */ |
|
| 3120 | + protected function _return_json($sticky_notices = false, $notices_arguments = array()) |
|
| 3121 | + { |
|
| 3122 | + // make sure any EE_Error notices have been handled. |
|
| 3123 | + $this->_process_notices($notices_arguments, true, $sticky_notices); |
|
| 3124 | + $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array(); |
|
| 3125 | + unset($this->_template_args['data']); |
|
| 3126 | + $json = array( |
|
| 3127 | + 'error' => isset($this->_template_args['error']) ? $this->_template_args['error'] : false, |
|
| 3128 | + 'success' => isset($this->_template_args['success']) ? $this->_template_args['success'] : false, |
|
| 3129 | + 'errors' => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false, |
|
| 3130 | + 'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false, |
|
| 3131 | + 'notices' => EE_Error::get_notices(), |
|
| 3132 | + 'content' => isset($this->_template_args['admin_page_content']) |
|
| 3133 | + ? $this->_template_args['admin_page_content'] : '', |
|
| 3134 | + 'data' => array_merge($data, array('template_args' => $this->_template_args)), |
|
| 3135 | + 'isEEajax' => true |
|
| 3136 | + // special flag so any ajax.Success methods in js can identify this return package as a EEajax package. |
|
| 3137 | + ); |
|
| 3138 | + // make sure there are no php errors or headers_sent. Then we can set correct json header. |
|
| 3139 | + if (null === error_get_last() || ! headers_sent()) { |
|
| 3140 | + header('Content-Type: application/json; charset=UTF-8'); |
|
| 3141 | + } |
|
| 3142 | + echo wp_json_encode($json); |
|
| 3143 | + exit(); |
|
| 3144 | + } |
|
| 3145 | + |
|
| 3146 | + |
|
| 3147 | + /** |
|
| 3148 | + * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax) |
|
| 3149 | + * |
|
| 3150 | + * @return void |
|
| 3151 | + * @throws EE_Error |
|
| 3152 | + */ |
|
| 3153 | + public function return_json() |
|
| 3154 | + { |
|
| 3155 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 3156 | + $this->_return_json(); |
|
| 3157 | + } else { |
|
| 3158 | + throw new EE_Error( |
|
| 3159 | + sprintf( |
|
| 3160 | + esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), |
|
| 3161 | + __FUNCTION__ |
|
| 3162 | + ) |
|
| 3163 | + ); |
|
| 3164 | + } |
|
| 3165 | + } |
|
| 3166 | + |
|
| 3167 | + |
|
| 3168 | + /** |
|
| 3169 | + * This provides a way for child hook classes to send along themselves by reference so methods/properties within |
|
| 3170 | + * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property. |
|
| 3171 | + * |
|
| 3172 | + * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child |
|
| 3173 | + */ |
|
| 3174 | + public function set_hook_object(EE_Admin_Hooks $hook_obj) |
|
| 3175 | + { |
|
| 3176 | + $this->_hook_obj = $hook_obj; |
|
| 3177 | + } |
|
| 3178 | + |
|
| 3179 | + |
|
| 3180 | + /** |
|
| 3181 | + * generates HTML wrapper with Tabbed nav for an admin page |
|
| 3182 | + * |
|
| 3183 | + * @param boolean $about whether to use the special about page wrapper or default. |
|
| 3184 | + * @return void |
|
| 3185 | + * @throws DomainException |
|
| 3186 | + * @throws EE_Error |
|
| 3187 | + */ |
|
| 3188 | + public function admin_page_wrapper($about = false) |
|
| 3189 | + { |
|
| 3190 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3191 | + $this->_nav_tabs = $this->_get_main_nav_tabs(); |
|
| 3192 | + $this->_template_args['nav_tabs'] = $this->_nav_tabs; |
|
| 3193 | + $this->_template_args['admin_page_title'] = $this->_admin_page_title; |
|
| 3194 | + $this->_template_args['before_admin_page_content'] = apply_filters( |
|
| 3195 | + "FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}", |
|
| 3196 | + isset($this->_template_args['before_admin_page_content']) |
|
| 3197 | + ? $this->_template_args['before_admin_page_content'] |
|
| 3198 | + : '' |
|
| 3199 | + ); |
|
| 3200 | + $this->_template_args['after_admin_page_content'] = apply_filters( |
|
| 3201 | + "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}", |
|
| 3202 | + isset($this->_template_args['after_admin_page_content']) |
|
| 3203 | + ? $this->_template_args['after_admin_page_content'] |
|
| 3204 | + : '' |
|
| 3205 | + ); |
|
| 3206 | + $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content(); |
|
| 3207 | + // load settings page wrapper template |
|
| 3208 | + $template_path = ! defined('DOING_AJAX') |
|
| 3209 | + ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' |
|
| 3210 | + : EE_ADMIN_TEMPLATE |
|
| 3211 | + . 'admin_wrapper_ajax.template.php'; |
|
| 3212 | + // about page? |
|
| 3213 | + $template_path = $about |
|
| 3214 | + ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' |
|
| 3215 | + : $template_path; |
|
| 3216 | + if (defined('DOING_AJAX')) { |
|
| 3217 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 3218 | + $template_path, |
|
| 3219 | + $this->_template_args, |
|
| 3220 | + true |
|
| 3221 | + ); |
|
| 3222 | + $this->_return_json(); |
|
| 3223 | + } else { |
|
| 3224 | + EEH_Template::display_template($template_path, $this->_template_args); |
|
| 3225 | + } |
|
| 3226 | + } |
|
| 3227 | + |
|
| 3228 | + |
|
| 3229 | + /** |
|
| 3230 | + * This returns the admin_nav tabs html using the configuration in the _nav_tabs property |
|
| 3231 | + * |
|
| 3232 | + * @return string html |
|
| 3233 | + * @throws EE_Error |
|
| 3234 | + */ |
|
| 3235 | + protected function _get_main_nav_tabs() |
|
| 3236 | + { |
|
| 3237 | + // let's generate the html using the EEH_Tabbed_Content helper. |
|
| 3238 | + // We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute |
|
| 3239 | + // (rather than setting in the page_routes array) |
|
| 3240 | + return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs); |
|
| 3241 | + } |
|
| 3242 | + |
|
| 3243 | + |
|
| 3244 | + /** |
|
| 3245 | + * sort nav tabs |
|
| 3246 | + * |
|
| 3247 | + * @param $a |
|
| 3248 | + * @param $b |
|
| 3249 | + * @return int |
|
| 3250 | + */ |
|
| 3251 | + private function _sort_nav_tabs($a, $b) |
|
| 3252 | + { |
|
| 3253 | + if ($a['order'] === $b['order']) { |
|
| 3254 | + return 0; |
|
| 3255 | + } |
|
| 3256 | + return ($a['order'] < $b['order']) ? -1 : 1; |
|
| 3257 | + } |
|
| 3258 | + |
|
| 3259 | + |
|
| 3260 | + /** |
|
| 3261 | + * generates HTML for the forms used on admin pages |
|
| 3262 | + * |
|
| 3263 | + * @param array $input_vars - array of input field details |
|
| 3264 | + * @param string $generator (options are 'string' or 'array', basically use this to indicate which generator to |
|
| 3265 | + * use) |
|
| 3266 | + * @param bool $id |
|
| 3267 | + * @return string |
|
| 3268 | + * @uses EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php) |
|
| 3269 | + * @uses EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php) |
|
| 3270 | + */ |
|
| 3271 | + protected function _generate_admin_form_fields($input_vars = array(), $generator = 'string', $id = false) |
|
| 3272 | + { |
|
| 3273 | + $content = $generator === 'string' |
|
| 3274 | + ? EEH_Form_Fields::get_form_fields($input_vars, $id) |
|
| 3275 | + : EEH_Form_Fields::get_form_fields_array($input_vars); |
|
| 3276 | + return $content; |
|
| 3277 | + } |
|
| 3278 | + |
|
| 3279 | + |
|
| 3280 | + /** |
|
| 3281 | + * generates the "Save" and "Save & Close" buttons for edit forms |
|
| 3282 | + * |
|
| 3283 | + * @param bool $both if true then both buttons will be generated. If false then just the "Save & |
|
| 3284 | + * Close" button. |
|
| 3285 | + * @param array $text if included, generator will use the given text for the buttons ( array([0] => |
|
| 3286 | + * 'Save', [1] => 'save & close') |
|
| 3287 | + * @param array $actions if included allows us to set the actions that each button will carry out (i.e. |
|
| 3288 | + * via the "name" value in the button). We can also use this to just dump |
|
| 3289 | + * default actions by submitting some other value. |
|
| 3290 | + * @param bool|string|null $referrer if false then we just do the default action on save and close. Other wise it |
|
| 3291 | + * will use the $referrer string. IF null, then we don't do ANYTHING on save and |
|
| 3292 | + * close (normal form handling). |
|
| 3293 | + */ |
|
| 3294 | + protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null) |
|
| 3295 | + { |
|
| 3296 | + // make sure $text and $actions are in an array |
|
| 3297 | + $text = (array) $text; |
|
| 3298 | + $actions = (array) $actions; |
|
| 3299 | + $referrer_url = empty($referrer) |
|
| 3300 | + ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' |
|
| 3301 | + . $_SERVER['REQUEST_URI'] |
|
| 3302 | + . '" />' |
|
| 3303 | + : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' |
|
| 3304 | + . $referrer |
|
| 3305 | + . '" />'; |
|
| 3306 | + $button_text = ! empty($text) |
|
| 3307 | + ? $text |
|
| 3308 | + : array( |
|
| 3309 | + esc_html__('Save', 'event_espresso'), |
|
| 3310 | + esc_html__('Save and Close', 'event_espresso'), |
|
| 3311 | + ); |
|
| 3312 | + $default_names = array('save', 'save_and_close'); |
|
| 3313 | + // add in a hidden index for the current page (so save and close redirects properly) |
|
| 3314 | + $this->_template_args['save_buttons'] = $referrer_url; |
|
| 3315 | + foreach ($button_text as $key => $button) { |
|
| 3316 | + $ref = $default_names[ $key ]; |
|
| 3317 | + $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' |
|
| 3318 | + . $ref |
|
| 3319 | + . '" value="' |
|
| 3320 | + . $button |
|
| 3321 | + . '" name="' |
|
| 3322 | + . (! empty($actions) ? $actions[ $key ] : $ref) |
|
| 3323 | + . '" id="' |
|
| 3324 | + . $this->_current_view . '_' . $ref |
|
| 3325 | + . '" />'; |
|
| 3326 | + if (! $both) { |
|
| 3327 | + break; |
|
| 3328 | + } |
|
| 3329 | + } |
|
| 3330 | + } |
|
| 3331 | + |
|
| 3332 | + |
|
| 3333 | + /** |
|
| 3334 | + * Wrapper for the protected function. Allows plugins/addons to call this to set the form tags. |
|
| 3335 | + * |
|
| 3336 | + * @see $this->_set_add_edit_form_tags() for details on params |
|
| 3337 | + * @since 4.6.0 |
|
| 3338 | + * @param string $route |
|
| 3339 | + * @param array $additional_hidden_fields |
|
| 3340 | + */ |
|
| 3341 | + public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array()) |
|
| 3342 | + { |
|
| 3343 | + $this->_set_add_edit_form_tags($route, $additional_hidden_fields); |
|
| 3344 | + } |
|
| 3345 | + |
|
| 3346 | + |
|
| 3347 | + /** |
|
| 3348 | + * set form open and close tags on add/edit pages. |
|
| 3349 | + * |
|
| 3350 | + * @param string $route the route you want the form to direct to |
|
| 3351 | + * @param array $additional_hidden_fields any additional hidden fields required in the form header |
|
| 3352 | + * @return void |
|
| 3353 | + */ |
|
| 3354 | + protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array()) |
|
| 3355 | + { |
|
| 3356 | + if (empty($route)) { |
|
| 3357 | + $user_msg = esc_html__( |
|
| 3358 | + 'An error occurred. No action was set for this page\'s form.', |
|
| 3359 | + 'event_espresso' |
|
| 3360 | + ); |
|
| 3361 | + $dev_msg = $user_msg . "\n" |
|
| 3362 | + . sprintf( |
|
| 3363 | + esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'), |
|
| 3364 | + __FUNCTION__, |
|
| 3365 | + __CLASS__ |
|
| 3366 | + ); |
|
| 3367 | + EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 3368 | + } |
|
| 3369 | + // open form |
|
| 3370 | + $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' |
|
| 3371 | + . $this->_admin_base_url |
|
| 3372 | + . '" id="' |
|
| 3373 | + . $route |
|
| 3374 | + . '_event_form" >'; |
|
| 3375 | + // add nonce |
|
| 3376 | + $nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false); |
|
| 3377 | + $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce; |
|
| 3378 | + // add REQUIRED form action |
|
| 3379 | + $hidden_fields = array( |
|
| 3380 | + 'action' => array('type' => 'hidden', 'value' => $route), |
|
| 3381 | + ); |
|
| 3382 | + // merge arrays |
|
| 3383 | + $hidden_fields = is_array($additional_hidden_fields) |
|
| 3384 | + ? array_merge($hidden_fields, $additional_hidden_fields) |
|
| 3385 | + : $hidden_fields; |
|
| 3386 | + // generate form fields |
|
| 3387 | + $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array'); |
|
| 3388 | + // add fields to form |
|
| 3389 | + foreach ((array) $form_fields as $field_name => $form_field) { |
|
| 3390 | + $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field']; |
|
| 3391 | + } |
|
| 3392 | + // close form |
|
| 3393 | + $this->_template_args['after_admin_page_content'] = '</form>'; |
|
| 3394 | + } |
|
| 3395 | + |
|
| 3396 | + |
|
| 3397 | + /** |
|
| 3398 | + * Public Wrapper for _redirect_after_action() method since its |
|
| 3399 | + * discovered it would be useful for external code to have access. |
|
| 3400 | + * |
|
| 3401 | + * @see EE_Admin_Page::_redirect_after_action() for params. |
|
| 3402 | + * @since 4.5.0 |
|
| 3403 | + * @param bool $success |
|
| 3404 | + * @param string $what |
|
| 3405 | + * @param string $action_desc |
|
| 3406 | + * @param array $query_args |
|
| 3407 | + * @param bool $override_overwrite |
|
| 3408 | + * @throws EE_Error |
|
| 3409 | + */ |
|
| 3410 | + public function redirect_after_action( |
|
| 3411 | + $success = false, |
|
| 3412 | + $what = 'item', |
|
| 3413 | + $action_desc = 'processed', |
|
| 3414 | + $query_args = array(), |
|
| 3415 | + $override_overwrite = false |
|
| 3416 | + ) { |
|
| 3417 | + $this->_redirect_after_action( |
|
| 3418 | + $success, |
|
| 3419 | + $what, |
|
| 3420 | + $action_desc, |
|
| 3421 | + $query_args, |
|
| 3422 | + $override_overwrite |
|
| 3423 | + ); |
|
| 3424 | + } |
|
| 3425 | + |
|
| 3426 | + |
|
| 3427 | + /** |
|
| 3428 | + * Helper method for merging existing request data with the returned redirect url. |
|
| 3429 | + * |
|
| 3430 | + * This is typically used for redirects after an action so that if the original view was a filtered view those |
|
| 3431 | + * filters are still applied. |
|
| 3432 | + * |
|
| 3433 | + * @param array $new_route_data |
|
| 3434 | + * @return array |
|
| 3435 | + */ |
|
| 3436 | + protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data) |
|
| 3437 | + { |
|
| 3438 | + foreach ($this->_req_data as $ref => $value) { |
|
| 3439 | + // unset nonces |
|
| 3440 | + if (strpos($ref, 'nonce') !== false) { |
|
| 3441 | + unset($this->_req_data[ $ref ]); |
|
| 3442 | + continue; |
|
| 3443 | + } |
|
| 3444 | + // urlencode values. |
|
| 3445 | + $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value); |
|
| 3446 | + $this->_req_data[ $ref ] = $value; |
|
| 3447 | + } |
|
| 3448 | + return array_merge($this->_req_data, $new_route_data); |
|
| 3449 | + } |
|
| 3450 | + |
|
| 3451 | + |
|
| 3452 | + /** |
|
| 3453 | + * _redirect_after_action |
|
| 3454 | + * |
|
| 3455 | + * @param int $success - whether success was for two or more records, or just one, or none |
|
| 3456 | + * @param string $what - what the action was performed on |
|
| 3457 | + * @param string $action_desc - what was done ie: updated, deleted, etc |
|
| 3458 | + * @param array $query_args - an array of query_args to be added to the URL to redirect to after the admin |
|
| 3459 | + * action is completed |
|
| 3460 | + * @param BOOL $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to |
|
| 3461 | + * override this so that they show. |
|
| 3462 | + * @return void |
|
| 3463 | + * @throws EE_Error |
|
| 3464 | + */ |
|
| 3465 | + protected function _redirect_after_action( |
|
| 3466 | + $success = 0, |
|
| 3467 | + $what = 'item', |
|
| 3468 | + $action_desc = 'processed', |
|
| 3469 | + $query_args = array(), |
|
| 3470 | + $override_overwrite = false |
|
| 3471 | + ) { |
|
| 3472 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3473 | + // class name for actions/filters. |
|
| 3474 | + $classname = get_class($this); |
|
| 3475 | + // set redirect url. |
|
| 3476 | + // Note if there is a "page" index in the $query_args then we go with vanilla admin.php route, |
|
| 3477 | + // otherwise we go with whatever is set as the _admin_base_url |
|
| 3478 | + $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url; |
|
| 3479 | + $notices = EE_Error::get_notices(false); |
|
| 3480 | + // overwrite default success messages //BUT ONLY if overwrite not overridden |
|
| 3481 | + if (! $override_overwrite || ! empty($notices['errors'])) { |
|
| 3482 | + EE_Error::overwrite_success(); |
|
| 3483 | + } |
|
| 3484 | + if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) { |
|
| 3485 | + // how many records affected ? more than one record ? or just one ? |
|
| 3486 | + if ($success > 1) { |
|
| 3487 | + // set plural msg |
|
| 3488 | + EE_Error::add_success( |
|
| 3489 | + sprintf( |
|
| 3490 | + esc_html__('The "%s" have been successfully %s.', 'event_espresso'), |
|
| 3491 | + $what, |
|
| 3492 | + $action_desc |
|
| 3493 | + ), |
|
| 3494 | + __FILE__, |
|
| 3495 | + __FUNCTION__, |
|
| 3496 | + __LINE__ |
|
| 3497 | + ); |
|
| 3498 | + } elseif ($success === 1) { |
|
| 3499 | + // set singular msg |
|
| 3500 | + EE_Error::add_success( |
|
| 3501 | + sprintf( |
|
| 3502 | + esc_html__('The "%s" has been successfully %s.', 'event_espresso'), |
|
| 3503 | + $what, |
|
| 3504 | + $action_desc |
|
| 3505 | + ), |
|
| 3506 | + __FILE__, |
|
| 3507 | + __FUNCTION__, |
|
| 3508 | + __LINE__ |
|
| 3509 | + ); |
|
| 3510 | + } |
|
| 3511 | + } |
|
| 3512 | + // check that $query_args isn't something crazy |
|
| 3513 | + if (! is_array($query_args)) { |
|
| 3514 | + $query_args = array(); |
|
| 3515 | + } |
|
| 3516 | + /** |
|
| 3517 | + * Allow injecting actions before the query_args are modified for possible different |
|
| 3518 | + * redirections on save and close actions |
|
| 3519 | + * |
|
| 3520 | + * @since 4.2.0 |
|
| 3521 | + * @param array $query_args The original query_args array coming into the |
|
| 3522 | + * method. |
|
| 3523 | + */ |
|
| 3524 | + do_action( |
|
| 3525 | + "AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}", |
|
| 3526 | + $query_args |
|
| 3527 | + ); |
|
| 3528 | + // calculate where we're going (if we have a "save and close" button pushed) |
|
| 3529 | + if (isset($this->_req_data['save_and_close'], $this->_req_data['save_and_close_referrer'])) { |
|
| 3530 | + // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce |
|
| 3531 | + $parsed_url = parse_url($this->_req_data['save_and_close_referrer']); |
|
| 3532 | + // regenerate query args array from referrer URL |
|
| 3533 | + parse_str($parsed_url['query'], $query_args); |
|
| 3534 | + // correct page and action will be in the query args now |
|
| 3535 | + $redirect_url = admin_url('admin.php'); |
|
| 3536 | + } |
|
| 3537 | + // merge any default query_args set in _default_route_query_args property |
|
| 3538 | + if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
| 3539 | + $args_to_merge = array(); |
|
| 3540 | + foreach ($this->_default_route_query_args as $query_param => $query_value) { |
|
| 3541 | + // is there a wp_referer array in our _default_route_query_args property? |
|
| 3542 | + if ($query_param === 'wp_referer') { |
|
| 3543 | + $query_value = (array) $query_value; |
|
| 3544 | + foreach ($query_value as $reference => $value) { |
|
| 3545 | + if (strpos($reference, 'nonce') !== false) { |
|
| 3546 | + continue; |
|
| 3547 | + } |
|
| 3548 | + // finally we will override any arguments in the referer with |
|
| 3549 | + // what might be set on the _default_route_query_args array. |
|
| 3550 | + if (isset($this->_default_route_query_args[ $reference ])) { |
|
| 3551 | + $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]); |
|
| 3552 | + } else { |
|
| 3553 | + $args_to_merge[ $reference ] = urlencode($value); |
|
| 3554 | + } |
|
| 3555 | + } |
|
| 3556 | + continue; |
|
| 3557 | + } |
|
| 3558 | + $args_to_merge[ $query_param ] = $query_value; |
|
| 3559 | + } |
|
| 3560 | + // now let's merge these arguments but override with what was specifically sent in to the |
|
| 3561 | + // redirect. |
|
| 3562 | + $query_args = array_merge($args_to_merge, $query_args); |
|
| 3563 | + } |
|
| 3564 | + $this->_process_notices($query_args); |
|
| 3565 | + // generate redirect url |
|
| 3566 | + // if redirecting to anything other than the main page, add a nonce |
|
| 3567 | + if (isset($query_args['action'])) { |
|
| 3568 | + // manually generate wp_nonce and merge that with the query vars |
|
| 3569 | + // becuz the wp_nonce_url function wrecks havoc on some vars |
|
| 3570 | + $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 3571 | + } |
|
| 3572 | + // we're adding some hooks and filters in here for processing any things just before redirects |
|
| 3573 | + // (example: an admin page has done an insert or update and we want to run something after that). |
|
| 3574 | + do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args); |
|
| 3575 | + $redirect_url = apply_filters( |
|
| 3576 | + 'FHEE_redirect_' . $classname . $this->_req_action, |
|
| 3577 | + self::add_query_args_and_nonce($query_args, $redirect_url), |
|
| 3578 | + $query_args |
|
| 3579 | + ); |
|
| 3580 | + // check if we're doing ajax. If we are then lets just return the results and js can handle how it wants. |
|
| 3581 | + if (defined('DOING_AJAX')) { |
|
| 3582 | + $default_data = array( |
|
| 3583 | + 'close' => true, |
|
| 3584 | + 'redirect_url' => $redirect_url, |
|
| 3585 | + 'where' => 'main', |
|
| 3586 | + 'what' => 'append', |
|
| 3587 | + ); |
|
| 3588 | + $this->_template_args['success'] = $success; |
|
| 3589 | + $this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge( |
|
| 3590 | + $default_data, |
|
| 3591 | + $this->_template_args['data'] |
|
| 3592 | + ) : $default_data; |
|
| 3593 | + $this->_return_json(); |
|
| 3594 | + } |
|
| 3595 | + wp_safe_redirect($redirect_url); |
|
| 3596 | + exit(); |
|
| 3597 | + } |
|
| 3598 | + |
|
| 3599 | + |
|
| 3600 | + /** |
|
| 3601 | + * process any notices before redirecting (or returning ajax request) |
|
| 3602 | + * This method sets the $this->_template_args['notices'] attribute; |
|
| 3603 | + * |
|
| 3604 | + * @param array $query_args any query args that need to be used for notice transient ('action') |
|
| 3605 | + * @param bool $skip_route_verify This is typically used when we are processing notices REALLY early and |
|
| 3606 | + * page_routes haven't been defined yet. |
|
| 3607 | + * @param bool $sticky_notices This is used to flag that regardless of whether this is doing_ajax or not, we |
|
| 3608 | + * still save a transient for the notice. |
|
| 3609 | + * @return void |
|
| 3610 | + * @throws EE_Error |
|
| 3611 | + */ |
|
| 3612 | + protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true) |
|
| 3613 | + { |
|
| 3614 | + // first let's set individual error properties if doing_ajax and the properties aren't already set. |
|
| 3615 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 3616 | + $notices = EE_Error::get_notices(false); |
|
| 3617 | + if (empty($this->_template_args['success'])) { |
|
| 3618 | + $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false; |
|
| 3619 | + } |
|
| 3620 | + if (empty($this->_template_args['errors'])) { |
|
| 3621 | + $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false; |
|
| 3622 | + } |
|
| 3623 | + if (empty($this->_template_args['attention'])) { |
|
| 3624 | + $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false; |
|
| 3625 | + } |
|
| 3626 | + } |
|
| 3627 | + $this->_template_args['notices'] = EE_Error::get_notices(); |
|
| 3628 | + // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true) |
|
| 3629 | + if (! defined('DOING_AJAX') || $sticky_notices) { |
|
| 3630 | + $route = isset($query_args['action']) ? $query_args['action'] : 'default'; |
|
| 3631 | + $this->_add_transient( |
|
| 3632 | + $route, |
|
| 3633 | + $this->_template_args['notices'], |
|
| 3634 | + true, |
|
| 3635 | + $skip_route_verify |
|
| 3636 | + ); |
|
| 3637 | + } |
|
| 3638 | + } |
|
| 3639 | + |
|
| 3640 | + |
|
| 3641 | + /** |
|
| 3642 | + * get_action_link_or_button |
|
| 3643 | + * returns the button html for adding, editing, or deleting an item (depending on given type) |
|
| 3644 | + * |
|
| 3645 | + * @param string $action use this to indicate which action the url is generated with. |
|
| 3646 | + * @param string $type accepted strings must be defined in the $_labels['button'] array(as the key) |
|
| 3647 | + * property. |
|
| 3648 | + * @param array $extra_request if the button requires extra params you can include them in $key=>$value pairs. |
|
| 3649 | + * @param string $class Use this to give the class for the button. Defaults to 'button-primary' |
|
| 3650 | + * @param string $base_url If this is not provided |
|
| 3651 | + * the _admin_base_url will be used as the default for the button base_url. |
|
| 3652 | + * Otherwise this value will be used. |
|
| 3653 | + * @param bool $exclude_nonce If true then no nonce will be in the generated button link. |
|
| 3654 | + * @return string |
|
| 3655 | + * @throws InvalidArgumentException |
|
| 3656 | + * @throws InvalidInterfaceException |
|
| 3657 | + * @throws InvalidDataTypeException |
|
| 3658 | + * @throws EE_Error |
|
| 3659 | + */ |
|
| 3660 | + public function get_action_link_or_button( |
|
| 3661 | + $action, |
|
| 3662 | + $type = 'add', |
|
| 3663 | + $extra_request = array(), |
|
| 3664 | + $class = 'button-primary', |
|
| 3665 | + $base_url = '', |
|
| 3666 | + $exclude_nonce = false |
|
| 3667 | + ) { |
|
| 3668 | + // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along) |
|
| 3669 | + if (empty($base_url) && ! isset($this->_page_routes[ $action ])) { |
|
| 3670 | + throw new EE_Error( |
|
| 3671 | + sprintf( |
|
| 3672 | + esc_html__( |
|
| 3673 | + 'There is no page route for given action for the button. This action was given: %s', |
|
| 3674 | + 'event_espresso' |
|
| 3675 | + ), |
|
| 3676 | + $action |
|
| 3677 | + ) |
|
| 3678 | + ); |
|
| 3679 | + } |
|
| 3680 | + if (! isset($this->_labels['buttons'][ $type ])) { |
|
| 3681 | + throw new EE_Error( |
|
| 3682 | + sprintf( |
|
| 3683 | + __( |
|
| 3684 | + 'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.', |
|
| 3685 | + 'event_espresso' |
|
| 3686 | + ), |
|
| 3687 | + $type |
|
| 3688 | + ) |
|
| 3689 | + ); |
|
| 3690 | + } |
|
| 3691 | + // finally check user access for this button. |
|
| 3692 | + $has_access = $this->check_user_access($action, true); |
|
| 3693 | + if (! $has_access) { |
|
| 3694 | + return ''; |
|
| 3695 | + } |
|
| 3696 | + $_base_url = ! $base_url ? $this->_admin_base_url : $base_url; |
|
| 3697 | + $query_args = array( |
|
| 3698 | + 'action' => $action, |
|
| 3699 | + ); |
|
| 3700 | + // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten. |
|
| 3701 | + if (! empty($extra_request)) { |
|
| 3702 | + $query_args = array_merge($extra_request, $query_args); |
|
| 3703 | + } |
|
| 3704 | + $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce); |
|
| 3705 | + return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class); |
|
| 3706 | + } |
|
| 3707 | + |
|
| 3708 | + |
|
| 3709 | + /** |
|
| 3710 | + * _per_page_screen_option |
|
| 3711 | + * Utility function for adding in a per_page_option in the screen_options_dropdown. |
|
| 3712 | + * |
|
| 3713 | + * @return void |
|
| 3714 | + * @throws InvalidArgumentException |
|
| 3715 | + * @throws InvalidInterfaceException |
|
| 3716 | + * @throws InvalidDataTypeException |
|
| 3717 | + */ |
|
| 3718 | + protected function _per_page_screen_option() |
|
| 3719 | + { |
|
| 3720 | + $option = 'per_page'; |
|
| 3721 | + $args = array( |
|
| 3722 | + 'label' => apply_filters( |
|
| 3723 | + 'FHEE__EE_Admin_Page___per_page_screen_options___label', |
|
| 3724 | + $this->_admin_page_title, |
|
| 3725 | + $this |
|
| 3726 | + ), |
|
| 3727 | + 'default' => (int) apply_filters( |
|
| 3728 | + 'FHEE__EE_Admin_Page___per_page_screen_options__default', |
|
| 3729 | + 20 |
|
| 3730 | + ), |
|
| 3731 | + 'option' => $this->_current_page . '_' . $this->_current_view . '_per_page', |
|
| 3732 | + ); |
|
| 3733 | + // ONLY add the screen option if the user has access to it. |
|
| 3734 | + if ($this->check_user_access($this->_current_view, true)) { |
|
| 3735 | + add_screen_option($option, $args); |
|
| 3736 | + } |
|
| 3737 | + } |
|
| 3738 | + |
|
| 3739 | + |
|
| 3740 | + /** |
|
| 3741 | + * set_per_page_screen_option |
|
| 3742 | + * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page. |
|
| 3743 | + * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than |
|
| 3744 | + * admin_menu. |
|
| 3745 | + * |
|
| 3746 | + * @return void |
|
| 3747 | + */ |
|
| 3748 | + private function _set_per_page_screen_options() |
|
| 3749 | + { |
|
| 3750 | + if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) { |
|
| 3751 | + check_admin_referer('screen-options-nonce', 'screenoptionnonce'); |
|
| 3752 | + if (! $user = wp_get_current_user()) { |
|
| 3753 | + return; |
|
| 3754 | + } |
|
| 3755 | + $option = $_POST['wp_screen_options']['option']; |
|
| 3756 | + $value = $_POST['wp_screen_options']['value']; |
|
| 3757 | + if ($option != sanitize_key($option)) { |
|
| 3758 | + return; |
|
| 3759 | + } |
|
| 3760 | + $map_option = $option; |
|
| 3761 | + $option = str_replace('-', '_', $option); |
|
| 3762 | + switch ($map_option) { |
|
| 3763 | + case $this->_current_page . '_' . $this->_current_view . '_per_page': |
|
| 3764 | + $value = (int) $value; |
|
| 3765 | + $max_value = apply_filters( |
|
| 3766 | + 'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value', |
|
| 3767 | + 999, |
|
| 3768 | + $this->_current_page, |
|
| 3769 | + $this->_current_view |
|
| 3770 | + ); |
|
| 3771 | + if ($value < 1) { |
|
| 3772 | + return; |
|
| 3773 | + } |
|
| 3774 | + $value = min($value, $max_value); |
|
| 3775 | + break; |
|
| 3776 | + default: |
|
| 3777 | + $value = apply_filters( |
|
| 3778 | + 'FHEE__EE_Admin_Page___set_per_page_screen_options__value', |
|
| 3779 | + false, |
|
| 3780 | + $option, |
|
| 3781 | + $value |
|
| 3782 | + ); |
|
| 3783 | + if (false === $value) { |
|
| 3784 | + return; |
|
| 3785 | + } |
|
| 3786 | + break; |
|
| 3787 | + } |
|
| 3788 | + update_user_meta($user->ID, $option, $value); |
|
| 3789 | + wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer())); |
|
| 3790 | + exit; |
|
| 3791 | + } |
|
| 3792 | + } |
|
| 3793 | + |
|
| 3794 | + |
|
| 3795 | + /** |
|
| 3796 | + * This just allows for setting the $_template_args property if it needs to be set outside the object |
|
| 3797 | + * |
|
| 3798 | + * @param array $data array that will be assigned to template args. |
|
| 3799 | + */ |
|
| 3800 | + public function set_template_args($data) |
|
| 3801 | + { |
|
| 3802 | + $this->_template_args = array_merge($this->_template_args, (array) $data); |
|
| 3803 | + } |
|
| 3804 | + |
|
| 3805 | + |
|
| 3806 | + /** |
|
| 3807 | + * This makes available the WP transient system for temporarily moving data between routes |
|
| 3808 | + * |
|
| 3809 | + * @param string $route the route that should receive the transient |
|
| 3810 | + * @param array $data the data that gets sent |
|
| 3811 | + * @param bool $notices If this is for notices then we use this to indicate so, otherwise its just a |
|
| 3812 | + * normal route transient. |
|
| 3813 | + * @param bool $skip_route_verify Used to indicate we want to skip route verification. This is usually ONLY used |
|
| 3814 | + * when we are adding a transient before page_routes have been defined. |
|
| 3815 | + * @return void |
|
| 3816 | + * @throws EE_Error |
|
| 3817 | + */ |
|
| 3818 | + protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false) |
|
| 3819 | + { |
|
| 3820 | + $user_id = get_current_user_id(); |
|
| 3821 | + if (! $skip_route_verify) { |
|
| 3822 | + $this->_verify_route($route); |
|
| 3823 | + } |
|
| 3824 | + // now let's set the string for what kind of transient we're setting |
|
| 3825 | + $transient = $notices |
|
| 3826 | + ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3827 | + : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3828 | + $data = $notices ? array('notices' => $data) : $data; |
|
| 3829 | + // is there already a transient for this route? If there is then let's ADD to that transient |
|
| 3830 | + $existing = is_multisite() && is_network_admin() |
|
| 3831 | + ? get_site_transient($transient) |
|
| 3832 | + : get_transient($transient); |
|
| 3833 | + if ($existing) { |
|
| 3834 | + $data = array_merge((array) $data, (array) $existing); |
|
| 3835 | + } |
|
| 3836 | + if (is_multisite() && is_network_admin()) { |
|
| 3837 | + set_site_transient($transient, $data, 8); |
|
| 3838 | + } else { |
|
| 3839 | + set_transient($transient, $data, 8); |
|
| 3840 | + } |
|
| 3841 | + } |
|
| 3842 | + |
|
| 3843 | + |
|
| 3844 | + /** |
|
| 3845 | + * this retrieves the temporary transient that has been set for moving data between routes. |
|
| 3846 | + * |
|
| 3847 | + * @param bool $notices true we get notices transient. False we just return normal route transient |
|
| 3848 | + * @param string $route |
|
| 3849 | + * @return mixed data |
|
| 3850 | + */ |
|
| 3851 | + protected function _get_transient($notices = false, $route = '') |
|
| 3852 | + { |
|
| 3853 | + $user_id = get_current_user_id(); |
|
| 3854 | + $route = ! $route ? $this->_req_action : $route; |
|
| 3855 | + $transient = $notices |
|
| 3856 | + ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3857 | + : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3858 | + $data = is_multisite() && is_network_admin() |
|
| 3859 | + ? get_site_transient($transient) |
|
| 3860 | + : get_transient($transient); |
|
| 3861 | + // delete transient after retrieval (just in case it hasn't expired); |
|
| 3862 | + if (is_multisite() && is_network_admin()) { |
|
| 3863 | + delete_site_transient($transient); |
|
| 3864 | + } else { |
|
| 3865 | + delete_transient($transient); |
|
| 3866 | + } |
|
| 3867 | + return $notices && isset($data['notices']) ? $data['notices'] : $data; |
|
| 3868 | + } |
|
| 3869 | + |
|
| 3870 | + |
|
| 3871 | + /** |
|
| 3872 | + * The purpose of this method is just to run garbage collection on any EE transients that might have expired but |
|
| 3873 | + * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the |
|
| 3874 | + * default route callback on the EE_Admin page you want it run.) |
|
| 3875 | + * |
|
| 3876 | + * @return void |
|
| 3877 | + */ |
|
| 3878 | + protected function _transient_garbage_collection() |
|
| 3879 | + { |
|
| 3880 | + global $wpdb; |
|
| 3881 | + // retrieve all existing transients |
|
| 3882 | + $query = "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'"; |
|
| 3883 | + if ($results = $wpdb->get_results($query)) { |
|
| 3884 | + foreach ($results as $result) { |
|
| 3885 | + $transient = str_replace('_transient_', '', $result->option_name); |
|
| 3886 | + get_transient($transient); |
|
| 3887 | + if (is_multisite() && is_network_admin()) { |
|
| 3888 | + get_site_transient($transient); |
|
| 3889 | + } |
|
| 3890 | + } |
|
| 3891 | + } |
|
| 3892 | + } |
|
| 3893 | + |
|
| 3894 | + |
|
| 3895 | + /** |
|
| 3896 | + * get_view |
|
| 3897 | + * |
|
| 3898 | + * @return string content of _view property |
|
| 3899 | + */ |
|
| 3900 | + public function get_view() |
|
| 3901 | + { |
|
| 3902 | + return $this->_view; |
|
| 3903 | + } |
|
| 3904 | + |
|
| 3905 | + |
|
| 3906 | + /** |
|
| 3907 | + * getter for the protected $_views property |
|
| 3908 | + * |
|
| 3909 | + * @return array |
|
| 3910 | + */ |
|
| 3911 | + public function get_views() |
|
| 3912 | + { |
|
| 3913 | + return $this->_views; |
|
| 3914 | + } |
|
| 3915 | + |
|
| 3916 | + |
|
| 3917 | + /** |
|
| 3918 | + * get_current_page |
|
| 3919 | + * |
|
| 3920 | + * @return string _current_page property value |
|
| 3921 | + */ |
|
| 3922 | + public function get_current_page() |
|
| 3923 | + { |
|
| 3924 | + return $this->_current_page; |
|
| 3925 | + } |
|
| 3926 | + |
|
| 3927 | + |
|
| 3928 | + /** |
|
| 3929 | + * get_current_view |
|
| 3930 | + * |
|
| 3931 | + * @return string _current_view property value |
|
| 3932 | + */ |
|
| 3933 | + public function get_current_view() |
|
| 3934 | + { |
|
| 3935 | + return $this->_current_view; |
|
| 3936 | + } |
|
| 3937 | + |
|
| 3938 | + |
|
| 3939 | + /** |
|
| 3940 | + * get_current_screen |
|
| 3941 | + * |
|
| 3942 | + * @return object The current WP_Screen object |
|
| 3943 | + */ |
|
| 3944 | + public function get_current_screen() |
|
| 3945 | + { |
|
| 3946 | + return $this->_current_screen; |
|
| 3947 | + } |
|
| 3948 | + |
|
| 3949 | + |
|
| 3950 | + /** |
|
| 3951 | + * get_current_page_view_url |
|
| 3952 | + * |
|
| 3953 | + * @return string This returns the url for the current_page_view. |
|
| 3954 | + */ |
|
| 3955 | + public function get_current_page_view_url() |
|
| 3956 | + { |
|
| 3957 | + return $this->_current_page_view_url; |
|
| 3958 | + } |
|
| 3959 | + |
|
| 3960 | + |
|
| 3961 | + /** |
|
| 3962 | + * just returns the _req_data property |
|
| 3963 | + * |
|
| 3964 | + * @return array |
|
| 3965 | + */ |
|
| 3966 | + public function get_request_data() |
|
| 3967 | + { |
|
| 3968 | + return $this->_req_data; |
|
| 3969 | + } |
|
| 3970 | + |
|
| 3971 | + |
|
| 3972 | + /** |
|
| 3973 | + * returns the _req_data protected property |
|
| 3974 | + * |
|
| 3975 | + * @return string |
|
| 3976 | + */ |
|
| 3977 | + public function get_req_action() |
|
| 3978 | + { |
|
| 3979 | + return $this->_req_action; |
|
| 3980 | + } |
|
| 3981 | + |
|
| 3982 | + |
|
| 3983 | + /** |
|
| 3984 | + * @return bool value of $_is_caf property |
|
| 3985 | + */ |
|
| 3986 | + public function is_caf() |
|
| 3987 | + { |
|
| 3988 | + return $this->_is_caf; |
|
| 3989 | + } |
|
| 3990 | + |
|
| 3991 | + |
|
| 3992 | + /** |
|
| 3993 | + * @return mixed |
|
| 3994 | + */ |
|
| 3995 | + public function default_espresso_metaboxes() |
|
| 3996 | + { |
|
| 3997 | + return $this->_default_espresso_metaboxes; |
|
| 3998 | + } |
|
| 3999 | + |
|
| 4000 | + |
|
| 4001 | + /** |
|
| 4002 | + * @return mixed |
|
| 4003 | + */ |
|
| 4004 | + public function admin_base_url() |
|
| 4005 | + { |
|
| 4006 | + return $this->_admin_base_url; |
|
| 4007 | + } |
|
| 4008 | + |
|
| 4009 | + |
|
| 4010 | + /** |
|
| 4011 | + * @return mixed |
|
| 4012 | + */ |
|
| 4013 | + public function wp_page_slug() |
|
| 4014 | + { |
|
| 4015 | + return $this->_wp_page_slug; |
|
| 4016 | + } |
|
| 4017 | + |
|
| 4018 | + |
|
| 4019 | + /** |
|
| 4020 | + * updates espresso configuration settings |
|
| 4021 | + * |
|
| 4022 | + * @param string $tab |
|
| 4023 | + * @param EE_Config_Base|EE_Config $config |
|
| 4024 | + * @param string $file file where error occurred |
|
| 4025 | + * @param string $func function where error occurred |
|
| 4026 | + * @param string $line line no where error occurred |
|
| 4027 | + * @return boolean |
|
| 4028 | + */ |
|
| 4029 | + protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '') |
|
| 4030 | + { |
|
| 4031 | + // remove any options that are NOT going to be saved with the config settings. |
|
| 4032 | + if (isset($config->core->ee_ueip_optin)) { |
|
| 4033 | + // TODO: remove the following two lines and make sure values are migrated from 3.1 |
|
| 4034 | + update_option('ee_ueip_optin', $config->core->ee_ueip_optin); |
|
| 4035 | + update_option('ee_ueip_has_notified', true); |
|
| 4036 | + } |
|
| 4037 | + // and save it (note we're also doing the network save here) |
|
| 4038 | + $net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true; |
|
| 4039 | + $config_saved = EE_Config::instance()->update_espresso_config(false, false); |
|
| 4040 | + if ($config_saved && $net_saved) { |
|
| 4041 | + EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab)); |
|
| 4042 | + return true; |
|
| 4043 | + } |
|
| 4044 | + EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line); |
|
| 4045 | + return false; |
|
| 4046 | + } |
|
| 4047 | + |
|
| 4048 | + |
|
| 4049 | + /** |
|
| 4050 | + * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument. |
|
| 4051 | + * |
|
| 4052 | + * @return array |
|
| 4053 | + */ |
|
| 4054 | + public function get_yes_no_values() |
|
| 4055 | + { |
|
| 4056 | + return $this->_yes_no_values; |
|
| 4057 | + } |
|
| 4058 | + |
|
| 4059 | + |
|
| 4060 | + protected function _get_dir() |
|
| 4061 | + { |
|
| 4062 | + $reflector = new ReflectionClass(get_class($this)); |
|
| 4063 | + return dirname($reflector->getFileName()); |
|
| 4064 | + } |
|
| 4065 | + |
|
| 4066 | + |
|
| 4067 | + /** |
|
| 4068 | + * A helper for getting a "next link". |
|
| 4069 | + * |
|
| 4070 | + * @param string $url The url to link to |
|
| 4071 | + * @param string $class The class to use. |
|
| 4072 | + * @return string |
|
| 4073 | + */ |
|
| 4074 | + protected function _next_link($url, $class = 'dashicons dashicons-arrow-right') |
|
| 4075 | + { |
|
| 4076 | + return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4077 | + } |
|
| 4078 | + |
|
| 4079 | + |
|
| 4080 | + /** |
|
| 4081 | + * A helper for getting a "previous link". |
|
| 4082 | + * |
|
| 4083 | + * @param string $url The url to link to |
|
| 4084 | + * @param string $class The class to use. |
|
| 4085 | + * @return string |
|
| 4086 | + */ |
|
| 4087 | + protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left') |
|
| 4088 | + { |
|
| 4089 | + return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4090 | + } |
|
| 4091 | + |
|
| 4092 | + |
|
| 4093 | + |
|
| 4094 | + |
|
| 4095 | + |
|
| 4096 | + |
|
| 4097 | + |
|
| 4098 | + // below are some messages related methods that should be available across the EE_Admin system. Note, these methods are NOT page specific |
|
| 4099 | + |
|
| 4100 | + |
|
| 4101 | + /** |
|
| 4102 | + * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller |
|
| 4103 | + * 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 |
|
| 4104 | + * _req_data array. |
|
| 4105 | + * |
|
| 4106 | + * @return bool success/fail |
|
| 4107 | + * @throws EE_Error |
|
| 4108 | + * @throws InvalidArgumentException |
|
| 4109 | + * @throws ReflectionException |
|
| 4110 | + * @throws InvalidDataTypeException |
|
| 4111 | + * @throws InvalidInterfaceException |
|
| 4112 | + */ |
|
| 4113 | + protected function _process_resend_registration() |
|
| 4114 | + { |
|
| 4115 | + $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data); |
|
| 4116 | + do_action( |
|
| 4117 | + 'AHEE__EE_Admin_Page___process_resend_registration', |
|
| 4118 | + $this->_template_args['success'], |
|
| 4119 | + $this->_req_data |
|
| 4120 | + ); |
|
| 4121 | + return $this->_template_args['success']; |
|
| 4122 | + } |
|
| 4123 | + |
|
| 4124 | + |
|
| 4125 | + /** |
|
| 4126 | + * This automatically processes any payment message notifications when manual payment has been applied. |
|
| 4127 | + * |
|
| 4128 | + * @param \EE_Payment $payment |
|
| 4129 | + * @return bool success/fail |
|
| 4130 | + */ |
|
| 4131 | + protected function _process_payment_notification(EE_Payment $payment) |
|
| 4132 | + { |
|
| 4133 | + add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true'); |
|
| 4134 | + do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment); |
|
| 4135 | + $this->_template_args['success'] = apply_filters( |
|
| 4136 | + 'FHEE__EE_Admin_Page___process_admin_payment_notification__success', |
|
| 4137 | + false, |
|
| 4138 | + $payment |
|
| 4139 | + ); |
|
| 4140 | + return $this->_template_args['success']; |
|
| 4141 | + } |
|
| 4142 | 4142 | } |
@@ -500,7 +500,7 @@ discard block |
||
| 500 | 500 | ); |
| 501 | 501 | global $ee_menu_slugs; |
| 502 | 502 | $ee_menu_slugs = (array) $ee_menu_slugs; |
| 503 | - if (! defined('DOING_AJAX') && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ]))) { |
|
| 503 | + if ( ! defined('DOING_AJAX') && ( ! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page]))) { |
|
| 504 | 504 | return; |
| 505 | 505 | } |
| 506 | 506 | // becuz WP List tables have two duplicate select inputs for choosing bulk actions, we need to copy the action from the second to the first |
@@ -524,7 +524,7 @@ discard block |
||
| 524 | 524 | ? $this->_req_data['route'] |
| 525 | 525 | : $this->_req_action; |
| 526 | 526 | $this->_current_view = $this->_req_action; |
| 527 | - $this->_req_nonce = $this->_req_action . '_nonce'; |
|
| 527 | + $this->_req_nonce = $this->_req_action.'_nonce'; |
|
| 528 | 528 | $this->_define_page_props(); |
| 529 | 529 | $this->_current_page_view_url = add_query_arg( |
| 530 | 530 | array('page' => $this->_current_page, 'action' => $this->_current_view), |
@@ -558,21 +558,21 @@ discard block |
||
| 558 | 558 | } |
| 559 | 559 | // filter routes and page_config so addons can add their stuff. Filtering done per class |
| 560 | 560 | $this->_page_routes = apply_filters( |
| 561 | - 'FHEE__' . get_class($this) . '__page_setup__page_routes', |
|
| 561 | + 'FHEE__'.get_class($this).'__page_setup__page_routes', |
|
| 562 | 562 | $this->_page_routes, |
| 563 | 563 | $this |
| 564 | 564 | ); |
| 565 | 565 | $this->_page_config = apply_filters( |
| 566 | - 'FHEE__' . get_class($this) . '__page_setup__page_config', |
|
| 566 | + 'FHEE__'.get_class($this).'__page_setup__page_config', |
|
| 567 | 567 | $this->_page_config, |
| 568 | 568 | $this |
| 569 | 569 | ); |
| 570 | 570 | // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present |
| 571 | 571 | // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action |
| 572 | - if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) { |
|
| 572 | + if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_'.$this->_current_view)) { |
|
| 573 | 573 | add_action( |
| 574 | 574 | 'AHEE__EE_Admin_Page__route_admin_request', |
| 575 | - array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view), |
|
| 575 | + array($this, 'AHEE__EE_Admin_Page__route_admin_request_'.$this->_current_view), |
|
| 576 | 576 | 10, |
| 577 | 577 | 2 |
| 578 | 578 | ); |
@@ -585,8 +585,8 @@ discard block |
||
| 585 | 585 | if ($this->_is_UI_request) { |
| 586 | 586 | // admin_init stuff - global, all views for this page class, specific view |
| 587 | 587 | add_action('admin_init', array($this, 'admin_init'), 10); |
| 588 | - if (method_exists($this, 'admin_init_' . $this->_current_view)) { |
|
| 589 | - add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15); |
|
| 588 | + if (method_exists($this, 'admin_init_'.$this->_current_view)) { |
|
| 589 | + add_action('admin_init', array($this, 'admin_init_'.$this->_current_view), 15); |
|
| 590 | 590 | } |
| 591 | 591 | } else { |
| 592 | 592 | // hijack regular WP loading and route admin request immediately |
@@ -606,12 +606,12 @@ discard block |
||
| 606 | 606 | */ |
| 607 | 607 | private function _do_other_page_hooks() |
| 608 | 608 | { |
| 609 | - $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array()); |
|
| 609 | + $registered_pages = apply_filters('FHEE_do_other_page_hooks_'.$this->page_slug, array()); |
|
| 610 | 610 | foreach ($registered_pages as $page) { |
| 611 | 611 | // now let's setup the file name and class that should be present |
| 612 | 612 | $classname = str_replace('.class.php', '', $page); |
| 613 | 613 | // autoloaders should take care of loading file |
| 614 | - if (! class_exists($classname)) { |
|
| 614 | + if ( ! class_exists($classname)) { |
|
| 615 | 615 | $error_msg[] = sprintf( |
| 616 | 616 | esc_html__( |
| 617 | 617 | 'Something went wrong with loading the %s admin hooks page.', |
@@ -628,7 +628,7 @@ discard block |
||
| 628 | 628 | ), |
| 629 | 629 | $page, |
| 630 | 630 | '<br />', |
| 631 | - '<strong>' . $classname . '</strong>' |
|
| 631 | + '<strong>'.$classname.'</strong>' |
|
| 632 | 632 | ); |
| 633 | 633 | throw new EE_Error(implode('||', $error_msg)); |
| 634 | 634 | } |
@@ -668,13 +668,13 @@ discard block |
||
| 668 | 668 | // load admin_notices - global, page class, and view specific |
| 669 | 669 | add_action('admin_notices', array($this, 'admin_notices_global'), 5); |
| 670 | 670 | add_action('admin_notices', array($this, 'admin_notices'), 10); |
| 671 | - if (method_exists($this, 'admin_notices_' . $this->_current_view)) { |
|
| 672 | - add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15); |
|
| 671 | + if (method_exists($this, 'admin_notices_'.$this->_current_view)) { |
|
| 672 | + add_action('admin_notices', array($this, 'admin_notices_'.$this->_current_view), 15); |
|
| 673 | 673 | } |
| 674 | 674 | // load network admin_notices - global, page class, and view specific |
| 675 | 675 | add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5); |
| 676 | - if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) { |
|
| 677 | - add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view)); |
|
| 676 | + if (method_exists($this, 'network_admin_notices_'.$this->_current_view)) { |
|
| 677 | + add_action('network_admin_notices', array($this, 'network_admin_notices_'.$this->_current_view)); |
|
| 678 | 678 | } |
| 679 | 679 | // this will save any per_page screen options if they are present |
| 680 | 680 | $this->_set_per_page_screen_options(); |
@@ -796,7 +796,7 @@ discard block |
||
| 796 | 796 | protected function _verify_routes() |
| 797 | 797 | { |
| 798 | 798 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 799 | - if (! $this->_current_page && ! defined('DOING_AJAX')) { |
|
| 799 | + if ( ! $this->_current_page && ! defined('DOING_AJAX')) { |
|
| 800 | 800 | return false; |
| 801 | 801 | } |
| 802 | 802 | $this->_route = false; |
@@ -808,7 +808,7 @@ discard block |
||
| 808 | 808 | $this->_admin_page_title |
| 809 | 809 | ); |
| 810 | 810 | // developer error msg |
| 811 | - $error_msg .= '||' . $error_msg |
|
| 811 | + $error_msg .= '||'.$error_msg |
|
| 812 | 812 | . esc_html__( |
| 813 | 813 | ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', |
| 814 | 814 | 'event_espresso' |
@@ -817,9 +817,9 @@ discard block |
||
| 817 | 817 | } |
| 818 | 818 | // and that the requested page route exists |
| 819 | 819 | if (array_key_exists($this->_req_action, $this->_page_routes)) { |
| 820 | - $this->_route = $this->_page_routes[ $this->_req_action ]; |
|
| 821 | - $this->_route_config = isset($this->_page_config[ $this->_req_action ]) |
|
| 822 | - ? $this->_page_config[ $this->_req_action ] : array(); |
|
| 820 | + $this->_route = $this->_page_routes[$this->_req_action]; |
|
| 821 | + $this->_route_config = isset($this->_page_config[$this->_req_action]) |
|
| 822 | + ? $this->_page_config[$this->_req_action] : array(); |
|
| 823 | 823 | } else { |
| 824 | 824 | // user error msg |
| 825 | 825 | $error_msg = sprintf( |
@@ -830,7 +830,7 @@ discard block |
||
| 830 | 830 | $this->_admin_page_title |
| 831 | 831 | ); |
| 832 | 832 | // developer error msg |
| 833 | - $error_msg .= '||' . $error_msg |
|
| 833 | + $error_msg .= '||'.$error_msg |
|
| 834 | 834 | . sprintf( |
| 835 | 835 | esc_html__( |
| 836 | 836 | ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', |
@@ -841,7 +841,7 @@ discard block |
||
| 841 | 841 | throw new EE_Error($error_msg); |
| 842 | 842 | } |
| 843 | 843 | // and that a default route exists |
| 844 | - if (! array_key_exists('default', $this->_page_routes)) { |
|
| 844 | + if ( ! array_key_exists('default', $this->_page_routes)) { |
|
| 845 | 845 | // user error msg |
| 846 | 846 | $error_msg = sprintf( |
| 847 | 847 | esc_html__( |
@@ -851,7 +851,7 @@ discard block |
||
| 851 | 851 | $this->_admin_page_title |
| 852 | 852 | ); |
| 853 | 853 | // developer error msg |
| 854 | - $error_msg .= '||' . $error_msg |
|
| 854 | + $error_msg .= '||'.$error_msg |
|
| 855 | 855 | . esc_html__( |
| 856 | 856 | ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', |
| 857 | 857 | 'event_espresso' |
@@ -890,7 +890,7 @@ discard block |
||
| 890 | 890 | $this->_admin_page_title |
| 891 | 891 | ); |
| 892 | 892 | // developer error msg |
| 893 | - $error_msg .= '||' . $error_msg |
|
| 893 | + $error_msg .= '||'.$error_msg |
|
| 894 | 894 | . sprintf( |
| 895 | 895 | esc_html__( |
| 896 | 896 | ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', |
@@ -915,7 +915,7 @@ discard block |
||
| 915 | 915 | protected function _verify_nonce($nonce, $nonce_ref) |
| 916 | 916 | { |
| 917 | 917 | // verify nonce against expected value |
| 918 | - if (! wp_verify_nonce($nonce, $nonce_ref)) { |
|
| 918 | + if ( ! wp_verify_nonce($nonce, $nonce_ref)) { |
|
| 919 | 919 | // these are not the droids you are looking for !!! |
| 920 | 920 | $msg = sprintf( |
| 921 | 921 | esc_html__('%sNonce Fail.%s', 'event_espresso'), |
@@ -932,7 +932,7 @@ discard block |
||
| 932 | 932 | __CLASS__ |
| 933 | 933 | ); |
| 934 | 934 | } |
| 935 | - if (! defined('DOING_AJAX')) { |
|
| 935 | + if ( ! defined('DOING_AJAX')) { |
|
| 936 | 936 | wp_die($msg); |
| 937 | 937 | } else { |
| 938 | 938 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
@@ -957,7 +957,7 @@ discard block |
||
| 957 | 957 | */ |
| 958 | 958 | protected function _route_admin_request() |
| 959 | 959 | { |
| 960 | - if (! $this->_is_UI_request) { |
|
| 960 | + if ( ! $this->_is_UI_request) { |
|
| 961 | 961 | $this->_verify_routes(); |
| 962 | 962 | } |
| 963 | 963 | $nonce_check = isset($this->_route_config['require_nonce']) |
@@ -965,8 +965,8 @@ discard block |
||
| 965 | 965 | : true; |
| 966 | 966 | if ($this->_req_action !== 'default' && $nonce_check) { |
| 967 | 967 | // set nonce from post data |
| 968 | - $nonce = isset($this->_req_data[ $this->_req_nonce ]) |
|
| 969 | - ? sanitize_text_field($this->_req_data[ $this->_req_nonce ]) |
|
| 968 | + $nonce = isset($this->_req_data[$this->_req_nonce]) |
|
| 969 | + ? sanitize_text_field($this->_req_data[$this->_req_nonce]) |
|
| 970 | 970 | : ''; |
| 971 | 971 | $this->_verify_nonce($nonce, $this->_req_nonce); |
| 972 | 972 | } |
@@ -981,7 +981,7 @@ discard block |
||
| 981 | 981 | $error_msg = ''; |
| 982 | 982 | // action right before calling route |
| 983 | 983 | // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request') |
| 984 | - if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
| 984 | + if ( ! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
| 985 | 985 | do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this); |
| 986 | 986 | } |
| 987 | 987 | // right before calling the route, let's remove _wp_http_referer from the |
@@ -990,7 +990,7 @@ discard block |
||
| 990 | 990 | '_wp_http_referer', |
| 991 | 991 | wp_unslash($_SERVER['REQUEST_URI']) |
| 992 | 992 | ); |
| 993 | - if (! empty($func)) { |
|
| 993 | + if ( ! empty($func)) { |
|
| 994 | 994 | if (is_array($func)) { |
| 995 | 995 | list($class, $method) = $func; |
| 996 | 996 | } elseif (strpos($func, '::') !== false) { |
@@ -999,7 +999,7 @@ discard block |
||
| 999 | 999 | $class = $this; |
| 1000 | 1000 | $method = $func; |
| 1001 | 1001 | } |
| 1002 | - if (! (is_object($class) && $class === $this)) { |
|
| 1002 | + if ( ! (is_object($class) && $class === $this)) { |
|
| 1003 | 1003 | // send along this admin page object for access by addons. |
| 1004 | 1004 | $args['admin_page_object'] = $this; |
| 1005 | 1005 | } |
@@ -1039,7 +1039,7 @@ discard block |
||
| 1039 | 1039 | $method |
| 1040 | 1040 | ); |
| 1041 | 1041 | } |
| 1042 | - if (! empty($error_msg)) { |
|
| 1042 | + if ( ! empty($error_msg)) { |
|
| 1043 | 1043 | throw new EE_Error($error_msg); |
| 1044 | 1044 | } |
| 1045 | 1045 | } |
@@ -1123,7 +1123,7 @@ discard block |
||
| 1123 | 1123 | if (strpos($key, 'nonce') !== false) { |
| 1124 | 1124 | continue; |
| 1125 | 1125 | } |
| 1126 | - $args[ 'wp_referer[' . $key . ']' ] = $value; |
|
| 1126 | + $args['wp_referer['.$key.']'] = $value; |
|
| 1127 | 1127 | } |
| 1128 | 1128 | } |
| 1129 | 1129 | return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce); |
@@ -1163,8 +1163,8 @@ discard block |
||
| 1163 | 1163 | protected function _add_help_tabs() |
| 1164 | 1164 | { |
| 1165 | 1165 | $tour_buttons = ''; |
| 1166 | - if (isset($this->_page_config[ $this->_req_action ])) { |
|
| 1167 | - $config = $this->_page_config[ $this->_req_action ]; |
|
| 1166 | + if (isset($this->_page_config[$this->_req_action])) { |
|
| 1167 | + $config = $this->_page_config[$this->_req_action]; |
|
| 1168 | 1168 | // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
| 1169 | 1169 | // is there a help tour for the current route? if there is let's setup the tour buttons |
| 1170 | 1170 | // if (isset($this->_help_tour[ $this->_req_action ])) { |
@@ -1187,7 +1187,7 @@ discard block |
||
| 1187 | 1187 | // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well. |
| 1188 | 1188 | if (is_array($config) && isset($config['help_sidebar'])) { |
| 1189 | 1189 | // check that the callback given is valid |
| 1190 | - if (! method_exists($this, $config['help_sidebar'])) { |
|
| 1190 | + if ( ! method_exists($this, $config['help_sidebar'])) { |
|
| 1191 | 1191 | throw new EE_Error( |
| 1192 | 1192 | sprintf( |
| 1193 | 1193 | esc_html__( |
@@ -1200,7 +1200,7 @@ discard block |
||
| 1200 | 1200 | ); |
| 1201 | 1201 | } |
| 1202 | 1202 | $content = apply_filters( |
| 1203 | - 'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', |
|
| 1203 | + 'FHEE__'.get_class($this).'__add_help_tabs__help_sidebar', |
|
| 1204 | 1204 | $this->{$config['help_sidebar']}() |
| 1205 | 1205 | ); |
| 1206 | 1206 | $content .= $tour_buttons; // add help tour buttons. |
@@ -1208,27 +1208,27 @@ discard block |
||
| 1208 | 1208 | $this->_current_screen->set_help_sidebar($content); |
| 1209 | 1209 | } |
| 1210 | 1210 | // if we DON'T have config help sidebar and there ARE tour buttons then we'll just add the tour buttons to the sidebar. |
| 1211 | - if (! isset($config['help_sidebar']) && ! empty($tour_buttons)) { |
|
| 1211 | + if ( ! isset($config['help_sidebar']) && ! empty($tour_buttons)) { |
|
| 1212 | 1212 | $this->_current_screen->set_help_sidebar($tour_buttons); |
| 1213 | 1213 | } |
| 1214 | 1214 | // handle if no help_tabs are set so the sidebar will still show for the help tour buttons |
| 1215 | - if (! isset($config['help_tabs']) && ! empty($tour_buttons)) { |
|
| 1215 | + if ( ! isset($config['help_tabs']) && ! empty($tour_buttons)) { |
|
| 1216 | 1216 | $_ht['id'] = $this->page_slug; |
| 1217 | 1217 | $_ht['title'] = esc_html__('Help Tours', 'event_espresso'); |
| 1218 | 1218 | $_ht['content'] = '<p>' |
| 1219 | 1219 | . esc_html__( |
| 1220 | 1220 | 'The buttons to the right allow you to start/restart any help tours available for this page', |
| 1221 | 1221 | 'event_espresso' |
| 1222 | - ) . '</p>'; |
|
| 1222 | + ).'</p>'; |
|
| 1223 | 1223 | $this->_current_screen->add_help_tab($_ht); |
| 1224 | 1224 | } |
| 1225 | - if (! isset($config['help_tabs'])) { |
|
| 1225 | + if ( ! isset($config['help_tabs'])) { |
|
| 1226 | 1226 | return; |
| 1227 | 1227 | } //no help tabs for this route |
| 1228 | 1228 | foreach ((array) $config['help_tabs'] as $tab_id => $cfg) { |
| 1229 | 1229 | // we're here so there ARE help tabs! |
| 1230 | 1230 | // make sure we've got what we need |
| 1231 | - if (! isset($cfg['title'])) { |
|
| 1231 | + if ( ! isset($cfg['title'])) { |
|
| 1232 | 1232 | throw new EE_Error( |
| 1233 | 1233 | esc_html__( |
| 1234 | 1234 | 'The _page_config array is not set up properly for help tabs. It is missing a title', |
@@ -1236,7 +1236,7 @@ discard block |
||
| 1236 | 1236 | ) |
| 1237 | 1237 | ); |
| 1238 | 1238 | } |
| 1239 | - if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
| 1239 | + if ( ! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
| 1240 | 1240 | throw new EE_Error( |
| 1241 | 1241 | esc_html__( |
| 1242 | 1242 | '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', |
@@ -1245,11 +1245,11 @@ discard block |
||
| 1245 | 1245 | ); |
| 1246 | 1246 | } |
| 1247 | 1247 | // first priority goes to content. |
| 1248 | - if (! empty($cfg['content'])) { |
|
| 1248 | + if ( ! empty($cfg['content'])) { |
|
| 1249 | 1249 | $content = ! empty($cfg['content']) ? $cfg['content'] : null; |
| 1250 | 1250 | // second priority goes to filename |
| 1251 | - } elseif (! empty($cfg['filename'])) { |
|
| 1252 | - $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php'; |
|
| 1251 | + } elseif ( ! empty($cfg['filename'])) { |
|
| 1252 | + $file_path = $this->_get_dir().'/help_tabs/'.$cfg['filename'].'.help_tab.php'; |
|
| 1253 | 1253 | // 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) |
| 1254 | 1254 | $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
| 1255 | 1255 | . basename($this->_get_dir()) |
@@ -1257,7 +1257,7 @@ discard block |
||
| 1257 | 1257 | . $cfg['filename'] |
| 1258 | 1258 | . '.help_tab.php' : $file_path; |
| 1259 | 1259 | // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
| 1260 | - if (! isset($cfg['callback']) && ! is_readable($file_path)) { |
|
| 1260 | + if ( ! isset($cfg['callback']) && ! is_readable($file_path)) { |
|
| 1261 | 1261 | EE_Error::add_error( |
| 1262 | 1262 | sprintf( |
| 1263 | 1263 | esc_html__( |
@@ -1303,7 +1303,7 @@ discard block |
||
| 1303 | 1303 | return; |
| 1304 | 1304 | } |
| 1305 | 1305 | // setup config array for help tab method |
| 1306 | - $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id; |
|
| 1306 | + $id = $this->page_slug.'-'.$this->_req_action.'-'.$tab_id; |
|
| 1307 | 1307 | $_ht = array( |
| 1308 | 1308 | 'id' => $id, |
| 1309 | 1309 | 'title' => $cfg['title'], |
@@ -1431,8 +1431,8 @@ discard block |
||
| 1431 | 1431 | $qtips = (array) $this->_route_config['qtips']; |
| 1432 | 1432 | // load qtip loader |
| 1433 | 1433 | $path = array( |
| 1434 | - $this->_get_dir() . '/qtips/', |
|
| 1435 | - EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/', |
|
| 1434 | + $this->_get_dir().'/qtips/', |
|
| 1435 | + EE_ADMIN_PAGES.basename($this->_get_dir()).'/qtips/', |
|
| 1436 | 1436 | ); |
| 1437 | 1437 | EEH_Qtip_Loader::instance()->register($qtips, $path); |
| 1438 | 1438 | } |
@@ -1454,7 +1454,7 @@ discard block |
||
| 1454 | 1454 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 1455 | 1455 | $i = 0; |
| 1456 | 1456 | foreach ($this->_page_config as $slug => $config) { |
| 1457 | - if (! is_array($config) |
|
| 1457 | + if ( ! is_array($config) |
|
| 1458 | 1458 | || ( |
| 1459 | 1459 | is_array($config) |
| 1460 | 1460 | && ( |
@@ -1471,12 +1471,12 @@ discard block |
||
| 1471 | 1471 | // nav tab is only to appear when route requested. |
| 1472 | 1472 | continue; |
| 1473 | 1473 | } |
| 1474 | - if (! $this->check_user_access($slug, true)) { |
|
| 1474 | + if ( ! $this->check_user_access($slug, true)) { |
|
| 1475 | 1475 | // no nav tab because current user does not have access. |
| 1476 | 1476 | continue; |
| 1477 | 1477 | } |
| 1478 | - $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : ''; |
|
| 1479 | - $this->_nav_tabs[ $slug ] = array( |
|
| 1478 | + $css_class = isset($config['css_class']) ? $config['css_class'].' ' : ''; |
|
| 1479 | + $this->_nav_tabs[$slug] = array( |
|
| 1480 | 1480 | 'url' => isset($config['nav']['url']) |
| 1481 | 1481 | ? $config['nav']['url'] |
| 1482 | 1482 | : self::add_query_args_and_nonce( |
@@ -1488,14 +1488,14 @@ discard block |
||
| 1488 | 1488 | : ucwords( |
| 1489 | 1489 | str_replace('_', ' ', $slug) |
| 1490 | 1490 | ), |
| 1491 | - 'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class, |
|
| 1491 | + 'css_class' => $this->_req_action === $slug ? $css_class.'nav-tab-active' : $css_class, |
|
| 1492 | 1492 | 'order' => isset($config['nav']['order']) ? $config['nav']['order'] : $i, |
| 1493 | 1493 | ); |
| 1494 | 1494 | $i++; |
| 1495 | 1495 | } |
| 1496 | 1496 | // if $this->_nav_tabs is empty then lets set the default |
| 1497 | 1497 | if (empty($this->_nav_tabs)) { |
| 1498 | - $this->_nav_tabs[ $this->_default_nav_tab_name ] = array( |
|
| 1498 | + $this->_nav_tabs[$this->_default_nav_tab_name] = array( |
|
| 1499 | 1499 | 'url' => $this->_admin_base_url, |
| 1500 | 1500 | 'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)), |
| 1501 | 1501 | 'css_class' => 'nav-tab-active', |
@@ -1520,10 +1520,10 @@ discard block |
||
| 1520 | 1520 | foreach ($this->_route_config['labels'] as $label => $text) { |
| 1521 | 1521 | if (is_array($text)) { |
| 1522 | 1522 | foreach ($text as $sublabel => $subtext) { |
| 1523 | - $this->_labels[ $label ][ $sublabel ] = $subtext; |
|
| 1523 | + $this->_labels[$label][$sublabel] = $subtext; |
|
| 1524 | 1524 | } |
| 1525 | 1525 | } else { |
| 1526 | - $this->_labels[ $label ] = $text; |
|
| 1526 | + $this->_labels[$label] = $text; |
|
| 1527 | 1527 | } |
| 1528 | 1528 | } |
| 1529 | 1529 | } |
@@ -1545,12 +1545,12 @@ discard block |
||
| 1545 | 1545 | { |
| 1546 | 1546 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 1547 | 1547 | $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check; |
| 1548 | - $capability = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ]) |
|
| 1548 | + $capability = ! empty($route_to_check) && isset($this->_page_routes[$route_to_check]) |
|
| 1549 | 1549 | && is_array( |
| 1550 | - $this->_page_routes[ $route_to_check ] |
|
| 1550 | + $this->_page_routes[$route_to_check] |
|
| 1551 | 1551 | ) |
| 1552 | - && ! empty($this->_page_routes[ $route_to_check ]['capability']) |
|
| 1553 | - ? $this->_page_routes[ $route_to_check ]['capability'] : null; |
|
| 1552 | + && ! empty($this->_page_routes[$route_to_check]['capability']) |
|
| 1553 | + ? $this->_page_routes[$route_to_check]['capability'] : null; |
|
| 1554 | 1554 | if (empty($capability) && empty($route_to_check)) { |
| 1555 | 1555 | $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' |
| 1556 | 1556 | : $this->_route['capability']; |
@@ -1558,7 +1558,7 @@ discard block |
||
| 1558 | 1558 | $capability = empty($capability) ? 'manage_options' : $capability; |
| 1559 | 1559 | } |
| 1560 | 1560 | $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0; |
| 1561 | - if (! defined('DOING_AJAX') |
|
| 1561 | + if ( ! defined('DOING_AJAX') |
|
| 1562 | 1562 | && ( |
| 1563 | 1563 | ! function_exists('is_admin') |
| 1564 | 1564 | || ! EE_Registry::instance()->CAP->current_user_can( |
@@ -1661,7 +1661,7 @@ discard block |
||
| 1661 | 1661 | public function admin_footer_global() |
| 1662 | 1662 | { |
| 1663 | 1663 | // dialog container for dialog helper |
| 1664 | - $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n"; |
|
| 1664 | + $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">'."\n"; |
|
| 1665 | 1665 | $d_cont .= '<div class="ee-notices"></div>'; |
| 1666 | 1666 | $d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>'; |
| 1667 | 1667 | $d_cont .= '</div>'; |
@@ -1672,7 +1672,7 @@ discard block |
||
| 1672 | 1672 | // echo implode('<br />', $this->_help_tour[ $this->_req_action ]); |
| 1673 | 1673 | // } |
| 1674 | 1674 | // current set timezone for timezone js |
| 1675 | - echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>'; |
|
| 1675 | + echo '<span id="current_timezone" class="hidden">'.EEH_DTT_Helper::get_timezone().'</span>'; |
|
| 1676 | 1676 | } |
| 1677 | 1677 | |
| 1678 | 1678 | |
@@ -1706,7 +1706,7 @@ discard block |
||
| 1706 | 1706 | // loop through the array and setup content |
| 1707 | 1707 | foreach ($help_array as $trigger => $help) { |
| 1708 | 1708 | // make sure the array is setup properly |
| 1709 | - if (! isset($help['title']) || ! isset($help['content'])) { |
|
| 1709 | + if ( ! isset($help['title']) || ! isset($help['content'])) { |
|
| 1710 | 1710 | throw new EE_Error( |
| 1711 | 1711 | esc_html__( |
| 1712 | 1712 | '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', |
@@ -1721,7 +1721,7 @@ discard block |
||
| 1721 | 1721 | 'help_popup_content' => $help['content'], |
| 1722 | 1722 | ); |
| 1723 | 1723 | $content .= EEH_Template::display_template( |
| 1724 | - EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php', |
|
| 1724 | + EE_ADMIN_TEMPLATE.'admin_help_popup.template.php', |
|
| 1725 | 1725 | $template_args, |
| 1726 | 1726 | true |
| 1727 | 1727 | ); |
@@ -1743,15 +1743,15 @@ discard block |
||
| 1743 | 1743 | private function _get_help_content() |
| 1744 | 1744 | { |
| 1745 | 1745 | // what is the method we're looking for? |
| 1746 | - $method_name = '_help_popup_content_' . $this->_req_action; |
|
| 1746 | + $method_name = '_help_popup_content_'.$this->_req_action; |
|
| 1747 | 1747 | // if method doesn't exist let's get out. |
| 1748 | - if (! method_exists($this, $method_name)) { |
|
| 1748 | + if ( ! method_exists($this, $method_name)) { |
|
| 1749 | 1749 | return array(); |
| 1750 | 1750 | } |
| 1751 | 1751 | // k we're good to go let's retrieve the help array |
| 1752 | 1752 | $help_array = call_user_func(array($this, $method_name)); |
| 1753 | 1753 | // make sure we've got an array! |
| 1754 | - if (! is_array($help_array)) { |
|
| 1754 | + if ( ! is_array($help_array)) { |
|
| 1755 | 1755 | throw new EE_Error( |
| 1756 | 1756 | esc_html__( |
| 1757 | 1757 | 'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', |
@@ -1783,8 +1783,8 @@ discard block |
||
| 1783 | 1783 | // 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 |
| 1784 | 1784 | $help_array = $this->_get_help_content(); |
| 1785 | 1785 | $help_content = ''; |
| 1786 | - if (empty($help_array) || ! isset($help_array[ $trigger_id ])) { |
|
| 1787 | - $help_array[ $trigger_id ] = array( |
|
| 1786 | + if (empty($help_array) || ! isset($help_array[$trigger_id])) { |
|
| 1787 | + $help_array[$trigger_id] = array( |
|
| 1788 | 1788 | 'title' => esc_html__('Missing Content', 'event_espresso'), |
| 1789 | 1789 | 'content' => esc_html__( |
| 1790 | 1790 | '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.)', |
@@ -1860,15 +1860,15 @@ discard block |
||
| 1860 | 1860 | // register all styles |
| 1861 | 1861 | wp_register_style( |
| 1862 | 1862 | 'espresso-ui-theme', |
| 1863 | - EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', |
|
| 1863 | + EE_GLOBAL_ASSETS_URL.'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', |
|
| 1864 | 1864 | array(), |
| 1865 | 1865 | EVENT_ESPRESSO_VERSION |
| 1866 | 1866 | ); |
| 1867 | - wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1867 | + wp_register_style('ee-admin-css', EE_ADMIN_URL.'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1868 | 1868 | // helpers styles |
| 1869 | 1869 | wp_register_style( |
| 1870 | 1870 | 'ee-text-links', |
| 1871 | - EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', |
|
| 1871 | + EE_PLUGIN_DIR_URL.'core/helpers/assets/ee_text_list_helper.css', |
|
| 1872 | 1872 | array(), |
| 1873 | 1873 | EVENT_ESPRESSO_VERSION |
| 1874 | 1874 | ); |
@@ -1876,21 +1876,21 @@ discard block |
||
| 1876 | 1876 | // register all scripts |
| 1877 | 1877 | wp_register_script( |
| 1878 | 1878 | 'ee-dialog', |
| 1879 | - EE_ADMIN_URL . 'assets/ee-dialog-helper.js', |
|
| 1879 | + EE_ADMIN_URL.'assets/ee-dialog-helper.js', |
|
| 1880 | 1880 | array('jquery', 'jquery-ui-draggable'), |
| 1881 | 1881 | EVENT_ESPRESSO_VERSION, |
| 1882 | 1882 | true |
| 1883 | 1883 | ); |
| 1884 | 1884 | wp_register_script( |
| 1885 | 1885 | 'ee_admin_js', |
| 1886 | - EE_ADMIN_URL . 'assets/ee-admin-page.js', |
|
| 1886 | + EE_ADMIN_URL.'assets/ee-admin-page.js', |
|
| 1887 | 1887 | array('espresso_core', 'ee-parse-uri', 'ee-dialog'), |
| 1888 | 1888 | EVENT_ESPRESSO_VERSION, |
| 1889 | 1889 | true |
| 1890 | 1890 | ); |
| 1891 | 1891 | wp_register_script( |
| 1892 | 1892 | 'jquery-ui-timepicker-addon', |
| 1893 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', |
|
| 1893 | + EE_GLOBAL_ASSETS_URL.'scripts/jquery-ui-timepicker-addon.js', |
|
| 1894 | 1894 | array('jquery-ui-datepicker', 'jquery-ui-slider'), |
| 1895 | 1895 | EVENT_ESPRESSO_VERSION, |
| 1896 | 1896 | true |
@@ -1902,7 +1902,7 @@ discard block |
||
| 1902 | 1902 | // script for sorting tables |
| 1903 | 1903 | wp_register_script( |
| 1904 | 1904 | 'espresso_ajax_table_sorting', |
| 1905 | - EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js', |
|
| 1905 | + EE_ADMIN_URL.'assets/espresso_ajax_table_sorting.js', |
|
| 1906 | 1906 | array('ee_admin_js', 'jquery-ui-sortable'), |
| 1907 | 1907 | EVENT_ESPRESSO_VERSION, |
| 1908 | 1908 | true |
@@ -1910,7 +1910,7 @@ discard block |
||
| 1910 | 1910 | // script for parsing uri's |
| 1911 | 1911 | wp_register_script( |
| 1912 | 1912 | 'ee-parse-uri', |
| 1913 | - EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', |
|
| 1913 | + EE_GLOBAL_ASSETS_URL.'scripts/parseuri.js', |
|
| 1914 | 1914 | array(), |
| 1915 | 1915 | EVENT_ESPRESSO_VERSION, |
| 1916 | 1916 | true |
@@ -1918,7 +1918,7 @@ discard block |
||
| 1918 | 1918 | // and parsing associative serialized form elements |
| 1919 | 1919 | wp_register_script( |
| 1920 | 1920 | 'ee-serialize-full-array', |
| 1921 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', |
|
| 1921 | + EE_GLOBAL_ASSETS_URL.'scripts/jquery.serializefullarray.js', |
|
| 1922 | 1922 | array('jquery'), |
| 1923 | 1923 | EVENT_ESPRESSO_VERSION, |
| 1924 | 1924 | true |
@@ -1926,28 +1926,28 @@ discard block |
||
| 1926 | 1926 | // helpers scripts |
| 1927 | 1927 | wp_register_script( |
| 1928 | 1928 | 'ee-text-links', |
| 1929 | - EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', |
|
| 1929 | + EE_PLUGIN_DIR_URL.'core/helpers/assets/ee_text_list_helper.js', |
|
| 1930 | 1930 | array('jquery'), |
| 1931 | 1931 | EVENT_ESPRESSO_VERSION, |
| 1932 | 1932 | true |
| 1933 | 1933 | ); |
| 1934 | 1934 | wp_register_script( |
| 1935 | 1935 | 'ee-moment-core', |
| 1936 | - EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', |
|
| 1936 | + EE_THIRD_PARTY_URL.'moment/moment-with-locales.min.js', |
|
| 1937 | 1937 | array(), |
| 1938 | 1938 | EVENT_ESPRESSO_VERSION, |
| 1939 | 1939 | true |
| 1940 | 1940 | ); |
| 1941 | 1941 | wp_register_script( |
| 1942 | 1942 | 'ee-moment', |
| 1943 | - EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', |
|
| 1943 | + EE_THIRD_PARTY_URL.'moment/moment-timezone-with-data.min.js', |
|
| 1944 | 1944 | array('ee-moment-core'), |
| 1945 | 1945 | EVENT_ESPRESSO_VERSION, |
| 1946 | 1946 | true |
| 1947 | 1947 | ); |
| 1948 | 1948 | wp_register_script( |
| 1949 | 1949 | 'ee-datepicker', |
| 1950 | - EE_ADMIN_URL . 'assets/ee-datepicker.js', |
|
| 1950 | + EE_ADMIN_URL.'assets/ee-datepicker.js', |
|
| 1951 | 1951 | array('jquery-ui-timepicker-addon', 'ee-moment'), |
| 1952 | 1952 | EVENT_ESPRESSO_VERSION, |
| 1953 | 1953 | true |
@@ -2083,12 +2083,12 @@ discard block |
||
| 2083 | 2083 | protected function _set_list_table() |
| 2084 | 2084 | { |
| 2085 | 2085 | // first is this a list_table view? |
| 2086 | - if (! isset($this->_route_config['list_table'])) { |
|
| 2086 | + if ( ! isset($this->_route_config['list_table'])) { |
|
| 2087 | 2087 | return; |
| 2088 | 2088 | } //not a list_table view so get out. |
| 2089 | 2089 | // list table functions are per view specific (because some admin pages might have more than one list table!) |
| 2090 | - $list_table_view = '_set_list_table_views_' . $this->_req_action; |
|
| 2091 | - if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) { |
|
| 2090 | + $list_table_view = '_set_list_table_views_'.$this->_req_action; |
|
| 2091 | + if ( ! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) { |
|
| 2092 | 2092 | // user error msg |
| 2093 | 2093 | $error_msg = esc_html__( |
| 2094 | 2094 | 'An error occurred. The requested list table views could not be found.', |
@@ -2108,10 +2108,10 @@ discard block |
||
| 2108 | 2108 | } |
| 2109 | 2109 | // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally |
| 2110 | 2110 | $this->_views = apply_filters( |
| 2111 | - 'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, |
|
| 2111 | + 'FHEE_list_table_views_'.$this->page_slug.'_'.$this->_req_action, |
|
| 2112 | 2112 | $this->_views |
| 2113 | 2113 | ); |
| 2114 | - $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views); |
|
| 2114 | + $this->_views = apply_filters('FHEE_list_table_views_'.$this->page_slug, $this->_views); |
|
| 2115 | 2115 | $this->_views = apply_filters('FHEE_list_table_views', $this->_views); |
| 2116 | 2116 | $this->_set_list_table_view(); |
| 2117 | 2117 | $this->_set_list_table_object(); |
@@ -2127,7 +2127,7 @@ discard block |
||
| 2127 | 2127 | { |
| 2128 | 2128 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 2129 | 2129 | // looking at active items or dumpster diving ? |
| 2130 | - if (! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) { |
|
| 2130 | + if ( ! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) { |
|
| 2131 | 2131 | $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all'; |
| 2132 | 2132 | } else { |
| 2133 | 2133 | $this->_view = sanitize_key($this->_req_data['status']); |
@@ -2148,7 +2148,7 @@ discard block |
||
| 2148 | 2148 | protected function _set_list_table_object() |
| 2149 | 2149 | { |
| 2150 | 2150 | if (isset($this->_route_config['list_table'])) { |
| 2151 | - if (! class_exists($this->_route_config['list_table'])) { |
|
| 2151 | + if ( ! class_exists($this->_route_config['list_table'])) { |
|
| 2152 | 2152 | throw new EE_Error( |
| 2153 | 2153 | sprintf( |
| 2154 | 2154 | esc_html__( |
@@ -2186,15 +2186,15 @@ discard block |
||
| 2186 | 2186 | foreach ($this->_views as $key => $view) { |
| 2187 | 2187 | $query_args = array(); |
| 2188 | 2188 | // check for current view |
| 2189 | - $this->_views[ $key ]['class'] = $this->_view === $view['slug'] ? 'current' : ''; |
|
| 2189 | + $this->_views[$key]['class'] = $this->_view === $view['slug'] ? 'current' : ''; |
|
| 2190 | 2190 | $query_args['action'] = $this->_req_action; |
| 2191 | - $query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 2191 | + $query_args[$this->_req_action.'_nonce'] = wp_create_nonce($query_args['action'].'_nonce'); |
|
| 2192 | 2192 | $query_args['status'] = $view['slug']; |
| 2193 | 2193 | // merge any other arguments sent in. |
| 2194 | - if (isset($extra_query_args[ $view['slug'] ])) { |
|
| 2195 | - $query_args = array_merge($query_args, $extra_query_args[ $view['slug'] ]); |
|
| 2194 | + if (isset($extra_query_args[$view['slug']])) { |
|
| 2195 | + $query_args = array_merge($query_args, $extra_query_args[$view['slug']]); |
|
| 2196 | 2196 | } |
| 2197 | - $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 2197 | + $this->_views[$key]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 2198 | 2198 | } |
| 2199 | 2199 | return $this->_views; |
| 2200 | 2200 | } |
@@ -2213,7 +2213,7 @@ discard block |
||
| 2213 | 2213 | { |
| 2214 | 2214 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 2215 | 2215 | $values = array(10, 25, 50, 100); |
| 2216 | - $per_page = (! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10; |
|
| 2216 | + $per_page = ( ! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10; |
|
| 2217 | 2217 | if ($max_entries) { |
| 2218 | 2218 | $values[] = $max_entries; |
| 2219 | 2219 | sort($values); |
@@ -2225,14 +2225,14 @@ discard block |
||
| 2225 | 2225 | <select id="entries-per-page-slct" name="entries-per-page-slct">'; |
| 2226 | 2226 | foreach ($values as $value) { |
| 2227 | 2227 | if ($value < $max_entries) { |
| 2228 | - $selected = $value === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2228 | + $selected = $value === $per_page ? ' selected="'.$per_page.'"' : ''; |
|
| 2229 | 2229 | $entries_per_page_dropdown .= ' |
| 2230 | - <option value="' . $value . '"' . $selected . '>' . $value . ' </option>'; |
|
| 2230 | + <option value="' . $value.'"'.$selected.'>'.$value.' </option>'; |
|
| 2231 | 2231 | } |
| 2232 | 2232 | } |
| 2233 | - $selected = $max_entries === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2233 | + $selected = $max_entries === $per_page ? ' selected="'.$per_page.'"' : ''; |
|
| 2234 | 2234 | $entries_per_page_dropdown .= ' |
| 2235 | - <option value="' . $max_entries . '"' . $selected . '>All </option>'; |
|
| 2235 | + <option value="' . $max_entries.'"'.$selected.'>All </option>'; |
|
| 2236 | 2236 | $entries_per_page_dropdown .= ' |
| 2237 | 2237 | </select> |
| 2238 | 2238 | entries |
@@ -2256,7 +2256,7 @@ discard block |
||
| 2256 | 2256 | empty($this->_search_btn_label) ? $this->page_label |
| 2257 | 2257 | : $this->_search_btn_label |
| 2258 | 2258 | ); |
| 2259 | - $this->_template_args['search']['callback'] = 'search_' . $this->page_slug; |
|
| 2259 | + $this->_template_args['search']['callback'] = 'search_'.$this->page_slug; |
|
| 2260 | 2260 | } |
| 2261 | 2261 | |
| 2262 | 2262 | |
@@ -2342,7 +2342,7 @@ discard block |
||
| 2342 | 2342 | $total_columns = ! empty($screen_columns) |
| 2343 | 2343 | ? $screen_columns |
| 2344 | 2344 | : $this->_route_config['columns'][1]; |
| 2345 | - $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns; |
|
| 2345 | + $this->_template_args['current_screen_widget_class'] = 'columns-'.$total_columns; |
|
| 2346 | 2346 | $this->_template_args['current_page'] = $this->_wp_page_slug; |
| 2347 | 2347 | $this->_template_args['screen'] = $this->_current_screen; |
| 2348 | 2348 | $this->_column_template_path = EE_ADMIN_TEMPLATE |
@@ -2387,7 +2387,7 @@ discard block |
||
| 2387 | 2387 | */ |
| 2388 | 2388 | protected function _espresso_ratings_request() |
| 2389 | 2389 | { |
| 2390 | - if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
| 2390 | + if ( ! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
| 2391 | 2391 | return; |
| 2392 | 2392 | } |
| 2393 | 2393 | $ratings_box_title = apply_filters( |
@@ -2415,7 +2415,7 @@ discard block |
||
| 2415 | 2415 | public function espresso_ratings_request() |
| 2416 | 2416 | { |
| 2417 | 2417 | EEH_Template::display_template( |
| 2418 | - EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php', |
|
| 2418 | + EE_ADMIN_TEMPLATE.'espresso_ratings_request_content.template.php', |
|
| 2419 | 2419 | array() |
| 2420 | 2420 | ); |
| 2421 | 2421 | } |
@@ -2428,17 +2428,17 @@ discard block |
||
| 2428 | 2428 | . '</p><p class="hide-if-js">' |
| 2429 | 2429 | . esc_html__('This widget requires JavaScript.', 'event_espresso') |
| 2430 | 2430 | . '</p>'; |
| 2431 | - $pre = '<div class="espresso-rss-display">' . "\n\t"; |
|
| 2432 | - $pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>'; |
|
| 2433 | - $post = '</div>' . "\n"; |
|
| 2434 | - $cache_key = 'ee_rss_' . md5($rss_id); |
|
| 2431 | + $pre = '<div class="espresso-rss-display">'."\n\t"; |
|
| 2432 | + $pre .= '<span id="'.$rss_id.'_url" class="hidden">'.$url.'</span>'; |
|
| 2433 | + $post = '</div>'."\n"; |
|
| 2434 | + $cache_key = 'ee_rss_'.md5($rss_id); |
|
| 2435 | 2435 | $output = get_transient($cache_key); |
| 2436 | 2436 | if ($output !== false) { |
| 2437 | - echo $pre . $output . $post; |
|
| 2437 | + echo $pre.$output.$post; |
|
| 2438 | 2438 | return true; |
| 2439 | 2439 | } |
| 2440 | - if (! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 2441 | - echo $pre . $loading . $post; |
|
| 2440 | + if ( ! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 2441 | + echo $pre.$loading.$post; |
|
| 2442 | 2442 | return false; |
| 2443 | 2443 | } |
| 2444 | 2444 | ob_start(); |
@@ -2505,19 +2505,19 @@ discard block |
||
| 2505 | 2505 | public function espresso_sponsors_post_box() |
| 2506 | 2506 | { |
| 2507 | 2507 | EEH_Template::display_template( |
| 2508 | - EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php' |
|
| 2508 | + EE_ADMIN_TEMPLATE.'admin_general_metabox_contents_espresso_sponsors.template.php' |
|
| 2509 | 2509 | ); |
| 2510 | 2510 | } |
| 2511 | 2511 | |
| 2512 | 2512 | |
| 2513 | 2513 | private function _publish_post_box() |
| 2514 | 2514 | { |
| 2515 | - $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview'; |
|
| 2515 | + $meta_box_ref = 'espresso_'.$this->page_slug.'_editor_overview'; |
|
| 2516 | 2516 | // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array |
| 2517 | 2517 | // then we'll use that for the metabox label. |
| 2518 | 2518 | // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes) |
| 2519 | - if (! empty($this->_labels['publishbox'])) { |
|
| 2520 | - $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ] |
|
| 2519 | + if ( ! empty($this->_labels['publishbox'])) { |
|
| 2520 | + $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action] |
|
| 2521 | 2521 | : $this->_labels['publishbox']; |
| 2522 | 2522 | } else { |
| 2523 | 2523 | $box_label = esc_html__('Publish', 'event_espresso'); |
@@ -2546,7 +2546,7 @@ discard block |
||
| 2546 | 2546 | ? $this->_template_args['publish_box_extra_content'] |
| 2547 | 2547 | : ''; |
| 2548 | 2548 | echo EEH_Template::display_template( |
| 2549 | - EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php', |
|
| 2549 | + EE_ADMIN_TEMPLATE.'admin_details_publish_metabox.template.php', |
|
| 2550 | 2550 | $this->_template_args, |
| 2551 | 2551 | true |
| 2552 | 2552 | ); |
@@ -2638,8 +2638,8 @@ discard block |
||
| 2638 | 2638 | ); |
| 2639 | 2639 | } |
| 2640 | 2640 | $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : ''; |
| 2641 | - if (! empty($name) && ! empty($id)) { |
|
| 2642 | - $hidden_field_arr[ $name ] = array( |
|
| 2641 | + if ( ! empty($name) && ! empty($id)) { |
|
| 2642 | + $hidden_field_arr[$name] = array( |
|
| 2643 | 2643 | 'type' => 'hidden', |
| 2644 | 2644 | 'value' => $id, |
| 2645 | 2645 | ); |
@@ -2649,7 +2649,7 @@ discard block |
||
| 2649 | 2649 | } |
| 2650 | 2650 | // add hidden field |
| 2651 | 2651 | $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name) |
| 2652 | - ? $hf[ $name ]['field'] |
|
| 2652 | + ? $hf[$name]['field'] |
|
| 2653 | 2653 | : $hf; |
| 2654 | 2654 | } |
| 2655 | 2655 | |
@@ -2751,7 +2751,7 @@ discard block |
||
| 2751 | 2751 | } |
| 2752 | 2752 | // 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) |
| 2753 | 2753 | $call_back_func = $create_func |
| 2754 | - ? function ($post, $metabox) { |
|
| 2754 | + ? function($post, $metabox) { |
|
| 2755 | 2755 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 2756 | 2756 | echo EEH_Template::display_template( |
| 2757 | 2757 | $metabox['args']['template_path'], |
@@ -2761,7 +2761,7 @@ discard block |
||
| 2761 | 2761 | } |
| 2762 | 2762 | : $callback; |
| 2763 | 2763 | add_meta_box( |
| 2764 | - str_replace('_', '-', $action) . '-mbox', |
|
| 2764 | + str_replace('_', '-', $action).'-mbox', |
|
| 2765 | 2765 | $title, |
| 2766 | 2766 | $call_back_func, |
| 2767 | 2767 | $this->_wp_page_slug, |
@@ -2853,9 +2853,9 @@ discard block |
||
| 2853 | 2853 | : 'espresso-default-admin'; |
| 2854 | 2854 | $template_path = $sidebar |
| 2855 | 2855 | ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php' |
| 2856 | - : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2856 | + : EE_ADMIN_TEMPLATE.'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2857 | 2857 | if (defined('DOING_AJAX') && DOING_AJAX) { |
| 2858 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2858 | + $template_path = EE_ADMIN_TEMPLATE.'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2859 | 2859 | } |
| 2860 | 2860 | $template_path = ! empty($this->_column_template_path) |
| 2861 | 2861 | ? $this->_column_template_path : $template_path; |
@@ -2920,7 +2920,7 @@ discard block |
||
| 2920 | 2920 | ) |
| 2921 | 2921 | : $this->_template_args['preview_action_button']; |
| 2922 | 2922 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
| 2923 | - EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php', |
|
| 2923 | + EE_ADMIN_TEMPLATE.'admin_caf_full_page_preview.template.php', |
|
| 2924 | 2924 | $this->_template_args, |
| 2925 | 2925 | true |
| 2926 | 2926 | ); |
@@ -2969,7 +2969,7 @@ discard block |
||
| 2969 | 2969 | // setup search attributes |
| 2970 | 2970 | $this->_set_search_attributes(); |
| 2971 | 2971 | $this->_template_args['current_page'] = $this->_wp_page_slug; |
| 2972 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php'; |
|
| 2972 | + $template_path = EE_ADMIN_TEMPLATE.'admin_list_wrapper.template.php'; |
|
| 2973 | 2973 | $this->_template_args['table_url'] = defined('DOING_AJAX') |
| 2974 | 2974 | ? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url) |
| 2975 | 2975 | : add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url); |
@@ -2977,10 +2977,10 @@ discard block |
||
| 2977 | 2977 | $this->_template_args['current_route'] = $this->_req_action; |
| 2978 | 2978 | $this->_template_args['list_table_class'] = get_class($this->_list_table_object); |
| 2979 | 2979 | $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback(); |
| 2980 | - if (! empty($ajax_sorting_callback)) { |
|
| 2980 | + if ( ! empty($ajax_sorting_callback)) { |
|
| 2981 | 2981 | $sortable_list_table_form_fields = wp_nonce_field( |
| 2982 | - $ajax_sorting_callback . '_nonce', |
|
| 2983 | - $ajax_sorting_callback . '_nonce', |
|
| 2982 | + $ajax_sorting_callback.'_nonce', |
|
| 2983 | + $ajax_sorting_callback.'_nonce', |
|
| 2984 | 2984 | false, |
| 2985 | 2985 | false |
| 2986 | 2986 | ); |
@@ -2997,7 +2997,7 @@ discard block |
||
| 2997 | 2997 | $hidden_form_fields = isset($this->_template_args['list_table_hidden_fields']) |
| 2998 | 2998 | ? $this->_template_args['list_table_hidden_fields'] |
| 2999 | 2999 | : ''; |
| 3000 | - $nonce_ref = $this->_req_action . '_nonce'; |
|
| 3000 | + $nonce_ref = $this->_req_action.'_nonce'; |
|
| 3001 | 3001 | $hidden_form_fields .= '<input type="hidden" name="' |
| 3002 | 3002 | . $nonce_ref |
| 3003 | 3003 | . '" value="' |
@@ -3006,10 +3006,10 @@ discard block |
||
| 3006 | 3006 | $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
| 3007 | 3007 | // display message about search results? |
| 3008 | 3008 | $this->_template_args['before_list_table'] .= ! empty($this->_req_data['s']) |
| 3009 | - ? '<p class="ee-search-results">' . sprintf( |
|
| 3009 | + ? '<p class="ee-search-results">'.sprintf( |
|
| 3010 | 3010 | esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'), |
| 3011 | 3011 | trim($this->_req_data['s'], '%') |
| 3012 | - ) . '</p>' |
|
| 3012 | + ).'</p>' |
|
| 3013 | 3013 | : ''; |
| 3014 | 3014 | // filter before_list_table template arg |
| 3015 | 3015 | $this->_template_args['before_list_table'] = apply_filters( |
@@ -3090,7 +3090,7 @@ discard block |
||
| 3090 | 3090 | $this |
| 3091 | 3091 | ); |
| 3092 | 3092 | return EEH_Template::display_template( |
| 3093 | - EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php', |
|
| 3093 | + EE_ADMIN_TEMPLATE.'admin_details_legend.template.php', |
|
| 3094 | 3094 | $this->_template_args, |
| 3095 | 3095 | true |
| 3096 | 3096 | ); |
@@ -3313,17 +3313,17 @@ discard block |
||
| 3313 | 3313 | // add in a hidden index for the current page (so save and close redirects properly) |
| 3314 | 3314 | $this->_template_args['save_buttons'] = $referrer_url; |
| 3315 | 3315 | foreach ($button_text as $key => $button) { |
| 3316 | - $ref = $default_names[ $key ]; |
|
| 3316 | + $ref = $default_names[$key]; |
|
| 3317 | 3317 | $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' |
| 3318 | 3318 | . $ref |
| 3319 | 3319 | . '" value="' |
| 3320 | 3320 | . $button |
| 3321 | 3321 | . '" name="' |
| 3322 | - . (! empty($actions) ? $actions[ $key ] : $ref) |
|
| 3322 | + . ( ! empty($actions) ? $actions[$key] : $ref) |
|
| 3323 | 3323 | . '" id="' |
| 3324 | - . $this->_current_view . '_' . $ref |
|
| 3324 | + . $this->_current_view.'_'.$ref |
|
| 3325 | 3325 | . '" />'; |
| 3326 | - if (! $both) { |
|
| 3326 | + if ( ! $both) { |
|
| 3327 | 3327 | break; |
| 3328 | 3328 | } |
| 3329 | 3329 | } |
@@ -3358,13 +3358,13 @@ discard block |
||
| 3358 | 3358 | 'An error occurred. No action was set for this page\'s form.', |
| 3359 | 3359 | 'event_espresso' |
| 3360 | 3360 | ); |
| 3361 | - $dev_msg = $user_msg . "\n" |
|
| 3361 | + $dev_msg = $user_msg."\n" |
|
| 3362 | 3362 | . sprintf( |
| 3363 | 3363 | esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'), |
| 3364 | 3364 | __FUNCTION__, |
| 3365 | 3365 | __CLASS__ |
| 3366 | 3366 | ); |
| 3367 | - EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 3367 | + EE_Error::add_error($user_msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 3368 | 3368 | } |
| 3369 | 3369 | // open form |
| 3370 | 3370 | $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' |
@@ -3373,8 +3373,8 @@ discard block |
||
| 3373 | 3373 | . $route |
| 3374 | 3374 | . '_event_form" >'; |
| 3375 | 3375 | // add nonce |
| 3376 | - $nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false); |
|
| 3377 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce; |
|
| 3376 | + $nonce = wp_nonce_field($route.'_nonce', $route.'_nonce', false, false); |
|
| 3377 | + $this->_template_args['before_admin_page_content'] .= "\n\t".$nonce; |
|
| 3378 | 3378 | // add REQUIRED form action |
| 3379 | 3379 | $hidden_fields = array( |
| 3380 | 3380 | 'action' => array('type' => 'hidden', 'value' => $route), |
@@ -3387,7 +3387,7 @@ discard block |
||
| 3387 | 3387 | $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array'); |
| 3388 | 3388 | // add fields to form |
| 3389 | 3389 | foreach ((array) $form_fields as $field_name => $form_field) { |
| 3390 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field']; |
|
| 3390 | + $this->_template_args['before_admin_page_content'] .= "\n\t".$form_field['field']; |
|
| 3391 | 3391 | } |
| 3392 | 3392 | // close form |
| 3393 | 3393 | $this->_template_args['after_admin_page_content'] = '</form>'; |
@@ -3438,12 +3438,12 @@ discard block |
||
| 3438 | 3438 | foreach ($this->_req_data as $ref => $value) { |
| 3439 | 3439 | // unset nonces |
| 3440 | 3440 | if (strpos($ref, 'nonce') !== false) { |
| 3441 | - unset($this->_req_data[ $ref ]); |
|
| 3441 | + unset($this->_req_data[$ref]); |
|
| 3442 | 3442 | continue; |
| 3443 | 3443 | } |
| 3444 | 3444 | // urlencode values. |
| 3445 | 3445 | $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value); |
| 3446 | - $this->_req_data[ $ref ] = $value; |
|
| 3446 | + $this->_req_data[$ref] = $value; |
|
| 3447 | 3447 | } |
| 3448 | 3448 | return array_merge($this->_req_data, $new_route_data); |
| 3449 | 3449 | } |
@@ -3478,10 +3478,10 @@ discard block |
||
| 3478 | 3478 | $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url; |
| 3479 | 3479 | $notices = EE_Error::get_notices(false); |
| 3480 | 3480 | // overwrite default success messages //BUT ONLY if overwrite not overridden |
| 3481 | - if (! $override_overwrite || ! empty($notices['errors'])) { |
|
| 3481 | + if ( ! $override_overwrite || ! empty($notices['errors'])) { |
|
| 3482 | 3482 | EE_Error::overwrite_success(); |
| 3483 | 3483 | } |
| 3484 | - if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) { |
|
| 3484 | + if ( ! empty($what) && ! empty($action_desc) && empty($notices['errors'])) { |
|
| 3485 | 3485 | // how many records affected ? more than one record ? or just one ? |
| 3486 | 3486 | if ($success > 1) { |
| 3487 | 3487 | // set plural msg |
@@ -3510,7 +3510,7 @@ discard block |
||
| 3510 | 3510 | } |
| 3511 | 3511 | } |
| 3512 | 3512 | // check that $query_args isn't something crazy |
| 3513 | - if (! is_array($query_args)) { |
|
| 3513 | + if ( ! is_array($query_args)) { |
|
| 3514 | 3514 | $query_args = array(); |
| 3515 | 3515 | } |
| 3516 | 3516 | /** |
@@ -3535,7 +3535,7 @@ discard block |
||
| 3535 | 3535 | $redirect_url = admin_url('admin.php'); |
| 3536 | 3536 | } |
| 3537 | 3537 | // merge any default query_args set in _default_route_query_args property |
| 3538 | - if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
| 3538 | + if ( ! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
| 3539 | 3539 | $args_to_merge = array(); |
| 3540 | 3540 | foreach ($this->_default_route_query_args as $query_param => $query_value) { |
| 3541 | 3541 | // is there a wp_referer array in our _default_route_query_args property? |
@@ -3547,15 +3547,15 @@ discard block |
||
| 3547 | 3547 | } |
| 3548 | 3548 | // finally we will override any arguments in the referer with |
| 3549 | 3549 | // what might be set on the _default_route_query_args array. |
| 3550 | - if (isset($this->_default_route_query_args[ $reference ])) { |
|
| 3551 | - $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]); |
|
| 3550 | + if (isset($this->_default_route_query_args[$reference])) { |
|
| 3551 | + $args_to_merge[$reference] = urlencode($this->_default_route_query_args[$reference]); |
|
| 3552 | 3552 | } else { |
| 3553 | - $args_to_merge[ $reference ] = urlencode($value); |
|
| 3553 | + $args_to_merge[$reference] = urlencode($value); |
|
| 3554 | 3554 | } |
| 3555 | 3555 | } |
| 3556 | 3556 | continue; |
| 3557 | 3557 | } |
| 3558 | - $args_to_merge[ $query_param ] = $query_value; |
|
| 3558 | + $args_to_merge[$query_param] = $query_value; |
|
| 3559 | 3559 | } |
| 3560 | 3560 | // now let's merge these arguments but override with what was specifically sent in to the |
| 3561 | 3561 | // redirect. |
@@ -3567,13 +3567,13 @@ discard block |
||
| 3567 | 3567 | if (isset($query_args['action'])) { |
| 3568 | 3568 | // manually generate wp_nonce and merge that with the query vars |
| 3569 | 3569 | // becuz the wp_nonce_url function wrecks havoc on some vars |
| 3570 | - $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 3570 | + $query_args['_wpnonce'] = wp_create_nonce($query_args['action'].'_nonce'); |
|
| 3571 | 3571 | } |
| 3572 | 3572 | // we're adding some hooks and filters in here for processing any things just before redirects |
| 3573 | 3573 | // (example: an admin page has done an insert or update and we want to run something after that). |
| 3574 | - do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args); |
|
| 3574 | + do_action('AHEE_redirect_'.$classname.$this->_req_action, $query_args); |
|
| 3575 | 3575 | $redirect_url = apply_filters( |
| 3576 | - 'FHEE_redirect_' . $classname . $this->_req_action, |
|
| 3576 | + 'FHEE_redirect_'.$classname.$this->_req_action, |
|
| 3577 | 3577 | self::add_query_args_and_nonce($query_args, $redirect_url), |
| 3578 | 3578 | $query_args |
| 3579 | 3579 | ); |
@@ -3626,7 +3626,7 @@ discard block |
||
| 3626 | 3626 | } |
| 3627 | 3627 | $this->_template_args['notices'] = EE_Error::get_notices(); |
| 3628 | 3628 | // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true) |
| 3629 | - if (! defined('DOING_AJAX') || $sticky_notices) { |
|
| 3629 | + if ( ! defined('DOING_AJAX') || $sticky_notices) { |
|
| 3630 | 3630 | $route = isset($query_args['action']) ? $query_args['action'] : 'default'; |
| 3631 | 3631 | $this->_add_transient( |
| 3632 | 3632 | $route, |
@@ -3666,7 +3666,7 @@ discard block |
||
| 3666 | 3666 | $exclude_nonce = false |
| 3667 | 3667 | ) { |
| 3668 | 3668 | // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along) |
| 3669 | - if (empty($base_url) && ! isset($this->_page_routes[ $action ])) { |
|
| 3669 | + if (empty($base_url) && ! isset($this->_page_routes[$action])) { |
|
| 3670 | 3670 | throw new EE_Error( |
| 3671 | 3671 | sprintf( |
| 3672 | 3672 | esc_html__( |
@@ -3677,7 +3677,7 @@ discard block |
||
| 3677 | 3677 | ) |
| 3678 | 3678 | ); |
| 3679 | 3679 | } |
| 3680 | - if (! isset($this->_labels['buttons'][ $type ])) { |
|
| 3680 | + if ( ! isset($this->_labels['buttons'][$type])) { |
|
| 3681 | 3681 | throw new EE_Error( |
| 3682 | 3682 | sprintf( |
| 3683 | 3683 | __( |
@@ -3690,7 +3690,7 @@ discard block |
||
| 3690 | 3690 | } |
| 3691 | 3691 | // finally check user access for this button. |
| 3692 | 3692 | $has_access = $this->check_user_access($action, true); |
| 3693 | - if (! $has_access) { |
|
| 3693 | + if ( ! $has_access) { |
|
| 3694 | 3694 | return ''; |
| 3695 | 3695 | } |
| 3696 | 3696 | $_base_url = ! $base_url ? $this->_admin_base_url : $base_url; |
@@ -3698,11 +3698,11 @@ discard block |
||
| 3698 | 3698 | 'action' => $action, |
| 3699 | 3699 | ); |
| 3700 | 3700 | // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten. |
| 3701 | - if (! empty($extra_request)) { |
|
| 3701 | + if ( ! empty($extra_request)) { |
|
| 3702 | 3702 | $query_args = array_merge($extra_request, $query_args); |
| 3703 | 3703 | } |
| 3704 | 3704 | $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce); |
| 3705 | - return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class); |
|
| 3705 | + return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][$type], $class); |
|
| 3706 | 3706 | } |
| 3707 | 3707 | |
| 3708 | 3708 | |
@@ -3728,7 +3728,7 @@ discard block |
||
| 3728 | 3728 | 'FHEE__EE_Admin_Page___per_page_screen_options__default', |
| 3729 | 3729 | 20 |
| 3730 | 3730 | ), |
| 3731 | - 'option' => $this->_current_page . '_' . $this->_current_view . '_per_page', |
|
| 3731 | + 'option' => $this->_current_page.'_'.$this->_current_view.'_per_page', |
|
| 3732 | 3732 | ); |
| 3733 | 3733 | // ONLY add the screen option if the user has access to it. |
| 3734 | 3734 | if ($this->check_user_access($this->_current_view, true)) { |
@@ -3749,7 +3749,7 @@ discard block |
||
| 3749 | 3749 | { |
| 3750 | 3750 | if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) { |
| 3751 | 3751 | check_admin_referer('screen-options-nonce', 'screenoptionnonce'); |
| 3752 | - if (! $user = wp_get_current_user()) { |
|
| 3752 | + if ( ! $user = wp_get_current_user()) { |
|
| 3753 | 3753 | return; |
| 3754 | 3754 | } |
| 3755 | 3755 | $option = $_POST['wp_screen_options']['option']; |
@@ -3760,7 +3760,7 @@ discard block |
||
| 3760 | 3760 | $map_option = $option; |
| 3761 | 3761 | $option = str_replace('-', '_', $option); |
| 3762 | 3762 | switch ($map_option) { |
| 3763 | - case $this->_current_page . '_' . $this->_current_view . '_per_page': |
|
| 3763 | + case $this->_current_page.'_'.$this->_current_view.'_per_page': |
|
| 3764 | 3764 | $value = (int) $value; |
| 3765 | 3765 | $max_value = apply_filters( |
| 3766 | 3766 | 'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value', |
@@ -3818,13 +3818,13 @@ discard block |
||
| 3818 | 3818 | protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false) |
| 3819 | 3819 | { |
| 3820 | 3820 | $user_id = get_current_user_id(); |
| 3821 | - if (! $skip_route_verify) { |
|
| 3821 | + if ( ! $skip_route_verify) { |
|
| 3822 | 3822 | $this->_verify_route($route); |
| 3823 | 3823 | } |
| 3824 | 3824 | // now let's set the string for what kind of transient we're setting |
| 3825 | 3825 | $transient = $notices |
| 3826 | - ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3827 | - : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3826 | + ? 'ee_rte_n_tx_'.$route.'_'.$user_id |
|
| 3827 | + : 'rte_tx_'.$route.'_'.$user_id; |
|
| 3828 | 3828 | $data = $notices ? array('notices' => $data) : $data; |
| 3829 | 3829 | // is there already a transient for this route? If there is then let's ADD to that transient |
| 3830 | 3830 | $existing = is_multisite() && is_network_admin() |
@@ -3853,8 +3853,8 @@ discard block |
||
| 3853 | 3853 | $user_id = get_current_user_id(); |
| 3854 | 3854 | $route = ! $route ? $this->_req_action : $route; |
| 3855 | 3855 | $transient = $notices |
| 3856 | - ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3857 | - : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3856 | + ? 'ee_rte_n_tx_'.$route.'_'.$user_id |
|
| 3857 | + : 'rte_tx_'.$route.'_'.$user_id; |
|
| 3858 | 3858 | $data = is_multisite() && is_network_admin() |
| 3859 | 3859 | ? get_site_transient($transient) |
| 3860 | 3860 | : get_transient($transient); |
@@ -4073,7 +4073,7 @@ discard block |
||
| 4073 | 4073 | */ |
| 4074 | 4074 | protected function _next_link($url, $class = 'dashicons dashicons-arrow-right') |
| 4075 | 4075 | { |
| 4076 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4076 | + return '<a class="'.$class.'" href="'.$url.'"></a>'; |
|
| 4077 | 4077 | } |
| 4078 | 4078 | |
| 4079 | 4079 | |
@@ -4086,7 +4086,7 @@ discard block |
||
| 4086 | 4086 | */ |
| 4087 | 4087 | protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left') |
| 4088 | 4088 | { |
| 4089 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4089 | + return '<a class="'.$class.'" href="'.$url.'"></a>'; |
|
| 4090 | 4090 | } |
| 4091 | 4091 | |
| 4092 | 4092 | |
@@ -15,269 +15,269 @@ |
||
| 15 | 15 | abstract class EE_Help_Tour extends EE_Base |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * This is the label for the tour. It is used when regenerating restart buttons for the tour. Set this in the |
|
| 20 | - * constructor of the child class. |
|
| 21 | - * |
|
| 22 | - * @access protected |
|
| 23 | - * @var string |
|
| 24 | - */ |
|
| 25 | - protected $_label = ''; |
|
| 26 | - |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * This is the slug for the tour. It should be unique from all tours and is used for starting a tour and setting |
|
| 30 | - * cookies for the tour. Set this in the constructor of the child class. |
|
| 31 | - * |
|
| 32 | - * @access protected |
|
| 33 | - * @var string |
|
| 34 | - */ |
|
| 35 | - protected $_slug = ''; |
|
| 36 | - |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * This will contain the formatted array for the stops that gets used by EE_Admin_Page->_add_help_tour() for |
|
| 40 | - * setting up a tour on a given page. format for array is: array( |
|
| 41 | - * 0 => array( |
|
| 42 | - * 'id' => 'id_element', //if attached to an css id for an element then use this param. id's will take |
|
| 43 | - * precendence even if you also set class. |
|
| 44 | - * 'class' => 'class_element', //if attached to a css class for an element anchoring the stop then use |
|
| 45 | - * this param. The first element for that class is the anchor. If the class or the id are empty then the |
|
| 46 | - * stop will be a modal on the page anchored to the main body. |
|
| 47 | - * 'custom_class' => 'some_custom_class', //optional custom class to add for this stop. |
|
| 48 | - * 'button_text' => 'custom text for button', //optional |
|
| 49 | - * 'content' => 'The content for the stop', //required |
|
| 50 | - * 'pause_after' => false, //indicate if you want the tour to pause after this stop and it will get |
|
| 51 | - * added to the pauseAfter global option array setup for the joyride instance. This is only applicable |
|
| 52 | - * when this tour has been set to run on timer. |
|
| 53 | - * 'options' => array( |
|
| 54 | - * //override any of the global options set via the help_tour "option_callback" for the joyride |
|
| 55 | - * instance on this specific stop. |
|
| 56 | - * ) |
|
| 57 | - * ) |
|
| 58 | - * ); |
|
| 59 | - * |
|
| 60 | - * @access protected |
|
| 61 | - * @var array |
|
| 62 | - */ |
|
| 63 | - protected $_stops = array(); |
|
| 64 | - |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * This contains any stop specific options for the tour. |
|
| 68 | - * defaults are set but child classes can override. |
|
| 69 | - * |
|
| 70 | - * @access protected |
|
| 71 | - * @var array |
|
| 72 | - */ |
|
| 73 | - protected $_options = array(); |
|
| 74 | - |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * holds anything found in the $_REQUEST object (however we override any _gets with _post data). |
|
| 78 | - * |
|
| 79 | - * @access protected |
|
| 80 | - * @var array |
|
| 81 | - */ |
|
| 82 | - protected $_req_data = array(); |
|
| 83 | - |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * a flag that is set on init for whether this help_tour is happening on a caf install or not. |
|
| 87 | - * |
|
| 88 | - * @var boolean |
|
| 89 | - */ |
|
| 90 | - protected $_is_caf = false; |
|
| 91 | - |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * _constructor |
|
| 95 | - * initialized the tour object and sets up important properties required to setup the tour. |
|
| 96 | - * |
|
| 97 | - * @access public |
|
| 98 | - * @param boolean $caf used to indicate if this tour is happening on caf install or not. |
|
| 99 | - * @return void |
|
| 100 | - */ |
|
| 101 | - public function __construct($caf = false) |
|
| 102 | - { |
|
| 103 | - $this->_is_caf = $caf; |
|
| 104 | - $this->_req_data = array_merge($_GET, $_POST); |
|
| 105 | - $this->_set_tour_properties(); |
|
| 106 | - $this->_set_tour_stops(); |
|
| 107 | - $this->_set_tour_options(); |
|
| 108 | - |
|
| 109 | - // make sure the last tour stop has "end tour" for its button |
|
| 110 | - $end = array_pop($this->_stops); |
|
| 111 | - $end['button_text'] = __('End Tour', 'event_espresso'); |
|
| 112 | - // add back to stops |
|
| 113 | - $this->_stops[] = $end; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * required method that has the sole purpose of setting up the tour $_label and $_slug properties |
|
| 119 | - * |
|
| 120 | - * @abstract |
|
| 121 | - * @access protected |
|
| 122 | - * @return void |
|
| 123 | - */ |
|
| 124 | - abstract protected function _set_tour_properties(); |
|
| 125 | - |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * required method that's sole purpose is to setup the $_stops property |
|
| 129 | - * |
|
| 130 | - * @abstract |
|
| 131 | - * @access protected |
|
| 132 | - * @return void |
|
| 133 | - */ |
|
| 134 | - abstract protected function _set_tour_stops(); |
|
| 135 | - |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * The method can optionally be overridden by child classes to set the _options array if there are any default |
|
| 139 | - * options the child wishes to override for a this tour. See property definition for more info |
|
| 140 | - * |
|
| 141 | - * @access protected |
|
| 142 | - * @return void |
|
| 143 | - */ |
|
| 144 | - protected function _set_tour_options($options = array()) |
|
| 145 | - { |
|
| 146 | - $defaults = array( |
|
| 147 | - 'tipLocation' => 'bottom', |
|
| 148 | - // 'top', 'bottom', 'right', 'left' in relation to parent |
|
| 149 | - 'nubPosition' => 'auto', |
|
| 150 | - // override on a per tooltip bases. can be "auto", "right", "top", "bottom", "left" |
|
| 151 | - 'tipAdjustmentY' => 0, |
|
| 152 | - // allow for adjustment of tip |
|
| 153 | - 'tipAdjustmentX' => 0, |
|
| 154 | - // allow for adjustment of tip |
|
| 155 | - 'scroll' => true, |
|
| 156 | - // whether to scrollTo the next step or not |
|
| 157 | - 'scrollSpeed' => 300, |
|
| 158 | - // Page scrolling speed in ms |
|
| 159 | - 'timer' => 0, |
|
| 160 | - // 0 = off, all other numbers = time(ms) |
|
| 161 | - 'autoStart' => true, |
|
| 162 | - // true or false - false tour starts when restart called |
|
| 163 | - 'startTimerOnClick' => true, |
|
| 164 | - // true/false to start timer on first click |
|
| 165 | - 'nextButton' => true, |
|
| 166 | - // true/false for next button visibility |
|
| 167 | - 'button_text' => __('Next', 'event_espresso'), |
|
| 168 | - 'tipAnimation' => 'fade', |
|
| 169 | - // 'pop' or 'fade' in each tip |
|
| 170 | - 'pauseAfter' => array(), |
|
| 171 | - // array of indexes where to pause the tour after |
|
| 172 | - 'tipAnimationFadeSpeed' => 300, |
|
| 173 | - // if 'fade'- speed in ms of transition |
|
| 174 | - 'cookieMonster' => true, |
|
| 175 | - // true/false for whether cookies are used |
|
| 176 | - 'cookieName' => $this->get_slug(), |
|
| 177 | - // choose your own cookie name (setup will add the prefix for the specific page joyride) |
|
| 178 | - // set to false or yoursite.com |
|
| 179 | - 'cookieDomain' => false, |
|
| 180 | - // Where the tip be attached if not inline |
|
| 181 | - // 'tipContainer' => 'body', |
|
| 182 | - 'modal' => false, |
|
| 183 | - // Whether to cover page with modal during the tour |
|
| 184 | - 'expose' => false, |
|
| 185 | - // Whether to expose the elements at each step in the tour (requires modal:true), |
|
| 186 | - 'postExposeCallback' => 'EEHelpTour.postExposeCallback', |
|
| 187 | - // A method to call after an element has been exposed |
|
| 188 | - 'preRideCallback' => 'EEHelpTour_preRideCallback', |
|
| 189 | - // A method to call before the tour starts (passed index, tip, and cloned exposed element) |
|
| 190 | - 'postRideCallback' => 'EEHelpTour_postRideCallback', |
|
| 191 | - // a method to call once the tour closes. This will correspond to the name of a js method that will have to be defined in loaded js. |
|
| 192 | - 'preStepCallback' => 'EEHelpTour_preStepCallback', |
|
| 193 | - // A method to call before each step |
|
| 194 | - 'postStepCallback' => 'EEHelpTour_postStepCallback', |
|
| 195 | - // A method to call after each step (remember this will correspond with a js method that you will have to define in a js file BEFORE ee-help-tour.js loads, if the default methods do not exist, then ee-help-tour.js just substitues empty functions $.noop)/**/ |
|
| 196 | - ); |
|
| 197 | - |
|
| 198 | - $options = ! empty($options) && is_array($options) ? array_merge($defaults, $options) : $defaults; |
|
| 199 | - $this->_options = $options; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * getter functions to return all the properties for the tour. |
|
| 205 | - */ |
|
| 206 | - |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * get_slug |
|
| 210 | - * |
|
| 211 | - * @return string slug for the tour |
|
| 212 | - */ |
|
| 213 | - public function get_slug() |
|
| 214 | - { |
|
| 215 | - if (empty($this->_slug)) { |
|
| 216 | - throw new EE_Error( |
|
| 217 | - sprintf( |
|
| 218 | - __( |
|
| 219 | - 'There is no slug set for the help tour class (%s). Make sure that the $_slug property is set in the class constructor', |
|
| 220 | - 'event_espresso' |
|
| 221 | - ), |
|
| 222 | - get_class($this) |
|
| 223 | - ) |
|
| 224 | - ); |
|
| 225 | - } |
|
| 226 | - return $this->_slug; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - |
|
| 230 | - /** |
|
| 231 | - * get_label |
|
| 232 | - * |
|
| 233 | - * @return string |
|
| 234 | - */ |
|
| 235 | - public function get_label() |
|
| 236 | - { |
|
| 237 | - if (empty($this->_label)) { |
|
| 238 | - throw new EE_Error( |
|
| 239 | - sprintf( |
|
| 240 | - __( |
|
| 241 | - 'There is no label set for the help tour class (%s). Make sure that the $_label property is set in the class constructor', |
|
| 242 | - 'event_espresso' |
|
| 243 | - ), |
|
| 244 | - get_class($this) |
|
| 245 | - ) |
|
| 246 | - ); |
|
| 247 | - } |
|
| 248 | - return $this->_label; |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - |
|
| 252 | - /** |
|
| 253 | - * get_stops |
|
| 254 | - * |
|
| 255 | - * @return array |
|
| 256 | - */ |
|
| 257 | - public function get_stops() |
|
| 258 | - { |
|
| 259 | - foreach ($this->_stops as $ind => $stop) { |
|
| 260 | - if (! isset($stop['button_text'])) { |
|
| 261 | - $this->_stops[ $ind ]['button_text'] = $this->_options['button_text']; |
|
| 262 | - } |
|
| 263 | - } |
|
| 264 | - return $this->_stops; |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - |
|
| 268 | - /** |
|
| 269 | - * get options |
|
| 270 | - * |
|
| 271 | - * @return array |
|
| 272 | - */ |
|
| 273 | - public function get_options() |
|
| 274 | - { |
|
| 275 | - // let's make sure there are not pauses set |
|
| 276 | - foreach ($this->_stops as $ind => $stop) { |
|
| 277 | - if (isset($stop['pause_after']) && $stop['pause_after']) { |
|
| 278 | - $this->_options['pauseAfter'][] = $ind; |
|
| 279 | - } |
|
| 280 | - } |
|
| 281 | - return apply_filters('FHEE__' . get_class($this) . '__get_options', $this->_options, $this); |
|
| 282 | - } |
|
| 18 | + /** |
|
| 19 | + * This is the label for the tour. It is used when regenerating restart buttons for the tour. Set this in the |
|
| 20 | + * constructor of the child class. |
|
| 21 | + * |
|
| 22 | + * @access protected |
|
| 23 | + * @var string |
|
| 24 | + */ |
|
| 25 | + protected $_label = ''; |
|
| 26 | + |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * This is the slug for the tour. It should be unique from all tours and is used for starting a tour and setting |
|
| 30 | + * cookies for the tour. Set this in the constructor of the child class. |
|
| 31 | + * |
|
| 32 | + * @access protected |
|
| 33 | + * @var string |
|
| 34 | + */ |
|
| 35 | + protected $_slug = ''; |
|
| 36 | + |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * This will contain the formatted array for the stops that gets used by EE_Admin_Page->_add_help_tour() for |
|
| 40 | + * setting up a tour on a given page. format for array is: array( |
|
| 41 | + * 0 => array( |
|
| 42 | + * 'id' => 'id_element', //if attached to an css id for an element then use this param. id's will take |
|
| 43 | + * precendence even if you also set class. |
|
| 44 | + * 'class' => 'class_element', //if attached to a css class for an element anchoring the stop then use |
|
| 45 | + * this param. The first element for that class is the anchor. If the class or the id are empty then the |
|
| 46 | + * stop will be a modal on the page anchored to the main body. |
|
| 47 | + * 'custom_class' => 'some_custom_class', //optional custom class to add for this stop. |
|
| 48 | + * 'button_text' => 'custom text for button', //optional |
|
| 49 | + * 'content' => 'The content for the stop', //required |
|
| 50 | + * 'pause_after' => false, //indicate if you want the tour to pause after this stop and it will get |
|
| 51 | + * added to the pauseAfter global option array setup for the joyride instance. This is only applicable |
|
| 52 | + * when this tour has been set to run on timer. |
|
| 53 | + * 'options' => array( |
|
| 54 | + * //override any of the global options set via the help_tour "option_callback" for the joyride |
|
| 55 | + * instance on this specific stop. |
|
| 56 | + * ) |
|
| 57 | + * ) |
|
| 58 | + * ); |
|
| 59 | + * |
|
| 60 | + * @access protected |
|
| 61 | + * @var array |
|
| 62 | + */ |
|
| 63 | + protected $_stops = array(); |
|
| 64 | + |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * This contains any stop specific options for the tour. |
|
| 68 | + * defaults are set but child classes can override. |
|
| 69 | + * |
|
| 70 | + * @access protected |
|
| 71 | + * @var array |
|
| 72 | + */ |
|
| 73 | + protected $_options = array(); |
|
| 74 | + |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * holds anything found in the $_REQUEST object (however we override any _gets with _post data). |
|
| 78 | + * |
|
| 79 | + * @access protected |
|
| 80 | + * @var array |
|
| 81 | + */ |
|
| 82 | + protected $_req_data = array(); |
|
| 83 | + |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * a flag that is set on init for whether this help_tour is happening on a caf install or not. |
|
| 87 | + * |
|
| 88 | + * @var boolean |
|
| 89 | + */ |
|
| 90 | + protected $_is_caf = false; |
|
| 91 | + |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * _constructor |
|
| 95 | + * initialized the tour object and sets up important properties required to setup the tour. |
|
| 96 | + * |
|
| 97 | + * @access public |
|
| 98 | + * @param boolean $caf used to indicate if this tour is happening on caf install or not. |
|
| 99 | + * @return void |
|
| 100 | + */ |
|
| 101 | + public function __construct($caf = false) |
|
| 102 | + { |
|
| 103 | + $this->_is_caf = $caf; |
|
| 104 | + $this->_req_data = array_merge($_GET, $_POST); |
|
| 105 | + $this->_set_tour_properties(); |
|
| 106 | + $this->_set_tour_stops(); |
|
| 107 | + $this->_set_tour_options(); |
|
| 108 | + |
|
| 109 | + // make sure the last tour stop has "end tour" for its button |
|
| 110 | + $end = array_pop($this->_stops); |
|
| 111 | + $end['button_text'] = __('End Tour', 'event_espresso'); |
|
| 112 | + // add back to stops |
|
| 113 | + $this->_stops[] = $end; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * required method that has the sole purpose of setting up the tour $_label and $_slug properties |
|
| 119 | + * |
|
| 120 | + * @abstract |
|
| 121 | + * @access protected |
|
| 122 | + * @return void |
|
| 123 | + */ |
|
| 124 | + abstract protected function _set_tour_properties(); |
|
| 125 | + |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * required method that's sole purpose is to setup the $_stops property |
|
| 129 | + * |
|
| 130 | + * @abstract |
|
| 131 | + * @access protected |
|
| 132 | + * @return void |
|
| 133 | + */ |
|
| 134 | + abstract protected function _set_tour_stops(); |
|
| 135 | + |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * The method can optionally be overridden by child classes to set the _options array if there are any default |
|
| 139 | + * options the child wishes to override for a this tour. See property definition for more info |
|
| 140 | + * |
|
| 141 | + * @access protected |
|
| 142 | + * @return void |
|
| 143 | + */ |
|
| 144 | + protected function _set_tour_options($options = array()) |
|
| 145 | + { |
|
| 146 | + $defaults = array( |
|
| 147 | + 'tipLocation' => 'bottom', |
|
| 148 | + // 'top', 'bottom', 'right', 'left' in relation to parent |
|
| 149 | + 'nubPosition' => 'auto', |
|
| 150 | + // override on a per tooltip bases. can be "auto", "right", "top", "bottom", "left" |
|
| 151 | + 'tipAdjustmentY' => 0, |
|
| 152 | + // allow for adjustment of tip |
|
| 153 | + 'tipAdjustmentX' => 0, |
|
| 154 | + // allow for adjustment of tip |
|
| 155 | + 'scroll' => true, |
|
| 156 | + // whether to scrollTo the next step or not |
|
| 157 | + 'scrollSpeed' => 300, |
|
| 158 | + // Page scrolling speed in ms |
|
| 159 | + 'timer' => 0, |
|
| 160 | + // 0 = off, all other numbers = time(ms) |
|
| 161 | + 'autoStart' => true, |
|
| 162 | + // true or false - false tour starts when restart called |
|
| 163 | + 'startTimerOnClick' => true, |
|
| 164 | + // true/false to start timer on first click |
|
| 165 | + 'nextButton' => true, |
|
| 166 | + // true/false for next button visibility |
|
| 167 | + 'button_text' => __('Next', 'event_espresso'), |
|
| 168 | + 'tipAnimation' => 'fade', |
|
| 169 | + // 'pop' or 'fade' in each tip |
|
| 170 | + 'pauseAfter' => array(), |
|
| 171 | + // array of indexes where to pause the tour after |
|
| 172 | + 'tipAnimationFadeSpeed' => 300, |
|
| 173 | + // if 'fade'- speed in ms of transition |
|
| 174 | + 'cookieMonster' => true, |
|
| 175 | + // true/false for whether cookies are used |
|
| 176 | + 'cookieName' => $this->get_slug(), |
|
| 177 | + // choose your own cookie name (setup will add the prefix for the specific page joyride) |
|
| 178 | + // set to false or yoursite.com |
|
| 179 | + 'cookieDomain' => false, |
|
| 180 | + // Where the tip be attached if not inline |
|
| 181 | + // 'tipContainer' => 'body', |
|
| 182 | + 'modal' => false, |
|
| 183 | + // Whether to cover page with modal during the tour |
|
| 184 | + 'expose' => false, |
|
| 185 | + // Whether to expose the elements at each step in the tour (requires modal:true), |
|
| 186 | + 'postExposeCallback' => 'EEHelpTour.postExposeCallback', |
|
| 187 | + // A method to call after an element has been exposed |
|
| 188 | + 'preRideCallback' => 'EEHelpTour_preRideCallback', |
|
| 189 | + // A method to call before the tour starts (passed index, tip, and cloned exposed element) |
|
| 190 | + 'postRideCallback' => 'EEHelpTour_postRideCallback', |
|
| 191 | + // a method to call once the tour closes. This will correspond to the name of a js method that will have to be defined in loaded js. |
|
| 192 | + 'preStepCallback' => 'EEHelpTour_preStepCallback', |
|
| 193 | + // A method to call before each step |
|
| 194 | + 'postStepCallback' => 'EEHelpTour_postStepCallback', |
|
| 195 | + // A method to call after each step (remember this will correspond with a js method that you will have to define in a js file BEFORE ee-help-tour.js loads, if the default methods do not exist, then ee-help-tour.js just substitues empty functions $.noop)/**/ |
|
| 196 | + ); |
|
| 197 | + |
|
| 198 | + $options = ! empty($options) && is_array($options) ? array_merge($defaults, $options) : $defaults; |
|
| 199 | + $this->_options = $options; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * getter functions to return all the properties for the tour. |
|
| 205 | + */ |
|
| 206 | + |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * get_slug |
|
| 210 | + * |
|
| 211 | + * @return string slug for the tour |
|
| 212 | + */ |
|
| 213 | + public function get_slug() |
|
| 214 | + { |
|
| 215 | + if (empty($this->_slug)) { |
|
| 216 | + throw new EE_Error( |
|
| 217 | + sprintf( |
|
| 218 | + __( |
|
| 219 | + 'There is no slug set for the help tour class (%s). Make sure that the $_slug property is set in the class constructor', |
|
| 220 | + 'event_espresso' |
|
| 221 | + ), |
|
| 222 | + get_class($this) |
|
| 223 | + ) |
|
| 224 | + ); |
|
| 225 | + } |
|
| 226 | + return $this->_slug; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + |
|
| 230 | + /** |
|
| 231 | + * get_label |
|
| 232 | + * |
|
| 233 | + * @return string |
|
| 234 | + */ |
|
| 235 | + public function get_label() |
|
| 236 | + { |
|
| 237 | + if (empty($this->_label)) { |
|
| 238 | + throw new EE_Error( |
|
| 239 | + sprintf( |
|
| 240 | + __( |
|
| 241 | + 'There is no label set for the help tour class (%s). Make sure that the $_label property is set in the class constructor', |
|
| 242 | + 'event_espresso' |
|
| 243 | + ), |
|
| 244 | + get_class($this) |
|
| 245 | + ) |
|
| 246 | + ); |
|
| 247 | + } |
|
| 248 | + return $this->_label; |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + |
|
| 252 | + /** |
|
| 253 | + * get_stops |
|
| 254 | + * |
|
| 255 | + * @return array |
|
| 256 | + */ |
|
| 257 | + public function get_stops() |
|
| 258 | + { |
|
| 259 | + foreach ($this->_stops as $ind => $stop) { |
|
| 260 | + if (! isset($stop['button_text'])) { |
|
| 261 | + $this->_stops[ $ind ]['button_text'] = $this->_options['button_text']; |
|
| 262 | + } |
|
| 263 | + } |
|
| 264 | + return $this->_stops; |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + |
|
| 268 | + /** |
|
| 269 | + * get options |
|
| 270 | + * |
|
| 271 | + * @return array |
|
| 272 | + */ |
|
| 273 | + public function get_options() |
|
| 274 | + { |
|
| 275 | + // let's make sure there are not pauses set |
|
| 276 | + foreach ($this->_stops as $ind => $stop) { |
|
| 277 | + if (isset($stop['pause_after']) && $stop['pause_after']) { |
|
| 278 | + $this->_options['pauseAfter'][] = $ind; |
|
| 279 | + } |
|
| 280 | + } |
|
| 281 | + return apply_filters('FHEE__' . get_class($this) . '__get_options', $this->_options, $this); |
|
| 282 | + } |
|
| 283 | 283 | } |
@@ -14,2537 +14,2537 @@ discard block |
||
| 14 | 14 | final class EE_Config implements ResettableInterface |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - const OPTION_NAME = 'ee_config'; |
|
| 18 | - |
|
| 19 | - const LOG_NAME = 'ee_config_log'; |
|
| 20 | - |
|
| 21 | - const LOG_LENGTH = 100; |
|
| 22 | - |
|
| 23 | - const ADDON_OPTION_NAMES = 'ee_config_option_names'; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * instance of the EE_Config object |
|
| 27 | - * |
|
| 28 | - * @var EE_Config $_instance |
|
| 29 | - * @access private |
|
| 30 | - */ |
|
| 31 | - private static $_instance; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @var boolean $_logging_enabled |
|
| 35 | - */ |
|
| 36 | - private static $_logging_enabled = false; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * @var LegacyShortcodesManager $legacy_shortcodes_manager |
|
| 40 | - */ |
|
| 41 | - private $legacy_shortcodes_manager; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * An StdClass whose property names are addon slugs, |
|
| 45 | - * and values are their config classes |
|
| 46 | - * |
|
| 47 | - * @var StdClass |
|
| 48 | - */ |
|
| 49 | - public $addons; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * @var EE_Admin_Config |
|
| 53 | - */ |
|
| 54 | - public $admin; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @var EE_Core_Config |
|
| 58 | - */ |
|
| 59 | - public $core; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @var EE_Currency_Config |
|
| 63 | - */ |
|
| 64 | - public $currency; |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * @var EE_Organization_Config |
|
| 68 | - */ |
|
| 69 | - public $organization; |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @var EE_Registration_Config |
|
| 73 | - */ |
|
| 74 | - public $registration; |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * @var EE_Template_Config |
|
| 78 | - */ |
|
| 79 | - public $template_settings; |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Holds EE environment values. |
|
| 83 | - * |
|
| 84 | - * @var EE_Environment_Config |
|
| 85 | - */ |
|
| 86 | - public $environment; |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * settings pertaining to Google maps |
|
| 90 | - * |
|
| 91 | - * @var EE_Map_Config |
|
| 92 | - */ |
|
| 93 | - public $map_settings; |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * settings pertaining to Taxes |
|
| 97 | - * |
|
| 98 | - * @var EE_Tax_Config |
|
| 99 | - */ |
|
| 100 | - public $tax_settings; |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Settings pertaining to global messages settings. |
|
| 104 | - * |
|
| 105 | - * @var EE_Messages_Config |
|
| 106 | - */ |
|
| 107 | - public $messages; |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @deprecated |
|
| 111 | - * @var EE_Gateway_Config |
|
| 112 | - */ |
|
| 113 | - public $gateway; |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * @var array $_addon_option_names |
|
| 117 | - * @access private |
|
| 118 | - */ |
|
| 119 | - private $_addon_option_names = array(); |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * @var array $_module_route_map |
|
| 123 | - * @access private |
|
| 124 | - */ |
|
| 125 | - private static $_module_route_map = array(); |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * @var array $_module_forward_map |
|
| 129 | - * @access private |
|
| 130 | - */ |
|
| 131 | - private static $_module_forward_map = array(); |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * @var array $_module_view_map |
|
| 135 | - * @access private |
|
| 136 | - */ |
|
| 137 | - private static $_module_view_map = array(); |
|
| 138 | - |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * @singleton method used to instantiate class object |
|
| 142 | - * @access public |
|
| 143 | - * @return EE_Config instance |
|
| 144 | - */ |
|
| 145 | - public static function instance() |
|
| 146 | - { |
|
| 147 | - // check if class object is instantiated, and instantiated properly |
|
| 148 | - if (! self::$_instance instanceof EE_Config) { |
|
| 149 | - self::$_instance = new self(); |
|
| 150 | - } |
|
| 151 | - return self::$_instance; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * Resets the config |
|
| 157 | - * |
|
| 158 | - * @param bool $hard_reset if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE |
|
| 159 | - * (default) leaves the database alone, and merely resets the EE_Config object to |
|
| 160 | - * reflect its state in the database |
|
| 161 | - * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave |
|
| 162 | - * $_instance as NULL. Useful in case you want to forget about the old instance on |
|
| 163 | - * EE_Config, but might not be ready to instantiate EE_Config currently (eg if the |
|
| 164 | - * site was put into maintenance mode) |
|
| 165 | - * @return EE_Config |
|
| 166 | - */ |
|
| 167 | - public static function reset($hard_reset = false, $reinstantiate = true) |
|
| 168 | - { |
|
| 169 | - if (self::$_instance instanceof EE_Config) { |
|
| 170 | - if ($hard_reset) { |
|
| 171 | - self::$_instance->legacy_shortcodes_manager = null; |
|
| 172 | - self::$_instance->_addon_option_names = array(); |
|
| 173 | - self::$_instance->_initialize_config(); |
|
| 174 | - self::$_instance->update_espresso_config(); |
|
| 175 | - } |
|
| 176 | - self::$_instance->update_addon_option_names(); |
|
| 177 | - } |
|
| 178 | - self::$_instance = null; |
|
| 179 | - // we don't need to reset the static properties imo because those should |
|
| 180 | - // only change when a module is added or removed. Currently we don't |
|
| 181 | - // support removing a module during a request when it previously existed |
|
| 182 | - if ($reinstantiate) { |
|
| 183 | - return self::instance(); |
|
| 184 | - } else { |
|
| 185 | - return null; |
|
| 186 | - } |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * class constructor |
|
| 192 | - * |
|
| 193 | - * @access private |
|
| 194 | - */ |
|
| 195 | - private function __construct() |
|
| 196 | - { |
|
| 197 | - do_action('AHEE__EE_Config__construct__begin', $this); |
|
| 198 | - EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false); |
|
| 199 | - // setup empty config classes |
|
| 200 | - $this->_initialize_config(); |
|
| 201 | - // load existing EE site settings |
|
| 202 | - $this->_load_core_config(); |
|
| 203 | - // confirm everything loaded correctly and set filtered defaults if not |
|
| 204 | - $this->_verify_config(); |
|
| 205 | - // register shortcodes and modules |
|
| 206 | - add_action( |
|
| 207 | - 'AHEE__EE_System__register_shortcodes_modules_and_widgets', |
|
| 208 | - array($this, 'register_shortcodes_and_modules'), |
|
| 209 | - 999 |
|
| 210 | - ); |
|
| 211 | - // initialize shortcodes and modules |
|
| 212 | - add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules')); |
|
| 213 | - // register widgets |
|
| 214 | - add_action('widgets_init', array($this, 'widgets_init'), 10); |
|
| 215 | - // shutdown |
|
| 216 | - add_action('shutdown', array($this, 'shutdown'), 10); |
|
| 217 | - // construct__end hook |
|
| 218 | - do_action('AHEE__EE_Config__construct__end', $this); |
|
| 219 | - // hardcoded hack |
|
| 220 | - $this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - |
|
| 224 | - /** |
|
| 225 | - * @return boolean |
|
| 226 | - */ |
|
| 227 | - public static function logging_enabled() |
|
| 228 | - { |
|
| 229 | - return self::$_logging_enabled; |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * use to get the current theme if needed from static context |
|
| 235 | - * |
|
| 236 | - * @return string current theme set. |
|
| 237 | - */ |
|
| 238 | - public static function get_current_theme() |
|
| 239 | - { |
|
| 240 | - return isset(self::$_instance->template_settings->current_espresso_theme) |
|
| 241 | - ? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014'; |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - |
|
| 245 | - /** |
|
| 246 | - * _initialize_config |
|
| 247 | - * |
|
| 248 | - * @access private |
|
| 249 | - * @return void |
|
| 250 | - */ |
|
| 251 | - private function _initialize_config() |
|
| 252 | - { |
|
| 253 | - EE_Config::trim_log(); |
|
| 254 | - // set defaults |
|
| 255 | - $this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array()); |
|
| 256 | - $this->addons = new stdClass(); |
|
| 257 | - // set _module_route_map |
|
| 258 | - EE_Config::$_module_route_map = array(); |
|
| 259 | - // set _module_forward_map |
|
| 260 | - EE_Config::$_module_forward_map = array(); |
|
| 261 | - // set _module_view_map |
|
| 262 | - EE_Config::$_module_view_map = array(); |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * load core plugin configuration |
|
| 268 | - * |
|
| 269 | - * @access private |
|
| 270 | - * @return void |
|
| 271 | - */ |
|
| 272 | - private function _load_core_config() |
|
| 273 | - { |
|
| 274 | - // load_core_config__start hook |
|
| 275 | - do_action('AHEE__EE_Config___load_core_config__start', $this); |
|
| 276 | - $espresso_config = $this->get_espresso_config(); |
|
| 277 | - foreach ($espresso_config as $config => $settings) { |
|
| 278 | - // load_core_config__start hook |
|
| 279 | - $settings = apply_filters( |
|
| 280 | - 'FHEE__EE_Config___load_core_config__config_settings', |
|
| 281 | - $settings, |
|
| 282 | - $config, |
|
| 283 | - $this |
|
| 284 | - ); |
|
| 285 | - if (is_object($settings) && property_exists($this, $config)) { |
|
| 286 | - $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings); |
|
| 287 | - // call configs populate method to ensure any defaults are set for empty values. |
|
| 288 | - if (method_exists($settings, 'populate')) { |
|
| 289 | - $this->{$config}->populate(); |
|
| 290 | - } |
|
| 291 | - if (method_exists($settings, 'do_hooks')) { |
|
| 292 | - $this->{$config}->do_hooks(); |
|
| 293 | - } |
|
| 294 | - } |
|
| 295 | - } |
|
| 296 | - if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) { |
|
| 297 | - $this->update_espresso_config(); |
|
| 298 | - } |
|
| 299 | - // load_core_config__end hook |
|
| 300 | - do_action('AHEE__EE_Config___load_core_config__end', $this); |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * _verify_config |
|
| 306 | - * |
|
| 307 | - * @access protected |
|
| 308 | - * @return void |
|
| 309 | - */ |
|
| 310 | - protected function _verify_config() |
|
| 311 | - { |
|
| 312 | - $this->core = $this->core instanceof EE_Core_Config |
|
| 313 | - ? $this->core |
|
| 314 | - : new EE_Core_Config(); |
|
| 315 | - $this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core); |
|
| 316 | - $this->organization = $this->organization instanceof EE_Organization_Config |
|
| 317 | - ? $this->organization |
|
| 318 | - : new EE_Organization_Config(); |
|
| 319 | - $this->organization = apply_filters( |
|
| 320 | - 'FHEE__EE_Config___initialize_config__organization', |
|
| 321 | - $this->organization |
|
| 322 | - ); |
|
| 323 | - $this->currency = $this->currency instanceof EE_Currency_Config |
|
| 324 | - ? $this->currency |
|
| 325 | - : new EE_Currency_Config(); |
|
| 326 | - $this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency); |
|
| 327 | - $this->registration = $this->registration instanceof EE_Registration_Config |
|
| 328 | - ? $this->registration |
|
| 329 | - : new EE_Registration_Config(); |
|
| 330 | - $this->registration = apply_filters( |
|
| 331 | - 'FHEE__EE_Config___initialize_config__registration', |
|
| 332 | - $this->registration |
|
| 333 | - ); |
|
| 334 | - $this->admin = $this->admin instanceof EE_Admin_Config |
|
| 335 | - ? $this->admin |
|
| 336 | - : new EE_Admin_Config(); |
|
| 337 | - $this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin); |
|
| 338 | - $this->template_settings = $this->template_settings instanceof EE_Template_Config |
|
| 339 | - ? $this->template_settings |
|
| 340 | - : new EE_Template_Config(); |
|
| 341 | - $this->template_settings = apply_filters( |
|
| 342 | - 'FHEE__EE_Config___initialize_config__template_settings', |
|
| 343 | - $this->template_settings |
|
| 344 | - ); |
|
| 345 | - $this->map_settings = $this->map_settings instanceof EE_Map_Config |
|
| 346 | - ? $this->map_settings |
|
| 347 | - : new EE_Map_Config(); |
|
| 348 | - $this->map_settings = apply_filters( |
|
| 349 | - 'FHEE__EE_Config___initialize_config__map_settings', |
|
| 350 | - $this->map_settings |
|
| 351 | - ); |
|
| 352 | - $this->environment = $this->environment instanceof EE_Environment_Config |
|
| 353 | - ? $this->environment |
|
| 354 | - : new EE_Environment_Config(); |
|
| 355 | - $this->environment = apply_filters( |
|
| 356 | - 'FHEE__EE_Config___initialize_config__environment', |
|
| 357 | - $this->environment |
|
| 358 | - ); |
|
| 359 | - $this->tax_settings = $this->tax_settings instanceof EE_Tax_Config |
|
| 360 | - ? $this->tax_settings |
|
| 361 | - : new EE_Tax_Config(); |
|
| 362 | - $this->tax_settings = apply_filters( |
|
| 363 | - 'FHEE__EE_Config___initialize_config__tax_settings', |
|
| 364 | - $this->tax_settings |
|
| 365 | - ); |
|
| 366 | - $this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages); |
|
| 367 | - $this->messages = $this->messages instanceof EE_Messages_Config |
|
| 368 | - ? $this->messages |
|
| 369 | - : new EE_Messages_Config(); |
|
| 370 | - $this->gateway = $this->gateway instanceof EE_Gateway_Config |
|
| 371 | - ? $this->gateway |
|
| 372 | - : new EE_Gateway_Config(); |
|
| 373 | - $this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway); |
|
| 374 | - $this->legacy_shortcodes_manager = null; |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - |
|
| 378 | - /** |
|
| 379 | - * get_espresso_config |
|
| 380 | - * |
|
| 381 | - * @access public |
|
| 382 | - * @return array of espresso config stuff |
|
| 383 | - */ |
|
| 384 | - public function get_espresso_config() |
|
| 385 | - { |
|
| 386 | - // grab espresso configuration |
|
| 387 | - return apply_filters( |
|
| 388 | - 'FHEE__EE_Config__get_espresso_config__CFG', |
|
| 389 | - get_option(EE_Config::OPTION_NAME, array()) |
|
| 390 | - ); |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - |
|
| 394 | - /** |
|
| 395 | - * double_check_config_comparison |
|
| 396 | - * |
|
| 397 | - * @access public |
|
| 398 | - * @param string $option |
|
| 399 | - * @param $old_value |
|
| 400 | - * @param $value |
|
| 401 | - */ |
|
| 402 | - public function double_check_config_comparison($option = '', $old_value, $value) |
|
| 403 | - { |
|
| 404 | - // make sure we're checking the ee config |
|
| 405 | - if ($option === EE_Config::OPTION_NAME) { |
|
| 406 | - // run a loose comparison of the old value against the new value for type and properties, |
|
| 407 | - // but NOT exact instance like WP update_option does (ie: NOT type safe comparison) |
|
| 408 | - if ($value != $old_value) { |
|
| 409 | - // if they are NOT the same, then remove the hook, |
|
| 410 | - // which means the subsequent update results will be based solely on the update query results |
|
| 411 | - // the reason we do this is because, as stated above, |
|
| 412 | - // WP update_option performs an exact instance comparison (===) on any update values passed to it |
|
| 413 | - // this happens PRIOR to serialization and any subsequent update. |
|
| 414 | - // If values are found to match their previous old value, |
|
| 415 | - // then WP bails before performing any update. |
|
| 416 | - // Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version |
|
| 417 | - // it just pulled from the db, with the one being passed to it (which will not match). |
|
| 418 | - // HOWEVER, once the object is serialized and passed off to MySQL to update, |
|
| 419 | - // MySQL MAY ALSO NOT perform the update because |
|
| 420 | - // the string it sees in the db looks the same as the new one it has been passed!!! |
|
| 421 | - // This results in the query returning an "affected rows" value of ZERO, |
|
| 422 | - // which gets returned immediately by WP update_option and looks like an error. |
|
| 423 | - remove_action('update_option', array($this, 'check_config_updated')); |
|
| 424 | - } |
|
| 425 | - } |
|
| 426 | - } |
|
| 427 | - |
|
| 428 | - |
|
| 429 | - /** |
|
| 430 | - * update_espresso_config |
|
| 431 | - * |
|
| 432 | - * @access public |
|
| 433 | - */ |
|
| 434 | - protected function _reset_espresso_addon_config() |
|
| 435 | - { |
|
| 436 | - $this->_addon_option_names = array(); |
|
| 437 | - foreach ($this->addons as $addon_name => $addon_config_obj) { |
|
| 438 | - $addon_config_obj = maybe_unserialize($addon_config_obj); |
|
| 439 | - if ($addon_config_obj instanceof EE_Config_Base) { |
|
| 440 | - $this->update_config('addons', $addon_name, $addon_config_obj, false); |
|
| 441 | - } |
|
| 442 | - $this->addons->{$addon_name} = null; |
|
| 443 | - } |
|
| 444 | - } |
|
| 445 | - |
|
| 446 | - |
|
| 447 | - /** |
|
| 448 | - * update_espresso_config |
|
| 449 | - * |
|
| 450 | - * @access public |
|
| 451 | - * @param bool $add_success |
|
| 452 | - * @param bool $add_error |
|
| 453 | - * @return bool |
|
| 454 | - */ |
|
| 455 | - public function update_espresso_config($add_success = false, $add_error = true) |
|
| 456 | - { |
|
| 457 | - // don't allow config updates during WP heartbeats |
|
| 458 | - if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
| 459 | - return false; |
|
| 460 | - } |
|
| 461 | - // commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197 |
|
| 462 | - // $clone = clone( self::$_instance ); |
|
| 463 | - // self::$_instance = NULL; |
|
| 464 | - do_action('AHEE__EE_Config__update_espresso_config__begin', $this); |
|
| 465 | - $this->_reset_espresso_addon_config(); |
|
| 466 | - // hook into update_option because that happens AFTER the ( $value === $old_value ) conditional |
|
| 467 | - // but BEFORE the actual update occurs |
|
| 468 | - add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3); |
|
| 469 | - // don't want to persist legacy_shortcodes_manager, but don't want to lose it either |
|
| 470 | - $legacy_shortcodes_manager = $this->legacy_shortcodes_manager; |
|
| 471 | - $this->legacy_shortcodes_manager = null; |
|
| 472 | - // now update "ee_config" |
|
| 473 | - $saved = update_option(EE_Config::OPTION_NAME, $this); |
|
| 474 | - $this->legacy_shortcodes_manager = $legacy_shortcodes_manager; |
|
| 475 | - EE_Config::log(EE_Config::OPTION_NAME); |
|
| 476 | - // if not saved... check if the hook we just added still exists; |
|
| 477 | - // if it does, it means one of two things: |
|
| 478 | - // that update_option bailed at the($value === $old_value) conditional, |
|
| 479 | - // or... |
|
| 480 | - // the db update query returned 0 rows affected |
|
| 481 | - // (probably because the data value was the same from it's perspective) |
|
| 482 | - // so the existence of the hook means that a negative result from update_option is NOT an error, |
|
| 483 | - // but just means no update occurred, so don't display an error to the user. |
|
| 484 | - // BUT... if update_option returns FALSE, AND the hook is missing, |
|
| 485 | - // then it means that something truly went wrong |
|
| 486 | - $saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved; |
|
| 487 | - // remove our action since we don't want it in the system anymore |
|
| 488 | - remove_action('update_option', array($this, 'double_check_config_comparison'), 1); |
|
| 489 | - do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved); |
|
| 490 | - // self::$_instance = $clone; |
|
| 491 | - // unset( $clone ); |
|
| 492 | - // if config remains the same or was updated successfully |
|
| 493 | - if ($saved) { |
|
| 494 | - if ($add_success) { |
|
| 495 | - EE_Error::add_success( |
|
| 496 | - __('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'), |
|
| 497 | - __FILE__, |
|
| 498 | - __FUNCTION__, |
|
| 499 | - __LINE__ |
|
| 500 | - ); |
|
| 501 | - } |
|
| 502 | - return true; |
|
| 503 | - } else { |
|
| 504 | - if ($add_error) { |
|
| 505 | - EE_Error::add_error( |
|
| 506 | - __('The Event Espresso Configuration Settings were not updated.', 'event_espresso'), |
|
| 507 | - __FILE__, |
|
| 508 | - __FUNCTION__, |
|
| 509 | - __LINE__ |
|
| 510 | - ); |
|
| 511 | - } |
|
| 512 | - return false; |
|
| 513 | - } |
|
| 514 | - } |
|
| 515 | - |
|
| 516 | - |
|
| 517 | - /** |
|
| 518 | - * _verify_config_params |
|
| 519 | - * |
|
| 520 | - * @access private |
|
| 521 | - * @param string $section |
|
| 522 | - * @param string $name |
|
| 523 | - * @param string $config_class |
|
| 524 | - * @param EE_Config_Base $config_obj |
|
| 525 | - * @param array $tests_to_run |
|
| 526 | - * @param bool $display_errors |
|
| 527 | - * @return bool TRUE on success, FALSE on fail |
|
| 528 | - */ |
|
| 529 | - private function _verify_config_params( |
|
| 530 | - $section = '', |
|
| 531 | - $name = '', |
|
| 532 | - $config_class = '', |
|
| 533 | - $config_obj = null, |
|
| 534 | - $tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8), |
|
| 535 | - $display_errors = true |
|
| 536 | - ) { |
|
| 537 | - try { |
|
| 538 | - foreach ($tests_to_run as $test) { |
|
| 539 | - switch ($test) { |
|
| 540 | - // TEST #1 : check that section was set |
|
| 541 | - case 1: |
|
| 542 | - if (empty($section)) { |
|
| 543 | - if ($display_errors) { |
|
| 544 | - throw new EE_Error( |
|
| 545 | - sprintf( |
|
| 546 | - __( |
|
| 547 | - 'No configuration section has been provided while attempting to save "%s".', |
|
| 548 | - 'event_espresso' |
|
| 549 | - ), |
|
| 550 | - $config_class |
|
| 551 | - ) |
|
| 552 | - ); |
|
| 553 | - } |
|
| 554 | - return false; |
|
| 555 | - } |
|
| 556 | - break; |
|
| 557 | - // TEST #2 : check that settings section exists |
|
| 558 | - case 2: |
|
| 559 | - if (! isset($this->{$section})) { |
|
| 560 | - if ($display_errors) { |
|
| 561 | - throw new EE_Error( |
|
| 562 | - sprintf( |
|
| 563 | - __('The "%s" configuration section does not exist.', 'event_espresso'), |
|
| 564 | - $section |
|
| 565 | - ) |
|
| 566 | - ); |
|
| 567 | - } |
|
| 568 | - return false; |
|
| 569 | - } |
|
| 570 | - break; |
|
| 571 | - // TEST #3 : check that section is the proper format |
|
| 572 | - case 3: |
|
| 573 | - if (! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass) |
|
| 574 | - ) { |
|
| 575 | - if ($display_errors) { |
|
| 576 | - throw new EE_Error( |
|
| 577 | - sprintf( |
|
| 578 | - __( |
|
| 579 | - 'The "%s" configuration settings have not been formatted correctly.', |
|
| 580 | - 'event_espresso' |
|
| 581 | - ), |
|
| 582 | - $section |
|
| 583 | - ) |
|
| 584 | - ); |
|
| 585 | - } |
|
| 586 | - return false; |
|
| 587 | - } |
|
| 588 | - break; |
|
| 589 | - // TEST #4 : check that config section name has been set |
|
| 590 | - case 4: |
|
| 591 | - if (empty($name)) { |
|
| 592 | - if ($display_errors) { |
|
| 593 | - throw new EE_Error( |
|
| 594 | - __( |
|
| 595 | - 'No name has been provided for the specific configuration section.', |
|
| 596 | - 'event_espresso' |
|
| 597 | - ) |
|
| 598 | - ); |
|
| 599 | - } |
|
| 600 | - return false; |
|
| 601 | - } |
|
| 602 | - break; |
|
| 603 | - // TEST #5 : check that a config class name has been set |
|
| 604 | - case 5: |
|
| 605 | - if (empty($config_class)) { |
|
| 606 | - if ($display_errors) { |
|
| 607 | - throw new EE_Error( |
|
| 608 | - __( |
|
| 609 | - 'No class name has been provided for the specific configuration section.', |
|
| 610 | - 'event_espresso' |
|
| 611 | - ) |
|
| 612 | - ); |
|
| 613 | - } |
|
| 614 | - return false; |
|
| 615 | - } |
|
| 616 | - break; |
|
| 617 | - // TEST #6 : verify config class is accessible |
|
| 618 | - case 6: |
|
| 619 | - if (! class_exists($config_class)) { |
|
| 620 | - if ($display_errors) { |
|
| 621 | - throw new EE_Error( |
|
| 622 | - sprintf( |
|
| 623 | - __( |
|
| 624 | - 'The "%s" class does not exist. Please ensure that an autoloader has been set for it.', |
|
| 625 | - 'event_espresso' |
|
| 626 | - ), |
|
| 627 | - $config_class |
|
| 628 | - ) |
|
| 629 | - ); |
|
| 630 | - } |
|
| 631 | - return false; |
|
| 632 | - } |
|
| 633 | - break; |
|
| 634 | - // TEST #7 : check that config has even been set |
|
| 635 | - case 7: |
|
| 636 | - if (! isset($this->{$section}->{$name})) { |
|
| 637 | - if ($display_errors) { |
|
| 638 | - throw new EE_Error( |
|
| 639 | - sprintf( |
|
| 640 | - __('No configuration has been set for "%1$s->%2$s".', 'event_espresso'), |
|
| 641 | - $section, |
|
| 642 | - $name |
|
| 643 | - ) |
|
| 644 | - ); |
|
| 645 | - } |
|
| 646 | - return false; |
|
| 647 | - } else { |
|
| 648 | - // and make sure it's not serialized |
|
| 649 | - $this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name}); |
|
| 650 | - } |
|
| 651 | - break; |
|
| 652 | - // TEST #8 : check that config is the requested type |
|
| 653 | - case 8: |
|
| 654 | - if (! $this->{$section}->{$name} instanceof $config_class) { |
|
| 655 | - if ($display_errors) { |
|
| 656 | - throw new EE_Error( |
|
| 657 | - sprintf( |
|
| 658 | - __( |
|
| 659 | - 'The configuration for "%1$s->%2$s" is not of the "%3$s" class.', |
|
| 660 | - 'event_espresso' |
|
| 661 | - ), |
|
| 662 | - $section, |
|
| 663 | - $name, |
|
| 664 | - $config_class |
|
| 665 | - ) |
|
| 666 | - ); |
|
| 667 | - } |
|
| 668 | - return false; |
|
| 669 | - } |
|
| 670 | - break; |
|
| 671 | - // TEST #9 : verify config object |
|
| 672 | - case 9: |
|
| 673 | - if (! $config_obj instanceof EE_Config_Base) { |
|
| 674 | - if ($display_errors) { |
|
| 675 | - throw new EE_Error( |
|
| 676 | - sprintf( |
|
| 677 | - __('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'), |
|
| 678 | - print_r($config_obj, true) |
|
| 679 | - ) |
|
| 680 | - ); |
|
| 681 | - } |
|
| 682 | - return false; |
|
| 683 | - } |
|
| 684 | - break; |
|
| 685 | - } |
|
| 686 | - } |
|
| 687 | - } catch (EE_Error $e) { |
|
| 688 | - $e->get_error(); |
|
| 689 | - } |
|
| 690 | - // you have successfully run the gauntlet |
|
| 691 | - return true; |
|
| 692 | - } |
|
| 693 | - |
|
| 694 | - |
|
| 695 | - /** |
|
| 696 | - * _generate_config_option_name |
|
| 697 | - * |
|
| 698 | - * @access protected |
|
| 699 | - * @param string $section |
|
| 700 | - * @param string $name |
|
| 701 | - * @return string |
|
| 702 | - */ |
|
| 703 | - private function _generate_config_option_name($section = '', $name = '') |
|
| 704 | - { |
|
| 705 | - return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name)); |
|
| 706 | - } |
|
| 707 | - |
|
| 708 | - |
|
| 709 | - /** |
|
| 710 | - * _set_config_class |
|
| 711 | - * ensures that a config class is set, either from a passed config class or one generated from the config name |
|
| 712 | - * |
|
| 713 | - * @access private |
|
| 714 | - * @param string $config_class |
|
| 715 | - * @param string $name |
|
| 716 | - * @return string |
|
| 717 | - */ |
|
| 718 | - private function _set_config_class($config_class = '', $name = '') |
|
| 719 | - { |
|
| 720 | - return ! empty($config_class) |
|
| 721 | - ? $config_class |
|
| 722 | - : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config'; |
|
| 723 | - } |
|
| 724 | - |
|
| 725 | - |
|
| 726 | - /** |
|
| 727 | - * set_config |
|
| 728 | - * |
|
| 729 | - * @access protected |
|
| 730 | - * @param string $section |
|
| 731 | - * @param string $name |
|
| 732 | - * @param string $config_class |
|
| 733 | - * @param EE_Config_Base $config_obj |
|
| 734 | - * @return EE_Config_Base |
|
| 735 | - */ |
|
| 736 | - public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null) |
|
| 737 | - { |
|
| 738 | - // ensure config class is set to something |
|
| 739 | - $config_class = $this->_set_config_class($config_class, $name); |
|
| 740 | - // run tests 1-4, 6, and 7 to verify all config params are set and valid |
|
| 741 | - if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 742 | - return null; |
|
| 743 | - } |
|
| 744 | - $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 745 | - // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now |
|
| 746 | - if (! isset($this->_addon_option_names[ $config_option_name ])) { |
|
| 747 | - $this->_addon_option_names[ $config_option_name ] = $config_class; |
|
| 748 | - $this->update_addon_option_names(); |
|
| 749 | - } |
|
| 750 | - // verify the incoming config object but suppress errors |
|
| 751 | - if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 752 | - $config_obj = new $config_class(); |
|
| 753 | - } |
|
| 754 | - if (get_option($config_option_name)) { |
|
| 755 | - EE_Config::log($config_option_name); |
|
| 756 | - update_option($config_option_name, $config_obj); |
|
| 757 | - $this->{$section}->{$name} = $config_obj; |
|
| 758 | - return $this->{$section}->{$name}; |
|
| 759 | - } else { |
|
| 760 | - // create a wp-option for this config |
|
| 761 | - if (add_option($config_option_name, $config_obj, '', 'no')) { |
|
| 762 | - $this->{$section}->{$name} = maybe_unserialize($config_obj); |
|
| 763 | - return $this->{$section}->{$name}; |
|
| 764 | - } else { |
|
| 765 | - EE_Error::add_error( |
|
| 766 | - sprintf(__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class), |
|
| 767 | - __FILE__, |
|
| 768 | - __FUNCTION__, |
|
| 769 | - __LINE__ |
|
| 770 | - ); |
|
| 771 | - return null; |
|
| 772 | - } |
|
| 773 | - } |
|
| 774 | - } |
|
| 775 | - |
|
| 776 | - |
|
| 777 | - /** |
|
| 778 | - * update_config |
|
| 779 | - * Important: the config object must ALREADY be set, otherwise this will produce an error. |
|
| 780 | - * |
|
| 781 | - * @access public |
|
| 782 | - * @param string $section |
|
| 783 | - * @param string $name |
|
| 784 | - * @param EE_Config_Base|string $config_obj |
|
| 785 | - * @param bool $throw_errors |
|
| 786 | - * @return bool |
|
| 787 | - */ |
|
| 788 | - public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true) |
|
| 789 | - { |
|
| 790 | - // don't allow config updates during WP heartbeats |
|
| 791 | - if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
| 792 | - return false; |
|
| 793 | - } |
|
| 794 | - $config_obj = maybe_unserialize($config_obj); |
|
| 795 | - // get class name of the incoming object |
|
| 796 | - $config_class = get_class($config_obj); |
|
| 797 | - // run tests 1-5 and 9 to verify config |
|
| 798 | - if (! $this->_verify_config_params( |
|
| 799 | - $section, |
|
| 800 | - $name, |
|
| 801 | - $config_class, |
|
| 802 | - $config_obj, |
|
| 803 | - array(1, 2, 3, 4, 7, 9) |
|
| 804 | - ) |
|
| 805 | - ) { |
|
| 806 | - return false; |
|
| 807 | - } |
|
| 808 | - $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 809 | - // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array |
|
| 810 | - if (! isset($this->_addon_option_names[ $config_option_name ])) { |
|
| 811 | - // save new config to db |
|
| 812 | - if ($this->set_config($section, $name, $config_class, $config_obj)) { |
|
| 813 | - return true; |
|
| 814 | - } |
|
| 815 | - } else { |
|
| 816 | - // first check if the record already exists |
|
| 817 | - $existing_config = get_option($config_option_name); |
|
| 818 | - $config_obj = serialize($config_obj); |
|
| 819 | - // just return if db record is already up to date (NOT type safe comparison) |
|
| 820 | - if ($existing_config == $config_obj) { |
|
| 821 | - $this->{$section}->{$name} = $config_obj; |
|
| 822 | - return true; |
|
| 823 | - } elseif (update_option($config_option_name, $config_obj)) { |
|
| 824 | - EE_Config::log($config_option_name); |
|
| 825 | - // update wp-option for this config class |
|
| 826 | - $this->{$section}->{$name} = $config_obj; |
|
| 827 | - return true; |
|
| 828 | - } elseif ($throw_errors) { |
|
| 829 | - EE_Error::add_error( |
|
| 830 | - sprintf( |
|
| 831 | - __( |
|
| 832 | - 'The "%1$s" object stored at"%2$s" was not successfully updated in the database.', |
|
| 833 | - 'event_espresso' |
|
| 834 | - ), |
|
| 835 | - $config_class, |
|
| 836 | - 'EE_Config->' . $section . '->' . $name |
|
| 837 | - ), |
|
| 838 | - __FILE__, |
|
| 839 | - __FUNCTION__, |
|
| 840 | - __LINE__ |
|
| 841 | - ); |
|
| 842 | - } |
|
| 843 | - } |
|
| 844 | - return false; |
|
| 845 | - } |
|
| 846 | - |
|
| 847 | - |
|
| 848 | - /** |
|
| 849 | - * get_config |
|
| 850 | - * |
|
| 851 | - * @access public |
|
| 852 | - * @param string $section |
|
| 853 | - * @param string $name |
|
| 854 | - * @param string $config_class |
|
| 855 | - * @return mixed EE_Config_Base | NULL |
|
| 856 | - */ |
|
| 857 | - public function get_config($section = '', $name = '', $config_class = '') |
|
| 858 | - { |
|
| 859 | - // ensure config class is set to something |
|
| 860 | - $config_class = $this->_set_config_class($config_class, $name); |
|
| 861 | - // run tests 1-4, 6 and 7 to verify that all params have been set |
|
| 862 | - if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 863 | - return null; |
|
| 864 | - } |
|
| 865 | - // now test if the requested config object exists, but suppress errors |
|
| 866 | - if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) { |
|
| 867 | - // config already exists, so pass it back |
|
| 868 | - return $this->{$section}->{$name}; |
|
| 869 | - } |
|
| 870 | - // load config option from db if it exists |
|
| 871 | - $config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name)); |
|
| 872 | - // verify the newly retrieved config object, but suppress errors |
|
| 873 | - if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 874 | - // config is good, so set it and pass it back |
|
| 875 | - $this->{$section}->{$name} = $config_obj; |
|
| 876 | - return $this->{$section}->{$name}; |
|
| 877 | - } |
|
| 878 | - // oops! $config_obj is not already set and does not exist in the db, so create a new one |
|
| 879 | - $config_obj = $this->set_config($section, $name, $config_class); |
|
| 880 | - // verify the newly created config object |
|
| 881 | - if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) { |
|
| 882 | - return $this->{$section}->{$name}; |
|
| 883 | - } else { |
|
| 884 | - EE_Error::add_error( |
|
| 885 | - sprintf(__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class), |
|
| 886 | - __FILE__, |
|
| 887 | - __FUNCTION__, |
|
| 888 | - __LINE__ |
|
| 889 | - ); |
|
| 890 | - } |
|
| 891 | - return null; |
|
| 892 | - } |
|
| 893 | - |
|
| 894 | - |
|
| 895 | - /** |
|
| 896 | - * get_config_option |
|
| 897 | - * |
|
| 898 | - * @access public |
|
| 899 | - * @param string $config_option_name |
|
| 900 | - * @return mixed EE_Config_Base | FALSE |
|
| 901 | - */ |
|
| 902 | - public function get_config_option($config_option_name = '') |
|
| 903 | - { |
|
| 904 | - // retrieve the wp-option for this config class. |
|
| 905 | - $config_option = maybe_unserialize(get_option($config_option_name, array())); |
|
| 906 | - if (empty($config_option)) { |
|
| 907 | - EE_Config::log($config_option_name . '-NOT-FOUND'); |
|
| 908 | - } |
|
| 909 | - return $config_option; |
|
| 910 | - } |
|
| 911 | - |
|
| 912 | - |
|
| 913 | - /** |
|
| 914 | - * log |
|
| 915 | - * |
|
| 916 | - * @param string $config_option_name |
|
| 917 | - */ |
|
| 918 | - public static function log($config_option_name = '') |
|
| 919 | - { |
|
| 920 | - if (EE_Config::logging_enabled() && ! empty($config_option_name)) { |
|
| 921 | - $config_log = get_option(EE_Config::LOG_NAME, array()); |
|
| 922 | - // copy incoming $_REQUEST and sanitize it so we can save it |
|
| 923 | - $_request = $_REQUEST; |
|
| 924 | - array_walk_recursive($_request, 'sanitize_text_field'); |
|
| 925 | - $config_log[ (string) microtime(true) ] = array( |
|
| 926 | - 'config_name' => $config_option_name, |
|
| 927 | - 'request' => $_request, |
|
| 928 | - ); |
|
| 929 | - update_option(EE_Config::LOG_NAME, $config_log); |
|
| 930 | - } |
|
| 931 | - } |
|
| 932 | - |
|
| 933 | - |
|
| 934 | - /** |
|
| 935 | - * trim_log |
|
| 936 | - * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH |
|
| 937 | - */ |
|
| 938 | - public static function trim_log() |
|
| 939 | - { |
|
| 940 | - if (! EE_Config::logging_enabled()) { |
|
| 941 | - return; |
|
| 942 | - } |
|
| 943 | - $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array())); |
|
| 944 | - $log_length = count($config_log); |
|
| 945 | - if ($log_length > EE_Config::LOG_LENGTH) { |
|
| 946 | - ksort($config_log); |
|
| 947 | - $config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true); |
|
| 948 | - update_option(EE_Config::LOG_NAME, $config_log); |
|
| 949 | - } |
|
| 950 | - } |
|
| 951 | - |
|
| 952 | - |
|
| 953 | - /** |
|
| 954 | - * get_page_for_posts |
|
| 955 | - * if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the |
|
| 956 | - * wp-option "page_for_posts", or "posts" if no page is selected |
|
| 957 | - * |
|
| 958 | - * @access public |
|
| 959 | - * @return string |
|
| 960 | - */ |
|
| 961 | - public static function get_page_for_posts() |
|
| 962 | - { |
|
| 963 | - $page_for_posts = get_option('page_for_posts'); |
|
| 964 | - if (! $page_for_posts) { |
|
| 965 | - return 'posts'; |
|
| 966 | - } |
|
| 967 | - /** @type WPDB $wpdb */ |
|
| 968 | - global $wpdb; |
|
| 969 | - $SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d"; |
|
| 970 | - return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts)); |
|
| 971 | - } |
|
| 972 | - |
|
| 973 | - |
|
| 974 | - /** |
|
| 975 | - * register_shortcodes_and_modules. |
|
| 976 | - * At this point, it's too early to tell if we're maintenance mode or not. |
|
| 977 | - * In fact, this is where we give modules a chance to let core know they exist |
|
| 978 | - * so they can help trigger maintenance mode if it's needed |
|
| 979 | - * |
|
| 980 | - * @access public |
|
| 981 | - * @return void |
|
| 982 | - */ |
|
| 983 | - public function register_shortcodes_and_modules() |
|
| 984 | - { |
|
| 985 | - // allow modules to set hooks for the rest of the system |
|
| 986 | - EE_Registry::instance()->modules = $this->_register_modules(); |
|
| 987 | - } |
|
| 988 | - |
|
| 989 | - |
|
| 990 | - /** |
|
| 991 | - * initialize_shortcodes_and_modules |
|
| 992 | - * meaning they can start adding their hooks to get stuff done |
|
| 993 | - * |
|
| 994 | - * @access public |
|
| 995 | - * @return void |
|
| 996 | - */ |
|
| 997 | - public function initialize_shortcodes_and_modules() |
|
| 998 | - { |
|
| 999 | - // allow modules to set hooks for the rest of the system |
|
| 1000 | - $this->_initialize_modules(); |
|
| 1001 | - } |
|
| 1002 | - |
|
| 1003 | - |
|
| 1004 | - /** |
|
| 1005 | - * widgets_init |
|
| 1006 | - * |
|
| 1007 | - * @access private |
|
| 1008 | - * @return void |
|
| 1009 | - */ |
|
| 1010 | - public function widgets_init() |
|
| 1011 | - { |
|
| 1012 | - // only init widgets on admin pages when not in complete maintenance, and |
|
| 1013 | - // on frontend when not in any maintenance mode |
|
| 1014 | - if (! EE_Maintenance_Mode::instance()->level() |
|
| 1015 | - || ( |
|
| 1016 | - is_admin() |
|
| 1017 | - && EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance |
|
| 1018 | - ) |
|
| 1019 | - ) { |
|
| 1020 | - // grab list of installed widgets |
|
| 1021 | - $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR); |
|
| 1022 | - // filter list of modules to register |
|
| 1023 | - $widgets_to_register = apply_filters( |
|
| 1024 | - 'FHEE__EE_Config__register_widgets__widgets_to_register', |
|
| 1025 | - $widgets_to_register |
|
| 1026 | - ); |
|
| 1027 | - if (! empty($widgets_to_register)) { |
|
| 1028 | - // cycle thru widget folders |
|
| 1029 | - foreach ($widgets_to_register as $widget_path) { |
|
| 1030 | - // add to list of installed widget modules |
|
| 1031 | - EE_Config::register_ee_widget($widget_path); |
|
| 1032 | - } |
|
| 1033 | - } |
|
| 1034 | - // filter list of installed modules |
|
| 1035 | - EE_Registry::instance()->widgets = apply_filters( |
|
| 1036 | - 'FHEE__EE_Config__register_widgets__installed_widgets', |
|
| 1037 | - EE_Registry::instance()->widgets |
|
| 1038 | - ); |
|
| 1039 | - } |
|
| 1040 | - } |
|
| 1041 | - |
|
| 1042 | - |
|
| 1043 | - /** |
|
| 1044 | - * register_ee_widget - makes core aware of this widget |
|
| 1045 | - * |
|
| 1046 | - * @access public |
|
| 1047 | - * @param string $widget_path - full path up to and including widget folder |
|
| 1048 | - * @return void |
|
| 1049 | - */ |
|
| 1050 | - public static function register_ee_widget($widget_path = null) |
|
| 1051 | - { |
|
| 1052 | - do_action('AHEE__EE_Config__register_widget__begin', $widget_path); |
|
| 1053 | - $widget_ext = '.widget.php'; |
|
| 1054 | - // make all separators match |
|
| 1055 | - $widget_path = rtrim(str_replace('\\', DS, $widget_path), DS); |
|
| 1056 | - // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1057 | - if (strpos($widget_path, $widget_ext) !== false) { |
|
| 1058 | - // grab and shortcode file name from directory name and break apart at dots |
|
| 1059 | - $file_name = explode('.', basename($widget_path)); |
|
| 1060 | - // take first segment from file name pieces and remove class prefix if it exists |
|
| 1061 | - $widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0]; |
|
| 1062 | - // sanitize shortcode directory name |
|
| 1063 | - $widget = sanitize_key($widget); |
|
| 1064 | - // now we need to rebuild the shortcode path |
|
| 1065 | - $widget_path = explode('/', $widget_path); |
|
| 1066 | - // remove last segment |
|
| 1067 | - array_pop($widget_path); |
|
| 1068 | - // glue it back together |
|
| 1069 | - $widget_path = implode(DS, $widget_path); |
|
| 1070 | - } else { |
|
| 1071 | - // grab and sanitize widget directory name |
|
| 1072 | - $widget = sanitize_key(basename($widget_path)); |
|
| 1073 | - } |
|
| 1074 | - // create classname from widget directory name |
|
| 1075 | - $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget))); |
|
| 1076 | - // add class prefix |
|
| 1077 | - $widget_class = 'EEW_' . $widget; |
|
| 1078 | - // does the widget exist ? |
|
| 1079 | - if (! is_readable($widget_path . '/' . $widget_class . $widget_ext)) { |
|
| 1080 | - $msg = sprintf( |
|
| 1081 | - __( |
|
| 1082 | - 'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', |
|
| 1083 | - 'event_espresso' |
|
| 1084 | - ), |
|
| 1085 | - $widget_class, |
|
| 1086 | - $widget_path . '/' . $widget_class . $widget_ext |
|
| 1087 | - ); |
|
| 1088 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1089 | - return; |
|
| 1090 | - } |
|
| 1091 | - // load the widget class file |
|
| 1092 | - require_once($widget_path . '/' . $widget_class . $widget_ext); |
|
| 1093 | - // verify that class exists |
|
| 1094 | - if (! class_exists($widget_class)) { |
|
| 1095 | - $msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class); |
|
| 1096 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1097 | - return; |
|
| 1098 | - } |
|
| 1099 | - register_widget($widget_class); |
|
| 1100 | - // add to array of registered widgets |
|
| 1101 | - EE_Registry::instance()->widgets->{$widget_class} = $widget_path . '/' . $widget_class . $widget_ext; |
|
| 1102 | - } |
|
| 1103 | - |
|
| 1104 | - |
|
| 1105 | - /** |
|
| 1106 | - * _register_modules |
|
| 1107 | - * |
|
| 1108 | - * @access private |
|
| 1109 | - * @return array |
|
| 1110 | - */ |
|
| 1111 | - private function _register_modules() |
|
| 1112 | - { |
|
| 1113 | - // grab list of installed modules |
|
| 1114 | - $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR); |
|
| 1115 | - // filter list of modules to register |
|
| 1116 | - $modules_to_register = apply_filters( |
|
| 1117 | - 'FHEE__EE_Config__register_modules__modules_to_register', |
|
| 1118 | - $modules_to_register |
|
| 1119 | - ); |
|
| 1120 | - if (! empty($modules_to_register)) { |
|
| 1121 | - // loop through folders |
|
| 1122 | - foreach ($modules_to_register as $module_path) { |
|
| 1123 | - /**TEMPORARILY EXCLUDE gateways from modules for time being**/ |
|
| 1124 | - if ($module_path !== EE_MODULES . 'zzz-copy-this-module-template' |
|
| 1125 | - && $module_path !== EE_MODULES . 'gateways' |
|
| 1126 | - ) { |
|
| 1127 | - // add to list of installed modules |
|
| 1128 | - EE_Config::register_module($module_path); |
|
| 1129 | - } |
|
| 1130 | - } |
|
| 1131 | - } |
|
| 1132 | - // filter list of installed modules |
|
| 1133 | - return apply_filters( |
|
| 1134 | - 'FHEE__EE_Config___register_modules__installed_modules', |
|
| 1135 | - EE_Registry::instance()->modules |
|
| 1136 | - ); |
|
| 1137 | - } |
|
| 1138 | - |
|
| 1139 | - |
|
| 1140 | - /** |
|
| 1141 | - * register_module - makes core aware of this module |
|
| 1142 | - * |
|
| 1143 | - * @access public |
|
| 1144 | - * @param string $module_path - full path up to and including module folder |
|
| 1145 | - * @return bool |
|
| 1146 | - */ |
|
| 1147 | - public static function register_module($module_path = null) |
|
| 1148 | - { |
|
| 1149 | - do_action('AHEE__EE_Config__register_module__begin', $module_path); |
|
| 1150 | - $module_ext = '.module.php'; |
|
| 1151 | - // make all separators match |
|
| 1152 | - $module_path = str_replace(array('\\', '/'), '/', $module_path); |
|
| 1153 | - // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1154 | - if (strpos($module_path, $module_ext) !== false) { |
|
| 1155 | - // grab and shortcode file name from directory name and break apart at dots |
|
| 1156 | - $module_file = explode('.', basename($module_path)); |
|
| 1157 | - // now we need to rebuild the shortcode path |
|
| 1158 | - $module_path = explode('/', $module_path); |
|
| 1159 | - // remove last segment |
|
| 1160 | - array_pop($module_path); |
|
| 1161 | - // glue it back together |
|
| 1162 | - $module_path = implode('/', $module_path) . '/'; |
|
| 1163 | - // take first segment from file name pieces and sanitize it |
|
| 1164 | - $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]); |
|
| 1165 | - // ensure class prefix is added |
|
| 1166 | - $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module; |
|
| 1167 | - } else { |
|
| 1168 | - // we need to generate the filename based off of the folder name |
|
| 1169 | - // grab and sanitize module name |
|
| 1170 | - $module = strtolower(basename($module_path)); |
|
| 1171 | - $module = preg_replace('/[^a-z0-9_\-]/', '', $module); |
|
| 1172 | - // like trailingslashit() |
|
| 1173 | - $module_path = rtrim($module_path, '/') . '/'; |
|
| 1174 | - // create classname from module directory name |
|
| 1175 | - $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module))); |
|
| 1176 | - // add class prefix |
|
| 1177 | - $module_class = 'EED_' . $module; |
|
| 1178 | - } |
|
| 1179 | - // does the module exist ? |
|
| 1180 | - if (! is_readable($module_path . '/' . $module_class . $module_ext)) { |
|
| 1181 | - $msg = sprintf( |
|
| 1182 | - __( |
|
| 1183 | - 'The requested %s module file could not be found or is not readable due to file permissions.', |
|
| 1184 | - 'event_espresso' |
|
| 1185 | - ), |
|
| 1186 | - $module |
|
| 1187 | - ); |
|
| 1188 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1189 | - return false; |
|
| 1190 | - } |
|
| 1191 | - // load the module class file |
|
| 1192 | - require_once($module_path . $module_class . $module_ext); |
|
| 1193 | - // verify that class exists |
|
| 1194 | - if (! class_exists($module_class)) { |
|
| 1195 | - $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
|
| 1196 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1197 | - return false; |
|
| 1198 | - } |
|
| 1199 | - // add to array of registered modules |
|
| 1200 | - EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext; |
|
| 1201 | - do_action( |
|
| 1202 | - 'AHEE__EE_Config__register_module__complete', |
|
| 1203 | - $module_class, |
|
| 1204 | - EE_Registry::instance()->modules->{$module_class} |
|
| 1205 | - ); |
|
| 1206 | - return true; |
|
| 1207 | - } |
|
| 1208 | - |
|
| 1209 | - |
|
| 1210 | - /** |
|
| 1211 | - * _initialize_modules |
|
| 1212 | - * allow modules to set hooks for the rest of the system |
|
| 1213 | - * |
|
| 1214 | - * @access private |
|
| 1215 | - * @return void |
|
| 1216 | - */ |
|
| 1217 | - private function _initialize_modules() |
|
| 1218 | - { |
|
| 1219 | - // cycle thru shortcode folders |
|
| 1220 | - foreach (EE_Registry::instance()->modules as $module_class => $module_path) { |
|
| 1221 | - // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system |
|
| 1222 | - // which set hooks ? |
|
| 1223 | - if (is_admin()) { |
|
| 1224 | - // fire immediately |
|
| 1225 | - call_user_func(array($module_class, 'set_hooks_admin')); |
|
| 1226 | - } else { |
|
| 1227 | - // delay until other systems are online |
|
| 1228 | - add_action( |
|
| 1229 | - 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', |
|
| 1230 | - array($module_class, 'set_hooks') |
|
| 1231 | - ); |
|
| 1232 | - } |
|
| 1233 | - } |
|
| 1234 | - } |
|
| 1235 | - |
|
| 1236 | - |
|
| 1237 | - /** |
|
| 1238 | - * register_route - adds module method routes to route_map |
|
| 1239 | - * |
|
| 1240 | - * @access public |
|
| 1241 | - * @param string $route - "pretty" public alias for module method |
|
| 1242 | - * @param string $module - module name (classname without EED_ prefix) |
|
| 1243 | - * @param string $method_name - the actual module method to be routed to |
|
| 1244 | - * @param string $key - url param key indicating a route is being called |
|
| 1245 | - * @return bool |
|
| 1246 | - */ |
|
| 1247 | - public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee') |
|
| 1248 | - { |
|
| 1249 | - do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name); |
|
| 1250 | - $module = str_replace('EED_', '', $module); |
|
| 1251 | - $module_class = 'EED_' . $module; |
|
| 1252 | - if (! isset(EE_Registry::instance()->modules->{$module_class})) { |
|
| 1253 | - $msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module); |
|
| 1254 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1255 | - return false; |
|
| 1256 | - } |
|
| 1257 | - if (empty($route)) { |
|
| 1258 | - $msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route); |
|
| 1259 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1260 | - return false; |
|
| 1261 | - } |
|
| 1262 | - if (! method_exists('EED_' . $module, $method_name)) { |
|
| 1263 | - $msg = sprintf( |
|
| 1264 | - __('A valid class method for the %s route has not been supplied.', 'event_espresso'), |
|
| 1265 | - $route |
|
| 1266 | - ); |
|
| 1267 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1268 | - return false; |
|
| 1269 | - } |
|
| 1270 | - EE_Config::$_module_route_map[ (string) $key ][ (string) $route ] = array('EED_' . $module, $method_name); |
|
| 1271 | - return true; |
|
| 1272 | - } |
|
| 1273 | - |
|
| 1274 | - |
|
| 1275 | - /** |
|
| 1276 | - * get_route - get module method route |
|
| 1277 | - * |
|
| 1278 | - * @access public |
|
| 1279 | - * @param string $route - "pretty" public alias for module method |
|
| 1280 | - * @param string $key - url param key indicating a route is being called |
|
| 1281 | - * @return string |
|
| 1282 | - */ |
|
| 1283 | - public static function get_route($route = null, $key = 'ee') |
|
| 1284 | - { |
|
| 1285 | - do_action('AHEE__EE_Config__get_route__begin', $route); |
|
| 1286 | - $route = (string) apply_filters('FHEE__EE_Config__get_route', $route); |
|
| 1287 | - if (isset(EE_Config::$_module_route_map[ $key ][ $route ])) { |
|
| 1288 | - return EE_Config::$_module_route_map[ $key ][ $route ]; |
|
| 1289 | - } |
|
| 1290 | - return null; |
|
| 1291 | - } |
|
| 1292 | - |
|
| 1293 | - |
|
| 1294 | - /** |
|
| 1295 | - * get_routes - get ALL module method routes |
|
| 1296 | - * |
|
| 1297 | - * @access public |
|
| 1298 | - * @return array |
|
| 1299 | - */ |
|
| 1300 | - public static function get_routes() |
|
| 1301 | - { |
|
| 1302 | - return EE_Config::$_module_route_map; |
|
| 1303 | - } |
|
| 1304 | - |
|
| 1305 | - |
|
| 1306 | - /** |
|
| 1307 | - * register_forward - allows modules to forward request to another module for further processing |
|
| 1308 | - * |
|
| 1309 | - * @access public |
|
| 1310 | - * @param string $route - "pretty" public alias for module method |
|
| 1311 | - * @param integer $status - integer value corresponding to status constant strings set in module parent |
|
| 1312 | - * class, allows different forwards to be served based on status |
|
| 1313 | - * @param array|string $forward - function name or array( class, method ) |
|
| 1314 | - * @param string $key - url param key indicating a route is being called |
|
| 1315 | - * @return bool |
|
| 1316 | - */ |
|
| 1317 | - public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee') |
|
| 1318 | - { |
|
| 1319 | - do_action('AHEE__EE_Config__register_forward', $route, $status, $forward); |
|
| 1320 | - if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) { |
|
| 1321 | - $msg = sprintf( |
|
| 1322 | - __('The module route %s for this forward has not been registered.', 'event_espresso'), |
|
| 1323 | - $route |
|
| 1324 | - ); |
|
| 1325 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1326 | - return false; |
|
| 1327 | - } |
|
| 1328 | - if (empty($forward)) { |
|
| 1329 | - $msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route); |
|
| 1330 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1331 | - return false; |
|
| 1332 | - } |
|
| 1333 | - if (is_array($forward)) { |
|
| 1334 | - if (! isset($forward[1])) { |
|
| 1335 | - $msg = sprintf( |
|
| 1336 | - __('A class method for the %s forwarding route has not been supplied.', 'event_espresso'), |
|
| 1337 | - $route |
|
| 1338 | - ); |
|
| 1339 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1340 | - return false; |
|
| 1341 | - } |
|
| 1342 | - if (! method_exists($forward[0], $forward[1])) { |
|
| 1343 | - $msg = sprintf( |
|
| 1344 | - __('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1345 | - $forward[1], |
|
| 1346 | - $route |
|
| 1347 | - ); |
|
| 1348 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1349 | - return false; |
|
| 1350 | - } |
|
| 1351 | - } elseif (! function_exists($forward)) { |
|
| 1352 | - $msg = sprintf( |
|
| 1353 | - __('The function %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1354 | - $forward, |
|
| 1355 | - $route |
|
| 1356 | - ); |
|
| 1357 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1358 | - return false; |
|
| 1359 | - } |
|
| 1360 | - EE_Config::$_module_forward_map[ $key ][ $route ][ absint($status) ] = $forward; |
|
| 1361 | - return true; |
|
| 1362 | - } |
|
| 1363 | - |
|
| 1364 | - |
|
| 1365 | - /** |
|
| 1366 | - * get_forward - get forwarding route |
|
| 1367 | - * |
|
| 1368 | - * @access public |
|
| 1369 | - * @param string $route - "pretty" public alias for module method |
|
| 1370 | - * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1371 | - * allows different forwards to be served based on status |
|
| 1372 | - * @param string $key - url param key indicating a route is being called |
|
| 1373 | - * @return string |
|
| 1374 | - */ |
|
| 1375 | - public static function get_forward($route = null, $status = 0, $key = 'ee') |
|
| 1376 | - { |
|
| 1377 | - do_action('AHEE__EE_Config__get_forward__begin', $route, $status); |
|
| 1378 | - if (isset(EE_Config::$_module_forward_map[ $key ][ $route ][ $status ])) { |
|
| 1379 | - return apply_filters( |
|
| 1380 | - 'FHEE__EE_Config__get_forward', |
|
| 1381 | - EE_Config::$_module_forward_map[ $key ][ $route ][ $status ], |
|
| 1382 | - $route, |
|
| 1383 | - $status |
|
| 1384 | - ); |
|
| 1385 | - } |
|
| 1386 | - return null; |
|
| 1387 | - } |
|
| 1388 | - |
|
| 1389 | - |
|
| 1390 | - /** |
|
| 1391 | - * register_forward - allows modules to specify different view templates for different method routes and status |
|
| 1392 | - * results |
|
| 1393 | - * |
|
| 1394 | - * @access public |
|
| 1395 | - * @param string $route - "pretty" public alias for module method |
|
| 1396 | - * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1397 | - * allows different views to be served based on status |
|
| 1398 | - * @param string $view |
|
| 1399 | - * @param string $key - url param key indicating a route is being called |
|
| 1400 | - * @return bool |
|
| 1401 | - */ |
|
| 1402 | - public static function register_view($route = null, $status = 0, $view = null, $key = 'ee') |
|
| 1403 | - { |
|
| 1404 | - do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view); |
|
| 1405 | - if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) { |
|
| 1406 | - $msg = sprintf( |
|
| 1407 | - __('The module route %s for this view has not been registered.', 'event_espresso'), |
|
| 1408 | - $route |
|
| 1409 | - ); |
|
| 1410 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1411 | - return false; |
|
| 1412 | - } |
|
| 1413 | - if (! is_readable($view)) { |
|
| 1414 | - $msg = sprintf( |
|
| 1415 | - __( |
|
| 1416 | - 'The %s view file could not be found or is not readable due to file permissions.', |
|
| 1417 | - 'event_espresso' |
|
| 1418 | - ), |
|
| 1419 | - $view |
|
| 1420 | - ); |
|
| 1421 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1422 | - return false; |
|
| 1423 | - } |
|
| 1424 | - EE_Config::$_module_view_map[ $key ][ $route ][ absint($status) ] = $view; |
|
| 1425 | - return true; |
|
| 1426 | - } |
|
| 1427 | - |
|
| 1428 | - |
|
| 1429 | - /** |
|
| 1430 | - * get_view - get view for route and status |
|
| 1431 | - * |
|
| 1432 | - * @access public |
|
| 1433 | - * @param string $route - "pretty" public alias for module method |
|
| 1434 | - * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1435 | - * allows different views to be served based on status |
|
| 1436 | - * @param string $key - url param key indicating a route is being called |
|
| 1437 | - * @return string |
|
| 1438 | - */ |
|
| 1439 | - public static function get_view($route = null, $status = 0, $key = 'ee') |
|
| 1440 | - { |
|
| 1441 | - do_action('AHEE__EE_Config__get_view__begin', $route, $status); |
|
| 1442 | - if (isset(EE_Config::$_module_view_map[ $key ][ $route ][ $status ])) { |
|
| 1443 | - return apply_filters( |
|
| 1444 | - 'FHEE__EE_Config__get_view', |
|
| 1445 | - EE_Config::$_module_view_map[ $key ][ $route ][ $status ], |
|
| 1446 | - $route, |
|
| 1447 | - $status |
|
| 1448 | - ); |
|
| 1449 | - } |
|
| 1450 | - return null; |
|
| 1451 | - } |
|
| 1452 | - |
|
| 1453 | - |
|
| 1454 | - public function update_addon_option_names() |
|
| 1455 | - { |
|
| 1456 | - update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names); |
|
| 1457 | - } |
|
| 1458 | - |
|
| 1459 | - |
|
| 1460 | - public function shutdown() |
|
| 1461 | - { |
|
| 1462 | - $this->update_addon_option_names(); |
|
| 1463 | - } |
|
| 1464 | - |
|
| 1465 | - |
|
| 1466 | - /** |
|
| 1467 | - * @return LegacyShortcodesManager |
|
| 1468 | - */ |
|
| 1469 | - public static function getLegacyShortcodesManager() |
|
| 1470 | - { |
|
| 1471 | - |
|
| 1472 | - if (! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) { |
|
| 1473 | - EE_Config::instance()->legacy_shortcodes_manager = new LegacyShortcodesManager( |
|
| 1474 | - EE_Registry::instance() |
|
| 1475 | - ); |
|
| 1476 | - } |
|
| 1477 | - return EE_Config::instance()->legacy_shortcodes_manager; |
|
| 1478 | - } |
|
| 1479 | - |
|
| 1480 | - |
|
| 1481 | - /** |
|
| 1482 | - * register_shortcode - makes core aware of this shortcode |
|
| 1483 | - * |
|
| 1484 | - * @deprecated 4.9.26 |
|
| 1485 | - * @param string $shortcode_path - full path up to and including shortcode folder |
|
| 1486 | - * @return bool |
|
| 1487 | - */ |
|
| 1488 | - public static function register_shortcode($shortcode_path = null) |
|
| 1489 | - { |
|
| 1490 | - EE_Error::doing_it_wrong( |
|
| 1491 | - __METHOD__, |
|
| 1492 | - __( |
|
| 1493 | - 'Usage is deprecated. Use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::registerShortcode() as direct replacement, or better yet, please see the new \EventEspresso\core\services\shortcodes\ShortcodesManager class.', |
|
| 1494 | - 'event_espresso' |
|
| 1495 | - ), |
|
| 1496 | - '4.9.26' |
|
| 1497 | - ); |
|
| 1498 | - return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path); |
|
| 1499 | - } |
|
| 1500 | -} |
|
| 1501 | - |
|
| 1502 | -/** |
|
| 1503 | - * Base class used for config classes. These classes should generally not have |
|
| 1504 | - * magic functions in use, except we'll allow them to magically set and get stuff... |
|
| 1505 | - * basically, they should just be well-defined stdClasses |
|
| 1506 | - */ |
|
| 1507 | -class EE_Config_Base |
|
| 1508 | -{ |
|
| 1509 | - |
|
| 1510 | - /** |
|
| 1511 | - * Utility function for escaping the value of a property and returning. |
|
| 1512 | - * |
|
| 1513 | - * @param string $property property name (checks to see if exists). |
|
| 1514 | - * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
| 1515 | - * @throws \EE_Error |
|
| 1516 | - */ |
|
| 1517 | - public function get_pretty($property) |
|
| 1518 | - { |
|
| 1519 | - if (! property_exists($this, $property)) { |
|
| 1520 | - throw new EE_Error( |
|
| 1521 | - sprintf( |
|
| 1522 | - __( |
|
| 1523 | - '%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.', |
|
| 1524 | - 'event_espresso' |
|
| 1525 | - ), |
|
| 1526 | - get_class($this), |
|
| 1527 | - $property |
|
| 1528 | - ) |
|
| 1529 | - ); |
|
| 1530 | - } |
|
| 1531 | - // just handling escaping of strings for now. |
|
| 1532 | - if (is_string($this->{$property})) { |
|
| 1533 | - return stripslashes($this->{$property}); |
|
| 1534 | - } |
|
| 1535 | - return $this->{$property}; |
|
| 1536 | - } |
|
| 1537 | - |
|
| 1538 | - |
|
| 1539 | - public function populate() |
|
| 1540 | - { |
|
| 1541 | - // grab defaults via a new instance of this class. |
|
| 1542 | - $class_name = get_class($this); |
|
| 1543 | - $defaults = new $class_name; |
|
| 1544 | - // loop through the properties for this class and see if they are set. If they are NOT, then grab the |
|
| 1545 | - // default from our $defaults object. |
|
| 1546 | - foreach (get_object_vars($defaults) as $property => $value) { |
|
| 1547 | - if ($this->{$property} === null) { |
|
| 1548 | - $this->{$property} = $value; |
|
| 1549 | - } |
|
| 1550 | - } |
|
| 1551 | - // cleanup |
|
| 1552 | - unset($defaults); |
|
| 1553 | - } |
|
| 1554 | - |
|
| 1555 | - |
|
| 1556 | - /** |
|
| 1557 | - * __isset |
|
| 1558 | - * |
|
| 1559 | - * @param $a |
|
| 1560 | - * @return bool |
|
| 1561 | - */ |
|
| 1562 | - public function __isset($a) |
|
| 1563 | - { |
|
| 1564 | - return false; |
|
| 1565 | - } |
|
| 1566 | - |
|
| 1567 | - |
|
| 1568 | - /** |
|
| 1569 | - * __unset |
|
| 1570 | - * |
|
| 1571 | - * @param $a |
|
| 1572 | - * @return bool |
|
| 1573 | - */ |
|
| 1574 | - public function __unset($a) |
|
| 1575 | - { |
|
| 1576 | - return false; |
|
| 1577 | - } |
|
| 1578 | - |
|
| 1579 | - |
|
| 1580 | - /** |
|
| 1581 | - * __clone |
|
| 1582 | - */ |
|
| 1583 | - public function __clone() |
|
| 1584 | - { |
|
| 1585 | - } |
|
| 1586 | - |
|
| 1587 | - |
|
| 1588 | - /** |
|
| 1589 | - * __wakeup |
|
| 1590 | - */ |
|
| 1591 | - public function __wakeup() |
|
| 1592 | - { |
|
| 1593 | - } |
|
| 1594 | - |
|
| 1595 | - |
|
| 1596 | - /** |
|
| 1597 | - * __destruct |
|
| 1598 | - */ |
|
| 1599 | - public function __destruct() |
|
| 1600 | - { |
|
| 1601 | - } |
|
| 1602 | -} |
|
| 1603 | - |
|
| 1604 | -/** |
|
| 1605 | - * Class for defining what's in the EE_Config relating to registration settings |
|
| 1606 | - */ |
|
| 1607 | -class EE_Core_Config extends EE_Config_Base |
|
| 1608 | -{ |
|
| 1609 | - |
|
| 1610 | - const OPTION_NAME_UXIP = 'ee_ueip_optin'; |
|
| 1611 | - |
|
| 1612 | - |
|
| 1613 | - public $current_blog_id; |
|
| 1614 | - |
|
| 1615 | - public $ee_ueip_optin; |
|
| 1616 | - |
|
| 1617 | - public $ee_ueip_has_notified; |
|
| 1618 | - |
|
| 1619 | - /** |
|
| 1620 | - * Not to be confused with the 4 critical page variables (See |
|
| 1621 | - * get_critical_pages_array()), this is just an array of wp posts that have EE |
|
| 1622 | - * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode |
|
| 1623 | - * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array. |
|
| 1624 | - * |
|
| 1625 | - * @var array |
|
| 1626 | - */ |
|
| 1627 | - public $post_shortcodes; |
|
| 1628 | - |
|
| 1629 | - public $module_route_map; |
|
| 1630 | - |
|
| 1631 | - public $module_forward_map; |
|
| 1632 | - |
|
| 1633 | - public $module_view_map; |
|
| 1634 | - |
|
| 1635 | - /** |
|
| 1636 | - * The next 4 vars are the IDs of critical EE pages. |
|
| 1637 | - * |
|
| 1638 | - * @var int |
|
| 1639 | - */ |
|
| 1640 | - public $reg_page_id; |
|
| 1641 | - |
|
| 1642 | - public $txn_page_id; |
|
| 1643 | - |
|
| 1644 | - public $thank_you_page_id; |
|
| 1645 | - |
|
| 1646 | - public $cancel_page_id; |
|
| 1647 | - |
|
| 1648 | - /** |
|
| 1649 | - * The next 4 vars are the URLs of critical EE pages. |
|
| 1650 | - * |
|
| 1651 | - * @var int |
|
| 1652 | - */ |
|
| 1653 | - public $reg_page_url; |
|
| 1654 | - |
|
| 1655 | - public $txn_page_url; |
|
| 1656 | - |
|
| 1657 | - public $thank_you_page_url; |
|
| 1658 | - |
|
| 1659 | - public $cancel_page_url; |
|
| 1660 | - |
|
| 1661 | - /** |
|
| 1662 | - * The next vars relate to the custom slugs for EE CPT routes |
|
| 1663 | - */ |
|
| 1664 | - public $event_cpt_slug; |
|
| 1665 | - |
|
| 1666 | - /** |
|
| 1667 | - * This caches the _ee_ueip_option in case this config is reset in the same |
|
| 1668 | - * request across blog switches in a multisite context. |
|
| 1669 | - * Avoids extra queries to the db for this option. |
|
| 1670 | - * |
|
| 1671 | - * @var bool |
|
| 1672 | - */ |
|
| 1673 | - public static $ee_ueip_option; |
|
| 1674 | - |
|
| 1675 | - |
|
| 1676 | - /** |
|
| 1677 | - * class constructor |
|
| 1678 | - * |
|
| 1679 | - * @access public |
|
| 1680 | - */ |
|
| 1681 | - public function __construct() |
|
| 1682 | - { |
|
| 1683 | - // set default organization settings |
|
| 1684 | - $this->current_blog_id = get_current_blog_id(); |
|
| 1685 | - $this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id; |
|
| 1686 | - $this->ee_ueip_optin = $this->_get_main_ee_ueip_optin(); |
|
| 1687 | - $this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true; |
|
| 1688 | - $this->post_shortcodes = array(); |
|
| 1689 | - $this->module_route_map = array(); |
|
| 1690 | - $this->module_forward_map = array(); |
|
| 1691 | - $this->module_view_map = array(); |
|
| 1692 | - // critical EE page IDs |
|
| 1693 | - $this->reg_page_id = 0; |
|
| 1694 | - $this->txn_page_id = 0; |
|
| 1695 | - $this->thank_you_page_id = 0; |
|
| 1696 | - $this->cancel_page_id = 0; |
|
| 1697 | - // critical EE page URLs |
|
| 1698 | - $this->reg_page_url = ''; |
|
| 1699 | - $this->txn_page_url = ''; |
|
| 1700 | - $this->thank_you_page_url = ''; |
|
| 1701 | - $this->cancel_page_url = ''; |
|
| 1702 | - // cpt slugs |
|
| 1703 | - $this->event_cpt_slug = __('events', 'event_espresso'); |
|
| 1704 | - // ueip constant check |
|
| 1705 | - if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) { |
|
| 1706 | - $this->ee_ueip_optin = false; |
|
| 1707 | - $this->ee_ueip_has_notified = true; |
|
| 1708 | - } |
|
| 1709 | - } |
|
| 1710 | - |
|
| 1711 | - |
|
| 1712 | - /** |
|
| 1713 | - * @return array |
|
| 1714 | - */ |
|
| 1715 | - public function get_critical_pages_array() |
|
| 1716 | - { |
|
| 1717 | - return array( |
|
| 1718 | - $this->reg_page_id, |
|
| 1719 | - $this->txn_page_id, |
|
| 1720 | - $this->thank_you_page_id, |
|
| 1721 | - $this->cancel_page_id, |
|
| 1722 | - ); |
|
| 1723 | - } |
|
| 1724 | - |
|
| 1725 | - |
|
| 1726 | - /** |
|
| 1727 | - * @return array |
|
| 1728 | - */ |
|
| 1729 | - public function get_critical_pages_shortcodes_array() |
|
| 1730 | - { |
|
| 1731 | - return array( |
|
| 1732 | - $this->reg_page_id => 'ESPRESSO_CHECKOUT', |
|
| 1733 | - $this->txn_page_id => 'ESPRESSO_TXN_PAGE', |
|
| 1734 | - $this->thank_you_page_id => 'ESPRESSO_THANK_YOU', |
|
| 1735 | - $this->cancel_page_id => 'ESPRESSO_CANCELLED', |
|
| 1736 | - ); |
|
| 1737 | - } |
|
| 1738 | - |
|
| 1739 | - |
|
| 1740 | - /** |
|
| 1741 | - * gets/returns URL for EE reg_page |
|
| 1742 | - * |
|
| 1743 | - * @access public |
|
| 1744 | - * @return string |
|
| 1745 | - */ |
|
| 1746 | - public function reg_page_url() |
|
| 1747 | - { |
|
| 1748 | - if (! $this->reg_page_url) { |
|
| 1749 | - $this->reg_page_url = add_query_arg( |
|
| 1750 | - array('uts' => time()), |
|
| 1751 | - get_permalink($this->reg_page_id) |
|
| 1752 | - ) . '#checkout'; |
|
| 1753 | - } |
|
| 1754 | - return $this->reg_page_url; |
|
| 1755 | - } |
|
| 1756 | - |
|
| 1757 | - |
|
| 1758 | - /** |
|
| 1759 | - * gets/returns URL for EE txn_page |
|
| 1760 | - * |
|
| 1761 | - * @param array $query_args like what gets passed to |
|
| 1762 | - * add_query_arg() as the first argument |
|
| 1763 | - * @access public |
|
| 1764 | - * @return string |
|
| 1765 | - */ |
|
| 1766 | - public function txn_page_url($query_args = array()) |
|
| 1767 | - { |
|
| 1768 | - if (! $this->txn_page_url) { |
|
| 1769 | - $this->txn_page_url = get_permalink($this->txn_page_id); |
|
| 1770 | - } |
|
| 1771 | - if ($query_args) { |
|
| 1772 | - return add_query_arg($query_args, $this->txn_page_url); |
|
| 1773 | - } else { |
|
| 1774 | - return $this->txn_page_url; |
|
| 1775 | - } |
|
| 1776 | - } |
|
| 1777 | - |
|
| 1778 | - |
|
| 1779 | - /** |
|
| 1780 | - * gets/returns URL for EE thank_you_page |
|
| 1781 | - * |
|
| 1782 | - * @param array $query_args like what gets passed to |
|
| 1783 | - * add_query_arg() as the first argument |
|
| 1784 | - * @access public |
|
| 1785 | - * @return string |
|
| 1786 | - */ |
|
| 1787 | - public function thank_you_page_url($query_args = array()) |
|
| 1788 | - { |
|
| 1789 | - if (! $this->thank_you_page_url) { |
|
| 1790 | - $this->thank_you_page_url = get_permalink($this->thank_you_page_id); |
|
| 1791 | - } |
|
| 1792 | - if ($query_args) { |
|
| 1793 | - return add_query_arg($query_args, $this->thank_you_page_url); |
|
| 1794 | - } else { |
|
| 1795 | - return $this->thank_you_page_url; |
|
| 1796 | - } |
|
| 1797 | - } |
|
| 1798 | - |
|
| 1799 | - |
|
| 1800 | - /** |
|
| 1801 | - * gets/returns URL for EE cancel_page |
|
| 1802 | - * |
|
| 1803 | - * @access public |
|
| 1804 | - * @return string |
|
| 1805 | - */ |
|
| 1806 | - public function cancel_page_url() |
|
| 1807 | - { |
|
| 1808 | - if (! $this->cancel_page_url) { |
|
| 1809 | - $this->cancel_page_url = get_permalink($this->cancel_page_id); |
|
| 1810 | - } |
|
| 1811 | - return $this->cancel_page_url; |
|
| 1812 | - } |
|
| 1813 | - |
|
| 1814 | - |
|
| 1815 | - /** |
|
| 1816 | - * Resets all critical page urls to their original state. Used primarily by the __sleep() magic method currently. |
|
| 1817 | - * |
|
| 1818 | - * @since 4.7.5 |
|
| 1819 | - */ |
|
| 1820 | - protected function _reset_urls() |
|
| 1821 | - { |
|
| 1822 | - $this->reg_page_url = ''; |
|
| 1823 | - $this->txn_page_url = ''; |
|
| 1824 | - $this->cancel_page_url = ''; |
|
| 1825 | - $this->thank_you_page_url = ''; |
|
| 1826 | - } |
|
| 1827 | - |
|
| 1828 | - |
|
| 1829 | - /** |
|
| 1830 | - * Used to return what the optin value is set for the EE User Experience Program. |
|
| 1831 | - * This accounts for multisite and this value being requested for a subsite. In multisite, the value is set |
|
| 1832 | - * on the main site only. |
|
| 1833 | - * |
|
| 1834 | - * @return bool |
|
| 1835 | - */ |
|
| 1836 | - protected function _get_main_ee_ueip_optin() |
|
| 1837 | - { |
|
| 1838 | - // if this is the main site then we can just bypass our direct query. |
|
| 1839 | - if (is_main_site()) { |
|
| 1840 | - return get_option(self::OPTION_NAME_UXIP, false); |
|
| 1841 | - } |
|
| 1842 | - // is this already cached for this request? If so use it. |
|
| 1843 | - if (EE_Core_Config::$ee_ueip_option !== null) { |
|
| 1844 | - return EE_Core_Config::$ee_ueip_option; |
|
| 1845 | - } |
|
| 1846 | - global $wpdb; |
|
| 1847 | - $current_network_main_site = is_multisite() ? get_current_site() : null; |
|
| 1848 | - $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1; |
|
| 1849 | - $option = self::OPTION_NAME_UXIP; |
|
| 1850 | - // set correct table for query |
|
| 1851 | - $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options'; |
|
| 1852 | - // rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because |
|
| 1853 | - // get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be |
|
| 1854 | - // re-constructed on the blog switch. Note, we are still executing any core wp filters on this option retrieval. |
|
| 1855 | - // this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog |
|
| 1856 | - // for the purpose of caching. |
|
| 1857 | - $pre = apply_filters('pre_option_' . $option, false, $option); |
|
| 1858 | - if (false !== $pre) { |
|
| 1859 | - EE_Core_Config::$ee_ueip_option = $pre; |
|
| 1860 | - return EE_Core_Config::$ee_ueip_option; |
|
| 1861 | - } |
|
| 1862 | - $row = $wpdb->get_row( |
|
| 1863 | - $wpdb->prepare( |
|
| 1864 | - "SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1", |
|
| 1865 | - $option |
|
| 1866 | - ) |
|
| 1867 | - ); |
|
| 1868 | - if (is_object($row)) { |
|
| 1869 | - $value = $row->option_value; |
|
| 1870 | - } else { // option does not exist so use default. |
|
| 1871 | - EE_Core_Config::$ee_ueip_option = apply_filters('default_option_' . $option, false, $option); |
|
| 1872 | - return EE_Core_Config::$ee_ueip_option; |
|
| 1873 | - } |
|
| 1874 | - EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option); |
|
| 1875 | - return EE_Core_Config::$ee_ueip_option; |
|
| 1876 | - } |
|
| 1877 | - |
|
| 1878 | - |
|
| 1879 | - /** |
|
| 1880 | - * Utility function for escaping the value of a property and returning. |
|
| 1881 | - * |
|
| 1882 | - * @param string $property property name (checks to see if exists). |
|
| 1883 | - * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
| 1884 | - * @throws \EE_Error |
|
| 1885 | - */ |
|
| 1886 | - public function get_pretty($property) |
|
| 1887 | - { |
|
| 1888 | - if ($property === self::OPTION_NAME_UXIP) { |
|
| 1889 | - return $this->ee_ueip_optin ? 'yes' : 'no'; |
|
| 1890 | - } |
|
| 1891 | - return parent::get_pretty($property); |
|
| 1892 | - } |
|
| 1893 | - |
|
| 1894 | - |
|
| 1895 | - /** |
|
| 1896 | - * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values |
|
| 1897 | - * on the object. |
|
| 1898 | - * |
|
| 1899 | - * @return array |
|
| 1900 | - */ |
|
| 1901 | - public function __sleep() |
|
| 1902 | - { |
|
| 1903 | - // reset all url properties |
|
| 1904 | - $this->_reset_urls(); |
|
| 1905 | - // return what to save to db |
|
| 1906 | - return array_keys(get_object_vars($this)); |
|
| 1907 | - } |
|
| 1908 | -} |
|
| 1909 | - |
|
| 1910 | -/** |
|
| 1911 | - * Config class for storing info on the Organization |
|
| 1912 | - */ |
|
| 1913 | -class EE_Organization_Config extends EE_Config_Base |
|
| 1914 | -{ |
|
| 1915 | - |
|
| 1916 | - /** |
|
| 1917 | - * @var string $name |
|
| 1918 | - * eg EE4.1 |
|
| 1919 | - */ |
|
| 1920 | - public $name; |
|
| 1921 | - |
|
| 1922 | - /** |
|
| 1923 | - * @var string $address_1 |
|
| 1924 | - * eg 123 Onna Road |
|
| 1925 | - */ |
|
| 1926 | - public $address_1 = ''; |
|
| 1927 | - |
|
| 1928 | - /** |
|
| 1929 | - * @var string $address_2 |
|
| 1930 | - * eg PO Box 123 |
|
| 1931 | - */ |
|
| 1932 | - public $address_2 = ''; |
|
| 1933 | - |
|
| 1934 | - /** |
|
| 1935 | - * @var string $city |
|
| 1936 | - * eg Inna City |
|
| 1937 | - */ |
|
| 1938 | - public $city = ''; |
|
| 1939 | - |
|
| 1940 | - /** |
|
| 1941 | - * @var int $STA_ID |
|
| 1942 | - * eg 4 |
|
| 1943 | - */ |
|
| 1944 | - public $STA_ID = 0; |
|
| 1945 | - |
|
| 1946 | - /** |
|
| 1947 | - * @var string $CNT_ISO |
|
| 1948 | - * eg US |
|
| 1949 | - */ |
|
| 1950 | - public $CNT_ISO = ''; |
|
| 1951 | - |
|
| 1952 | - /** |
|
| 1953 | - * @var string $zip |
|
| 1954 | - * eg 12345 or V1A 2B3 |
|
| 1955 | - */ |
|
| 1956 | - public $zip = ''; |
|
| 1957 | - |
|
| 1958 | - /** |
|
| 1959 | - * @var string $email |
|
| 1960 | - * eg [email protected] |
|
| 1961 | - */ |
|
| 1962 | - public $email; |
|
| 1963 | - |
|
| 1964 | - /** |
|
| 1965 | - * @var string $phone |
|
| 1966 | - * eg. 111-111-1111 |
|
| 1967 | - */ |
|
| 1968 | - public $phone = ''; |
|
| 1969 | - |
|
| 1970 | - /** |
|
| 1971 | - * @var string $vat |
|
| 1972 | - * VAT/Tax Number |
|
| 1973 | - */ |
|
| 1974 | - public $vat = ''; |
|
| 1975 | - |
|
| 1976 | - /** |
|
| 1977 | - * @var string $logo_url |
|
| 1978 | - * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg |
|
| 1979 | - */ |
|
| 1980 | - public $logo_url = ''; |
|
| 1981 | - |
|
| 1982 | - /** |
|
| 1983 | - * The below are all various properties for holding links to organization social network profiles |
|
| 1984 | - * |
|
| 1985 | - * @var string |
|
| 1986 | - */ |
|
| 1987 | - /** |
|
| 1988 | - * facebook (facebook.com/profile.name) |
|
| 1989 | - * |
|
| 1990 | - * @var string |
|
| 1991 | - */ |
|
| 1992 | - public $facebook = ''; |
|
| 1993 | - |
|
| 1994 | - /** |
|
| 1995 | - * twitter (twitter.com/twitter_handle) |
|
| 1996 | - * |
|
| 1997 | - * @var string |
|
| 1998 | - */ |
|
| 1999 | - public $twitter = ''; |
|
| 2000 | - |
|
| 2001 | - /** |
|
| 2002 | - * linkedin (linkedin.com/in/profile_name) |
|
| 2003 | - * |
|
| 2004 | - * @var string |
|
| 2005 | - */ |
|
| 2006 | - public $linkedin = ''; |
|
| 2007 | - |
|
| 2008 | - /** |
|
| 2009 | - * pinterest (www.pinterest.com/profile_name) |
|
| 2010 | - * |
|
| 2011 | - * @var string |
|
| 2012 | - */ |
|
| 2013 | - public $pinterest = ''; |
|
| 2014 | - |
|
| 2015 | - /** |
|
| 2016 | - * google+ (google.com/+profileName) |
|
| 2017 | - * |
|
| 2018 | - * @var string |
|
| 2019 | - */ |
|
| 2020 | - public $google = ''; |
|
| 2021 | - |
|
| 2022 | - /** |
|
| 2023 | - * instagram (instagram.com/handle) |
|
| 2024 | - * |
|
| 2025 | - * @var string |
|
| 2026 | - */ |
|
| 2027 | - public $instagram = ''; |
|
| 2028 | - |
|
| 2029 | - |
|
| 2030 | - /** |
|
| 2031 | - * class constructor |
|
| 2032 | - * |
|
| 2033 | - * @access public |
|
| 2034 | - */ |
|
| 2035 | - public function __construct() |
|
| 2036 | - { |
|
| 2037 | - // set default organization settings |
|
| 2038 | - // decode HTML entities from the WP blogname, because it's stored in the DB with HTML entities encoded |
|
| 2039 | - $this->name = wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES); |
|
| 2040 | - $this->email = get_bloginfo('admin_email'); |
|
| 2041 | - } |
|
| 2042 | -} |
|
| 2043 | - |
|
| 2044 | -/** |
|
| 2045 | - * Class for defining what's in the EE_Config relating to currency |
|
| 2046 | - */ |
|
| 2047 | -class EE_Currency_Config extends EE_Config_Base |
|
| 2048 | -{ |
|
| 2049 | - |
|
| 2050 | - /** |
|
| 2051 | - * @var string $code |
|
| 2052 | - * eg 'US' |
|
| 2053 | - */ |
|
| 2054 | - public $code; |
|
| 2055 | - |
|
| 2056 | - /** |
|
| 2057 | - * @var string $name |
|
| 2058 | - * eg 'Dollar' |
|
| 2059 | - */ |
|
| 2060 | - public $name; |
|
| 2061 | - |
|
| 2062 | - /** |
|
| 2063 | - * plural name |
|
| 2064 | - * |
|
| 2065 | - * @var string $plural |
|
| 2066 | - * eg 'Dollars' |
|
| 2067 | - */ |
|
| 2068 | - public $plural; |
|
| 2069 | - |
|
| 2070 | - /** |
|
| 2071 | - * currency sign |
|
| 2072 | - * |
|
| 2073 | - * @var string $sign |
|
| 2074 | - * eg '$' |
|
| 2075 | - */ |
|
| 2076 | - public $sign; |
|
| 2077 | - |
|
| 2078 | - /** |
|
| 2079 | - * Whether the currency sign should come before the number or not |
|
| 2080 | - * |
|
| 2081 | - * @var boolean $sign_b4 |
|
| 2082 | - */ |
|
| 2083 | - public $sign_b4; |
|
| 2084 | - |
|
| 2085 | - /** |
|
| 2086 | - * How many digits should come after the decimal place |
|
| 2087 | - * |
|
| 2088 | - * @var int $dec_plc |
|
| 2089 | - */ |
|
| 2090 | - public $dec_plc; |
|
| 2091 | - |
|
| 2092 | - /** |
|
| 2093 | - * Symbol to use for decimal mark |
|
| 2094 | - * |
|
| 2095 | - * @var string $dec_mrk |
|
| 2096 | - * eg '.' |
|
| 2097 | - */ |
|
| 2098 | - public $dec_mrk; |
|
| 2099 | - |
|
| 2100 | - /** |
|
| 2101 | - * Symbol to use for thousands |
|
| 2102 | - * |
|
| 2103 | - * @var string $thsnds |
|
| 2104 | - * eg ',' |
|
| 2105 | - */ |
|
| 2106 | - public $thsnds; |
|
| 2107 | - |
|
| 2108 | - |
|
| 2109 | - /** |
|
| 2110 | - * class constructor |
|
| 2111 | - * |
|
| 2112 | - * @access public |
|
| 2113 | - * @param string $CNT_ISO |
|
| 2114 | - * @throws \EE_Error |
|
| 2115 | - */ |
|
| 2116 | - public function __construct($CNT_ISO = '') |
|
| 2117 | - { |
|
| 2118 | - /** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */ |
|
| 2119 | - $table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
| 2120 | - // get country code from organization settings or use default |
|
| 2121 | - $ORG_CNT = isset(EE_Registry::instance()->CFG->organization) |
|
| 2122 | - && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config |
|
| 2123 | - ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
| 2124 | - : ''; |
|
| 2125 | - // but override if requested |
|
| 2126 | - $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT; |
|
| 2127 | - // so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists |
|
| 2128 | - if (! empty($CNT_ISO) |
|
| 2129 | - && EE_Maintenance_Mode::instance()->models_can_query() |
|
| 2130 | - && $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table()) |
|
| 2131 | - ) { |
|
| 2132 | - // retrieve the country settings from the db, just in case they have been customized |
|
| 2133 | - $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO); |
|
| 2134 | - if ($country instanceof EE_Country) { |
|
| 2135 | - $this->code = $country->currency_code(); // currency code: USD, CAD, EUR |
|
| 2136 | - $this->name = $country->currency_name_single(); // Dollar |
|
| 2137 | - $this->plural = $country->currency_name_plural(); // Dollars |
|
| 2138 | - $this->sign = $country->currency_sign(); // currency sign: $ |
|
| 2139 | - $this->sign_b4 = $country->currency_sign_before( |
|
| 2140 | - ); // currency sign before or after: $TRUE or FALSE$ |
|
| 2141 | - $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2142 | - $this->dec_mrk = $country->currency_decimal_mark( |
|
| 2143 | - ); // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2144 | - $this->thsnds = $country->currency_thousands_separator( |
|
| 2145 | - ); // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2146 | - } |
|
| 2147 | - } |
|
| 2148 | - // fallback to hardcoded defaults, in case the above failed |
|
| 2149 | - if (empty($this->code)) { |
|
| 2150 | - // set default currency settings |
|
| 2151 | - $this->code = 'USD'; // currency code: USD, CAD, EUR |
|
| 2152 | - $this->name = __('Dollar', 'event_espresso'); // Dollar |
|
| 2153 | - $this->plural = __('Dollars', 'event_espresso'); // Dollars |
|
| 2154 | - $this->sign = '$'; // currency sign: $ |
|
| 2155 | - $this->sign_b4 = true; // currency sign before or after: $TRUE or FALSE$ |
|
| 2156 | - $this->dec_plc = 2; // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2157 | - $this->dec_mrk = '.'; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2158 | - $this->thsnds = ','; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2159 | - } |
|
| 2160 | - } |
|
| 2161 | -} |
|
| 2162 | - |
|
| 2163 | -/** |
|
| 2164 | - * Class for defining what's in the EE_Config relating to registration settings |
|
| 2165 | - */ |
|
| 2166 | -class EE_Registration_Config extends EE_Config_Base |
|
| 2167 | -{ |
|
| 2168 | - |
|
| 2169 | - /** |
|
| 2170 | - * Default registration status |
|
| 2171 | - * |
|
| 2172 | - * @var string $default_STS_ID |
|
| 2173 | - * eg 'RPP' |
|
| 2174 | - */ |
|
| 2175 | - public $default_STS_ID; |
|
| 2176 | - |
|
| 2177 | - /** |
|
| 2178 | - * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of |
|
| 2179 | - * registrations) |
|
| 2180 | - * |
|
| 2181 | - * @var int |
|
| 2182 | - */ |
|
| 2183 | - public $default_maximum_number_of_tickets; |
|
| 2184 | - |
|
| 2185 | - /** |
|
| 2186 | - * level of validation to apply to email addresses |
|
| 2187 | - * |
|
| 2188 | - * @var string $email_validation_level |
|
| 2189 | - * options: 'basic', 'wp_default', 'i18n', 'i18n_dns' |
|
| 2190 | - */ |
|
| 2191 | - public $email_validation_level; |
|
| 2192 | - |
|
| 2193 | - /** |
|
| 2194 | - * whether or not to show alternate payment options during the reg process if payment status is pending |
|
| 2195 | - * |
|
| 2196 | - * @var boolean $show_pending_payment_options |
|
| 2197 | - */ |
|
| 2198 | - public $show_pending_payment_options; |
|
| 2199 | - |
|
| 2200 | - /** |
|
| 2201 | - * Whether to skip the registration confirmation page |
|
| 2202 | - * |
|
| 2203 | - * @var boolean $skip_reg_confirmation |
|
| 2204 | - */ |
|
| 2205 | - public $skip_reg_confirmation; |
|
| 2206 | - |
|
| 2207 | - /** |
|
| 2208 | - * an array of SPCO reg steps where: |
|
| 2209 | - * the keys denotes the reg step order |
|
| 2210 | - * each element consists of an array with the following elements: |
|
| 2211 | - * "file_path" => the file path to the EE_SPCO_Reg_Step class |
|
| 2212 | - * "class_name" => the specific EE_SPCO_Reg_Step child class name |
|
| 2213 | - * "slug" => the URL param used to trigger the reg step |
|
| 2214 | - * |
|
| 2215 | - * @var array $reg_steps |
|
| 2216 | - */ |
|
| 2217 | - public $reg_steps; |
|
| 2218 | - |
|
| 2219 | - /** |
|
| 2220 | - * Whether registration confirmation should be the last page of SPCO |
|
| 2221 | - * |
|
| 2222 | - * @var boolean $reg_confirmation_last |
|
| 2223 | - */ |
|
| 2224 | - public $reg_confirmation_last; |
|
| 2225 | - |
|
| 2226 | - /** |
|
| 2227 | - * Whether or not to enable the EE Bot Trap |
|
| 2228 | - * |
|
| 2229 | - * @var boolean $use_bot_trap |
|
| 2230 | - */ |
|
| 2231 | - public $use_bot_trap; |
|
| 2232 | - |
|
| 2233 | - /** |
|
| 2234 | - * Whether or not to encrypt some data sent by the EE Bot Trap |
|
| 2235 | - * |
|
| 2236 | - * @var boolean $use_encryption |
|
| 2237 | - */ |
|
| 2238 | - public $use_encryption; |
|
| 2239 | - |
|
| 2240 | - /** |
|
| 2241 | - * Whether or not to use ReCaptcha |
|
| 2242 | - * |
|
| 2243 | - * @var boolean $use_captcha |
|
| 2244 | - */ |
|
| 2245 | - public $use_captcha; |
|
| 2246 | - |
|
| 2247 | - /** |
|
| 2248 | - * ReCaptcha Theme |
|
| 2249 | - * |
|
| 2250 | - * @var string $recaptcha_theme |
|
| 2251 | - * options: 'dark', 'light', 'invisible' |
|
| 2252 | - */ |
|
| 2253 | - public $recaptcha_theme; |
|
| 2254 | - |
|
| 2255 | - /** |
|
| 2256 | - * ReCaptcha Badge - determines the position of the reCAPTCHA badge if using Invisible ReCaptcha. |
|
| 2257 | - * |
|
| 2258 | - * @var string $recaptcha_badge |
|
| 2259 | - * options: 'bottomright', 'bottomleft', 'inline' |
|
| 2260 | - */ |
|
| 2261 | - public $recaptcha_badge; |
|
| 17 | + const OPTION_NAME = 'ee_config'; |
|
| 18 | + |
|
| 19 | + const LOG_NAME = 'ee_config_log'; |
|
| 20 | + |
|
| 21 | + const LOG_LENGTH = 100; |
|
| 22 | + |
|
| 23 | + const ADDON_OPTION_NAMES = 'ee_config_option_names'; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * instance of the EE_Config object |
|
| 27 | + * |
|
| 28 | + * @var EE_Config $_instance |
|
| 29 | + * @access private |
|
| 30 | + */ |
|
| 31 | + private static $_instance; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @var boolean $_logging_enabled |
|
| 35 | + */ |
|
| 36 | + private static $_logging_enabled = false; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * @var LegacyShortcodesManager $legacy_shortcodes_manager |
|
| 40 | + */ |
|
| 41 | + private $legacy_shortcodes_manager; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * An StdClass whose property names are addon slugs, |
|
| 45 | + * and values are their config classes |
|
| 46 | + * |
|
| 47 | + * @var StdClass |
|
| 48 | + */ |
|
| 49 | + public $addons; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * @var EE_Admin_Config |
|
| 53 | + */ |
|
| 54 | + public $admin; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @var EE_Core_Config |
|
| 58 | + */ |
|
| 59 | + public $core; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @var EE_Currency_Config |
|
| 63 | + */ |
|
| 64 | + public $currency; |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @var EE_Organization_Config |
|
| 68 | + */ |
|
| 69 | + public $organization; |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @var EE_Registration_Config |
|
| 73 | + */ |
|
| 74 | + public $registration; |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * @var EE_Template_Config |
|
| 78 | + */ |
|
| 79 | + public $template_settings; |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Holds EE environment values. |
|
| 83 | + * |
|
| 84 | + * @var EE_Environment_Config |
|
| 85 | + */ |
|
| 86 | + public $environment; |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * settings pertaining to Google maps |
|
| 90 | + * |
|
| 91 | + * @var EE_Map_Config |
|
| 92 | + */ |
|
| 93 | + public $map_settings; |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * settings pertaining to Taxes |
|
| 97 | + * |
|
| 98 | + * @var EE_Tax_Config |
|
| 99 | + */ |
|
| 100 | + public $tax_settings; |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Settings pertaining to global messages settings. |
|
| 104 | + * |
|
| 105 | + * @var EE_Messages_Config |
|
| 106 | + */ |
|
| 107 | + public $messages; |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @deprecated |
|
| 111 | + * @var EE_Gateway_Config |
|
| 112 | + */ |
|
| 113 | + public $gateway; |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * @var array $_addon_option_names |
|
| 117 | + * @access private |
|
| 118 | + */ |
|
| 119 | + private $_addon_option_names = array(); |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * @var array $_module_route_map |
|
| 123 | + * @access private |
|
| 124 | + */ |
|
| 125 | + private static $_module_route_map = array(); |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * @var array $_module_forward_map |
|
| 129 | + * @access private |
|
| 130 | + */ |
|
| 131 | + private static $_module_forward_map = array(); |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * @var array $_module_view_map |
|
| 135 | + * @access private |
|
| 136 | + */ |
|
| 137 | + private static $_module_view_map = array(); |
|
| 138 | + |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * @singleton method used to instantiate class object |
|
| 142 | + * @access public |
|
| 143 | + * @return EE_Config instance |
|
| 144 | + */ |
|
| 145 | + public static function instance() |
|
| 146 | + { |
|
| 147 | + // check if class object is instantiated, and instantiated properly |
|
| 148 | + if (! self::$_instance instanceof EE_Config) { |
|
| 149 | + self::$_instance = new self(); |
|
| 150 | + } |
|
| 151 | + return self::$_instance; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * Resets the config |
|
| 157 | + * |
|
| 158 | + * @param bool $hard_reset if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE |
|
| 159 | + * (default) leaves the database alone, and merely resets the EE_Config object to |
|
| 160 | + * reflect its state in the database |
|
| 161 | + * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave |
|
| 162 | + * $_instance as NULL. Useful in case you want to forget about the old instance on |
|
| 163 | + * EE_Config, but might not be ready to instantiate EE_Config currently (eg if the |
|
| 164 | + * site was put into maintenance mode) |
|
| 165 | + * @return EE_Config |
|
| 166 | + */ |
|
| 167 | + public static function reset($hard_reset = false, $reinstantiate = true) |
|
| 168 | + { |
|
| 169 | + if (self::$_instance instanceof EE_Config) { |
|
| 170 | + if ($hard_reset) { |
|
| 171 | + self::$_instance->legacy_shortcodes_manager = null; |
|
| 172 | + self::$_instance->_addon_option_names = array(); |
|
| 173 | + self::$_instance->_initialize_config(); |
|
| 174 | + self::$_instance->update_espresso_config(); |
|
| 175 | + } |
|
| 176 | + self::$_instance->update_addon_option_names(); |
|
| 177 | + } |
|
| 178 | + self::$_instance = null; |
|
| 179 | + // we don't need to reset the static properties imo because those should |
|
| 180 | + // only change when a module is added or removed. Currently we don't |
|
| 181 | + // support removing a module during a request when it previously existed |
|
| 182 | + if ($reinstantiate) { |
|
| 183 | + return self::instance(); |
|
| 184 | + } else { |
|
| 185 | + return null; |
|
| 186 | + } |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + |
|
| 190 | + /** |
|
| 191 | + * class constructor |
|
| 192 | + * |
|
| 193 | + * @access private |
|
| 194 | + */ |
|
| 195 | + private function __construct() |
|
| 196 | + { |
|
| 197 | + do_action('AHEE__EE_Config__construct__begin', $this); |
|
| 198 | + EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false); |
|
| 199 | + // setup empty config classes |
|
| 200 | + $this->_initialize_config(); |
|
| 201 | + // load existing EE site settings |
|
| 202 | + $this->_load_core_config(); |
|
| 203 | + // confirm everything loaded correctly and set filtered defaults if not |
|
| 204 | + $this->_verify_config(); |
|
| 205 | + // register shortcodes and modules |
|
| 206 | + add_action( |
|
| 207 | + 'AHEE__EE_System__register_shortcodes_modules_and_widgets', |
|
| 208 | + array($this, 'register_shortcodes_and_modules'), |
|
| 209 | + 999 |
|
| 210 | + ); |
|
| 211 | + // initialize shortcodes and modules |
|
| 212 | + add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules')); |
|
| 213 | + // register widgets |
|
| 214 | + add_action('widgets_init', array($this, 'widgets_init'), 10); |
|
| 215 | + // shutdown |
|
| 216 | + add_action('shutdown', array($this, 'shutdown'), 10); |
|
| 217 | + // construct__end hook |
|
| 218 | + do_action('AHEE__EE_Config__construct__end', $this); |
|
| 219 | + // hardcoded hack |
|
| 220 | + $this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + |
|
| 224 | + /** |
|
| 225 | + * @return boolean |
|
| 226 | + */ |
|
| 227 | + public static function logging_enabled() |
|
| 228 | + { |
|
| 229 | + return self::$_logging_enabled; |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * use to get the current theme if needed from static context |
|
| 235 | + * |
|
| 236 | + * @return string current theme set. |
|
| 237 | + */ |
|
| 238 | + public static function get_current_theme() |
|
| 239 | + { |
|
| 240 | + return isset(self::$_instance->template_settings->current_espresso_theme) |
|
| 241 | + ? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014'; |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + |
|
| 245 | + /** |
|
| 246 | + * _initialize_config |
|
| 247 | + * |
|
| 248 | + * @access private |
|
| 249 | + * @return void |
|
| 250 | + */ |
|
| 251 | + private function _initialize_config() |
|
| 252 | + { |
|
| 253 | + EE_Config::trim_log(); |
|
| 254 | + // set defaults |
|
| 255 | + $this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array()); |
|
| 256 | + $this->addons = new stdClass(); |
|
| 257 | + // set _module_route_map |
|
| 258 | + EE_Config::$_module_route_map = array(); |
|
| 259 | + // set _module_forward_map |
|
| 260 | + EE_Config::$_module_forward_map = array(); |
|
| 261 | + // set _module_view_map |
|
| 262 | + EE_Config::$_module_view_map = array(); |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * load core plugin configuration |
|
| 268 | + * |
|
| 269 | + * @access private |
|
| 270 | + * @return void |
|
| 271 | + */ |
|
| 272 | + private function _load_core_config() |
|
| 273 | + { |
|
| 274 | + // load_core_config__start hook |
|
| 275 | + do_action('AHEE__EE_Config___load_core_config__start', $this); |
|
| 276 | + $espresso_config = $this->get_espresso_config(); |
|
| 277 | + foreach ($espresso_config as $config => $settings) { |
|
| 278 | + // load_core_config__start hook |
|
| 279 | + $settings = apply_filters( |
|
| 280 | + 'FHEE__EE_Config___load_core_config__config_settings', |
|
| 281 | + $settings, |
|
| 282 | + $config, |
|
| 283 | + $this |
|
| 284 | + ); |
|
| 285 | + if (is_object($settings) && property_exists($this, $config)) { |
|
| 286 | + $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings); |
|
| 287 | + // call configs populate method to ensure any defaults are set for empty values. |
|
| 288 | + if (method_exists($settings, 'populate')) { |
|
| 289 | + $this->{$config}->populate(); |
|
| 290 | + } |
|
| 291 | + if (method_exists($settings, 'do_hooks')) { |
|
| 292 | + $this->{$config}->do_hooks(); |
|
| 293 | + } |
|
| 294 | + } |
|
| 295 | + } |
|
| 296 | + if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) { |
|
| 297 | + $this->update_espresso_config(); |
|
| 298 | + } |
|
| 299 | + // load_core_config__end hook |
|
| 300 | + do_action('AHEE__EE_Config___load_core_config__end', $this); |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * _verify_config |
|
| 306 | + * |
|
| 307 | + * @access protected |
|
| 308 | + * @return void |
|
| 309 | + */ |
|
| 310 | + protected function _verify_config() |
|
| 311 | + { |
|
| 312 | + $this->core = $this->core instanceof EE_Core_Config |
|
| 313 | + ? $this->core |
|
| 314 | + : new EE_Core_Config(); |
|
| 315 | + $this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core); |
|
| 316 | + $this->organization = $this->organization instanceof EE_Organization_Config |
|
| 317 | + ? $this->organization |
|
| 318 | + : new EE_Organization_Config(); |
|
| 319 | + $this->organization = apply_filters( |
|
| 320 | + 'FHEE__EE_Config___initialize_config__organization', |
|
| 321 | + $this->organization |
|
| 322 | + ); |
|
| 323 | + $this->currency = $this->currency instanceof EE_Currency_Config |
|
| 324 | + ? $this->currency |
|
| 325 | + : new EE_Currency_Config(); |
|
| 326 | + $this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency); |
|
| 327 | + $this->registration = $this->registration instanceof EE_Registration_Config |
|
| 328 | + ? $this->registration |
|
| 329 | + : new EE_Registration_Config(); |
|
| 330 | + $this->registration = apply_filters( |
|
| 331 | + 'FHEE__EE_Config___initialize_config__registration', |
|
| 332 | + $this->registration |
|
| 333 | + ); |
|
| 334 | + $this->admin = $this->admin instanceof EE_Admin_Config |
|
| 335 | + ? $this->admin |
|
| 336 | + : new EE_Admin_Config(); |
|
| 337 | + $this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin); |
|
| 338 | + $this->template_settings = $this->template_settings instanceof EE_Template_Config |
|
| 339 | + ? $this->template_settings |
|
| 340 | + : new EE_Template_Config(); |
|
| 341 | + $this->template_settings = apply_filters( |
|
| 342 | + 'FHEE__EE_Config___initialize_config__template_settings', |
|
| 343 | + $this->template_settings |
|
| 344 | + ); |
|
| 345 | + $this->map_settings = $this->map_settings instanceof EE_Map_Config |
|
| 346 | + ? $this->map_settings |
|
| 347 | + : new EE_Map_Config(); |
|
| 348 | + $this->map_settings = apply_filters( |
|
| 349 | + 'FHEE__EE_Config___initialize_config__map_settings', |
|
| 350 | + $this->map_settings |
|
| 351 | + ); |
|
| 352 | + $this->environment = $this->environment instanceof EE_Environment_Config |
|
| 353 | + ? $this->environment |
|
| 354 | + : new EE_Environment_Config(); |
|
| 355 | + $this->environment = apply_filters( |
|
| 356 | + 'FHEE__EE_Config___initialize_config__environment', |
|
| 357 | + $this->environment |
|
| 358 | + ); |
|
| 359 | + $this->tax_settings = $this->tax_settings instanceof EE_Tax_Config |
|
| 360 | + ? $this->tax_settings |
|
| 361 | + : new EE_Tax_Config(); |
|
| 362 | + $this->tax_settings = apply_filters( |
|
| 363 | + 'FHEE__EE_Config___initialize_config__tax_settings', |
|
| 364 | + $this->tax_settings |
|
| 365 | + ); |
|
| 366 | + $this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages); |
|
| 367 | + $this->messages = $this->messages instanceof EE_Messages_Config |
|
| 368 | + ? $this->messages |
|
| 369 | + : new EE_Messages_Config(); |
|
| 370 | + $this->gateway = $this->gateway instanceof EE_Gateway_Config |
|
| 371 | + ? $this->gateway |
|
| 372 | + : new EE_Gateway_Config(); |
|
| 373 | + $this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway); |
|
| 374 | + $this->legacy_shortcodes_manager = null; |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + |
|
| 378 | + /** |
|
| 379 | + * get_espresso_config |
|
| 380 | + * |
|
| 381 | + * @access public |
|
| 382 | + * @return array of espresso config stuff |
|
| 383 | + */ |
|
| 384 | + public function get_espresso_config() |
|
| 385 | + { |
|
| 386 | + // grab espresso configuration |
|
| 387 | + return apply_filters( |
|
| 388 | + 'FHEE__EE_Config__get_espresso_config__CFG', |
|
| 389 | + get_option(EE_Config::OPTION_NAME, array()) |
|
| 390 | + ); |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + |
|
| 394 | + /** |
|
| 395 | + * double_check_config_comparison |
|
| 396 | + * |
|
| 397 | + * @access public |
|
| 398 | + * @param string $option |
|
| 399 | + * @param $old_value |
|
| 400 | + * @param $value |
|
| 401 | + */ |
|
| 402 | + public function double_check_config_comparison($option = '', $old_value, $value) |
|
| 403 | + { |
|
| 404 | + // make sure we're checking the ee config |
|
| 405 | + if ($option === EE_Config::OPTION_NAME) { |
|
| 406 | + // run a loose comparison of the old value against the new value for type and properties, |
|
| 407 | + // but NOT exact instance like WP update_option does (ie: NOT type safe comparison) |
|
| 408 | + if ($value != $old_value) { |
|
| 409 | + // if they are NOT the same, then remove the hook, |
|
| 410 | + // which means the subsequent update results will be based solely on the update query results |
|
| 411 | + // the reason we do this is because, as stated above, |
|
| 412 | + // WP update_option performs an exact instance comparison (===) on any update values passed to it |
|
| 413 | + // this happens PRIOR to serialization and any subsequent update. |
|
| 414 | + // If values are found to match their previous old value, |
|
| 415 | + // then WP bails before performing any update. |
|
| 416 | + // Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version |
|
| 417 | + // it just pulled from the db, with the one being passed to it (which will not match). |
|
| 418 | + // HOWEVER, once the object is serialized and passed off to MySQL to update, |
|
| 419 | + // MySQL MAY ALSO NOT perform the update because |
|
| 420 | + // the string it sees in the db looks the same as the new one it has been passed!!! |
|
| 421 | + // This results in the query returning an "affected rows" value of ZERO, |
|
| 422 | + // which gets returned immediately by WP update_option and looks like an error. |
|
| 423 | + remove_action('update_option', array($this, 'check_config_updated')); |
|
| 424 | + } |
|
| 425 | + } |
|
| 426 | + } |
|
| 427 | + |
|
| 428 | + |
|
| 429 | + /** |
|
| 430 | + * update_espresso_config |
|
| 431 | + * |
|
| 432 | + * @access public |
|
| 433 | + */ |
|
| 434 | + protected function _reset_espresso_addon_config() |
|
| 435 | + { |
|
| 436 | + $this->_addon_option_names = array(); |
|
| 437 | + foreach ($this->addons as $addon_name => $addon_config_obj) { |
|
| 438 | + $addon_config_obj = maybe_unserialize($addon_config_obj); |
|
| 439 | + if ($addon_config_obj instanceof EE_Config_Base) { |
|
| 440 | + $this->update_config('addons', $addon_name, $addon_config_obj, false); |
|
| 441 | + } |
|
| 442 | + $this->addons->{$addon_name} = null; |
|
| 443 | + } |
|
| 444 | + } |
|
| 445 | + |
|
| 446 | + |
|
| 447 | + /** |
|
| 448 | + * update_espresso_config |
|
| 449 | + * |
|
| 450 | + * @access public |
|
| 451 | + * @param bool $add_success |
|
| 452 | + * @param bool $add_error |
|
| 453 | + * @return bool |
|
| 454 | + */ |
|
| 455 | + public function update_espresso_config($add_success = false, $add_error = true) |
|
| 456 | + { |
|
| 457 | + // don't allow config updates during WP heartbeats |
|
| 458 | + if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
| 459 | + return false; |
|
| 460 | + } |
|
| 461 | + // commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197 |
|
| 462 | + // $clone = clone( self::$_instance ); |
|
| 463 | + // self::$_instance = NULL; |
|
| 464 | + do_action('AHEE__EE_Config__update_espresso_config__begin', $this); |
|
| 465 | + $this->_reset_espresso_addon_config(); |
|
| 466 | + // hook into update_option because that happens AFTER the ( $value === $old_value ) conditional |
|
| 467 | + // but BEFORE the actual update occurs |
|
| 468 | + add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3); |
|
| 469 | + // don't want to persist legacy_shortcodes_manager, but don't want to lose it either |
|
| 470 | + $legacy_shortcodes_manager = $this->legacy_shortcodes_manager; |
|
| 471 | + $this->legacy_shortcodes_manager = null; |
|
| 472 | + // now update "ee_config" |
|
| 473 | + $saved = update_option(EE_Config::OPTION_NAME, $this); |
|
| 474 | + $this->legacy_shortcodes_manager = $legacy_shortcodes_manager; |
|
| 475 | + EE_Config::log(EE_Config::OPTION_NAME); |
|
| 476 | + // if not saved... check if the hook we just added still exists; |
|
| 477 | + // if it does, it means one of two things: |
|
| 478 | + // that update_option bailed at the($value === $old_value) conditional, |
|
| 479 | + // or... |
|
| 480 | + // the db update query returned 0 rows affected |
|
| 481 | + // (probably because the data value was the same from it's perspective) |
|
| 482 | + // so the existence of the hook means that a negative result from update_option is NOT an error, |
|
| 483 | + // but just means no update occurred, so don't display an error to the user. |
|
| 484 | + // BUT... if update_option returns FALSE, AND the hook is missing, |
|
| 485 | + // then it means that something truly went wrong |
|
| 486 | + $saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved; |
|
| 487 | + // remove our action since we don't want it in the system anymore |
|
| 488 | + remove_action('update_option', array($this, 'double_check_config_comparison'), 1); |
|
| 489 | + do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved); |
|
| 490 | + // self::$_instance = $clone; |
|
| 491 | + // unset( $clone ); |
|
| 492 | + // if config remains the same or was updated successfully |
|
| 493 | + if ($saved) { |
|
| 494 | + if ($add_success) { |
|
| 495 | + EE_Error::add_success( |
|
| 496 | + __('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'), |
|
| 497 | + __FILE__, |
|
| 498 | + __FUNCTION__, |
|
| 499 | + __LINE__ |
|
| 500 | + ); |
|
| 501 | + } |
|
| 502 | + return true; |
|
| 503 | + } else { |
|
| 504 | + if ($add_error) { |
|
| 505 | + EE_Error::add_error( |
|
| 506 | + __('The Event Espresso Configuration Settings were not updated.', 'event_espresso'), |
|
| 507 | + __FILE__, |
|
| 508 | + __FUNCTION__, |
|
| 509 | + __LINE__ |
|
| 510 | + ); |
|
| 511 | + } |
|
| 512 | + return false; |
|
| 513 | + } |
|
| 514 | + } |
|
| 515 | + |
|
| 516 | + |
|
| 517 | + /** |
|
| 518 | + * _verify_config_params |
|
| 519 | + * |
|
| 520 | + * @access private |
|
| 521 | + * @param string $section |
|
| 522 | + * @param string $name |
|
| 523 | + * @param string $config_class |
|
| 524 | + * @param EE_Config_Base $config_obj |
|
| 525 | + * @param array $tests_to_run |
|
| 526 | + * @param bool $display_errors |
|
| 527 | + * @return bool TRUE on success, FALSE on fail |
|
| 528 | + */ |
|
| 529 | + private function _verify_config_params( |
|
| 530 | + $section = '', |
|
| 531 | + $name = '', |
|
| 532 | + $config_class = '', |
|
| 533 | + $config_obj = null, |
|
| 534 | + $tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8), |
|
| 535 | + $display_errors = true |
|
| 536 | + ) { |
|
| 537 | + try { |
|
| 538 | + foreach ($tests_to_run as $test) { |
|
| 539 | + switch ($test) { |
|
| 540 | + // TEST #1 : check that section was set |
|
| 541 | + case 1: |
|
| 542 | + if (empty($section)) { |
|
| 543 | + if ($display_errors) { |
|
| 544 | + throw new EE_Error( |
|
| 545 | + sprintf( |
|
| 546 | + __( |
|
| 547 | + 'No configuration section has been provided while attempting to save "%s".', |
|
| 548 | + 'event_espresso' |
|
| 549 | + ), |
|
| 550 | + $config_class |
|
| 551 | + ) |
|
| 552 | + ); |
|
| 553 | + } |
|
| 554 | + return false; |
|
| 555 | + } |
|
| 556 | + break; |
|
| 557 | + // TEST #2 : check that settings section exists |
|
| 558 | + case 2: |
|
| 559 | + if (! isset($this->{$section})) { |
|
| 560 | + if ($display_errors) { |
|
| 561 | + throw new EE_Error( |
|
| 562 | + sprintf( |
|
| 563 | + __('The "%s" configuration section does not exist.', 'event_espresso'), |
|
| 564 | + $section |
|
| 565 | + ) |
|
| 566 | + ); |
|
| 567 | + } |
|
| 568 | + return false; |
|
| 569 | + } |
|
| 570 | + break; |
|
| 571 | + // TEST #3 : check that section is the proper format |
|
| 572 | + case 3: |
|
| 573 | + if (! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass) |
|
| 574 | + ) { |
|
| 575 | + if ($display_errors) { |
|
| 576 | + throw new EE_Error( |
|
| 577 | + sprintf( |
|
| 578 | + __( |
|
| 579 | + 'The "%s" configuration settings have not been formatted correctly.', |
|
| 580 | + 'event_espresso' |
|
| 581 | + ), |
|
| 582 | + $section |
|
| 583 | + ) |
|
| 584 | + ); |
|
| 585 | + } |
|
| 586 | + return false; |
|
| 587 | + } |
|
| 588 | + break; |
|
| 589 | + // TEST #4 : check that config section name has been set |
|
| 590 | + case 4: |
|
| 591 | + if (empty($name)) { |
|
| 592 | + if ($display_errors) { |
|
| 593 | + throw new EE_Error( |
|
| 594 | + __( |
|
| 595 | + 'No name has been provided for the specific configuration section.', |
|
| 596 | + 'event_espresso' |
|
| 597 | + ) |
|
| 598 | + ); |
|
| 599 | + } |
|
| 600 | + return false; |
|
| 601 | + } |
|
| 602 | + break; |
|
| 603 | + // TEST #5 : check that a config class name has been set |
|
| 604 | + case 5: |
|
| 605 | + if (empty($config_class)) { |
|
| 606 | + if ($display_errors) { |
|
| 607 | + throw new EE_Error( |
|
| 608 | + __( |
|
| 609 | + 'No class name has been provided for the specific configuration section.', |
|
| 610 | + 'event_espresso' |
|
| 611 | + ) |
|
| 612 | + ); |
|
| 613 | + } |
|
| 614 | + return false; |
|
| 615 | + } |
|
| 616 | + break; |
|
| 617 | + // TEST #6 : verify config class is accessible |
|
| 618 | + case 6: |
|
| 619 | + if (! class_exists($config_class)) { |
|
| 620 | + if ($display_errors) { |
|
| 621 | + throw new EE_Error( |
|
| 622 | + sprintf( |
|
| 623 | + __( |
|
| 624 | + 'The "%s" class does not exist. Please ensure that an autoloader has been set for it.', |
|
| 625 | + 'event_espresso' |
|
| 626 | + ), |
|
| 627 | + $config_class |
|
| 628 | + ) |
|
| 629 | + ); |
|
| 630 | + } |
|
| 631 | + return false; |
|
| 632 | + } |
|
| 633 | + break; |
|
| 634 | + // TEST #7 : check that config has even been set |
|
| 635 | + case 7: |
|
| 636 | + if (! isset($this->{$section}->{$name})) { |
|
| 637 | + if ($display_errors) { |
|
| 638 | + throw new EE_Error( |
|
| 639 | + sprintf( |
|
| 640 | + __('No configuration has been set for "%1$s->%2$s".', 'event_espresso'), |
|
| 641 | + $section, |
|
| 642 | + $name |
|
| 643 | + ) |
|
| 644 | + ); |
|
| 645 | + } |
|
| 646 | + return false; |
|
| 647 | + } else { |
|
| 648 | + // and make sure it's not serialized |
|
| 649 | + $this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name}); |
|
| 650 | + } |
|
| 651 | + break; |
|
| 652 | + // TEST #8 : check that config is the requested type |
|
| 653 | + case 8: |
|
| 654 | + if (! $this->{$section}->{$name} instanceof $config_class) { |
|
| 655 | + if ($display_errors) { |
|
| 656 | + throw new EE_Error( |
|
| 657 | + sprintf( |
|
| 658 | + __( |
|
| 659 | + 'The configuration for "%1$s->%2$s" is not of the "%3$s" class.', |
|
| 660 | + 'event_espresso' |
|
| 661 | + ), |
|
| 662 | + $section, |
|
| 663 | + $name, |
|
| 664 | + $config_class |
|
| 665 | + ) |
|
| 666 | + ); |
|
| 667 | + } |
|
| 668 | + return false; |
|
| 669 | + } |
|
| 670 | + break; |
|
| 671 | + // TEST #9 : verify config object |
|
| 672 | + case 9: |
|
| 673 | + if (! $config_obj instanceof EE_Config_Base) { |
|
| 674 | + if ($display_errors) { |
|
| 675 | + throw new EE_Error( |
|
| 676 | + sprintf( |
|
| 677 | + __('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'), |
|
| 678 | + print_r($config_obj, true) |
|
| 679 | + ) |
|
| 680 | + ); |
|
| 681 | + } |
|
| 682 | + return false; |
|
| 683 | + } |
|
| 684 | + break; |
|
| 685 | + } |
|
| 686 | + } |
|
| 687 | + } catch (EE_Error $e) { |
|
| 688 | + $e->get_error(); |
|
| 689 | + } |
|
| 690 | + // you have successfully run the gauntlet |
|
| 691 | + return true; |
|
| 692 | + } |
|
| 693 | + |
|
| 694 | + |
|
| 695 | + /** |
|
| 696 | + * _generate_config_option_name |
|
| 697 | + * |
|
| 698 | + * @access protected |
|
| 699 | + * @param string $section |
|
| 700 | + * @param string $name |
|
| 701 | + * @return string |
|
| 702 | + */ |
|
| 703 | + private function _generate_config_option_name($section = '', $name = '') |
|
| 704 | + { |
|
| 705 | + return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name)); |
|
| 706 | + } |
|
| 707 | + |
|
| 708 | + |
|
| 709 | + /** |
|
| 710 | + * _set_config_class |
|
| 711 | + * ensures that a config class is set, either from a passed config class or one generated from the config name |
|
| 712 | + * |
|
| 713 | + * @access private |
|
| 714 | + * @param string $config_class |
|
| 715 | + * @param string $name |
|
| 716 | + * @return string |
|
| 717 | + */ |
|
| 718 | + private function _set_config_class($config_class = '', $name = '') |
|
| 719 | + { |
|
| 720 | + return ! empty($config_class) |
|
| 721 | + ? $config_class |
|
| 722 | + : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config'; |
|
| 723 | + } |
|
| 724 | + |
|
| 725 | + |
|
| 726 | + /** |
|
| 727 | + * set_config |
|
| 728 | + * |
|
| 729 | + * @access protected |
|
| 730 | + * @param string $section |
|
| 731 | + * @param string $name |
|
| 732 | + * @param string $config_class |
|
| 733 | + * @param EE_Config_Base $config_obj |
|
| 734 | + * @return EE_Config_Base |
|
| 735 | + */ |
|
| 736 | + public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null) |
|
| 737 | + { |
|
| 738 | + // ensure config class is set to something |
|
| 739 | + $config_class = $this->_set_config_class($config_class, $name); |
|
| 740 | + // run tests 1-4, 6, and 7 to verify all config params are set and valid |
|
| 741 | + if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 742 | + return null; |
|
| 743 | + } |
|
| 744 | + $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 745 | + // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now |
|
| 746 | + if (! isset($this->_addon_option_names[ $config_option_name ])) { |
|
| 747 | + $this->_addon_option_names[ $config_option_name ] = $config_class; |
|
| 748 | + $this->update_addon_option_names(); |
|
| 749 | + } |
|
| 750 | + // verify the incoming config object but suppress errors |
|
| 751 | + if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 752 | + $config_obj = new $config_class(); |
|
| 753 | + } |
|
| 754 | + if (get_option($config_option_name)) { |
|
| 755 | + EE_Config::log($config_option_name); |
|
| 756 | + update_option($config_option_name, $config_obj); |
|
| 757 | + $this->{$section}->{$name} = $config_obj; |
|
| 758 | + return $this->{$section}->{$name}; |
|
| 759 | + } else { |
|
| 760 | + // create a wp-option for this config |
|
| 761 | + if (add_option($config_option_name, $config_obj, '', 'no')) { |
|
| 762 | + $this->{$section}->{$name} = maybe_unserialize($config_obj); |
|
| 763 | + return $this->{$section}->{$name}; |
|
| 764 | + } else { |
|
| 765 | + EE_Error::add_error( |
|
| 766 | + sprintf(__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class), |
|
| 767 | + __FILE__, |
|
| 768 | + __FUNCTION__, |
|
| 769 | + __LINE__ |
|
| 770 | + ); |
|
| 771 | + return null; |
|
| 772 | + } |
|
| 773 | + } |
|
| 774 | + } |
|
| 775 | + |
|
| 776 | + |
|
| 777 | + /** |
|
| 778 | + * update_config |
|
| 779 | + * Important: the config object must ALREADY be set, otherwise this will produce an error. |
|
| 780 | + * |
|
| 781 | + * @access public |
|
| 782 | + * @param string $section |
|
| 783 | + * @param string $name |
|
| 784 | + * @param EE_Config_Base|string $config_obj |
|
| 785 | + * @param bool $throw_errors |
|
| 786 | + * @return bool |
|
| 787 | + */ |
|
| 788 | + public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true) |
|
| 789 | + { |
|
| 790 | + // don't allow config updates during WP heartbeats |
|
| 791 | + if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
| 792 | + return false; |
|
| 793 | + } |
|
| 794 | + $config_obj = maybe_unserialize($config_obj); |
|
| 795 | + // get class name of the incoming object |
|
| 796 | + $config_class = get_class($config_obj); |
|
| 797 | + // run tests 1-5 and 9 to verify config |
|
| 798 | + if (! $this->_verify_config_params( |
|
| 799 | + $section, |
|
| 800 | + $name, |
|
| 801 | + $config_class, |
|
| 802 | + $config_obj, |
|
| 803 | + array(1, 2, 3, 4, 7, 9) |
|
| 804 | + ) |
|
| 805 | + ) { |
|
| 806 | + return false; |
|
| 807 | + } |
|
| 808 | + $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 809 | + // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array |
|
| 810 | + if (! isset($this->_addon_option_names[ $config_option_name ])) { |
|
| 811 | + // save new config to db |
|
| 812 | + if ($this->set_config($section, $name, $config_class, $config_obj)) { |
|
| 813 | + return true; |
|
| 814 | + } |
|
| 815 | + } else { |
|
| 816 | + // first check if the record already exists |
|
| 817 | + $existing_config = get_option($config_option_name); |
|
| 818 | + $config_obj = serialize($config_obj); |
|
| 819 | + // just return if db record is already up to date (NOT type safe comparison) |
|
| 820 | + if ($existing_config == $config_obj) { |
|
| 821 | + $this->{$section}->{$name} = $config_obj; |
|
| 822 | + return true; |
|
| 823 | + } elseif (update_option($config_option_name, $config_obj)) { |
|
| 824 | + EE_Config::log($config_option_name); |
|
| 825 | + // update wp-option for this config class |
|
| 826 | + $this->{$section}->{$name} = $config_obj; |
|
| 827 | + return true; |
|
| 828 | + } elseif ($throw_errors) { |
|
| 829 | + EE_Error::add_error( |
|
| 830 | + sprintf( |
|
| 831 | + __( |
|
| 832 | + 'The "%1$s" object stored at"%2$s" was not successfully updated in the database.', |
|
| 833 | + 'event_espresso' |
|
| 834 | + ), |
|
| 835 | + $config_class, |
|
| 836 | + 'EE_Config->' . $section . '->' . $name |
|
| 837 | + ), |
|
| 838 | + __FILE__, |
|
| 839 | + __FUNCTION__, |
|
| 840 | + __LINE__ |
|
| 841 | + ); |
|
| 842 | + } |
|
| 843 | + } |
|
| 844 | + return false; |
|
| 845 | + } |
|
| 846 | + |
|
| 847 | + |
|
| 848 | + /** |
|
| 849 | + * get_config |
|
| 850 | + * |
|
| 851 | + * @access public |
|
| 852 | + * @param string $section |
|
| 853 | + * @param string $name |
|
| 854 | + * @param string $config_class |
|
| 855 | + * @return mixed EE_Config_Base | NULL |
|
| 856 | + */ |
|
| 857 | + public function get_config($section = '', $name = '', $config_class = '') |
|
| 858 | + { |
|
| 859 | + // ensure config class is set to something |
|
| 860 | + $config_class = $this->_set_config_class($config_class, $name); |
|
| 861 | + // run tests 1-4, 6 and 7 to verify that all params have been set |
|
| 862 | + if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 863 | + return null; |
|
| 864 | + } |
|
| 865 | + // now test if the requested config object exists, but suppress errors |
|
| 866 | + if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) { |
|
| 867 | + // config already exists, so pass it back |
|
| 868 | + return $this->{$section}->{$name}; |
|
| 869 | + } |
|
| 870 | + // load config option from db if it exists |
|
| 871 | + $config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name)); |
|
| 872 | + // verify the newly retrieved config object, but suppress errors |
|
| 873 | + if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 874 | + // config is good, so set it and pass it back |
|
| 875 | + $this->{$section}->{$name} = $config_obj; |
|
| 876 | + return $this->{$section}->{$name}; |
|
| 877 | + } |
|
| 878 | + // oops! $config_obj is not already set and does not exist in the db, so create a new one |
|
| 879 | + $config_obj = $this->set_config($section, $name, $config_class); |
|
| 880 | + // verify the newly created config object |
|
| 881 | + if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) { |
|
| 882 | + return $this->{$section}->{$name}; |
|
| 883 | + } else { |
|
| 884 | + EE_Error::add_error( |
|
| 885 | + sprintf(__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class), |
|
| 886 | + __FILE__, |
|
| 887 | + __FUNCTION__, |
|
| 888 | + __LINE__ |
|
| 889 | + ); |
|
| 890 | + } |
|
| 891 | + return null; |
|
| 892 | + } |
|
| 893 | + |
|
| 894 | + |
|
| 895 | + /** |
|
| 896 | + * get_config_option |
|
| 897 | + * |
|
| 898 | + * @access public |
|
| 899 | + * @param string $config_option_name |
|
| 900 | + * @return mixed EE_Config_Base | FALSE |
|
| 901 | + */ |
|
| 902 | + public function get_config_option($config_option_name = '') |
|
| 903 | + { |
|
| 904 | + // retrieve the wp-option for this config class. |
|
| 905 | + $config_option = maybe_unserialize(get_option($config_option_name, array())); |
|
| 906 | + if (empty($config_option)) { |
|
| 907 | + EE_Config::log($config_option_name . '-NOT-FOUND'); |
|
| 908 | + } |
|
| 909 | + return $config_option; |
|
| 910 | + } |
|
| 911 | + |
|
| 912 | + |
|
| 913 | + /** |
|
| 914 | + * log |
|
| 915 | + * |
|
| 916 | + * @param string $config_option_name |
|
| 917 | + */ |
|
| 918 | + public static function log($config_option_name = '') |
|
| 919 | + { |
|
| 920 | + if (EE_Config::logging_enabled() && ! empty($config_option_name)) { |
|
| 921 | + $config_log = get_option(EE_Config::LOG_NAME, array()); |
|
| 922 | + // copy incoming $_REQUEST and sanitize it so we can save it |
|
| 923 | + $_request = $_REQUEST; |
|
| 924 | + array_walk_recursive($_request, 'sanitize_text_field'); |
|
| 925 | + $config_log[ (string) microtime(true) ] = array( |
|
| 926 | + 'config_name' => $config_option_name, |
|
| 927 | + 'request' => $_request, |
|
| 928 | + ); |
|
| 929 | + update_option(EE_Config::LOG_NAME, $config_log); |
|
| 930 | + } |
|
| 931 | + } |
|
| 932 | + |
|
| 933 | + |
|
| 934 | + /** |
|
| 935 | + * trim_log |
|
| 936 | + * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH |
|
| 937 | + */ |
|
| 938 | + public static function trim_log() |
|
| 939 | + { |
|
| 940 | + if (! EE_Config::logging_enabled()) { |
|
| 941 | + return; |
|
| 942 | + } |
|
| 943 | + $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array())); |
|
| 944 | + $log_length = count($config_log); |
|
| 945 | + if ($log_length > EE_Config::LOG_LENGTH) { |
|
| 946 | + ksort($config_log); |
|
| 947 | + $config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true); |
|
| 948 | + update_option(EE_Config::LOG_NAME, $config_log); |
|
| 949 | + } |
|
| 950 | + } |
|
| 951 | + |
|
| 952 | + |
|
| 953 | + /** |
|
| 954 | + * get_page_for_posts |
|
| 955 | + * if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the |
|
| 956 | + * wp-option "page_for_posts", or "posts" if no page is selected |
|
| 957 | + * |
|
| 958 | + * @access public |
|
| 959 | + * @return string |
|
| 960 | + */ |
|
| 961 | + public static function get_page_for_posts() |
|
| 962 | + { |
|
| 963 | + $page_for_posts = get_option('page_for_posts'); |
|
| 964 | + if (! $page_for_posts) { |
|
| 965 | + return 'posts'; |
|
| 966 | + } |
|
| 967 | + /** @type WPDB $wpdb */ |
|
| 968 | + global $wpdb; |
|
| 969 | + $SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d"; |
|
| 970 | + return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts)); |
|
| 971 | + } |
|
| 972 | + |
|
| 973 | + |
|
| 974 | + /** |
|
| 975 | + * register_shortcodes_and_modules. |
|
| 976 | + * At this point, it's too early to tell if we're maintenance mode or not. |
|
| 977 | + * In fact, this is where we give modules a chance to let core know they exist |
|
| 978 | + * so they can help trigger maintenance mode if it's needed |
|
| 979 | + * |
|
| 980 | + * @access public |
|
| 981 | + * @return void |
|
| 982 | + */ |
|
| 983 | + public function register_shortcodes_and_modules() |
|
| 984 | + { |
|
| 985 | + // allow modules to set hooks for the rest of the system |
|
| 986 | + EE_Registry::instance()->modules = $this->_register_modules(); |
|
| 987 | + } |
|
| 988 | + |
|
| 989 | + |
|
| 990 | + /** |
|
| 991 | + * initialize_shortcodes_and_modules |
|
| 992 | + * meaning they can start adding their hooks to get stuff done |
|
| 993 | + * |
|
| 994 | + * @access public |
|
| 995 | + * @return void |
|
| 996 | + */ |
|
| 997 | + public function initialize_shortcodes_and_modules() |
|
| 998 | + { |
|
| 999 | + // allow modules to set hooks for the rest of the system |
|
| 1000 | + $this->_initialize_modules(); |
|
| 1001 | + } |
|
| 1002 | + |
|
| 1003 | + |
|
| 1004 | + /** |
|
| 1005 | + * widgets_init |
|
| 1006 | + * |
|
| 1007 | + * @access private |
|
| 1008 | + * @return void |
|
| 1009 | + */ |
|
| 1010 | + public function widgets_init() |
|
| 1011 | + { |
|
| 1012 | + // only init widgets on admin pages when not in complete maintenance, and |
|
| 1013 | + // on frontend when not in any maintenance mode |
|
| 1014 | + if (! EE_Maintenance_Mode::instance()->level() |
|
| 1015 | + || ( |
|
| 1016 | + is_admin() |
|
| 1017 | + && EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance |
|
| 1018 | + ) |
|
| 1019 | + ) { |
|
| 1020 | + // grab list of installed widgets |
|
| 1021 | + $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR); |
|
| 1022 | + // filter list of modules to register |
|
| 1023 | + $widgets_to_register = apply_filters( |
|
| 1024 | + 'FHEE__EE_Config__register_widgets__widgets_to_register', |
|
| 1025 | + $widgets_to_register |
|
| 1026 | + ); |
|
| 1027 | + if (! empty($widgets_to_register)) { |
|
| 1028 | + // cycle thru widget folders |
|
| 1029 | + foreach ($widgets_to_register as $widget_path) { |
|
| 1030 | + // add to list of installed widget modules |
|
| 1031 | + EE_Config::register_ee_widget($widget_path); |
|
| 1032 | + } |
|
| 1033 | + } |
|
| 1034 | + // filter list of installed modules |
|
| 1035 | + EE_Registry::instance()->widgets = apply_filters( |
|
| 1036 | + 'FHEE__EE_Config__register_widgets__installed_widgets', |
|
| 1037 | + EE_Registry::instance()->widgets |
|
| 1038 | + ); |
|
| 1039 | + } |
|
| 1040 | + } |
|
| 1041 | + |
|
| 1042 | + |
|
| 1043 | + /** |
|
| 1044 | + * register_ee_widget - makes core aware of this widget |
|
| 1045 | + * |
|
| 1046 | + * @access public |
|
| 1047 | + * @param string $widget_path - full path up to and including widget folder |
|
| 1048 | + * @return void |
|
| 1049 | + */ |
|
| 1050 | + public static function register_ee_widget($widget_path = null) |
|
| 1051 | + { |
|
| 1052 | + do_action('AHEE__EE_Config__register_widget__begin', $widget_path); |
|
| 1053 | + $widget_ext = '.widget.php'; |
|
| 1054 | + // make all separators match |
|
| 1055 | + $widget_path = rtrim(str_replace('\\', DS, $widget_path), DS); |
|
| 1056 | + // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1057 | + if (strpos($widget_path, $widget_ext) !== false) { |
|
| 1058 | + // grab and shortcode file name from directory name and break apart at dots |
|
| 1059 | + $file_name = explode('.', basename($widget_path)); |
|
| 1060 | + // take first segment from file name pieces and remove class prefix if it exists |
|
| 1061 | + $widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0]; |
|
| 1062 | + // sanitize shortcode directory name |
|
| 1063 | + $widget = sanitize_key($widget); |
|
| 1064 | + // now we need to rebuild the shortcode path |
|
| 1065 | + $widget_path = explode('/', $widget_path); |
|
| 1066 | + // remove last segment |
|
| 1067 | + array_pop($widget_path); |
|
| 1068 | + // glue it back together |
|
| 1069 | + $widget_path = implode(DS, $widget_path); |
|
| 1070 | + } else { |
|
| 1071 | + // grab and sanitize widget directory name |
|
| 1072 | + $widget = sanitize_key(basename($widget_path)); |
|
| 1073 | + } |
|
| 1074 | + // create classname from widget directory name |
|
| 1075 | + $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget))); |
|
| 1076 | + // add class prefix |
|
| 1077 | + $widget_class = 'EEW_' . $widget; |
|
| 1078 | + // does the widget exist ? |
|
| 1079 | + if (! is_readable($widget_path . '/' . $widget_class . $widget_ext)) { |
|
| 1080 | + $msg = sprintf( |
|
| 1081 | + __( |
|
| 1082 | + 'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', |
|
| 1083 | + 'event_espresso' |
|
| 1084 | + ), |
|
| 1085 | + $widget_class, |
|
| 1086 | + $widget_path . '/' . $widget_class . $widget_ext |
|
| 1087 | + ); |
|
| 1088 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1089 | + return; |
|
| 1090 | + } |
|
| 1091 | + // load the widget class file |
|
| 1092 | + require_once($widget_path . '/' . $widget_class . $widget_ext); |
|
| 1093 | + // verify that class exists |
|
| 1094 | + if (! class_exists($widget_class)) { |
|
| 1095 | + $msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class); |
|
| 1096 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1097 | + return; |
|
| 1098 | + } |
|
| 1099 | + register_widget($widget_class); |
|
| 1100 | + // add to array of registered widgets |
|
| 1101 | + EE_Registry::instance()->widgets->{$widget_class} = $widget_path . '/' . $widget_class . $widget_ext; |
|
| 1102 | + } |
|
| 1103 | + |
|
| 1104 | + |
|
| 1105 | + /** |
|
| 1106 | + * _register_modules |
|
| 1107 | + * |
|
| 1108 | + * @access private |
|
| 1109 | + * @return array |
|
| 1110 | + */ |
|
| 1111 | + private function _register_modules() |
|
| 1112 | + { |
|
| 1113 | + // grab list of installed modules |
|
| 1114 | + $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR); |
|
| 1115 | + // filter list of modules to register |
|
| 1116 | + $modules_to_register = apply_filters( |
|
| 1117 | + 'FHEE__EE_Config__register_modules__modules_to_register', |
|
| 1118 | + $modules_to_register |
|
| 1119 | + ); |
|
| 1120 | + if (! empty($modules_to_register)) { |
|
| 1121 | + // loop through folders |
|
| 1122 | + foreach ($modules_to_register as $module_path) { |
|
| 1123 | + /**TEMPORARILY EXCLUDE gateways from modules for time being**/ |
|
| 1124 | + if ($module_path !== EE_MODULES . 'zzz-copy-this-module-template' |
|
| 1125 | + && $module_path !== EE_MODULES . 'gateways' |
|
| 1126 | + ) { |
|
| 1127 | + // add to list of installed modules |
|
| 1128 | + EE_Config::register_module($module_path); |
|
| 1129 | + } |
|
| 1130 | + } |
|
| 1131 | + } |
|
| 1132 | + // filter list of installed modules |
|
| 1133 | + return apply_filters( |
|
| 1134 | + 'FHEE__EE_Config___register_modules__installed_modules', |
|
| 1135 | + EE_Registry::instance()->modules |
|
| 1136 | + ); |
|
| 1137 | + } |
|
| 1138 | + |
|
| 1139 | + |
|
| 1140 | + /** |
|
| 1141 | + * register_module - makes core aware of this module |
|
| 1142 | + * |
|
| 1143 | + * @access public |
|
| 1144 | + * @param string $module_path - full path up to and including module folder |
|
| 1145 | + * @return bool |
|
| 1146 | + */ |
|
| 1147 | + public static function register_module($module_path = null) |
|
| 1148 | + { |
|
| 1149 | + do_action('AHEE__EE_Config__register_module__begin', $module_path); |
|
| 1150 | + $module_ext = '.module.php'; |
|
| 1151 | + // make all separators match |
|
| 1152 | + $module_path = str_replace(array('\\', '/'), '/', $module_path); |
|
| 1153 | + // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1154 | + if (strpos($module_path, $module_ext) !== false) { |
|
| 1155 | + // grab and shortcode file name from directory name and break apart at dots |
|
| 1156 | + $module_file = explode('.', basename($module_path)); |
|
| 1157 | + // now we need to rebuild the shortcode path |
|
| 1158 | + $module_path = explode('/', $module_path); |
|
| 1159 | + // remove last segment |
|
| 1160 | + array_pop($module_path); |
|
| 1161 | + // glue it back together |
|
| 1162 | + $module_path = implode('/', $module_path) . '/'; |
|
| 1163 | + // take first segment from file name pieces and sanitize it |
|
| 1164 | + $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]); |
|
| 1165 | + // ensure class prefix is added |
|
| 1166 | + $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module; |
|
| 1167 | + } else { |
|
| 1168 | + // we need to generate the filename based off of the folder name |
|
| 1169 | + // grab and sanitize module name |
|
| 1170 | + $module = strtolower(basename($module_path)); |
|
| 1171 | + $module = preg_replace('/[^a-z0-9_\-]/', '', $module); |
|
| 1172 | + // like trailingslashit() |
|
| 1173 | + $module_path = rtrim($module_path, '/') . '/'; |
|
| 1174 | + // create classname from module directory name |
|
| 1175 | + $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module))); |
|
| 1176 | + // add class prefix |
|
| 1177 | + $module_class = 'EED_' . $module; |
|
| 1178 | + } |
|
| 1179 | + // does the module exist ? |
|
| 1180 | + if (! is_readable($module_path . '/' . $module_class . $module_ext)) { |
|
| 1181 | + $msg = sprintf( |
|
| 1182 | + __( |
|
| 1183 | + 'The requested %s module file could not be found or is not readable due to file permissions.', |
|
| 1184 | + 'event_espresso' |
|
| 1185 | + ), |
|
| 1186 | + $module |
|
| 1187 | + ); |
|
| 1188 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1189 | + return false; |
|
| 1190 | + } |
|
| 1191 | + // load the module class file |
|
| 1192 | + require_once($module_path . $module_class . $module_ext); |
|
| 1193 | + // verify that class exists |
|
| 1194 | + if (! class_exists($module_class)) { |
|
| 1195 | + $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
|
| 1196 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1197 | + return false; |
|
| 1198 | + } |
|
| 1199 | + // add to array of registered modules |
|
| 1200 | + EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext; |
|
| 1201 | + do_action( |
|
| 1202 | + 'AHEE__EE_Config__register_module__complete', |
|
| 1203 | + $module_class, |
|
| 1204 | + EE_Registry::instance()->modules->{$module_class} |
|
| 1205 | + ); |
|
| 1206 | + return true; |
|
| 1207 | + } |
|
| 1208 | + |
|
| 1209 | + |
|
| 1210 | + /** |
|
| 1211 | + * _initialize_modules |
|
| 1212 | + * allow modules to set hooks for the rest of the system |
|
| 1213 | + * |
|
| 1214 | + * @access private |
|
| 1215 | + * @return void |
|
| 1216 | + */ |
|
| 1217 | + private function _initialize_modules() |
|
| 1218 | + { |
|
| 1219 | + // cycle thru shortcode folders |
|
| 1220 | + foreach (EE_Registry::instance()->modules as $module_class => $module_path) { |
|
| 1221 | + // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system |
|
| 1222 | + // which set hooks ? |
|
| 1223 | + if (is_admin()) { |
|
| 1224 | + // fire immediately |
|
| 1225 | + call_user_func(array($module_class, 'set_hooks_admin')); |
|
| 1226 | + } else { |
|
| 1227 | + // delay until other systems are online |
|
| 1228 | + add_action( |
|
| 1229 | + 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', |
|
| 1230 | + array($module_class, 'set_hooks') |
|
| 1231 | + ); |
|
| 1232 | + } |
|
| 1233 | + } |
|
| 1234 | + } |
|
| 1235 | + |
|
| 1236 | + |
|
| 1237 | + /** |
|
| 1238 | + * register_route - adds module method routes to route_map |
|
| 1239 | + * |
|
| 1240 | + * @access public |
|
| 1241 | + * @param string $route - "pretty" public alias for module method |
|
| 1242 | + * @param string $module - module name (classname without EED_ prefix) |
|
| 1243 | + * @param string $method_name - the actual module method to be routed to |
|
| 1244 | + * @param string $key - url param key indicating a route is being called |
|
| 1245 | + * @return bool |
|
| 1246 | + */ |
|
| 1247 | + public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee') |
|
| 1248 | + { |
|
| 1249 | + do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name); |
|
| 1250 | + $module = str_replace('EED_', '', $module); |
|
| 1251 | + $module_class = 'EED_' . $module; |
|
| 1252 | + if (! isset(EE_Registry::instance()->modules->{$module_class})) { |
|
| 1253 | + $msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module); |
|
| 1254 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1255 | + return false; |
|
| 1256 | + } |
|
| 1257 | + if (empty($route)) { |
|
| 1258 | + $msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route); |
|
| 1259 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1260 | + return false; |
|
| 1261 | + } |
|
| 1262 | + if (! method_exists('EED_' . $module, $method_name)) { |
|
| 1263 | + $msg = sprintf( |
|
| 1264 | + __('A valid class method for the %s route has not been supplied.', 'event_espresso'), |
|
| 1265 | + $route |
|
| 1266 | + ); |
|
| 1267 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1268 | + return false; |
|
| 1269 | + } |
|
| 1270 | + EE_Config::$_module_route_map[ (string) $key ][ (string) $route ] = array('EED_' . $module, $method_name); |
|
| 1271 | + return true; |
|
| 1272 | + } |
|
| 1273 | + |
|
| 1274 | + |
|
| 1275 | + /** |
|
| 1276 | + * get_route - get module method route |
|
| 1277 | + * |
|
| 1278 | + * @access public |
|
| 1279 | + * @param string $route - "pretty" public alias for module method |
|
| 1280 | + * @param string $key - url param key indicating a route is being called |
|
| 1281 | + * @return string |
|
| 1282 | + */ |
|
| 1283 | + public static function get_route($route = null, $key = 'ee') |
|
| 1284 | + { |
|
| 1285 | + do_action('AHEE__EE_Config__get_route__begin', $route); |
|
| 1286 | + $route = (string) apply_filters('FHEE__EE_Config__get_route', $route); |
|
| 1287 | + if (isset(EE_Config::$_module_route_map[ $key ][ $route ])) { |
|
| 1288 | + return EE_Config::$_module_route_map[ $key ][ $route ]; |
|
| 1289 | + } |
|
| 1290 | + return null; |
|
| 1291 | + } |
|
| 1292 | + |
|
| 1293 | + |
|
| 1294 | + /** |
|
| 1295 | + * get_routes - get ALL module method routes |
|
| 1296 | + * |
|
| 1297 | + * @access public |
|
| 1298 | + * @return array |
|
| 1299 | + */ |
|
| 1300 | + public static function get_routes() |
|
| 1301 | + { |
|
| 1302 | + return EE_Config::$_module_route_map; |
|
| 1303 | + } |
|
| 1304 | + |
|
| 1305 | + |
|
| 1306 | + /** |
|
| 1307 | + * register_forward - allows modules to forward request to another module for further processing |
|
| 1308 | + * |
|
| 1309 | + * @access public |
|
| 1310 | + * @param string $route - "pretty" public alias for module method |
|
| 1311 | + * @param integer $status - integer value corresponding to status constant strings set in module parent |
|
| 1312 | + * class, allows different forwards to be served based on status |
|
| 1313 | + * @param array|string $forward - function name or array( class, method ) |
|
| 1314 | + * @param string $key - url param key indicating a route is being called |
|
| 1315 | + * @return bool |
|
| 1316 | + */ |
|
| 1317 | + public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee') |
|
| 1318 | + { |
|
| 1319 | + do_action('AHEE__EE_Config__register_forward', $route, $status, $forward); |
|
| 1320 | + if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) { |
|
| 1321 | + $msg = sprintf( |
|
| 1322 | + __('The module route %s for this forward has not been registered.', 'event_espresso'), |
|
| 1323 | + $route |
|
| 1324 | + ); |
|
| 1325 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1326 | + return false; |
|
| 1327 | + } |
|
| 1328 | + if (empty($forward)) { |
|
| 1329 | + $msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route); |
|
| 1330 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1331 | + return false; |
|
| 1332 | + } |
|
| 1333 | + if (is_array($forward)) { |
|
| 1334 | + if (! isset($forward[1])) { |
|
| 1335 | + $msg = sprintf( |
|
| 1336 | + __('A class method for the %s forwarding route has not been supplied.', 'event_espresso'), |
|
| 1337 | + $route |
|
| 1338 | + ); |
|
| 1339 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1340 | + return false; |
|
| 1341 | + } |
|
| 1342 | + if (! method_exists($forward[0], $forward[1])) { |
|
| 1343 | + $msg = sprintf( |
|
| 1344 | + __('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1345 | + $forward[1], |
|
| 1346 | + $route |
|
| 1347 | + ); |
|
| 1348 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1349 | + return false; |
|
| 1350 | + } |
|
| 1351 | + } elseif (! function_exists($forward)) { |
|
| 1352 | + $msg = sprintf( |
|
| 1353 | + __('The function %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1354 | + $forward, |
|
| 1355 | + $route |
|
| 1356 | + ); |
|
| 1357 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1358 | + return false; |
|
| 1359 | + } |
|
| 1360 | + EE_Config::$_module_forward_map[ $key ][ $route ][ absint($status) ] = $forward; |
|
| 1361 | + return true; |
|
| 1362 | + } |
|
| 1363 | + |
|
| 1364 | + |
|
| 1365 | + /** |
|
| 1366 | + * get_forward - get forwarding route |
|
| 1367 | + * |
|
| 1368 | + * @access public |
|
| 1369 | + * @param string $route - "pretty" public alias for module method |
|
| 1370 | + * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1371 | + * allows different forwards to be served based on status |
|
| 1372 | + * @param string $key - url param key indicating a route is being called |
|
| 1373 | + * @return string |
|
| 1374 | + */ |
|
| 1375 | + public static function get_forward($route = null, $status = 0, $key = 'ee') |
|
| 1376 | + { |
|
| 1377 | + do_action('AHEE__EE_Config__get_forward__begin', $route, $status); |
|
| 1378 | + if (isset(EE_Config::$_module_forward_map[ $key ][ $route ][ $status ])) { |
|
| 1379 | + return apply_filters( |
|
| 1380 | + 'FHEE__EE_Config__get_forward', |
|
| 1381 | + EE_Config::$_module_forward_map[ $key ][ $route ][ $status ], |
|
| 1382 | + $route, |
|
| 1383 | + $status |
|
| 1384 | + ); |
|
| 1385 | + } |
|
| 1386 | + return null; |
|
| 1387 | + } |
|
| 1388 | + |
|
| 1389 | + |
|
| 1390 | + /** |
|
| 1391 | + * register_forward - allows modules to specify different view templates for different method routes and status |
|
| 1392 | + * results |
|
| 1393 | + * |
|
| 1394 | + * @access public |
|
| 1395 | + * @param string $route - "pretty" public alias for module method |
|
| 1396 | + * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1397 | + * allows different views to be served based on status |
|
| 1398 | + * @param string $view |
|
| 1399 | + * @param string $key - url param key indicating a route is being called |
|
| 1400 | + * @return bool |
|
| 1401 | + */ |
|
| 1402 | + public static function register_view($route = null, $status = 0, $view = null, $key = 'ee') |
|
| 1403 | + { |
|
| 1404 | + do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view); |
|
| 1405 | + if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) { |
|
| 1406 | + $msg = sprintf( |
|
| 1407 | + __('The module route %s for this view has not been registered.', 'event_espresso'), |
|
| 1408 | + $route |
|
| 1409 | + ); |
|
| 1410 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1411 | + return false; |
|
| 1412 | + } |
|
| 1413 | + if (! is_readable($view)) { |
|
| 1414 | + $msg = sprintf( |
|
| 1415 | + __( |
|
| 1416 | + 'The %s view file could not be found or is not readable due to file permissions.', |
|
| 1417 | + 'event_espresso' |
|
| 1418 | + ), |
|
| 1419 | + $view |
|
| 1420 | + ); |
|
| 1421 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1422 | + return false; |
|
| 1423 | + } |
|
| 1424 | + EE_Config::$_module_view_map[ $key ][ $route ][ absint($status) ] = $view; |
|
| 1425 | + return true; |
|
| 1426 | + } |
|
| 1427 | + |
|
| 1428 | + |
|
| 1429 | + /** |
|
| 1430 | + * get_view - get view for route and status |
|
| 1431 | + * |
|
| 1432 | + * @access public |
|
| 1433 | + * @param string $route - "pretty" public alias for module method |
|
| 1434 | + * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1435 | + * allows different views to be served based on status |
|
| 1436 | + * @param string $key - url param key indicating a route is being called |
|
| 1437 | + * @return string |
|
| 1438 | + */ |
|
| 1439 | + public static function get_view($route = null, $status = 0, $key = 'ee') |
|
| 1440 | + { |
|
| 1441 | + do_action('AHEE__EE_Config__get_view__begin', $route, $status); |
|
| 1442 | + if (isset(EE_Config::$_module_view_map[ $key ][ $route ][ $status ])) { |
|
| 1443 | + return apply_filters( |
|
| 1444 | + 'FHEE__EE_Config__get_view', |
|
| 1445 | + EE_Config::$_module_view_map[ $key ][ $route ][ $status ], |
|
| 1446 | + $route, |
|
| 1447 | + $status |
|
| 1448 | + ); |
|
| 1449 | + } |
|
| 1450 | + return null; |
|
| 1451 | + } |
|
| 1452 | + |
|
| 1453 | + |
|
| 1454 | + public function update_addon_option_names() |
|
| 1455 | + { |
|
| 1456 | + update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names); |
|
| 1457 | + } |
|
| 1458 | + |
|
| 1459 | + |
|
| 1460 | + public function shutdown() |
|
| 1461 | + { |
|
| 1462 | + $this->update_addon_option_names(); |
|
| 1463 | + } |
|
| 1464 | + |
|
| 1465 | + |
|
| 1466 | + /** |
|
| 1467 | + * @return LegacyShortcodesManager |
|
| 1468 | + */ |
|
| 1469 | + public static function getLegacyShortcodesManager() |
|
| 1470 | + { |
|
| 1471 | + |
|
| 1472 | + if (! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) { |
|
| 1473 | + EE_Config::instance()->legacy_shortcodes_manager = new LegacyShortcodesManager( |
|
| 1474 | + EE_Registry::instance() |
|
| 1475 | + ); |
|
| 1476 | + } |
|
| 1477 | + return EE_Config::instance()->legacy_shortcodes_manager; |
|
| 1478 | + } |
|
| 1479 | + |
|
| 1480 | + |
|
| 1481 | + /** |
|
| 1482 | + * register_shortcode - makes core aware of this shortcode |
|
| 1483 | + * |
|
| 1484 | + * @deprecated 4.9.26 |
|
| 1485 | + * @param string $shortcode_path - full path up to and including shortcode folder |
|
| 1486 | + * @return bool |
|
| 1487 | + */ |
|
| 1488 | + public static function register_shortcode($shortcode_path = null) |
|
| 1489 | + { |
|
| 1490 | + EE_Error::doing_it_wrong( |
|
| 1491 | + __METHOD__, |
|
| 1492 | + __( |
|
| 1493 | + 'Usage is deprecated. Use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::registerShortcode() as direct replacement, or better yet, please see the new \EventEspresso\core\services\shortcodes\ShortcodesManager class.', |
|
| 1494 | + 'event_espresso' |
|
| 1495 | + ), |
|
| 1496 | + '4.9.26' |
|
| 1497 | + ); |
|
| 1498 | + return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path); |
|
| 1499 | + } |
|
| 1500 | +} |
|
| 2262 | 1501 | |
| 2263 | - /** |
|
| 2264 | - * ReCaptcha Type |
|
| 2265 | - * |
|
| 2266 | - * @var string $recaptcha_type |
|
| 2267 | - * options: 'audio', 'image' |
|
| 2268 | - */ |
|
| 2269 | - public $recaptcha_type; |
|
| 1502 | +/** |
|
| 1503 | + * Base class used for config classes. These classes should generally not have |
|
| 1504 | + * magic functions in use, except we'll allow them to magically set and get stuff... |
|
| 1505 | + * basically, they should just be well-defined stdClasses |
|
| 1506 | + */ |
|
| 1507 | +class EE_Config_Base |
|
| 1508 | +{ |
|
| 2270 | 1509 | |
| 2271 | - /** |
|
| 2272 | - * ReCaptcha language |
|
| 2273 | - * |
|
| 2274 | - * @var string $recaptcha_language |
|
| 2275 | - * eg 'en' |
|
| 2276 | - */ |
|
| 2277 | - public $recaptcha_language; |
|
| 1510 | + /** |
|
| 1511 | + * Utility function for escaping the value of a property and returning. |
|
| 1512 | + * |
|
| 1513 | + * @param string $property property name (checks to see if exists). |
|
| 1514 | + * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
| 1515 | + * @throws \EE_Error |
|
| 1516 | + */ |
|
| 1517 | + public function get_pretty($property) |
|
| 1518 | + { |
|
| 1519 | + if (! property_exists($this, $property)) { |
|
| 1520 | + throw new EE_Error( |
|
| 1521 | + sprintf( |
|
| 1522 | + __( |
|
| 1523 | + '%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.', |
|
| 1524 | + 'event_espresso' |
|
| 1525 | + ), |
|
| 1526 | + get_class($this), |
|
| 1527 | + $property |
|
| 1528 | + ) |
|
| 1529 | + ); |
|
| 1530 | + } |
|
| 1531 | + // just handling escaping of strings for now. |
|
| 1532 | + if (is_string($this->{$property})) { |
|
| 1533 | + return stripslashes($this->{$property}); |
|
| 1534 | + } |
|
| 1535 | + return $this->{$property}; |
|
| 1536 | + } |
|
| 1537 | + |
|
| 1538 | + |
|
| 1539 | + public function populate() |
|
| 1540 | + { |
|
| 1541 | + // grab defaults via a new instance of this class. |
|
| 1542 | + $class_name = get_class($this); |
|
| 1543 | + $defaults = new $class_name; |
|
| 1544 | + // loop through the properties for this class and see if they are set. If they are NOT, then grab the |
|
| 1545 | + // default from our $defaults object. |
|
| 1546 | + foreach (get_object_vars($defaults) as $property => $value) { |
|
| 1547 | + if ($this->{$property} === null) { |
|
| 1548 | + $this->{$property} = $value; |
|
| 1549 | + } |
|
| 1550 | + } |
|
| 1551 | + // cleanup |
|
| 1552 | + unset($defaults); |
|
| 1553 | + } |
|
| 1554 | + |
|
| 1555 | + |
|
| 1556 | + /** |
|
| 1557 | + * __isset |
|
| 1558 | + * |
|
| 1559 | + * @param $a |
|
| 1560 | + * @return bool |
|
| 1561 | + */ |
|
| 1562 | + public function __isset($a) |
|
| 1563 | + { |
|
| 1564 | + return false; |
|
| 1565 | + } |
|
| 1566 | + |
|
| 1567 | + |
|
| 1568 | + /** |
|
| 1569 | + * __unset |
|
| 1570 | + * |
|
| 1571 | + * @param $a |
|
| 1572 | + * @return bool |
|
| 1573 | + */ |
|
| 1574 | + public function __unset($a) |
|
| 1575 | + { |
|
| 1576 | + return false; |
|
| 1577 | + } |
|
| 1578 | + |
|
| 1579 | + |
|
| 1580 | + /** |
|
| 1581 | + * __clone |
|
| 1582 | + */ |
|
| 1583 | + public function __clone() |
|
| 1584 | + { |
|
| 1585 | + } |
|
| 1586 | + |
|
| 1587 | + |
|
| 1588 | + /** |
|
| 1589 | + * __wakeup |
|
| 1590 | + */ |
|
| 1591 | + public function __wakeup() |
|
| 1592 | + { |
|
| 1593 | + } |
|
| 1594 | + |
|
| 1595 | + |
|
| 1596 | + /** |
|
| 1597 | + * __destruct |
|
| 1598 | + */ |
|
| 1599 | + public function __destruct() |
|
| 1600 | + { |
|
| 1601 | + } |
|
| 1602 | +} |
|
| 2278 | 1603 | |
| 2279 | - /** |
|
| 2280 | - * ReCaptcha public key |
|
| 2281 | - * |
|
| 2282 | - * @var string $recaptcha_publickey |
|
| 2283 | - */ |
|
| 2284 | - public $recaptcha_publickey; |
|
| 1604 | +/** |
|
| 1605 | + * Class for defining what's in the EE_Config relating to registration settings |
|
| 1606 | + */ |
|
| 1607 | +class EE_Core_Config extends EE_Config_Base |
|
| 1608 | +{ |
|
| 2285 | 1609 | |
| 2286 | - /** |
|
| 2287 | - * ReCaptcha private key |
|
| 2288 | - * |
|
| 2289 | - * @var string $recaptcha_privatekey |
|
| 2290 | - */ |
|
| 2291 | - public $recaptcha_privatekey; |
|
| 1610 | + const OPTION_NAME_UXIP = 'ee_ueip_optin'; |
|
| 1611 | + |
|
| 1612 | + |
|
| 1613 | + public $current_blog_id; |
|
| 1614 | + |
|
| 1615 | + public $ee_ueip_optin; |
|
| 1616 | + |
|
| 1617 | + public $ee_ueip_has_notified; |
|
| 1618 | + |
|
| 1619 | + /** |
|
| 1620 | + * Not to be confused with the 4 critical page variables (See |
|
| 1621 | + * get_critical_pages_array()), this is just an array of wp posts that have EE |
|
| 1622 | + * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode |
|
| 1623 | + * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array. |
|
| 1624 | + * |
|
| 1625 | + * @var array |
|
| 1626 | + */ |
|
| 1627 | + public $post_shortcodes; |
|
| 1628 | + |
|
| 1629 | + public $module_route_map; |
|
| 1630 | + |
|
| 1631 | + public $module_forward_map; |
|
| 1632 | + |
|
| 1633 | + public $module_view_map; |
|
| 1634 | + |
|
| 1635 | + /** |
|
| 1636 | + * The next 4 vars are the IDs of critical EE pages. |
|
| 1637 | + * |
|
| 1638 | + * @var int |
|
| 1639 | + */ |
|
| 1640 | + public $reg_page_id; |
|
| 1641 | + |
|
| 1642 | + public $txn_page_id; |
|
| 1643 | + |
|
| 1644 | + public $thank_you_page_id; |
|
| 1645 | + |
|
| 1646 | + public $cancel_page_id; |
|
| 1647 | + |
|
| 1648 | + /** |
|
| 1649 | + * The next 4 vars are the URLs of critical EE pages. |
|
| 1650 | + * |
|
| 1651 | + * @var int |
|
| 1652 | + */ |
|
| 1653 | + public $reg_page_url; |
|
| 1654 | + |
|
| 1655 | + public $txn_page_url; |
|
| 1656 | + |
|
| 1657 | + public $thank_you_page_url; |
|
| 1658 | + |
|
| 1659 | + public $cancel_page_url; |
|
| 1660 | + |
|
| 1661 | + /** |
|
| 1662 | + * The next vars relate to the custom slugs for EE CPT routes |
|
| 1663 | + */ |
|
| 1664 | + public $event_cpt_slug; |
|
| 1665 | + |
|
| 1666 | + /** |
|
| 1667 | + * This caches the _ee_ueip_option in case this config is reset in the same |
|
| 1668 | + * request across blog switches in a multisite context. |
|
| 1669 | + * Avoids extra queries to the db for this option. |
|
| 1670 | + * |
|
| 1671 | + * @var bool |
|
| 1672 | + */ |
|
| 1673 | + public static $ee_ueip_option; |
|
| 1674 | + |
|
| 1675 | + |
|
| 1676 | + /** |
|
| 1677 | + * class constructor |
|
| 1678 | + * |
|
| 1679 | + * @access public |
|
| 1680 | + */ |
|
| 1681 | + public function __construct() |
|
| 1682 | + { |
|
| 1683 | + // set default organization settings |
|
| 1684 | + $this->current_blog_id = get_current_blog_id(); |
|
| 1685 | + $this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id; |
|
| 1686 | + $this->ee_ueip_optin = $this->_get_main_ee_ueip_optin(); |
|
| 1687 | + $this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true; |
|
| 1688 | + $this->post_shortcodes = array(); |
|
| 1689 | + $this->module_route_map = array(); |
|
| 1690 | + $this->module_forward_map = array(); |
|
| 1691 | + $this->module_view_map = array(); |
|
| 1692 | + // critical EE page IDs |
|
| 1693 | + $this->reg_page_id = 0; |
|
| 1694 | + $this->txn_page_id = 0; |
|
| 1695 | + $this->thank_you_page_id = 0; |
|
| 1696 | + $this->cancel_page_id = 0; |
|
| 1697 | + // critical EE page URLs |
|
| 1698 | + $this->reg_page_url = ''; |
|
| 1699 | + $this->txn_page_url = ''; |
|
| 1700 | + $this->thank_you_page_url = ''; |
|
| 1701 | + $this->cancel_page_url = ''; |
|
| 1702 | + // cpt slugs |
|
| 1703 | + $this->event_cpt_slug = __('events', 'event_espresso'); |
|
| 1704 | + // ueip constant check |
|
| 1705 | + if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) { |
|
| 1706 | + $this->ee_ueip_optin = false; |
|
| 1707 | + $this->ee_ueip_has_notified = true; |
|
| 1708 | + } |
|
| 1709 | + } |
|
| 1710 | + |
|
| 1711 | + |
|
| 1712 | + /** |
|
| 1713 | + * @return array |
|
| 1714 | + */ |
|
| 1715 | + public function get_critical_pages_array() |
|
| 1716 | + { |
|
| 1717 | + return array( |
|
| 1718 | + $this->reg_page_id, |
|
| 1719 | + $this->txn_page_id, |
|
| 1720 | + $this->thank_you_page_id, |
|
| 1721 | + $this->cancel_page_id, |
|
| 1722 | + ); |
|
| 1723 | + } |
|
| 1724 | + |
|
| 1725 | + |
|
| 1726 | + /** |
|
| 1727 | + * @return array |
|
| 1728 | + */ |
|
| 1729 | + public function get_critical_pages_shortcodes_array() |
|
| 1730 | + { |
|
| 1731 | + return array( |
|
| 1732 | + $this->reg_page_id => 'ESPRESSO_CHECKOUT', |
|
| 1733 | + $this->txn_page_id => 'ESPRESSO_TXN_PAGE', |
|
| 1734 | + $this->thank_you_page_id => 'ESPRESSO_THANK_YOU', |
|
| 1735 | + $this->cancel_page_id => 'ESPRESSO_CANCELLED', |
|
| 1736 | + ); |
|
| 1737 | + } |
|
| 1738 | + |
|
| 1739 | + |
|
| 1740 | + /** |
|
| 1741 | + * gets/returns URL for EE reg_page |
|
| 1742 | + * |
|
| 1743 | + * @access public |
|
| 1744 | + * @return string |
|
| 1745 | + */ |
|
| 1746 | + public function reg_page_url() |
|
| 1747 | + { |
|
| 1748 | + if (! $this->reg_page_url) { |
|
| 1749 | + $this->reg_page_url = add_query_arg( |
|
| 1750 | + array('uts' => time()), |
|
| 1751 | + get_permalink($this->reg_page_id) |
|
| 1752 | + ) . '#checkout'; |
|
| 1753 | + } |
|
| 1754 | + return $this->reg_page_url; |
|
| 1755 | + } |
|
| 1756 | + |
|
| 1757 | + |
|
| 1758 | + /** |
|
| 1759 | + * gets/returns URL for EE txn_page |
|
| 1760 | + * |
|
| 1761 | + * @param array $query_args like what gets passed to |
|
| 1762 | + * add_query_arg() as the first argument |
|
| 1763 | + * @access public |
|
| 1764 | + * @return string |
|
| 1765 | + */ |
|
| 1766 | + public function txn_page_url($query_args = array()) |
|
| 1767 | + { |
|
| 1768 | + if (! $this->txn_page_url) { |
|
| 1769 | + $this->txn_page_url = get_permalink($this->txn_page_id); |
|
| 1770 | + } |
|
| 1771 | + if ($query_args) { |
|
| 1772 | + return add_query_arg($query_args, $this->txn_page_url); |
|
| 1773 | + } else { |
|
| 1774 | + return $this->txn_page_url; |
|
| 1775 | + } |
|
| 1776 | + } |
|
| 1777 | + |
|
| 1778 | + |
|
| 1779 | + /** |
|
| 1780 | + * gets/returns URL for EE thank_you_page |
|
| 1781 | + * |
|
| 1782 | + * @param array $query_args like what gets passed to |
|
| 1783 | + * add_query_arg() as the first argument |
|
| 1784 | + * @access public |
|
| 1785 | + * @return string |
|
| 1786 | + */ |
|
| 1787 | + public function thank_you_page_url($query_args = array()) |
|
| 1788 | + { |
|
| 1789 | + if (! $this->thank_you_page_url) { |
|
| 1790 | + $this->thank_you_page_url = get_permalink($this->thank_you_page_id); |
|
| 1791 | + } |
|
| 1792 | + if ($query_args) { |
|
| 1793 | + return add_query_arg($query_args, $this->thank_you_page_url); |
|
| 1794 | + } else { |
|
| 1795 | + return $this->thank_you_page_url; |
|
| 1796 | + } |
|
| 1797 | + } |
|
| 1798 | + |
|
| 1799 | + |
|
| 1800 | + /** |
|
| 1801 | + * gets/returns URL for EE cancel_page |
|
| 1802 | + * |
|
| 1803 | + * @access public |
|
| 1804 | + * @return string |
|
| 1805 | + */ |
|
| 1806 | + public function cancel_page_url() |
|
| 1807 | + { |
|
| 1808 | + if (! $this->cancel_page_url) { |
|
| 1809 | + $this->cancel_page_url = get_permalink($this->cancel_page_id); |
|
| 1810 | + } |
|
| 1811 | + return $this->cancel_page_url; |
|
| 1812 | + } |
|
| 1813 | + |
|
| 1814 | + |
|
| 1815 | + /** |
|
| 1816 | + * Resets all critical page urls to their original state. Used primarily by the __sleep() magic method currently. |
|
| 1817 | + * |
|
| 1818 | + * @since 4.7.5 |
|
| 1819 | + */ |
|
| 1820 | + protected function _reset_urls() |
|
| 1821 | + { |
|
| 1822 | + $this->reg_page_url = ''; |
|
| 1823 | + $this->txn_page_url = ''; |
|
| 1824 | + $this->cancel_page_url = ''; |
|
| 1825 | + $this->thank_you_page_url = ''; |
|
| 1826 | + } |
|
| 1827 | + |
|
| 1828 | + |
|
| 1829 | + /** |
|
| 1830 | + * Used to return what the optin value is set for the EE User Experience Program. |
|
| 1831 | + * This accounts for multisite and this value being requested for a subsite. In multisite, the value is set |
|
| 1832 | + * on the main site only. |
|
| 1833 | + * |
|
| 1834 | + * @return bool |
|
| 1835 | + */ |
|
| 1836 | + protected function _get_main_ee_ueip_optin() |
|
| 1837 | + { |
|
| 1838 | + // if this is the main site then we can just bypass our direct query. |
|
| 1839 | + if (is_main_site()) { |
|
| 1840 | + return get_option(self::OPTION_NAME_UXIP, false); |
|
| 1841 | + } |
|
| 1842 | + // is this already cached for this request? If so use it. |
|
| 1843 | + if (EE_Core_Config::$ee_ueip_option !== null) { |
|
| 1844 | + return EE_Core_Config::$ee_ueip_option; |
|
| 1845 | + } |
|
| 1846 | + global $wpdb; |
|
| 1847 | + $current_network_main_site = is_multisite() ? get_current_site() : null; |
|
| 1848 | + $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1; |
|
| 1849 | + $option = self::OPTION_NAME_UXIP; |
|
| 1850 | + // set correct table for query |
|
| 1851 | + $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options'; |
|
| 1852 | + // rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because |
|
| 1853 | + // get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be |
|
| 1854 | + // re-constructed on the blog switch. Note, we are still executing any core wp filters on this option retrieval. |
|
| 1855 | + // this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog |
|
| 1856 | + // for the purpose of caching. |
|
| 1857 | + $pre = apply_filters('pre_option_' . $option, false, $option); |
|
| 1858 | + if (false !== $pre) { |
|
| 1859 | + EE_Core_Config::$ee_ueip_option = $pre; |
|
| 1860 | + return EE_Core_Config::$ee_ueip_option; |
|
| 1861 | + } |
|
| 1862 | + $row = $wpdb->get_row( |
|
| 1863 | + $wpdb->prepare( |
|
| 1864 | + "SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1", |
|
| 1865 | + $option |
|
| 1866 | + ) |
|
| 1867 | + ); |
|
| 1868 | + if (is_object($row)) { |
|
| 1869 | + $value = $row->option_value; |
|
| 1870 | + } else { // option does not exist so use default. |
|
| 1871 | + EE_Core_Config::$ee_ueip_option = apply_filters('default_option_' . $option, false, $option); |
|
| 1872 | + return EE_Core_Config::$ee_ueip_option; |
|
| 1873 | + } |
|
| 1874 | + EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option); |
|
| 1875 | + return EE_Core_Config::$ee_ueip_option; |
|
| 1876 | + } |
|
| 1877 | + |
|
| 1878 | + |
|
| 1879 | + /** |
|
| 1880 | + * Utility function for escaping the value of a property and returning. |
|
| 1881 | + * |
|
| 1882 | + * @param string $property property name (checks to see if exists). |
|
| 1883 | + * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
| 1884 | + * @throws \EE_Error |
|
| 1885 | + */ |
|
| 1886 | + public function get_pretty($property) |
|
| 1887 | + { |
|
| 1888 | + if ($property === self::OPTION_NAME_UXIP) { |
|
| 1889 | + return $this->ee_ueip_optin ? 'yes' : 'no'; |
|
| 1890 | + } |
|
| 1891 | + return parent::get_pretty($property); |
|
| 1892 | + } |
|
| 1893 | + |
|
| 1894 | + |
|
| 1895 | + /** |
|
| 1896 | + * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values |
|
| 1897 | + * on the object. |
|
| 1898 | + * |
|
| 1899 | + * @return array |
|
| 1900 | + */ |
|
| 1901 | + public function __sleep() |
|
| 1902 | + { |
|
| 1903 | + // reset all url properties |
|
| 1904 | + $this->_reset_urls(); |
|
| 1905 | + // return what to save to db |
|
| 1906 | + return array_keys(get_object_vars($this)); |
|
| 1907 | + } |
|
| 1908 | +} |
|
| 2292 | 1909 | |
| 2293 | - /** |
|
| 2294 | - * array of form names protected by ReCaptcha |
|
| 2295 | - * |
|
| 2296 | - * @var array $recaptcha_protected_forms |
|
| 2297 | - */ |
|
| 2298 | - public $recaptcha_protected_forms; |
|
| 1910 | +/** |
|
| 1911 | + * Config class for storing info on the Organization |
|
| 1912 | + */ |
|
| 1913 | +class EE_Organization_Config extends EE_Config_Base |
|
| 1914 | +{ |
|
| 2299 | 1915 | |
| 2300 | - /** |
|
| 2301 | - * ReCaptcha width |
|
| 2302 | - * |
|
| 2303 | - * @var int $recaptcha_width |
|
| 2304 | - * @deprecated |
|
| 2305 | - */ |
|
| 2306 | - public $recaptcha_width; |
|
| 1916 | + /** |
|
| 1917 | + * @var string $name |
|
| 1918 | + * eg EE4.1 |
|
| 1919 | + */ |
|
| 1920 | + public $name; |
|
| 1921 | + |
|
| 1922 | + /** |
|
| 1923 | + * @var string $address_1 |
|
| 1924 | + * eg 123 Onna Road |
|
| 1925 | + */ |
|
| 1926 | + public $address_1 = ''; |
|
| 1927 | + |
|
| 1928 | + /** |
|
| 1929 | + * @var string $address_2 |
|
| 1930 | + * eg PO Box 123 |
|
| 1931 | + */ |
|
| 1932 | + public $address_2 = ''; |
|
| 1933 | + |
|
| 1934 | + /** |
|
| 1935 | + * @var string $city |
|
| 1936 | + * eg Inna City |
|
| 1937 | + */ |
|
| 1938 | + public $city = ''; |
|
| 1939 | + |
|
| 1940 | + /** |
|
| 1941 | + * @var int $STA_ID |
|
| 1942 | + * eg 4 |
|
| 1943 | + */ |
|
| 1944 | + public $STA_ID = 0; |
|
| 1945 | + |
|
| 1946 | + /** |
|
| 1947 | + * @var string $CNT_ISO |
|
| 1948 | + * eg US |
|
| 1949 | + */ |
|
| 1950 | + public $CNT_ISO = ''; |
|
| 1951 | + |
|
| 1952 | + /** |
|
| 1953 | + * @var string $zip |
|
| 1954 | + * eg 12345 or V1A 2B3 |
|
| 1955 | + */ |
|
| 1956 | + public $zip = ''; |
|
| 1957 | + |
|
| 1958 | + /** |
|
| 1959 | + * @var string $email |
|
| 1960 | + * eg [email protected] |
|
| 1961 | + */ |
|
| 1962 | + public $email; |
|
| 1963 | + |
|
| 1964 | + /** |
|
| 1965 | + * @var string $phone |
|
| 1966 | + * eg. 111-111-1111 |
|
| 1967 | + */ |
|
| 1968 | + public $phone = ''; |
|
| 1969 | + |
|
| 1970 | + /** |
|
| 1971 | + * @var string $vat |
|
| 1972 | + * VAT/Tax Number |
|
| 1973 | + */ |
|
| 1974 | + public $vat = ''; |
|
| 1975 | + |
|
| 1976 | + /** |
|
| 1977 | + * @var string $logo_url |
|
| 1978 | + * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg |
|
| 1979 | + */ |
|
| 1980 | + public $logo_url = ''; |
|
| 1981 | + |
|
| 1982 | + /** |
|
| 1983 | + * The below are all various properties for holding links to organization social network profiles |
|
| 1984 | + * |
|
| 1985 | + * @var string |
|
| 1986 | + */ |
|
| 1987 | + /** |
|
| 1988 | + * facebook (facebook.com/profile.name) |
|
| 1989 | + * |
|
| 1990 | + * @var string |
|
| 1991 | + */ |
|
| 1992 | + public $facebook = ''; |
|
| 1993 | + |
|
| 1994 | + /** |
|
| 1995 | + * twitter (twitter.com/twitter_handle) |
|
| 1996 | + * |
|
| 1997 | + * @var string |
|
| 1998 | + */ |
|
| 1999 | + public $twitter = ''; |
|
| 2000 | + |
|
| 2001 | + /** |
|
| 2002 | + * linkedin (linkedin.com/in/profile_name) |
|
| 2003 | + * |
|
| 2004 | + * @var string |
|
| 2005 | + */ |
|
| 2006 | + public $linkedin = ''; |
|
| 2007 | + |
|
| 2008 | + /** |
|
| 2009 | + * pinterest (www.pinterest.com/profile_name) |
|
| 2010 | + * |
|
| 2011 | + * @var string |
|
| 2012 | + */ |
|
| 2013 | + public $pinterest = ''; |
|
| 2014 | + |
|
| 2015 | + /** |
|
| 2016 | + * google+ (google.com/+profileName) |
|
| 2017 | + * |
|
| 2018 | + * @var string |
|
| 2019 | + */ |
|
| 2020 | + public $google = ''; |
|
| 2021 | + |
|
| 2022 | + /** |
|
| 2023 | + * instagram (instagram.com/handle) |
|
| 2024 | + * |
|
| 2025 | + * @var string |
|
| 2026 | + */ |
|
| 2027 | + public $instagram = ''; |
|
| 2028 | + |
|
| 2029 | + |
|
| 2030 | + /** |
|
| 2031 | + * class constructor |
|
| 2032 | + * |
|
| 2033 | + * @access public |
|
| 2034 | + */ |
|
| 2035 | + public function __construct() |
|
| 2036 | + { |
|
| 2037 | + // set default organization settings |
|
| 2038 | + // decode HTML entities from the WP blogname, because it's stored in the DB with HTML entities encoded |
|
| 2039 | + $this->name = wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES); |
|
| 2040 | + $this->email = get_bloginfo('admin_email'); |
|
| 2041 | + } |
|
| 2042 | +} |
|
| 2307 | 2043 | |
| 2308 | - /** |
|
| 2309 | - * Whether or not invalid attempts to directly access the registration checkout page should be tracked. |
|
| 2310 | - * |
|
| 2311 | - * @var boolean $track_invalid_checkout_access |
|
| 2312 | - */ |
|
| 2313 | - protected $track_invalid_checkout_access = true; |
|
| 2044 | +/** |
|
| 2045 | + * Class for defining what's in the EE_Config relating to currency |
|
| 2046 | + */ |
|
| 2047 | +class EE_Currency_Config extends EE_Config_Base |
|
| 2048 | +{ |
|
| 2314 | 2049 | |
| 2315 | - /** |
|
| 2316 | - * Whether or not to show the privacy policy consent checkbox |
|
| 2317 | - * |
|
| 2318 | - * @var bool |
|
| 2319 | - */ |
|
| 2320 | - public $consent_checkbox_enabled; |
|
| 2050 | + /** |
|
| 2051 | + * @var string $code |
|
| 2052 | + * eg 'US' |
|
| 2053 | + */ |
|
| 2054 | + public $code; |
|
| 2055 | + |
|
| 2056 | + /** |
|
| 2057 | + * @var string $name |
|
| 2058 | + * eg 'Dollar' |
|
| 2059 | + */ |
|
| 2060 | + public $name; |
|
| 2061 | + |
|
| 2062 | + /** |
|
| 2063 | + * plural name |
|
| 2064 | + * |
|
| 2065 | + * @var string $plural |
|
| 2066 | + * eg 'Dollars' |
|
| 2067 | + */ |
|
| 2068 | + public $plural; |
|
| 2069 | + |
|
| 2070 | + /** |
|
| 2071 | + * currency sign |
|
| 2072 | + * |
|
| 2073 | + * @var string $sign |
|
| 2074 | + * eg '$' |
|
| 2075 | + */ |
|
| 2076 | + public $sign; |
|
| 2077 | + |
|
| 2078 | + /** |
|
| 2079 | + * Whether the currency sign should come before the number or not |
|
| 2080 | + * |
|
| 2081 | + * @var boolean $sign_b4 |
|
| 2082 | + */ |
|
| 2083 | + public $sign_b4; |
|
| 2084 | + |
|
| 2085 | + /** |
|
| 2086 | + * How many digits should come after the decimal place |
|
| 2087 | + * |
|
| 2088 | + * @var int $dec_plc |
|
| 2089 | + */ |
|
| 2090 | + public $dec_plc; |
|
| 2091 | + |
|
| 2092 | + /** |
|
| 2093 | + * Symbol to use for decimal mark |
|
| 2094 | + * |
|
| 2095 | + * @var string $dec_mrk |
|
| 2096 | + * eg '.' |
|
| 2097 | + */ |
|
| 2098 | + public $dec_mrk; |
|
| 2099 | + |
|
| 2100 | + /** |
|
| 2101 | + * Symbol to use for thousands |
|
| 2102 | + * |
|
| 2103 | + * @var string $thsnds |
|
| 2104 | + * eg ',' |
|
| 2105 | + */ |
|
| 2106 | + public $thsnds; |
|
| 2107 | + |
|
| 2108 | + |
|
| 2109 | + /** |
|
| 2110 | + * class constructor |
|
| 2111 | + * |
|
| 2112 | + * @access public |
|
| 2113 | + * @param string $CNT_ISO |
|
| 2114 | + * @throws \EE_Error |
|
| 2115 | + */ |
|
| 2116 | + public function __construct($CNT_ISO = '') |
|
| 2117 | + { |
|
| 2118 | + /** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */ |
|
| 2119 | + $table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
| 2120 | + // get country code from organization settings or use default |
|
| 2121 | + $ORG_CNT = isset(EE_Registry::instance()->CFG->organization) |
|
| 2122 | + && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config |
|
| 2123 | + ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
| 2124 | + : ''; |
|
| 2125 | + // but override if requested |
|
| 2126 | + $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT; |
|
| 2127 | + // so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists |
|
| 2128 | + if (! empty($CNT_ISO) |
|
| 2129 | + && EE_Maintenance_Mode::instance()->models_can_query() |
|
| 2130 | + && $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table()) |
|
| 2131 | + ) { |
|
| 2132 | + // retrieve the country settings from the db, just in case they have been customized |
|
| 2133 | + $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO); |
|
| 2134 | + if ($country instanceof EE_Country) { |
|
| 2135 | + $this->code = $country->currency_code(); // currency code: USD, CAD, EUR |
|
| 2136 | + $this->name = $country->currency_name_single(); // Dollar |
|
| 2137 | + $this->plural = $country->currency_name_plural(); // Dollars |
|
| 2138 | + $this->sign = $country->currency_sign(); // currency sign: $ |
|
| 2139 | + $this->sign_b4 = $country->currency_sign_before( |
|
| 2140 | + ); // currency sign before or after: $TRUE or FALSE$ |
|
| 2141 | + $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2142 | + $this->dec_mrk = $country->currency_decimal_mark( |
|
| 2143 | + ); // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2144 | + $this->thsnds = $country->currency_thousands_separator( |
|
| 2145 | + ); // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2146 | + } |
|
| 2147 | + } |
|
| 2148 | + // fallback to hardcoded defaults, in case the above failed |
|
| 2149 | + if (empty($this->code)) { |
|
| 2150 | + // set default currency settings |
|
| 2151 | + $this->code = 'USD'; // currency code: USD, CAD, EUR |
|
| 2152 | + $this->name = __('Dollar', 'event_espresso'); // Dollar |
|
| 2153 | + $this->plural = __('Dollars', 'event_espresso'); // Dollars |
|
| 2154 | + $this->sign = '$'; // currency sign: $ |
|
| 2155 | + $this->sign_b4 = true; // currency sign before or after: $TRUE or FALSE$ |
|
| 2156 | + $this->dec_plc = 2; // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2157 | + $this->dec_mrk = '.'; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2158 | + $this->thsnds = ','; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2159 | + } |
|
| 2160 | + } |
|
| 2161 | +} |
|
| 2321 | 2162 | |
| 2322 | - /** |
|
| 2323 | - * Label text to show on the checkbox |
|
| 2324 | - * |
|
| 2325 | - * @var string |
|
| 2326 | - */ |
|
| 2327 | - public $consent_checkbox_label_text; |
|
| 2163 | +/** |
|
| 2164 | + * Class for defining what's in the EE_Config relating to registration settings |
|
| 2165 | + */ |
|
| 2166 | +class EE_Registration_Config extends EE_Config_Base |
|
| 2167 | +{ |
|
| 2328 | 2168 | |
| 2329 | - /* |
|
| 2169 | + /** |
|
| 2170 | + * Default registration status |
|
| 2171 | + * |
|
| 2172 | + * @var string $default_STS_ID |
|
| 2173 | + * eg 'RPP' |
|
| 2174 | + */ |
|
| 2175 | + public $default_STS_ID; |
|
| 2176 | + |
|
| 2177 | + /** |
|
| 2178 | + * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of |
|
| 2179 | + * registrations) |
|
| 2180 | + * |
|
| 2181 | + * @var int |
|
| 2182 | + */ |
|
| 2183 | + public $default_maximum_number_of_tickets; |
|
| 2184 | + |
|
| 2185 | + /** |
|
| 2186 | + * level of validation to apply to email addresses |
|
| 2187 | + * |
|
| 2188 | + * @var string $email_validation_level |
|
| 2189 | + * options: 'basic', 'wp_default', 'i18n', 'i18n_dns' |
|
| 2190 | + */ |
|
| 2191 | + public $email_validation_level; |
|
| 2192 | + |
|
| 2193 | + /** |
|
| 2194 | + * whether or not to show alternate payment options during the reg process if payment status is pending |
|
| 2195 | + * |
|
| 2196 | + * @var boolean $show_pending_payment_options |
|
| 2197 | + */ |
|
| 2198 | + public $show_pending_payment_options; |
|
| 2199 | + |
|
| 2200 | + /** |
|
| 2201 | + * Whether to skip the registration confirmation page |
|
| 2202 | + * |
|
| 2203 | + * @var boolean $skip_reg_confirmation |
|
| 2204 | + */ |
|
| 2205 | + public $skip_reg_confirmation; |
|
| 2206 | + |
|
| 2207 | + /** |
|
| 2208 | + * an array of SPCO reg steps where: |
|
| 2209 | + * the keys denotes the reg step order |
|
| 2210 | + * each element consists of an array with the following elements: |
|
| 2211 | + * "file_path" => the file path to the EE_SPCO_Reg_Step class |
|
| 2212 | + * "class_name" => the specific EE_SPCO_Reg_Step child class name |
|
| 2213 | + * "slug" => the URL param used to trigger the reg step |
|
| 2214 | + * |
|
| 2215 | + * @var array $reg_steps |
|
| 2216 | + */ |
|
| 2217 | + public $reg_steps; |
|
| 2218 | + |
|
| 2219 | + /** |
|
| 2220 | + * Whether registration confirmation should be the last page of SPCO |
|
| 2221 | + * |
|
| 2222 | + * @var boolean $reg_confirmation_last |
|
| 2223 | + */ |
|
| 2224 | + public $reg_confirmation_last; |
|
| 2225 | + |
|
| 2226 | + /** |
|
| 2227 | + * Whether or not to enable the EE Bot Trap |
|
| 2228 | + * |
|
| 2229 | + * @var boolean $use_bot_trap |
|
| 2230 | + */ |
|
| 2231 | + public $use_bot_trap; |
|
| 2232 | + |
|
| 2233 | + /** |
|
| 2234 | + * Whether or not to encrypt some data sent by the EE Bot Trap |
|
| 2235 | + * |
|
| 2236 | + * @var boolean $use_encryption |
|
| 2237 | + */ |
|
| 2238 | + public $use_encryption; |
|
| 2239 | + |
|
| 2240 | + /** |
|
| 2241 | + * Whether or not to use ReCaptcha |
|
| 2242 | + * |
|
| 2243 | + * @var boolean $use_captcha |
|
| 2244 | + */ |
|
| 2245 | + public $use_captcha; |
|
| 2246 | + |
|
| 2247 | + /** |
|
| 2248 | + * ReCaptcha Theme |
|
| 2249 | + * |
|
| 2250 | + * @var string $recaptcha_theme |
|
| 2251 | + * options: 'dark', 'light', 'invisible' |
|
| 2252 | + */ |
|
| 2253 | + public $recaptcha_theme; |
|
| 2254 | + |
|
| 2255 | + /** |
|
| 2256 | + * ReCaptcha Badge - determines the position of the reCAPTCHA badge if using Invisible ReCaptcha. |
|
| 2257 | + * |
|
| 2258 | + * @var string $recaptcha_badge |
|
| 2259 | + * options: 'bottomright', 'bottomleft', 'inline' |
|
| 2260 | + */ |
|
| 2261 | + public $recaptcha_badge; |
|
| 2262 | + |
|
| 2263 | + /** |
|
| 2264 | + * ReCaptcha Type |
|
| 2265 | + * |
|
| 2266 | + * @var string $recaptcha_type |
|
| 2267 | + * options: 'audio', 'image' |
|
| 2268 | + */ |
|
| 2269 | + public $recaptcha_type; |
|
| 2270 | + |
|
| 2271 | + /** |
|
| 2272 | + * ReCaptcha language |
|
| 2273 | + * |
|
| 2274 | + * @var string $recaptcha_language |
|
| 2275 | + * eg 'en' |
|
| 2276 | + */ |
|
| 2277 | + public $recaptcha_language; |
|
| 2278 | + |
|
| 2279 | + /** |
|
| 2280 | + * ReCaptcha public key |
|
| 2281 | + * |
|
| 2282 | + * @var string $recaptcha_publickey |
|
| 2283 | + */ |
|
| 2284 | + public $recaptcha_publickey; |
|
| 2285 | + |
|
| 2286 | + /** |
|
| 2287 | + * ReCaptcha private key |
|
| 2288 | + * |
|
| 2289 | + * @var string $recaptcha_privatekey |
|
| 2290 | + */ |
|
| 2291 | + public $recaptcha_privatekey; |
|
| 2292 | + |
|
| 2293 | + /** |
|
| 2294 | + * array of form names protected by ReCaptcha |
|
| 2295 | + * |
|
| 2296 | + * @var array $recaptcha_protected_forms |
|
| 2297 | + */ |
|
| 2298 | + public $recaptcha_protected_forms; |
|
| 2299 | + |
|
| 2300 | + /** |
|
| 2301 | + * ReCaptcha width |
|
| 2302 | + * |
|
| 2303 | + * @var int $recaptcha_width |
|
| 2304 | + * @deprecated |
|
| 2305 | + */ |
|
| 2306 | + public $recaptcha_width; |
|
| 2307 | + |
|
| 2308 | + /** |
|
| 2309 | + * Whether or not invalid attempts to directly access the registration checkout page should be tracked. |
|
| 2310 | + * |
|
| 2311 | + * @var boolean $track_invalid_checkout_access |
|
| 2312 | + */ |
|
| 2313 | + protected $track_invalid_checkout_access = true; |
|
| 2314 | + |
|
| 2315 | + /** |
|
| 2316 | + * Whether or not to show the privacy policy consent checkbox |
|
| 2317 | + * |
|
| 2318 | + * @var bool |
|
| 2319 | + */ |
|
| 2320 | + public $consent_checkbox_enabled; |
|
| 2321 | + |
|
| 2322 | + /** |
|
| 2323 | + * Label text to show on the checkbox |
|
| 2324 | + * |
|
| 2325 | + * @var string |
|
| 2326 | + */ |
|
| 2327 | + public $consent_checkbox_label_text; |
|
| 2328 | + |
|
| 2329 | + /* |
|
| 2330 | 2330 | * String describing how long to keep payment logs. Passed into DateTime constructor |
| 2331 | 2331 | * @var string |
| 2332 | 2332 | */ |
| 2333 | - public $gateway_log_lifespan = '1 week'; |
|
| 2334 | - |
|
| 2335 | - /** |
|
| 2336 | - * Enable copy attendee info at form |
|
| 2337 | - * |
|
| 2338 | - * @var boolean $enable_copy_attendee |
|
| 2339 | - */ |
|
| 2340 | - protected $copy_attendee_info = true; |
|
| 2341 | - |
|
| 2342 | - |
|
| 2343 | - /** |
|
| 2344 | - * class constructor |
|
| 2345 | - * |
|
| 2346 | - * @access public |
|
| 2347 | - */ |
|
| 2348 | - public function __construct() |
|
| 2349 | - { |
|
| 2350 | - // set default registration settings |
|
| 2351 | - $this->default_STS_ID = EEM_Registration::status_id_pending_payment; |
|
| 2352 | - $this->email_validation_level = 'wp_default'; |
|
| 2353 | - $this->show_pending_payment_options = true; |
|
| 2354 | - $this->skip_reg_confirmation = true; |
|
| 2355 | - $this->reg_steps = array(); |
|
| 2356 | - $this->reg_confirmation_last = false; |
|
| 2357 | - $this->use_bot_trap = true; |
|
| 2358 | - $this->use_encryption = true; |
|
| 2359 | - $this->use_captcha = false; |
|
| 2360 | - $this->recaptcha_theme = 'light'; |
|
| 2361 | - $this->recaptcha_badge = 'bottomleft'; |
|
| 2362 | - $this->recaptcha_type = 'image'; |
|
| 2363 | - $this->recaptcha_language = 'en'; |
|
| 2364 | - $this->recaptcha_publickey = null; |
|
| 2365 | - $this->recaptcha_privatekey = null; |
|
| 2366 | - $this->recaptcha_protected_forms = array(); |
|
| 2367 | - $this->recaptcha_width = 500; |
|
| 2368 | - $this->default_maximum_number_of_tickets = 10; |
|
| 2369 | - $this->consent_checkbox_enabled = false; |
|
| 2370 | - $this->consent_checkbox_label_text = ''; |
|
| 2371 | - $this->gateway_log_lifespan = '7 days'; |
|
| 2372 | - $this->copy_attendee_info = true; |
|
| 2373 | - } |
|
| 2374 | - |
|
| 2375 | - |
|
| 2376 | - /** |
|
| 2377 | - * This is called by the config loader and hooks are initialized AFTER the config has been populated. |
|
| 2378 | - * |
|
| 2379 | - * @since 4.8.8.rc.019 |
|
| 2380 | - */ |
|
| 2381 | - public function do_hooks() |
|
| 2382 | - { |
|
| 2383 | - add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event')); |
|
| 2384 | - add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event')); |
|
| 2385 | - add_action('setup_theme', array($this, 'setDefaultCheckboxLabelText')); |
|
| 2386 | - } |
|
| 2387 | - |
|
| 2388 | - |
|
| 2389 | - /** |
|
| 2390 | - * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the |
|
| 2391 | - * EVT_default_registration_status field matches the config setting for default_STS_ID. |
|
| 2392 | - */ |
|
| 2393 | - public function set_default_reg_status_on_EEM_Event() |
|
| 2394 | - { |
|
| 2395 | - EEM_Event::set_default_reg_status($this->default_STS_ID); |
|
| 2396 | - } |
|
| 2397 | - |
|
| 2398 | - |
|
| 2399 | - /** |
|
| 2400 | - * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field |
|
| 2401 | - * for Events matches the config setting for default_maximum_number_of_tickets |
|
| 2402 | - */ |
|
| 2403 | - public function set_default_max_ticket_on_EEM_Event() |
|
| 2404 | - { |
|
| 2405 | - EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets); |
|
| 2406 | - } |
|
| 2407 | - |
|
| 2408 | - |
|
| 2409 | - /** |
|
| 2410 | - * Sets the default consent checkbox text. This needs to be done a bit later than when EE_Registration_Config is |
|
| 2411 | - * constructed because that happens before we can get the privacy policy page's permalink. |
|
| 2412 | - * |
|
| 2413 | - * @throws InvalidArgumentException |
|
| 2414 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2415 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2416 | - */ |
|
| 2417 | - public function setDefaultCheckboxLabelText() |
|
| 2418 | - { |
|
| 2419 | - if ($this->getConsentCheckboxLabelText() === null |
|
| 2420 | - || $this->getConsentCheckboxLabelText() === '') { |
|
| 2421 | - $opening_a_tag = ''; |
|
| 2422 | - $closing_a_tag = ''; |
|
| 2423 | - if (function_exists('get_privacy_policy_url')) { |
|
| 2424 | - $privacy_page_url = get_privacy_policy_url(); |
|
| 2425 | - if (! empty($privacy_page_url)) { |
|
| 2426 | - $opening_a_tag = '<a href="' . $privacy_page_url . '" target="_blank">'; |
|
| 2427 | - $closing_a_tag = '</a>'; |
|
| 2428 | - } |
|
| 2429 | - } |
|
| 2430 | - $loader = LoaderFactory::getLoader(); |
|
| 2431 | - $org_config = $loader->getShared('EE_Organization_Config'); |
|
| 2432 | - /** |
|
| 2433 | - * @var $org_config EE_Organization_Config |
|
| 2434 | - */ |
|
| 2435 | - |
|
| 2436 | - $this->setConsentCheckboxLabelText( |
|
| 2437 | - sprintf( |
|
| 2438 | - esc_html__( |
|
| 2439 | - 'I consent to %1$s storing and using my personal information, according to their %2$sprivacy policy%3$s.', |
|
| 2440 | - 'event_espresso' |
|
| 2441 | - ), |
|
| 2442 | - $org_config->name, |
|
| 2443 | - $opening_a_tag, |
|
| 2444 | - $closing_a_tag |
|
| 2445 | - ) |
|
| 2446 | - ); |
|
| 2447 | - } |
|
| 2448 | - } |
|
| 2449 | - |
|
| 2450 | - |
|
| 2451 | - /** |
|
| 2452 | - * @return boolean |
|
| 2453 | - */ |
|
| 2454 | - public function track_invalid_checkout_access() |
|
| 2455 | - { |
|
| 2456 | - return $this->track_invalid_checkout_access; |
|
| 2457 | - } |
|
| 2458 | - |
|
| 2459 | - |
|
| 2460 | - /** |
|
| 2461 | - * @param boolean $track_invalid_checkout_access |
|
| 2462 | - */ |
|
| 2463 | - public function set_track_invalid_checkout_access($track_invalid_checkout_access) |
|
| 2464 | - { |
|
| 2465 | - $this->track_invalid_checkout_access = filter_var( |
|
| 2466 | - $track_invalid_checkout_access, |
|
| 2467 | - FILTER_VALIDATE_BOOLEAN |
|
| 2468 | - ); |
|
| 2469 | - } |
|
| 2470 | - |
|
| 2471 | - /** |
|
| 2472 | - * @return boolean |
|
| 2473 | - */ |
|
| 2474 | - public function copyAttendeeInfo() |
|
| 2475 | - { |
|
| 2476 | - return $this->copy_attendee_info; |
|
| 2477 | - } |
|
| 2478 | - |
|
| 2479 | - |
|
| 2480 | - /** |
|
| 2481 | - * @param boolean $copy_attendee_info |
|
| 2482 | - */ |
|
| 2483 | - public function setCopyAttendeeInfo($copy_attendee_info) |
|
| 2484 | - { |
|
| 2485 | - $this->copy_attendee_info = filter_var( |
|
| 2486 | - $copy_attendee_info, |
|
| 2487 | - FILTER_VALIDATE_BOOLEAN |
|
| 2488 | - ); |
|
| 2489 | - } |
|
| 2490 | - |
|
| 2491 | - |
|
| 2492 | - /** |
|
| 2493 | - * Gets the options to make availalbe for the gateway log lifespan |
|
| 2494 | - * @return array |
|
| 2495 | - */ |
|
| 2496 | - public function gatewayLogLifespanOptions() |
|
| 2497 | - { |
|
| 2498 | - return (array) apply_filters( |
|
| 2499 | - 'FHEE_EE_Admin_Config__gatewayLogLifespanOptions', |
|
| 2500 | - array( |
|
| 2501 | - '1 second' => esc_html__('Don\'t Log At All', 'event_espresso'), |
|
| 2502 | - '1 day' => esc_html__('1 Day', 'event_espresso'), |
|
| 2503 | - '7 days' => esc_html__('7 Days', 'event_espresso'), |
|
| 2504 | - '14 days' => esc_html__('14 Days', 'event_espresso'), |
|
| 2505 | - '30 days' => esc_html__('30 Days', 'event_espresso') |
|
| 2506 | - ) |
|
| 2507 | - ); |
|
| 2508 | - } |
|
| 2509 | - |
|
| 2510 | - |
|
| 2511 | - /** |
|
| 2512 | - * @return bool |
|
| 2513 | - */ |
|
| 2514 | - public function isConsentCheckboxEnabled() |
|
| 2515 | - { |
|
| 2516 | - return $this->consent_checkbox_enabled; |
|
| 2517 | - } |
|
| 2518 | - |
|
| 2519 | - |
|
| 2520 | - /** |
|
| 2521 | - * @param bool $consent_checkbox_enabled |
|
| 2522 | - */ |
|
| 2523 | - public function setConsentCheckboxEnabled($consent_checkbox_enabled) |
|
| 2524 | - { |
|
| 2525 | - $this->consent_checkbox_enabled = filter_var( |
|
| 2526 | - $consent_checkbox_enabled, |
|
| 2527 | - FILTER_VALIDATE_BOOLEAN |
|
| 2528 | - ); |
|
| 2529 | - } |
|
| 2530 | - |
|
| 2531 | - |
|
| 2532 | - /** |
|
| 2533 | - * @return string |
|
| 2534 | - */ |
|
| 2535 | - public function getConsentCheckboxLabelText() |
|
| 2536 | - { |
|
| 2537 | - return $this->consent_checkbox_label_text; |
|
| 2538 | - } |
|
| 2539 | - |
|
| 2540 | - |
|
| 2541 | - /** |
|
| 2542 | - * @param string $consent_checkbox_label_text |
|
| 2543 | - */ |
|
| 2544 | - public function setConsentCheckboxLabelText($consent_checkbox_label_text) |
|
| 2545 | - { |
|
| 2546 | - $this->consent_checkbox_label_text = (string) $consent_checkbox_label_text; |
|
| 2547 | - } |
|
| 2333 | + public $gateway_log_lifespan = '1 week'; |
|
| 2334 | + |
|
| 2335 | + /** |
|
| 2336 | + * Enable copy attendee info at form |
|
| 2337 | + * |
|
| 2338 | + * @var boolean $enable_copy_attendee |
|
| 2339 | + */ |
|
| 2340 | + protected $copy_attendee_info = true; |
|
| 2341 | + |
|
| 2342 | + |
|
| 2343 | + /** |
|
| 2344 | + * class constructor |
|
| 2345 | + * |
|
| 2346 | + * @access public |
|
| 2347 | + */ |
|
| 2348 | + public function __construct() |
|
| 2349 | + { |
|
| 2350 | + // set default registration settings |
|
| 2351 | + $this->default_STS_ID = EEM_Registration::status_id_pending_payment; |
|
| 2352 | + $this->email_validation_level = 'wp_default'; |
|
| 2353 | + $this->show_pending_payment_options = true; |
|
| 2354 | + $this->skip_reg_confirmation = true; |
|
| 2355 | + $this->reg_steps = array(); |
|
| 2356 | + $this->reg_confirmation_last = false; |
|
| 2357 | + $this->use_bot_trap = true; |
|
| 2358 | + $this->use_encryption = true; |
|
| 2359 | + $this->use_captcha = false; |
|
| 2360 | + $this->recaptcha_theme = 'light'; |
|
| 2361 | + $this->recaptcha_badge = 'bottomleft'; |
|
| 2362 | + $this->recaptcha_type = 'image'; |
|
| 2363 | + $this->recaptcha_language = 'en'; |
|
| 2364 | + $this->recaptcha_publickey = null; |
|
| 2365 | + $this->recaptcha_privatekey = null; |
|
| 2366 | + $this->recaptcha_protected_forms = array(); |
|
| 2367 | + $this->recaptcha_width = 500; |
|
| 2368 | + $this->default_maximum_number_of_tickets = 10; |
|
| 2369 | + $this->consent_checkbox_enabled = false; |
|
| 2370 | + $this->consent_checkbox_label_text = ''; |
|
| 2371 | + $this->gateway_log_lifespan = '7 days'; |
|
| 2372 | + $this->copy_attendee_info = true; |
|
| 2373 | + } |
|
| 2374 | + |
|
| 2375 | + |
|
| 2376 | + /** |
|
| 2377 | + * This is called by the config loader and hooks are initialized AFTER the config has been populated. |
|
| 2378 | + * |
|
| 2379 | + * @since 4.8.8.rc.019 |
|
| 2380 | + */ |
|
| 2381 | + public function do_hooks() |
|
| 2382 | + { |
|
| 2383 | + add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event')); |
|
| 2384 | + add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event')); |
|
| 2385 | + add_action('setup_theme', array($this, 'setDefaultCheckboxLabelText')); |
|
| 2386 | + } |
|
| 2387 | + |
|
| 2388 | + |
|
| 2389 | + /** |
|
| 2390 | + * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the |
|
| 2391 | + * EVT_default_registration_status field matches the config setting for default_STS_ID. |
|
| 2392 | + */ |
|
| 2393 | + public function set_default_reg_status_on_EEM_Event() |
|
| 2394 | + { |
|
| 2395 | + EEM_Event::set_default_reg_status($this->default_STS_ID); |
|
| 2396 | + } |
|
| 2397 | + |
|
| 2398 | + |
|
| 2399 | + /** |
|
| 2400 | + * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field |
|
| 2401 | + * for Events matches the config setting for default_maximum_number_of_tickets |
|
| 2402 | + */ |
|
| 2403 | + public function set_default_max_ticket_on_EEM_Event() |
|
| 2404 | + { |
|
| 2405 | + EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets); |
|
| 2406 | + } |
|
| 2407 | + |
|
| 2408 | + |
|
| 2409 | + /** |
|
| 2410 | + * Sets the default consent checkbox text. This needs to be done a bit later than when EE_Registration_Config is |
|
| 2411 | + * constructed because that happens before we can get the privacy policy page's permalink. |
|
| 2412 | + * |
|
| 2413 | + * @throws InvalidArgumentException |
|
| 2414 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2415 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2416 | + */ |
|
| 2417 | + public function setDefaultCheckboxLabelText() |
|
| 2418 | + { |
|
| 2419 | + if ($this->getConsentCheckboxLabelText() === null |
|
| 2420 | + || $this->getConsentCheckboxLabelText() === '') { |
|
| 2421 | + $opening_a_tag = ''; |
|
| 2422 | + $closing_a_tag = ''; |
|
| 2423 | + if (function_exists('get_privacy_policy_url')) { |
|
| 2424 | + $privacy_page_url = get_privacy_policy_url(); |
|
| 2425 | + if (! empty($privacy_page_url)) { |
|
| 2426 | + $opening_a_tag = '<a href="' . $privacy_page_url . '" target="_blank">'; |
|
| 2427 | + $closing_a_tag = '</a>'; |
|
| 2428 | + } |
|
| 2429 | + } |
|
| 2430 | + $loader = LoaderFactory::getLoader(); |
|
| 2431 | + $org_config = $loader->getShared('EE_Organization_Config'); |
|
| 2432 | + /** |
|
| 2433 | + * @var $org_config EE_Organization_Config |
|
| 2434 | + */ |
|
| 2435 | + |
|
| 2436 | + $this->setConsentCheckboxLabelText( |
|
| 2437 | + sprintf( |
|
| 2438 | + esc_html__( |
|
| 2439 | + 'I consent to %1$s storing and using my personal information, according to their %2$sprivacy policy%3$s.', |
|
| 2440 | + 'event_espresso' |
|
| 2441 | + ), |
|
| 2442 | + $org_config->name, |
|
| 2443 | + $opening_a_tag, |
|
| 2444 | + $closing_a_tag |
|
| 2445 | + ) |
|
| 2446 | + ); |
|
| 2447 | + } |
|
| 2448 | + } |
|
| 2449 | + |
|
| 2450 | + |
|
| 2451 | + /** |
|
| 2452 | + * @return boolean |
|
| 2453 | + */ |
|
| 2454 | + public function track_invalid_checkout_access() |
|
| 2455 | + { |
|
| 2456 | + return $this->track_invalid_checkout_access; |
|
| 2457 | + } |
|
| 2458 | + |
|
| 2459 | + |
|
| 2460 | + /** |
|
| 2461 | + * @param boolean $track_invalid_checkout_access |
|
| 2462 | + */ |
|
| 2463 | + public function set_track_invalid_checkout_access($track_invalid_checkout_access) |
|
| 2464 | + { |
|
| 2465 | + $this->track_invalid_checkout_access = filter_var( |
|
| 2466 | + $track_invalid_checkout_access, |
|
| 2467 | + FILTER_VALIDATE_BOOLEAN |
|
| 2468 | + ); |
|
| 2469 | + } |
|
| 2470 | + |
|
| 2471 | + /** |
|
| 2472 | + * @return boolean |
|
| 2473 | + */ |
|
| 2474 | + public function copyAttendeeInfo() |
|
| 2475 | + { |
|
| 2476 | + return $this->copy_attendee_info; |
|
| 2477 | + } |
|
| 2478 | + |
|
| 2479 | + |
|
| 2480 | + /** |
|
| 2481 | + * @param boolean $copy_attendee_info |
|
| 2482 | + */ |
|
| 2483 | + public function setCopyAttendeeInfo($copy_attendee_info) |
|
| 2484 | + { |
|
| 2485 | + $this->copy_attendee_info = filter_var( |
|
| 2486 | + $copy_attendee_info, |
|
| 2487 | + FILTER_VALIDATE_BOOLEAN |
|
| 2488 | + ); |
|
| 2489 | + } |
|
| 2490 | + |
|
| 2491 | + |
|
| 2492 | + /** |
|
| 2493 | + * Gets the options to make availalbe for the gateway log lifespan |
|
| 2494 | + * @return array |
|
| 2495 | + */ |
|
| 2496 | + public function gatewayLogLifespanOptions() |
|
| 2497 | + { |
|
| 2498 | + return (array) apply_filters( |
|
| 2499 | + 'FHEE_EE_Admin_Config__gatewayLogLifespanOptions', |
|
| 2500 | + array( |
|
| 2501 | + '1 second' => esc_html__('Don\'t Log At All', 'event_espresso'), |
|
| 2502 | + '1 day' => esc_html__('1 Day', 'event_espresso'), |
|
| 2503 | + '7 days' => esc_html__('7 Days', 'event_espresso'), |
|
| 2504 | + '14 days' => esc_html__('14 Days', 'event_espresso'), |
|
| 2505 | + '30 days' => esc_html__('30 Days', 'event_espresso') |
|
| 2506 | + ) |
|
| 2507 | + ); |
|
| 2508 | + } |
|
| 2509 | + |
|
| 2510 | + |
|
| 2511 | + /** |
|
| 2512 | + * @return bool |
|
| 2513 | + */ |
|
| 2514 | + public function isConsentCheckboxEnabled() |
|
| 2515 | + { |
|
| 2516 | + return $this->consent_checkbox_enabled; |
|
| 2517 | + } |
|
| 2518 | + |
|
| 2519 | + |
|
| 2520 | + /** |
|
| 2521 | + * @param bool $consent_checkbox_enabled |
|
| 2522 | + */ |
|
| 2523 | + public function setConsentCheckboxEnabled($consent_checkbox_enabled) |
|
| 2524 | + { |
|
| 2525 | + $this->consent_checkbox_enabled = filter_var( |
|
| 2526 | + $consent_checkbox_enabled, |
|
| 2527 | + FILTER_VALIDATE_BOOLEAN |
|
| 2528 | + ); |
|
| 2529 | + } |
|
| 2530 | + |
|
| 2531 | + |
|
| 2532 | + /** |
|
| 2533 | + * @return string |
|
| 2534 | + */ |
|
| 2535 | + public function getConsentCheckboxLabelText() |
|
| 2536 | + { |
|
| 2537 | + return $this->consent_checkbox_label_text; |
|
| 2538 | + } |
|
| 2539 | + |
|
| 2540 | + |
|
| 2541 | + /** |
|
| 2542 | + * @param string $consent_checkbox_label_text |
|
| 2543 | + */ |
|
| 2544 | + public function setConsentCheckboxLabelText($consent_checkbox_label_text) |
|
| 2545 | + { |
|
| 2546 | + $this->consent_checkbox_label_text = (string) $consent_checkbox_label_text; |
|
| 2547 | + } |
|
| 2548 | 2548 | } |
| 2549 | 2549 | |
| 2550 | 2550 | /** |
@@ -2553,151 +2553,151 @@ discard block |
||
| 2553 | 2553 | class EE_Admin_Config extends EE_Config_Base |
| 2554 | 2554 | { |
| 2555 | 2555 | |
| 2556 | - /** |
|
| 2557 | - * @var boolean $use_personnel_manager |
|
| 2558 | - */ |
|
| 2559 | - public $use_personnel_manager; |
|
| 2560 | - |
|
| 2561 | - /** |
|
| 2562 | - * @var boolean $use_dashboard_widget |
|
| 2563 | - */ |
|
| 2564 | - public $use_dashboard_widget; |
|
| 2565 | - |
|
| 2566 | - /** |
|
| 2567 | - * @var int $events_in_dashboard |
|
| 2568 | - */ |
|
| 2569 | - public $events_in_dashboard; |
|
| 2570 | - |
|
| 2571 | - /** |
|
| 2572 | - * @var boolean $use_event_timezones |
|
| 2573 | - */ |
|
| 2574 | - public $use_event_timezones; |
|
| 2575 | - |
|
| 2576 | - /** |
|
| 2577 | - * @var string $log_file_name |
|
| 2578 | - */ |
|
| 2579 | - public $log_file_name; |
|
| 2580 | - |
|
| 2581 | - /** |
|
| 2582 | - * @var string $debug_file_name |
|
| 2583 | - */ |
|
| 2584 | - public $debug_file_name; |
|
| 2585 | - |
|
| 2586 | - /** |
|
| 2587 | - * @var boolean $use_remote_logging |
|
| 2588 | - */ |
|
| 2589 | - public $use_remote_logging; |
|
| 2590 | - |
|
| 2591 | - /** |
|
| 2592 | - * @var string $remote_logging_url |
|
| 2593 | - */ |
|
| 2594 | - public $remote_logging_url; |
|
| 2595 | - |
|
| 2596 | - /** |
|
| 2597 | - * @var boolean $show_reg_footer |
|
| 2598 | - */ |
|
| 2599 | - public $show_reg_footer; |
|
| 2600 | - |
|
| 2601 | - /** |
|
| 2602 | - * @var string $affiliate_id |
|
| 2603 | - */ |
|
| 2604 | - public $affiliate_id; |
|
| 2605 | - |
|
| 2606 | - /** |
|
| 2607 | - * help tours on or off (global setting) |
|
| 2608 | - * |
|
| 2609 | - * @var boolean |
|
| 2610 | - */ |
|
| 2611 | - public $help_tour_activation; |
|
| 2612 | - |
|
| 2613 | - /** |
|
| 2614 | - * adds extra layer of encoding to session data to prevent serialization errors |
|
| 2615 | - * but is incompatible with some server configuration errors |
|
| 2616 | - * if you get "500 internal server errors" during registration, try turning this on |
|
| 2617 | - * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off |
|
| 2618 | - * |
|
| 2619 | - * @var boolean $encode_session_data |
|
| 2620 | - */ |
|
| 2621 | - private $encode_session_data = false; |
|
| 2622 | - |
|
| 2623 | - |
|
| 2624 | - /** |
|
| 2625 | - * class constructor |
|
| 2626 | - * |
|
| 2627 | - * @access public |
|
| 2628 | - */ |
|
| 2629 | - public function __construct() |
|
| 2630 | - { |
|
| 2631 | - // set default general admin settings |
|
| 2632 | - $this->use_personnel_manager = true; |
|
| 2633 | - $this->use_dashboard_widget = true; |
|
| 2634 | - $this->events_in_dashboard = 30; |
|
| 2635 | - $this->use_event_timezones = false; |
|
| 2636 | - $this->use_remote_logging = false; |
|
| 2637 | - $this->remote_logging_url = null; |
|
| 2638 | - $this->show_reg_footer = apply_filters( |
|
| 2639 | - 'FHEE__EE_Admin_Config__show_reg_footer__default', |
|
| 2640 | - false |
|
| 2641 | - ); |
|
| 2642 | - $this->affiliate_id = 'default'; |
|
| 2643 | - $this->help_tour_activation = false; |
|
| 2644 | - $this->encode_session_data = false; |
|
| 2645 | - } |
|
| 2646 | - |
|
| 2647 | - |
|
| 2648 | - /** |
|
| 2649 | - * @param bool $reset |
|
| 2650 | - * @return string |
|
| 2651 | - */ |
|
| 2652 | - public function log_file_name($reset = false) |
|
| 2653 | - { |
|
| 2654 | - if (empty($this->log_file_name) || $reset) { |
|
| 2655 | - $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt'; |
|
| 2656 | - EE_Config::instance()->update_espresso_config(false, false); |
|
| 2657 | - } |
|
| 2658 | - return $this->log_file_name; |
|
| 2659 | - } |
|
| 2660 | - |
|
| 2661 | - |
|
| 2662 | - /** |
|
| 2663 | - * @param bool $reset |
|
| 2664 | - * @return string |
|
| 2665 | - */ |
|
| 2666 | - public function debug_file_name($reset = false) |
|
| 2667 | - { |
|
| 2668 | - if (empty($this->debug_file_name) || $reset) { |
|
| 2669 | - $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt'; |
|
| 2670 | - EE_Config::instance()->update_espresso_config(false, false); |
|
| 2671 | - } |
|
| 2672 | - return $this->debug_file_name; |
|
| 2673 | - } |
|
| 2674 | - |
|
| 2675 | - |
|
| 2676 | - /** |
|
| 2677 | - * @return string |
|
| 2678 | - */ |
|
| 2679 | - public function affiliate_id() |
|
| 2680 | - { |
|
| 2681 | - return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default'; |
|
| 2682 | - } |
|
| 2683 | - |
|
| 2684 | - |
|
| 2685 | - /** |
|
| 2686 | - * @return boolean |
|
| 2687 | - */ |
|
| 2688 | - public function encode_session_data() |
|
| 2689 | - { |
|
| 2690 | - return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2691 | - } |
|
| 2692 | - |
|
| 2693 | - |
|
| 2694 | - /** |
|
| 2695 | - * @param boolean $encode_session_data |
|
| 2696 | - */ |
|
| 2697 | - public function set_encode_session_data($encode_session_data) |
|
| 2698 | - { |
|
| 2699 | - $this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2700 | - } |
|
| 2556 | + /** |
|
| 2557 | + * @var boolean $use_personnel_manager |
|
| 2558 | + */ |
|
| 2559 | + public $use_personnel_manager; |
|
| 2560 | + |
|
| 2561 | + /** |
|
| 2562 | + * @var boolean $use_dashboard_widget |
|
| 2563 | + */ |
|
| 2564 | + public $use_dashboard_widget; |
|
| 2565 | + |
|
| 2566 | + /** |
|
| 2567 | + * @var int $events_in_dashboard |
|
| 2568 | + */ |
|
| 2569 | + public $events_in_dashboard; |
|
| 2570 | + |
|
| 2571 | + /** |
|
| 2572 | + * @var boolean $use_event_timezones |
|
| 2573 | + */ |
|
| 2574 | + public $use_event_timezones; |
|
| 2575 | + |
|
| 2576 | + /** |
|
| 2577 | + * @var string $log_file_name |
|
| 2578 | + */ |
|
| 2579 | + public $log_file_name; |
|
| 2580 | + |
|
| 2581 | + /** |
|
| 2582 | + * @var string $debug_file_name |
|
| 2583 | + */ |
|
| 2584 | + public $debug_file_name; |
|
| 2585 | + |
|
| 2586 | + /** |
|
| 2587 | + * @var boolean $use_remote_logging |
|
| 2588 | + */ |
|
| 2589 | + public $use_remote_logging; |
|
| 2590 | + |
|
| 2591 | + /** |
|
| 2592 | + * @var string $remote_logging_url |
|
| 2593 | + */ |
|
| 2594 | + public $remote_logging_url; |
|
| 2595 | + |
|
| 2596 | + /** |
|
| 2597 | + * @var boolean $show_reg_footer |
|
| 2598 | + */ |
|
| 2599 | + public $show_reg_footer; |
|
| 2600 | + |
|
| 2601 | + /** |
|
| 2602 | + * @var string $affiliate_id |
|
| 2603 | + */ |
|
| 2604 | + public $affiliate_id; |
|
| 2605 | + |
|
| 2606 | + /** |
|
| 2607 | + * help tours on or off (global setting) |
|
| 2608 | + * |
|
| 2609 | + * @var boolean |
|
| 2610 | + */ |
|
| 2611 | + public $help_tour_activation; |
|
| 2612 | + |
|
| 2613 | + /** |
|
| 2614 | + * adds extra layer of encoding to session data to prevent serialization errors |
|
| 2615 | + * but is incompatible with some server configuration errors |
|
| 2616 | + * if you get "500 internal server errors" during registration, try turning this on |
|
| 2617 | + * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off |
|
| 2618 | + * |
|
| 2619 | + * @var boolean $encode_session_data |
|
| 2620 | + */ |
|
| 2621 | + private $encode_session_data = false; |
|
| 2622 | + |
|
| 2623 | + |
|
| 2624 | + /** |
|
| 2625 | + * class constructor |
|
| 2626 | + * |
|
| 2627 | + * @access public |
|
| 2628 | + */ |
|
| 2629 | + public function __construct() |
|
| 2630 | + { |
|
| 2631 | + // set default general admin settings |
|
| 2632 | + $this->use_personnel_manager = true; |
|
| 2633 | + $this->use_dashboard_widget = true; |
|
| 2634 | + $this->events_in_dashboard = 30; |
|
| 2635 | + $this->use_event_timezones = false; |
|
| 2636 | + $this->use_remote_logging = false; |
|
| 2637 | + $this->remote_logging_url = null; |
|
| 2638 | + $this->show_reg_footer = apply_filters( |
|
| 2639 | + 'FHEE__EE_Admin_Config__show_reg_footer__default', |
|
| 2640 | + false |
|
| 2641 | + ); |
|
| 2642 | + $this->affiliate_id = 'default'; |
|
| 2643 | + $this->help_tour_activation = false; |
|
| 2644 | + $this->encode_session_data = false; |
|
| 2645 | + } |
|
| 2646 | + |
|
| 2647 | + |
|
| 2648 | + /** |
|
| 2649 | + * @param bool $reset |
|
| 2650 | + * @return string |
|
| 2651 | + */ |
|
| 2652 | + public function log_file_name($reset = false) |
|
| 2653 | + { |
|
| 2654 | + if (empty($this->log_file_name) || $reset) { |
|
| 2655 | + $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt'; |
|
| 2656 | + EE_Config::instance()->update_espresso_config(false, false); |
|
| 2657 | + } |
|
| 2658 | + return $this->log_file_name; |
|
| 2659 | + } |
|
| 2660 | + |
|
| 2661 | + |
|
| 2662 | + /** |
|
| 2663 | + * @param bool $reset |
|
| 2664 | + * @return string |
|
| 2665 | + */ |
|
| 2666 | + public function debug_file_name($reset = false) |
|
| 2667 | + { |
|
| 2668 | + if (empty($this->debug_file_name) || $reset) { |
|
| 2669 | + $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt'; |
|
| 2670 | + EE_Config::instance()->update_espresso_config(false, false); |
|
| 2671 | + } |
|
| 2672 | + return $this->debug_file_name; |
|
| 2673 | + } |
|
| 2674 | + |
|
| 2675 | + |
|
| 2676 | + /** |
|
| 2677 | + * @return string |
|
| 2678 | + */ |
|
| 2679 | + public function affiliate_id() |
|
| 2680 | + { |
|
| 2681 | + return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default'; |
|
| 2682 | + } |
|
| 2683 | + |
|
| 2684 | + |
|
| 2685 | + /** |
|
| 2686 | + * @return boolean |
|
| 2687 | + */ |
|
| 2688 | + public function encode_session_data() |
|
| 2689 | + { |
|
| 2690 | + return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2691 | + } |
|
| 2692 | + |
|
| 2693 | + |
|
| 2694 | + /** |
|
| 2695 | + * @param boolean $encode_session_data |
|
| 2696 | + */ |
|
| 2697 | + public function set_encode_session_data($encode_session_data) |
|
| 2698 | + { |
|
| 2699 | + $this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2700 | + } |
|
| 2701 | 2701 | } |
| 2702 | 2702 | |
| 2703 | 2703 | /** |
@@ -2706,70 +2706,70 @@ discard block |
||
| 2706 | 2706 | class EE_Template_Config extends EE_Config_Base |
| 2707 | 2707 | { |
| 2708 | 2708 | |
| 2709 | - /** |
|
| 2710 | - * @var boolean $enable_default_style |
|
| 2711 | - */ |
|
| 2712 | - public $enable_default_style; |
|
| 2713 | - |
|
| 2714 | - /** |
|
| 2715 | - * @var string $custom_style_sheet |
|
| 2716 | - */ |
|
| 2717 | - public $custom_style_sheet; |
|
| 2718 | - |
|
| 2719 | - /** |
|
| 2720 | - * @var boolean $display_address_in_regform |
|
| 2721 | - */ |
|
| 2722 | - public $display_address_in_regform; |
|
| 2723 | - |
|
| 2724 | - /** |
|
| 2725 | - * @var int $display_description_on_multi_reg_page |
|
| 2726 | - */ |
|
| 2727 | - public $display_description_on_multi_reg_page; |
|
| 2728 | - |
|
| 2729 | - /** |
|
| 2730 | - * @var boolean $use_custom_templates |
|
| 2731 | - */ |
|
| 2732 | - public $use_custom_templates; |
|
| 2733 | - |
|
| 2734 | - /** |
|
| 2735 | - * @var string $current_espresso_theme |
|
| 2736 | - */ |
|
| 2737 | - public $current_espresso_theme; |
|
| 2738 | - |
|
| 2739 | - /** |
|
| 2740 | - * @var EE_Ticket_Selector_Config $EED_Ticket_Selector |
|
| 2741 | - */ |
|
| 2742 | - public $EED_Ticket_Selector; |
|
| 2743 | - |
|
| 2744 | - /** |
|
| 2745 | - * @var EE_Event_Single_Config $EED_Event_Single |
|
| 2746 | - */ |
|
| 2747 | - public $EED_Event_Single; |
|
| 2748 | - |
|
| 2749 | - /** |
|
| 2750 | - * @var EE_Events_Archive_Config $EED_Events_Archive |
|
| 2751 | - */ |
|
| 2752 | - public $EED_Events_Archive; |
|
| 2753 | - |
|
| 2754 | - |
|
| 2755 | - /** |
|
| 2756 | - * class constructor |
|
| 2757 | - * |
|
| 2758 | - * @access public |
|
| 2759 | - */ |
|
| 2760 | - public function __construct() |
|
| 2761 | - { |
|
| 2762 | - // set default template settings |
|
| 2763 | - $this->enable_default_style = true; |
|
| 2764 | - $this->custom_style_sheet = null; |
|
| 2765 | - $this->display_address_in_regform = true; |
|
| 2766 | - $this->display_description_on_multi_reg_page = false; |
|
| 2767 | - $this->use_custom_templates = false; |
|
| 2768 | - $this->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
| 2769 | - $this->EED_Event_Single = null; |
|
| 2770 | - $this->EED_Events_Archive = null; |
|
| 2771 | - $this->EED_Ticket_Selector = null; |
|
| 2772 | - } |
|
| 2709 | + /** |
|
| 2710 | + * @var boolean $enable_default_style |
|
| 2711 | + */ |
|
| 2712 | + public $enable_default_style; |
|
| 2713 | + |
|
| 2714 | + /** |
|
| 2715 | + * @var string $custom_style_sheet |
|
| 2716 | + */ |
|
| 2717 | + public $custom_style_sheet; |
|
| 2718 | + |
|
| 2719 | + /** |
|
| 2720 | + * @var boolean $display_address_in_regform |
|
| 2721 | + */ |
|
| 2722 | + public $display_address_in_regform; |
|
| 2723 | + |
|
| 2724 | + /** |
|
| 2725 | + * @var int $display_description_on_multi_reg_page |
|
| 2726 | + */ |
|
| 2727 | + public $display_description_on_multi_reg_page; |
|
| 2728 | + |
|
| 2729 | + /** |
|
| 2730 | + * @var boolean $use_custom_templates |
|
| 2731 | + */ |
|
| 2732 | + public $use_custom_templates; |
|
| 2733 | + |
|
| 2734 | + /** |
|
| 2735 | + * @var string $current_espresso_theme |
|
| 2736 | + */ |
|
| 2737 | + public $current_espresso_theme; |
|
| 2738 | + |
|
| 2739 | + /** |
|
| 2740 | + * @var EE_Ticket_Selector_Config $EED_Ticket_Selector |
|
| 2741 | + */ |
|
| 2742 | + public $EED_Ticket_Selector; |
|
| 2743 | + |
|
| 2744 | + /** |
|
| 2745 | + * @var EE_Event_Single_Config $EED_Event_Single |
|
| 2746 | + */ |
|
| 2747 | + public $EED_Event_Single; |
|
| 2748 | + |
|
| 2749 | + /** |
|
| 2750 | + * @var EE_Events_Archive_Config $EED_Events_Archive |
|
| 2751 | + */ |
|
| 2752 | + public $EED_Events_Archive; |
|
| 2753 | + |
|
| 2754 | + |
|
| 2755 | + /** |
|
| 2756 | + * class constructor |
|
| 2757 | + * |
|
| 2758 | + * @access public |
|
| 2759 | + */ |
|
| 2760 | + public function __construct() |
|
| 2761 | + { |
|
| 2762 | + // set default template settings |
|
| 2763 | + $this->enable_default_style = true; |
|
| 2764 | + $this->custom_style_sheet = null; |
|
| 2765 | + $this->display_address_in_regform = true; |
|
| 2766 | + $this->display_description_on_multi_reg_page = false; |
|
| 2767 | + $this->use_custom_templates = false; |
|
| 2768 | + $this->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
| 2769 | + $this->EED_Event_Single = null; |
|
| 2770 | + $this->EED_Events_Archive = null; |
|
| 2771 | + $this->EED_Ticket_Selector = null; |
|
| 2772 | + } |
|
| 2773 | 2773 | } |
| 2774 | 2774 | |
| 2775 | 2775 | /** |
@@ -2778,114 +2778,114 @@ discard block |
||
| 2778 | 2778 | class EE_Map_Config extends EE_Config_Base |
| 2779 | 2779 | { |
| 2780 | 2780 | |
| 2781 | - /** |
|
| 2782 | - * @var boolean $use_google_maps |
|
| 2783 | - */ |
|
| 2784 | - public $use_google_maps; |
|
| 2785 | - |
|
| 2786 | - /** |
|
| 2787 | - * @var string $api_key |
|
| 2788 | - */ |
|
| 2789 | - public $google_map_api_key; |
|
| 2790 | - |
|
| 2791 | - /** |
|
| 2792 | - * @var int $event_details_map_width |
|
| 2793 | - */ |
|
| 2794 | - public $event_details_map_width; |
|
| 2795 | - |
|
| 2796 | - /** |
|
| 2797 | - * @var int $event_details_map_height |
|
| 2798 | - */ |
|
| 2799 | - public $event_details_map_height; |
|
| 2800 | - |
|
| 2801 | - /** |
|
| 2802 | - * @var int $event_details_map_zoom |
|
| 2803 | - */ |
|
| 2804 | - public $event_details_map_zoom; |
|
| 2805 | - |
|
| 2806 | - /** |
|
| 2807 | - * @var boolean $event_details_display_nav |
|
| 2808 | - */ |
|
| 2809 | - public $event_details_display_nav; |
|
| 2810 | - |
|
| 2811 | - /** |
|
| 2812 | - * @var boolean $event_details_nav_size |
|
| 2813 | - */ |
|
| 2814 | - public $event_details_nav_size; |
|
| 2815 | - |
|
| 2816 | - /** |
|
| 2817 | - * @var string $event_details_control_type |
|
| 2818 | - */ |
|
| 2819 | - public $event_details_control_type; |
|
| 2820 | - |
|
| 2821 | - /** |
|
| 2822 | - * @var string $event_details_map_align |
|
| 2823 | - */ |
|
| 2824 | - public $event_details_map_align; |
|
| 2825 | - |
|
| 2826 | - /** |
|
| 2827 | - * @var int $event_list_map_width |
|
| 2828 | - */ |
|
| 2829 | - public $event_list_map_width; |
|
| 2830 | - |
|
| 2831 | - /** |
|
| 2832 | - * @var int $event_list_map_height |
|
| 2833 | - */ |
|
| 2834 | - public $event_list_map_height; |
|
| 2835 | - |
|
| 2836 | - /** |
|
| 2837 | - * @var int $event_list_map_zoom |
|
| 2838 | - */ |
|
| 2839 | - public $event_list_map_zoom; |
|
| 2840 | - |
|
| 2841 | - /** |
|
| 2842 | - * @var boolean $event_list_display_nav |
|
| 2843 | - */ |
|
| 2844 | - public $event_list_display_nav; |
|
| 2845 | - |
|
| 2846 | - /** |
|
| 2847 | - * @var boolean $event_list_nav_size |
|
| 2848 | - */ |
|
| 2849 | - public $event_list_nav_size; |
|
| 2850 | - |
|
| 2851 | - /** |
|
| 2852 | - * @var string $event_list_control_type |
|
| 2853 | - */ |
|
| 2854 | - public $event_list_control_type; |
|
| 2855 | - |
|
| 2856 | - /** |
|
| 2857 | - * @var string $event_list_map_align |
|
| 2858 | - */ |
|
| 2859 | - public $event_list_map_align; |
|
| 2860 | - |
|
| 2861 | - |
|
| 2862 | - /** |
|
| 2863 | - * class constructor |
|
| 2864 | - * |
|
| 2865 | - * @access public |
|
| 2866 | - */ |
|
| 2867 | - public function __construct() |
|
| 2868 | - { |
|
| 2869 | - // set default map settings |
|
| 2870 | - $this->use_google_maps = true; |
|
| 2871 | - $this->google_map_api_key = ''; |
|
| 2872 | - // for event details pages (reg page) |
|
| 2873 | - $this->event_details_map_width = 585; // ee_map_width_single |
|
| 2874 | - $this->event_details_map_height = 362; // ee_map_height_single |
|
| 2875 | - $this->event_details_map_zoom = 14; // ee_map_zoom_single |
|
| 2876 | - $this->event_details_display_nav = true; // ee_map_nav_display_single |
|
| 2877 | - $this->event_details_nav_size = false; // ee_map_nav_size_single |
|
| 2878 | - $this->event_details_control_type = 'default'; // ee_map_type_control_single |
|
| 2879 | - $this->event_details_map_align = 'center'; // ee_map_align_single |
|
| 2880 | - // for event list pages |
|
| 2881 | - $this->event_list_map_width = 300; // ee_map_width |
|
| 2882 | - $this->event_list_map_height = 185; // ee_map_height |
|
| 2883 | - $this->event_list_map_zoom = 12; // ee_map_zoom |
|
| 2884 | - $this->event_list_display_nav = false; // ee_map_nav_display |
|
| 2885 | - $this->event_list_nav_size = true; // ee_map_nav_size |
|
| 2886 | - $this->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
| 2887 | - $this->event_list_map_align = 'center'; // ee_map_align |
|
| 2888 | - } |
|
| 2781 | + /** |
|
| 2782 | + * @var boolean $use_google_maps |
|
| 2783 | + */ |
|
| 2784 | + public $use_google_maps; |
|
| 2785 | + |
|
| 2786 | + /** |
|
| 2787 | + * @var string $api_key |
|
| 2788 | + */ |
|
| 2789 | + public $google_map_api_key; |
|
| 2790 | + |
|
| 2791 | + /** |
|
| 2792 | + * @var int $event_details_map_width |
|
| 2793 | + */ |
|
| 2794 | + public $event_details_map_width; |
|
| 2795 | + |
|
| 2796 | + /** |
|
| 2797 | + * @var int $event_details_map_height |
|
| 2798 | + */ |
|
| 2799 | + public $event_details_map_height; |
|
| 2800 | + |
|
| 2801 | + /** |
|
| 2802 | + * @var int $event_details_map_zoom |
|
| 2803 | + */ |
|
| 2804 | + public $event_details_map_zoom; |
|
| 2805 | + |
|
| 2806 | + /** |
|
| 2807 | + * @var boolean $event_details_display_nav |
|
| 2808 | + */ |
|
| 2809 | + public $event_details_display_nav; |
|
| 2810 | + |
|
| 2811 | + /** |
|
| 2812 | + * @var boolean $event_details_nav_size |
|
| 2813 | + */ |
|
| 2814 | + public $event_details_nav_size; |
|
| 2815 | + |
|
| 2816 | + /** |
|
| 2817 | + * @var string $event_details_control_type |
|
| 2818 | + */ |
|
| 2819 | + public $event_details_control_type; |
|
| 2820 | + |
|
| 2821 | + /** |
|
| 2822 | + * @var string $event_details_map_align |
|
| 2823 | + */ |
|
| 2824 | + public $event_details_map_align; |
|
| 2825 | + |
|
| 2826 | + /** |
|
| 2827 | + * @var int $event_list_map_width |
|
| 2828 | + */ |
|
| 2829 | + public $event_list_map_width; |
|
| 2830 | + |
|
| 2831 | + /** |
|
| 2832 | + * @var int $event_list_map_height |
|
| 2833 | + */ |
|
| 2834 | + public $event_list_map_height; |
|
| 2835 | + |
|
| 2836 | + /** |
|
| 2837 | + * @var int $event_list_map_zoom |
|
| 2838 | + */ |
|
| 2839 | + public $event_list_map_zoom; |
|
| 2840 | + |
|
| 2841 | + /** |
|
| 2842 | + * @var boolean $event_list_display_nav |
|
| 2843 | + */ |
|
| 2844 | + public $event_list_display_nav; |
|
| 2845 | + |
|
| 2846 | + /** |
|
| 2847 | + * @var boolean $event_list_nav_size |
|
| 2848 | + */ |
|
| 2849 | + public $event_list_nav_size; |
|
| 2850 | + |
|
| 2851 | + /** |
|
| 2852 | + * @var string $event_list_control_type |
|
| 2853 | + */ |
|
| 2854 | + public $event_list_control_type; |
|
| 2855 | + |
|
| 2856 | + /** |
|
| 2857 | + * @var string $event_list_map_align |
|
| 2858 | + */ |
|
| 2859 | + public $event_list_map_align; |
|
| 2860 | + |
|
| 2861 | + |
|
| 2862 | + /** |
|
| 2863 | + * class constructor |
|
| 2864 | + * |
|
| 2865 | + * @access public |
|
| 2866 | + */ |
|
| 2867 | + public function __construct() |
|
| 2868 | + { |
|
| 2869 | + // set default map settings |
|
| 2870 | + $this->use_google_maps = true; |
|
| 2871 | + $this->google_map_api_key = ''; |
|
| 2872 | + // for event details pages (reg page) |
|
| 2873 | + $this->event_details_map_width = 585; // ee_map_width_single |
|
| 2874 | + $this->event_details_map_height = 362; // ee_map_height_single |
|
| 2875 | + $this->event_details_map_zoom = 14; // ee_map_zoom_single |
|
| 2876 | + $this->event_details_display_nav = true; // ee_map_nav_display_single |
|
| 2877 | + $this->event_details_nav_size = false; // ee_map_nav_size_single |
|
| 2878 | + $this->event_details_control_type = 'default'; // ee_map_type_control_single |
|
| 2879 | + $this->event_details_map_align = 'center'; // ee_map_align_single |
|
| 2880 | + // for event list pages |
|
| 2881 | + $this->event_list_map_width = 300; // ee_map_width |
|
| 2882 | + $this->event_list_map_height = 185; // ee_map_height |
|
| 2883 | + $this->event_list_map_zoom = 12; // ee_map_zoom |
|
| 2884 | + $this->event_list_display_nav = false; // ee_map_nav_display |
|
| 2885 | + $this->event_list_nav_size = true; // ee_map_nav_size |
|
| 2886 | + $this->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
| 2887 | + $this->event_list_map_align = 'center'; // ee_map_align |
|
| 2888 | + } |
|
| 2889 | 2889 | } |
| 2890 | 2890 | |
| 2891 | 2891 | /** |
@@ -2894,46 +2894,46 @@ discard block |
||
| 2894 | 2894 | class EE_Events_Archive_Config extends EE_Config_Base |
| 2895 | 2895 | { |
| 2896 | 2896 | |
| 2897 | - public $display_status_banner; |
|
| 2897 | + public $display_status_banner; |
|
| 2898 | 2898 | |
| 2899 | - public $display_description; |
|
| 2899 | + public $display_description; |
|
| 2900 | 2900 | |
| 2901 | - public $display_ticket_selector; |
|
| 2901 | + public $display_ticket_selector; |
|
| 2902 | 2902 | |
| 2903 | - public $display_datetimes; |
|
| 2903 | + public $display_datetimes; |
|
| 2904 | 2904 | |
| 2905 | - public $display_venue; |
|
| 2905 | + public $display_venue; |
|
| 2906 | 2906 | |
| 2907 | - public $display_expired_events; |
|
| 2907 | + public $display_expired_events; |
|
| 2908 | 2908 | |
| 2909 | - public $use_sortable_display_order; |
|
| 2909 | + public $use_sortable_display_order; |
|
| 2910 | 2910 | |
| 2911 | - public $display_order_tickets; |
|
| 2911 | + public $display_order_tickets; |
|
| 2912 | 2912 | |
| 2913 | - public $display_order_datetimes; |
|
| 2913 | + public $display_order_datetimes; |
|
| 2914 | 2914 | |
| 2915 | - public $display_order_event; |
|
| 2915 | + public $display_order_event; |
|
| 2916 | 2916 | |
| 2917 | - public $display_order_venue; |
|
| 2917 | + public $display_order_venue; |
|
| 2918 | 2918 | |
| 2919 | 2919 | |
| 2920 | - /** |
|
| 2921 | - * class constructor |
|
| 2922 | - */ |
|
| 2923 | - public function __construct() |
|
| 2924 | - { |
|
| 2925 | - $this->display_status_banner = 0; |
|
| 2926 | - $this->display_description = 1; |
|
| 2927 | - $this->display_ticket_selector = 0; |
|
| 2928 | - $this->display_datetimes = 1; |
|
| 2929 | - $this->display_venue = 0; |
|
| 2930 | - $this->display_expired_events = 0; |
|
| 2931 | - $this->use_sortable_display_order = false; |
|
| 2932 | - $this->display_order_tickets = 100; |
|
| 2933 | - $this->display_order_datetimes = 110; |
|
| 2934 | - $this->display_order_event = 120; |
|
| 2935 | - $this->display_order_venue = 130; |
|
| 2936 | - } |
|
| 2920 | + /** |
|
| 2921 | + * class constructor |
|
| 2922 | + */ |
|
| 2923 | + public function __construct() |
|
| 2924 | + { |
|
| 2925 | + $this->display_status_banner = 0; |
|
| 2926 | + $this->display_description = 1; |
|
| 2927 | + $this->display_ticket_selector = 0; |
|
| 2928 | + $this->display_datetimes = 1; |
|
| 2929 | + $this->display_venue = 0; |
|
| 2930 | + $this->display_expired_events = 0; |
|
| 2931 | + $this->use_sortable_display_order = false; |
|
| 2932 | + $this->display_order_tickets = 100; |
|
| 2933 | + $this->display_order_datetimes = 110; |
|
| 2934 | + $this->display_order_event = 120; |
|
| 2935 | + $this->display_order_venue = 130; |
|
| 2936 | + } |
|
| 2937 | 2937 | } |
| 2938 | 2938 | |
| 2939 | 2939 | /** |
@@ -2942,34 +2942,34 @@ discard block |
||
| 2942 | 2942 | class EE_Event_Single_Config extends EE_Config_Base |
| 2943 | 2943 | { |
| 2944 | 2944 | |
| 2945 | - public $display_status_banner_single; |
|
| 2945 | + public $display_status_banner_single; |
|
| 2946 | 2946 | |
| 2947 | - public $display_venue; |
|
| 2947 | + public $display_venue; |
|
| 2948 | 2948 | |
| 2949 | - public $use_sortable_display_order; |
|
| 2949 | + public $use_sortable_display_order; |
|
| 2950 | 2950 | |
| 2951 | - public $display_order_tickets; |
|
| 2951 | + public $display_order_tickets; |
|
| 2952 | 2952 | |
| 2953 | - public $display_order_datetimes; |
|
| 2953 | + public $display_order_datetimes; |
|
| 2954 | 2954 | |
| 2955 | - public $display_order_event; |
|
| 2955 | + public $display_order_event; |
|
| 2956 | 2956 | |
| 2957 | - public $display_order_venue; |
|
| 2957 | + public $display_order_venue; |
|
| 2958 | 2958 | |
| 2959 | 2959 | |
| 2960 | - /** |
|
| 2961 | - * class constructor |
|
| 2962 | - */ |
|
| 2963 | - public function __construct() |
|
| 2964 | - { |
|
| 2965 | - $this->display_status_banner_single = 0; |
|
| 2966 | - $this->display_venue = 1; |
|
| 2967 | - $this->use_sortable_display_order = false; |
|
| 2968 | - $this->display_order_tickets = 100; |
|
| 2969 | - $this->display_order_datetimes = 110; |
|
| 2970 | - $this->display_order_event = 120; |
|
| 2971 | - $this->display_order_venue = 130; |
|
| 2972 | - } |
|
| 2960 | + /** |
|
| 2961 | + * class constructor |
|
| 2962 | + */ |
|
| 2963 | + public function __construct() |
|
| 2964 | + { |
|
| 2965 | + $this->display_status_banner_single = 0; |
|
| 2966 | + $this->display_venue = 1; |
|
| 2967 | + $this->use_sortable_display_order = false; |
|
| 2968 | + $this->display_order_tickets = 100; |
|
| 2969 | + $this->display_order_datetimes = 110; |
|
| 2970 | + $this->display_order_event = 120; |
|
| 2971 | + $this->display_order_venue = 130; |
|
| 2972 | + } |
|
| 2973 | 2973 | } |
| 2974 | 2974 | |
| 2975 | 2975 | /** |
@@ -2978,172 +2978,172 @@ discard block |
||
| 2978 | 2978 | class EE_Ticket_Selector_Config extends EE_Config_Base |
| 2979 | 2979 | { |
| 2980 | 2980 | |
| 2981 | - /** |
|
| 2982 | - * constant to indicate that a datetime selector should NEVER be shown for ticket selectors |
|
| 2983 | - */ |
|
| 2984 | - const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector'; |
|
| 2985 | - |
|
| 2986 | - /** |
|
| 2987 | - * constant to indicate that a datetime selector should only be shown for ticket selectors |
|
| 2988 | - * when the number of datetimes for the event matches the value set for $datetime_selector_threshold |
|
| 2989 | - */ |
|
| 2990 | - const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector'; |
|
| 2991 | - |
|
| 2992 | - /** |
|
| 2993 | - * @var boolean $show_ticket_sale_columns |
|
| 2994 | - */ |
|
| 2995 | - public $show_ticket_sale_columns; |
|
| 2996 | - |
|
| 2997 | - /** |
|
| 2998 | - * @var boolean $show_ticket_details |
|
| 2999 | - */ |
|
| 3000 | - public $show_ticket_details; |
|
| 3001 | - |
|
| 3002 | - /** |
|
| 3003 | - * @var boolean $show_expired_tickets |
|
| 3004 | - */ |
|
| 3005 | - public $show_expired_tickets; |
|
| 3006 | - |
|
| 3007 | - /** |
|
| 3008 | - * whether or not to display a dropdown box populated with event datetimes |
|
| 3009 | - * that toggles which tickets are displayed for a ticket selector. |
|
| 3010 | - * uses one of the *_DATETIME_SELECTOR constants defined above |
|
| 3011 | - * |
|
| 3012 | - * @var string $show_datetime_selector |
|
| 3013 | - */ |
|
| 3014 | - private $show_datetime_selector = 'no_datetime_selector'; |
|
| 3015 | - |
|
| 3016 | - /** |
|
| 3017 | - * the number of datetimes an event has to have before conditionally displaying a datetime selector |
|
| 3018 | - * |
|
| 3019 | - * @var int $datetime_selector_threshold |
|
| 3020 | - */ |
|
| 3021 | - private $datetime_selector_threshold = 3; |
|
| 3022 | - |
|
| 3023 | - /** |
|
| 3024 | - * determines the maximum number of "checked" dates in the date and time filter |
|
| 3025 | - * |
|
| 3026 | - * @var int $datetime_selector_checked |
|
| 3027 | - */ |
|
| 3028 | - private $datetime_selector_max_checked = 10; |
|
| 3029 | - |
|
| 3030 | - |
|
| 3031 | - /** |
|
| 3032 | - * class constructor |
|
| 3033 | - */ |
|
| 3034 | - public function __construct() |
|
| 3035 | - { |
|
| 3036 | - $this->show_ticket_sale_columns = true; |
|
| 3037 | - $this->show_ticket_details = true; |
|
| 3038 | - $this->show_expired_tickets = true; |
|
| 3039 | - $this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
| 3040 | - $this->datetime_selector_threshold = 3; |
|
| 3041 | - $this->datetime_selector_max_checked = 10; |
|
| 3042 | - } |
|
| 3043 | - |
|
| 3044 | - |
|
| 3045 | - /** |
|
| 3046 | - * returns true if a datetime selector should be displayed |
|
| 3047 | - * |
|
| 3048 | - * @param array $datetimes |
|
| 3049 | - * @return bool |
|
| 3050 | - */ |
|
| 3051 | - public function showDatetimeSelector(array $datetimes) |
|
| 3052 | - { |
|
| 3053 | - // if the settings are NOT: don't show OR below threshold, THEN active = true |
|
| 3054 | - return ! ( |
|
| 3055 | - $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR |
|
| 3056 | - || ( |
|
| 3057 | - $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR |
|
| 3058 | - && count($datetimes) < $this->getDatetimeSelectorThreshold() |
|
| 3059 | - ) |
|
| 3060 | - ); |
|
| 3061 | - } |
|
| 3062 | - |
|
| 3063 | - |
|
| 3064 | - /** |
|
| 3065 | - * @return string |
|
| 3066 | - */ |
|
| 3067 | - public function getShowDatetimeSelector() |
|
| 3068 | - { |
|
| 3069 | - return $this->show_datetime_selector; |
|
| 3070 | - } |
|
| 3071 | - |
|
| 3072 | - |
|
| 3073 | - /** |
|
| 3074 | - * @param bool $keys_only |
|
| 3075 | - * @return array |
|
| 3076 | - */ |
|
| 3077 | - public function getShowDatetimeSelectorOptions($keys_only = true) |
|
| 3078 | - { |
|
| 3079 | - return $keys_only |
|
| 3080 | - ? array( |
|
| 3081 | - \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR, |
|
| 3082 | - \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR, |
|
| 3083 | - ) |
|
| 3084 | - : array( |
|
| 3085 | - \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__( |
|
| 3086 | - 'Do not show date & time filter', |
|
| 3087 | - 'event_espresso' |
|
| 3088 | - ), |
|
| 3089 | - \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR => esc_html__( |
|
| 3090 | - 'Maybe show date & time filter', |
|
| 3091 | - 'event_espresso' |
|
| 3092 | - ), |
|
| 3093 | - ); |
|
| 3094 | - } |
|
| 3095 | - |
|
| 3096 | - |
|
| 3097 | - /** |
|
| 3098 | - * @param string $show_datetime_selector |
|
| 3099 | - */ |
|
| 3100 | - public function setShowDatetimeSelector($show_datetime_selector) |
|
| 3101 | - { |
|
| 3102 | - $this->show_datetime_selector = in_array( |
|
| 3103 | - $show_datetime_selector, |
|
| 3104 | - $this->getShowDatetimeSelectorOptions(), |
|
| 3105 | - true |
|
| 3106 | - ) |
|
| 3107 | - ? $show_datetime_selector |
|
| 3108 | - : \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
| 3109 | - } |
|
| 3110 | - |
|
| 3111 | - |
|
| 3112 | - /** |
|
| 3113 | - * @return int |
|
| 3114 | - */ |
|
| 3115 | - public function getDatetimeSelectorThreshold() |
|
| 3116 | - { |
|
| 3117 | - return $this->datetime_selector_threshold; |
|
| 3118 | - } |
|
| 3119 | - |
|
| 3120 | - |
|
| 3121 | - /** |
|
| 3122 | - * @param int $datetime_selector_threshold |
|
| 3123 | - */ |
|
| 3124 | - public function setDatetimeSelectorThreshold($datetime_selector_threshold) |
|
| 3125 | - { |
|
| 3126 | - $datetime_selector_threshold = absint($datetime_selector_threshold); |
|
| 3127 | - $this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3; |
|
| 3128 | - } |
|
| 3129 | - |
|
| 3130 | - |
|
| 3131 | - /** |
|
| 3132 | - * @return int |
|
| 3133 | - */ |
|
| 3134 | - public function getDatetimeSelectorMaxChecked() |
|
| 3135 | - { |
|
| 3136 | - return $this->datetime_selector_max_checked; |
|
| 3137 | - } |
|
| 3138 | - |
|
| 3139 | - |
|
| 3140 | - /** |
|
| 3141 | - * @param int $datetime_selector_max_checked |
|
| 3142 | - */ |
|
| 3143 | - public function setDatetimeSelectorMaxChecked($datetime_selector_max_checked) |
|
| 3144 | - { |
|
| 3145 | - $this->datetime_selector_max_checked = absint($datetime_selector_max_checked); |
|
| 3146 | - } |
|
| 2981 | + /** |
|
| 2982 | + * constant to indicate that a datetime selector should NEVER be shown for ticket selectors |
|
| 2983 | + */ |
|
| 2984 | + const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector'; |
|
| 2985 | + |
|
| 2986 | + /** |
|
| 2987 | + * constant to indicate that a datetime selector should only be shown for ticket selectors |
|
| 2988 | + * when the number of datetimes for the event matches the value set for $datetime_selector_threshold |
|
| 2989 | + */ |
|
| 2990 | + const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector'; |
|
| 2991 | + |
|
| 2992 | + /** |
|
| 2993 | + * @var boolean $show_ticket_sale_columns |
|
| 2994 | + */ |
|
| 2995 | + public $show_ticket_sale_columns; |
|
| 2996 | + |
|
| 2997 | + /** |
|
| 2998 | + * @var boolean $show_ticket_details |
|
| 2999 | + */ |
|
| 3000 | + public $show_ticket_details; |
|
| 3001 | + |
|
| 3002 | + /** |
|
| 3003 | + * @var boolean $show_expired_tickets |
|
| 3004 | + */ |
|
| 3005 | + public $show_expired_tickets; |
|
| 3006 | + |
|
| 3007 | + /** |
|
| 3008 | + * whether or not to display a dropdown box populated with event datetimes |
|
| 3009 | + * that toggles which tickets are displayed for a ticket selector. |
|
| 3010 | + * uses one of the *_DATETIME_SELECTOR constants defined above |
|
| 3011 | + * |
|
| 3012 | + * @var string $show_datetime_selector |
|
| 3013 | + */ |
|
| 3014 | + private $show_datetime_selector = 'no_datetime_selector'; |
|
| 3015 | + |
|
| 3016 | + /** |
|
| 3017 | + * the number of datetimes an event has to have before conditionally displaying a datetime selector |
|
| 3018 | + * |
|
| 3019 | + * @var int $datetime_selector_threshold |
|
| 3020 | + */ |
|
| 3021 | + private $datetime_selector_threshold = 3; |
|
| 3022 | + |
|
| 3023 | + /** |
|
| 3024 | + * determines the maximum number of "checked" dates in the date and time filter |
|
| 3025 | + * |
|
| 3026 | + * @var int $datetime_selector_checked |
|
| 3027 | + */ |
|
| 3028 | + private $datetime_selector_max_checked = 10; |
|
| 3029 | + |
|
| 3030 | + |
|
| 3031 | + /** |
|
| 3032 | + * class constructor |
|
| 3033 | + */ |
|
| 3034 | + public function __construct() |
|
| 3035 | + { |
|
| 3036 | + $this->show_ticket_sale_columns = true; |
|
| 3037 | + $this->show_ticket_details = true; |
|
| 3038 | + $this->show_expired_tickets = true; |
|
| 3039 | + $this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
| 3040 | + $this->datetime_selector_threshold = 3; |
|
| 3041 | + $this->datetime_selector_max_checked = 10; |
|
| 3042 | + } |
|
| 3043 | + |
|
| 3044 | + |
|
| 3045 | + /** |
|
| 3046 | + * returns true if a datetime selector should be displayed |
|
| 3047 | + * |
|
| 3048 | + * @param array $datetimes |
|
| 3049 | + * @return bool |
|
| 3050 | + */ |
|
| 3051 | + public function showDatetimeSelector(array $datetimes) |
|
| 3052 | + { |
|
| 3053 | + // if the settings are NOT: don't show OR below threshold, THEN active = true |
|
| 3054 | + return ! ( |
|
| 3055 | + $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR |
|
| 3056 | + || ( |
|
| 3057 | + $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR |
|
| 3058 | + && count($datetimes) < $this->getDatetimeSelectorThreshold() |
|
| 3059 | + ) |
|
| 3060 | + ); |
|
| 3061 | + } |
|
| 3062 | + |
|
| 3063 | + |
|
| 3064 | + /** |
|
| 3065 | + * @return string |
|
| 3066 | + */ |
|
| 3067 | + public function getShowDatetimeSelector() |
|
| 3068 | + { |
|
| 3069 | + return $this->show_datetime_selector; |
|
| 3070 | + } |
|
| 3071 | + |
|
| 3072 | + |
|
| 3073 | + /** |
|
| 3074 | + * @param bool $keys_only |
|
| 3075 | + * @return array |
|
| 3076 | + */ |
|
| 3077 | + public function getShowDatetimeSelectorOptions($keys_only = true) |
|
| 3078 | + { |
|
| 3079 | + return $keys_only |
|
| 3080 | + ? array( |
|
| 3081 | + \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR, |
|
| 3082 | + \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR, |
|
| 3083 | + ) |
|
| 3084 | + : array( |
|
| 3085 | + \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__( |
|
| 3086 | + 'Do not show date & time filter', |
|
| 3087 | + 'event_espresso' |
|
| 3088 | + ), |
|
| 3089 | + \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR => esc_html__( |
|
| 3090 | + 'Maybe show date & time filter', |
|
| 3091 | + 'event_espresso' |
|
| 3092 | + ), |
|
| 3093 | + ); |
|
| 3094 | + } |
|
| 3095 | + |
|
| 3096 | + |
|
| 3097 | + /** |
|
| 3098 | + * @param string $show_datetime_selector |
|
| 3099 | + */ |
|
| 3100 | + public function setShowDatetimeSelector($show_datetime_selector) |
|
| 3101 | + { |
|
| 3102 | + $this->show_datetime_selector = in_array( |
|
| 3103 | + $show_datetime_selector, |
|
| 3104 | + $this->getShowDatetimeSelectorOptions(), |
|
| 3105 | + true |
|
| 3106 | + ) |
|
| 3107 | + ? $show_datetime_selector |
|
| 3108 | + : \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
| 3109 | + } |
|
| 3110 | + |
|
| 3111 | + |
|
| 3112 | + /** |
|
| 3113 | + * @return int |
|
| 3114 | + */ |
|
| 3115 | + public function getDatetimeSelectorThreshold() |
|
| 3116 | + { |
|
| 3117 | + return $this->datetime_selector_threshold; |
|
| 3118 | + } |
|
| 3119 | + |
|
| 3120 | + |
|
| 3121 | + /** |
|
| 3122 | + * @param int $datetime_selector_threshold |
|
| 3123 | + */ |
|
| 3124 | + public function setDatetimeSelectorThreshold($datetime_selector_threshold) |
|
| 3125 | + { |
|
| 3126 | + $datetime_selector_threshold = absint($datetime_selector_threshold); |
|
| 3127 | + $this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3; |
|
| 3128 | + } |
|
| 3129 | + |
|
| 3130 | + |
|
| 3131 | + /** |
|
| 3132 | + * @return int |
|
| 3133 | + */ |
|
| 3134 | + public function getDatetimeSelectorMaxChecked() |
|
| 3135 | + { |
|
| 3136 | + return $this->datetime_selector_max_checked; |
|
| 3137 | + } |
|
| 3138 | + |
|
| 3139 | + |
|
| 3140 | + /** |
|
| 3141 | + * @param int $datetime_selector_max_checked |
|
| 3142 | + */ |
|
| 3143 | + public function setDatetimeSelectorMaxChecked($datetime_selector_max_checked) |
|
| 3144 | + { |
|
| 3145 | + $this->datetime_selector_max_checked = absint($datetime_selector_max_checked); |
|
| 3146 | + } |
|
| 3147 | 3147 | } |
| 3148 | 3148 | |
| 3149 | 3149 | /** |
@@ -3156,86 +3156,86 @@ discard block |
||
| 3156 | 3156 | class EE_Environment_Config extends EE_Config_Base |
| 3157 | 3157 | { |
| 3158 | 3158 | |
| 3159 | - /** |
|
| 3160 | - * Hold any php environment variables that we want to track. |
|
| 3161 | - * |
|
| 3162 | - * @var stdClass; |
|
| 3163 | - */ |
|
| 3164 | - public $php; |
|
| 3165 | - |
|
| 3166 | - |
|
| 3167 | - /** |
|
| 3168 | - * constructor |
|
| 3169 | - */ |
|
| 3170 | - public function __construct() |
|
| 3171 | - { |
|
| 3172 | - $this->php = new stdClass(); |
|
| 3173 | - $this->_set_php_values(); |
|
| 3174 | - } |
|
| 3175 | - |
|
| 3176 | - |
|
| 3177 | - /** |
|
| 3178 | - * This sets the php environment variables. |
|
| 3179 | - * |
|
| 3180 | - * @since 4.4.0 |
|
| 3181 | - * @return void |
|
| 3182 | - */ |
|
| 3183 | - protected function _set_php_values() |
|
| 3184 | - { |
|
| 3185 | - $this->php->max_input_vars = ini_get('max_input_vars'); |
|
| 3186 | - $this->php->version = phpversion(); |
|
| 3187 | - } |
|
| 3188 | - |
|
| 3189 | - |
|
| 3190 | - /** |
|
| 3191 | - * helper method for determining whether input_count is |
|
| 3192 | - * reaching the potential maximum the server can handle |
|
| 3193 | - * according to max_input_vars |
|
| 3194 | - * |
|
| 3195 | - * @param int $input_count the count of input vars. |
|
| 3196 | - * @return array { |
|
| 3197 | - * An array that represents whether available space and if no available space the error |
|
| 3198 | - * message. |
|
| 3199 | - * @type bool $has_space whether more inputs can be added. |
|
| 3200 | - * @type string $msg Any message to be displayed. |
|
| 3201 | - * } |
|
| 3202 | - */ |
|
| 3203 | - public function max_input_vars_limit_check($input_count = 0) |
|
| 3204 | - { |
|
| 3205 | - if (! empty($this->php->max_input_vars) |
|
| 3206 | - && ($input_count >= $this->php->max_input_vars) |
|
| 3207 | - ) { |
|
| 3208 | - // check the server setting because the config value could be stale |
|
| 3209 | - $max_input_vars = ini_get('max_input_vars'); |
|
| 3210 | - if ($input_count >= $max_input_vars) { |
|
| 3211 | - return sprintf( |
|
| 3212 | - esc_html__( |
|
| 3213 | - 'The maximum number of inputs on this page has been exceeded. You cannot make edits to this page because of your server\'s PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.%1$sPlease contact your web host and ask them to raise the "max_input_vars" limit.', |
|
| 3214 | - 'event_espresso' |
|
| 3215 | - ), |
|
| 3216 | - '<br>', |
|
| 3217 | - $input_count, |
|
| 3218 | - $max_input_vars |
|
| 3219 | - ); |
|
| 3220 | - } else { |
|
| 3221 | - return ''; |
|
| 3222 | - } |
|
| 3223 | - } else { |
|
| 3224 | - return ''; |
|
| 3225 | - } |
|
| 3226 | - } |
|
| 3227 | - |
|
| 3228 | - |
|
| 3229 | - /** |
|
| 3230 | - * The purpose of this method is just to force rechecking php values so if they've changed, they get updated. |
|
| 3231 | - * |
|
| 3232 | - * @since 4.4.1 |
|
| 3233 | - * @return void |
|
| 3234 | - */ |
|
| 3235 | - public function recheck_values() |
|
| 3236 | - { |
|
| 3237 | - $this->_set_php_values(); |
|
| 3238 | - } |
|
| 3159 | + /** |
|
| 3160 | + * Hold any php environment variables that we want to track. |
|
| 3161 | + * |
|
| 3162 | + * @var stdClass; |
|
| 3163 | + */ |
|
| 3164 | + public $php; |
|
| 3165 | + |
|
| 3166 | + |
|
| 3167 | + /** |
|
| 3168 | + * constructor |
|
| 3169 | + */ |
|
| 3170 | + public function __construct() |
|
| 3171 | + { |
|
| 3172 | + $this->php = new stdClass(); |
|
| 3173 | + $this->_set_php_values(); |
|
| 3174 | + } |
|
| 3175 | + |
|
| 3176 | + |
|
| 3177 | + /** |
|
| 3178 | + * This sets the php environment variables. |
|
| 3179 | + * |
|
| 3180 | + * @since 4.4.0 |
|
| 3181 | + * @return void |
|
| 3182 | + */ |
|
| 3183 | + protected function _set_php_values() |
|
| 3184 | + { |
|
| 3185 | + $this->php->max_input_vars = ini_get('max_input_vars'); |
|
| 3186 | + $this->php->version = phpversion(); |
|
| 3187 | + } |
|
| 3188 | + |
|
| 3189 | + |
|
| 3190 | + /** |
|
| 3191 | + * helper method for determining whether input_count is |
|
| 3192 | + * reaching the potential maximum the server can handle |
|
| 3193 | + * according to max_input_vars |
|
| 3194 | + * |
|
| 3195 | + * @param int $input_count the count of input vars. |
|
| 3196 | + * @return array { |
|
| 3197 | + * An array that represents whether available space and if no available space the error |
|
| 3198 | + * message. |
|
| 3199 | + * @type bool $has_space whether more inputs can be added. |
|
| 3200 | + * @type string $msg Any message to be displayed. |
|
| 3201 | + * } |
|
| 3202 | + */ |
|
| 3203 | + public function max_input_vars_limit_check($input_count = 0) |
|
| 3204 | + { |
|
| 3205 | + if (! empty($this->php->max_input_vars) |
|
| 3206 | + && ($input_count >= $this->php->max_input_vars) |
|
| 3207 | + ) { |
|
| 3208 | + // check the server setting because the config value could be stale |
|
| 3209 | + $max_input_vars = ini_get('max_input_vars'); |
|
| 3210 | + if ($input_count >= $max_input_vars) { |
|
| 3211 | + return sprintf( |
|
| 3212 | + esc_html__( |
|
| 3213 | + 'The maximum number of inputs on this page has been exceeded. You cannot make edits to this page because of your server\'s PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.%1$sPlease contact your web host and ask them to raise the "max_input_vars" limit.', |
|
| 3214 | + 'event_espresso' |
|
| 3215 | + ), |
|
| 3216 | + '<br>', |
|
| 3217 | + $input_count, |
|
| 3218 | + $max_input_vars |
|
| 3219 | + ); |
|
| 3220 | + } else { |
|
| 3221 | + return ''; |
|
| 3222 | + } |
|
| 3223 | + } else { |
|
| 3224 | + return ''; |
|
| 3225 | + } |
|
| 3226 | + } |
|
| 3227 | + |
|
| 3228 | + |
|
| 3229 | + /** |
|
| 3230 | + * The purpose of this method is just to force rechecking php values so if they've changed, they get updated. |
|
| 3231 | + * |
|
| 3232 | + * @since 4.4.1 |
|
| 3233 | + * @return void |
|
| 3234 | + */ |
|
| 3235 | + public function recheck_values() |
|
| 3236 | + { |
|
| 3237 | + $this->_set_php_values(); |
|
| 3238 | + } |
|
| 3239 | 3239 | } |
| 3240 | 3240 | |
| 3241 | 3241 | /** |
@@ -3248,21 +3248,21 @@ discard block |
||
| 3248 | 3248 | class EE_Tax_Config extends EE_Config_Base |
| 3249 | 3249 | { |
| 3250 | 3250 | |
| 3251 | - /* |
|
| 3251 | + /* |
|
| 3252 | 3252 | * flag to indicate whether or not to display ticket prices with the taxes included |
| 3253 | 3253 | * |
| 3254 | 3254 | * @var boolean $prices_displayed_including_taxes |
| 3255 | 3255 | */ |
| 3256 | - public $prices_displayed_including_taxes; |
|
| 3256 | + public $prices_displayed_including_taxes; |
|
| 3257 | 3257 | |
| 3258 | 3258 | |
| 3259 | - /** |
|
| 3260 | - * class constructor |
|
| 3261 | - */ |
|
| 3262 | - public function __construct() |
|
| 3263 | - { |
|
| 3264 | - $this->prices_displayed_including_taxes = true; |
|
| 3265 | - } |
|
| 3259 | + /** |
|
| 3260 | + * class constructor |
|
| 3261 | + */ |
|
| 3262 | + public function __construct() |
|
| 3263 | + { |
|
| 3264 | + $this->prices_displayed_including_taxes = true; |
|
| 3265 | + } |
|
| 3266 | 3266 | } |
| 3267 | 3267 | |
| 3268 | 3268 | /** |
@@ -3276,19 +3276,19 @@ discard block |
||
| 3276 | 3276 | class EE_Messages_Config extends EE_Config_Base |
| 3277 | 3277 | { |
| 3278 | 3278 | |
| 3279 | - /** |
|
| 3280 | - * This is an integer representing the deletion threshold in months for when old messages will get deleted. |
|
| 3281 | - * A value of 0 represents never deleting. Default is 0. |
|
| 3282 | - * |
|
| 3283 | - * @var integer |
|
| 3284 | - */ |
|
| 3285 | - public $delete_threshold; |
|
| 3279 | + /** |
|
| 3280 | + * This is an integer representing the deletion threshold in months for when old messages will get deleted. |
|
| 3281 | + * A value of 0 represents never deleting. Default is 0. |
|
| 3282 | + * |
|
| 3283 | + * @var integer |
|
| 3284 | + */ |
|
| 3285 | + public $delete_threshold; |
|
| 3286 | 3286 | |
| 3287 | 3287 | |
| 3288 | - public function __construct() |
|
| 3289 | - { |
|
| 3290 | - $this->delete_threshold = 0; |
|
| 3291 | - } |
|
| 3288 | + public function __construct() |
|
| 3289 | + { |
|
| 3290 | + $this->delete_threshold = 0; |
|
| 3291 | + } |
|
| 3292 | 3292 | } |
| 3293 | 3293 | |
| 3294 | 3294 | /** |
@@ -3299,31 +3299,31 @@ discard block |
||
| 3299 | 3299 | class EE_Gateway_Config extends EE_Config_Base |
| 3300 | 3300 | { |
| 3301 | 3301 | |
| 3302 | - /** |
|
| 3303 | - * Array with keys that are payment gateways slugs, and values are arrays |
|
| 3304 | - * with any config info the gateway wants to store |
|
| 3305 | - * |
|
| 3306 | - * @var array |
|
| 3307 | - */ |
|
| 3308 | - public $payment_settings; |
|
| 3309 | - |
|
| 3310 | - /** |
|
| 3311 | - * Where keys are gateway slugs, and values are booleans indicating whether or not |
|
| 3312 | - * the gateway is stored in the uploads directory |
|
| 3313 | - * |
|
| 3314 | - * @var array |
|
| 3315 | - */ |
|
| 3316 | - public $active_gateways; |
|
| 3317 | - |
|
| 3318 | - |
|
| 3319 | - /** |
|
| 3320 | - * class constructor |
|
| 3321 | - * |
|
| 3322 | - * @deprecated |
|
| 3323 | - */ |
|
| 3324 | - public function __construct() |
|
| 3325 | - { |
|
| 3326 | - $this->payment_settings = array(); |
|
| 3327 | - $this->active_gateways = array('Invoice' => false); |
|
| 3328 | - } |
|
| 3302 | + /** |
|
| 3303 | + * Array with keys that are payment gateways slugs, and values are arrays |
|
| 3304 | + * with any config info the gateway wants to store |
|
| 3305 | + * |
|
| 3306 | + * @var array |
|
| 3307 | + */ |
|
| 3308 | + public $payment_settings; |
|
| 3309 | + |
|
| 3310 | + /** |
|
| 3311 | + * Where keys are gateway slugs, and values are booleans indicating whether or not |
|
| 3312 | + * the gateway is stored in the uploads directory |
|
| 3313 | + * |
|
| 3314 | + * @var array |
|
| 3315 | + */ |
|
| 3316 | + public $active_gateways; |
|
| 3317 | + |
|
| 3318 | + |
|
| 3319 | + /** |
|
| 3320 | + * class constructor |
|
| 3321 | + * |
|
| 3322 | + * @deprecated |
|
| 3323 | + */ |
|
| 3324 | + public function __construct() |
|
| 3325 | + { |
|
| 3326 | + $this->payment_settings = array(); |
|
| 3327 | + $this->active_gateways = array('Invoice' => false); |
|
| 3328 | + } |
|
| 3329 | 3329 | } |
@@ -14,1442 +14,1442 @@ |
||
| 14 | 14 | class Extend_Registration_Form_Admin_Page extends Registration_Form_Admin_Page |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
| 19 | - */ |
|
| 20 | - public function __construct($routing = true) |
|
| 21 | - { |
|
| 22 | - define('REGISTRATION_FORM_CAF_ADMIN', EE_CORE_CAF_ADMIN_EXTEND . 'registration_form/'); |
|
| 23 | - define('REGISTRATION_FORM_CAF_ASSETS_PATH', REGISTRATION_FORM_CAF_ADMIN . 'assets/'); |
|
| 24 | - define('REGISTRATION_FORM_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/assets/'); |
|
| 25 | - define('REGISTRATION_FORM_CAF_TEMPLATE_PATH', REGISTRATION_FORM_CAF_ADMIN . 'templates/'); |
|
| 26 | - define('REGISTRATION_FORM_CAF_TEMPLATE_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/templates/'); |
|
| 27 | - parent::__construct($routing); |
|
| 28 | - } |
|
| 29 | - |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @return void |
|
| 33 | - */ |
|
| 34 | - protected function _extend_page_config() |
|
| 35 | - { |
|
| 36 | - $this->_admin_base_path = REGISTRATION_FORM_CAF_ADMIN; |
|
| 37 | - $qst_id = ! empty($this->_req_data['QST_ID']) && ! is_array($this->_req_data['QST_ID']) |
|
| 38 | - ? $this->_req_data['QST_ID'] : 0; |
|
| 39 | - $qsg_id = ! empty($this->_req_data['QSG_ID']) && ! is_array($this->_req_data['QSG_ID']) |
|
| 40 | - ? $this->_req_data['QSG_ID'] : 0; |
|
| 41 | - |
|
| 42 | - $new_page_routes = array( |
|
| 43 | - 'question_groups' => array( |
|
| 44 | - 'func' => '_question_groups_overview_list_table', |
|
| 45 | - 'capability' => 'ee_read_question_groups', |
|
| 46 | - ), |
|
| 47 | - 'add_question' => array( |
|
| 48 | - 'func' => '_edit_question', |
|
| 49 | - 'capability' => 'ee_edit_questions', |
|
| 50 | - ), |
|
| 51 | - 'insert_question' => array( |
|
| 52 | - 'func' => '_insert_or_update_question', |
|
| 53 | - 'args' => array('new_question' => true), |
|
| 54 | - 'capability' => 'ee_edit_questions', |
|
| 55 | - 'noheader' => true, |
|
| 56 | - ), |
|
| 57 | - 'duplicate_question' => array( |
|
| 58 | - 'func' => '_duplicate_question', |
|
| 59 | - 'capability' => 'ee_edit_questions', |
|
| 60 | - 'noheader' => true, |
|
| 61 | - ), |
|
| 62 | - 'trash_question' => array( |
|
| 63 | - 'func' => '_trash_question', |
|
| 64 | - 'capability' => 'ee_delete_question', |
|
| 65 | - 'obj_id' => $qst_id, |
|
| 66 | - 'noheader' => true, |
|
| 67 | - ), |
|
| 68 | - |
|
| 69 | - 'restore_question' => array( |
|
| 70 | - 'func' => '_trash_or_restore_questions', |
|
| 71 | - 'capability' => 'ee_delete_question', |
|
| 72 | - 'obj_id' => $qst_id, |
|
| 73 | - 'args' => array('trash' => false), |
|
| 74 | - 'noheader' => true, |
|
| 75 | - ), |
|
| 76 | - |
|
| 77 | - 'delete_question' => array( |
|
| 78 | - 'func' => '_delete_question', |
|
| 79 | - 'capability' => 'ee_delete_question', |
|
| 80 | - 'obj_id' => $qst_id, |
|
| 81 | - 'noheader' => true, |
|
| 82 | - ), |
|
| 83 | - |
|
| 84 | - 'trash_questions' => array( |
|
| 85 | - 'func' => '_trash_or_restore_questions', |
|
| 86 | - 'capability' => 'ee_delete_questions', |
|
| 87 | - 'args' => array('trash' => true), |
|
| 88 | - 'noheader' => true, |
|
| 89 | - ), |
|
| 90 | - |
|
| 91 | - 'restore_questions' => array( |
|
| 92 | - 'func' => '_trash_or_restore_questions', |
|
| 93 | - 'capability' => 'ee_delete_questions', |
|
| 94 | - 'args' => array('trash' => false), |
|
| 95 | - 'noheader' => true, |
|
| 96 | - ), |
|
| 97 | - |
|
| 98 | - 'delete_questions' => array( |
|
| 99 | - 'func' => '_delete_questions', |
|
| 100 | - 'args' => array(), |
|
| 101 | - 'capability' => 'ee_delete_questions', |
|
| 102 | - 'noheader' => true, |
|
| 103 | - ), |
|
| 104 | - |
|
| 105 | - 'add_question_group' => array( |
|
| 106 | - 'func' => '_edit_question_group', |
|
| 107 | - 'capability' => 'ee_edit_question_groups', |
|
| 108 | - ), |
|
| 109 | - |
|
| 110 | - 'edit_question_group' => array( |
|
| 111 | - 'func' => '_edit_question_group', |
|
| 112 | - 'capability' => 'ee_edit_question_group', |
|
| 113 | - 'obj_id' => $qsg_id, |
|
| 114 | - 'args' => array('edit'), |
|
| 115 | - ), |
|
| 116 | - |
|
| 117 | - 'delete_question_groups' => array( |
|
| 118 | - 'func' => '_delete_question_groups', |
|
| 119 | - 'capability' => 'ee_delete_question_groups', |
|
| 120 | - 'noheader' => true, |
|
| 121 | - ), |
|
| 122 | - |
|
| 123 | - 'delete_question_group' => array( |
|
| 124 | - 'func' => '_delete_question_groups', |
|
| 125 | - 'capability' => 'ee_delete_question_group', |
|
| 126 | - 'obj_id' => $qsg_id, |
|
| 127 | - 'noheader' => true, |
|
| 128 | - ), |
|
| 129 | - |
|
| 130 | - 'trash_question_group' => array( |
|
| 131 | - 'func' => '_trash_or_restore_question_groups', |
|
| 132 | - 'args' => array('trash' => true), |
|
| 133 | - 'capability' => 'ee_delete_question_group', |
|
| 134 | - 'obj_id' => $qsg_id, |
|
| 135 | - 'noheader' => true, |
|
| 136 | - ), |
|
| 137 | - |
|
| 138 | - 'restore_question_group' => array( |
|
| 139 | - 'func' => '_trash_or_restore_question_groups', |
|
| 140 | - 'args' => array('trash' => false), |
|
| 141 | - 'capability' => 'ee_delete_question_group', |
|
| 142 | - 'obj_id' => $qsg_id, |
|
| 143 | - 'noheader' => true, |
|
| 144 | - ), |
|
| 145 | - |
|
| 146 | - 'insert_question_group' => array( |
|
| 147 | - 'func' => '_insert_or_update_question_group', |
|
| 148 | - 'args' => array('new_question_group' => true), |
|
| 149 | - 'capability' => 'ee_edit_question_groups', |
|
| 150 | - 'noheader' => true, |
|
| 151 | - ), |
|
| 152 | - |
|
| 153 | - 'update_question_group' => array( |
|
| 154 | - 'func' => '_insert_or_update_question_group', |
|
| 155 | - 'args' => array('new_question_group' => false), |
|
| 156 | - 'capability' => 'ee_edit_question_group', |
|
| 157 | - 'obj_id' => $qsg_id, |
|
| 158 | - 'noheader' => true, |
|
| 159 | - ), |
|
| 160 | - |
|
| 161 | - 'trash_question_groups' => array( |
|
| 162 | - 'func' => '_trash_or_restore_question_groups', |
|
| 163 | - 'args' => array('trash' => true), |
|
| 164 | - 'capability' => 'ee_delete_question_groups', |
|
| 165 | - 'noheader' => array('trash' => false), |
|
| 166 | - ), |
|
| 167 | - |
|
| 168 | - 'restore_question_groups' => array( |
|
| 169 | - 'func' => '_trash_or_restore_question_groups', |
|
| 170 | - 'args' => array('trash' => false), |
|
| 171 | - 'capability' => 'ee_delete_question_groups', |
|
| 172 | - 'noheader' => true, |
|
| 173 | - ), |
|
| 174 | - |
|
| 175 | - |
|
| 176 | - 'espresso_update_question_group_order' => array( |
|
| 177 | - 'func' => 'update_question_group_order', |
|
| 178 | - 'capability' => 'ee_edit_question_groups', |
|
| 179 | - 'noheader' => true, |
|
| 180 | - ), |
|
| 181 | - |
|
| 182 | - 'view_reg_form_settings' => array( |
|
| 183 | - 'func' => '_reg_form_settings', |
|
| 184 | - 'capability' => 'manage_options', |
|
| 185 | - ), |
|
| 186 | - |
|
| 187 | - 'update_reg_form_settings' => array( |
|
| 188 | - 'func' => '_update_reg_form_settings', |
|
| 189 | - 'capability' => 'manage_options', |
|
| 190 | - 'noheader' => true, |
|
| 191 | - ), |
|
| 192 | - ); |
|
| 193 | - $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
| 194 | - |
|
| 195 | - $new_page_config = array( |
|
| 196 | - |
|
| 197 | - 'question_groups' => array( |
|
| 198 | - 'nav' => array( |
|
| 199 | - 'label' => esc_html__('Question Groups', 'event_espresso'), |
|
| 200 | - 'order' => 20, |
|
| 201 | - ), |
|
| 202 | - 'list_table' => 'Registration_Form_Question_Groups_Admin_List_Table', |
|
| 203 | - 'help_tabs' => array( |
|
| 204 | - 'registration_form_question_groups_help_tab' => array( |
|
| 205 | - 'title' => esc_html__('Question Groups', 'event_espresso'), |
|
| 206 | - 'filename' => 'registration_form_question_groups', |
|
| 207 | - ), |
|
| 208 | - 'registration_form_question_groups_table_column_headings_help_tab' => array( |
|
| 209 | - 'title' => esc_html__('Question Groups Table Column Headings', 'event_espresso'), |
|
| 210 | - 'filename' => 'registration_form_question_groups_table_column_headings', |
|
| 211 | - ), |
|
| 212 | - 'registration_form_question_groups_views_bulk_actions_search_help_tab' => array( |
|
| 213 | - 'title' => esc_html__('Question Groups Views & Bulk Actions & Search', 'event_espresso'), |
|
| 214 | - 'filename' => 'registration_form_question_groups_views_bulk_actions_search', |
|
| 215 | - ), |
|
| 216 | - ), |
|
| 217 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 218 | - // 'help_tour' => array('Registration_Form_Question_Groups_Help_Tour'), |
|
| 219 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 220 | - 'require_nonce' => false, |
|
| 221 | - 'qtips' => array( |
|
| 222 | - 'EE_Registration_Form_Tips', |
|
| 223 | - ), |
|
| 224 | - ), |
|
| 225 | - |
|
| 226 | - 'add_question' => array( |
|
| 227 | - 'nav' => array( |
|
| 228 | - 'label' => esc_html__('Add Question', 'event_espresso'), |
|
| 229 | - 'order' => 5, |
|
| 230 | - 'persistent' => false, |
|
| 231 | - ), |
|
| 232 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 233 | - 'help_tabs' => array( |
|
| 234 | - 'registration_form_add_question_help_tab' => array( |
|
| 235 | - 'title' => esc_html__('Add Question', 'event_espresso'), |
|
| 236 | - 'filename' => 'registration_form_add_question', |
|
| 237 | - ), |
|
| 238 | - ), |
|
| 239 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 240 | - // 'help_tour' => array('Registration_Form_Add_Question_Help_Tour'), |
|
| 241 | - 'require_nonce' => false, |
|
| 242 | - ), |
|
| 243 | - |
|
| 244 | - 'add_question_group' => array( |
|
| 245 | - 'nav' => array( |
|
| 246 | - 'label' => esc_html__('Add Question Group', 'event_espresso'), |
|
| 247 | - 'order' => 5, |
|
| 248 | - 'persistent' => false, |
|
| 249 | - ), |
|
| 250 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 251 | - 'help_tabs' => array( |
|
| 252 | - 'registration_form_add_question_group_help_tab' => array( |
|
| 253 | - 'title' => esc_html__('Add Question Group', 'event_espresso'), |
|
| 254 | - 'filename' => 'registration_form_add_question_group', |
|
| 255 | - ), |
|
| 256 | - ), |
|
| 257 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 258 | - // 'help_tour' => array('Registration_Form_Add_Question_Group_Help_Tour'), |
|
| 259 | - 'require_nonce' => false, |
|
| 260 | - ), |
|
| 261 | - |
|
| 262 | - 'edit_question_group' => array( |
|
| 263 | - 'nav' => array( |
|
| 264 | - 'label' => esc_html__('Edit Question Group', 'event_espresso'), |
|
| 265 | - 'order' => 5, |
|
| 266 | - 'persistent' => false, |
|
| 267 | - 'url' => isset($this->_req_data['question_group_id']) ? add_query_arg( |
|
| 268 | - array('question_group_id' => $this->_req_data['question_group_id']), |
|
| 269 | - $this->_current_page_view_url |
|
| 270 | - ) : $this->_admin_base_url, |
|
| 271 | - ), |
|
| 272 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 273 | - 'help_tabs' => array( |
|
| 274 | - 'registration_form_edit_question_group_help_tab' => array( |
|
| 275 | - 'title' => esc_html__('Edit Question Group', 'event_espresso'), |
|
| 276 | - 'filename' => 'registration_form_edit_question_group', |
|
| 277 | - ), |
|
| 278 | - ), |
|
| 279 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 280 | - // 'help_tour' => array('Registration_Form_Edit_Question_Group_Help_Tour'), |
|
| 281 | - 'require_nonce' => false, |
|
| 282 | - ), |
|
| 283 | - |
|
| 284 | - 'view_reg_form_settings' => array( |
|
| 285 | - 'nav' => array( |
|
| 286 | - 'label' => esc_html__('Reg Form Settings', 'event_espresso'), |
|
| 287 | - 'order' => 40, |
|
| 288 | - ), |
|
| 289 | - 'labels' => array( |
|
| 290 | - 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
| 291 | - ), |
|
| 292 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 293 | - 'help_tabs' => array( |
|
| 294 | - 'registration_form_reg_form_settings_help_tab' => array( |
|
| 295 | - 'title' => esc_html__('Registration Form Settings', 'event_espresso'), |
|
| 296 | - 'filename' => 'registration_form_reg_form_settings', |
|
| 297 | - ), |
|
| 298 | - ), |
|
| 299 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 300 | - // 'help_tour' => array('Registration_Form_Settings_Help_Tour'), |
|
| 301 | - 'require_nonce' => false, |
|
| 302 | - ), |
|
| 303 | - |
|
| 304 | - ); |
|
| 305 | - $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
| 306 | - |
|
| 307 | - // change the list table we're going to use so it's the NEW list table! |
|
| 308 | - $this->_page_config['default']['list_table'] = 'Extend_Registration_Form_Questions_Admin_List_Table'; |
|
| 309 | - |
|
| 310 | - |
|
| 311 | - // additional labels |
|
| 312 | - $new_labels = array( |
|
| 313 | - 'add_question' => esc_html__('Add New Question', 'event_espresso'), |
|
| 314 | - 'delete_question' => esc_html__('Delete Question', 'event_espresso'), |
|
| 315 | - 'add_question_group' => esc_html__('Add New Question Group', 'event_espresso'), |
|
| 316 | - 'edit_question_group' => esc_html__('Edit Question Group', 'event_espresso'), |
|
| 317 | - 'delete_question_group' => esc_html__('Delete Question Group', 'event_espresso'), |
|
| 318 | - ); |
|
| 319 | - $this->_labels['buttons'] = array_merge($this->_labels['buttons'], $new_labels); |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - |
|
| 323 | - /** |
|
| 324 | - * @return void |
|
| 325 | - */ |
|
| 326 | - protected function _ajax_hooks() |
|
| 327 | - { |
|
| 328 | - add_action('wp_ajax_espresso_update_question_group_order', array($this, 'update_question_group_order')); |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - |
|
| 332 | - /** |
|
| 333 | - * @return void |
|
| 334 | - */ |
|
| 335 | - public function load_scripts_styles_question_groups() |
|
| 336 | - { |
|
| 337 | - wp_enqueue_script('espresso_ajax_table_sorting'); |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - |
|
| 341 | - /** |
|
| 342 | - * @return void |
|
| 343 | - */ |
|
| 344 | - public function load_scripts_styles_add_question_group() |
|
| 345 | - { |
|
| 346 | - $this->load_scripts_styles_forms(); |
|
| 347 | - $this->load_sortable_question_script(); |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - |
|
| 351 | - /** |
|
| 352 | - * @return void |
|
| 353 | - */ |
|
| 354 | - public function load_scripts_styles_edit_question_group() |
|
| 355 | - { |
|
| 356 | - $this->load_scripts_styles_forms(); |
|
| 357 | - $this->load_sortable_question_script(); |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - |
|
| 361 | - /** |
|
| 362 | - * registers and enqueues script for questions |
|
| 363 | - * |
|
| 364 | - * @return void |
|
| 365 | - */ |
|
| 366 | - public function load_sortable_question_script() |
|
| 367 | - { |
|
| 368 | - wp_register_script( |
|
| 369 | - 'ee-question-sortable', |
|
| 370 | - REGISTRATION_FORM_CAF_ASSETS_URL . 'ee_question_order.js', |
|
| 371 | - array('jquery-ui-sortable'), |
|
| 372 | - EVENT_ESPRESSO_VERSION, |
|
| 373 | - true |
|
| 374 | - ); |
|
| 375 | - wp_enqueue_script('ee-question-sortable'); |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - |
|
| 379 | - /** |
|
| 380 | - * @return void |
|
| 381 | - */ |
|
| 382 | - protected function _set_list_table_views_default() |
|
| 383 | - { |
|
| 384 | - $this->_views = array( |
|
| 385 | - 'all' => array( |
|
| 386 | - 'slug' => 'all', |
|
| 387 | - 'label' => esc_html__('View All Questions', 'event_espresso'), |
|
| 388 | - 'count' => 0, |
|
| 389 | - 'bulk_action' => array( |
|
| 390 | - 'trash_questions' => esc_html__('Trash', 'event_espresso'), |
|
| 391 | - ), |
|
| 392 | - ), |
|
| 393 | - ); |
|
| 394 | - |
|
| 395 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 396 | - 'ee_delete_questions', |
|
| 397 | - 'espresso_registration_form_trash_questions' |
|
| 398 | - ) |
|
| 399 | - ) { |
|
| 400 | - $this->_views['trash'] = array( |
|
| 401 | - 'slug' => 'trash', |
|
| 402 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 403 | - 'count' => 0, |
|
| 404 | - 'bulk_action' => array( |
|
| 405 | - 'delete_questions' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 406 | - 'restore_questions' => esc_html__('Restore', 'event_espresso'), |
|
| 407 | - ), |
|
| 408 | - ); |
|
| 409 | - } |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - |
|
| 413 | - /** |
|
| 414 | - * @return void |
|
| 415 | - */ |
|
| 416 | - protected function _set_list_table_views_question_groups() |
|
| 417 | - { |
|
| 418 | - $this->_views = array( |
|
| 419 | - 'all' => array( |
|
| 420 | - 'slug' => 'all', |
|
| 421 | - 'label' => esc_html__('All', 'event_espresso'), |
|
| 422 | - 'count' => 0, |
|
| 423 | - 'bulk_action' => array( |
|
| 424 | - 'trash_question_groups' => esc_html__('Trash', 'event_espresso'), |
|
| 425 | - ), |
|
| 426 | - ), |
|
| 427 | - ); |
|
| 428 | - |
|
| 429 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 430 | - 'ee_delete_question_groups', |
|
| 431 | - 'espresso_registration_form_trash_question_groups' |
|
| 432 | - ) |
|
| 433 | - ) { |
|
| 434 | - $this->_views['trash'] = array( |
|
| 435 | - 'slug' => 'trash', |
|
| 436 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 437 | - 'count' => 0, |
|
| 438 | - 'bulk_action' => array( |
|
| 439 | - 'delete_question_groups' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 440 | - 'restore_question_groups' => esc_html__('Restore', 'event_espresso'), |
|
| 441 | - ), |
|
| 442 | - ); |
|
| 443 | - } |
|
| 444 | - } |
|
| 445 | - |
|
| 446 | - |
|
| 447 | - /** |
|
| 448 | - * @return void |
|
| 449 | - * @throws EE_Error |
|
| 450 | - * @throws InvalidArgumentException |
|
| 451 | - * @throws InvalidDataTypeException |
|
| 452 | - * @throws InvalidInterfaceException |
|
| 453 | - */ |
|
| 454 | - protected function _questions_overview_list_table() |
|
| 455 | - { |
|
| 456 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 457 | - 'add_question', |
|
| 458 | - 'add_question', |
|
| 459 | - array(), |
|
| 460 | - 'add-new-h2' |
|
| 461 | - ); |
|
| 462 | - parent::_questions_overview_list_table(); |
|
| 463 | - } |
|
| 464 | - |
|
| 465 | - |
|
| 466 | - /** |
|
| 467 | - * @return void |
|
| 468 | - * @throws DomainException |
|
| 469 | - * @throws EE_Error |
|
| 470 | - * @throws InvalidArgumentException |
|
| 471 | - * @throws InvalidDataTypeException |
|
| 472 | - * @throws InvalidInterfaceException |
|
| 473 | - */ |
|
| 474 | - protected function _question_groups_overview_list_table() |
|
| 475 | - { |
|
| 476 | - $this->_search_btn_label = esc_html__('Question Groups', 'event_espresso'); |
|
| 477 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 478 | - 'add_question_group', |
|
| 479 | - 'add_question_group', |
|
| 480 | - array(), |
|
| 481 | - 'add-new-h2' |
|
| 482 | - ); |
|
| 483 | - $this->display_admin_list_table_page_with_sidebar(); |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - |
|
| 487 | - /** |
|
| 488 | - * @return void |
|
| 489 | - * @throws EE_Error |
|
| 490 | - * @throws InvalidArgumentException |
|
| 491 | - * @throws InvalidDataTypeException |
|
| 492 | - * @throws InvalidInterfaceException |
|
| 493 | - */ |
|
| 494 | - protected function _delete_question() |
|
| 495 | - { |
|
| 496 | - $success = $this->_delete_items($this->_question_model); |
|
| 497 | - $this->_redirect_after_action( |
|
| 498 | - $success, |
|
| 499 | - $this->_question_model->item_name($success), |
|
| 500 | - 'deleted', |
|
| 501 | - array('action' => 'default', 'status' => 'all') |
|
| 502 | - ); |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - |
|
| 506 | - /** |
|
| 507 | - * @return void |
|
| 508 | - * @throws EE_Error |
|
| 509 | - * @throws InvalidArgumentException |
|
| 510 | - * @throws InvalidDataTypeException |
|
| 511 | - * @throws InvalidInterfaceException |
|
| 512 | - */ |
|
| 513 | - protected function _delete_questions() |
|
| 514 | - { |
|
| 515 | - $success = $this->_delete_items($this->_question_model); |
|
| 516 | - $this->_redirect_after_action( |
|
| 517 | - $success, |
|
| 518 | - $this->_question_model->item_name($success), |
|
| 519 | - 'deleted permanently', |
|
| 520 | - array('action' => 'default', 'status' => 'trash') |
|
| 521 | - ); |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - |
|
| 525 | - /** |
|
| 526 | - * Performs the deletion of a single or multiple questions or question groups. |
|
| 527 | - * |
|
| 528 | - * @param EEM_Soft_Delete_Base $model |
|
| 529 | - * @return int number of items deleted permanently |
|
| 530 | - * @throws EE_Error |
|
| 531 | - * @throws InvalidArgumentException |
|
| 532 | - * @throws InvalidDataTypeException |
|
| 533 | - * @throws InvalidInterfaceException |
|
| 534 | - */ |
|
| 535 | - private function _delete_items(EEM_Soft_Delete_Base $model) |
|
| 536 | - { |
|
| 537 | - $success = 0; |
|
| 538 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 539 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 540 | - // if array has more than one element than success message should be plural |
|
| 541 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 542 | - // cycle thru bulk action checkboxes |
|
| 543 | - while (list($ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 544 | - if (! $this->_delete_item($ID, $model)) { |
|
| 545 | - $success = 0; |
|
| 546 | - } |
|
| 547 | - } |
|
| 548 | - } elseif (! empty($this->_req_data['QSG_ID'])) { |
|
| 549 | - $success = $this->_delete_item($this->_req_data['QSG_ID'], $model); |
|
| 550 | - } elseif (! empty($this->_req_data['QST_ID'])) { |
|
| 551 | - $success = $this->_delete_item($this->_req_data['QST_ID'], $model); |
|
| 552 | - } else { |
|
| 553 | - EE_Error::add_error( |
|
| 554 | - sprintf( |
|
| 555 | - esc_html__( |
|
| 556 | - "No Questions or Question Groups were selected for deleting. This error usually shows when you've attempted to delete via bulk action but there were no selections.", |
|
| 557 | - "event_espresso" |
|
| 558 | - ) |
|
| 559 | - ), |
|
| 560 | - __FILE__, |
|
| 561 | - __FUNCTION__, |
|
| 562 | - __LINE__ |
|
| 563 | - ); |
|
| 564 | - } |
|
| 565 | - return $success; |
|
| 566 | - } |
|
| 567 | - |
|
| 568 | - |
|
| 569 | - /** |
|
| 570 | - * Deletes the specified question (and its associated question options) or question group |
|
| 571 | - * |
|
| 572 | - * @param int $id |
|
| 573 | - * @param EEM_Soft_Delete_Base $model |
|
| 574 | - * @return boolean |
|
| 575 | - * @throws EE_Error |
|
| 576 | - * @throws InvalidArgumentException |
|
| 577 | - * @throws InvalidDataTypeException |
|
| 578 | - * @throws InvalidInterfaceException |
|
| 579 | - */ |
|
| 580 | - protected function _delete_item($id, $model) |
|
| 581 | - { |
|
| 582 | - if ($model instanceof EEM_Question) { |
|
| 583 | - EEM_Question_Option::instance()->delete_permanently(array(array('QST_ID' => absint($id)))); |
|
| 584 | - } |
|
| 585 | - return $model->delete_permanently_by_ID(absint($id)); |
|
| 586 | - } |
|
| 587 | - |
|
| 588 | - |
|
| 589 | - /****************************** QUESTION GROUPS ******************************/ |
|
| 590 | - |
|
| 591 | - |
|
| 592 | - /** |
|
| 593 | - * @param string $type |
|
| 594 | - * @return void |
|
| 595 | - * @throws DomainException |
|
| 596 | - * @throws EE_Error |
|
| 597 | - * @throws InvalidArgumentException |
|
| 598 | - * @throws InvalidDataTypeException |
|
| 599 | - * @throws InvalidInterfaceException |
|
| 600 | - */ |
|
| 601 | - protected function _edit_question_group($type = 'add') |
|
| 602 | - { |
|
| 603 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 604 | - $ID = isset($this->_req_data['QSG_ID']) && ! empty($this->_req_data['QSG_ID']) |
|
| 605 | - ? absint($this->_req_data['QSG_ID']) |
|
| 606 | - : false; |
|
| 607 | - |
|
| 608 | - switch ($this->_req_action) { |
|
| 609 | - case 'add_question_group': |
|
| 610 | - $this->_admin_page_title = esc_html__('Add Question Group', 'event_espresso'); |
|
| 611 | - break; |
|
| 612 | - case 'edit_question_group': |
|
| 613 | - $this->_admin_page_title = esc_html__('Edit Question Group', 'event_espresso'); |
|
| 614 | - break; |
|
| 615 | - default: |
|
| 616 | - $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
|
| 617 | - } |
|
| 618 | - // add ID to title if editing |
|
| 619 | - $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title; |
|
| 620 | - if ($ID) { |
|
| 621 | - /** @var EE_Question_Group $questionGroup */ |
|
| 622 | - $questionGroup = $this->_question_group_model->get_one_by_ID($ID); |
|
| 623 | - $additional_hidden_fields = array('QSG_ID' => array('type' => 'hidden', 'value' => $ID)); |
|
| 624 | - $this->_set_add_edit_form_tags('update_question_group', $additional_hidden_fields); |
|
| 625 | - } else { |
|
| 626 | - /** @var EE_Question_Group $questionGroup */ |
|
| 627 | - $questionGroup = EEM_Question_Group::instance()->create_default_object(); |
|
| 628 | - $questionGroup->set_order_to_latest(); |
|
| 629 | - $this->_set_add_edit_form_tags('insert_question_group'); |
|
| 630 | - } |
|
| 631 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
| 632 | - $this->_template_args['all_questions'] = $questionGroup->questions_in_and_not_in_group(); |
|
| 633 | - $this->_template_args['QSG_ID'] = $ID ? $ID : true; |
|
| 634 | - $this->_template_args['question_group'] = $questionGroup; |
|
| 635 | - |
|
| 636 | - $redirect_URL = add_query_arg(array('action' => 'question_groups'), $this->_admin_base_url); |
|
| 637 | - $this->_set_publish_post_box_vars('id', $ID, false, $redirect_URL); |
|
| 638 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 639 | - REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'question_groups_main_meta_box.template.php', |
|
| 640 | - $this->_template_args, |
|
| 641 | - true |
|
| 642 | - ); |
|
| 643 | - |
|
| 644 | - // the details template wrapper |
|
| 645 | - $this->display_admin_page_with_sidebar(); |
|
| 646 | - } |
|
| 647 | - |
|
| 648 | - |
|
| 649 | - /** |
|
| 650 | - * @return void |
|
| 651 | - * @throws EE_Error |
|
| 652 | - * @throws InvalidArgumentException |
|
| 653 | - * @throws InvalidDataTypeException |
|
| 654 | - * @throws InvalidInterfaceException |
|
| 655 | - */ |
|
| 656 | - protected function _delete_question_groups() |
|
| 657 | - { |
|
| 658 | - $success = $this->_delete_items($this->_question_group_model); |
|
| 659 | - $this->_redirect_after_action( |
|
| 660 | - $success, |
|
| 661 | - $this->_question_group_model->item_name($success), |
|
| 662 | - 'deleted permanently', |
|
| 663 | - array('action' => 'question_groups', 'status' => 'trash') |
|
| 664 | - ); |
|
| 665 | - } |
|
| 666 | - |
|
| 667 | - |
|
| 668 | - /** |
|
| 669 | - * @param bool $new_question_group |
|
| 670 | - * @throws EE_Error |
|
| 671 | - * @throws InvalidArgumentException |
|
| 672 | - * @throws InvalidDataTypeException |
|
| 673 | - * @throws InvalidInterfaceException |
|
| 674 | - */ |
|
| 675 | - protected function _insert_or_update_question_group($new_question_group = true) |
|
| 676 | - { |
|
| 677 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 678 | - $set_column_values = $this->_set_column_values_for($this->_question_group_model); |
|
| 679 | - if ($new_question_group) { |
|
| 680 | - // make sure identifier is unique |
|
| 681 | - $identifier_value = isset($set_column_values['QSG_identifier']) ? $set_column_values['QSG_identifier'] : ''; |
|
| 682 | - $identifier_exists = ! empty($identifier_value) |
|
| 683 | - ? $this->_question_group_model->count([['QSG_identifier' => $set_column_values['QSG_identifier']]]) > 0 |
|
| 684 | - : false; |
|
| 685 | - if ($identifier_exists) { |
|
| 686 | - $set_column_values['QSG_identifier'] .= uniqid('id', true); |
|
| 687 | - } |
|
| 688 | - $QSG_ID = $this->_question_group_model->insert($set_column_values); |
|
| 689 | - $success = $QSG_ID ? 1 : 0; |
|
| 690 | - if ($success === 0) { |
|
| 691 | - EE_Error::add_error( |
|
| 692 | - esc_html__('Something went wrong saving the question group.', 'event_espresso'), |
|
| 693 | - __FILE__, |
|
| 694 | - __FUNCTION__, |
|
| 695 | - __LINE__ |
|
| 696 | - ); |
|
| 697 | - $this->_redirect_after_action( |
|
| 698 | - false, |
|
| 699 | - '', |
|
| 700 | - '', |
|
| 701 | - array('action' => 'edit_question_group', 'QSG_ID' => $QSG_ID), |
|
| 702 | - true |
|
| 703 | - ); |
|
| 704 | - } |
|
| 705 | - } else { |
|
| 706 | - $QSG_ID = absint($this->_req_data['QSG_ID']); |
|
| 707 | - unset($set_column_values['QSG_ID']); |
|
| 708 | - $success = $this->_question_group_model->update($set_column_values, array(array('QSG_ID' => $QSG_ID))); |
|
| 709 | - } |
|
| 710 | - |
|
| 711 | - $phone_question_id = EEM_Question::instance()->get_Question_ID_from_system_string( |
|
| 712 | - EEM_Attendee::system_question_phone |
|
| 713 | - ); |
|
| 714 | - // update the existing related questions |
|
| 715 | - // BUT FIRST... delete the phone question from the Question_Group_Question |
|
| 716 | - // if it is being added to this question group (therefore removed from the existing group) |
|
| 717 | - if (isset($this->_req_data['questions'], $this->_req_data['questions'][ $phone_question_id ])) { |
|
| 718 | - // delete where QST ID = system phone question ID and Question Group ID is NOT this group |
|
| 719 | - EEM_Question_Group_Question::instance()->delete( |
|
| 720 | - array( |
|
| 721 | - array( |
|
| 722 | - 'QST_ID' => $phone_question_id, |
|
| 723 | - 'QSG_ID' => array('!=', $QSG_ID), |
|
| 724 | - ), |
|
| 725 | - ) |
|
| 726 | - ); |
|
| 727 | - } |
|
| 728 | - /** @type EE_Question_Group $question_group */ |
|
| 729 | - $question_group = $this->_question_group_model->get_one_by_ID($QSG_ID); |
|
| 730 | - $questions = $question_group->questions(); |
|
| 731 | - // make sure system phone question is added to list of questions for this group |
|
| 732 | - if (! isset($questions[ $phone_question_id ])) { |
|
| 733 | - $questions[ $phone_question_id ] = EEM_Question::instance()->get_one_by_ID($phone_question_id); |
|
| 734 | - } |
|
| 735 | - |
|
| 736 | - foreach ($questions as $question_ID => $question) { |
|
| 737 | - // first we always check for order. |
|
| 738 | - if (! empty($this->_req_data['question_orders'][ $question_ID ])) { |
|
| 739 | - // update question order |
|
| 740 | - $question_group->update_question_order( |
|
| 741 | - $question_ID, |
|
| 742 | - $this->_req_data['question_orders'][ $question_ID ] |
|
| 743 | - ); |
|
| 744 | - } |
|
| 745 | - |
|
| 746 | - // then we always check if adding or removing. |
|
| 747 | - if (isset($this->_req_data['questions'], $this->_req_data['questions'][ $question_ID ])) { |
|
| 748 | - $question_group->add_question($question_ID); |
|
| 749 | - } else { |
|
| 750 | - // not found, remove it (but only if not a system question for the personal group |
|
| 751 | - // with the exception of lname system question - we allow removal of it) |
|
| 752 | - if (in_array( |
|
| 753 | - $question->system_ID(), |
|
| 754 | - EEM_Question::instance()->required_system_questions_in_system_question_group( |
|
| 755 | - $question_group->system_group() |
|
| 756 | - ) |
|
| 757 | - )) { |
|
| 758 | - continue; |
|
| 759 | - } else { |
|
| 760 | - $question_group->remove_question($question_ID); |
|
| 761 | - } |
|
| 762 | - } |
|
| 763 | - } |
|
| 764 | - // save new related questions |
|
| 765 | - if (isset($this->_req_data['questions'])) { |
|
| 766 | - foreach ($this->_req_data['questions'] as $QST_ID) { |
|
| 767 | - $question_group->add_question($QST_ID); |
|
| 768 | - if (isset($this->_req_data['question_orders'][ $QST_ID ])) { |
|
| 769 | - $question_group->update_question_order($QST_ID, $this->_req_data['question_orders'][ $QST_ID ]); |
|
| 770 | - } |
|
| 771 | - } |
|
| 772 | - } |
|
| 773 | - |
|
| 774 | - if ($success !== false) { |
|
| 775 | - $msg = $new_question_group |
|
| 776 | - ? sprintf( |
|
| 777 | - esc_html__('The %s has been created', 'event_espresso'), |
|
| 778 | - $this->_question_group_model->item_name() |
|
| 779 | - ) |
|
| 780 | - : sprintf( |
|
| 781 | - esc_html__( |
|
| 782 | - 'The %s has been updated', |
|
| 783 | - 'event_espresso' |
|
| 784 | - ), |
|
| 785 | - $this->_question_group_model->item_name() |
|
| 786 | - ); |
|
| 787 | - EE_Error::add_success($msg); |
|
| 788 | - } |
|
| 789 | - $this->_redirect_after_action( |
|
| 790 | - false, |
|
| 791 | - '', |
|
| 792 | - '', |
|
| 793 | - array('action' => 'edit_question_group', 'QSG_ID' => $QSG_ID), |
|
| 794 | - true |
|
| 795 | - ); |
|
| 796 | - } |
|
| 797 | - |
|
| 798 | - |
|
| 799 | - /** |
|
| 800 | - * duplicates a question and all its question options and redirects to the new question. |
|
| 801 | - * |
|
| 802 | - * @return void |
|
| 803 | - * @throws EE_Error |
|
| 804 | - * @throws InvalidArgumentException |
|
| 805 | - * @throws ReflectionException |
|
| 806 | - * @throws InvalidDataTypeException |
|
| 807 | - * @throws InvalidInterfaceException |
|
| 808 | - */ |
|
| 809 | - public function _duplicate_question() |
|
| 810 | - { |
|
| 811 | - $question_ID = (int) $this->_req_data['QST_ID']; |
|
| 812 | - $question = EEM_Question::instance()->get_one_by_ID($question_ID); |
|
| 813 | - if ($question instanceof EE_Question) { |
|
| 814 | - $new_question = $question->duplicate(); |
|
| 815 | - if ($new_question instanceof EE_Question) { |
|
| 816 | - $this->_redirect_after_action( |
|
| 817 | - true, |
|
| 818 | - esc_html__('Question', 'event_espresso'), |
|
| 819 | - esc_html__('Duplicated', 'event_espresso'), |
|
| 820 | - array('action' => 'edit_question', 'QST_ID' => $new_question->ID()), |
|
| 821 | - true |
|
| 822 | - ); |
|
| 823 | - } else { |
|
| 824 | - global $wpdb; |
|
| 825 | - EE_Error::add_error( |
|
| 826 | - sprintf( |
|
| 827 | - esc_html__( |
|
| 828 | - 'Could not duplicate question with ID %1$d because: %2$s', |
|
| 829 | - 'event_espresso' |
|
| 830 | - ), |
|
| 831 | - $question_ID, |
|
| 832 | - $wpdb->last_error |
|
| 833 | - ), |
|
| 834 | - __FILE__, |
|
| 835 | - __FUNCTION__, |
|
| 836 | - __LINE__ |
|
| 837 | - ); |
|
| 838 | - $this->_redirect_after_action(false, '', '', array('action' => 'default'), false); |
|
| 839 | - } |
|
| 840 | - } else { |
|
| 841 | - EE_Error::add_error( |
|
| 842 | - sprintf( |
|
| 843 | - esc_html__( |
|
| 844 | - 'Could not duplicate question with ID %d because it didn\'t exist!', |
|
| 845 | - 'event_espresso' |
|
| 846 | - ), |
|
| 847 | - $question_ID |
|
| 848 | - ), |
|
| 849 | - __FILE__, |
|
| 850 | - __FUNCTION__, |
|
| 851 | - __LINE__ |
|
| 852 | - ); |
|
| 853 | - $this->_redirect_after_action(false, '', '', array('action' => 'default'), false); |
|
| 854 | - } |
|
| 855 | - } |
|
| 856 | - |
|
| 857 | - |
|
| 858 | - /** |
|
| 859 | - * @param bool $trash |
|
| 860 | - * @throws EE_Error |
|
| 861 | - */ |
|
| 862 | - protected function _trash_or_restore_question_groups($trash = true) |
|
| 863 | - { |
|
| 864 | - $this->_trash_or_restore_items($this->_question_group_model, $trash); |
|
| 865 | - } |
|
| 866 | - |
|
| 867 | - |
|
| 868 | - /** |
|
| 869 | - *_trash_question |
|
| 870 | - * |
|
| 871 | - * @return void |
|
| 872 | - * @throws EE_Error |
|
| 873 | - */ |
|
| 874 | - protected function _trash_question() |
|
| 875 | - { |
|
| 876 | - $success = $this->_question_model->delete_by_ID((int) $this->_req_data['QST_ID']); |
|
| 877 | - $query_args = array('action' => 'default', 'status' => 'all'); |
|
| 878 | - $this->_redirect_after_action($success, $this->_question_model->item_name($success), 'trashed', $query_args); |
|
| 879 | - } |
|
| 880 | - |
|
| 881 | - |
|
| 882 | - /** |
|
| 883 | - * @param bool $trash |
|
| 884 | - * @throws EE_Error |
|
| 885 | - */ |
|
| 886 | - protected function _trash_or_restore_questions($trash = true) |
|
| 887 | - { |
|
| 888 | - $this->_trash_or_restore_items($this->_question_model, $trash); |
|
| 889 | - } |
|
| 890 | - |
|
| 891 | - |
|
| 892 | - /** |
|
| 893 | - * Internally used to delete or restore items, using the request data. Meant to be |
|
| 894 | - * flexible between question or question groups |
|
| 895 | - * |
|
| 896 | - * @param EEM_Soft_Delete_Base $model |
|
| 897 | - * @param boolean $trash whether to trash or restore |
|
| 898 | - * @throws EE_Error |
|
| 899 | - */ |
|
| 900 | - private function _trash_or_restore_items(EEM_Soft_Delete_Base $model, $trash = true) |
|
| 901 | - { |
|
| 902 | - |
|
| 903 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 904 | - |
|
| 905 | - $success = 1; |
|
| 906 | - // Checkboxes |
|
| 907 | - // echo "trash $trash"; |
|
| 908 | - // var_dump($this->_req_data['checkbox']);die; |
|
| 909 | - if (isset($this->_req_data['checkbox'])) { |
|
| 910 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 911 | - // if array has more than one element than success message should be plural |
|
| 912 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 913 | - // cycle thru bulk action checkboxes |
|
| 914 | - while (list($ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 915 | - if (! $model->delete_or_restore_by_ID($trash, absint($ID))) { |
|
| 916 | - $success = 0; |
|
| 917 | - } |
|
| 918 | - } |
|
| 919 | - } else { |
|
| 920 | - // grab single id and delete |
|
| 921 | - $ID = absint($this->_req_data['checkbox']); |
|
| 922 | - if (! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
| 923 | - $success = 0; |
|
| 924 | - } |
|
| 925 | - } |
|
| 926 | - } else { |
|
| 927 | - // delete via trash link |
|
| 928 | - // grab single id and delete |
|
| 929 | - $ID = absint($this->_req_data[ $model->primary_key_name() ]); |
|
| 930 | - if (! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
| 931 | - $success = 0; |
|
| 932 | - } |
|
| 933 | - } |
|
| 934 | - |
|
| 935 | - |
|
| 936 | - $action = $model instanceof EEM_Question ? 'default' : 'question_groups';// strtolower( $model->item_name(2) ); |
|
| 937 | - // echo "action :$action"; |
|
| 938 | - // $action = 'questions' ? 'default' : $action; |
|
| 939 | - if ($trash) { |
|
| 940 | - $action_desc = 'trashed'; |
|
| 941 | - $status = 'trash'; |
|
| 942 | - } else { |
|
| 943 | - $action_desc = 'restored'; |
|
| 944 | - $status = 'all'; |
|
| 945 | - } |
|
| 946 | - $this->_redirect_after_action( |
|
| 947 | - $success, |
|
| 948 | - $model->item_name($success), |
|
| 949 | - $action_desc, |
|
| 950 | - array('action' => $action, 'status' => $status) |
|
| 951 | - ); |
|
| 952 | - } |
|
| 953 | - |
|
| 954 | - |
|
| 955 | - /** |
|
| 956 | - * @param $per_page |
|
| 957 | - * @param int $current_page |
|
| 958 | - * @param bool|false $count |
|
| 959 | - * @return EE_Soft_Delete_Base_Class[]|int |
|
| 960 | - * @throws EE_Error |
|
| 961 | - * @throws InvalidArgumentException |
|
| 962 | - * @throws InvalidDataTypeException |
|
| 963 | - * @throws InvalidInterfaceException |
|
| 964 | - */ |
|
| 965 | - public function get_trashed_questions($per_page, $current_page = 1, $count = false) |
|
| 966 | - { |
|
| 967 | - $query_params = $this->get_query_params(EEM_Question::instance(), $per_page, $current_page); |
|
| 968 | - |
|
| 969 | - if ($count) { |
|
| 970 | - // note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
|
| 971 | - $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
| 972 | - $results = $this->_question_model->count_deleted($where); |
|
| 973 | - } else { |
|
| 974 | - // note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
|
| 975 | - $results = $this->_question_model->get_all_deleted($query_params); |
|
| 976 | - } |
|
| 977 | - return $results; |
|
| 978 | - } |
|
| 979 | - |
|
| 980 | - |
|
| 981 | - /** |
|
| 982 | - * @param $per_page |
|
| 983 | - * @param int $current_page |
|
| 984 | - * @param bool|false $count |
|
| 985 | - * @return EE_Soft_Delete_Base_Class[]|int |
|
| 986 | - * @throws EE_Error |
|
| 987 | - * @throws InvalidArgumentException |
|
| 988 | - * @throws InvalidDataTypeException |
|
| 989 | - * @throws InvalidInterfaceException |
|
| 990 | - */ |
|
| 991 | - public function get_question_groups($per_page, $current_page = 1, $count = false) |
|
| 992 | - { |
|
| 993 | - $questionGroupModel = EEM_Question_Group::instance(); |
|
| 994 | - $query_params = $this->get_query_params($questionGroupModel, $per_page, $current_page); |
|
| 995 | - if ($count) { |
|
| 996 | - $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
| 997 | - $results = $questionGroupModel->count($where); |
|
| 998 | - } else { |
|
| 999 | - $results = $questionGroupModel->get_all($query_params); |
|
| 1000 | - } |
|
| 1001 | - return $results; |
|
| 1002 | - } |
|
| 1003 | - |
|
| 1004 | - |
|
| 1005 | - /** |
|
| 1006 | - * @param $per_page |
|
| 1007 | - * @param int $current_page |
|
| 1008 | - * @param bool $count |
|
| 1009 | - * @return EE_Soft_Delete_Base_Class[]|int |
|
| 1010 | - * @throws EE_Error |
|
| 1011 | - * @throws InvalidArgumentException |
|
| 1012 | - * @throws InvalidDataTypeException |
|
| 1013 | - * @throws InvalidInterfaceException |
|
| 1014 | - */ |
|
| 1015 | - public function get_trashed_question_groups($per_page, $current_page = 1, $count = false) |
|
| 1016 | - { |
|
| 1017 | - $questionGroupModel = EEM_Question_Group::instance(); |
|
| 1018 | - $query_params = $this->get_query_params($questionGroupModel, $per_page, $current_page); |
|
| 1019 | - if ($count) { |
|
| 1020 | - $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
| 1021 | - $query_params['limit'] = null; |
|
| 1022 | - $results = $questionGroupModel->count_deleted($where); |
|
| 1023 | - } else { |
|
| 1024 | - $results = $questionGroupModel->get_all_deleted($query_params); |
|
| 1025 | - } |
|
| 1026 | - return $results; |
|
| 1027 | - } |
|
| 1028 | - |
|
| 1029 | - |
|
| 1030 | - /** |
|
| 1031 | - * method for performing updates to question order |
|
| 1032 | - * |
|
| 1033 | - * @return void results array |
|
| 1034 | - * @throws EE_Error |
|
| 1035 | - * @throws InvalidArgumentException |
|
| 1036 | - * @throws InvalidDataTypeException |
|
| 1037 | - * @throws InvalidInterfaceException |
|
| 1038 | - */ |
|
| 1039 | - public function update_question_group_order() |
|
| 1040 | - { |
|
| 1041 | - |
|
| 1042 | - $success = esc_html__('Question group order was updated successfully.', 'event_espresso'); |
|
| 1043 | - |
|
| 1044 | - // grab our row IDs |
|
| 1045 | - $row_ids = isset($this->_req_data['row_ids']) && ! empty($this->_req_data['row_ids']) |
|
| 1046 | - ? explode(',', rtrim($this->_req_data['row_ids'], ',')) |
|
| 1047 | - : array(); |
|
| 1048 | - |
|
| 1049 | - $perpage = ! empty($this->_req_data['perpage']) |
|
| 1050 | - ? (int) $this->_req_data['perpage'] |
|
| 1051 | - : null; |
|
| 1052 | - $curpage = ! empty($this->_req_data['curpage']) |
|
| 1053 | - ? (int) $this->_req_data['curpage'] |
|
| 1054 | - : null; |
|
| 1055 | - |
|
| 1056 | - if (! empty($row_ids)) { |
|
| 1057 | - // figure out where we start the row_id count at for the current page. |
|
| 1058 | - $qsgcount = empty($curpage) ? 0 : ($curpage - 1) * $perpage; |
|
| 1059 | - |
|
| 1060 | - $row_count = count($row_ids); |
|
| 1061 | - for ($i = 0; $i < $row_count; $i++) { |
|
| 1062 | - // Update the questions when re-ordering |
|
| 1063 | - $updated = EEM_Question_Group::instance()->update( |
|
| 1064 | - array('QSG_order' => $qsgcount), |
|
| 1065 | - array(array('QSG_ID' => $row_ids[ $i ])) |
|
| 1066 | - ); |
|
| 1067 | - if ($updated === false) { |
|
| 1068 | - $success = false; |
|
| 1069 | - } |
|
| 1070 | - $qsgcount++; |
|
| 1071 | - } |
|
| 1072 | - } else { |
|
| 1073 | - $success = false; |
|
| 1074 | - } |
|
| 1075 | - |
|
| 1076 | - $errors = ! $success |
|
| 1077 | - ? esc_html__('An error occurred. The question group order was not updated.', 'event_espresso') |
|
| 1078 | - : false; |
|
| 1079 | - |
|
| 1080 | - echo wp_json_encode(array('return_data' => false, 'success' => $success, 'errors' => $errors)); |
|
| 1081 | - die(); |
|
| 1082 | - } |
|
| 1083 | - |
|
| 1084 | - |
|
| 1085 | - |
|
| 1086 | - /*************************************** REGISTRATION SETTINGS ***************************************/ |
|
| 1087 | - |
|
| 1088 | - |
|
| 1089 | - /** |
|
| 1090 | - * @throws DomainException |
|
| 1091 | - * @throws EE_Error |
|
| 1092 | - * @throws InvalidArgumentException |
|
| 1093 | - * @throws InvalidDataTypeException |
|
| 1094 | - * @throws InvalidInterfaceException |
|
| 1095 | - */ |
|
| 1096 | - protected function _reg_form_settings() |
|
| 1097 | - { |
|
| 1098 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
| 1099 | - add_action( |
|
| 1100 | - 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template', |
|
| 1101 | - array($this, 'email_validation_settings_form'), |
|
| 1102 | - 2 |
|
| 1103 | - ); |
|
| 1104 | - add_action( |
|
| 1105 | - 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template', |
|
| 1106 | - array($this, 'copy_attendee_info_settings_form'), |
|
| 1107 | - 4 |
|
| 1108 | - ); |
|
| 1109 | - $this->_template_args = (array) apply_filters( |
|
| 1110 | - 'FHEE__Extend_Registration_Form_Admin_Page___reg_form_settings___template_args', |
|
| 1111 | - $this->_template_args |
|
| 1112 | - ); |
|
| 1113 | - $this->_set_add_edit_form_tags('update_reg_form_settings'); |
|
| 1114 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 1115 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 1116 | - REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'reg_form_settings.template.php', |
|
| 1117 | - $this->_template_args, |
|
| 1118 | - true |
|
| 1119 | - ); |
|
| 1120 | - $this->display_admin_page_with_sidebar(); |
|
| 1121 | - } |
|
| 1122 | - |
|
| 1123 | - |
|
| 1124 | - /** |
|
| 1125 | - * @return void |
|
| 1126 | - * @throws EE_Error |
|
| 1127 | - * @throws InvalidArgumentException |
|
| 1128 | - * @throws ReflectionException |
|
| 1129 | - * @throws InvalidDataTypeException |
|
| 1130 | - * @throws InvalidInterfaceException |
|
| 1131 | - */ |
|
| 1132 | - protected function _update_reg_form_settings() |
|
| 1133 | - { |
|
| 1134 | - EE_Registry::instance()->CFG->registration = $this->update_email_validation_settings_form( |
|
| 1135 | - EE_Registry::instance()->CFG->registration |
|
| 1136 | - ); |
|
| 1137 | - EE_Registry::instance()->CFG->registration = $this->update_copy_attendee_info_settings_form( |
|
| 1138 | - EE_Registry::instance()->CFG->registration |
|
| 1139 | - ); |
|
| 1140 | - EE_Registry::instance()->CFG->registration = apply_filters( |
|
| 1141 | - 'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration', |
|
| 1142 | - EE_Registry::instance()->CFG->registration |
|
| 1143 | - ); |
|
| 1144 | - $success = $this->_update_espresso_configuration( |
|
| 1145 | - esc_html__('Registration Form Options', 'event_espresso'), |
|
| 1146 | - EE_Registry::instance()->CFG, |
|
| 1147 | - __FILE__, |
|
| 1148 | - __FUNCTION__, |
|
| 1149 | - __LINE__ |
|
| 1150 | - ); |
|
| 1151 | - $this->_redirect_after_action( |
|
| 1152 | - $success, |
|
| 1153 | - esc_html__('Registration Form Options', 'event_espresso'), |
|
| 1154 | - 'updated', |
|
| 1155 | - array('action' => 'view_reg_form_settings') |
|
| 1156 | - ); |
|
| 1157 | - } |
|
| 1158 | - |
|
| 1159 | - |
|
| 1160 | - /** |
|
| 1161 | - * @return void |
|
| 1162 | - * @throws EE_Error |
|
| 1163 | - * @throws InvalidArgumentException |
|
| 1164 | - * @throws InvalidDataTypeException |
|
| 1165 | - * @throws InvalidInterfaceException |
|
| 1166 | - */ |
|
| 1167 | - public function copy_attendee_info_settings_form() |
|
| 1168 | - { |
|
| 1169 | - echo $this->_copy_attendee_info_settings_form()->get_html(); |
|
| 1170 | - } |
|
| 1171 | - |
|
| 1172 | - /** |
|
| 1173 | - * _copy_attendee_info_settings_form |
|
| 1174 | - * |
|
| 1175 | - * @access protected |
|
| 1176 | - * @return EE_Form_Section_Proper |
|
| 1177 | - * @throws \EE_Error |
|
| 1178 | - */ |
|
| 1179 | - protected function _copy_attendee_info_settings_form() |
|
| 1180 | - { |
|
| 1181 | - return new EE_Form_Section_Proper( |
|
| 1182 | - array( |
|
| 1183 | - 'name' => 'copy_attendee_info_settings', |
|
| 1184 | - 'html_id' => 'copy_attendee_info_settings', |
|
| 1185 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 1186 | - 'subsections' => apply_filters( |
|
| 1187 | - 'FHEE__Extend_Registration_Form_Admin_Page___copy_attendee_info_settings_form__form_subsections', |
|
| 1188 | - array( |
|
| 1189 | - 'copy_attendee_info_hdr' => new EE_Form_Section_HTML( |
|
| 1190 | - EEH_HTML::h2(esc_html__('Copy Attendee Info Settings', 'event_espresso')) |
|
| 1191 | - ), |
|
| 1192 | - 'copy_attendee_info' => new EE_Yes_No_Input( |
|
| 1193 | - array( |
|
| 1194 | - 'html_label_text' => esc_html__( |
|
| 1195 | - 'Allow copy #1 attendee info to extra attendees?', |
|
| 1196 | - 'event_espresso' |
|
| 1197 | - ), |
|
| 1198 | - 'html_help_text' => esc_html__( |
|
| 1199 | - 'Set to yes if you want to enable the copy of #1 attendee info to extra attendees at Registration Form.', |
|
| 1200 | - 'event_espresso' |
|
| 1201 | - ), |
|
| 1202 | - 'default' => EE_Registry::instance()->CFG->registration->copyAttendeeInfo(), |
|
| 1203 | - 'required' => false, |
|
| 1204 | - 'display_html_label_text' => false, |
|
| 1205 | - ) |
|
| 1206 | - ), |
|
| 1207 | - ) |
|
| 1208 | - ), |
|
| 1209 | - ) |
|
| 1210 | - ); |
|
| 1211 | - } |
|
| 1212 | - |
|
| 1213 | - /** |
|
| 1214 | - * @param EE_Registration_Config $EE_Registration_Config |
|
| 1215 | - * @return EE_Registration_Config |
|
| 1216 | - * @throws EE_Error |
|
| 1217 | - * @throws InvalidArgumentException |
|
| 1218 | - * @throws ReflectionException |
|
| 1219 | - * @throws InvalidDataTypeException |
|
| 1220 | - * @throws InvalidInterfaceException |
|
| 1221 | - */ |
|
| 1222 | - public function update_copy_attendee_info_settings_form(EE_Registration_Config $EE_Registration_Config) |
|
| 1223 | - { |
|
| 1224 | - $prev_copy_attendee_info = $EE_Registration_Config->copyAttendeeInfo(); |
|
| 1225 | - try { |
|
| 1226 | - $copy_attendee_info_settings_form = $this->_copy_attendee_info_settings_form(); |
|
| 1227 | - // if not displaying a form, then check for form submission |
|
| 1228 | - if ($copy_attendee_info_settings_form->was_submitted()) { |
|
| 1229 | - // capture form data |
|
| 1230 | - $copy_attendee_info_settings_form->receive_form_submission(); |
|
| 1231 | - // validate form data |
|
| 1232 | - if ($copy_attendee_info_settings_form->is_valid()) { |
|
| 1233 | - // grab validated data from form |
|
| 1234 | - $valid_data = $copy_attendee_info_settings_form->valid_data(); |
|
| 1235 | - if (isset($valid_data['copy_attendee_info'])) { |
|
| 1236 | - $EE_Registration_Config->setCopyAttendeeInfo($valid_data['copy_attendee_info']); |
|
| 1237 | - } else { |
|
| 1238 | - EE_Error::add_error( |
|
| 1239 | - esc_html__( |
|
| 1240 | - 'Invalid or missing Copy Attendee Info settings. Please refresh the form and try again.', |
|
| 1241 | - 'event_espresso' |
|
| 1242 | - ), |
|
| 1243 | - __FILE__, |
|
| 1244 | - __FUNCTION__, |
|
| 1245 | - __LINE__ |
|
| 1246 | - ); |
|
| 1247 | - } |
|
| 1248 | - } else { |
|
| 1249 | - if ($copy_attendee_info_settings_form->submission_error_message() !== '') { |
|
| 1250 | - EE_Error::add_error( |
|
| 1251 | - $copy_attendee_info_settings_form->submission_error_message(), |
|
| 1252 | - __FILE__, |
|
| 1253 | - __FUNCTION__, |
|
| 1254 | - __LINE__ |
|
| 1255 | - ); |
|
| 1256 | - } |
|
| 1257 | - } |
|
| 1258 | - } |
|
| 1259 | - } catch (EE_Error $e) { |
|
| 1260 | - $e->get_error(); |
|
| 1261 | - } |
|
| 1262 | - return $EE_Registration_Config; |
|
| 1263 | - } |
|
| 1264 | - |
|
| 1265 | - |
|
| 1266 | - /** |
|
| 1267 | - * @return void |
|
| 1268 | - * @throws EE_Error |
|
| 1269 | - * @throws InvalidArgumentException |
|
| 1270 | - * @throws InvalidDataTypeException |
|
| 1271 | - * @throws InvalidInterfaceException |
|
| 1272 | - */ |
|
| 1273 | - public function email_validation_settings_form() |
|
| 1274 | - { |
|
| 1275 | - echo $this->_email_validation_settings_form()->get_html(); |
|
| 1276 | - } |
|
| 1277 | - |
|
| 1278 | - |
|
| 1279 | - /** |
|
| 1280 | - * _email_validation_settings_form |
|
| 1281 | - * |
|
| 1282 | - * @access protected |
|
| 1283 | - * @return EE_Form_Section_Proper |
|
| 1284 | - * @throws \EE_Error |
|
| 1285 | - */ |
|
| 1286 | - protected function _email_validation_settings_form() |
|
| 1287 | - { |
|
| 1288 | - return new EE_Form_Section_Proper( |
|
| 1289 | - array( |
|
| 1290 | - 'name' => 'email_validation_settings', |
|
| 1291 | - 'html_id' => 'email_validation_settings', |
|
| 1292 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 1293 | - 'subsections' => apply_filters( |
|
| 1294 | - 'FHEE__Extend_Registration_Form_Admin_Page___email_validation_settings_form__form_subsections', |
|
| 1295 | - array( |
|
| 1296 | - 'email_validation_hdr' => new EE_Form_Section_HTML( |
|
| 1297 | - EEH_HTML::h2(esc_html__('Email Validation Settings', 'event_espresso')) |
|
| 1298 | - ), |
|
| 1299 | - 'email_validation_level' => new EE_Select_Input( |
|
| 1300 | - array( |
|
| 1301 | - 'basic' => esc_html__('Basic', 'event_espresso'), |
|
| 1302 | - 'wp_default' => esc_html__('WordPress Default', 'event_espresso'), |
|
| 1303 | - 'i18n' => esc_html__('International', 'event_espresso'), |
|
| 1304 | - 'i18n_dns' => esc_html__('International + DNS Check', 'event_espresso'), |
|
| 1305 | - ), |
|
| 1306 | - array( |
|
| 1307 | - 'html_label_text' => esc_html__('Email Validation Level', 'event_espresso') |
|
| 1308 | - . EEH_Template::get_help_tab_link('email_validation_info'), |
|
| 1309 | - 'html_help_text' => esc_html__( |
|
| 1310 | - 'These levels range from basic validation ( ie: [email protected] ) to more advanced checks against international email addresses (ie: üñîçøðé@example.com ) with additional MX and A record checks to confirm the domain actually exists. More information on on each level can be found within the help section.', |
|
| 1311 | - 'event_espresso' |
|
| 1312 | - ), |
|
| 1313 | - 'default' => isset( |
|
| 1314 | - EE_Registry::instance()->CFG->registration->email_validation_level |
|
| 1315 | - ) |
|
| 1316 | - ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
| 1317 | - : 'wp_default', |
|
| 1318 | - 'required' => false, |
|
| 1319 | - ) |
|
| 1320 | - ), |
|
| 1321 | - ) |
|
| 1322 | - ), |
|
| 1323 | - ) |
|
| 1324 | - ); |
|
| 1325 | - } |
|
| 1326 | - |
|
| 1327 | - |
|
| 1328 | - /** |
|
| 1329 | - * @param EE_Registration_Config $EE_Registration_Config |
|
| 1330 | - * @return EE_Registration_Config |
|
| 1331 | - * @throws EE_Error |
|
| 1332 | - * @throws InvalidArgumentException |
|
| 1333 | - * @throws ReflectionException |
|
| 1334 | - * @throws InvalidDataTypeException |
|
| 1335 | - * @throws InvalidInterfaceException |
|
| 1336 | - */ |
|
| 1337 | - public function update_email_validation_settings_form(EE_Registration_Config $EE_Registration_Config) |
|
| 1338 | - { |
|
| 1339 | - $prev_email_validation_level = $EE_Registration_Config->email_validation_level; |
|
| 1340 | - try { |
|
| 1341 | - $email_validation_settings_form = $this->_email_validation_settings_form(); |
|
| 1342 | - // if not displaying a form, then check for form submission |
|
| 1343 | - if ($email_validation_settings_form->was_submitted()) { |
|
| 1344 | - // capture form data |
|
| 1345 | - $email_validation_settings_form->receive_form_submission(); |
|
| 1346 | - // validate form data |
|
| 1347 | - if ($email_validation_settings_form->is_valid()) { |
|
| 1348 | - // grab validated data from form |
|
| 1349 | - $valid_data = $email_validation_settings_form->valid_data(); |
|
| 1350 | - if (isset($valid_data['email_validation_level'])) { |
|
| 1351 | - $email_validation_level = $valid_data['email_validation_level']; |
|
| 1352 | - // now if they want to use international email addresses |
|
| 1353 | - if ($email_validation_level === 'i18n' || $email_validation_level === 'i18n_dns') { |
|
| 1354 | - // in case we need to reset their email validation level, |
|
| 1355 | - // make sure that the previous value wasn't already set to one of the i18n options. |
|
| 1356 | - if ($prev_email_validation_level === 'i18n' || $prev_email_validation_level === 'i18n_dns') { |
|
| 1357 | - // if so, then reset it back to "basic" since that is the only other option that, |
|
| 1358 | - // despite offering poor validation, supports i18n email addresses |
|
| 1359 | - $prev_email_validation_level = 'basic'; |
|
| 1360 | - } |
|
| 1361 | - // confirm our i18n email validation will work on the server |
|
| 1362 | - if (! $this->_verify_pcre_support($EE_Registration_Config, $email_validation_level)) { |
|
| 1363 | - // or reset email validation level to previous value |
|
| 1364 | - $email_validation_level = $prev_email_validation_level; |
|
| 1365 | - } |
|
| 1366 | - } |
|
| 1367 | - $EE_Registration_Config->email_validation_level = $email_validation_level; |
|
| 1368 | - } else { |
|
| 1369 | - EE_Error::add_error( |
|
| 1370 | - esc_html__( |
|
| 1371 | - 'Invalid or missing Email Validation settings. Please refresh the form and try again.', |
|
| 1372 | - 'event_espresso' |
|
| 1373 | - ), |
|
| 1374 | - __FILE__, |
|
| 1375 | - __FUNCTION__, |
|
| 1376 | - __LINE__ |
|
| 1377 | - ); |
|
| 1378 | - } |
|
| 1379 | - } else { |
|
| 1380 | - if ($email_validation_settings_form->submission_error_message() !== '') { |
|
| 1381 | - EE_Error::add_error( |
|
| 1382 | - $email_validation_settings_form->submission_error_message(), |
|
| 1383 | - __FILE__, |
|
| 1384 | - __FUNCTION__, |
|
| 1385 | - __LINE__ |
|
| 1386 | - ); |
|
| 1387 | - } |
|
| 1388 | - } |
|
| 1389 | - } |
|
| 1390 | - } catch (EE_Error $e) { |
|
| 1391 | - $e->get_error(); |
|
| 1392 | - } |
|
| 1393 | - return $EE_Registration_Config; |
|
| 1394 | - } |
|
| 1395 | - |
|
| 1396 | - |
|
| 1397 | - /** |
|
| 1398 | - * confirms that the server's PHP version has the PCRE module enabled, |
|
| 1399 | - * and that the PCRE version works with our i18n email validation |
|
| 1400 | - * |
|
| 1401 | - * @param EE_Registration_Config $EE_Registration_Config |
|
| 1402 | - * @param string $email_validation_level |
|
| 1403 | - * @return bool |
|
| 1404 | - */ |
|
| 1405 | - private function _verify_pcre_support(EE_Registration_Config $EE_Registration_Config, $email_validation_level) |
|
| 1406 | - { |
|
| 1407 | - // first check that PCRE is enabled |
|
| 1408 | - if (! defined('PREG_BAD_UTF8_ERROR')) { |
|
| 1409 | - EE_Error::add_error( |
|
| 1410 | - sprintf( |
|
| 1411 | - esc_html__( |
|
| 1412 | - 'We\'re sorry, but it appears that your server\'s version of PHP was not compiled with PCRE unicode support.%1$sPlease contact your hosting company and ask them whether the PCRE compiled with your version of PHP on your server can be been built with the "--enable-unicode-properties" and "--enable-utf8" configuration switches to enable more complex regex expressions.%1$sIf they are unable, or unwilling to do so, then your server will not support international email addresses using UTF-8 unicode characters. This means you will either have to lower your email validation level to "Basic" or "WordPress Default", or switch to a hosting company that has/can enable PCRE unicode support on the server.', |
|
| 1413 | - 'event_espresso' |
|
| 1414 | - ), |
|
| 1415 | - '<br />' |
|
| 1416 | - ), |
|
| 1417 | - __FILE__, |
|
| 1418 | - __FUNCTION__, |
|
| 1419 | - __LINE__ |
|
| 1420 | - ); |
|
| 1421 | - return false; |
|
| 1422 | - } else { |
|
| 1423 | - // PCRE support is enabled, but let's still |
|
| 1424 | - // perform a test to see if the server will support it. |
|
| 1425 | - // but first, save the updated validation level to the config, |
|
| 1426 | - // so that the validation strategy picks it up. |
|
| 1427 | - // this will get bumped back down if it doesn't work |
|
| 1428 | - $EE_Registration_Config->email_validation_level = $email_validation_level; |
|
| 1429 | - try { |
|
| 1430 | - $email_validator = new EE_Email_Validation_Strategy(); |
|
| 1431 | - $i18n_email_address = apply_filters( |
|
| 1432 | - 'FHEE__Extend_Registration_Form_Admin_Page__update_email_validation_settings_form__i18n_email_address', |
|
| 1433 | - 'jägerjü[email protected]' |
|
| 1434 | - ); |
|
| 1435 | - $email_validator->validate($i18n_email_address); |
|
| 1436 | - } catch (Exception $e) { |
|
| 1437 | - EE_Error::add_error( |
|
| 1438 | - sprintf( |
|
| 1439 | - esc_html__( |
|
| 1440 | - 'We\'re sorry, but it appears that your server\'s configuration will not support the "International" or "International + DNS Check" email validation levels.%1$sTo correct this issue, please consult with your hosting company regarding your server\'s PCRE settings.%1$sIt is recommended that your PHP version be configured to use PCRE 8.10 or newer.%1$sMore information regarding PCRE versions and installation can be found here: %2$s', |
|
| 1441 | - 'event_espresso' |
|
| 1442 | - ), |
|
| 1443 | - '<br />', |
|
| 1444 | - '<a href="http://php.net/manual/en/pcre.installation.php" target="_blank" rel="noopener noreferrer">http://php.net/manual/en/pcre.installation.php</a>' |
|
| 1445 | - ), |
|
| 1446 | - __FILE__, |
|
| 1447 | - __FUNCTION__, |
|
| 1448 | - __LINE__ |
|
| 1449 | - ); |
|
| 1450 | - return false; |
|
| 1451 | - } |
|
| 1452 | - } |
|
| 1453 | - return true; |
|
| 1454 | - } |
|
| 17 | + /** |
|
| 18 | + * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
| 19 | + */ |
|
| 20 | + public function __construct($routing = true) |
|
| 21 | + { |
|
| 22 | + define('REGISTRATION_FORM_CAF_ADMIN', EE_CORE_CAF_ADMIN_EXTEND . 'registration_form/'); |
|
| 23 | + define('REGISTRATION_FORM_CAF_ASSETS_PATH', REGISTRATION_FORM_CAF_ADMIN . 'assets/'); |
|
| 24 | + define('REGISTRATION_FORM_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/assets/'); |
|
| 25 | + define('REGISTRATION_FORM_CAF_TEMPLATE_PATH', REGISTRATION_FORM_CAF_ADMIN . 'templates/'); |
|
| 26 | + define('REGISTRATION_FORM_CAF_TEMPLATE_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/templates/'); |
|
| 27 | + parent::__construct($routing); |
|
| 28 | + } |
|
| 29 | + |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @return void |
|
| 33 | + */ |
|
| 34 | + protected function _extend_page_config() |
|
| 35 | + { |
|
| 36 | + $this->_admin_base_path = REGISTRATION_FORM_CAF_ADMIN; |
|
| 37 | + $qst_id = ! empty($this->_req_data['QST_ID']) && ! is_array($this->_req_data['QST_ID']) |
|
| 38 | + ? $this->_req_data['QST_ID'] : 0; |
|
| 39 | + $qsg_id = ! empty($this->_req_data['QSG_ID']) && ! is_array($this->_req_data['QSG_ID']) |
|
| 40 | + ? $this->_req_data['QSG_ID'] : 0; |
|
| 41 | + |
|
| 42 | + $new_page_routes = array( |
|
| 43 | + 'question_groups' => array( |
|
| 44 | + 'func' => '_question_groups_overview_list_table', |
|
| 45 | + 'capability' => 'ee_read_question_groups', |
|
| 46 | + ), |
|
| 47 | + 'add_question' => array( |
|
| 48 | + 'func' => '_edit_question', |
|
| 49 | + 'capability' => 'ee_edit_questions', |
|
| 50 | + ), |
|
| 51 | + 'insert_question' => array( |
|
| 52 | + 'func' => '_insert_or_update_question', |
|
| 53 | + 'args' => array('new_question' => true), |
|
| 54 | + 'capability' => 'ee_edit_questions', |
|
| 55 | + 'noheader' => true, |
|
| 56 | + ), |
|
| 57 | + 'duplicate_question' => array( |
|
| 58 | + 'func' => '_duplicate_question', |
|
| 59 | + 'capability' => 'ee_edit_questions', |
|
| 60 | + 'noheader' => true, |
|
| 61 | + ), |
|
| 62 | + 'trash_question' => array( |
|
| 63 | + 'func' => '_trash_question', |
|
| 64 | + 'capability' => 'ee_delete_question', |
|
| 65 | + 'obj_id' => $qst_id, |
|
| 66 | + 'noheader' => true, |
|
| 67 | + ), |
|
| 68 | + |
|
| 69 | + 'restore_question' => array( |
|
| 70 | + 'func' => '_trash_or_restore_questions', |
|
| 71 | + 'capability' => 'ee_delete_question', |
|
| 72 | + 'obj_id' => $qst_id, |
|
| 73 | + 'args' => array('trash' => false), |
|
| 74 | + 'noheader' => true, |
|
| 75 | + ), |
|
| 76 | + |
|
| 77 | + 'delete_question' => array( |
|
| 78 | + 'func' => '_delete_question', |
|
| 79 | + 'capability' => 'ee_delete_question', |
|
| 80 | + 'obj_id' => $qst_id, |
|
| 81 | + 'noheader' => true, |
|
| 82 | + ), |
|
| 83 | + |
|
| 84 | + 'trash_questions' => array( |
|
| 85 | + 'func' => '_trash_or_restore_questions', |
|
| 86 | + 'capability' => 'ee_delete_questions', |
|
| 87 | + 'args' => array('trash' => true), |
|
| 88 | + 'noheader' => true, |
|
| 89 | + ), |
|
| 90 | + |
|
| 91 | + 'restore_questions' => array( |
|
| 92 | + 'func' => '_trash_or_restore_questions', |
|
| 93 | + 'capability' => 'ee_delete_questions', |
|
| 94 | + 'args' => array('trash' => false), |
|
| 95 | + 'noheader' => true, |
|
| 96 | + ), |
|
| 97 | + |
|
| 98 | + 'delete_questions' => array( |
|
| 99 | + 'func' => '_delete_questions', |
|
| 100 | + 'args' => array(), |
|
| 101 | + 'capability' => 'ee_delete_questions', |
|
| 102 | + 'noheader' => true, |
|
| 103 | + ), |
|
| 104 | + |
|
| 105 | + 'add_question_group' => array( |
|
| 106 | + 'func' => '_edit_question_group', |
|
| 107 | + 'capability' => 'ee_edit_question_groups', |
|
| 108 | + ), |
|
| 109 | + |
|
| 110 | + 'edit_question_group' => array( |
|
| 111 | + 'func' => '_edit_question_group', |
|
| 112 | + 'capability' => 'ee_edit_question_group', |
|
| 113 | + 'obj_id' => $qsg_id, |
|
| 114 | + 'args' => array('edit'), |
|
| 115 | + ), |
|
| 116 | + |
|
| 117 | + 'delete_question_groups' => array( |
|
| 118 | + 'func' => '_delete_question_groups', |
|
| 119 | + 'capability' => 'ee_delete_question_groups', |
|
| 120 | + 'noheader' => true, |
|
| 121 | + ), |
|
| 122 | + |
|
| 123 | + 'delete_question_group' => array( |
|
| 124 | + 'func' => '_delete_question_groups', |
|
| 125 | + 'capability' => 'ee_delete_question_group', |
|
| 126 | + 'obj_id' => $qsg_id, |
|
| 127 | + 'noheader' => true, |
|
| 128 | + ), |
|
| 129 | + |
|
| 130 | + 'trash_question_group' => array( |
|
| 131 | + 'func' => '_trash_or_restore_question_groups', |
|
| 132 | + 'args' => array('trash' => true), |
|
| 133 | + 'capability' => 'ee_delete_question_group', |
|
| 134 | + 'obj_id' => $qsg_id, |
|
| 135 | + 'noheader' => true, |
|
| 136 | + ), |
|
| 137 | + |
|
| 138 | + 'restore_question_group' => array( |
|
| 139 | + 'func' => '_trash_or_restore_question_groups', |
|
| 140 | + 'args' => array('trash' => false), |
|
| 141 | + 'capability' => 'ee_delete_question_group', |
|
| 142 | + 'obj_id' => $qsg_id, |
|
| 143 | + 'noheader' => true, |
|
| 144 | + ), |
|
| 145 | + |
|
| 146 | + 'insert_question_group' => array( |
|
| 147 | + 'func' => '_insert_or_update_question_group', |
|
| 148 | + 'args' => array('new_question_group' => true), |
|
| 149 | + 'capability' => 'ee_edit_question_groups', |
|
| 150 | + 'noheader' => true, |
|
| 151 | + ), |
|
| 152 | + |
|
| 153 | + 'update_question_group' => array( |
|
| 154 | + 'func' => '_insert_or_update_question_group', |
|
| 155 | + 'args' => array('new_question_group' => false), |
|
| 156 | + 'capability' => 'ee_edit_question_group', |
|
| 157 | + 'obj_id' => $qsg_id, |
|
| 158 | + 'noheader' => true, |
|
| 159 | + ), |
|
| 160 | + |
|
| 161 | + 'trash_question_groups' => array( |
|
| 162 | + 'func' => '_trash_or_restore_question_groups', |
|
| 163 | + 'args' => array('trash' => true), |
|
| 164 | + 'capability' => 'ee_delete_question_groups', |
|
| 165 | + 'noheader' => array('trash' => false), |
|
| 166 | + ), |
|
| 167 | + |
|
| 168 | + 'restore_question_groups' => array( |
|
| 169 | + 'func' => '_trash_or_restore_question_groups', |
|
| 170 | + 'args' => array('trash' => false), |
|
| 171 | + 'capability' => 'ee_delete_question_groups', |
|
| 172 | + 'noheader' => true, |
|
| 173 | + ), |
|
| 174 | + |
|
| 175 | + |
|
| 176 | + 'espresso_update_question_group_order' => array( |
|
| 177 | + 'func' => 'update_question_group_order', |
|
| 178 | + 'capability' => 'ee_edit_question_groups', |
|
| 179 | + 'noheader' => true, |
|
| 180 | + ), |
|
| 181 | + |
|
| 182 | + 'view_reg_form_settings' => array( |
|
| 183 | + 'func' => '_reg_form_settings', |
|
| 184 | + 'capability' => 'manage_options', |
|
| 185 | + ), |
|
| 186 | + |
|
| 187 | + 'update_reg_form_settings' => array( |
|
| 188 | + 'func' => '_update_reg_form_settings', |
|
| 189 | + 'capability' => 'manage_options', |
|
| 190 | + 'noheader' => true, |
|
| 191 | + ), |
|
| 192 | + ); |
|
| 193 | + $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
| 194 | + |
|
| 195 | + $new_page_config = array( |
|
| 196 | + |
|
| 197 | + 'question_groups' => array( |
|
| 198 | + 'nav' => array( |
|
| 199 | + 'label' => esc_html__('Question Groups', 'event_espresso'), |
|
| 200 | + 'order' => 20, |
|
| 201 | + ), |
|
| 202 | + 'list_table' => 'Registration_Form_Question_Groups_Admin_List_Table', |
|
| 203 | + 'help_tabs' => array( |
|
| 204 | + 'registration_form_question_groups_help_tab' => array( |
|
| 205 | + 'title' => esc_html__('Question Groups', 'event_espresso'), |
|
| 206 | + 'filename' => 'registration_form_question_groups', |
|
| 207 | + ), |
|
| 208 | + 'registration_form_question_groups_table_column_headings_help_tab' => array( |
|
| 209 | + 'title' => esc_html__('Question Groups Table Column Headings', 'event_espresso'), |
|
| 210 | + 'filename' => 'registration_form_question_groups_table_column_headings', |
|
| 211 | + ), |
|
| 212 | + 'registration_form_question_groups_views_bulk_actions_search_help_tab' => array( |
|
| 213 | + 'title' => esc_html__('Question Groups Views & Bulk Actions & Search', 'event_espresso'), |
|
| 214 | + 'filename' => 'registration_form_question_groups_views_bulk_actions_search', |
|
| 215 | + ), |
|
| 216 | + ), |
|
| 217 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 218 | + // 'help_tour' => array('Registration_Form_Question_Groups_Help_Tour'), |
|
| 219 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 220 | + 'require_nonce' => false, |
|
| 221 | + 'qtips' => array( |
|
| 222 | + 'EE_Registration_Form_Tips', |
|
| 223 | + ), |
|
| 224 | + ), |
|
| 225 | + |
|
| 226 | + 'add_question' => array( |
|
| 227 | + 'nav' => array( |
|
| 228 | + 'label' => esc_html__('Add Question', 'event_espresso'), |
|
| 229 | + 'order' => 5, |
|
| 230 | + 'persistent' => false, |
|
| 231 | + ), |
|
| 232 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 233 | + 'help_tabs' => array( |
|
| 234 | + 'registration_form_add_question_help_tab' => array( |
|
| 235 | + 'title' => esc_html__('Add Question', 'event_espresso'), |
|
| 236 | + 'filename' => 'registration_form_add_question', |
|
| 237 | + ), |
|
| 238 | + ), |
|
| 239 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 240 | + // 'help_tour' => array('Registration_Form_Add_Question_Help_Tour'), |
|
| 241 | + 'require_nonce' => false, |
|
| 242 | + ), |
|
| 243 | + |
|
| 244 | + 'add_question_group' => array( |
|
| 245 | + 'nav' => array( |
|
| 246 | + 'label' => esc_html__('Add Question Group', 'event_espresso'), |
|
| 247 | + 'order' => 5, |
|
| 248 | + 'persistent' => false, |
|
| 249 | + ), |
|
| 250 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 251 | + 'help_tabs' => array( |
|
| 252 | + 'registration_form_add_question_group_help_tab' => array( |
|
| 253 | + 'title' => esc_html__('Add Question Group', 'event_espresso'), |
|
| 254 | + 'filename' => 'registration_form_add_question_group', |
|
| 255 | + ), |
|
| 256 | + ), |
|
| 257 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 258 | + // 'help_tour' => array('Registration_Form_Add_Question_Group_Help_Tour'), |
|
| 259 | + 'require_nonce' => false, |
|
| 260 | + ), |
|
| 261 | + |
|
| 262 | + 'edit_question_group' => array( |
|
| 263 | + 'nav' => array( |
|
| 264 | + 'label' => esc_html__('Edit Question Group', 'event_espresso'), |
|
| 265 | + 'order' => 5, |
|
| 266 | + 'persistent' => false, |
|
| 267 | + 'url' => isset($this->_req_data['question_group_id']) ? add_query_arg( |
|
| 268 | + array('question_group_id' => $this->_req_data['question_group_id']), |
|
| 269 | + $this->_current_page_view_url |
|
| 270 | + ) : $this->_admin_base_url, |
|
| 271 | + ), |
|
| 272 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 273 | + 'help_tabs' => array( |
|
| 274 | + 'registration_form_edit_question_group_help_tab' => array( |
|
| 275 | + 'title' => esc_html__('Edit Question Group', 'event_espresso'), |
|
| 276 | + 'filename' => 'registration_form_edit_question_group', |
|
| 277 | + ), |
|
| 278 | + ), |
|
| 279 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 280 | + // 'help_tour' => array('Registration_Form_Edit_Question_Group_Help_Tour'), |
|
| 281 | + 'require_nonce' => false, |
|
| 282 | + ), |
|
| 283 | + |
|
| 284 | + 'view_reg_form_settings' => array( |
|
| 285 | + 'nav' => array( |
|
| 286 | + 'label' => esc_html__('Reg Form Settings', 'event_espresso'), |
|
| 287 | + 'order' => 40, |
|
| 288 | + ), |
|
| 289 | + 'labels' => array( |
|
| 290 | + 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
| 291 | + ), |
|
| 292 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 293 | + 'help_tabs' => array( |
|
| 294 | + 'registration_form_reg_form_settings_help_tab' => array( |
|
| 295 | + 'title' => esc_html__('Registration Form Settings', 'event_espresso'), |
|
| 296 | + 'filename' => 'registration_form_reg_form_settings', |
|
| 297 | + ), |
|
| 298 | + ), |
|
| 299 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 300 | + // 'help_tour' => array('Registration_Form_Settings_Help_Tour'), |
|
| 301 | + 'require_nonce' => false, |
|
| 302 | + ), |
|
| 303 | + |
|
| 304 | + ); |
|
| 305 | + $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
| 306 | + |
|
| 307 | + // change the list table we're going to use so it's the NEW list table! |
|
| 308 | + $this->_page_config['default']['list_table'] = 'Extend_Registration_Form_Questions_Admin_List_Table'; |
|
| 309 | + |
|
| 310 | + |
|
| 311 | + // additional labels |
|
| 312 | + $new_labels = array( |
|
| 313 | + 'add_question' => esc_html__('Add New Question', 'event_espresso'), |
|
| 314 | + 'delete_question' => esc_html__('Delete Question', 'event_espresso'), |
|
| 315 | + 'add_question_group' => esc_html__('Add New Question Group', 'event_espresso'), |
|
| 316 | + 'edit_question_group' => esc_html__('Edit Question Group', 'event_espresso'), |
|
| 317 | + 'delete_question_group' => esc_html__('Delete Question Group', 'event_espresso'), |
|
| 318 | + ); |
|
| 319 | + $this->_labels['buttons'] = array_merge($this->_labels['buttons'], $new_labels); |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + |
|
| 323 | + /** |
|
| 324 | + * @return void |
|
| 325 | + */ |
|
| 326 | + protected function _ajax_hooks() |
|
| 327 | + { |
|
| 328 | + add_action('wp_ajax_espresso_update_question_group_order', array($this, 'update_question_group_order')); |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + |
|
| 332 | + /** |
|
| 333 | + * @return void |
|
| 334 | + */ |
|
| 335 | + public function load_scripts_styles_question_groups() |
|
| 336 | + { |
|
| 337 | + wp_enqueue_script('espresso_ajax_table_sorting'); |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + |
|
| 341 | + /** |
|
| 342 | + * @return void |
|
| 343 | + */ |
|
| 344 | + public function load_scripts_styles_add_question_group() |
|
| 345 | + { |
|
| 346 | + $this->load_scripts_styles_forms(); |
|
| 347 | + $this->load_sortable_question_script(); |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + |
|
| 351 | + /** |
|
| 352 | + * @return void |
|
| 353 | + */ |
|
| 354 | + public function load_scripts_styles_edit_question_group() |
|
| 355 | + { |
|
| 356 | + $this->load_scripts_styles_forms(); |
|
| 357 | + $this->load_sortable_question_script(); |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + |
|
| 361 | + /** |
|
| 362 | + * registers and enqueues script for questions |
|
| 363 | + * |
|
| 364 | + * @return void |
|
| 365 | + */ |
|
| 366 | + public function load_sortable_question_script() |
|
| 367 | + { |
|
| 368 | + wp_register_script( |
|
| 369 | + 'ee-question-sortable', |
|
| 370 | + REGISTRATION_FORM_CAF_ASSETS_URL . 'ee_question_order.js', |
|
| 371 | + array('jquery-ui-sortable'), |
|
| 372 | + EVENT_ESPRESSO_VERSION, |
|
| 373 | + true |
|
| 374 | + ); |
|
| 375 | + wp_enqueue_script('ee-question-sortable'); |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + |
|
| 379 | + /** |
|
| 380 | + * @return void |
|
| 381 | + */ |
|
| 382 | + protected function _set_list_table_views_default() |
|
| 383 | + { |
|
| 384 | + $this->_views = array( |
|
| 385 | + 'all' => array( |
|
| 386 | + 'slug' => 'all', |
|
| 387 | + 'label' => esc_html__('View All Questions', 'event_espresso'), |
|
| 388 | + 'count' => 0, |
|
| 389 | + 'bulk_action' => array( |
|
| 390 | + 'trash_questions' => esc_html__('Trash', 'event_espresso'), |
|
| 391 | + ), |
|
| 392 | + ), |
|
| 393 | + ); |
|
| 394 | + |
|
| 395 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 396 | + 'ee_delete_questions', |
|
| 397 | + 'espresso_registration_form_trash_questions' |
|
| 398 | + ) |
|
| 399 | + ) { |
|
| 400 | + $this->_views['trash'] = array( |
|
| 401 | + 'slug' => 'trash', |
|
| 402 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 403 | + 'count' => 0, |
|
| 404 | + 'bulk_action' => array( |
|
| 405 | + 'delete_questions' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 406 | + 'restore_questions' => esc_html__('Restore', 'event_espresso'), |
|
| 407 | + ), |
|
| 408 | + ); |
|
| 409 | + } |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + |
|
| 413 | + /** |
|
| 414 | + * @return void |
|
| 415 | + */ |
|
| 416 | + protected function _set_list_table_views_question_groups() |
|
| 417 | + { |
|
| 418 | + $this->_views = array( |
|
| 419 | + 'all' => array( |
|
| 420 | + 'slug' => 'all', |
|
| 421 | + 'label' => esc_html__('All', 'event_espresso'), |
|
| 422 | + 'count' => 0, |
|
| 423 | + 'bulk_action' => array( |
|
| 424 | + 'trash_question_groups' => esc_html__('Trash', 'event_espresso'), |
|
| 425 | + ), |
|
| 426 | + ), |
|
| 427 | + ); |
|
| 428 | + |
|
| 429 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 430 | + 'ee_delete_question_groups', |
|
| 431 | + 'espresso_registration_form_trash_question_groups' |
|
| 432 | + ) |
|
| 433 | + ) { |
|
| 434 | + $this->_views['trash'] = array( |
|
| 435 | + 'slug' => 'trash', |
|
| 436 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 437 | + 'count' => 0, |
|
| 438 | + 'bulk_action' => array( |
|
| 439 | + 'delete_question_groups' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 440 | + 'restore_question_groups' => esc_html__('Restore', 'event_espresso'), |
|
| 441 | + ), |
|
| 442 | + ); |
|
| 443 | + } |
|
| 444 | + } |
|
| 445 | + |
|
| 446 | + |
|
| 447 | + /** |
|
| 448 | + * @return void |
|
| 449 | + * @throws EE_Error |
|
| 450 | + * @throws InvalidArgumentException |
|
| 451 | + * @throws InvalidDataTypeException |
|
| 452 | + * @throws InvalidInterfaceException |
|
| 453 | + */ |
|
| 454 | + protected function _questions_overview_list_table() |
|
| 455 | + { |
|
| 456 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 457 | + 'add_question', |
|
| 458 | + 'add_question', |
|
| 459 | + array(), |
|
| 460 | + 'add-new-h2' |
|
| 461 | + ); |
|
| 462 | + parent::_questions_overview_list_table(); |
|
| 463 | + } |
|
| 464 | + |
|
| 465 | + |
|
| 466 | + /** |
|
| 467 | + * @return void |
|
| 468 | + * @throws DomainException |
|
| 469 | + * @throws EE_Error |
|
| 470 | + * @throws InvalidArgumentException |
|
| 471 | + * @throws InvalidDataTypeException |
|
| 472 | + * @throws InvalidInterfaceException |
|
| 473 | + */ |
|
| 474 | + protected function _question_groups_overview_list_table() |
|
| 475 | + { |
|
| 476 | + $this->_search_btn_label = esc_html__('Question Groups', 'event_espresso'); |
|
| 477 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 478 | + 'add_question_group', |
|
| 479 | + 'add_question_group', |
|
| 480 | + array(), |
|
| 481 | + 'add-new-h2' |
|
| 482 | + ); |
|
| 483 | + $this->display_admin_list_table_page_with_sidebar(); |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + |
|
| 487 | + /** |
|
| 488 | + * @return void |
|
| 489 | + * @throws EE_Error |
|
| 490 | + * @throws InvalidArgumentException |
|
| 491 | + * @throws InvalidDataTypeException |
|
| 492 | + * @throws InvalidInterfaceException |
|
| 493 | + */ |
|
| 494 | + protected function _delete_question() |
|
| 495 | + { |
|
| 496 | + $success = $this->_delete_items($this->_question_model); |
|
| 497 | + $this->_redirect_after_action( |
|
| 498 | + $success, |
|
| 499 | + $this->_question_model->item_name($success), |
|
| 500 | + 'deleted', |
|
| 501 | + array('action' => 'default', 'status' => 'all') |
|
| 502 | + ); |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + |
|
| 506 | + /** |
|
| 507 | + * @return void |
|
| 508 | + * @throws EE_Error |
|
| 509 | + * @throws InvalidArgumentException |
|
| 510 | + * @throws InvalidDataTypeException |
|
| 511 | + * @throws InvalidInterfaceException |
|
| 512 | + */ |
|
| 513 | + protected function _delete_questions() |
|
| 514 | + { |
|
| 515 | + $success = $this->_delete_items($this->_question_model); |
|
| 516 | + $this->_redirect_after_action( |
|
| 517 | + $success, |
|
| 518 | + $this->_question_model->item_name($success), |
|
| 519 | + 'deleted permanently', |
|
| 520 | + array('action' => 'default', 'status' => 'trash') |
|
| 521 | + ); |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + |
|
| 525 | + /** |
|
| 526 | + * Performs the deletion of a single or multiple questions or question groups. |
|
| 527 | + * |
|
| 528 | + * @param EEM_Soft_Delete_Base $model |
|
| 529 | + * @return int number of items deleted permanently |
|
| 530 | + * @throws EE_Error |
|
| 531 | + * @throws InvalidArgumentException |
|
| 532 | + * @throws InvalidDataTypeException |
|
| 533 | + * @throws InvalidInterfaceException |
|
| 534 | + */ |
|
| 535 | + private function _delete_items(EEM_Soft_Delete_Base $model) |
|
| 536 | + { |
|
| 537 | + $success = 0; |
|
| 538 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 539 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 540 | + // if array has more than one element than success message should be plural |
|
| 541 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 542 | + // cycle thru bulk action checkboxes |
|
| 543 | + while (list($ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 544 | + if (! $this->_delete_item($ID, $model)) { |
|
| 545 | + $success = 0; |
|
| 546 | + } |
|
| 547 | + } |
|
| 548 | + } elseif (! empty($this->_req_data['QSG_ID'])) { |
|
| 549 | + $success = $this->_delete_item($this->_req_data['QSG_ID'], $model); |
|
| 550 | + } elseif (! empty($this->_req_data['QST_ID'])) { |
|
| 551 | + $success = $this->_delete_item($this->_req_data['QST_ID'], $model); |
|
| 552 | + } else { |
|
| 553 | + EE_Error::add_error( |
|
| 554 | + sprintf( |
|
| 555 | + esc_html__( |
|
| 556 | + "No Questions or Question Groups were selected for deleting. This error usually shows when you've attempted to delete via bulk action but there were no selections.", |
|
| 557 | + "event_espresso" |
|
| 558 | + ) |
|
| 559 | + ), |
|
| 560 | + __FILE__, |
|
| 561 | + __FUNCTION__, |
|
| 562 | + __LINE__ |
|
| 563 | + ); |
|
| 564 | + } |
|
| 565 | + return $success; |
|
| 566 | + } |
|
| 567 | + |
|
| 568 | + |
|
| 569 | + /** |
|
| 570 | + * Deletes the specified question (and its associated question options) or question group |
|
| 571 | + * |
|
| 572 | + * @param int $id |
|
| 573 | + * @param EEM_Soft_Delete_Base $model |
|
| 574 | + * @return boolean |
|
| 575 | + * @throws EE_Error |
|
| 576 | + * @throws InvalidArgumentException |
|
| 577 | + * @throws InvalidDataTypeException |
|
| 578 | + * @throws InvalidInterfaceException |
|
| 579 | + */ |
|
| 580 | + protected function _delete_item($id, $model) |
|
| 581 | + { |
|
| 582 | + if ($model instanceof EEM_Question) { |
|
| 583 | + EEM_Question_Option::instance()->delete_permanently(array(array('QST_ID' => absint($id)))); |
|
| 584 | + } |
|
| 585 | + return $model->delete_permanently_by_ID(absint($id)); |
|
| 586 | + } |
|
| 587 | + |
|
| 588 | + |
|
| 589 | + /****************************** QUESTION GROUPS ******************************/ |
|
| 590 | + |
|
| 591 | + |
|
| 592 | + /** |
|
| 593 | + * @param string $type |
|
| 594 | + * @return void |
|
| 595 | + * @throws DomainException |
|
| 596 | + * @throws EE_Error |
|
| 597 | + * @throws InvalidArgumentException |
|
| 598 | + * @throws InvalidDataTypeException |
|
| 599 | + * @throws InvalidInterfaceException |
|
| 600 | + */ |
|
| 601 | + protected function _edit_question_group($type = 'add') |
|
| 602 | + { |
|
| 603 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 604 | + $ID = isset($this->_req_data['QSG_ID']) && ! empty($this->_req_data['QSG_ID']) |
|
| 605 | + ? absint($this->_req_data['QSG_ID']) |
|
| 606 | + : false; |
|
| 607 | + |
|
| 608 | + switch ($this->_req_action) { |
|
| 609 | + case 'add_question_group': |
|
| 610 | + $this->_admin_page_title = esc_html__('Add Question Group', 'event_espresso'); |
|
| 611 | + break; |
|
| 612 | + case 'edit_question_group': |
|
| 613 | + $this->_admin_page_title = esc_html__('Edit Question Group', 'event_espresso'); |
|
| 614 | + break; |
|
| 615 | + default: |
|
| 616 | + $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
|
| 617 | + } |
|
| 618 | + // add ID to title if editing |
|
| 619 | + $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title; |
|
| 620 | + if ($ID) { |
|
| 621 | + /** @var EE_Question_Group $questionGroup */ |
|
| 622 | + $questionGroup = $this->_question_group_model->get_one_by_ID($ID); |
|
| 623 | + $additional_hidden_fields = array('QSG_ID' => array('type' => 'hidden', 'value' => $ID)); |
|
| 624 | + $this->_set_add_edit_form_tags('update_question_group', $additional_hidden_fields); |
|
| 625 | + } else { |
|
| 626 | + /** @var EE_Question_Group $questionGroup */ |
|
| 627 | + $questionGroup = EEM_Question_Group::instance()->create_default_object(); |
|
| 628 | + $questionGroup->set_order_to_latest(); |
|
| 629 | + $this->_set_add_edit_form_tags('insert_question_group'); |
|
| 630 | + } |
|
| 631 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
| 632 | + $this->_template_args['all_questions'] = $questionGroup->questions_in_and_not_in_group(); |
|
| 633 | + $this->_template_args['QSG_ID'] = $ID ? $ID : true; |
|
| 634 | + $this->_template_args['question_group'] = $questionGroup; |
|
| 635 | + |
|
| 636 | + $redirect_URL = add_query_arg(array('action' => 'question_groups'), $this->_admin_base_url); |
|
| 637 | + $this->_set_publish_post_box_vars('id', $ID, false, $redirect_URL); |
|
| 638 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 639 | + REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'question_groups_main_meta_box.template.php', |
|
| 640 | + $this->_template_args, |
|
| 641 | + true |
|
| 642 | + ); |
|
| 643 | + |
|
| 644 | + // the details template wrapper |
|
| 645 | + $this->display_admin_page_with_sidebar(); |
|
| 646 | + } |
|
| 647 | + |
|
| 648 | + |
|
| 649 | + /** |
|
| 650 | + * @return void |
|
| 651 | + * @throws EE_Error |
|
| 652 | + * @throws InvalidArgumentException |
|
| 653 | + * @throws InvalidDataTypeException |
|
| 654 | + * @throws InvalidInterfaceException |
|
| 655 | + */ |
|
| 656 | + protected function _delete_question_groups() |
|
| 657 | + { |
|
| 658 | + $success = $this->_delete_items($this->_question_group_model); |
|
| 659 | + $this->_redirect_after_action( |
|
| 660 | + $success, |
|
| 661 | + $this->_question_group_model->item_name($success), |
|
| 662 | + 'deleted permanently', |
|
| 663 | + array('action' => 'question_groups', 'status' => 'trash') |
|
| 664 | + ); |
|
| 665 | + } |
|
| 666 | + |
|
| 667 | + |
|
| 668 | + /** |
|
| 669 | + * @param bool $new_question_group |
|
| 670 | + * @throws EE_Error |
|
| 671 | + * @throws InvalidArgumentException |
|
| 672 | + * @throws InvalidDataTypeException |
|
| 673 | + * @throws InvalidInterfaceException |
|
| 674 | + */ |
|
| 675 | + protected function _insert_or_update_question_group($new_question_group = true) |
|
| 676 | + { |
|
| 677 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 678 | + $set_column_values = $this->_set_column_values_for($this->_question_group_model); |
|
| 679 | + if ($new_question_group) { |
|
| 680 | + // make sure identifier is unique |
|
| 681 | + $identifier_value = isset($set_column_values['QSG_identifier']) ? $set_column_values['QSG_identifier'] : ''; |
|
| 682 | + $identifier_exists = ! empty($identifier_value) |
|
| 683 | + ? $this->_question_group_model->count([['QSG_identifier' => $set_column_values['QSG_identifier']]]) > 0 |
|
| 684 | + : false; |
|
| 685 | + if ($identifier_exists) { |
|
| 686 | + $set_column_values['QSG_identifier'] .= uniqid('id', true); |
|
| 687 | + } |
|
| 688 | + $QSG_ID = $this->_question_group_model->insert($set_column_values); |
|
| 689 | + $success = $QSG_ID ? 1 : 0; |
|
| 690 | + if ($success === 0) { |
|
| 691 | + EE_Error::add_error( |
|
| 692 | + esc_html__('Something went wrong saving the question group.', 'event_espresso'), |
|
| 693 | + __FILE__, |
|
| 694 | + __FUNCTION__, |
|
| 695 | + __LINE__ |
|
| 696 | + ); |
|
| 697 | + $this->_redirect_after_action( |
|
| 698 | + false, |
|
| 699 | + '', |
|
| 700 | + '', |
|
| 701 | + array('action' => 'edit_question_group', 'QSG_ID' => $QSG_ID), |
|
| 702 | + true |
|
| 703 | + ); |
|
| 704 | + } |
|
| 705 | + } else { |
|
| 706 | + $QSG_ID = absint($this->_req_data['QSG_ID']); |
|
| 707 | + unset($set_column_values['QSG_ID']); |
|
| 708 | + $success = $this->_question_group_model->update($set_column_values, array(array('QSG_ID' => $QSG_ID))); |
|
| 709 | + } |
|
| 710 | + |
|
| 711 | + $phone_question_id = EEM_Question::instance()->get_Question_ID_from_system_string( |
|
| 712 | + EEM_Attendee::system_question_phone |
|
| 713 | + ); |
|
| 714 | + // update the existing related questions |
|
| 715 | + // BUT FIRST... delete the phone question from the Question_Group_Question |
|
| 716 | + // if it is being added to this question group (therefore removed from the existing group) |
|
| 717 | + if (isset($this->_req_data['questions'], $this->_req_data['questions'][ $phone_question_id ])) { |
|
| 718 | + // delete where QST ID = system phone question ID and Question Group ID is NOT this group |
|
| 719 | + EEM_Question_Group_Question::instance()->delete( |
|
| 720 | + array( |
|
| 721 | + array( |
|
| 722 | + 'QST_ID' => $phone_question_id, |
|
| 723 | + 'QSG_ID' => array('!=', $QSG_ID), |
|
| 724 | + ), |
|
| 725 | + ) |
|
| 726 | + ); |
|
| 727 | + } |
|
| 728 | + /** @type EE_Question_Group $question_group */ |
|
| 729 | + $question_group = $this->_question_group_model->get_one_by_ID($QSG_ID); |
|
| 730 | + $questions = $question_group->questions(); |
|
| 731 | + // make sure system phone question is added to list of questions for this group |
|
| 732 | + if (! isset($questions[ $phone_question_id ])) { |
|
| 733 | + $questions[ $phone_question_id ] = EEM_Question::instance()->get_one_by_ID($phone_question_id); |
|
| 734 | + } |
|
| 735 | + |
|
| 736 | + foreach ($questions as $question_ID => $question) { |
|
| 737 | + // first we always check for order. |
|
| 738 | + if (! empty($this->_req_data['question_orders'][ $question_ID ])) { |
|
| 739 | + // update question order |
|
| 740 | + $question_group->update_question_order( |
|
| 741 | + $question_ID, |
|
| 742 | + $this->_req_data['question_orders'][ $question_ID ] |
|
| 743 | + ); |
|
| 744 | + } |
|
| 745 | + |
|
| 746 | + // then we always check if adding or removing. |
|
| 747 | + if (isset($this->_req_data['questions'], $this->_req_data['questions'][ $question_ID ])) { |
|
| 748 | + $question_group->add_question($question_ID); |
|
| 749 | + } else { |
|
| 750 | + // not found, remove it (but only if not a system question for the personal group |
|
| 751 | + // with the exception of lname system question - we allow removal of it) |
|
| 752 | + if (in_array( |
|
| 753 | + $question->system_ID(), |
|
| 754 | + EEM_Question::instance()->required_system_questions_in_system_question_group( |
|
| 755 | + $question_group->system_group() |
|
| 756 | + ) |
|
| 757 | + )) { |
|
| 758 | + continue; |
|
| 759 | + } else { |
|
| 760 | + $question_group->remove_question($question_ID); |
|
| 761 | + } |
|
| 762 | + } |
|
| 763 | + } |
|
| 764 | + // save new related questions |
|
| 765 | + if (isset($this->_req_data['questions'])) { |
|
| 766 | + foreach ($this->_req_data['questions'] as $QST_ID) { |
|
| 767 | + $question_group->add_question($QST_ID); |
|
| 768 | + if (isset($this->_req_data['question_orders'][ $QST_ID ])) { |
|
| 769 | + $question_group->update_question_order($QST_ID, $this->_req_data['question_orders'][ $QST_ID ]); |
|
| 770 | + } |
|
| 771 | + } |
|
| 772 | + } |
|
| 773 | + |
|
| 774 | + if ($success !== false) { |
|
| 775 | + $msg = $new_question_group |
|
| 776 | + ? sprintf( |
|
| 777 | + esc_html__('The %s has been created', 'event_espresso'), |
|
| 778 | + $this->_question_group_model->item_name() |
|
| 779 | + ) |
|
| 780 | + : sprintf( |
|
| 781 | + esc_html__( |
|
| 782 | + 'The %s has been updated', |
|
| 783 | + 'event_espresso' |
|
| 784 | + ), |
|
| 785 | + $this->_question_group_model->item_name() |
|
| 786 | + ); |
|
| 787 | + EE_Error::add_success($msg); |
|
| 788 | + } |
|
| 789 | + $this->_redirect_after_action( |
|
| 790 | + false, |
|
| 791 | + '', |
|
| 792 | + '', |
|
| 793 | + array('action' => 'edit_question_group', 'QSG_ID' => $QSG_ID), |
|
| 794 | + true |
|
| 795 | + ); |
|
| 796 | + } |
|
| 797 | + |
|
| 798 | + |
|
| 799 | + /** |
|
| 800 | + * duplicates a question and all its question options and redirects to the new question. |
|
| 801 | + * |
|
| 802 | + * @return void |
|
| 803 | + * @throws EE_Error |
|
| 804 | + * @throws InvalidArgumentException |
|
| 805 | + * @throws ReflectionException |
|
| 806 | + * @throws InvalidDataTypeException |
|
| 807 | + * @throws InvalidInterfaceException |
|
| 808 | + */ |
|
| 809 | + public function _duplicate_question() |
|
| 810 | + { |
|
| 811 | + $question_ID = (int) $this->_req_data['QST_ID']; |
|
| 812 | + $question = EEM_Question::instance()->get_one_by_ID($question_ID); |
|
| 813 | + if ($question instanceof EE_Question) { |
|
| 814 | + $new_question = $question->duplicate(); |
|
| 815 | + if ($new_question instanceof EE_Question) { |
|
| 816 | + $this->_redirect_after_action( |
|
| 817 | + true, |
|
| 818 | + esc_html__('Question', 'event_espresso'), |
|
| 819 | + esc_html__('Duplicated', 'event_espresso'), |
|
| 820 | + array('action' => 'edit_question', 'QST_ID' => $new_question->ID()), |
|
| 821 | + true |
|
| 822 | + ); |
|
| 823 | + } else { |
|
| 824 | + global $wpdb; |
|
| 825 | + EE_Error::add_error( |
|
| 826 | + sprintf( |
|
| 827 | + esc_html__( |
|
| 828 | + 'Could not duplicate question with ID %1$d because: %2$s', |
|
| 829 | + 'event_espresso' |
|
| 830 | + ), |
|
| 831 | + $question_ID, |
|
| 832 | + $wpdb->last_error |
|
| 833 | + ), |
|
| 834 | + __FILE__, |
|
| 835 | + __FUNCTION__, |
|
| 836 | + __LINE__ |
|
| 837 | + ); |
|
| 838 | + $this->_redirect_after_action(false, '', '', array('action' => 'default'), false); |
|
| 839 | + } |
|
| 840 | + } else { |
|
| 841 | + EE_Error::add_error( |
|
| 842 | + sprintf( |
|
| 843 | + esc_html__( |
|
| 844 | + 'Could not duplicate question with ID %d because it didn\'t exist!', |
|
| 845 | + 'event_espresso' |
|
| 846 | + ), |
|
| 847 | + $question_ID |
|
| 848 | + ), |
|
| 849 | + __FILE__, |
|
| 850 | + __FUNCTION__, |
|
| 851 | + __LINE__ |
|
| 852 | + ); |
|
| 853 | + $this->_redirect_after_action(false, '', '', array('action' => 'default'), false); |
|
| 854 | + } |
|
| 855 | + } |
|
| 856 | + |
|
| 857 | + |
|
| 858 | + /** |
|
| 859 | + * @param bool $trash |
|
| 860 | + * @throws EE_Error |
|
| 861 | + */ |
|
| 862 | + protected function _trash_or_restore_question_groups($trash = true) |
|
| 863 | + { |
|
| 864 | + $this->_trash_or_restore_items($this->_question_group_model, $trash); |
|
| 865 | + } |
|
| 866 | + |
|
| 867 | + |
|
| 868 | + /** |
|
| 869 | + *_trash_question |
|
| 870 | + * |
|
| 871 | + * @return void |
|
| 872 | + * @throws EE_Error |
|
| 873 | + */ |
|
| 874 | + protected function _trash_question() |
|
| 875 | + { |
|
| 876 | + $success = $this->_question_model->delete_by_ID((int) $this->_req_data['QST_ID']); |
|
| 877 | + $query_args = array('action' => 'default', 'status' => 'all'); |
|
| 878 | + $this->_redirect_after_action($success, $this->_question_model->item_name($success), 'trashed', $query_args); |
|
| 879 | + } |
|
| 880 | + |
|
| 881 | + |
|
| 882 | + /** |
|
| 883 | + * @param bool $trash |
|
| 884 | + * @throws EE_Error |
|
| 885 | + */ |
|
| 886 | + protected function _trash_or_restore_questions($trash = true) |
|
| 887 | + { |
|
| 888 | + $this->_trash_or_restore_items($this->_question_model, $trash); |
|
| 889 | + } |
|
| 890 | + |
|
| 891 | + |
|
| 892 | + /** |
|
| 893 | + * Internally used to delete or restore items, using the request data. Meant to be |
|
| 894 | + * flexible between question or question groups |
|
| 895 | + * |
|
| 896 | + * @param EEM_Soft_Delete_Base $model |
|
| 897 | + * @param boolean $trash whether to trash or restore |
|
| 898 | + * @throws EE_Error |
|
| 899 | + */ |
|
| 900 | + private function _trash_or_restore_items(EEM_Soft_Delete_Base $model, $trash = true) |
|
| 901 | + { |
|
| 902 | + |
|
| 903 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 904 | + |
|
| 905 | + $success = 1; |
|
| 906 | + // Checkboxes |
|
| 907 | + // echo "trash $trash"; |
|
| 908 | + // var_dump($this->_req_data['checkbox']);die; |
|
| 909 | + if (isset($this->_req_data['checkbox'])) { |
|
| 910 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 911 | + // if array has more than one element than success message should be plural |
|
| 912 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 913 | + // cycle thru bulk action checkboxes |
|
| 914 | + while (list($ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 915 | + if (! $model->delete_or_restore_by_ID($trash, absint($ID))) { |
|
| 916 | + $success = 0; |
|
| 917 | + } |
|
| 918 | + } |
|
| 919 | + } else { |
|
| 920 | + // grab single id and delete |
|
| 921 | + $ID = absint($this->_req_data['checkbox']); |
|
| 922 | + if (! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
| 923 | + $success = 0; |
|
| 924 | + } |
|
| 925 | + } |
|
| 926 | + } else { |
|
| 927 | + // delete via trash link |
|
| 928 | + // grab single id and delete |
|
| 929 | + $ID = absint($this->_req_data[ $model->primary_key_name() ]); |
|
| 930 | + if (! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
| 931 | + $success = 0; |
|
| 932 | + } |
|
| 933 | + } |
|
| 934 | + |
|
| 935 | + |
|
| 936 | + $action = $model instanceof EEM_Question ? 'default' : 'question_groups';// strtolower( $model->item_name(2) ); |
|
| 937 | + // echo "action :$action"; |
|
| 938 | + // $action = 'questions' ? 'default' : $action; |
|
| 939 | + if ($trash) { |
|
| 940 | + $action_desc = 'trashed'; |
|
| 941 | + $status = 'trash'; |
|
| 942 | + } else { |
|
| 943 | + $action_desc = 'restored'; |
|
| 944 | + $status = 'all'; |
|
| 945 | + } |
|
| 946 | + $this->_redirect_after_action( |
|
| 947 | + $success, |
|
| 948 | + $model->item_name($success), |
|
| 949 | + $action_desc, |
|
| 950 | + array('action' => $action, 'status' => $status) |
|
| 951 | + ); |
|
| 952 | + } |
|
| 953 | + |
|
| 954 | + |
|
| 955 | + /** |
|
| 956 | + * @param $per_page |
|
| 957 | + * @param int $current_page |
|
| 958 | + * @param bool|false $count |
|
| 959 | + * @return EE_Soft_Delete_Base_Class[]|int |
|
| 960 | + * @throws EE_Error |
|
| 961 | + * @throws InvalidArgumentException |
|
| 962 | + * @throws InvalidDataTypeException |
|
| 963 | + * @throws InvalidInterfaceException |
|
| 964 | + */ |
|
| 965 | + public function get_trashed_questions($per_page, $current_page = 1, $count = false) |
|
| 966 | + { |
|
| 967 | + $query_params = $this->get_query_params(EEM_Question::instance(), $per_page, $current_page); |
|
| 968 | + |
|
| 969 | + if ($count) { |
|
| 970 | + // note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
|
| 971 | + $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
| 972 | + $results = $this->_question_model->count_deleted($where); |
|
| 973 | + } else { |
|
| 974 | + // note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
|
| 975 | + $results = $this->_question_model->get_all_deleted($query_params); |
|
| 976 | + } |
|
| 977 | + return $results; |
|
| 978 | + } |
|
| 979 | + |
|
| 980 | + |
|
| 981 | + /** |
|
| 982 | + * @param $per_page |
|
| 983 | + * @param int $current_page |
|
| 984 | + * @param bool|false $count |
|
| 985 | + * @return EE_Soft_Delete_Base_Class[]|int |
|
| 986 | + * @throws EE_Error |
|
| 987 | + * @throws InvalidArgumentException |
|
| 988 | + * @throws InvalidDataTypeException |
|
| 989 | + * @throws InvalidInterfaceException |
|
| 990 | + */ |
|
| 991 | + public function get_question_groups($per_page, $current_page = 1, $count = false) |
|
| 992 | + { |
|
| 993 | + $questionGroupModel = EEM_Question_Group::instance(); |
|
| 994 | + $query_params = $this->get_query_params($questionGroupModel, $per_page, $current_page); |
|
| 995 | + if ($count) { |
|
| 996 | + $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
| 997 | + $results = $questionGroupModel->count($where); |
|
| 998 | + } else { |
|
| 999 | + $results = $questionGroupModel->get_all($query_params); |
|
| 1000 | + } |
|
| 1001 | + return $results; |
|
| 1002 | + } |
|
| 1003 | + |
|
| 1004 | + |
|
| 1005 | + /** |
|
| 1006 | + * @param $per_page |
|
| 1007 | + * @param int $current_page |
|
| 1008 | + * @param bool $count |
|
| 1009 | + * @return EE_Soft_Delete_Base_Class[]|int |
|
| 1010 | + * @throws EE_Error |
|
| 1011 | + * @throws InvalidArgumentException |
|
| 1012 | + * @throws InvalidDataTypeException |
|
| 1013 | + * @throws InvalidInterfaceException |
|
| 1014 | + */ |
|
| 1015 | + public function get_trashed_question_groups($per_page, $current_page = 1, $count = false) |
|
| 1016 | + { |
|
| 1017 | + $questionGroupModel = EEM_Question_Group::instance(); |
|
| 1018 | + $query_params = $this->get_query_params($questionGroupModel, $per_page, $current_page); |
|
| 1019 | + if ($count) { |
|
| 1020 | + $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
| 1021 | + $query_params['limit'] = null; |
|
| 1022 | + $results = $questionGroupModel->count_deleted($where); |
|
| 1023 | + } else { |
|
| 1024 | + $results = $questionGroupModel->get_all_deleted($query_params); |
|
| 1025 | + } |
|
| 1026 | + return $results; |
|
| 1027 | + } |
|
| 1028 | + |
|
| 1029 | + |
|
| 1030 | + /** |
|
| 1031 | + * method for performing updates to question order |
|
| 1032 | + * |
|
| 1033 | + * @return void results array |
|
| 1034 | + * @throws EE_Error |
|
| 1035 | + * @throws InvalidArgumentException |
|
| 1036 | + * @throws InvalidDataTypeException |
|
| 1037 | + * @throws InvalidInterfaceException |
|
| 1038 | + */ |
|
| 1039 | + public function update_question_group_order() |
|
| 1040 | + { |
|
| 1041 | + |
|
| 1042 | + $success = esc_html__('Question group order was updated successfully.', 'event_espresso'); |
|
| 1043 | + |
|
| 1044 | + // grab our row IDs |
|
| 1045 | + $row_ids = isset($this->_req_data['row_ids']) && ! empty($this->_req_data['row_ids']) |
|
| 1046 | + ? explode(',', rtrim($this->_req_data['row_ids'], ',')) |
|
| 1047 | + : array(); |
|
| 1048 | + |
|
| 1049 | + $perpage = ! empty($this->_req_data['perpage']) |
|
| 1050 | + ? (int) $this->_req_data['perpage'] |
|
| 1051 | + : null; |
|
| 1052 | + $curpage = ! empty($this->_req_data['curpage']) |
|
| 1053 | + ? (int) $this->_req_data['curpage'] |
|
| 1054 | + : null; |
|
| 1055 | + |
|
| 1056 | + if (! empty($row_ids)) { |
|
| 1057 | + // figure out where we start the row_id count at for the current page. |
|
| 1058 | + $qsgcount = empty($curpage) ? 0 : ($curpage - 1) * $perpage; |
|
| 1059 | + |
|
| 1060 | + $row_count = count($row_ids); |
|
| 1061 | + for ($i = 0; $i < $row_count; $i++) { |
|
| 1062 | + // Update the questions when re-ordering |
|
| 1063 | + $updated = EEM_Question_Group::instance()->update( |
|
| 1064 | + array('QSG_order' => $qsgcount), |
|
| 1065 | + array(array('QSG_ID' => $row_ids[ $i ])) |
|
| 1066 | + ); |
|
| 1067 | + if ($updated === false) { |
|
| 1068 | + $success = false; |
|
| 1069 | + } |
|
| 1070 | + $qsgcount++; |
|
| 1071 | + } |
|
| 1072 | + } else { |
|
| 1073 | + $success = false; |
|
| 1074 | + } |
|
| 1075 | + |
|
| 1076 | + $errors = ! $success |
|
| 1077 | + ? esc_html__('An error occurred. The question group order was not updated.', 'event_espresso') |
|
| 1078 | + : false; |
|
| 1079 | + |
|
| 1080 | + echo wp_json_encode(array('return_data' => false, 'success' => $success, 'errors' => $errors)); |
|
| 1081 | + die(); |
|
| 1082 | + } |
|
| 1083 | + |
|
| 1084 | + |
|
| 1085 | + |
|
| 1086 | + /*************************************** REGISTRATION SETTINGS ***************************************/ |
|
| 1087 | + |
|
| 1088 | + |
|
| 1089 | + /** |
|
| 1090 | + * @throws DomainException |
|
| 1091 | + * @throws EE_Error |
|
| 1092 | + * @throws InvalidArgumentException |
|
| 1093 | + * @throws InvalidDataTypeException |
|
| 1094 | + * @throws InvalidInterfaceException |
|
| 1095 | + */ |
|
| 1096 | + protected function _reg_form_settings() |
|
| 1097 | + { |
|
| 1098 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
| 1099 | + add_action( |
|
| 1100 | + 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template', |
|
| 1101 | + array($this, 'email_validation_settings_form'), |
|
| 1102 | + 2 |
|
| 1103 | + ); |
|
| 1104 | + add_action( |
|
| 1105 | + 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template', |
|
| 1106 | + array($this, 'copy_attendee_info_settings_form'), |
|
| 1107 | + 4 |
|
| 1108 | + ); |
|
| 1109 | + $this->_template_args = (array) apply_filters( |
|
| 1110 | + 'FHEE__Extend_Registration_Form_Admin_Page___reg_form_settings___template_args', |
|
| 1111 | + $this->_template_args |
|
| 1112 | + ); |
|
| 1113 | + $this->_set_add_edit_form_tags('update_reg_form_settings'); |
|
| 1114 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 1115 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 1116 | + REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'reg_form_settings.template.php', |
|
| 1117 | + $this->_template_args, |
|
| 1118 | + true |
|
| 1119 | + ); |
|
| 1120 | + $this->display_admin_page_with_sidebar(); |
|
| 1121 | + } |
|
| 1122 | + |
|
| 1123 | + |
|
| 1124 | + /** |
|
| 1125 | + * @return void |
|
| 1126 | + * @throws EE_Error |
|
| 1127 | + * @throws InvalidArgumentException |
|
| 1128 | + * @throws ReflectionException |
|
| 1129 | + * @throws InvalidDataTypeException |
|
| 1130 | + * @throws InvalidInterfaceException |
|
| 1131 | + */ |
|
| 1132 | + protected function _update_reg_form_settings() |
|
| 1133 | + { |
|
| 1134 | + EE_Registry::instance()->CFG->registration = $this->update_email_validation_settings_form( |
|
| 1135 | + EE_Registry::instance()->CFG->registration |
|
| 1136 | + ); |
|
| 1137 | + EE_Registry::instance()->CFG->registration = $this->update_copy_attendee_info_settings_form( |
|
| 1138 | + EE_Registry::instance()->CFG->registration |
|
| 1139 | + ); |
|
| 1140 | + EE_Registry::instance()->CFG->registration = apply_filters( |
|
| 1141 | + 'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration', |
|
| 1142 | + EE_Registry::instance()->CFG->registration |
|
| 1143 | + ); |
|
| 1144 | + $success = $this->_update_espresso_configuration( |
|
| 1145 | + esc_html__('Registration Form Options', 'event_espresso'), |
|
| 1146 | + EE_Registry::instance()->CFG, |
|
| 1147 | + __FILE__, |
|
| 1148 | + __FUNCTION__, |
|
| 1149 | + __LINE__ |
|
| 1150 | + ); |
|
| 1151 | + $this->_redirect_after_action( |
|
| 1152 | + $success, |
|
| 1153 | + esc_html__('Registration Form Options', 'event_espresso'), |
|
| 1154 | + 'updated', |
|
| 1155 | + array('action' => 'view_reg_form_settings') |
|
| 1156 | + ); |
|
| 1157 | + } |
|
| 1158 | + |
|
| 1159 | + |
|
| 1160 | + /** |
|
| 1161 | + * @return void |
|
| 1162 | + * @throws EE_Error |
|
| 1163 | + * @throws InvalidArgumentException |
|
| 1164 | + * @throws InvalidDataTypeException |
|
| 1165 | + * @throws InvalidInterfaceException |
|
| 1166 | + */ |
|
| 1167 | + public function copy_attendee_info_settings_form() |
|
| 1168 | + { |
|
| 1169 | + echo $this->_copy_attendee_info_settings_form()->get_html(); |
|
| 1170 | + } |
|
| 1171 | + |
|
| 1172 | + /** |
|
| 1173 | + * _copy_attendee_info_settings_form |
|
| 1174 | + * |
|
| 1175 | + * @access protected |
|
| 1176 | + * @return EE_Form_Section_Proper |
|
| 1177 | + * @throws \EE_Error |
|
| 1178 | + */ |
|
| 1179 | + protected function _copy_attendee_info_settings_form() |
|
| 1180 | + { |
|
| 1181 | + return new EE_Form_Section_Proper( |
|
| 1182 | + array( |
|
| 1183 | + 'name' => 'copy_attendee_info_settings', |
|
| 1184 | + 'html_id' => 'copy_attendee_info_settings', |
|
| 1185 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 1186 | + 'subsections' => apply_filters( |
|
| 1187 | + 'FHEE__Extend_Registration_Form_Admin_Page___copy_attendee_info_settings_form__form_subsections', |
|
| 1188 | + array( |
|
| 1189 | + 'copy_attendee_info_hdr' => new EE_Form_Section_HTML( |
|
| 1190 | + EEH_HTML::h2(esc_html__('Copy Attendee Info Settings', 'event_espresso')) |
|
| 1191 | + ), |
|
| 1192 | + 'copy_attendee_info' => new EE_Yes_No_Input( |
|
| 1193 | + array( |
|
| 1194 | + 'html_label_text' => esc_html__( |
|
| 1195 | + 'Allow copy #1 attendee info to extra attendees?', |
|
| 1196 | + 'event_espresso' |
|
| 1197 | + ), |
|
| 1198 | + 'html_help_text' => esc_html__( |
|
| 1199 | + 'Set to yes if you want to enable the copy of #1 attendee info to extra attendees at Registration Form.', |
|
| 1200 | + 'event_espresso' |
|
| 1201 | + ), |
|
| 1202 | + 'default' => EE_Registry::instance()->CFG->registration->copyAttendeeInfo(), |
|
| 1203 | + 'required' => false, |
|
| 1204 | + 'display_html_label_text' => false, |
|
| 1205 | + ) |
|
| 1206 | + ), |
|
| 1207 | + ) |
|
| 1208 | + ), |
|
| 1209 | + ) |
|
| 1210 | + ); |
|
| 1211 | + } |
|
| 1212 | + |
|
| 1213 | + /** |
|
| 1214 | + * @param EE_Registration_Config $EE_Registration_Config |
|
| 1215 | + * @return EE_Registration_Config |
|
| 1216 | + * @throws EE_Error |
|
| 1217 | + * @throws InvalidArgumentException |
|
| 1218 | + * @throws ReflectionException |
|
| 1219 | + * @throws InvalidDataTypeException |
|
| 1220 | + * @throws InvalidInterfaceException |
|
| 1221 | + */ |
|
| 1222 | + public function update_copy_attendee_info_settings_form(EE_Registration_Config $EE_Registration_Config) |
|
| 1223 | + { |
|
| 1224 | + $prev_copy_attendee_info = $EE_Registration_Config->copyAttendeeInfo(); |
|
| 1225 | + try { |
|
| 1226 | + $copy_attendee_info_settings_form = $this->_copy_attendee_info_settings_form(); |
|
| 1227 | + // if not displaying a form, then check for form submission |
|
| 1228 | + if ($copy_attendee_info_settings_form->was_submitted()) { |
|
| 1229 | + // capture form data |
|
| 1230 | + $copy_attendee_info_settings_form->receive_form_submission(); |
|
| 1231 | + // validate form data |
|
| 1232 | + if ($copy_attendee_info_settings_form->is_valid()) { |
|
| 1233 | + // grab validated data from form |
|
| 1234 | + $valid_data = $copy_attendee_info_settings_form->valid_data(); |
|
| 1235 | + if (isset($valid_data['copy_attendee_info'])) { |
|
| 1236 | + $EE_Registration_Config->setCopyAttendeeInfo($valid_data['copy_attendee_info']); |
|
| 1237 | + } else { |
|
| 1238 | + EE_Error::add_error( |
|
| 1239 | + esc_html__( |
|
| 1240 | + 'Invalid or missing Copy Attendee Info settings. Please refresh the form and try again.', |
|
| 1241 | + 'event_espresso' |
|
| 1242 | + ), |
|
| 1243 | + __FILE__, |
|
| 1244 | + __FUNCTION__, |
|
| 1245 | + __LINE__ |
|
| 1246 | + ); |
|
| 1247 | + } |
|
| 1248 | + } else { |
|
| 1249 | + if ($copy_attendee_info_settings_form->submission_error_message() !== '') { |
|
| 1250 | + EE_Error::add_error( |
|
| 1251 | + $copy_attendee_info_settings_form->submission_error_message(), |
|
| 1252 | + __FILE__, |
|
| 1253 | + __FUNCTION__, |
|
| 1254 | + __LINE__ |
|
| 1255 | + ); |
|
| 1256 | + } |
|
| 1257 | + } |
|
| 1258 | + } |
|
| 1259 | + } catch (EE_Error $e) { |
|
| 1260 | + $e->get_error(); |
|
| 1261 | + } |
|
| 1262 | + return $EE_Registration_Config; |
|
| 1263 | + } |
|
| 1264 | + |
|
| 1265 | + |
|
| 1266 | + /** |
|
| 1267 | + * @return void |
|
| 1268 | + * @throws EE_Error |
|
| 1269 | + * @throws InvalidArgumentException |
|
| 1270 | + * @throws InvalidDataTypeException |
|
| 1271 | + * @throws InvalidInterfaceException |
|
| 1272 | + */ |
|
| 1273 | + public function email_validation_settings_form() |
|
| 1274 | + { |
|
| 1275 | + echo $this->_email_validation_settings_form()->get_html(); |
|
| 1276 | + } |
|
| 1277 | + |
|
| 1278 | + |
|
| 1279 | + /** |
|
| 1280 | + * _email_validation_settings_form |
|
| 1281 | + * |
|
| 1282 | + * @access protected |
|
| 1283 | + * @return EE_Form_Section_Proper |
|
| 1284 | + * @throws \EE_Error |
|
| 1285 | + */ |
|
| 1286 | + protected function _email_validation_settings_form() |
|
| 1287 | + { |
|
| 1288 | + return new EE_Form_Section_Proper( |
|
| 1289 | + array( |
|
| 1290 | + 'name' => 'email_validation_settings', |
|
| 1291 | + 'html_id' => 'email_validation_settings', |
|
| 1292 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 1293 | + 'subsections' => apply_filters( |
|
| 1294 | + 'FHEE__Extend_Registration_Form_Admin_Page___email_validation_settings_form__form_subsections', |
|
| 1295 | + array( |
|
| 1296 | + 'email_validation_hdr' => new EE_Form_Section_HTML( |
|
| 1297 | + EEH_HTML::h2(esc_html__('Email Validation Settings', 'event_espresso')) |
|
| 1298 | + ), |
|
| 1299 | + 'email_validation_level' => new EE_Select_Input( |
|
| 1300 | + array( |
|
| 1301 | + 'basic' => esc_html__('Basic', 'event_espresso'), |
|
| 1302 | + 'wp_default' => esc_html__('WordPress Default', 'event_espresso'), |
|
| 1303 | + 'i18n' => esc_html__('International', 'event_espresso'), |
|
| 1304 | + 'i18n_dns' => esc_html__('International + DNS Check', 'event_espresso'), |
|
| 1305 | + ), |
|
| 1306 | + array( |
|
| 1307 | + 'html_label_text' => esc_html__('Email Validation Level', 'event_espresso') |
|
| 1308 | + . EEH_Template::get_help_tab_link('email_validation_info'), |
|
| 1309 | + 'html_help_text' => esc_html__( |
|
| 1310 | + 'These levels range from basic validation ( ie: [email protected] ) to more advanced checks against international email addresses (ie: üñîçøðé@example.com ) with additional MX and A record checks to confirm the domain actually exists. More information on on each level can be found within the help section.', |
|
| 1311 | + 'event_espresso' |
|
| 1312 | + ), |
|
| 1313 | + 'default' => isset( |
|
| 1314 | + EE_Registry::instance()->CFG->registration->email_validation_level |
|
| 1315 | + ) |
|
| 1316 | + ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
| 1317 | + : 'wp_default', |
|
| 1318 | + 'required' => false, |
|
| 1319 | + ) |
|
| 1320 | + ), |
|
| 1321 | + ) |
|
| 1322 | + ), |
|
| 1323 | + ) |
|
| 1324 | + ); |
|
| 1325 | + } |
|
| 1326 | + |
|
| 1327 | + |
|
| 1328 | + /** |
|
| 1329 | + * @param EE_Registration_Config $EE_Registration_Config |
|
| 1330 | + * @return EE_Registration_Config |
|
| 1331 | + * @throws EE_Error |
|
| 1332 | + * @throws InvalidArgumentException |
|
| 1333 | + * @throws ReflectionException |
|
| 1334 | + * @throws InvalidDataTypeException |
|
| 1335 | + * @throws InvalidInterfaceException |
|
| 1336 | + */ |
|
| 1337 | + public function update_email_validation_settings_form(EE_Registration_Config $EE_Registration_Config) |
|
| 1338 | + { |
|
| 1339 | + $prev_email_validation_level = $EE_Registration_Config->email_validation_level; |
|
| 1340 | + try { |
|
| 1341 | + $email_validation_settings_form = $this->_email_validation_settings_form(); |
|
| 1342 | + // if not displaying a form, then check for form submission |
|
| 1343 | + if ($email_validation_settings_form->was_submitted()) { |
|
| 1344 | + // capture form data |
|
| 1345 | + $email_validation_settings_form->receive_form_submission(); |
|
| 1346 | + // validate form data |
|
| 1347 | + if ($email_validation_settings_form->is_valid()) { |
|
| 1348 | + // grab validated data from form |
|
| 1349 | + $valid_data = $email_validation_settings_form->valid_data(); |
|
| 1350 | + if (isset($valid_data['email_validation_level'])) { |
|
| 1351 | + $email_validation_level = $valid_data['email_validation_level']; |
|
| 1352 | + // now if they want to use international email addresses |
|
| 1353 | + if ($email_validation_level === 'i18n' || $email_validation_level === 'i18n_dns') { |
|
| 1354 | + // in case we need to reset their email validation level, |
|
| 1355 | + // make sure that the previous value wasn't already set to one of the i18n options. |
|
| 1356 | + if ($prev_email_validation_level === 'i18n' || $prev_email_validation_level === 'i18n_dns') { |
|
| 1357 | + // if so, then reset it back to "basic" since that is the only other option that, |
|
| 1358 | + // despite offering poor validation, supports i18n email addresses |
|
| 1359 | + $prev_email_validation_level = 'basic'; |
|
| 1360 | + } |
|
| 1361 | + // confirm our i18n email validation will work on the server |
|
| 1362 | + if (! $this->_verify_pcre_support($EE_Registration_Config, $email_validation_level)) { |
|
| 1363 | + // or reset email validation level to previous value |
|
| 1364 | + $email_validation_level = $prev_email_validation_level; |
|
| 1365 | + } |
|
| 1366 | + } |
|
| 1367 | + $EE_Registration_Config->email_validation_level = $email_validation_level; |
|
| 1368 | + } else { |
|
| 1369 | + EE_Error::add_error( |
|
| 1370 | + esc_html__( |
|
| 1371 | + 'Invalid or missing Email Validation settings. Please refresh the form and try again.', |
|
| 1372 | + 'event_espresso' |
|
| 1373 | + ), |
|
| 1374 | + __FILE__, |
|
| 1375 | + __FUNCTION__, |
|
| 1376 | + __LINE__ |
|
| 1377 | + ); |
|
| 1378 | + } |
|
| 1379 | + } else { |
|
| 1380 | + if ($email_validation_settings_form->submission_error_message() !== '') { |
|
| 1381 | + EE_Error::add_error( |
|
| 1382 | + $email_validation_settings_form->submission_error_message(), |
|
| 1383 | + __FILE__, |
|
| 1384 | + __FUNCTION__, |
|
| 1385 | + __LINE__ |
|
| 1386 | + ); |
|
| 1387 | + } |
|
| 1388 | + } |
|
| 1389 | + } |
|
| 1390 | + } catch (EE_Error $e) { |
|
| 1391 | + $e->get_error(); |
|
| 1392 | + } |
|
| 1393 | + return $EE_Registration_Config; |
|
| 1394 | + } |
|
| 1395 | + |
|
| 1396 | + |
|
| 1397 | + /** |
|
| 1398 | + * confirms that the server's PHP version has the PCRE module enabled, |
|
| 1399 | + * and that the PCRE version works with our i18n email validation |
|
| 1400 | + * |
|
| 1401 | + * @param EE_Registration_Config $EE_Registration_Config |
|
| 1402 | + * @param string $email_validation_level |
|
| 1403 | + * @return bool |
|
| 1404 | + */ |
|
| 1405 | + private function _verify_pcre_support(EE_Registration_Config $EE_Registration_Config, $email_validation_level) |
|
| 1406 | + { |
|
| 1407 | + // first check that PCRE is enabled |
|
| 1408 | + if (! defined('PREG_BAD_UTF8_ERROR')) { |
|
| 1409 | + EE_Error::add_error( |
|
| 1410 | + sprintf( |
|
| 1411 | + esc_html__( |
|
| 1412 | + 'We\'re sorry, but it appears that your server\'s version of PHP was not compiled with PCRE unicode support.%1$sPlease contact your hosting company and ask them whether the PCRE compiled with your version of PHP on your server can be been built with the "--enable-unicode-properties" and "--enable-utf8" configuration switches to enable more complex regex expressions.%1$sIf they are unable, or unwilling to do so, then your server will not support international email addresses using UTF-8 unicode characters. This means you will either have to lower your email validation level to "Basic" or "WordPress Default", or switch to a hosting company that has/can enable PCRE unicode support on the server.', |
|
| 1413 | + 'event_espresso' |
|
| 1414 | + ), |
|
| 1415 | + '<br />' |
|
| 1416 | + ), |
|
| 1417 | + __FILE__, |
|
| 1418 | + __FUNCTION__, |
|
| 1419 | + __LINE__ |
|
| 1420 | + ); |
|
| 1421 | + return false; |
|
| 1422 | + } else { |
|
| 1423 | + // PCRE support is enabled, but let's still |
|
| 1424 | + // perform a test to see if the server will support it. |
|
| 1425 | + // but first, save the updated validation level to the config, |
|
| 1426 | + // so that the validation strategy picks it up. |
|
| 1427 | + // this will get bumped back down if it doesn't work |
|
| 1428 | + $EE_Registration_Config->email_validation_level = $email_validation_level; |
|
| 1429 | + try { |
|
| 1430 | + $email_validator = new EE_Email_Validation_Strategy(); |
|
| 1431 | + $i18n_email_address = apply_filters( |
|
| 1432 | + 'FHEE__Extend_Registration_Form_Admin_Page__update_email_validation_settings_form__i18n_email_address', |
|
| 1433 | + 'jägerjü[email protected]' |
|
| 1434 | + ); |
|
| 1435 | + $email_validator->validate($i18n_email_address); |
|
| 1436 | + } catch (Exception $e) { |
|
| 1437 | + EE_Error::add_error( |
|
| 1438 | + sprintf( |
|
| 1439 | + esc_html__( |
|
| 1440 | + 'We\'re sorry, but it appears that your server\'s configuration will not support the "International" or "International + DNS Check" email validation levels.%1$sTo correct this issue, please consult with your hosting company regarding your server\'s PCRE settings.%1$sIt is recommended that your PHP version be configured to use PCRE 8.10 or newer.%1$sMore information regarding PCRE versions and installation can be found here: %2$s', |
|
| 1441 | + 'event_espresso' |
|
| 1442 | + ), |
|
| 1443 | + '<br />', |
|
| 1444 | + '<a href="http://php.net/manual/en/pcre.installation.php" target="_blank" rel="noopener noreferrer">http://php.net/manual/en/pcre.installation.php</a>' |
|
| 1445 | + ), |
|
| 1446 | + __FILE__, |
|
| 1447 | + __FUNCTION__, |
|
| 1448 | + __LINE__ |
|
| 1449 | + ); |
|
| 1450 | + return false; |
|
| 1451 | + } |
|
| 1452 | + } |
|
| 1453 | + return true; |
|
| 1454 | + } |
|
| 1455 | 1455 | } |
@@ -16,1268 +16,1268 @@ |
||
| 16 | 16 | { |
| 17 | 17 | |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * This is used to hold the reports template data which is setup early in the request. |
|
| 21 | - * |
|
| 22 | - * @type array |
|
| 23 | - */ |
|
| 24 | - protected $_reports_template_data = array(); |
|
| 19 | + /** |
|
| 20 | + * This is used to hold the reports template data which is setup early in the request. |
|
| 21 | + * |
|
| 22 | + * @type array |
|
| 23 | + */ |
|
| 24 | + protected $_reports_template_data = array(); |
|
| 25 | 25 | |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Extend_Registrations_Admin_Page constructor. |
|
| 29 | - * |
|
| 30 | - * @param bool $routing |
|
| 31 | - */ |
|
| 32 | - public function __construct($routing = true) |
|
| 33 | - { |
|
| 34 | - parent::__construct($routing); |
|
| 35 | - if (! defined('REG_CAF_TEMPLATE_PATH')) { |
|
| 36 | - define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/'); |
|
| 37 | - define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/'); |
|
| 38 | - define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/'); |
|
| 39 | - } |
|
| 40 | - } |
|
| 27 | + /** |
|
| 28 | + * Extend_Registrations_Admin_Page constructor. |
|
| 29 | + * |
|
| 30 | + * @param bool $routing |
|
| 31 | + */ |
|
| 32 | + public function __construct($routing = true) |
|
| 33 | + { |
|
| 34 | + parent::__construct($routing); |
|
| 35 | + if (! defined('REG_CAF_TEMPLATE_PATH')) { |
|
| 36 | + define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/'); |
|
| 37 | + define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/'); |
|
| 38 | + define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/'); |
|
| 39 | + } |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Extending page configuration. |
|
| 45 | - */ |
|
| 46 | - protected function _extend_page_config() |
|
| 47 | - { |
|
| 48 | - $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations'; |
|
| 49 | - $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID']) |
|
| 50 | - ? $this->_req_data['_REG_ID'] |
|
| 51 | - : 0; |
|
| 52 | - $new_page_routes = array( |
|
| 53 | - 'reports' => array( |
|
| 54 | - 'func' => '_registration_reports', |
|
| 55 | - 'capability' => 'ee_read_registrations', |
|
| 56 | - ), |
|
| 57 | - 'registration_checkins' => array( |
|
| 58 | - 'func' => '_registration_checkin_list_table', |
|
| 59 | - 'capability' => 'ee_read_checkins', |
|
| 60 | - ), |
|
| 61 | - 'newsletter_selected_send' => array( |
|
| 62 | - 'func' => '_newsletter_selected_send', |
|
| 63 | - 'noheader' => true, |
|
| 64 | - 'capability' => 'ee_send_message', |
|
| 65 | - ), |
|
| 66 | - 'delete_checkin_rows' => array( |
|
| 67 | - 'func' => '_delete_checkin_rows', |
|
| 68 | - 'noheader' => true, |
|
| 69 | - 'capability' => 'ee_delete_checkins', |
|
| 70 | - ), |
|
| 71 | - 'delete_checkin_row' => array( |
|
| 72 | - 'func' => '_delete_checkin_row', |
|
| 73 | - 'noheader' => true, |
|
| 74 | - 'capability' => 'ee_delete_checkin', |
|
| 75 | - 'obj_id' => $reg_id, |
|
| 76 | - ), |
|
| 77 | - 'toggle_checkin_status' => array( |
|
| 78 | - 'func' => '_toggle_checkin_status', |
|
| 79 | - 'noheader' => true, |
|
| 80 | - 'capability' => 'ee_edit_checkin', |
|
| 81 | - 'obj_id' => $reg_id, |
|
| 82 | - ), |
|
| 83 | - 'toggle_checkin_status_bulk' => array( |
|
| 84 | - 'func' => '_toggle_checkin_status', |
|
| 85 | - 'noheader' => true, |
|
| 86 | - 'capability' => 'ee_edit_checkins', |
|
| 87 | - ), |
|
| 88 | - 'event_registrations' => array( |
|
| 89 | - 'func' => '_event_registrations_list_table', |
|
| 90 | - 'capability' => 'ee_read_checkins', |
|
| 91 | - ), |
|
| 92 | - 'registrations_checkin_report' => array( |
|
| 93 | - 'func' => '_registrations_checkin_report', |
|
| 94 | - 'noheader' => true, |
|
| 95 | - 'capability' => 'ee_read_registrations', |
|
| 96 | - ), |
|
| 97 | - ); |
|
| 98 | - $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
| 99 | - $new_page_config = array( |
|
| 100 | - 'reports' => array( |
|
| 101 | - 'nav' => array( |
|
| 102 | - 'label' => esc_html__('Reports', 'event_espresso'), |
|
| 103 | - 'order' => 30, |
|
| 104 | - ), |
|
| 105 | - 'help_tabs' => array( |
|
| 106 | - 'registrations_reports_help_tab' => array( |
|
| 107 | - 'title' => esc_html__('Registration Reports', 'event_espresso'), |
|
| 108 | - 'filename' => 'registrations_reports', |
|
| 109 | - ), |
|
| 110 | - ), |
|
| 111 | - /*'help_tour' => array( 'Registration_Reports_Help_Tour' ),*/ |
|
| 112 | - 'require_nonce' => false, |
|
| 113 | - ), |
|
| 114 | - 'event_registrations' => array( |
|
| 115 | - 'nav' => array( |
|
| 116 | - 'label' => esc_html__('Event Check-In', 'event_espresso'), |
|
| 117 | - 'order' => 10, |
|
| 118 | - 'persistent' => true, |
|
| 119 | - ), |
|
| 120 | - 'help_tabs' => array( |
|
| 121 | - 'registrations_event_checkin_help_tab' => array( |
|
| 122 | - 'title' => esc_html__('Registrations Event Check-In', 'event_espresso'), |
|
| 123 | - 'filename' => 'registrations_event_checkin', |
|
| 124 | - ), |
|
| 125 | - 'registrations_event_checkin_table_column_headings_help_tab' => array( |
|
| 126 | - 'title' => esc_html__('Event Check-In Table Column Headings', 'event_espresso'), |
|
| 127 | - 'filename' => 'registrations_event_checkin_table_column_headings', |
|
| 128 | - ), |
|
| 129 | - 'registrations_event_checkin_filters_help_tab' => array( |
|
| 130 | - 'title' => esc_html__('Event Check-In Filters', 'event_espresso'), |
|
| 131 | - 'filename' => 'registrations_event_checkin_filters', |
|
| 132 | - ), |
|
| 133 | - 'registrations_event_checkin_views_help_tab' => array( |
|
| 134 | - 'title' => esc_html__('Event Check-In Views', 'event_espresso'), |
|
| 135 | - 'filename' => 'registrations_event_checkin_views', |
|
| 136 | - ), |
|
| 137 | - 'registrations_event_checkin_other_help_tab' => array( |
|
| 138 | - 'title' => esc_html__('Event Check-In Other', 'event_espresso'), |
|
| 139 | - 'filename' => 'registrations_event_checkin_other', |
|
| 140 | - ), |
|
| 141 | - ), |
|
| 142 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 143 | - // 'help_tour' => array('Event_Checkin_Help_Tour'), |
|
| 144 | - 'qtips' => array('Registration_List_Table_Tips'), |
|
| 145 | - 'list_table' => 'EE_Event_Registrations_List_Table', |
|
| 146 | - 'metaboxes' => array(), |
|
| 147 | - 'require_nonce' => false, |
|
| 148 | - ), |
|
| 149 | - 'registration_checkins' => array( |
|
| 150 | - 'nav' => array( |
|
| 151 | - 'label' => esc_html__('Check-In Records', 'event_espresso'), |
|
| 152 | - 'order' => 15, |
|
| 153 | - 'persistent' => false, |
|
| 154 | - 'url' => '', |
|
| 155 | - ), |
|
| 156 | - 'list_table' => 'EE_Registration_CheckIn_List_Table', |
|
| 157 | - // 'help_tour' => array( 'Checkin_Toggle_View_Help_Tour' ), |
|
| 158 | - 'metaboxes' => array(), |
|
| 159 | - 'require_nonce' => false, |
|
| 160 | - ), |
|
| 161 | - ); |
|
| 162 | - $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
| 163 | - $this->_page_config['contact_list']['list_table'] = 'Extend_EE_Attendee_Contact_List_Table'; |
|
| 164 | - $this->_page_config['default']['list_table'] = 'Extend_EE_Registrations_List_Table'; |
|
| 165 | - } |
|
| 43 | + /** |
|
| 44 | + * Extending page configuration. |
|
| 45 | + */ |
|
| 46 | + protected function _extend_page_config() |
|
| 47 | + { |
|
| 48 | + $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations'; |
|
| 49 | + $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID']) |
|
| 50 | + ? $this->_req_data['_REG_ID'] |
|
| 51 | + : 0; |
|
| 52 | + $new_page_routes = array( |
|
| 53 | + 'reports' => array( |
|
| 54 | + 'func' => '_registration_reports', |
|
| 55 | + 'capability' => 'ee_read_registrations', |
|
| 56 | + ), |
|
| 57 | + 'registration_checkins' => array( |
|
| 58 | + 'func' => '_registration_checkin_list_table', |
|
| 59 | + 'capability' => 'ee_read_checkins', |
|
| 60 | + ), |
|
| 61 | + 'newsletter_selected_send' => array( |
|
| 62 | + 'func' => '_newsletter_selected_send', |
|
| 63 | + 'noheader' => true, |
|
| 64 | + 'capability' => 'ee_send_message', |
|
| 65 | + ), |
|
| 66 | + 'delete_checkin_rows' => array( |
|
| 67 | + 'func' => '_delete_checkin_rows', |
|
| 68 | + 'noheader' => true, |
|
| 69 | + 'capability' => 'ee_delete_checkins', |
|
| 70 | + ), |
|
| 71 | + 'delete_checkin_row' => array( |
|
| 72 | + 'func' => '_delete_checkin_row', |
|
| 73 | + 'noheader' => true, |
|
| 74 | + 'capability' => 'ee_delete_checkin', |
|
| 75 | + 'obj_id' => $reg_id, |
|
| 76 | + ), |
|
| 77 | + 'toggle_checkin_status' => array( |
|
| 78 | + 'func' => '_toggle_checkin_status', |
|
| 79 | + 'noheader' => true, |
|
| 80 | + 'capability' => 'ee_edit_checkin', |
|
| 81 | + 'obj_id' => $reg_id, |
|
| 82 | + ), |
|
| 83 | + 'toggle_checkin_status_bulk' => array( |
|
| 84 | + 'func' => '_toggle_checkin_status', |
|
| 85 | + 'noheader' => true, |
|
| 86 | + 'capability' => 'ee_edit_checkins', |
|
| 87 | + ), |
|
| 88 | + 'event_registrations' => array( |
|
| 89 | + 'func' => '_event_registrations_list_table', |
|
| 90 | + 'capability' => 'ee_read_checkins', |
|
| 91 | + ), |
|
| 92 | + 'registrations_checkin_report' => array( |
|
| 93 | + 'func' => '_registrations_checkin_report', |
|
| 94 | + 'noheader' => true, |
|
| 95 | + 'capability' => 'ee_read_registrations', |
|
| 96 | + ), |
|
| 97 | + ); |
|
| 98 | + $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
| 99 | + $new_page_config = array( |
|
| 100 | + 'reports' => array( |
|
| 101 | + 'nav' => array( |
|
| 102 | + 'label' => esc_html__('Reports', 'event_espresso'), |
|
| 103 | + 'order' => 30, |
|
| 104 | + ), |
|
| 105 | + 'help_tabs' => array( |
|
| 106 | + 'registrations_reports_help_tab' => array( |
|
| 107 | + 'title' => esc_html__('Registration Reports', 'event_espresso'), |
|
| 108 | + 'filename' => 'registrations_reports', |
|
| 109 | + ), |
|
| 110 | + ), |
|
| 111 | + /*'help_tour' => array( 'Registration_Reports_Help_Tour' ),*/ |
|
| 112 | + 'require_nonce' => false, |
|
| 113 | + ), |
|
| 114 | + 'event_registrations' => array( |
|
| 115 | + 'nav' => array( |
|
| 116 | + 'label' => esc_html__('Event Check-In', 'event_espresso'), |
|
| 117 | + 'order' => 10, |
|
| 118 | + 'persistent' => true, |
|
| 119 | + ), |
|
| 120 | + 'help_tabs' => array( |
|
| 121 | + 'registrations_event_checkin_help_tab' => array( |
|
| 122 | + 'title' => esc_html__('Registrations Event Check-In', 'event_espresso'), |
|
| 123 | + 'filename' => 'registrations_event_checkin', |
|
| 124 | + ), |
|
| 125 | + 'registrations_event_checkin_table_column_headings_help_tab' => array( |
|
| 126 | + 'title' => esc_html__('Event Check-In Table Column Headings', 'event_espresso'), |
|
| 127 | + 'filename' => 'registrations_event_checkin_table_column_headings', |
|
| 128 | + ), |
|
| 129 | + 'registrations_event_checkin_filters_help_tab' => array( |
|
| 130 | + 'title' => esc_html__('Event Check-In Filters', 'event_espresso'), |
|
| 131 | + 'filename' => 'registrations_event_checkin_filters', |
|
| 132 | + ), |
|
| 133 | + 'registrations_event_checkin_views_help_tab' => array( |
|
| 134 | + 'title' => esc_html__('Event Check-In Views', 'event_espresso'), |
|
| 135 | + 'filename' => 'registrations_event_checkin_views', |
|
| 136 | + ), |
|
| 137 | + 'registrations_event_checkin_other_help_tab' => array( |
|
| 138 | + 'title' => esc_html__('Event Check-In Other', 'event_espresso'), |
|
| 139 | + 'filename' => 'registrations_event_checkin_other', |
|
| 140 | + ), |
|
| 141 | + ), |
|
| 142 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 143 | + // 'help_tour' => array('Event_Checkin_Help_Tour'), |
|
| 144 | + 'qtips' => array('Registration_List_Table_Tips'), |
|
| 145 | + 'list_table' => 'EE_Event_Registrations_List_Table', |
|
| 146 | + 'metaboxes' => array(), |
|
| 147 | + 'require_nonce' => false, |
|
| 148 | + ), |
|
| 149 | + 'registration_checkins' => array( |
|
| 150 | + 'nav' => array( |
|
| 151 | + 'label' => esc_html__('Check-In Records', 'event_espresso'), |
|
| 152 | + 'order' => 15, |
|
| 153 | + 'persistent' => false, |
|
| 154 | + 'url' => '', |
|
| 155 | + ), |
|
| 156 | + 'list_table' => 'EE_Registration_CheckIn_List_Table', |
|
| 157 | + // 'help_tour' => array( 'Checkin_Toggle_View_Help_Tour' ), |
|
| 158 | + 'metaboxes' => array(), |
|
| 159 | + 'require_nonce' => false, |
|
| 160 | + ), |
|
| 161 | + ); |
|
| 162 | + $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
| 163 | + $this->_page_config['contact_list']['list_table'] = 'Extend_EE_Attendee_Contact_List_Table'; |
|
| 164 | + $this->_page_config['default']['list_table'] = 'Extend_EE_Registrations_List_Table'; |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | 167 | |
| 168 | - /** |
|
| 169 | - * Ajax hooks for all routes in this page. |
|
| 170 | - */ |
|
| 171 | - protected function _ajax_hooks() |
|
| 172 | - { |
|
| 173 | - parent::_ajax_hooks(); |
|
| 174 | - add_action('wp_ajax_get_newsletter_form_content', array($this, 'get_newsletter_form_content')); |
|
| 175 | - } |
|
| 168 | + /** |
|
| 169 | + * Ajax hooks for all routes in this page. |
|
| 170 | + */ |
|
| 171 | + protected function _ajax_hooks() |
|
| 172 | + { |
|
| 173 | + parent::_ajax_hooks(); |
|
| 174 | + add_action('wp_ajax_get_newsletter_form_content', array($this, 'get_newsletter_form_content')); |
|
| 175 | + } |
|
| 176 | 176 | |
| 177 | 177 | |
| 178 | - /** |
|
| 179 | - * Global scripts for all routes in this page. |
|
| 180 | - */ |
|
| 181 | - public function load_scripts_styles() |
|
| 182 | - { |
|
| 183 | - parent::load_scripts_styles(); |
|
| 184 | - // if newsletter message type is active then let's add filter and load js for it. |
|
| 185 | - if (EEH_MSG_Template::is_mt_active('newsletter')) { |
|
| 186 | - // enqueue newsletter js |
|
| 187 | - wp_enqueue_script( |
|
| 188 | - 'ee-newsletter-trigger', |
|
| 189 | - REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js', |
|
| 190 | - array('ee-dialog'), |
|
| 191 | - EVENT_ESPRESSO_VERSION, |
|
| 192 | - true |
|
| 193 | - ); |
|
| 194 | - wp_enqueue_style( |
|
| 195 | - 'ee-newsletter-trigger-css', |
|
| 196 | - REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css', |
|
| 197 | - array(), |
|
| 198 | - EVENT_ESPRESSO_VERSION |
|
| 199 | - ); |
|
| 200 | - // hook in buttons for newsletter message type trigger. |
|
| 201 | - add_action( |
|
| 202 | - 'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', |
|
| 203 | - array($this, 'add_newsletter_action_buttons'), |
|
| 204 | - 10 |
|
| 205 | - ); |
|
| 206 | - } |
|
| 207 | - } |
|
| 178 | + /** |
|
| 179 | + * Global scripts for all routes in this page. |
|
| 180 | + */ |
|
| 181 | + public function load_scripts_styles() |
|
| 182 | + { |
|
| 183 | + parent::load_scripts_styles(); |
|
| 184 | + // if newsletter message type is active then let's add filter and load js for it. |
|
| 185 | + if (EEH_MSG_Template::is_mt_active('newsletter')) { |
|
| 186 | + // enqueue newsletter js |
|
| 187 | + wp_enqueue_script( |
|
| 188 | + 'ee-newsletter-trigger', |
|
| 189 | + REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js', |
|
| 190 | + array('ee-dialog'), |
|
| 191 | + EVENT_ESPRESSO_VERSION, |
|
| 192 | + true |
|
| 193 | + ); |
|
| 194 | + wp_enqueue_style( |
|
| 195 | + 'ee-newsletter-trigger-css', |
|
| 196 | + REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css', |
|
| 197 | + array(), |
|
| 198 | + EVENT_ESPRESSO_VERSION |
|
| 199 | + ); |
|
| 200 | + // hook in buttons for newsletter message type trigger. |
|
| 201 | + add_action( |
|
| 202 | + 'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', |
|
| 203 | + array($this, 'add_newsletter_action_buttons'), |
|
| 204 | + 10 |
|
| 205 | + ); |
|
| 206 | + } |
|
| 207 | + } |
|
| 208 | 208 | |
| 209 | 209 | |
| 210 | - /** |
|
| 211 | - * Scripts and styles for just the reports route. |
|
| 212 | - */ |
|
| 213 | - public function load_scripts_styles_reports() |
|
| 214 | - { |
|
| 215 | - wp_register_script( |
|
| 216 | - 'ee-reg-reports-js', |
|
| 217 | - REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js', |
|
| 218 | - array('google-charts'), |
|
| 219 | - EVENT_ESPRESSO_VERSION, |
|
| 220 | - true |
|
| 221 | - ); |
|
| 222 | - wp_enqueue_script('ee-reg-reports-js'); |
|
| 223 | - $this->_registration_reports_js_setup(); |
|
| 224 | - } |
|
| 210 | + /** |
|
| 211 | + * Scripts and styles for just the reports route. |
|
| 212 | + */ |
|
| 213 | + public function load_scripts_styles_reports() |
|
| 214 | + { |
|
| 215 | + wp_register_script( |
|
| 216 | + 'ee-reg-reports-js', |
|
| 217 | + REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js', |
|
| 218 | + array('google-charts'), |
|
| 219 | + EVENT_ESPRESSO_VERSION, |
|
| 220 | + true |
|
| 221 | + ); |
|
| 222 | + wp_enqueue_script('ee-reg-reports-js'); |
|
| 223 | + $this->_registration_reports_js_setup(); |
|
| 224 | + } |
|
| 225 | 225 | |
| 226 | 226 | |
| 227 | - /** |
|
| 228 | - * Register screen options for event_registrations route. |
|
| 229 | - */ |
|
| 230 | - protected function _add_screen_options_event_registrations() |
|
| 231 | - { |
|
| 232 | - $this->_per_page_screen_option(); |
|
| 233 | - } |
|
| 227 | + /** |
|
| 228 | + * Register screen options for event_registrations route. |
|
| 229 | + */ |
|
| 230 | + protected function _add_screen_options_event_registrations() |
|
| 231 | + { |
|
| 232 | + $this->_per_page_screen_option(); |
|
| 233 | + } |
|
| 234 | 234 | |
| 235 | 235 | |
| 236 | - /** |
|
| 237 | - * Register screen options for registration_checkins route |
|
| 238 | - */ |
|
| 239 | - protected function _add_screen_options_registration_checkins() |
|
| 240 | - { |
|
| 241 | - $page_title = $this->_admin_page_title; |
|
| 242 | - $this->_admin_page_title = esc_html__('Check-In Records', 'event_espresso'); |
|
| 243 | - $this->_per_page_screen_option(); |
|
| 244 | - $this->_admin_page_title = $page_title; |
|
| 245 | - } |
|
| 236 | + /** |
|
| 237 | + * Register screen options for registration_checkins route |
|
| 238 | + */ |
|
| 239 | + protected function _add_screen_options_registration_checkins() |
|
| 240 | + { |
|
| 241 | + $page_title = $this->_admin_page_title; |
|
| 242 | + $this->_admin_page_title = esc_html__('Check-In Records', 'event_espresso'); |
|
| 243 | + $this->_per_page_screen_option(); |
|
| 244 | + $this->_admin_page_title = $page_title; |
|
| 245 | + } |
|
| 246 | 246 | |
| 247 | 247 | |
| 248 | - /** |
|
| 249 | - * Set views property for event_registrations route. |
|
| 250 | - */ |
|
| 251 | - protected function _set_list_table_views_event_registrations() |
|
| 252 | - { |
|
| 253 | - $this->_views = array( |
|
| 254 | - 'all' => array( |
|
| 255 | - 'slug' => 'all', |
|
| 256 | - 'label' => esc_html__('All', 'event_espresso'), |
|
| 257 | - 'count' => 0, |
|
| 258 | - 'bulk_action' => ! isset($this->_req_data['event_id']) |
|
| 259 | - ? array() |
|
| 260 | - : array( |
|
| 261 | - 'toggle_checkin_status_bulk' => esc_html__('Toggle Check-In', 'event_espresso'), |
|
| 262 | - ), |
|
| 263 | - ), |
|
| 264 | - ); |
|
| 265 | - } |
|
| 248 | + /** |
|
| 249 | + * Set views property for event_registrations route. |
|
| 250 | + */ |
|
| 251 | + protected function _set_list_table_views_event_registrations() |
|
| 252 | + { |
|
| 253 | + $this->_views = array( |
|
| 254 | + 'all' => array( |
|
| 255 | + 'slug' => 'all', |
|
| 256 | + 'label' => esc_html__('All', 'event_espresso'), |
|
| 257 | + 'count' => 0, |
|
| 258 | + 'bulk_action' => ! isset($this->_req_data['event_id']) |
|
| 259 | + ? array() |
|
| 260 | + : array( |
|
| 261 | + 'toggle_checkin_status_bulk' => esc_html__('Toggle Check-In', 'event_espresso'), |
|
| 262 | + ), |
|
| 263 | + ), |
|
| 264 | + ); |
|
| 265 | + } |
|
| 266 | 266 | |
| 267 | 267 | |
| 268 | - /** |
|
| 269 | - * Set views property for registration_checkins route. |
|
| 270 | - */ |
|
| 271 | - protected function _set_list_table_views_registration_checkins() |
|
| 272 | - { |
|
| 273 | - $this->_views = array( |
|
| 274 | - 'all' => array( |
|
| 275 | - 'slug' => 'all', |
|
| 276 | - 'label' => esc_html__('All', 'event_espresso'), |
|
| 277 | - 'count' => 0, |
|
| 278 | - 'bulk_action' => array('delete_checkin_rows' => esc_html__('Delete Check-In Rows', 'event_espresso')), |
|
| 279 | - ), |
|
| 280 | - ); |
|
| 281 | - } |
|
| 268 | + /** |
|
| 269 | + * Set views property for registration_checkins route. |
|
| 270 | + */ |
|
| 271 | + protected function _set_list_table_views_registration_checkins() |
|
| 272 | + { |
|
| 273 | + $this->_views = array( |
|
| 274 | + 'all' => array( |
|
| 275 | + 'slug' => 'all', |
|
| 276 | + 'label' => esc_html__('All', 'event_espresso'), |
|
| 277 | + 'count' => 0, |
|
| 278 | + 'bulk_action' => array('delete_checkin_rows' => esc_html__('Delete Check-In Rows', 'event_espresso')), |
|
| 279 | + ), |
|
| 280 | + ); |
|
| 281 | + } |
|
| 282 | 282 | |
| 283 | 283 | |
| 284 | - /** |
|
| 285 | - * callback for ajax action. |
|
| 286 | - * |
|
| 287 | - * @since 4.3.0 |
|
| 288 | - * @return void (JSON) |
|
| 289 | - * @throws EE_Error |
|
| 290 | - * @throws InvalidArgumentException |
|
| 291 | - * @throws InvalidDataTypeException |
|
| 292 | - * @throws InvalidInterfaceException |
|
| 293 | - */ |
|
| 294 | - public function get_newsletter_form_content() |
|
| 295 | - { |
|
| 296 | - // do a nonce check cause we're not coming in from an normal route here. |
|
| 297 | - $nonce = isset($this->_req_data['get_newsletter_form_content_nonce']) ? sanitize_text_field( |
|
| 298 | - $this->_req_data['get_newsletter_form_content_nonce'] |
|
| 299 | - ) : ''; |
|
| 300 | - $nonce_ref = 'get_newsletter_form_content_nonce'; |
|
| 301 | - $this->_verify_nonce($nonce, $nonce_ref); |
|
| 302 | - // let's get the mtp for the incoming MTP_ ID |
|
| 303 | - if (! isset($this->_req_data['GRP_ID'])) { |
|
| 304 | - EE_Error::add_error( |
|
| 305 | - esc_html__( |
|
| 306 | - 'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).', |
|
| 307 | - 'event_espresso' |
|
| 308 | - ), |
|
| 309 | - __FILE__, |
|
| 310 | - __FUNCTION__, |
|
| 311 | - __LINE__ |
|
| 312 | - ); |
|
| 313 | - $this->_template_args['success'] = false; |
|
| 314 | - $this->_template_args['error'] = true; |
|
| 315 | - $this->_return_json(); |
|
| 316 | - } |
|
| 317 | - $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']); |
|
| 318 | - if (! $MTPG instanceof EE_Message_Template_Group) { |
|
| 319 | - EE_Error::add_error( |
|
| 320 | - sprintf( |
|
| 321 | - esc_html__( |
|
| 322 | - 'The GRP_ID given (%d) does not appear to have a corresponding row in the database.', |
|
| 323 | - 'event_espresso' |
|
| 324 | - ), |
|
| 325 | - $this->_req_data['GRP_ID'] |
|
| 326 | - ), |
|
| 327 | - __FILE__, |
|
| 328 | - __FUNCTION__, |
|
| 329 | - __LINE__ |
|
| 330 | - ); |
|
| 331 | - $this->_template_args['success'] = false; |
|
| 332 | - $this->_template_args['error'] = true; |
|
| 333 | - $this->_return_json(); |
|
| 334 | - } |
|
| 335 | - $MTPs = $MTPG->context_templates(); |
|
| 336 | - $MTPs = $MTPs['attendee']; |
|
| 337 | - $template_fields = array(); |
|
| 338 | - /** @var EE_Message_Template $MTP */ |
|
| 339 | - foreach ($MTPs as $MTP) { |
|
| 340 | - $field = $MTP->get('MTP_template_field'); |
|
| 341 | - if ($field === 'content') { |
|
| 342 | - $content = $MTP->get('MTP_content'); |
|
| 343 | - if (! empty($content['newsletter_content'])) { |
|
| 344 | - $template_fields['newsletter_content'] = $content['newsletter_content']; |
|
| 345 | - } |
|
| 346 | - continue; |
|
| 347 | - } |
|
| 348 | - $template_fields[ $MTP->get('MTP_template_field') ] = $MTP->get('MTP_content'); |
|
| 349 | - } |
|
| 350 | - $this->_template_args['success'] = true; |
|
| 351 | - $this->_template_args['error'] = false; |
|
| 352 | - $this->_template_args['data'] = array( |
|
| 353 | - 'batch_message_from' => isset($template_fields['from']) |
|
| 354 | - ? $template_fields['from'] |
|
| 355 | - : '', |
|
| 356 | - 'batch_message_subject' => isset($template_fields['subject']) |
|
| 357 | - ? $template_fields['subject'] |
|
| 358 | - : '', |
|
| 359 | - 'batch_message_content' => isset($template_fields['newsletter_content']) |
|
| 360 | - ? $template_fields['newsletter_content'] |
|
| 361 | - : '', |
|
| 362 | - ); |
|
| 363 | - $this->_return_json(); |
|
| 364 | - } |
|
| 284 | + /** |
|
| 285 | + * callback for ajax action. |
|
| 286 | + * |
|
| 287 | + * @since 4.3.0 |
|
| 288 | + * @return void (JSON) |
|
| 289 | + * @throws EE_Error |
|
| 290 | + * @throws InvalidArgumentException |
|
| 291 | + * @throws InvalidDataTypeException |
|
| 292 | + * @throws InvalidInterfaceException |
|
| 293 | + */ |
|
| 294 | + public function get_newsletter_form_content() |
|
| 295 | + { |
|
| 296 | + // do a nonce check cause we're not coming in from an normal route here. |
|
| 297 | + $nonce = isset($this->_req_data['get_newsletter_form_content_nonce']) ? sanitize_text_field( |
|
| 298 | + $this->_req_data['get_newsletter_form_content_nonce'] |
|
| 299 | + ) : ''; |
|
| 300 | + $nonce_ref = 'get_newsletter_form_content_nonce'; |
|
| 301 | + $this->_verify_nonce($nonce, $nonce_ref); |
|
| 302 | + // let's get the mtp for the incoming MTP_ ID |
|
| 303 | + if (! isset($this->_req_data['GRP_ID'])) { |
|
| 304 | + EE_Error::add_error( |
|
| 305 | + esc_html__( |
|
| 306 | + 'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).', |
|
| 307 | + 'event_espresso' |
|
| 308 | + ), |
|
| 309 | + __FILE__, |
|
| 310 | + __FUNCTION__, |
|
| 311 | + __LINE__ |
|
| 312 | + ); |
|
| 313 | + $this->_template_args['success'] = false; |
|
| 314 | + $this->_template_args['error'] = true; |
|
| 315 | + $this->_return_json(); |
|
| 316 | + } |
|
| 317 | + $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']); |
|
| 318 | + if (! $MTPG instanceof EE_Message_Template_Group) { |
|
| 319 | + EE_Error::add_error( |
|
| 320 | + sprintf( |
|
| 321 | + esc_html__( |
|
| 322 | + 'The GRP_ID given (%d) does not appear to have a corresponding row in the database.', |
|
| 323 | + 'event_espresso' |
|
| 324 | + ), |
|
| 325 | + $this->_req_data['GRP_ID'] |
|
| 326 | + ), |
|
| 327 | + __FILE__, |
|
| 328 | + __FUNCTION__, |
|
| 329 | + __LINE__ |
|
| 330 | + ); |
|
| 331 | + $this->_template_args['success'] = false; |
|
| 332 | + $this->_template_args['error'] = true; |
|
| 333 | + $this->_return_json(); |
|
| 334 | + } |
|
| 335 | + $MTPs = $MTPG->context_templates(); |
|
| 336 | + $MTPs = $MTPs['attendee']; |
|
| 337 | + $template_fields = array(); |
|
| 338 | + /** @var EE_Message_Template $MTP */ |
|
| 339 | + foreach ($MTPs as $MTP) { |
|
| 340 | + $field = $MTP->get('MTP_template_field'); |
|
| 341 | + if ($field === 'content') { |
|
| 342 | + $content = $MTP->get('MTP_content'); |
|
| 343 | + if (! empty($content['newsletter_content'])) { |
|
| 344 | + $template_fields['newsletter_content'] = $content['newsletter_content']; |
|
| 345 | + } |
|
| 346 | + continue; |
|
| 347 | + } |
|
| 348 | + $template_fields[ $MTP->get('MTP_template_field') ] = $MTP->get('MTP_content'); |
|
| 349 | + } |
|
| 350 | + $this->_template_args['success'] = true; |
|
| 351 | + $this->_template_args['error'] = false; |
|
| 352 | + $this->_template_args['data'] = array( |
|
| 353 | + 'batch_message_from' => isset($template_fields['from']) |
|
| 354 | + ? $template_fields['from'] |
|
| 355 | + : '', |
|
| 356 | + 'batch_message_subject' => isset($template_fields['subject']) |
|
| 357 | + ? $template_fields['subject'] |
|
| 358 | + : '', |
|
| 359 | + 'batch_message_content' => isset($template_fields['newsletter_content']) |
|
| 360 | + ? $template_fields['newsletter_content'] |
|
| 361 | + : '', |
|
| 362 | + ); |
|
| 363 | + $this->_return_json(); |
|
| 364 | + } |
|
| 365 | 365 | |
| 366 | 366 | |
| 367 | - /** |
|
| 368 | - * callback for AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons action |
|
| 369 | - * |
|
| 370 | - * @since 4.3.0 |
|
| 371 | - * @param EE_Admin_List_Table $list_table |
|
| 372 | - * @return void |
|
| 373 | - * @throws InvalidArgumentException |
|
| 374 | - * @throws InvalidDataTypeException |
|
| 375 | - * @throws InvalidInterfaceException |
|
| 376 | - */ |
|
| 377 | - public function add_newsletter_action_buttons(EE_Admin_List_Table $list_table) |
|
| 378 | - { |
|
| 379 | - if (! EE_Registry::instance()->CAP->current_user_can( |
|
| 380 | - 'ee_send_message', |
|
| 381 | - 'espresso_registrations_newsletter_selected_send' |
|
| 382 | - ) |
|
| 383 | - ) { |
|
| 384 | - return; |
|
| 385 | - } |
|
| 386 | - $routes_to_add_to = array( |
|
| 387 | - 'contact_list', |
|
| 388 | - 'event_registrations', |
|
| 389 | - 'default', |
|
| 390 | - ); |
|
| 391 | - if ($this->_current_page === 'espresso_registrations' && in_array($this->_req_action, $routes_to_add_to)) { |
|
| 392 | - if (($this->_req_action === 'event_registrations' && empty($this->_req_data['event_id'])) |
|
| 393 | - || (isset($this->_req_data['status']) && $this->_req_data['status'] === 'trash') |
|
| 394 | - ) { |
|
| 395 | - echo ''; |
|
| 396 | - } else { |
|
| 397 | - $button_text = sprintf( |
|
| 398 | - esc_html__('Send Batch Message (%s selected)', 'event_espresso'), |
|
| 399 | - '<span class="send-selected-newsletter-count">0</span>' |
|
| 400 | - ); |
|
| 401 | - echo '<button id="selected-batch-send-trigger" class="button secondary-button">' |
|
| 402 | - . '<span class="dashicons dashicons-email "></span>' |
|
| 403 | - . $button_text |
|
| 404 | - . '</button>'; |
|
| 405 | - add_action('admin_footer', array($this, 'newsletter_send_form_skeleton')); |
|
| 406 | - } |
|
| 407 | - } |
|
| 408 | - } |
|
| 367 | + /** |
|
| 368 | + * callback for AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons action |
|
| 369 | + * |
|
| 370 | + * @since 4.3.0 |
|
| 371 | + * @param EE_Admin_List_Table $list_table |
|
| 372 | + * @return void |
|
| 373 | + * @throws InvalidArgumentException |
|
| 374 | + * @throws InvalidDataTypeException |
|
| 375 | + * @throws InvalidInterfaceException |
|
| 376 | + */ |
|
| 377 | + public function add_newsletter_action_buttons(EE_Admin_List_Table $list_table) |
|
| 378 | + { |
|
| 379 | + if (! EE_Registry::instance()->CAP->current_user_can( |
|
| 380 | + 'ee_send_message', |
|
| 381 | + 'espresso_registrations_newsletter_selected_send' |
|
| 382 | + ) |
|
| 383 | + ) { |
|
| 384 | + return; |
|
| 385 | + } |
|
| 386 | + $routes_to_add_to = array( |
|
| 387 | + 'contact_list', |
|
| 388 | + 'event_registrations', |
|
| 389 | + 'default', |
|
| 390 | + ); |
|
| 391 | + if ($this->_current_page === 'espresso_registrations' && in_array($this->_req_action, $routes_to_add_to)) { |
|
| 392 | + if (($this->_req_action === 'event_registrations' && empty($this->_req_data['event_id'])) |
|
| 393 | + || (isset($this->_req_data['status']) && $this->_req_data['status'] === 'trash') |
|
| 394 | + ) { |
|
| 395 | + echo ''; |
|
| 396 | + } else { |
|
| 397 | + $button_text = sprintf( |
|
| 398 | + esc_html__('Send Batch Message (%s selected)', 'event_espresso'), |
|
| 399 | + '<span class="send-selected-newsletter-count">0</span>' |
|
| 400 | + ); |
|
| 401 | + echo '<button id="selected-batch-send-trigger" class="button secondary-button">' |
|
| 402 | + . '<span class="dashicons dashicons-email "></span>' |
|
| 403 | + . $button_text |
|
| 404 | + . '</button>'; |
|
| 405 | + add_action('admin_footer', array($this, 'newsletter_send_form_skeleton')); |
|
| 406 | + } |
|
| 407 | + } |
|
| 408 | + } |
|
| 409 | 409 | |
| 410 | 410 | |
| 411 | - /** |
|
| 412 | - * @throws DomainException |
|
| 413 | - * @throws EE_Error |
|
| 414 | - * @throws InvalidArgumentException |
|
| 415 | - * @throws InvalidDataTypeException |
|
| 416 | - * @throws InvalidInterfaceException |
|
| 417 | - */ |
|
| 418 | - public function newsletter_send_form_skeleton() |
|
| 419 | - { |
|
| 420 | - $list_table = $this->_list_table_object; |
|
| 421 | - $codes = array(); |
|
| 422 | - // need to templates for the newsletter message type for the template selector. |
|
| 423 | - $values[] = array('text' => esc_html__('Select Template to Use', 'event_espresso'), 'id' => 0); |
|
| 424 | - $mtps = EEM_Message_Template_Group::instance()->get_all( |
|
| 425 | - array(array('MTP_message_type' => 'newsletter', 'MTP_messenger' => 'email')) |
|
| 426 | - ); |
|
| 427 | - foreach ($mtps as $mtp) { |
|
| 428 | - $name = $mtp->name(); |
|
| 429 | - $values[] = array( |
|
| 430 | - 'text' => empty($name) ? esc_html__('Global', 'event_espresso') : $name, |
|
| 431 | - 'id' => $mtp->ID(), |
|
| 432 | - ); |
|
| 433 | - } |
|
| 434 | - // need to get a list of shortcodes that are available for the newsletter message type. |
|
| 435 | - $shortcodes = EEH_MSG_Template::get_shortcodes( |
|
| 436 | - 'newsletter', |
|
| 437 | - 'email', |
|
| 438 | - array(), |
|
| 439 | - 'attendee', |
|
| 440 | - false |
|
| 441 | - ); |
|
| 442 | - foreach ($shortcodes as $field => $shortcode_array) { |
|
| 443 | - $available_shortcodes = array(); |
|
| 444 | - foreach ($shortcode_array as $shortcode => $shortcode_details) { |
|
| 445 | - $field_id = $field === '[NEWSLETTER_CONTENT]' |
|
| 446 | - ? 'content' |
|
| 447 | - : $field; |
|
| 448 | - $field_id = 'batch-message-' . strtolower($field_id); |
|
| 449 | - $available_shortcodes[] = '<span class="js-shortcode-selection" data-value="' |
|
| 450 | - . $shortcode |
|
| 451 | - . '" data-linked-input-id="' . $field_id . '">' |
|
| 452 | - . $shortcode |
|
| 453 | - . '</span>'; |
|
| 454 | - } |
|
| 455 | - $codes[ $field ] = implode(', ', $available_shortcodes); |
|
| 456 | - } |
|
| 457 | - $shortcodes = $codes; |
|
| 458 | - $form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php'; |
|
| 459 | - $form_template_args = array( |
|
| 460 | - 'form_action' => admin_url('admin.php?page=espresso_registrations'), |
|
| 461 | - 'form_route' => 'newsletter_selected_send', |
|
| 462 | - 'form_nonce_name' => 'newsletter_selected_send_nonce', |
|
| 463 | - 'form_nonce' => wp_create_nonce('newsletter_selected_send_nonce'), |
|
| 464 | - 'redirect_back_to' => $this->_req_action, |
|
| 465 | - 'ajax_nonce' => wp_create_nonce('get_newsletter_form_content_nonce'), |
|
| 466 | - 'template_selector' => EEH_Form_Fields::select_input('newsletter_mtp_selected', $values), |
|
| 467 | - 'shortcodes' => $shortcodes, |
|
| 468 | - 'id_type' => $list_table instanceof EE_Attendee_Contact_List_Table ? 'contact' : 'registration', |
|
| 469 | - ); |
|
| 470 | - EEH_Template::display_template($form_template, $form_template_args); |
|
| 471 | - } |
|
| 411 | + /** |
|
| 412 | + * @throws DomainException |
|
| 413 | + * @throws EE_Error |
|
| 414 | + * @throws InvalidArgumentException |
|
| 415 | + * @throws InvalidDataTypeException |
|
| 416 | + * @throws InvalidInterfaceException |
|
| 417 | + */ |
|
| 418 | + public function newsletter_send_form_skeleton() |
|
| 419 | + { |
|
| 420 | + $list_table = $this->_list_table_object; |
|
| 421 | + $codes = array(); |
|
| 422 | + // need to templates for the newsletter message type for the template selector. |
|
| 423 | + $values[] = array('text' => esc_html__('Select Template to Use', 'event_espresso'), 'id' => 0); |
|
| 424 | + $mtps = EEM_Message_Template_Group::instance()->get_all( |
|
| 425 | + array(array('MTP_message_type' => 'newsletter', 'MTP_messenger' => 'email')) |
|
| 426 | + ); |
|
| 427 | + foreach ($mtps as $mtp) { |
|
| 428 | + $name = $mtp->name(); |
|
| 429 | + $values[] = array( |
|
| 430 | + 'text' => empty($name) ? esc_html__('Global', 'event_espresso') : $name, |
|
| 431 | + 'id' => $mtp->ID(), |
|
| 432 | + ); |
|
| 433 | + } |
|
| 434 | + // need to get a list of shortcodes that are available for the newsletter message type. |
|
| 435 | + $shortcodes = EEH_MSG_Template::get_shortcodes( |
|
| 436 | + 'newsletter', |
|
| 437 | + 'email', |
|
| 438 | + array(), |
|
| 439 | + 'attendee', |
|
| 440 | + false |
|
| 441 | + ); |
|
| 442 | + foreach ($shortcodes as $field => $shortcode_array) { |
|
| 443 | + $available_shortcodes = array(); |
|
| 444 | + foreach ($shortcode_array as $shortcode => $shortcode_details) { |
|
| 445 | + $field_id = $field === '[NEWSLETTER_CONTENT]' |
|
| 446 | + ? 'content' |
|
| 447 | + : $field; |
|
| 448 | + $field_id = 'batch-message-' . strtolower($field_id); |
|
| 449 | + $available_shortcodes[] = '<span class="js-shortcode-selection" data-value="' |
|
| 450 | + . $shortcode |
|
| 451 | + . '" data-linked-input-id="' . $field_id . '">' |
|
| 452 | + . $shortcode |
|
| 453 | + . '</span>'; |
|
| 454 | + } |
|
| 455 | + $codes[ $field ] = implode(', ', $available_shortcodes); |
|
| 456 | + } |
|
| 457 | + $shortcodes = $codes; |
|
| 458 | + $form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php'; |
|
| 459 | + $form_template_args = array( |
|
| 460 | + 'form_action' => admin_url('admin.php?page=espresso_registrations'), |
|
| 461 | + 'form_route' => 'newsletter_selected_send', |
|
| 462 | + 'form_nonce_name' => 'newsletter_selected_send_nonce', |
|
| 463 | + 'form_nonce' => wp_create_nonce('newsletter_selected_send_nonce'), |
|
| 464 | + 'redirect_back_to' => $this->_req_action, |
|
| 465 | + 'ajax_nonce' => wp_create_nonce('get_newsletter_form_content_nonce'), |
|
| 466 | + 'template_selector' => EEH_Form_Fields::select_input('newsletter_mtp_selected', $values), |
|
| 467 | + 'shortcodes' => $shortcodes, |
|
| 468 | + 'id_type' => $list_table instanceof EE_Attendee_Contact_List_Table ? 'contact' : 'registration', |
|
| 469 | + ); |
|
| 470 | + EEH_Template::display_template($form_template, $form_template_args); |
|
| 471 | + } |
|
| 472 | 472 | |
| 473 | 473 | |
| 474 | - /** |
|
| 475 | - * Handles sending selected registrations/contacts a newsletter. |
|
| 476 | - * |
|
| 477 | - * @since 4.3.0 |
|
| 478 | - * @return void |
|
| 479 | - * @throws EE_Error |
|
| 480 | - * @throws InvalidArgumentException |
|
| 481 | - * @throws InvalidDataTypeException |
|
| 482 | - * @throws InvalidInterfaceException |
|
| 483 | - */ |
|
| 484 | - protected function _newsletter_selected_send() |
|
| 485 | - { |
|
| 486 | - $success = true; |
|
| 487 | - // first we need to make sure we have a GRP_ID so we know what template we're sending and updating! |
|
| 488 | - if (empty($this->_req_data['newsletter_mtp_selected'])) { |
|
| 489 | - EE_Error::add_error( |
|
| 490 | - esc_html__( |
|
| 491 | - 'In order to send a message, a Message Template GRP_ID is needed. It was not provided so messages were not sent.', |
|
| 492 | - 'event_espresso' |
|
| 493 | - ), |
|
| 494 | - __FILE__, |
|
| 495 | - __FUNCTION__, |
|
| 496 | - __LINE__ |
|
| 497 | - ); |
|
| 498 | - $success = false; |
|
| 499 | - } |
|
| 500 | - if ($success) { |
|
| 501 | - // update Message template in case there are any changes |
|
| 502 | - $Message_Template_Group = EEM_Message_Template_Group::instance()->get_one_by_ID( |
|
| 503 | - $this->_req_data['newsletter_mtp_selected'] |
|
| 504 | - ); |
|
| 505 | - $Message_Templates = $Message_Template_Group instanceof EE_Message_Template_Group |
|
| 506 | - ? $Message_Template_Group->context_templates() |
|
| 507 | - : array(); |
|
| 508 | - if (empty($Message_Templates)) { |
|
| 509 | - EE_Error::add_error( |
|
| 510 | - esc_html__( |
|
| 511 | - 'Unable to retrieve message template fields from the db. Messages not sent.', |
|
| 512 | - 'event_espresso' |
|
| 513 | - ), |
|
| 514 | - __FILE__, |
|
| 515 | - __FUNCTION__, |
|
| 516 | - __LINE__ |
|
| 517 | - ); |
|
| 518 | - } |
|
| 519 | - // let's just update the specific fields |
|
| 520 | - foreach ($Message_Templates['attendee'] as $Message_Template) { |
|
| 521 | - if ($Message_Template instanceof EE_Message_Template) { |
|
| 522 | - $field = $Message_Template->get('MTP_template_field'); |
|
| 523 | - $content = $Message_Template->get('MTP_content'); |
|
| 524 | - $new_content = $content; |
|
| 525 | - switch ($field) { |
|
| 526 | - case 'from': |
|
| 527 | - $new_content = ! empty($this->_req_data['batch_message']['from']) |
|
| 528 | - ? $this->_req_data['batch_message']['from'] |
|
| 529 | - : $content; |
|
| 530 | - break; |
|
| 531 | - case 'subject': |
|
| 532 | - $new_content = ! empty($this->_req_data['batch_message']['subject']) |
|
| 533 | - ? $this->_req_data['batch_message']['subject'] |
|
| 534 | - : $content; |
|
| 535 | - break; |
|
| 536 | - case 'content': |
|
| 537 | - $new_content = $content; |
|
| 538 | - $new_content['newsletter_content'] = ! empty($this->_req_data['batch_message']['content']) |
|
| 539 | - ? $this->_req_data['batch_message']['content'] |
|
| 540 | - : $content['newsletter_content']; |
|
| 541 | - break; |
|
| 542 | - default: |
|
| 543 | - // continue the foreach loop, we don't want to set $new_content nor save. |
|
| 544 | - continue 2; |
|
| 545 | - } |
|
| 546 | - $Message_Template->set('MTP_content', $new_content); |
|
| 547 | - $Message_Template->save(); |
|
| 548 | - } |
|
| 549 | - } |
|
| 550 | - // great fields are updated! now let's make sure we just have contact objects (EE_Attendee). |
|
| 551 | - $id_type = ! empty($this->_req_data['batch_message']['id_type']) |
|
| 552 | - ? $this->_req_data['batch_message']['id_type'] |
|
| 553 | - : 'registration'; |
|
| 554 | - // id_type will affect how we assemble the ids. |
|
| 555 | - $ids = ! empty($this->_req_data['batch_message']['ids']) |
|
| 556 | - ? json_decode(stripslashes($this->_req_data['batch_message']['ids'])) |
|
| 557 | - : array(); |
|
| 558 | - $registrations_used_for_contact_data = array(); |
|
| 559 | - // using switch because eventually we'll have other contexts that will be used for generating messages. |
|
| 560 | - switch ($id_type) { |
|
| 561 | - case 'registration': |
|
| 562 | - $registrations_used_for_contact_data = EEM_Registration::instance()->get_all( |
|
| 563 | - array( |
|
| 564 | - array( |
|
| 565 | - 'REG_ID' => array('IN', $ids), |
|
| 566 | - ), |
|
| 567 | - ) |
|
| 568 | - ); |
|
| 569 | - break; |
|
| 570 | - case 'contact': |
|
| 571 | - $registrations_used_for_contact_data = EEM_Registration::instance() |
|
| 572 | - ->get_latest_registration_for_each_of_given_contacts( |
|
| 573 | - $ids |
|
| 574 | - ); |
|
| 575 | - break; |
|
| 576 | - } |
|
| 577 | - do_action_ref_array( |
|
| 578 | - 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
| 579 | - array( |
|
| 580 | - $registrations_used_for_contact_data, |
|
| 581 | - $Message_Template_Group->ID(), |
|
| 582 | - ) |
|
| 583 | - ); |
|
| 584 | - // kept for backward compat, internally we no longer use this action. |
|
| 585 | - // @deprecated 4.8.36.rc.002 |
|
| 586 | - $contacts = $id_type === 'registration' |
|
| 587 | - ? EEM_Attendee::instance()->get_array_of_contacts_from_reg_ids($ids) |
|
| 588 | - : EEM_Attendee::instance()->get_all(array(array('ATT_ID' => array('in', $ids)))); |
|
| 589 | - do_action_ref_array( |
|
| 590 | - 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send', |
|
| 591 | - array( |
|
| 592 | - $contacts, |
|
| 593 | - $Message_Template_Group->ID(), |
|
| 594 | - ) |
|
| 595 | - ); |
|
| 596 | - } |
|
| 597 | - $query_args = array( |
|
| 598 | - 'action' => ! empty($this->_req_data['redirect_back_to']) |
|
| 599 | - ? $this->_req_data['redirect_back_to'] |
|
| 600 | - : 'default', |
|
| 601 | - ); |
|
| 602 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 603 | - } |
|
| 474 | + /** |
|
| 475 | + * Handles sending selected registrations/contacts a newsletter. |
|
| 476 | + * |
|
| 477 | + * @since 4.3.0 |
|
| 478 | + * @return void |
|
| 479 | + * @throws EE_Error |
|
| 480 | + * @throws InvalidArgumentException |
|
| 481 | + * @throws InvalidDataTypeException |
|
| 482 | + * @throws InvalidInterfaceException |
|
| 483 | + */ |
|
| 484 | + protected function _newsletter_selected_send() |
|
| 485 | + { |
|
| 486 | + $success = true; |
|
| 487 | + // first we need to make sure we have a GRP_ID so we know what template we're sending and updating! |
|
| 488 | + if (empty($this->_req_data['newsletter_mtp_selected'])) { |
|
| 489 | + EE_Error::add_error( |
|
| 490 | + esc_html__( |
|
| 491 | + 'In order to send a message, a Message Template GRP_ID is needed. It was not provided so messages were not sent.', |
|
| 492 | + 'event_espresso' |
|
| 493 | + ), |
|
| 494 | + __FILE__, |
|
| 495 | + __FUNCTION__, |
|
| 496 | + __LINE__ |
|
| 497 | + ); |
|
| 498 | + $success = false; |
|
| 499 | + } |
|
| 500 | + if ($success) { |
|
| 501 | + // update Message template in case there are any changes |
|
| 502 | + $Message_Template_Group = EEM_Message_Template_Group::instance()->get_one_by_ID( |
|
| 503 | + $this->_req_data['newsletter_mtp_selected'] |
|
| 504 | + ); |
|
| 505 | + $Message_Templates = $Message_Template_Group instanceof EE_Message_Template_Group |
|
| 506 | + ? $Message_Template_Group->context_templates() |
|
| 507 | + : array(); |
|
| 508 | + if (empty($Message_Templates)) { |
|
| 509 | + EE_Error::add_error( |
|
| 510 | + esc_html__( |
|
| 511 | + 'Unable to retrieve message template fields from the db. Messages not sent.', |
|
| 512 | + 'event_espresso' |
|
| 513 | + ), |
|
| 514 | + __FILE__, |
|
| 515 | + __FUNCTION__, |
|
| 516 | + __LINE__ |
|
| 517 | + ); |
|
| 518 | + } |
|
| 519 | + // let's just update the specific fields |
|
| 520 | + foreach ($Message_Templates['attendee'] as $Message_Template) { |
|
| 521 | + if ($Message_Template instanceof EE_Message_Template) { |
|
| 522 | + $field = $Message_Template->get('MTP_template_field'); |
|
| 523 | + $content = $Message_Template->get('MTP_content'); |
|
| 524 | + $new_content = $content; |
|
| 525 | + switch ($field) { |
|
| 526 | + case 'from': |
|
| 527 | + $new_content = ! empty($this->_req_data['batch_message']['from']) |
|
| 528 | + ? $this->_req_data['batch_message']['from'] |
|
| 529 | + : $content; |
|
| 530 | + break; |
|
| 531 | + case 'subject': |
|
| 532 | + $new_content = ! empty($this->_req_data['batch_message']['subject']) |
|
| 533 | + ? $this->_req_data['batch_message']['subject'] |
|
| 534 | + : $content; |
|
| 535 | + break; |
|
| 536 | + case 'content': |
|
| 537 | + $new_content = $content; |
|
| 538 | + $new_content['newsletter_content'] = ! empty($this->_req_data['batch_message']['content']) |
|
| 539 | + ? $this->_req_data['batch_message']['content'] |
|
| 540 | + : $content['newsletter_content']; |
|
| 541 | + break; |
|
| 542 | + default: |
|
| 543 | + // continue the foreach loop, we don't want to set $new_content nor save. |
|
| 544 | + continue 2; |
|
| 545 | + } |
|
| 546 | + $Message_Template->set('MTP_content', $new_content); |
|
| 547 | + $Message_Template->save(); |
|
| 548 | + } |
|
| 549 | + } |
|
| 550 | + // great fields are updated! now let's make sure we just have contact objects (EE_Attendee). |
|
| 551 | + $id_type = ! empty($this->_req_data['batch_message']['id_type']) |
|
| 552 | + ? $this->_req_data['batch_message']['id_type'] |
|
| 553 | + : 'registration'; |
|
| 554 | + // id_type will affect how we assemble the ids. |
|
| 555 | + $ids = ! empty($this->_req_data['batch_message']['ids']) |
|
| 556 | + ? json_decode(stripslashes($this->_req_data['batch_message']['ids'])) |
|
| 557 | + : array(); |
|
| 558 | + $registrations_used_for_contact_data = array(); |
|
| 559 | + // using switch because eventually we'll have other contexts that will be used for generating messages. |
|
| 560 | + switch ($id_type) { |
|
| 561 | + case 'registration': |
|
| 562 | + $registrations_used_for_contact_data = EEM_Registration::instance()->get_all( |
|
| 563 | + array( |
|
| 564 | + array( |
|
| 565 | + 'REG_ID' => array('IN', $ids), |
|
| 566 | + ), |
|
| 567 | + ) |
|
| 568 | + ); |
|
| 569 | + break; |
|
| 570 | + case 'contact': |
|
| 571 | + $registrations_used_for_contact_data = EEM_Registration::instance() |
|
| 572 | + ->get_latest_registration_for_each_of_given_contacts( |
|
| 573 | + $ids |
|
| 574 | + ); |
|
| 575 | + break; |
|
| 576 | + } |
|
| 577 | + do_action_ref_array( |
|
| 578 | + 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
| 579 | + array( |
|
| 580 | + $registrations_used_for_contact_data, |
|
| 581 | + $Message_Template_Group->ID(), |
|
| 582 | + ) |
|
| 583 | + ); |
|
| 584 | + // kept for backward compat, internally we no longer use this action. |
|
| 585 | + // @deprecated 4.8.36.rc.002 |
|
| 586 | + $contacts = $id_type === 'registration' |
|
| 587 | + ? EEM_Attendee::instance()->get_array_of_contacts_from_reg_ids($ids) |
|
| 588 | + : EEM_Attendee::instance()->get_all(array(array('ATT_ID' => array('in', $ids)))); |
|
| 589 | + do_action_ref_array( |
|
| 590 | + 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send', |
|
| 591 | + array( |
|
| 592 | + $contacts, |
|
| 593 | + $Message_Template_Group->ID(), |
|
| 594 | + ) |
|
| 595 | + ); |
|
| 596 | + } |
|
| 597 | + $query_args = array( |
|
| 598 | + 'action' => ! empty($this->_req_data['redirect_back_to']) |
|
| 599 | + ? $this->_req_data['redirect_back_to'] |
|
| 600 | + : 'default', |
|
| 601 | + ); |
|
| 602 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 603 | + } |
|
| 604 | 604 | |
| 605 | 605 | |
| 606 | - /** |
|
| 607 | - * This is called when javascript is being enqueued to setup the various data needed for the reports js. |
|
| 608 | - * Also $this->{$_reports_template_data} property is set for later usage by the _registration_reports method. |
|
| 609 | - */ |
|
| 610 | - protected function _registration_reports_js_setup() |
|
| 611 | - { |
|
| 612 | - $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_day_report(); |
|
| 613 | - $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_event_report(); |
|
| 614 | - } |
|
| 606 | + /** |
|
| 607 | + * This is called when javascript is being enqueued to setup the various data needed for the reports js. |
|
| 608 | + * Also $this->{$_reports_template_data} property is set for later usage by the _registration_reports method. |
|
| 609 | + */ |
|
| 610 | + protected function _registration_reports_js_setup() |
|
| 611 | + { |
|
| 612 | + $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_day_report(); |
|
| 613 | + $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_event_report(); |
|
| 614 | + } |
|
| 615 | 615 | |
| 616 | 616 | |
| 617 | - /** |
|
| 618 | - * generates Business Reports regarding Registrations |
|
| 619 | - * |
|
| 620 | - * @access protected |
|
| 621 | - * @return void |
|
| 622 | - * @throws DomainException |
|
| 623 | - */ |
|
| 624 | - protected function _registration_reports() |
|
| 625 | - { |
|
| 626 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php'; |
|
| 627 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 628 | - $template_path, |
|
| 629 | - $this->_reports_template_data, |
|
| 630 | - true |
|
| 631 | - ); |
|
| 632 | - // the final template wrapper |
|
| 633 | - $this->display_admin_page_with_no_sidebar(); |
|
| 634 | - } |
|
| 617 | + /** |
|
| 618 | + * generates Business Reports regarding Registrations |
|
| 619 | + * |
|
| 620 | + * @access protected |
|
| 621 | + * @return void |
|
| 622 | + * @throws DomainException |
|
| 623 | + */ |
|
| 624 | + protected function _registration_reports() |
|
| 625 | + { |
|
| 626 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php'; |
|
| 627 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 628 | + $template_path, |
|
| 629 | + $this->_reports_template_data, |
|
| 630 | + true |
|
| 631 | + ); |
|
| 632 | + // the final template wrapper |
|
| 633 | + $this->display_admin_page_with_no_sidebar(); |
|
| 634 | + } |
|
| 635 | 635 | |
| 636 | 636 | |
| 637 | - /** |
|
| 638 | - * Generates Business Report showing total registrations per day. |
|
| 639 | - * |
|
| 640 | - * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
| 641 | - * @return string |
|
| 642 | - * @throws EE_Error |
|
| 643 | - * @throws InvalidArgumentException |
|
| 644 | - * @throws InvalidDataTypeException |
|
| 645 | - * @throws InvalidInterfaceException |
|
| 646 | - */ |
|
| 647 | - private function _registrations_per_day_report($period = '-1 month') |
|
| 648 | - { |
|
| 649 | - $report_ID = 'reg-admin-registrations-per-day-report-dv'; |
|
| 650 | - $results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report($period); |
|
| 651 | - $results = (array) $results; |
|
| 652 | - $regs = array(); |
|
| 653 | - $subtitle = ''; |
|
| 654 | - if ($results) { |
|
| 655 | - $column_titles = array(); |
|
| 656 | - $tracker = 0; |
|
| 657 | - foreach ($results as $result) { |
|
| 658 | - $report_column_values = array(); |
|
| 659 | - foreach ($result as $property_name => $property_value) { |
|
| 660 | - $property_value = $property_name === 'Registration_REG_date' ? $property_value |
|
| 661 | - : (int) $property_value; |
|
| 662 | - $report_column_values[] = $property_value; |
|
| 663 | - if ($tracker === 0) { |
|
| 664 | - if ($property_name === 'Registration_REG_date') { |
|
| 665 | - $column_titles[] = esc_html__( |
|
| 666 | - 'Date (only days with registrations are shown)', |
|
| 667 | - 'event_espresso' |
|
| 668 | - ); |
|
| 669 | - } else { |
|
| 670 | - $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence'); |
|
| 671 | - } |
|
| 672 | - } |
|
| 673 | - } |
|
| 674 | - $tracker++; |
|
| 675 | - $regs[] = $report_column_values; |
|
| 676 | - } |
|
| 677 | - // make sure the column_titles is pushed to the beginning of the array |
|
| 678 | - array_unshift($regs, $column_titles); |
|
| 679 | - // setup the date range. |
|
| 680 | - $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
|
| 681 | - $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
| 682 | - $ending_date = new DateTime("now", $DateTimeZone); |
|
| 683 | - $subtitle = sprintf( |
|
| 684 | - _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'), |
|
| 685 | - $beginning_date->format('Y-m-d'), |
|
| 686 | - $ending_date->format('Y-m-d') |
|
| 687 | - ); |
|
| 688 | - } |
|
| 689 | - $report_title = esc_html__('Total Registrations per Day', 'event_espresso'); |
|
| 690 | - $report_params = array( |
|
| 691 | - 'title' => $report_title, |
|
| 692 | - 'subtitle' => $subtitle, |
|
| 693 | - 'id' => $report_ID, |
|
| 694 | - 'regs' => $regs, |
|
| 695 | - 'noResults' => empty($regs), |
|
| 696 | - 'noRegsMsg' => sprintf( |
|
| 697 | - esc_html__( |
|
| 698 | - '%sThere are currently no registration records in the last month for this report.%s', |
|
| 699 | - 'event_espresso' |
|
| 700 | - ), |
|
| 701 | - '<h2>' . $report_title . '</h2><p>', |
|
| 702 | - '</p>' |
|
| 703 | - ), |
|
| 704 | - ); |
|
| 705 | - wp_localize_script('ee-reg-reports-js', 'regPerDay', $report_params); |
|
| 706 | - return $report_ID; |
|
| 707 | - } |
|
| 637 | + /** |
|
| 638 | + * Generates Business Report showing total registrations per day. |
|
| 639 | + * |
|
| 640 | + * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
| 641 | + * @return string |
|
| 642 | + * @throws EE_Error |
|
| 643 | + * @throws InvalidArgumentException |
|
| 644 | + * @throws InvalidDataTypeException |
|
| 645 | + * @throws InvalidInterfaceException |
|
| 646 | + */ |
|
| 647 | + private function _registrations_per_day_report($period = '-1 month') |
|
| 648 | + { |
|
| 649 | + $report_ID = 'reg-admin-registrations-per-day-report-dv'; |
|
| 650 | + $results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report($period); |
|
| 651 | + $results = (array) $results; |
|
| 652 | + $regs = array(); |
|
| 653 | + $subtitle = ''; |
|
| 654 | + if ($results) { |
|
| 655 | + $column_titles = array(); |
|
| 656 | + $tracker = 0; |
|
| 657 | + foreach ($results as $result) { |
|
| 658 | + $report_column_values = array(); |
|
| 659 | + foreach ($result as $property_name => $property_value) { |
|
| 660 | + $property_value = $property_name === 'Registration_REG_date' ? $property_value |
|
| 661 | + : (int) $property_value; |
|
| 662 | + $report_column_values[] = $property_value; |
|
| 663 | + if ($tracker === 0) { |
|
| 664 | + if ($property_name === 'Registration_REG_date') { |
|
| 665 | + $column_titles[] = esc_html__( |
|
| 666 | + 'Date (only days with registrations are shown)', |
|
| 667 | + 'event_espresso' |
|
| 668 | + ); |
|
| 669 | + } else { |
|
| 670 | + $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence'); |
|
| 671 | + } |
|
| 672 | + } |
|
| 673 | + } |
|
| 674 | + $tracker++; |
|
| 675 | + $regs[] = $report_column_values; |
|
| 676 | + } |
|
| 677 | + // make sure the column_titles is pushed to the beginning of the array |
|
| 678 | + array_unshift($regs, $column_titles); |
|
| 679 | + // setup the date range. |
|
| 680 | + $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
|
| 681 | + $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
| 682 | + $ending_date = new DateTime("now", $DateTimeZone); |
|
| 683 | + $subtitle = sprintf( |
|
| 684 | + _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'), |
|
| 685 | + $beginning_date->format('Y-m-d'), |
|
| 686 | + $ending_date->format('Y-m-d') |
|
| 687 | + ); |
|
| 688 | + } |
|
| 689 | + $report_title = esc_html__('Total Registrations per Day', 'event_espresso'); |
|
| 690 | + $report_params = array( |
|
| 691 | + 'title' => $report_title, |
|
| 692 | + 'subtitle' => $subtitle, |
|
| 693 | + 'id' => $report_ID, |
|
| 694 | + 'regs' => $regs, |
|
| 695 | + 'noResults' => empty($regs), |
|
| 696 | + 'noRegsMsg' => sprintf( |
|
| 697 | + esc_html__( |
|
| 698 | + '%sThere are currently no registration records in the last month for this report.%s', |
|
| 699 | + 'event_espresso' |
|
| 700 | + ), |
|
| 701 | + '<h2>' . $report_title . '</h2><p>', |
|
| 702 | + '</p>' |
|
| 703 | + ), |
|
| 704 | + ); |
|
| 705 | + wp_localize_script('ee-reg-reports-js', 'regPerDay', $report_params); |
|
| 706 | + return $report_ID; |
|
| 707 | + } |
|
| 708 | 708 | |
| 709 | 709 | |
| 710 | - /** |
|
| 711 | - * Generates Business Report showing total registrations per event. |
|
| 712 | - * |
|
| 713 | - * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
| 714 | - * @return string |
|
| 715 | - * @throws EE_Error |
|
| 716 | - * @throws InvalidArgumentException |
|
| 717 | - * @throws InvalidDataTypeException |
|
| 718 | - * @throws InvalidInterfaceException |
|
| 719 | - */ |
|
| 720 | - private function _registrations_per_event_report($period = '-1 month') |
|
| 721 | - { |
|
| 722 | - $report_ID = 'reg-admin-registrations-per-event-report-dv'; |
|
| 723 | - $results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report($period); |
|
| 724 | - $results = (array) $results; |
|
| 725 | - $regs = array(); |
|
| 726 | - $subtitle = ''; |
|
| 727 | - if ($results) { |
|
| 728 | - $column_titles = array(); |
|
| 729 | - $tracker = 0; |
|
| 730 | - foreach ($results as $result) { |
|
| 731 | - $report_column_values = array(); |
|
| 732 | - foreach ($result as $property_name => $property_value) { |
|
| 733 | - $property_value = $property_name === 'Registration_Event' ? wp_trim_words( |
|
| 734 | - $property_value, |
|
| 735 | - 4, |
|
| 736 | - '...' |
|
| 737 | - ) : (int) $property_value; |
|
| 738 | - $report_column_values[] = $property_value; |
|
| 739 | - if ($tracker === 0) { |
|
| 740 | - if ($property_name === 'Registration_Event') { |
|
| 741 | - $column_titles[] = esc_html__('Event', 'event_espresso'); |
|
| 742 | - } else { |
|
| 743 | - $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence'); |
|
| 744 | - } |
|
| 745 | - } |
|
| 746 | - } |
|
| 747 | - $tracker++; |
|
| 748 | - $regs[] = $report_column_values; |
|
| 749 | - } |
|
| 750 | - // make sure the column_titles is pushed to the beginning of the array |
|
| 751 | - array_unshift($regs, $column_titles); |
|
| 752 | - // setup the date range. |
|
| 753 | - $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
|
| 754 | - $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
| 755 | - $ending_date = new DateTime("now", $DateTimeZone); |
|
| 756 | - $subtitle = sprintf( |
|
| 757 | - _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'), |
|
| 758 | - $beginning_date->format('Y-m-d'), |
|
| 759 | - $ending_date->format('Y-m-d') |
|
| 760 | - ); |
|
| 761 | - } |
|
| 762 | - $report_title = esc_html__('Total Registrations per Event', 'event_espresso'); |
|
| 763 | - $report_params = array( |
|
| 764 | - 'title' => $report_title, |
|
| 765 | - 'subtitle' => $subtitle, |
|
| 766 | - 'id' => $report_ID, |
|
| 767 | - 'regs' => $regs, |
|
| 768 | - 'noResults' => empty($regs), |
|
| 769 | - 'noRegsMsg' => sprintf( |
|
| 770 | - esc_html__( |
|
| 771 | - '%sThere are currently no registration records in the last month for this report.%s', |
|
| 772 | - 'event_espresso' |
|
| 773 | - ), |
|
| 774 | - '<h2>' . $report_title . '</h2><p>', |
|
| 775 | - '</p>' |
|
| 776 | - ), |
|
| 777 | - ); |
|
| 778 | - wp_localize_script('ee-reg-reports-js', 'regPerEvent', $report_params); |
|
| 779 | - return $report_ID; |
|
| 780 | - } |
|
| 710 | + /** |
|
| 711 | + * Generates Business Report showing total registrations per event. |
|
| 712 | + * |
|
| 713 | + * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
| 714 | + * @return string |
|
| 715 | + * @throws EE_Error |
|
| 716 | + * @throws InvalidArgumentException |
|
| 717 | + * @throws InvalidDataTypeException |
|
| 718 | + * @throws InvalidInterfaceException |
|
| 719 | + */ |
|
| 720 | + private function _registrations_per_event_report($period = '-1 month') |
|
| 721 | + { |
|
| 722 | + $report_ID = 'reg-admin-registrations-per-event-report-dv'; |
|
| 723 | + $results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report($period); |
|
| 724 | + $results = (array) $results; |
|
| 725 | + $regs = array(); |
|
| 726 | + $subtitle = ''; |
|
| 727 | + if ($results) { |
|
| 728 | + $column_titles = array(); |
|
| 729 | + $tracker = 0; |
|
| 730 | + foreach ($results as $result) { |
|
| 731 | + $report_column_values = array(); |
|
| 732 | + foreach ($result as $property_name => $property_value) { |
|
| 733 | + $property_value = $property_name === 'Registration_Event' ? wp_trim_words( |
|
| 734 | + $property_value, |
|
| 735 | + 4, |
|
| 736 | + '...' |
|
| 737 | + ) : (int) $property_value; |
|
| 738 | + $report_column_values[] = $property_value; |
|
| 739 | + if ($tracker === 0) { |
|
| 740 | + if ($property_name === 'Registration_Event') { |
|
| 741 | + $column_titles[] = esc_html__('Event', 'event_espresso'); |
|
| 742 | + } else { |
|
| 743 | + $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence'); |
|
| 744 | + } |
|
| 745 | + } |
|
| 746 | + } |
|
| 747 | + $tracker++; |
|
| 748 | + $regs[] = $report_column_values; |
|
| 749 | + } |
|
| 750 | + // make sure the column_titles is pushed to the beginning of the array |
|
| 751 | + array_unshift($regs, $column_titles); |
|
| 752 | + // setup the date range. |
|
| 753 | + $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
|
| 754 | + $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
| 755 | + $ending_date = new DateTime("now", $DateTimeZone); |
|
| 756 | + $subtitle = sprintf( |
|
| 757 | + _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'), |
|
| 758 | + $beginning_date->format('Y-m-d'), |
|
| 759 | + $ending_date->format('Y-m-d') |
|
| 760 | + ); |
|
| 761 | + } |
|
| 762 | + $report_title = esc_html__('Total Registrations per Event', 'event_espresso'); |
|
| 763 | + $report_params = array( |
|
| 764 | + 'title' => $report_title, |
|
| 765 | + 'subtitle' => $subtitle, |
|
| 766 | + 'id' => $report_ID, |
|
| 767 | + 'regs' => $regs, |
|
| 768 | + 'noResults' => empty($regs), |
|
| 769 | + 'noRegsMsg' => sprintf( |
|
| 770 | + esc_html__( |
|
| 771 | + '%sThere are currently no registration records in the last month for this report.%s', |
|
| 772 | + 'event_espresso' |
|
| 773 | + ), |
|
| 774 | + '<h2>' . $report_title . '</h2><p>', |
|
| 775 | + '</p>' |
|
| 776 | + ), |
|
| 777 | + ); |
|
| 778 | + wp_localize_script('ee-reg-reports-js', 'regPerEvent', $report_params); |
|
| 779 | + return $report_ID; |
|
| 780 | + } |
|
| 781 | 781 | |
| 782 | 782 | |
| 783 | - /** |
|
| 784 | - * generates HTML for the Registration Check-in list table (showing all Check-ins for a specific registration) |
|
| 785 | - * |
|
| 786 | - * @access protected |
|
| 787 | - * @return void |
|
| 788 | - * @throws EE_Error |
|
| 789 | - * @throws InvalidArgumentException |
|
| 790 | - * @throws InvalidDataTypeException |
|
| 791 | - * @throws InvalidInterfaceException |
|
| 792 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 793 | - */ |
|
| 794 | - protected function _registration_checkin_list_table() |
|
| 795 | - { |
|
| 796 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 797 | - $reg_id = isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : null; |
|
| 798 | - /** @var EE_Registration $registration */ |
|
| 799 | - $registration = EEM_Registration::instance()->get_one_by_ID($reg_id); |
|
| 800 | - if (! $registration instanceof EE_Registration) { |
|
| 801 | - throw new EE_Error( |
|
| 802 | - sprintf( |
|
| 803 | - esc_html__('An error occurred. There is no registration with ID (%d)', 'event_espresso'), |
|
| 804 | - $reg_id |
|
| 805 | - ) |
|
| 806 | - ); |
|
| 807 | - } |
|
| 808 | - $attendee = $registration->attendee(); |
|
| 809 | - $this->_admin_page_title .= $this->get_action_link_or_button( |
|
| 810 | - 'new_registration', |
|
| 811 | - 'add-registrant', |
|
| 812 | - array('event_id' => $registration->event_ID()), |
|
| 813 | - 'add-new-h2' |
|
| 814 | - ); |
|
| 815 | - $checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in); |
|
| 816 | - $checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out); |
|
| 817 | - $legend_items = array( |
|
| 818 | - 'checkin' => array( |
|
| 819 | - 'class' => $checked_in->cssClasses(), |
|
| 820 | - 'desc' => $checked_in->legendLabel(), |
|
| 821 | - ), |
|
| 822 | - 'checkout' => array( |
|
| 823 | - 'class' => $checked_out->cssClasses(), |
|
| 824 | - 'desc' => $checked_out->legendLabel(), |
|
| 825 | - ), |
|
| 826 | - ); |
|
| 827 | - $this->_template_args['after_list_table'] = $this->_display_legend($legend_items); |
|
| 828 | - $dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null; |
|
| 829 | - /** @var EE_Datetime $datetime */ |
|
| 830 | - $datetime = EEM_Datetime::instance()->get_one_by_ID($dtt_id); |
|
| 831 | - $datetime_label = ''; |
|
| 832 | - if ($datetime instanceof EE_Datetime) { |
|
| 833 | - $datetime_label = $datetime->get_dtt_display_name(true); |
|
| 834 | - $datetime_label .= ! empty($datetime_label) |
|
| 835 | - ? ' (' . $datetime->get_dtt_display_name() . ')' |
|
| 836 | - : $datetime->get_dtt_display_name(); |
|
| 837 | - } |
|
| 838 | - $datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration |
|
| 839 | - ? EE_Admin_Page::add_query_args_and_nonce( |
|
| 840 | - array( |
|
| 841 | - 'action' => 'event_registrations', |
|
| 842 | - 'event_id' => $registration->event_ID(), |
|
| 843 | - 'DTT_ID' => $dtt_id, |
|
| 844 | - ), |
|
| 845 | - $this->_admin_base_url |
|
| 846 | - ) |
|
| 847 | - : ''; |
|
| 848 | - $datetime_link = ! empty($datetime_link) |
|
| 849 | - ? '<a href="' . $datetime_link . '">' |
|
| 850 | - . '<span id="checkin-dtt">' |
|
| 851 | - . $datetime_label |
|
| 852 | - . '</span></a>' |
|
| 853 | - : $datetime_label; |
|
| 854 | - $attendee_name = $attendee instanceof EE_Attendee |
|
| 855 | - ? $attendee->full_name() |
|
| 856 | - : ''; |
|
| 857 | - $attendee_link = $attendee instanceof EE_Attendee |
|
| 858 | - ? $attendee->get_admin_details_link() |
|
| 859 | - : ''; |
|
| 860 | - $attendee_link = ! empty($attendee_link) |
|
| 861 | - ? '<a href="' . $attendee->get_admin_details_link() . '"' |
|
| 862 | - . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">' |
|
| 863 | - . '<span id="checkin-attendee-name">' |
|
| 864 | - . $attendee_name |
|
| 865 | - . '</span></a>' |
|
| 866 | - : ''; |
|
| 867 | - $event_link = $registration->event() instanceof EE_Event |
|
| 868 | - ? $registration->event()->get_admin_details_link() |
|
| 869 | - : ''; |
|
| 870 | - $event_link = ! empty($event_link) |
|
| 871 | - ? '<a href="' . $event_link . '"' |
|
| 872 | - . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">' |
|
| 873 | - . '<span id="checkin-event-name">' |
|
| 874 | - . $registration->event_name() |
|
| 875 | - . '</span>' |
|
| 876 | - . '</a>' |
|
| 877 | - : ''; |
|
| 878 | - $this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id) |
|
| 879 | - ? '<h2>' . sprintf( |
|
| 880 | - esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'), |
|
| 881 | - $attendee_link, |
|
| 882 | - $datetime_link, |
|
| 883 | - $event_link |
|
| 884 | - ) . '</h2>' |
|
| 885 | - : ''; |
|
| 886 | - $this->_template_args['list_table_hidden_fields'] = ! empty($reg_id) |
|
| 887 | - ? '<input type="hidden" name="_REG_ID" value="' . $reg_id . '">' : ''; |
|
| 888 | - $this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id) |
|
| 889 | - ? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : ''; |
|
| 890 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 891 | - } |
|
| 783 | + /** |
|
| 784 | + * generates HTML for the Registration Check-in list table (showing all Check-ins for a specific registration) |
|
| 785 | + * |
|
| 786 | + * @access protected |
|
| 787 | + * @return void |
|
| 788 | + * @throws EE_Error |
|
| 789 | + * @throws InvalidArgumentException |
|
| 790 | + * @throws InvalidDataTypeException |
|
| 791 | + * @throws InvalidInterfaceException |
|
| 792 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 793 | + */ |
|
| 794 | + protected function _registration_checkin_list_table() |
|
| 795 | + { |
|
| 796 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 797 | + $reg_id = isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : null; |
|
| 798 | + /** @var EE_Registration $registration */ |
|
| 799 | + $registration = EEM_Registration::instance()->get_one_by_ID($reg_id); |
|
| 800 | + if (! $registration instanceof EE_Registration) { |
|
| 801 | + throw new EE_Error( |
|
| 802 | + sprintf( |
|
| 803 | + esc_html__('An error occurred. There is no registration with ID (%d)', 'event_espresso'), |
|
| 804 | + $reg_id |
|
| 805 | + ) |
|
| 806 | + ); |
|
| 807 | + } |
|
| 808 | + $attendee = $registration->attendee(); |
|
| 809 | + $this->_admin_page_title .= $this->get_action_link_or_button( |
|
| 810 | + 'new_registration', |
|
| 811 | + 'add-registrant', |
|
| 812 | + array('event_id' => $registration->event_ID()), |
|
| 813 | + 'add-new-h2' |
|
| 814 | + ); |
|
| 815 | + $checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in); |
|
| 816 | + $checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out); |
|
| 817 | + $legend_items = array( |
|
| 818 | + 'checkin' => array( |
|
| 819 | + 'class' => $checked_in->cssClasses(), |
|
| 820 | + 'desc' => $checked_in->legendLabel(), |
|
| 821 | + ), |
|
| 822 | + 'checkout' => array( |
|
| 823 | + 'class' => $checked_out->cssClasses(), |
|
| 824 | + 'desc' => $checked_out->legendLabel(), |
|
| 825 | + ), |
|
| 826 | + ); |
|
| 827 | + $this->_template_args['after_list_table'] = $this->_display_legend($legend_items); |
|
| 828 | + $dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null; |
|
| 829 | + /** @var EE_Datetime $datetime */ |
|
| 830 | + $datetime = EEM_Datetime::instance()->get_one_by_ID($dtt_id); |
|
| 831 | + $datetime_label = ''; |
|
| 832 | + if ($datetime instanceof EE_Datetime) { |
|
| 833 | + $datetime_label = $datetime->get_dtt_display_name(true); |
|
| 834 | + $datetime_label .= ! empty($datetime_label) |
|
| 835 | + ? ' (' . $datetime->get_dtt_display_name() . ')' |
|
| 836 | + : $datetime->get_dtt_display_name(); |
|
| 837 | + } |
|
| 838 | + $datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration |
|
| 839 | + ? EE_Admin_Page::add_query_args_and_nonce( |
|
| 840 | + array( |
|
| 841 | + 'action' => 'event_registrations', |
|
| 842 | + 'event_id' => $registration->event_ID(), |
|
| 843 | + 'DTT_ID' => $dtt_id, |
|
| 844 | + ), |
|
| 845 | + $this->_admin_base_url |
|
| 846 | + ) |
|
| 847 | + : ''; |
|
| 848 | + $datetime_link = ! empty($datetime_link) |
|
| 849 | + ? '<a href="' . $datetime_link . '">' |
|
| 850 | + . '<span id="checkin-dtt">' |
|
| 851 | + . $datetime_label |
|
| 852 | + . '</span></a>' |
|
| 853 | + : $datetime_label; |
|
| 854 | + $attendee_name = $attendee instanceof EE_Attendee |
|
| 855 | + ? $attendee->full_name() |
|
| 856 | + : ''; |
|
| 857 | + $attendee_link = $attendee instanceof EE_Attendee |
|
| 858 | + ? $attendee->get_admin_details_link() |
|
| 859 | + : ''; |
|
| 860 | + $attendee_link = ! empty($attendee_link) |
|
| 861 | + ? '<a href="' . $attendee->get_admin_details_link() . '"' |
|
| 862 | + . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">' |
|
| 863 | + . '<span id="checkin-attendee-name">' |
|
| 864 | + . $attendee_name |
|
| 865 | + . '</span></a>' |
|
| 866 | + : ''; |
|
| 867 | + $event_link = $registration->event() instanceof EE_Event |
|
| 868 | + ? $registration->event()->get_admin_details_link() |
|
| 869 | + : ''; |
|
| 870 | + $event_link = ! empty($event_link) |
|
| 871 | + ? '<a href="' . $event_link . '"' |
|
| 872 | + . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">' |
|
| 873 | + . '<span id="checkin-event-name">' |
|
| 874 | + . $registration->event_name() |
|
| 875 | + . '</span>' |
|
| 876 | + . '</a>' |
|
| 877 | + : ''; |
|
| 878 | + $this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id) |
|
| 879 | + ? '<h2>' . sprintf( |
|
| 880 | + esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'), |
|
| 881 | + $attendee_link, |
|
| 882 | + $datetime_link, |
|
| 883 | + $event_link |
|
| 884 | + ) . '</h2>' |
|
| 885 | + : ''; |
|
| 886 | + $this->_template_args['list_table_hidden_fields'] = ! empty($reg_id) |
|
| 887 | + ? '<input type="hidden" name="_REG_ID" value="' . $reg_id . '">' : ''; |
|
| 888 | + $this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id) |
|
| 889 | + ? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : ''; |
|
| 890 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 891 | + } |
|
| 892 | 892 | |
| 893 | 893 | |
| 894 | - /** |
|
| 895 | - * toggle the Check-in status for the given registration (coming from ajax) |
|
| 896 | - * |
|
| 897 | - * @return void (JSON) |
|
| 898 | - * @throws EE_Error |
|
| 899 | - * @throws InvalidArgumentException |
|
| 900 | - * @throws InvalidDataTypeException |
|
| 901 | - * @throws InvalidInterfaceException |
|
| 902 | - */ |
|
| 903 | - public function toggle_checkin_status() |
|
| 904 | - { |
|
| 905 | - // first make sure we have the necessary data |
|
| 906 | - if (! isset($this->_req_data['_regid'])) { |
|
| 907 | - EE_Error::add_error( |
|
| 908 | - esc_html__( |
|
| 909 | - 'There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax', |
|
| 910 | - 'event_espresso' |
|
| 911 | - ), |
|
| 912 | - __FILE__, |
|
| 913 | - __FUNCTION__, |
|
| 914 | - __LINE__ |
|
| 915 | - ); |
|
| 916 | - $this->_template_args['success'] = false; |
|
| 917 | - $this->_template_args['error'] = true; |
|
| 918 | - $this->_return_json(); |
|
| 919 | - }; |
|
| 920 | - // do a nonce check cause we're not coming in from an normal route here. |
|
| 921 | - $nonce = isset($this->_req_data['checkinnonce']) ? sanitize_text_field($this->_req_data['checkinnonce']) |
|
| 922 | - : ''; |
|
| 923 | - $nonce_ref = 'checkin_nonce'; |
|
| 924 | - $this->_verify_nonce($nonce, $nonce_ref); |
|
| 925 | - // beautiful! Made it this far so let's get the status. |
|
| 926 | - $new_status = new CheckinStatusDashicon($this->_toggle_checkin_status()); |
|
| 927 | - // setup new class to return via ajax |
|
| 928 | - $this->_template_args['admin_page_content'] = 'clickable trigger-checkin ' . $new_status->cssClasses(); |
|
| 929 | - $this->_template_args['success'] = true; |
|
| 930 | - $this->_return_json(); |
|
| 931 | - } |
|
| 894 | + /** |
|
| 895 | + * toggle the Check-in status for the given registration (coming from ajax) |
|
| 896 | + * |
|
| 897 | + * @return void (JSON) |
|
| 898 | + * @throws EE_Error |
|
| 899 | + * @throws InvalidArgumentException |
|
| 900 | + * @throws InvalidDataTypeException |
|
| 901 | + * @throws InvalidInterfaceException |
|
| 902 | + */ |
|
| 903 | + public function toggle_checkin_status() |
|
| 904 | + { |
|
| 905 | + // first make sure we have the necessary data |
|
| 906 | + if (! isset($this->_req_data['_regid'])) { |
|
| 907 | + EE_Error::add_error( |
|
| 908 | + esc_html__( |
|
| 909 | + 'There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax', |
|
| 910 | + 'event_espresso' |
|
| 911 | + ), |
|
| 912 | + __FILE__, |
|
| 913 | + __FUNCTION__, |
|
| 914 | + __LINE__ |
|
| 915 | + ); |
|
| 916 | + $this->_template_args['success'] = false; |
|
| 917 | + $this->_template_args['error'] = true; |
|
| 918 | + $this->_return_json(); |
|
| 919 | + }; |
|
| 920 | + // do a nonce check cause we're not coming in from an normal route here. |
|
| 921 | + $nonce = isset($this->_req_data['checkinnonce']) ? sanitize_text_field($this->_req_data['checkinnonce']) |
|
| 922 | + : ''; |
|
| 923 | + $nonce_ref = 'checkin_nonce'; |
|
| 924 | + $this->_verify_nonce($nonce, $nonce_ref); |
|
| 925 | + // beautiful! Made it this far so let's get the status. |
|
| 926 | + $new_status = new CheckinStatusDashicon($this->_toggle_checkin_status()); |
|
| 927 | + // setup new class to return via ajax |
|
| 928 | + $this->_template_args['admin_page_content'] = 'clickable trigger-checkin ' . $new_status->cssClasses(); |
|
| 929 | + $this->_template_args['success'] = true; |
|
| 930 | + $this->_return_json(); |
|
| 931 | + } |
|
| 932 | 932 | |
| 933 | 933 | |
| 934 | - /** |
|
| 935 | - * handles toggling the checkin status for the registration, |
|
| 936 | - * |
|
| 937 | - * @access protected |
|
| 938 | - * @return int|void |
|
| 939 | - * @throws EE_Error |
|
| 940 | - * @throws InvalidArgumentException |
|
| 941 | - * @throws InvalidDataTypeException |
|
| 942 | - * @throws InvalidInterfaceException |
|
| 943 | - */ |
|
| 944 | - protected function _toggle_checkin_status() |
|
| 945 | - { |
|
| 946 | - // first let's get the query args out of the way for the redirect |
|
| 947 | - $query_args = array( |
|
| 948 | - 'action' => 'event_registrations', |
|
| 949 | - 'event_id' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null, |
|
| 950 | - 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null, |
|
| 951 | - ); |
|
| 952 | - $new_status = false; |
|
| 953 | - // bulk action check in toggle |
|
| 954 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 955 | - // cycle thru checkboxes |
|
| 956 | - while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 957 | - $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null; |
|
| 958 | - $new_status = $this->_toggle_checkin($REG_ID, $DTT_ID); |
|
| 959 | - } |
|
| 960 | - } elseif (isset($this->_req_data['_regid'])) { |
|
| 961 | - // coming from ajax request |
|
| 962 | - $DTT_ID = isset($this->_req_data['dttid']) ? $this->_req_data['dttid'] : null; |
|
| 963 | - $query_args['DTT_ID'] = $DTT_ID; |
|
| 964 | - $new_status = $this->_toggle_checkin($this->_req_data['_regid'], $DTT_ID); |
|
| 965 | - } else { |
|
| 966 | - EE_Error::add_error( |
|
| 967 | - esc_html__('Missing some required data to toggle the Check-in', 'event_espresso'), |
|
| 968 | - __FILE__, |
|
| 969 | - __FUNCTION__, |
|
| 970 | - __LINE__ |
|
| 971 | - ); |
|
| 972 | - } |
|
| 973 | - if (defined('DOING_AJAX')) { |
|
| 974 | - return $new_status; |
|
| 975 | - } |
|
| 976 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 977 | - } |
|
| 934 | + /** |
|
| 935 | + * handles toggling the checkin status for the registration, |
|
| 936 | + * |
|
| 937 | + * @access protected |
|
| 938 | + * @return int|void |
|
| 939 | + * @throws EE_Error |
|
| 940 | + * @throws InvalidArgumentException |
|
| 941 | + * @throws InvalidDataTypeException |
|
| 942 | + * @throws InvalidInterfaceException |
|
| 943 | + */ |
|
| 944 | + protected function _toggle_checkin_status() |
|
| 945 | + { |
|
| 946 | + // first let's get the query args out of the way for the redirect |
|
| 947 | + $query_args = array( |
|
| 948 | + 'action' => 'event_registrations', |
|
| 949 | + 'event_id' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null, |
|
| 950 | + 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null, |
|
| 951 | + ); |
|
| 952 | + $new_status = false; |
|
| 953 | + // bulk action check in toggle |
|
| 954 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 955 | + // cycle thru checkboxes |
|
| 956 | + while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 957 | + $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null; |
|
| 958 | + $new_status = $this->_toggle_checkin($REG_ID, $DTT_ID); |
|
| 959 | + } |
|
| 960 | + } elseif (isset($this->_req_data['_regid'])) { |
|
| 961 | + // coming from ajax request |
|
| 962 | + $DTT_ID = isset($this->_req_data['dttid']) ? $this->_req_data['dttid'] : null; |
|
| 963 | + $query_args['DTT_ID'] = $DTT_ID; |
|
| 964 | + $new_status = $this->_toggle_checkin($this->_req_data['_regid'], $DTT_ID); |
|
| 965 | + } else { |
|
| 966 | + EE_Error::add_error( |
|
| 967 | + esc_html__('Missing some required data to toggle the Check-in', 'event_espresso'), |
|
| 968 | + __FILE__, |
|
| 969 | + __FUNCTION__, |
|
| 970 | + __LINE__ |
|
| 971 | + ); |
|
| 972 | + } |
|
| 973 | + if (defined('DOING_AJAX')) { |
|
| 974 | + return $new_status; |
|
| 975 | + } |
|
| 976 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 977 | + } |
|
| 978 | 978 | |
| 979 | 979 | |
| 980 | - /** |
|
| 981 | - * This is toggles a single Check-in for the given registration and datetime. |
|
| 982 | - * |
|
| 983 | - * @param int $REG_ID The registration we're toggling |
|
| 984 | - * @param int $DTT_ID The datetime we're toggling |
|
| 985 | - * @return int The new status toggled to. |
|
| 986 | - * @throws EE_Error |
|
| 987 | - * @throws InvalidArgumentException |
|
| 988 | - * @throws InvalidDataTypeException |
|
| 989 | - * @throws InvalidInterfaceException |
|
| 990 | - */ |
|
| 991 | - private function _toggle_checkin($REG_ID, $DTT_ID) |
|
| 992 | - { |
|
| 993 | - /** @var EE_Registration $REG */ |
|
| 994 | - $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID); |
|
| 995 | - $new_status = $REG->toggle_checkin_status($DTT_ID); |
|
| 996 | - if ($new_status !== false) { |
|
| 997 | - EE_Error::add_success($REG->get_checkin_msg($DTT_ID)); |
|
| 998 | - } else { |
|
| 999 | - EE_Error::add_error($REG->get_checkin_msg($DTT_ID, true), __FILE__, __FUNCTION__, __LINE__); |
|
| 1000 | - $new_status = false; |
|
| 1001 | - } |
|
| 1002 | - return $new_status; |
|
| 1003 | - } |
|
| 980 | + /** |
|
| 981 | + * This is toggles a single Check-in for the given registration and datetime. |
|
| 982 | + * |
|
| 983 | + * @param int $REG_ID The registration we're toggling |
|
| 984 | + * @param int $DTT_ID The datetime we're toggling |
|
| 985 | + * @return int The new status toggled to. |
|
| 986 | + * @throws EE_Error |
|
| 987 | + * @throws InvalidArgumentException |
|
| 988 | + * @throws InvalidDataTypeException |
|
| 989 | + * @throws InvalidInterfaceException |
|
| 990 | + */ |
|
| 991 | + private function _toggle_checkin($REG_ID, $DTT_ID) |
|
| 992 | + { |
|
| 993 | + /** @var EE_Registration $REG */ |
|
| 994 | + $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID); |
|
| 995 | + $new_status = $REG->toggle_checkin_status($DTT_ID); |
|
| 996 | + if ($new_status !== false) { |
|
| 997 | + EE_Error::add_success($REG->get_checkin_msg($DTT_ID)); |
|
| 998 | + } else { |
|
| 999 | + EE_Error::add_error($REG->get_checkin_msg($DTT_ID, true), __FILE__, __FUNCTION__, __LINE__); |
|
| 1000 | + $new_status = false; |
|
| 1001 | + } |
|
| 1002 | + return $new_status; |
|
| 1003 | + } |
|
| 1004 | 1004 | |
| 1005 | 1005 | |
| 1006 | - /** |
|
| 1007 | - * Takes care of deleting multiple EE_Checkin table rows |
|
| 1008 | - * |
|
| 1009 | - * @access protected |
|
| 1010 | - * @return void |
|
| 1011 | - * @throws EE_Error |
|
| 1012 | - * @throws InvalidArgumentException |
|
| 1013 | - * @throws InvalidDataTypeException |
|
| 1014 | - * @throws InvalidInterfaceException |
|
| 1015 | - */ |
|
| 1016 | - protected function _delete_checkin_rows() |
|
| 1017 | - { |
|
| 1018 | - $query_args = array( |
|
| 1019 | - 'action' => 'registration_checkins', |
|
| 1020 | - 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0, |
|
| 1021 | - '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0, |
|
| 1022 | - ); |
|
| 1023 | - $errors = 0; |
|
| 1024 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 1025 | - while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 1026 | - if (! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) { |
|
| 1027 | - $errors++; |
|
| 1028 | - } |
|
| 1029 | - } |
|
| 1030 | - } else { |
|
| 1031 | - EE_Error::add_error( |
|
| 1032 | - esc_html__( |
|
| 1033 | - 'So, something went wrong with the bulk delete because there was no data received for instructions on WHAT to delete!', |
|
| 1034 | - 'event_espresso' |
|
| 1035 | - ), |
|
| 1036 | - __FILE__, |
|
| 1037 | - __FUNCTION__, |
|
| 1038 | - __LINE__ |
|
| 1039 | - ); |
|
| 1040 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 1041 | - } |
|
| 1042 | - if ($errors > 0) { |
|
| 1043 | - EE_Error::add_error( |
|
| 1044 | - sprintf(__('There were %d records that did not delete successfully', 'event_espresso'), $errors), |
|
| 1045 | - __FILE__, |
|
| 1046 | - __FUNCTION__, |
|
| 1047 | - __LINE__ |
|
| 1048 | - ); |
|
| 1049 | - } else { |
|
| 1050 | - EE_Error::add_success(__('Records were successfully deleted', 'event_espresso')); |
|
| 1051 | - } |
|
| 1052 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 1053 | - } |
|
| 1006 | + /** |
|
| 1007 | + * Takes care of deleting multiple EE_Checkin table rows |
|
| 1008 | + * |
|
| 1009 | + * @access protected |
|
| 1010 | + * @return void |
|
| 1011 | + * @throws EE_Error |
|
| 1012 | + * @throws InvalidArgumentException |
|
| 1013 | + * @throws InvalidDataTypeException |
|
| 1014 | + * @throws InvalidInterfaceException |
|
| 1015 | + */ |
|
| 1016 | + protected function _delete_checkin_rows() |
|
| 1017 | + { |
|
| 1018 | + $query_args = array( |
|
| 1019 | + 'action' => 'registration_checkins', |
|
| 1020 | + 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0, |
|
| 1021 | + '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0, |
|
| 1022 | + ); |
|
| 1023 | + $errors = 0; |
|
| 1024 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 1025 | + while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 1026 | + if (! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) { |
|
| 1027 | + $errors++; |
|
| 1028 | + } |
|
| 1029 | + } |
|
| 1030 | + } else { |
|
| 1031 | + EE_Error::add_error( |
|
| 1032 | + esc_html__( |
|
| 1033 | + 'So, something went wrong with the bulk delete because there was no data received for instructions on WHAT to delete!', |
|
| 1034 | + 'event_espresso' |
|
| 1035 | + ), |
|
| 1036 | + __FILE__, |
|
| 1037 | + __FUNCTION__, |
|
| 1038 | + __LINE__ |
|
| 1039 | + ); |
|
| 1040 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 1041 | + } |
|
| 1042 | + if ($errors > 0) { |
|
| 1043 | + EE_Error::add_error( |
|
| 1044 | + sprintf(__('There were %d records that did not delete successfully', 'event_espresso'), $errors), |
|
| 1045 | + __FILE__, |
|
| 1046 | + __FUNCTION__, |
|
| 1047 | + __LINE__ |
|
| 1048 | + ); |
|
| 1049 | + } else { |
|
| 1050 | + EE_Error::add_success(__('Records were successfully deleted', 'event_espresso')); |
|
| 1051 | + } |
|
| 1052 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 1053 | + } |
|
| 1054 | 1054 | |
| 1055 | 1055 | |
| 1056 | - /** |
|
| 1057 | - * Deletes a single EE_Checkin row |
|
| 1058 | - * |
|
| 1059 | - * @return void |
|
| 1060 | - * @throws EE_Error |
|
| 1061 | - * @throws InvalidArgumentException |
|
| 1062 | - * @throws InvalidDataTypeException |
|
| 1063 | - * @throws InvalidInterfaceException |
|
| 1064 | - */ |
|
| 1065 | - protected function _delete_checkin_row() |
|
| 1066 | - { |
|
| 1067 | - $query_args = array( |
|
| 1068 | - 'action' => 'registration_checkins', |
|
| 1069 | - 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0, |
|
| 1070 | - '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0, |
|
| 1071 | - ); |
|
| 1072 | - if (! empty($this->_req_data['CHK_ID'])) { |
|
| 1073 | - if (! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) { |
|
| 1074 | - EE_Error::add_error( |
|
| 1075 | - esc_html__('Something went wrong and this check-in record was not deleted', 'event_espresso'), |
|
| 1076 | - __FILE__, |
|
| 1077 | - __FUNCTION__, |
|
| 1078 | - __LINE__ |
|
| 1079 | - ); |
|
| 1080 | - } else { |
|
| 1081 | - EE_Error::add_success(__('Check-In record successfully deleted', 'event_espresso')); |
|
| 1082 | - } |
|
| 1083 | - } else { |
|
| 1084 | - EE_Error::add_error( |
|
| 1085 | - esc_html__( |
|
| 1086 | - 'In order to delete a Check-in record, there must be a Check-In ID available. There is not. It is not your fault, there is just a gremlin living in the code', |
|
| 1087 | - 'event_espresso' |
|
| 1088 | - ), |
|
| 1089 | - __FILE__, |
|
| 1090 | - __FUNCTION__, |
|
| 1091 | - __LINE__ |
|
| 1092 | - ); |
|
| 1093 | - } |
|
| 1094 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 1095 | - } |
|
| 1056 | + /** |
|
| 1057 | + * Deletes a single EE_Checkin row |
|
| 1058 | + * |
|
| 1059 | + * @return void |
|
| 1060 | + * @throws EE_Error |
|
| 1061 | + * @throws InvalidArgumentException |
|
| 1062 | + * @throws InvalidDataTypeException |
|
| 1063 | + * @throws InvalidInterfaceException |
|
| 1064 | + */ |
|
| 1065 | + protected function _delete_checkin_row() |
|
| 1066 | + { |
|
| 1067 | + $query_args = array( |
|
| 1068 | + 'action' => 'registration_checkins', |
|
| 1069 | + 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0, |
|
| 1070 | + '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0, |
|
| 1071 | + ); |
|
| 1072 | + if (! empty($this->_req_data['CHK_ID'])) { |
|
| 1073 | + if (! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) { |
|
| 1074 | + EE_Error::add_error( |
|
| 1075 | + esc_html__('Something went wrong and this check-in record was not deleted', 'event_espresso'), |
|
| 1076 | + __FILE__, |
|
| 1077 | + __FUNCTION__, |
|
| 1078 | + __LINE__ |
|
| 1079 | + ); |
|
| 1080 | + } else { |
|
| 1081 | + EE_Error::add_success(__('Check-In record successfully deleted', 'event_espresso')); |
|
| 1082 | + } |
|
| 1083 | + } else { |
|
| 1084 | + EE_Error::add_error( |
|
| 1085 | + esc_html__( |
|
| 1086 | + 'In order to delete a Check-in record, there must be a Check-In ID available. There is not. It is not your fault, there is just a gremlin living in the code', |
|
| 1087 | + 'event_espresso' |
|
| 1088 | + ), |
|
| 1089 | + __FILE__, |
|
| 1090 | + __FUNCTION__, |
|
| 1091 | + __LINE__ |
|
| 1092 | + ); |
|
| 1093 | + } |
|
| 1094 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 1095 | + } |
|
| 1096 | 1096 | |
| 1097 | 1097 | |
| 1098 | - /** |
|
| 1099 | - * generates HTML for the Event Registrations List Table |
|
| 1100 | - * |
|
| 1101 | - * @access protected |
|
| 1102 | - * @return void |
|
| 1103 | - * @throws EE_Error |
|
| 1104 | - * @throws InvalidArgumentException |
|
| 1105 | - * @throws InvalidDataTypeException |
|
| 1106 | - * @throws InvalidInterfaceException |
|
| 1107 | - */ |
|
| 1108 | - protected function _event_registrations_list_table() |
|
| 1109 | - { |
|
| 1110 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1111 | - $this->_admin_page_title .= isset($this->_req_data['event_id']) |
|
| 1112 | - ? $this->get_action_link_or_button( |
|
| 1113 | - 'new_registration', |
|
| 1114 | - 'add-registrant', |
|
| 1115 | - array('event_id' => $this->_req_data['event_id']), |
|
| 1116 | - 'add-new-h2', |
|
| 1117 | - '', |
|
| 1118 | - false |
|
| 1119 | - ) |
|
| 1120 | - : ''; |
|
| 1121 | - $checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in); |
|
| 1122 | - $checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out); |
|
| 1123 | - $checked_never = new CheckinStatusDashicon(EE_Checkin::status_checked_never); |
|
| 1124 | - $legend_items = array( |
|
| 1125 | - 'star-icon' => array( |
|
| 1126 | - 'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8', |
|
| 1127 | - 'desc' => esc_html__('This Registrant is the Primary Registrant', 'event_espresso'), |
|
| 1128 | - ), |
|
| 1129 | - 'checkin' => array( |
|
| 1130 | - 'class' => $checked_in->cssClasses(), |
|
| 1131 | - 'desc' => $checked_in->legendLabel(), |
|
| 1132 | - ), |
|
| 1133 | - 'checkout' => array( |
|
| 1134 | - 'class' => $checked_out->cssClasses(), |
|
| 1135 | - 'desc' => $checked_out->legendLabel(), |
|
| 1136 | - ), |
|
| 1137 | - 'nocheckinrecord' => array( |
|
| 1138 | - 'class' => $checked_never->cssClasses(), |
|
| 1139 | - 'desc' => $checked_never->legendLabel(), |
|
| 1140 | - ), |
|
| 1141 | - 'approved_status' => array( |
|
| 1142 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved, |
|
| 1143 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'), |
|
| 1144 | - ), |
|
| 1145 | - 'cancelled_status' => array( |
|
| 1146 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled, |
|
| 1147 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'), |
|
| 1148 | - ), |
|
| 1149 | - 'declined_status' => array( |
|
| 1150 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined, |
|
| 1151 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'), |
|
| 1152 | - ), |
|
| 1153 | - 'not_approved' => array( |
|
| 1154 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved, |
|
| 1155 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'), |
|
| 1156 | - ), |
|
| 1157 | - 'pending_status' => array( |
|
| 1158 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment, |
|
| 1159 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'), |
|
| 1160 | - ), |
|
| 1161 | - 'wait_list' => array( |
|
| 1162 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list, |
|
| 1163 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'), |
|
| 1164 | - ), |
|
| 1165 | - ); |
|
| 1166 | - $this->_template_args['after_list_table'] = $this->_display_legend($legend_items); |
|
| 1167 | - $event_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null; |
|
| 1168 | - /** @var EE_Event $event */ |
|
| 1169 | - $event = EEM_Event::instance()->get_one_by_ID($event_id); |
|
| 1170 | - $this->_template_args['before_list_table'] = $event instanceof EE_Event |
|
| 1171 | - ? '<h2>' . sprintf( |
|
| 1172 | - esc_html__('Viewing Registrations for Event: %s', 'event_espresso'), |
|
| 1173 | - EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name') |
|
| 1174 | - ) . '</h2>' |
|
| 1175 | - : ''; |
|
| 1176 | - // need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on |
|
| 1177 | - // the event. |
|
| 1178 | - $DTT_ID = ! empty($this->_req_data['DTT_ID']) ? absint($this->_req_data['DTT_ID']) : 0; |
|
| 1179 | - $datetime = null; |
|
| 1180 | - if ($event instanceof EE_Event) { |
|
| 1181 | - $datetimes_on_event = $event->datetimes(); |
|
| 1182 | - if (count($datetimes_on_event) === 1) { |
|
| 1183 | - $datetime = reset($datetimes_on_event); |
|
| 1184 | - } |
|
| 1185 | - } |
|
| 1186 | - $datetime = $datetime instanceof EE_Datetime ? $datetime : EEM_Datetime::instance()->get_one_by_ID($DTT_ID); |
|
| 1187 | - if ($datetime instanceof EE_Datetime && $this->_template_args['before_list_table'] !== '') { |
|
| 1188 | - $this->_template_args['before_list_table'] = substr($this->_template_args['before_list_table'], 0, -5); |
|
| 1189 | - $this->_template_args['before_list_table'] .= ' <span class="drk-grey-text">'; |
|
| 1190 | - $this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>'; |
|
| 1191 | - $this->_template_args['before_list_table'] .= $datetime->name(); |
|
| 1192 | - $this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )'; |
|
| 1193 | - $this->_template_args['before_list_table'] .= '</span></h2>'; |
|
| 1194 | - } |
|
| 1195 | - // if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status |
|
| 1196 | - // column represents |
|
| 1197 | - if (! $datetime instanceof EE_Datetime) { |
|
| 1198 | - $this->_template_args['before_list_table'] .= '<br><p class="description">' |
|
| 1199 | - . esc_html__( |
|
| 1200 | - 'In this view, the check-in status represents the latest check-in record for the registration in that row.', |
|
| 1201 | - 'event_espresso' |
|
| 1202 | - ) |
|
| 1203 | - . '</p>'; |
|
| 1204 | - } |
|
| 1205 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1206 | - } |
|
| 1098 | + /** |
|
| 1099 | + * generates HTML for the Event Registrations List Table |
|
| 1100 | + * |
|
| 1101 | + * @access protected |
|
| 1102 | + * @return void |
|
| 1103 | + * @throws EE_Error |
|
| 1104 | + * @throws InvalidArgumentException |
|
| 1105 | + * @throws InvalidDataTypeException |
|
| 1106 | + * @throws InvalidInterfaceException |
|
| 1107 | + */ |
|
| 1108 | + protected function _event_registrations_list_table() |
|
| 1109 | + { |
|
| 1110 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1111 | + $this->_admin_page_title .= isset($this->_req_data['event_id']) |
|
| 1112 | + ? $this->get_action_link_or_button( |
|
| 1113 | + 'new_registration', |
|
| 1114 | + 'add-registrant', |
|
| 1115 | + array('event_id' => $this->_req_data['event_id']), |
|
| 1116 | + 'add-new-h2', |
|
| 1117 | + '', |
|
| 1118 | + false |
|
| 1119 | + ) |
|
| 1120 | + : ''; |
|
| 1121 | + $checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in); |
|
| 1122 | + $checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out); |
|
| 1123 | + $checked_never = new CheckinStatusDashicon(EE_Checkin::status_checked_never); |
|
| 1124 | + $legend_items = array( |
|
| 1125 | + 'star-icon' => array( |
|
| 1126 | + 'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8', |
|
| 1127 | + 'desc' => esc_html__('This Registrant is the Primary Registrant', 'event_espresso'), |
|
| 1128 | + ), |
|
| 1129 | + 'checkin' => array( |
|
| 1130 | + 'class' => $checked_in->cssClasses(), |
|
| 1131 | + 'desc' => $checked_in->legendLabel(), |
|
| 1132 | + ), |
|
| 1133 | + 'checkout' => array( |
|
| 1134 | + 'class' => $checked_out->cssClasses(), |
|
| 1135 | + 'desc' => $checked_out->legendLabel(), |
|
| 1136 | + ), |
|
| 1137 | + 'nocheckinrecord' => array( |
|
| 1138 | + 'class' => $checked_never->cssClasses(), |
|
| 1139 | + 'desc' => $checked_never->legendLabel(), |
|
| 1140 | + ), |
|
| 1141 | + 'approved_status' => array( |
|
| 1142 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved, |
|
| 1143 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'), |
|
| 1144 | + ), |
|
| 1145 | + 'cancelled_status' => array( |
|
| 1146 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled, |
|
| 1147 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'), |
|
| 1148 | + ), |
|
| 1149 | + 'declined_status' => array( |
|
| 1150 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined, |
|
| 1151 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'), |
|
| 1152 | + ), |
|
| 1153 | + 'not_approved' => array( |
|
| 1154 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved, |
|
| 1155 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'), |
|
| 1156 | + ), |
|
| 1157 | + 'pending_status' => array( |
|
| 1158 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment, |
|
| 1159 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'), |
|
| 1160 | + ), |
|
| 1161 | + 'wait_list' => array( |
|
| 1162 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list, |
|
| 1163 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'), |
|
| 1164 | + ), |
|
| 1165 | + ); |
|
| 1166 | + $this->_template_args['after_list_table'] = $this->_display_legend($legend_items); |
|
| 1167 | + $event_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null; |
|
| 1168 | + /** @var EE_Event $event */ |
|
| 1169 | + $event = EEM_Event::instance()->get_one_by_ID($event_id); |
|
| 1170 | + $this->_template_args['before_list_table'] = $event instanceof EE_Event |
|
| 1171 | + ? '<h2>' . sprintf( |
|
| 1172 | + esc_html__('Viewing Registrations for Event: %s', 'event_espresso'), |
|
| 1173 | + EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name') |
|
| 1174 | + ) . '</h2>' |
|
| 1175 | + : ''; |
|
| 1176 | + // need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on |
|
| 1177 | + // the event. |
|
| 1178 | + $DTT_ID = ! empty($this->_req_data['DTT_ID']) ? absint($this->_req_data['DTT_ID']) : 0; |
|
| 1179 | + $datetime = null; |
|
| 1180 | + if ($event instanceof EE_Event) { |
|
| 1181 | + $datetimes_on_event = $event->datetimes(); |
|
| 1182 | + if (count($datetimes_on_event) === 1) { |
|
| 1183 | + $datetime = reset($datetimes_on_event); |
|
| 1184 | + } |
|
| 1185 | + } |
|
| 1186 | + $datetime = $datetime instanceof EE_Datetime ? $datetime : EEM_Datetime::instance()->get_one_by_ID($DTT_ID); |
|
| 1187 | + if ($datetime instanceof EE_Datetime && $this->_template_args['before_list_table'] !== '') { |
|
| 1188 | + $this->_template_args['before_list_table'] = substr($this->_template_args['before_list_table'], 0, -5); |
|
| 1189 | + $this->_template_args['before_list_table'] .= ' <span class="drk-grey-text">'; |
|
| 1190 | + $this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>'; |
|
| 1191 | + $this->_template_args['before_list_table'] .= $datetime->name(); |
|
| 1192 | + $this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )'; |
|
| 1193 | + $this->_template_args['before_list_table'] .= '</span></h2>'; |
|
| 1194 | + } |
|
| 1195 | + // if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status |
|
| 1196 | + // column represents |
|
| 1197 | + if (! $datetime instanceof EE_Datetime) { |
|
| 1198 | + $this->_template_args['before_list_table'] .= '<br><p class="description">' |
|
| 1199 | + . esc_html__( |
|
| 1200 | + 'In this view, the check-in status represents the latest check-in record for the registration in that row.', |
|
| 1201 | + 'event_espresso' |
|
| 1202 | + ) |
|
| 1203 | + . '</p>'; |
|
| 1204 | + } |
|
| 1205 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1206 | + } |
|
| 1207 | 1207 | |
| 1208 | - /** |
|
| 1209 | - * Download the registrations check-in report (same as the normal registration report, but with different where |
|
| 1210 | - * conditions) |
|
| 1211 | - * |
|
| 1212 | - * @return void ends the request by a redirect or download |
|
| 1213 | - */ |
|
| 1214 | - public function _registrations_checkin_report() |
|
| 1215 | - { |
|
| 1216 | - $this->_registrations_report_base('_get_checkin_query_params_from_request'); |
|
| 1217 | - } |
|
| 1208 | + /** |
|
| 1209 | + * Download the registrations check-in report (same as the normal registration report, but with different where |
|
| 1210 | + * conditions) |
|
| 1211 | + * |
|
| 1212 | + * @return void ends the request by a redirect or download |
|
| 1213 | + */ |
|
| 1214 | + public function _registrations_checkin_report() |
|
| 1215 | + { |
|
| 1216 | + $this->_registrations_report_base('_get_checkin_query_params_from_request'); |
|
| 1217 | + } |
|
| 1218 | 1218 | |
| 1219 | - /** |
|
| 1220 | - * Gets the query params from the request, plus adds a where condition for the registration status, |
|
| 1221 | - * because on the checkin page we only ever want to see approved and pending-approval registrations |
|
| 1222 | - * |
|
| 1223 | - * @param array $request |
|
| 1224 | - * @param int $per_page |
|
| 1225 | - * @param bool $count |
|
| 1226 | - * @return array |
|
| 1227 | - * @throws EE_Error |
|
| 1228 | - */ |
|
| 1229 | - protected function _get_checkin_query_params_from_request( |
|
| 1230 | - $request, |
|
| 1231 | - $per_page = 10, |
|
| 1232 | - $count = false |
|
| 1233 | - ) { |
|
| 1234 | - $query_params = $this->_get_registration_query_parameters($request, $per_page, $count); |
|
| 1235 | - // unlike the regular registrations list table, |
|
| 1236 | - $status_ids_array = apply_filters( |
|
| 1237 | - 'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array', |
|
| 1238 | - array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved) |
|
| 1239 | - ); |
|
| 1240 | - $query_params[0]['STS_ID'] = array('IN', $status_ids_array); |
|
| 1241 | - return $query_params; |
|
| 1242 | - } |
|
| 1219 | + /** |
|
| 1220 | + * Gets the query params from the request, plus adds a where condition for the registration status, |
|
| 1221 | + * because on the checkin page we only ever want to see approved and pending-approval registrations |
|
| 1222 | + * |
|
| 1223 | + * @param array $request |
|
| 1224 | + * @param int $per_page |
|
| 1225 | + * @param bool $count |
|
| 1226 | + * @return array |
|
| 1227 | + * @throws EE_Error |
|
| 1228 | + */ |
|
| 1229 | + protected function _get_checkin_query_params_from_request( |
|
| 1230 | + $request, |
|
| 1231 | + $per_page = 10, |
|
| 1232 | + $count = false |
|
| 1233 | + ) { |
|
| 1234 | + $query_params = $this->_get_registration_query_parameters($request, $per_page, $count); |
|
| 1235 | + // unlike the regular registrations list table, |
|
| 1236 | + $status_ids_array = apply_filters( |
|
| 1237 | + 'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array', |
|
| 1238 | + array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved) |
|
| 1239 | + ); |
|
| 1240 | + $query_params[0]['STS_ID'] = array('IN', $status_ids_array); |
|
| 1241 | + return $query_params; |
|
| 1242 | + } |
|
| 1243 | 1243 | |
| 1244 | 1244 | |
| 1245 | - /** |
|
| 1246 | - * Gets registrations for an event |
|
| 1247 | - * |
|
| 1248 | - * @param int $per_page |
|
| 1249 | - * @param bool $count whether to return count or data. |
|
| 1250 | - * @param bool $trash |
|
| 1251 | - * @param string $orderby |
|
| 1252 | - * @return EE_Registration[]|int |
|
| 1253 | - * @throws EE_Error |
|
| 1254 | - * @throws InvalidArgumentException |
|
| 1255 | - * @throws InvalidDataTypeException |
|
| 1256 | - * @throws InvalidInterfaceException |
|
| 1257 | - */ |
|
| 1258 | - public function get_event_attendees($per_page = 10, $count = false, $trash = false, $orderby = 'ATT_fname') |
|
| 1259 | - { |
|
| 1260 | - // normalize some request params that get setup by the parent `get_registrations` method. |
|
| 1261 | - $request = $this->_req_data; |
|
| 1262 | - $request['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : $orderby; |
|
| 1263 | - $request['order'] = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC'; |
|
| 1264 | - if ($trash) { |
|
| 1265 | - $request['status'] = 'trash'; |
|
| 1266 | - } |
|
| 1267 | - $query_params = $this->_get_checkin_query_params_from_request($request, $per_page, $count); |
|
| 1268 | - /** |
|
| 1269 | - * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected |
|
| 1270 | - * |
|
| 1271 | - * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093 |
|
| 1272 | - * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1273 | - * or if you have the development copy of EE you can view this at the path: |
|
| 1274 | - * /docs/G--Model-System/model-query-params.md |
|
| 1275 | - */ |
|
| 1276 | - $query_params['group_by'] = ''; |
|
| 1245 | + /** |
|
| 1246 | + * Gets registrations for an event |
|
| 1247 | + * |
|
| 1248 | + * @param int $per_page |
|
| 1249 | + * @param bool $count whether to return count or data. |
|
| 1250 | + * @param bool $trash |
|
| 1251 | + * @param string $orderby |
|
| 1252 | + * @return EE_Registration[]|int |
|
| 1253 | + * @throws EE_Error |
|
| 1254 | + * @throws InvalidArgumentException |
|
| 1255 | + * @throws InvalidDataTypeException |
|
| 1256 | + * @throws InvalidInterfaceException |
|
| 1257 | + */ |
|
| 1258 | + public function get_event_attendees($per_page = 10, $count = false, $trash = false, $orderby = 'ATT_fname') |
|
| 1259 | + { |
|
| 1260 | + // normalize some request params that get setup by the parent `get_registrations` method. |
|
| 1261 | + $request = $this->_req_data; |
|
| 1262 | + $request['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : $orderby; |
|
| 1263 | + $request['order'] = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC'; |
|
| 1264 | + if ($trash) { |
|
| 1265 | + $request['status'] = 'trash'; |
|
| 1266 | + } |
|
| 1267 | + $query_params = $this->_get_checkin_query_params_from_request($request, $per_page, $count); |
|
| 1268 | + /** |
|
| 1269 | + * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected |
|
| 1270 | + * |
|
| 1271 | + * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093 |
|
| 1272 | + * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1273 | + * or if you have the development copy of EE you can view this at the path: |
|
| 1274 | + * /docs/G--Model-System/model-query-params.md |
|
| 1275 | + */ |
|
| 1276 | + $query_params['group_by'] = ''; |
|
| 1277 | 1277 | |
| 1278 | - return $count |
|
| 1279 | - ? EEM_Registration::instance()->count($query_params) |
|
| 1280 | - /** @type EE_Registration[] */ |
|
| 1281 | - : EEM_Registration::instance()->get_all($query_params); |
|
| 1282 | - } |
|
| 1278 | + return $count |
|
| 1279 | + ? EEM_Registration::instance()->count($query_params) |
|
| 1280 | + /** @type EE_Registration[] */ |
|
| 1281 | + : EEM_Registration::instance()->get_all($query_params); |
|
| 1282 | + } |
|
| 1283 | 1283 | } |
@@ -16,1283 +16,1283 @@ |
||
| 16 | 16 | { |
| 17 | 17 | |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * Extend_Events_Admin_Page constructor. |
|
| 21 | - * |
|
| 22 | - * @param bool $routing |
|
| 23 | - */ |
|
| 24 | - public function __construct($routing = true) |
|
| 25 | - { |
|
| 26 | - parent::__construct($routing); |
|
| 27 | - if (! defined('EVENTS_CAF_TEMPLATE_PATH')) { |
|
| 28 | - define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/'); |
|
| 29 | - define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/'); |
|
| 30 | - define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/'); |
|
| 31 | - } |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * Sets routes. |
|
| 37 | - */ |
|
| 38 | - protected function _extend_page_config() |
|
| 39 | - { |
|
| 40 | - $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events'; |
|
| 41 | - // is there a evt_id in the request? |
|
| 42 | - $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID']) |
|
| 43 | - ? $this->_req_data['EVT_ID'] |
|
| 44 | - : 0; |
|
| 45 | - $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id; |
|
| 46 | - // tkt_id? |
|
| 47 | - $tkt_id = ! empty($this->_req_data['TKT_ID']) && ! is_array($this->_req_data['TKT_ID']) |
|
| 48 | - ? $this->_req_data['TKT_ID'] |
|
| 49 | - : 0; |
|
| 50 | - $new_page_routes = array( |
|
| 51 | - 'duplicate_event' => array( |
|
| 52 | - 'func' => '_duplicate_event', |
|
| 53 | - 'capability' => 'ee_edit_event', |
|
| 54 | - 'obj_id' => $evt_id, |
|
| 55 | - 'noheader' => true, |
|
| 56 | - ), |
|
| 57 | - 'ticket_list_table' => array( |
|
| 58 | - 'func' => '_tickets_overview_list_table', |
|
| 59 | - 'capability' => 'ee_read_default_tickets', |
|
| 60 | - ), |
|
| 61 | - 'trash_ticket' => array( |
|
| 62 | - 'func' => '_trash_or_restore_ticket', |
|
| 63 | - 'capability' => 'ee_delete_default_ticket', |
|
| 64 | - 'obj_id' => $tkt_id, |
|
| 65 | - 'noheader' => true, |
|
| 66 | - 'args' => array('trash' => true), |
|
| 67 | - ), |
|
| 68 | - 'trash_tickets' => array( |
|
| 69 | - 'func' => '_trash_or_restore_ticket', |
|
| 70 | - 'capability' => 'ee_delete_default_tickets', |
|
| 71 | - 'noheader' => true, |
|
| 72 | - 'args' => array('trash' => true), |
|
| 73 | - ), |
|
| 74 | - 'restore_ticket' => array( |
|
| 75 | - 'func' => '_trash_or_restore_ticket', |
|
| 76 | - 'capability' => 'ee_delete_default_ticket', |
|
| 77 | - 'obj_id' => $tkt_id, |
|
| 78 | - 'noheader' => true, |
|
| 79 | - ), |
|
| 80 | - 'restore_tickets' => array( |
|
| 81 | - 'func' => '_trash_or_restore_ticket', |
|
| 82 | - 'capability' => 'ee_delete_default_tickets', |
|
| 83 | - 'noheader' => true, |
|
| 84 | - ), |
|
| 85 | - 'delete_ticket' => array( |
|
| 86 | - 'func' => '_delete_ticket', |
|
| 87 | - 'capability' => 'ee_delete_default_ticket', |
|
| 88 | - 'obj_id' => $tkt_id, |
|
| 89 | - 'noheader' => true, |
|
| 90 | - ), |
|
| 91 | - 'delete_tickets' => array( |
|
| 92 | - 'func' => '_delete_ticket', |
|
| 93 | - 'capability' => 'ee_delete_default_tickets', |
|
| 94 | - 'noheader' => true, |
|
| 95 | - ), |
|
| 96 | - 'import_page' => array( |
|
| 97 | - 'func' => '_import_page', |
|
| 98 | - 'capability' => 'import', |
|
| 99 | - ), |
|
| 100 | - 'import' => array( |
|
| 101 | - 'func' => '_import_events', |
|
| 102 | - 'capability' => 'import', |
|
| 103 | - 'noheader' => true, |
|
| 104 | - ), |
|
| 105 | - 'import_events' => array( |
|
| 106 | - 'func' => '_import_events', |
|
| 107 | - 'capability' => 'import', |
|
| 108 | - 'noheader' => true, |
|
| 109 | - ), |
|
| 110 | - 'export_events' => array( |
|
| 111 | - 'func' => '_events_export', |
|
| 112 | - 'capability' => 'export', |
|
| 113 | - 'noheader' => true, |
|
| 114 | - ), |
|
| 115 | - 'export_categories' => array( |
|
| 116 | - 'func' => '_categories_export', |
|
| 117 | - 'capability' => 'export', |
|
| 118 | - 'noheader' => true, |
|
| 119 | - ), |
|
| 120 | - 'sample_export_file' => array( |
|
| 121 | - 'func' => '_sample_export_file', |
|
| 122 | - 'capability' => 'export', |
|
| 123 | - 'noheader' => true, |
|
| 124 | - ), |
|
| 125 | - 'update_template_settings' => array( |
|
| 126 | - 'func' => '_update_template_settings', |
|
| 127 | - 'capability' => 'manage_options', |
|
| 128 | - 'noheader' => true, |
|
| 129 | - ), |
|
| 130 | - ); |
|
| 131 | - $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
| 132 | - // partial route/config override |
|
| 133 | - $this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes; |
|
| 134 | - $this->_page_config['create_new']['metaboxes'][] = '_premium_event_editor_meta_boxes'; |
|
| 135 | - $this->_page_config['create_new']['qtips'][] = 'EE_Event_Editor_Tips'; |
|
| 136 | - $this->_page_config['edit']['qtips'][] = 'EE_Event_Editor_Tips'; |
|
| 137 | - $this->_page_config['edit']['metaboxes'][] = '_premium_event_editor_meta_boxes'; |
|
| 138 | - $this->_page_config['default']['list_table'] = 'Extend_Events_Admin_List_Table'; |
|
| 139 | - // add tickets tab but only if there are more than one default ticket! |
|
| 140 | - $tkt_count = EEM_Ticket::instance()->count_deleted_and_undeleted( |
|
| 141 | - array(array('TKT_is_default' => 1)), |
|
| 142 | - 'TKT_ID', |
|
| 143 | - true |
|
| 144 | - ); |
|
| 145 | - if ($tkt_count > 1) { |
|
| 146 | - $new_page_config = array( |
|
| 147 | - 'ticket_list_table' => array( |
|
| 148 | - 'nav' => array( |
|
| 149 | - 'label' => esc_html__('Default Tickets', 'event_espresso'), |
|
| 150 | - 'order' => 60, |
|
| 151 | - ), |
|
| 152 | - 'list_table' => 'Tickets_List_Table', |
|
| 153 | - 'require_nonce' => false, |
|
| 154 | - ), |
|
| 155 | - ); |
|
| 156 | - } |
|
| 157 | - // template settings |
|
| 158 | - $new_page_config['template_settings'] = array( |
|
| 159 | - 'nav' => array( |
|
| 160 | - 'label' => esc_html__('Templates', 'event_espresso'), |
|
| 161 | - 'order' => 30, |
|
| 162 | - ), |
|
| 163 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 164 | - 'help_tabs' => array( |
|
| 165 | - 'general_settings_templates_help_tab' => array( |
|
| 166 | - 'title' => esc_html__('Templates', 'event_espresso'), |
|
| 167 | - 'filename' => 'general_settings_templates', |
|
| 168 | - ), |
|
| 169 | - ), |
|
| 170 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 171 | - // 'help_tour' => array('Templates_Help_Tour'), |
|
| 172 | - 'require_nonce' => false, |
|
| 173 | - ); |
|
| 174 | - $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
| 175 | - // add filters and actions |
|
| 176 | - // modifying _views |
|
| 177 | - add_filter( |
|
| 178 | - 'FHEE_event_datetime_metabox_add_additional_date_time_template', |
|
| 179 | - array($this, 'add_additional_datetime_button'), |
|
| 180 | - 10, |
|
| 181 | - 2 |
|
| 182 | - ); |
|
| 183 | - add_filter( |
|
| 184 | - 'FHEE_event_datetime_metabox_clone_button_template', |
|
| 185 | - array($this, 'add_datetime_clone_button'), |
|
| 186 | - 10, |
|
| 187 | - 2 |
|
| 188 | - ); |
|
| 189 | - add_filter( |
|
| 190 | - 'FHEE_event_datetime_metabox_timezones_template', |
|
| 191 | - array($this, 'datetime_timezones_template'), |
|
| 192 | - 10, |
|
| 193 | - 2 |
|
| 194 | - ); |
|
| 195 | - // filters for event list table |
|
| 196 | - add_filter('FHEE__Extend_Events_Admin_List_Table__filters', array($this, 'list_table_filters'), 10, 2); |
|
| 197 | - add_filter( |
|
| 198 | - 'FHEE__Events_Admin_List_Table__column_actions__action_links', |
|
| 199 | - array($this, 'extra_list_table_actions'), |
|
| 200 | - 10, |
|
| 201 | - 2 |
|
| 202 | - ); |
|
| 203 | - // legend item |
|
| 204 | - add_filter('FHEE__Events_Admin_Page___event_legend_items__items', array($this, 'additional_legend_items')); |
|
| 205 | - add_action('admin_init', array($this, 'admin_init')); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * admin_init |
|
| 211 | - */ |
|
| 212 | - public function admin_init() |
|
| 213 | - { |
|
| 214 | - EE_Registry::$i18n_js_strings = array_merge( |
|
| 215 | - EE_Registry::$i18n_js_strings, |
|
| 216 | - array( |
|
| 217 | - 'image_confirm' => esc_html__( |
|
| 218 | - 'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
|
| 219 | - 'event_espresso' |
|
| 220 | - ), |
|
| 221 | - 'event_starts_on' => esc_html__('Event Starts on', 'event_espresso'), |
|
| 222 | - 'event_ends_on' => esc_html__('Event Ends on', 'event_espresso'), |
|
| 223 | - 'event_datetime_actions' => esc_html__('Actions', 'event_espresso'), |
|
| 224 | - 'event_clone_dt_msg' => esc_html__('Clone this Event Date and Time', 'event_espresso'), |
|
| 225 | - 'remove_event_dt_msg' => esc_html__('Remove this Event Time', 'event_espresso'), |
|
| 226 | - ) |
|
| 227 | - ); |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * Add per page screen options to the default ticket list table view. |
|
| 233 | - */ |
|
| 234 | - protected function _add_screen_options_ticket_list_table() |
|
| 235 | - { |
|
| 236 | - $this->_per_page_screen_option(); |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * @param string $return |
|
| 242 | - * @param int $id |
|
| 243 | - * @param string $new_title |
|
| 244 | - * @param string $new_slug |
|
| 245 | - * @return string |
|
| 246 | - */ |
|
| 247 | - public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
|
| 248 | - { |
|
| 249 | - $return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug); |
|
| 250 | - // make sure this is only when editing |
|
| 251 | - if (! empty($id)) { |
|
| 252 | - $href = EE_Admin_Page::add_query_args_and_nonce( |
|
| 253 | - array('action' => 'duplicate_event', 'EVT_ID' => $id), |
|
| 254 | - $this->_admin_base_url |
|
| 255 | - ); |
|
| 256 | - $title = esc_attr__('Duplicate Event', 'event_espresso'); |
|
| 257 | - $return .= '<a href="' |
|
| 258 | - . $href |
|
| 259 | - . '" title="' |
|
| 260 | - . $title |
|
| 261 | - . '" id="ee-duplicate-event-button" class="button button-small" value="duplicate_event">' |
|
| 262 | - . $title |
|
| 263 | - . '</a>'; |
|
| 264 | - } |
|
| 265 | - return $return; |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - |
|
| 269 | - /** |
|
| 270 | - * Set the list table views for the default ticket list table view. |
|
| 271 | - */ |
|
| 272 | - public function _set_list_table_views_ticket_list_table() |
|
| 273 | - { |
|
| 274 | - $this->_views = array( |
|
| 275 | - 'all' => array( |
|
| 276 | - 'slug' => 'all', |
|
| 277 | - 'label' => esc_html__('All', 'event_espresso'), |
|
| 278 | - 'count' => 0, |
|
| 279 | - 'bulk_action' => array( |
|
| 280 | - 'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 281 | - ), |
|
| 282 | - ), |
|
| 283 | - 'trashed' => array( |
|
| 284 | - 'slug' => 'trashed', |
|
| 285 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 286 | - 'count' => 0, |
|
| 287 | - 'bulk_action' => array( |
|
| 288 | - 'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'), |
|
| 289 | - 'delete_tickets' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 290 | - ), |
|
| 291 | - ), |
|
| 292 | - ); |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - |
|
| 296 | - /** |
|
| 297 | - * Enqueue scripts and styles for the event editor. |
|
| 298 | - */ |
|
| 299 | - public function load_scripts_styles_edit() |
|
| 300 | - { |
|
| 301 | - wp_register_script( |
|
| 302 | - 'ee-event-editor-heartbeat', |
|
| 303 | - EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js', |
|
| 304 | - array('ee_admin_js', 'heartbeat'), |
|
| 305 | - EVENT_ESPRESSO_VERSION, |
|
| 306 | - true |
|
| 307 | - ); |
|
| 308 | - wp_enqueue_script('ee-accounting'); |
|
| 309 | - // styles |
|
| 310 | - wp_enqueue_style('espresso-ui-theme'); |
|
| 311 | - wp_enqueue_script('event_editor_js'); |
|
| 312 | - wp_enqueue_script('ee-event-editor-heartbeat'); |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - |
|
| 316 | - /** |
|
| 317 | - * Returns template for the additional datetime. |
|
| 318 | - * |
|
| 319 | - * @param $template |
|
| 320 | - * @param $template_args |
|
| 321 | - * @return mixed |
|
| 322 | - * @throws DomainException |
|
| 323 | - */ |
|
| 324 | - public function add_additional_datetime_button($template, $template_args) |
|
| 325 | - { |
|
| 326 | - return EEH_Template::display_template( |
|
| 327 | - EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php', |
|
| 328 | - $template_args, |
|
| 329 | - true |
|
| 330 | - ); |
|
| 331 | - } |
|
| 332 | - |
|
| 333 | - |
|
| 334 | - /** |
|
| 335 | - * Returns the template for cloning a datetime. |
|
| 336 | - * |
|
| 337 | - * @param $template |
|
| 338 | - * @param $template_args |
|
| 339 | - * @return mixed |
|
| 340 | - * @throws DomainException |
|
| 341 | - */ |
|
| 342 | - public function add_datetime_clone_button($template, $template_args) |
|
| 343 | - { |
|
| 344 | - return EEH_Template::display_template( |
|
| 345 | - EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php', |
|
| 346 | - $template_args, |
|
| 347 | - true |
|
| 348 | - ); |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * Returns the template for datetime timezones. |
|
| 354 | - * |
|
| 355 | - * @param $template |
|
| 356 | - * @param $template_args |
|
| 357 | - * @return mixed |
|
| 358 | - * @throws DomainException |
|
| 359 | - */ |
|
| 360 | - public function datetime_timezones_template($template, $template_args) |
|
| 361 | - { |
|
| 362 | - return EEH_Template::display_template( |
|
| 363 | - EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php', |
|
| 364 | - $template_args, |
|
| 365 | - true |
|
| 366 | - ); |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - |
|
| 370 | - /** |
|
| 371 | - * Sets the views for the default list table view. |
|
| 372 | - */ |
|
| 373 | - protected function _set_list_table_views_default() |
|
| 374 | - { |
|
| 375 | - parent::_set_list_table_views_default(); |
|
| 376 | - $new_views = array( |
|
| 377 | - 'today' => array( |
|
| 378 | - 'slug' => 'today', |
|
| 379 | - 'label' => esc_html__('Today', 'event_espresso'), |
|
| 380 | - 'count' => $this->total_events_today(), |
|
| 381 | - 'bulk_action' => array( |
|
| 382 | - 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 383 | - ), |
|
| 384 | - ), |
|
| 385 | - 'month' => array( |
|
| 386 | - 'slug' => 'month', |
|
| 387 | - 'label' => esc_html__('This Month', 'event_espresso'), |
|
| 388 | - 'count' => $this->total_events_this_month(), |
|
| 389 | - 'bulk_action' => array( |
|
| 390 | - 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 391 | - ), |
|
| 392 | - ), |
|
| 393 | - ); |
|
| 394 | - $this->_views = array_merge($this->_views, $new_views); |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - |
|
| 398 | - /** |
|
| 399 | - * Returns the extra action links for the default list table view. |
|
| 400 | - * |
|
| 401 | - * @param array $action_links |
|
| 402 | - * @param \EE_Event $event |
|
| 403 | - * @return array |
|
| 404 | - * @throws EE_Error |
|
| 405 | - */ |
|
| 406 | - public function extra_list_table_actions(array $action_links, \EE_Event $event) |
|
| 407 | - { |
|
| 408 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 409 | - 'ee_read_registrations', |
|
| 410 | - 'espresso_registrations_reports', |
|
| 411 | - $event->ID() |
|
| 412 | - ) |
|
| 413 | - ) { |
|
| 414 | - $reports_query_args = array( |
|
| 415 | - 'action' => 'reports', |
|
| 416 | - 'EVT_ID' => $event->ID(), |
|
| 417 | - ); |
|
| 418 | - $reports_link = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL); |
|
| 419 | - $action_links[] = '<a href="' |
|
| 420 | - . $reports_link |
|
| 421 | - . '" title="' |
|
| 422 | - . esc_attr__('View Report', 'event_espresso') |
|
| 423 | - . '"><div class="dashicons dashicons-chart-bar"></div></a>' |
|
| 424 | - . "\n\t"; |
|
| 425 | - } |
|
| 426 | - if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
| 427 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 428 | - $action_links[] = EEH_MSG_Template::get_message_action_link( |
|
| 429 | - 'see_notifications_for', |
|
| 430 | - null, |
|
| 431 | - array('EVT_ID' => $event->ID()) |
|
| 432 | - ); |
|
| 433 | - } |
|
| 434 | - return $action_links; |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - |
|
| 438 | - /** |
|
| 439 | - * @param $items |
|
| 440 | - * @return mixed |
|
| 441 | - */ |
|
| 442 | - public function additional_legend_items($items) |
|
| 443 | - { |
|
| 444 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 445 | - 'ee_read_registrations', |
|
| 446 | - 'espresso_registrations_reports' |
|
| 447 | - ) |
|
| 448 | - ) { |
|
| 449 | - $items['reports'] = array( |
|
| 450 | - 'class' => 'dashicons dashicons-chart-bar', |
|
| 451 | - 'desc' => esc_html__('Event Reports', 'event_espresso'), |
|
| 452 | - ); |
|
| 453 | - } |
|
| 454 | - if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
| 455 | - $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
| 456 | - if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) { |
|
| 457 | - $items['view_related_messages'] = array( |
|
| 458 | - 'class' => $related_for_icon['css_class'], |
|
| 459 | - 'desc' => $related_for_icon['label'], |
|
| 460 | - ); |
|
| 461 | - } |
|
| 462 | - } |
|
| 463 | - return $items; |
|
| 464 | - } |
|
| 465 | - |
|
| 466 | - |
|
| 467 | - /** |
|
| 468 | - * This is the callback method for the duplicate event route |
|
| 469 | - * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them |
|
| 470 | - * into a new event. We add a hook so that any plugins that add extra event details can hook into this |
|
| 471 | - * action. Note that the dupe will have **DUPLICATE** as its title and slug. |
|
| 472 | - * After duplication the redirect is to the new event edit page. |
|
| 473 | - * |
|
| 474 | - * @return void |
|
| 475 | - * @access protected |
|
| 476 | - * @throws EE_Error If EE_Event is not available with given ID |
|
| 477 | - */ |
|
| 478 | - protected function _duplicate_event() |
|
| 479 | - { |
|
| 480 | - // first make sure the ID for the event is in the request. |
|
| 481 | - // If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?) |
|
| 482 | - if (! isset($this->_req_data['EVT_ID'])) { |
|
| 483 | - EE_Error::add_error( |
|
| 484 | - esc_html__( |
|
| 485 | - 'In order to duplicate an event an Event ID is required. None was given.', |
|
| 486 | - 'event_espresso' |
|
| 487 | - ), |
|
| 488 | - __FILE__, |
|
| 489 | - __FUNCTION__, |
|
| 490 | - __LINE__ |
|
| 491 | - ); |
|
| 492 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 493 | - return; |
|
| 494 | - } |
|
| 495 | - // k we've got EVT_ID so let's use that to get the event we'll duplicate |
|
| 496 | - $orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']); |
|
| 497 | - if (! $orig_event instanceof EE_Event) { |
|
| 498 | - throw new EE_Error( |
|
| 499 | - sprintf( |
|
| 500 | - esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'), |
|
| 501 | - $this->_req_data['EVT_ID'] |
|
| 502 | - ) |
|
| 503 | - ); |
|
| 504 | - } |
|
| 505 | - // k now let's clone the $orig_event before getting relations |
|
| 506 | - $new_event = clone $orig_event; |
|
| 507 | - // original datetimes |
|
| 508 | - $orig_datetimes = $orig_event->get_many_related('Datetime'); |
|
| 509 | - // other original relations |
|
| 510 | - $orig_ven = $orig_event->get_many_related('Venue'); |
|
| 511 | - // reset the ID and modify other details to make it clear this is a dupe |
|
| 512 | - $new_event->set('EVT_ID', 0); |
|
| 513 | - $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso'); |
|
| 514 | - $new_event->set('EVT_name', $new_name); |
|
| 515 | - $new_event->set( |
|
| 516 | - 'EVT_slug', |
|
| 517 | - wp_unique_post_slug( |
|
| 518 | - sanitize_title($orig_event->name()), |
|
| 519 | - 0, |
|
| 520 | - 'publish', |
|
| 521 | - 'espresso_events', |
|
| 522 | - 0 |
|
| 523 | - ) |
|
| 524 | - ); |
|
| 525 | - $new_event->set('status', 'draft'); |
|
| 526 | - // duplicate discussion settings |
|
| 527 | - $new_event->set('comment_status', $orig_event->get('comment_status')); |
|
| 528 | - $new_event->set('ping_status', $orig_event->get('ping_status')); |
|
| 529 | - // save the new event |
|
| 530 | - $new_event->save(); |
|
| 531 | - // venues |
|
| 532 | - foreach ($orig_ven as $ven) { |
|
| 533 | - $new_event->_add_relation_to($ven, 'Venue'); |
|
| 534 | - } |
|
| 535 | - $new_event->save(); |
|
| 536 | - // now we need to get the question group relations and handle that |
|
| 537 | - // first primary question groups |
|
| 538 | - $orig_primary_qgs = $orig_event->get_many_related( |
|
| 539 | - 'Question_Group', |
|
| 540 | - [['Event_Question_Group.EQG_primary' => true]] |
|
| 541 | - ); |
|
| 542 | - if (! empty($orig_primary_qgs)) { |
|
| 543 | - foreach ($orig_primary_qgs as $id => $obj) { |
|
| 544 | - if ($obj instanceof EE_Question_Group) { |
|
| 545 | - $new_event->_add_relation_to($obj, 'Question_Group', ['EQG_primary' => true]); |
|
| 546 | - } |
|
| 547 | - } |
|
| 548 | - } |
|
| 549 | - // next additional attendee question groups |
|
| 550 | - $orig_additional_qgs = $orig_event->get_many_related( |
|
| 551 | - 'Question_Group', |
|
| 552 | - [['Event_Question_Group.EQG_additional' => true]] |
|
| 553 | - ); |
|
| 554 | - if (! empty($orig_additional_qgs)) { |
|
| 555 | - foreach ($orig_additional_qgs as $id => $obj) { |
|
| 556 | - if ($obj instanceof EE_Question_Group) { |
|
| 557 | - $new_event->_add_relation_to($obj, 'Question_Group', ['EQG_additional' => true]); |
|
| 558 | - } |
|
| 559 | - } |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - $new_event->save(); |
|
| 563 | - |
|
| 564 | - // k now that we have the new event saved we can loop through the datetimes and start adding relations. |
|
| 565 | - $cloned_tickets = array(); |
|
| 566 | - foreach ($orig_datetimes as $orig_dtt) { |
|
| 567 | - if (! $orig_dtt instanceof EE_Datetime) { |
|
| 568 | - continue; |
|
| 569 | - } |
|
| 570 | - $new_dtt = clone $orig_dtt; |
|
| 571 | - $orig_tkts = $orig_dtt->tickets(); |
|
| 572 | - // save new dtt then add to event |
|
| 573 | - $new_dtt->set('DTT_ID', 0); |
|
| 574 | - $new_dtt->set('DTT_sold', 0); |
|
| 575 | - $new_dtt->set_reserved(0); |
|
| 576 | - $new_dtt->save(); |
|
| 577 | - $new_event->_add_relation_to($new_dtt, 'Datetime'); |
|
| 578 | - $new_event->save(); |
|
| 579 | - // now let's get the ticket relations setup. |
|
| 580 | - foreach ((array) $orig_tkts as $orig_tkt) { |
|
| 581 | - // it's possible a datetime will have no tickets so let's verify we HAVE a ticket first. |
|
| 582 | - if (! $orig_tkt instanceof EE_Ticket) { |
|
| 583 | - continue; |
|
| 584 | - } |
|
| 585 | - // is this ticket archived? If it is then let's skip |
|
| 586 | - if ($orig_tkt->get('TKT_deleted')) { |
|
| 587 | - continue; |
|
| 588 | - } |
|
| 589 | - // does this original ticket already exist in the clone_tickets cache? |
|
| 590 | - // If so we'll just use the new ticket from it. |
|
| 591 | - if (isset($cloned_tickets[ $orig_tkt->ID() ])) { |
|
| 592 | - $new_tkt = $cloned_tickets[ $orig_tkt->ID() ]; |
|
| 593 | - } else { |
|
| 594 | - $new_tkt = clone $orig_tkt; |
|
| 595 | - // get relations on the $orig_tkt that we need to setup. |
|
| 596 | - $orig_prices = $orig_tkt->prices(); |
|
| 597 | - $new_tkt->set('TKT_ID', 0); |
|
| 598 | - $new_tkt->set('TKT_sold', 0); |
|
| 599 | - $new_tkt->set('TKT_reserved', 0); |
|
| 600 | - $new_tkt->save(); // make sure new ticket has ID. |
|
| 601 | - // price relations on new ticket need to be setup. |
|
| 602 | - foreach ($orig_prices as $orig_price) { |
|
| 603 | - $new_price = clone $orig_price; |
|
| 604 | - $new_price->set('PRC_ID', 0); |
|
| 605 | - $new_price->save(); |
|
| 606 | - $new_tkt->_add_relation_to($new_price, 'Price'); |
|
| 607 | - $new_tkt->save(); |
|
| 608 | - } |
|
| 609 | - |
|
| 610 | - do_action( |
|
| 611 | - 'AHEE__Extend_Events_Admin_Page___duplicate_event__duplicate_ticket__after', |
|
| 612 | - $orig_tkt, |
|
| 613 | - $new_tkt, |
|
| 614 | - $orig_prices, |
|
| 615 | - $orig_event, |
|
| 616 | - $orig_dtt, |
|
| 617 | - $new_dtt |
|
| 618 | - ); |
|
| 619 | - } |
|
| 620 | - // k now we can add the new ticket as a relation to the new datetime |
|
| 621 | - // and make sure its added to our cached $cloned_tickets array |
|
| 622 | - // for use with later datetimes that have the same ticket. |
|
| 623 | - $new_dtt->_add_relation_to($new_tkt, 'Ticket'); |
|
| 624 | - $new_dtt->save(); |
|
| 625 | - $cloned_tickets[ $orig_tkt->ID() ] = $new_tkt; |
|
| 626 | - } |
|
| 627 | - } |
|
| 628 | - // clone taxonomy information |
|
| 629 | - $taxonomies_to_clone_with = apply_filters( |
|
| 630 | - 'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone', |
|
| 631 | - array('espresso_event_categories', 'espresso_event_type', 'post_tag') |
|
| 632 | - ); |
|
| 633 | - // get terms for original event (notice) |
|
| 634 | - $orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with); |
|
| 635 | - // loop through terms and add them to new event. |
|
| 636 | - foreach ($orig_terms as $term) { |
|
| 637 | - wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true); |
|
| 638 | - } |
|
| 639 | - |
|
| 640 | - // duplicate other core WP_Post items for this event. |
|
| 641 | - // post thumbnail (feature image). |
|
| 642 | - $feature_image_id = get_post_thumbnail_id($orig_event->ID()); |
|
| 643 | - if ($feature_image_id) { |
|
| 644 | - update_post_meta($new_event->ID(), '_thumbnail_id', $feature_image_id); |
|
| 645 | - } |
|
| 646 | - |
|
| 647 | - // duplicate page_template setting |
|
| 648 | - $page_template = get_post_meta($orig_event->ID(), '_wp_page_template', true); |
|
| 649 | - if ($page_template) { |
|
| 650 | - update_post_meta($new_event->ID(), '_wp_page_template', $page_template); |
|
| 651 | - } |
|
| 652 | - |
|
| 653 | - do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event); |
|
| 654 | - // now let's redirect to the edit page for this duplicated event if we have a new event id. |
|
| 655 | - if ($new_event->ID()) { |
|
| 656 | - $redirect_args = array( |
|
| 657 | - 'post' => $new_event->ID(), |
|
| 658 | - 'action' => 'edit', |
|
| 659 | - ); |
|
| 660 | - EE_Error::add_success( |
|
| 661 | - esc_html__( |
|
| 662 | - 'Event successfully duplicated. Please review the details below and make any necessary edits', |
|
| 663 | - 'event_espresso' |
|
| 664 | - ) |
|
| 665 | - ); |
|
| 666 | - } else { |
|
| 667 | - $redirect_args = array( |
|
| 668 | - 'action' => 'default', |
|
| 669 | - ); |
|
| 670 | - EE_Error::add_error( |
|
| 671 | - esc_html__('Not able to duplicate event. Something went wrong.', 'event_espresso'), |
|
| 672 | - __FILE__, |
|
| 673 | - __FUNCTION__, |
|
| 674 | - __LINE__ |
|
| 675 | - ); |
|
| 676 | - } |
|
| 677 | - $this->_redirect_after_action(false, '', '', $redirect_args, true); |
|
| 678 | - } |
|
| 679 | - |
|
| 680 | - |
|
| 681 | - /** |
|
| 682 | - * Generates output for the import page. |
|
| 683 | - * |
|
| 684 | - * @throws DomainException |
|
| 685 | - */ |
|
| 686 | - protected function _import_page() |
|
| 687 | - { |
|
| 688 | - $title = esc_html__('Import', 'event_espresso'); |
|
| 689 | - $intro = esc_html__( |
|
| 690 | - 'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ', |
|
| 691 | - 'event_espresso' |
|
| 692 | - ); |
|
| 693 | - $form_url = EVENTS_ADMIN_URL; |
|
| 694 | - $action = 'import_events'; |
|
| 695 | - $type = 'csv'; |
|
| 696 | - $this->_template_args['form'] = EE_Import::instance()->upload_form( |
|
| 697 | - $title, |
|
| 698 | - $intro, |
|
| 699 | - $form_url, |
|
| 700 | - $action, |
|
| 701 | - $type |
|
| 702 | - ); |
|
| 703 | - $this->_template_args['sample_file_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 704 | - array('action' => 'sample_export_file'), |
|
| 705 | - $this->_admin_base_url |
|
| 706 | - ); |
|
| 707 | - $content = EEH_Template::display_template( |
|
| 708 | - EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php', |
|
| 709 | - $this->_template_args, |
|
| 710 | - true |
|
| 711 | - ); |
|
| 712 | - $this->_template_args['admin_page_content'] = $content; |
|
| 713 | - $this->display_admin_page_with_sidebar(); |
|
| 714 | - } |
|
| 715 | - |
|
| 716 | - |
|
| 717 | - /** |
|
| 718 | - * _import_events |
|
| 719 | - * This handles displaying the screen and running imports for importing events. |
|
| 720 | - * |
|
| 721 | - * @return void |
|
| 722 | - */ |
|
| 723 | - protected function _import_events() |
|
| 724 | - { |
|
| 725 | - require_once(EE_CLASSES . 'EE_Import.class.php'); |
|
| 726 | - $success = EE_Import::instance()->import(); |
|
| 727 | - $this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true); |
|
| 728 | - } |
|
| 729 | - |
|
| 730 | - |
|
| 731 | - /** |
|
| 732 | - * _events_export |
|
| 733 | - * Will export all (or just the given event) to a Excel compatible file. |
|
| 734 | - * |
|
| 735 | - * @access protected |
|
| 736 | - * @return void |
|
| 737 | - */ |
|
| 738 | - protected function _events_export() |
|
| 739 | - { |
|
| 740 | - if (isset($this->_req_data['EVT_ID'])) { |
|
| 741 | - $event_ids = $this->_req_data['EVT_ID']; |
|
| 742 | - } elseif (isset($this->_req_data['EVT_IDs'])) { |
|
| 743 | - $event_ids = $this->_req_data['EVT_IDs']; |
|
| 744 | - } else { |
|
| 745 | - $event_ids = null; |
|
| 746 | - } |
|
| 747 | - // todo: I don't like doing this but it'll do until we modify EE_Export Class. |
|
| 748 | - $new_request_args = array( |
|
| 749 | - 'export' => 'report', |
|
| 750 | - 'action' => 'all_event_data', |
|
| 751 | - 'EVT_ID' => $event_ids, |
|
| 752 | - ); |
|
| 753 | - $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
| 754 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 755 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 756 | - $EE_Export = EE_Export::instance($this->_req_data); |
|
| 757 | - $EE_Export->export(); |
|
| 758 | - } |
|
| 759 | - } |
|
| 760 | - |
|
| 761 | - |
|
| 762 | - /** |
|
| 763 | - * handle category exports() |
|
| 764 | - * |
|
| 765 | - * @return void |
|
| 766 | - */ |
|
| 767 | - protected function _categories_export() |
|
| 768 | - { |
|
| 769 | - // todo: I don't like doing this but it'll do until we modify EE_Export Class. |
|
| 770 | - $new_request_args = array( |
|
| 771 | - 'export' => 'report', |
|
| 772 | - 'action' => 'categories', |
|
| 773 | - 'category_ids' => $this->_req_data['EVT_CAT_ID'], |
|
| 774 | - ); |
|
| 775 | - $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
| 776 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 777 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 778 | - $EE_Export = EE_Export::instance($this->_req_data); |
|
| 779 | - $EE_Export->export(); |
|
| 780 | - } |
|
| 781 | - } |
|
| 782 | - |
|
| 783 | - |
|
| 784 | - /** |
|
| 785 | - * Creates a sample CSV file for importing |
|
| 786 | - */ |
|
| 787 | - protected function _sample_export_file() |
|
| 788 | - { |
|
| 789 | - // require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 790 | - EE_Export::instance()->export_sample(); |
|
| 791 | - } |
|
| 792 | - |
|
| 793 | - |
|
| 794 | - /************* Template Settings *************/ |
|
| 795 | - /** |
|
| 796 | - * Generates template settings page output |
|
| 797 | - * |
|
| 798 | - * @throws DomainException |
|
| 799 | - * @throws EE_Error |
|
| 800 | - */ |
|
| 801 | - protected function _template_settings() |
|
| 802 | - { |
|
| 803 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
| 804 | - /** |
|
| 805 | - * Note leaving this filter in for backward compatibility this was moved in 4.6.x |
|
| 806 | - * from General_Settings_Admin_Page to here. |
|
| 807 | - */ |
|
| 808 | - $this->_template_args = apply_filters( |
|
| 809 | - 'FHEE__General_Settings_Admin_Page__template_settings__template_args', |
|
| 810 | - $this->_template_args |
|
| 811 | - ); |
|
| 812 | - $this->_set_add_edit_form_tags('update_template_settings'); |
|
| 813 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 814 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 815 | - EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php', |
|
| 816 | - $this->_template_args, |
|
| 817 | - true |
|
| 818 | - ); |
|
| 819 | - $this->display_admin_page_with_sidebar(); |
|
| 820 | - } |
|
| 821 | - |
|
| 822 | - |
|
| 823 | - /** |
|
| 824 | - * Handler for updating template settings. |
|
| 825 | - * |
|
| 826 | - * @throws InvalidInterfaceException |
|
| 827 | - * @throws InvalidDataTypeException |
|
| 828 | - * @throws InvalidArgumentException |
|
| 829 | - */ |
|
| 830 | - protected function _update_template_settings() |
|
| 831 | - { |
|
| 832 | - /** |
|
| 833 | - * Note leaving this filter in for backward compatibility this was moved in 4.6.x |
|
| 834 | - * from General_Settings_Admin_Page to here. |
|
| 835 | - */ |
|
| 836 | - EE_Registry::instance()->CFG->template_settings = apply_filters( |
|
| 837 | - 'FHEE__General_Settings_Admin_Page__update_template_settings__data', |
|
| 838 | - EE_Registry::instance()->CFG->template_settings, |
|
| 839 | - $this->_req_data |
|
| 840 | - ); |
|
| 841 | - // update custom post type slugs and detect if we need to flush rewrite rules |
|
| 842 | - $old_slug = EE_Registry::instance()->CFG->core->event_cpt_slug; |
|
| 843 | - EE_Registry::instance()->CFG->core->event_cpt_slug = empty($this->_req_data['event_cpt_slug']) |
|
| 844 | - ? EE_Registry::instance()->CFG->core->event_cpt_slug |
|
| 845 | - : EEH_URL::slugify($this->_req_data['event_cpt_slug'], 'events'); |
|
| 846 | - $what = 'Template Settings'; |
|
| 847 | - $success = $this->_update_espresso_configuration( |
|
| 848 | - $what, |
|
| 849 | - EE_Registry::instance()->CFG->template_settings, |
|
| 850 | - __FILE__, |
|
| 851 | - __FUNCTION__, |
|
| 852 | - __LINE__ |
|
| 853 | - ); |
|
| 854 | - if (EE_Registry::instance()->CFG->core->event_cpt_slug != $old_slug) { |
|
| 855 | - /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */ |
|
| 856 | - $rewrite_rules = LoaderFactory::getLoader()->getShared( |
|
| 857 | - 'EventEspresso\core\domain\services\custom_post_types\RewriteRules' |
|
| 858 | - ); |
|
| 859 | - $rewrite_rules->flush(); |
|
| 860 | - } |
|
| 861 | - $this->_redirect_after_action($success, $what, 'updated', array('action' => 'template_settings')); |
|
| 862 | - } |
|
| 863 | - |
|
| 864 | - |
|
| 865 | - /** |
|
| 866 | - * _premium_event_editor_meta_boxes |
|
| 867 | - * add all metaboxes related to the event_editor |
|
| 868 | - * |
|
| 869 | - * @access protected |
|
| 870 | - * @return void |
|
| 871 | - * @throws EE_Error |
|
| 872 | - */ |
|
| 873 | - protected function _premium_event_editor_meta_boxes() |
|
| 874 | - { |
|
| 875 | - $this->verify_cpt_object(); |
|
| 876 | - add_meta_box( |
|
| 877 | - 'espresso_event_editor_event_options', |
|
| 878 | - esc_html__('Event Registration Options', 'event_espresso'), |
|
| 879 | - array($this, 'registration_options_meta_box'), |
|
| 880 | - $this->page_slug, |
|
| 881 | - 'side', |
|
| 882 | - 'core' |
|
| 883 | - ); |
|
| 884 | - } |
|
| 885 | - |
|
| 886 | - |
|
| 887 | - /** |
|
| 888 | - * override caf metabox |
|
| 889 | - * |
|
| 890 | - * @return void |
|
| 891 | - * @throws DomainException |
|
| 892 | - */ |
|
| 893 | - public function registration_options_meta_box() |
|
| 894 | - { |
|
| 895 | - $yes_no_values = array( |
|
| 896 | - array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')), |
|
| 897 | - array('id' => false, 'text' => esc_html__('No', 'event_espresso')), |
|
| 898 | - ); |
|
| 899 | - $default_reg_status_values = EEM_Registration::reg_status_array( |
|
| 900 | - array( |
|
| 901 | - EEM_Registration::status_id_cancelled, |
|
| 902 | - EEM_Registration::status_id_declined, |
|
| 903 | - EEM_Registration::status_id_incomplete, |
|
| 904 | - EEM_Registration::status_id_wait_list, |
|
| 905 | - ), |
|
| 906 | - true |
|
| 907 | - ); |
|
| 908 | - $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false); |
|
| 909 | - $template_args['_event'] = $this->_cpt_model_obj; |
|
| 910 | - $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
|
| 911 | - $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
| 912 | - 'default_reg_status', |
|
| 913 | - $default_reg_status_values, |
|
| 914 | - $this->_cpt_model_obj->default_registration_status() |
|
| 915 | - ); |
|
| 916 | - $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
| 917 | - 'display_desc', |
|
| 918 | - $yes_no_values, |
|
| 919 | - $this->_cpt_model_obj->display_description() |
|
| 920 | - ); |
|
| 921 | - $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
| 922 | - 'display_ticket_selector', |
|
| 923 | - $yes_no_values, |
|
| 924 | - $this->_cpt_model_obj->display_ticket_selector(), |
|
| 925 | - '', |
|
| 926 | - '', |
|
| 927 | - false |
|
| 928 | - ); |
|
| 929 | - $template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input( |
|
| 930 | - 'EVT_default_registration_status', |
|
| 931 | - $default_reg_status_values, |
|
| 932 | - $this->_cpt_model_obj->default_registration_status() |
|
| 933 | - ); |
|
| 934 | - $template_args['additional_registration_options'] = apply_filters( |
|
| 935 | - 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', |
|
| 936 | - '', |
|
| 937 | - $template_args, |
|
| 938 | - $yes_no_values, |
|
| 939 | - $default_reg_status_values |
|
| 940 | - ); |
|
| 941 | - EEH_Template::display_template( |
|
| 942 | - EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
| 943 | - $template_args |
|
| 944 | - ); |
|
| 945 | - } |
|
| 946 | - |
|
| 947 | - |
|
| 948 | - |
|
| 949 | - /** |
|
| 950 | - * wp_list_table_mods for caf |
|
| 951 | - * ============================ |
|
| 952 | - */ |
|
| 953 | - /** |
|
| 954 | - * hook into list table filters and provide filters for caffeinated list table |
|
| 955 | - * |
|
| 956 | - * @param array $old_filters any existing filters present |
|
| 957 | - * @param array $list_table_obj the list table object |
|
| 958 | - * @return array new filters |
|
| 959 | - */ |
|
| 960 | - public function list_table_filters($old_filters, $list_table_obj) |
|
| 961 | - { |
|
| 962 | - $filters = array(); |
|
| 963 | - // first month/year filters |
|
| 964 | - $filters[] = $this->espresso_event_months_dropdown(); |
|
| 965 | - $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
| 966 | - // active status dropdown |
|
| 967 | - if ($status !== 'draft') { |
|
| 968 | - $filters[] = $this->active_status_dropdown( |
|
| 969 | - isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : '' |
|
| 970 | - ); |
|
| 971 | - $filters[] = $this->venuesDropdown( |
|
| 972 | - isset($this->_req_data['venue']) ? $this->_req_data['venue'] : '' |
|
| 973 | - ); |
|
| 974 | - } |
|
| 975 | - // category filter |
|
| 976 | - $filters[] = $this->category_dropdown(); |
|
| 977 | - return array_merge($old_filters, $filters); |
|
| 978 | - } |
|
| 979 | - |
|
| 980 | - |
|
| 981 | - /** |
|
| 982 | - * espresso_event_months_dropdown |
|
| 983 | - * |
|
| 984 | - * @access public |
|
| 985 | - * @return string dropdown listing month/year selections for events. |
|
| 986 | - */ |
|
| 987 | - public function espresso_event_months_dropdown() |
|
| 988 | - { |
|
| 989 | - // what we need to do is get all PRIMARY datetimes for all events to filter on. |
|
| 990 | - // Note we need to include any other filters that are set! |
|
| 991 | - $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
| 992 | - // categories? |
|
| 993 | - $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0 |
|
| 994 | - ? $this->_req_data['EVT_CAT'] |
|
| 995 | - : null; |
|
| 996 | - // active status? |
|
| 997 | - $active_status = isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : null; |
|
| 998 | - $cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : ''; |
|
| 999 | - return EEH_Form_Fields::generate_event_months_dropdown($cur_date, $status, $category, $active_status); |
|
| 1000 | - } |
|
| 1001 | - |
|
| 1002 | - |
|
| 1003 | - /** |
|
| 1004 | - * returns a list of "active" statuses on the event |
|
| 1005 | - * |
|
| 1006 | - * @param string $current_value whatever the current active status is |
|
| 1007 | - * @return string |
|
| 1008 | - */ |
|
| 1009 | - public function active_status_dropdown($current_value = '') |
|
| 1010 | - { |
|
| 1011 | - $select_name = 'active_status'; |
|
| 1012 | - $values = array( |
|
| 1013 | - 'none' => esc_html__('Show Active/Inactive', 'event_espresso'), |
|
| 1014 | - 'active' => esc_html__('Active', 'event_espresso'), |
|
| 1015 | - 'upcoming' => esc_html__('Upcoming', 'event_espresso'), |
|
| 1016 | - 'expired' => esc_html__('Expired', 'event_espresso'), |
|
| 1017 | - 'inactive' => esc_html__('Inactive', 'event_espresso'), |
|
| 1018 | - ); |
|
| 1019 | - |
|
| 1020 | - return EEH_Form_Fields::select_input($select_name, $values, $current_value, '', 'wide'); |
|
| 1021 | - } |
|
| 1022 | - |
|
| 1023 | - /** |
|
| 1024 | - * returns a list of "venues" |
|
| 1025 | - * |
|
| 1026 | - * @param string $current_value whatever the current active status is |
|
| 1027 | - * @return string |
|
| 1028 | - */ |
|
| 1029 | - protected function venuesDropdown($current_value = '') |
|
| 1030 | - { |
|
| 1031 | - $select_name = 'venue'; |
|
| 1032 | - $values = array( |
|
| 1033 | - '' => esc_html__('All Venues', 'event_espresso'), |
|
| 1034 | - ); |
|
| 1035 | - // populate the list of venues. |
|
| 1036 | - $venue_model = EE_Registry::instance()->load_model('Venue'); |
|
| 1037 | - $venues = $venue_model->get_all(array('order_by' => array('VNU_name' => 'ASC'))); |
|
| 1038 | - |
|
| 1039 | - foreach ($venues as $venue) { |
|
| 1040 | - $values[ $venue->ID() ] = $venue->name(); |
|
| 1041 | - } |
|
| 1042 | - |
|
| 1043 | - return EEH_Form_Fields::select_input($select_name, $values, $current_value, '', 'wide'); |
|
| 1044 | - } |
|
| 1045 | - |
|
| 1046 | - |
|
| 1047 | - /** |
|
| 1048 | - * output a dropdown of the categories for the category filter on the event admin list table |
|
| 1049 | - * |
|
| 1050 | - * @access public |
|
| 1051 | - * @return string html |
|
| 1052 | - */ |
|
| 1053 | - public function category_dropdown() |
|
| 1054 | - { |
|
| 1055 | - $cur_cat = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1; |
|
| 1056 | - return EEH_Form_Fields::generate_event_category_dropdown($cur_cat); |
|
| 1057 | - } |
|
| 1058 | - |
|
| 1059 | - |
|
| 1060 | - /** |
|
| 1061 | - * get total number of events today |
|
| 1062 | - * |
|
| 1063 | - * @access public |
|
| 1064 | - * @return int |
|
| 1065 | - * @throws EE_Error |
|
| 1066 | - */ |
|
| 1067 | - public function total_events_today() |
|
| 1068 | - { |
|
| 1069 | - $start = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1070 | - 'DTT_EVT_start', |
|
| 1071 | - date('Y-m-d') . ' 00:00:00', |
|
| 1072 | - 'Y-m-d H:i:s', |
|
| 1073 | - 'UTC' |
|
| 1074 | - ); |
|
| 1075 | - $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1076 | - 'DTT_EVT_start', |
|
| 1077 | - date('Y-m-d') . ' 23:59:59', |
|
| 1078 | - 'Y-m-d H:i:s', |
|
| 1079 | - 'UTC' |
|
| 1080 | - ); |
|
| 1081 | - $where = array( |
|
| 1082 | - 'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)), |
|
| 1083 | - ); |
|
| 1084 | - $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
| 1085 | - return $count; |
|
| 1086 | - } |
|
| 1087 | - |
|
| 1088 | - |
|
| 1089 | - /** |
|
| 1090 | - * get total number of events this month |
|
| 1091 | - * |
|
| 1092 | - * @access public |
|
| 1093 | - * @return int |
|
| 1094 | - * @throws EE_Error |
|
| 1095 | - */ |
|
| 1096 | - public function total_events_this_month() |
|
| 1097 | - { |
|
| 1098 | - // Dates |
|
| 1099 | - $this_year_r = date('Y'); |
|
| 1100 | - $this_month_r = date('m'); |
|
| 1101 | - $days_this_month = date('t'); |
|
| 1102 | - $start = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1103 | - 'DTT_EVT_start', |
|
| 1104 | - $this_year_r . '-' . $this_month_r . '-01 00:00:00', |
|
| 1105 | - 'Y-m-d H:i:s', |
|
| 1106 | - 'UTC' |
|
| 1107 | - ); |
|
| 1108 | - $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1109 | - 'DTT_EVT_start', |
|
| 1110 | - $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59', |
|
| 1111 | - 'Y-m-d H:i:s', |
|
| 1112 | - 'UTC' |
|
| 1113 | - ); |
|
| 1114 | - $where = array( |
|
| 1115 | - 'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)), |
|
| 1116 | - ); |
|
| 1117 | - $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
| 1118 | - return $count; |
|
| 1119 | - } |
|
| 1120 | - |
|
| 1121 | - |
|
| 1122 | - /** DEFAULT TICKETS STUFF **/ |
|
| 1123 | - |
|
| 1124 | - /** |
|
| 1125 | - * Output default tickets list table view. |
|
| 1126 | - */ |
|
| 1127 | - public function _tickets_overview_list_table() |
|
| 1128 | - { |
|
| 1129 | - $this->_search_btn_label = esc_html__('Tickets', 'event_espresso'); |
|
| 1130 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1131 | - } |
|
| 1132 | - |
|
| 1133 | - |
|
| 1134 | - /** |
|
| 1135 | - * @param int $per_page |
|
| 1136 | - * @param bool $count |
|
| 1137 | - * @param bool $trashed |
|
| 1138 | - * @return \EE_Soft_Delete_Base_Class[]|int |
|
| 1139 | - */ |
|
| 1140 | - public function get_default_tickets($per_page = 10, $count = false, $trashed = false) |
|
| 1141 | - { |
|
| 1142 | - $orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby']; |
|
| 1143 | - $order = empty($this->_req_data['order']) ? 'ASC' : $this->_req_data['order']; |
|
| 1144 | - switch ($orderby) { |
|
| 1145 | - case 'TKT_name': |
|
| 1146 | - $orderby = array('TKT_name' => $order); |
|
| 1147 | - break; |
|
| 1148 | - case 'TKT_price': |
|
| 1149 | - $orderby = array('TKT_price' => $order); |
|
| 1150 | - break; |
|
| 1151 | - case 'TKT_uses': |
|
| 1152 | - $orderby = array('TKT_uses' => $order); |
|
| 1153 | - break; |
|
| 1154 | - case 'TKT_min': |
|
| 1155 | - $orderby = array('TKT_min' => $order); |
|
| 1156 | - break; |
|
| 1157 | - case 'TKT_max': |
|
| 1158 | - $orderby = array('TKT_max' => $order); |
|
| 1159 | - break; |
|
| 1160 | - case 'TKT_qty': |
|
| 1161 | - $orderby = array('TKT_qty' => $order); |
|
| 1162 | - break; |
|
| 1163 | - } |
|
| 1164 | - $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
| 1165 | - ? $this->_req_data['paged'] |
|
| 1166 | - : 1; |
|
| 1167 | - $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
| 1168 | - ? $this->_req_data['perpage'] |
|
| 1169 | - : $per_page; |
|
| 1170 | - $_where = array( |
|
| 1171 | - 'TKT_is_default' => 1, |
|
| 1172 | - 'TKT_deleted' => $trashed, |
|
| 1173 | - ); |
|
| 1174 | - $offset = ($current_page - 1) * $per_page; |
|
| 1175 | - $limit = array($offset, $per_page); |
|
| 1176 | - if (isset($this->_req_data['s'])) { |
|
| 1177 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 1178 | - $_where['OR'] = array( |
|
| 1179 | - 'TKT_name' => array('LIKE', $sstr), |
|
| 1180 | - 'TKT_description' => array('LIKE', $sstr), |
|
| 1181 | - ); |
|
| 1182 | - } |
|
| 1183 | - $query_params = array( |
|
| 1184 | - $_where, |
|
| 1185 | - 'order_by' => $orderby, |
|
| 1186 | - 'limit' => $limit, |
|
| 1187 | - 'group_by' => 'TKT_ID', |
|
| 1188 | - ); |
|
| 1189 | - if ($count) { |
|
| 1190 | - return EEM_Ticket::instance()->count_deleted_and_undeleted(array($_where)); |
|
| 1191 | - } else { |
|
| 1192 | - return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params); |
|
| 1193 | - } |
|
| 1194 | - } |
|
| 1195 | - |
|
| 1196 | - |
|
| 1197 | - /** |
|
| 1198 | - * @param bool $trash |
|
| 1199 | - * @throws EE_Error |
|
| 1200 | - */ |
|
| 1201 | - protected function _trash_or_restore_ticket($trash = false) |
|
| 1202 | - { |
|
| 1203 | - $success = 1; |
|
| 1204 | - $TKT = EEM_Ticket::instance(); |
|
| 1205 | - // checkboxes? |
|
| 1206 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 1207 | - // if array has more than one element then success message should be plural |
|
| 1208 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 1209 | - // cycle thru the boxes |
|
| 1210 | - while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 1211 | - if ($trash) { |
|
| 1212 | - if (! $TKT->delete_by_ID($TKT_ID)) { |
|
| 1213 | - $success = 0; |
|
| 1214 | - } |
|
| 1215 | - } else { |
|
| 1216 | - if (! $TKT->restore_by_ID($TKT_ID)) { |
|
| 1217 | - $success = 0; |
|
| 1218 | - } |
|
| 1219 | - } |
|
| 1220 | - } |
|
| 1221 | - } else { |
|
| 1222 | - // grab single id and trash |
|
| 1223 | - $TKT_ID = absint($this->_req_data['TKT_ID']); |
|
| 1224 | - if ($trash) { |
|
| 1225 | - if (! $TKT->delete_by_ID($TKT_ID)) { |
|
| 1226 | - $success = 0; |
|
| 1227 | - } |
|
| 1228 | - } else { |
|
| 1229 | - if (! $TKT->restore_by_ID($TKT_ID)) { |
|
| 1230 | - $success = 0; |
|
| 1231 | - } |
|
| 1232 | - } |
|
| 1233 | - } |
|
| 1234 | - $action_desc = $trash ? 'moved to the trash' : 'restored'; |
|
| 1235 | - $query_args = array( |
|
| 1236 | - 'action' => 'ticket_list_table', |
|
| 1237 | - 'status' => $trash ? '' : 'trashed', |
|
| 1238 | - ); |
|
| 1239 | - $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args); |
|
| 1240 | - } |
|
| 1241 | - |
|
| 1242 | - |
|
| 1243 | - /** |
|
| 1244 | - * Handles trashing default ticket. |
|
| 1245 | - */ |
|
| 1246 | - protected function _delete_ticket() |
|
| 1247 | - { |
|
| 1248 | - $success = 1; |
|
| 1249 | - // checkboxes? |
|
| 1250 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 1251 | - // if array has more than one element then success message should be plural |
|
| 1252 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 1253 | - // cycle thru the boxes |
|
| 1254 | - while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 1255 | - // delete |
|
| 1256 | - if (! $this->_delete_the_ticket($TKT_ID)) { |
|
| 1257 | - $success = 0; |
|
| 1258 | - } |
|
| 1259 | - } |
|
| 1260 | - } else { |
|
| 1261 | - // grab single id and trash |
|
| 1262 | - $TKT_ID = absint($this->_req_data['TKT_ID']); |
|
| 1263 | - if (! $this->_delete_the_ticket($TKT_ID)) { |
|
| 1264 | - $success = 0; |
|
| 1265 | - } |
|
| 1266 | - } |
|
| 1267 | - $action_desc = 'deleted'; |
|
| 1268 | - $query_args = array( |
|
| 1269 | - 'action' => 'ticket_list_table', |
|
| 1270 | - 'status' => 'trashed', |
|
| 1271 | - ); |
|
| 1272 | - // fail safe. If the default ticket count === 1 then we need to redirect to event overview. |
|
| 1273 | - if (EEM_Ticket::instance()->count_deleted_and_undeleted( |
|
| 1274 | - array(array('TKT_is_default' => 1)), |
|
| 1275 | - 'TKT_ID', |
|
| 1276 | - true |
|
| 1277 | - ) |
|
| 1278 | - ) { |
|
| 1279 | - $query_args = array(); |
|
| 1280 | - } |
|
| 1281 | - $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args); |
|
| 1282 | - } |
|
| 1283 | - |
|
| 1284 | - |
|
| 1285 | - /** |
|
| 1286 | - * @param int $TKT_ID |
|
| 1287 | - * @return bool|int |
|
| 1288 | - * @throws EE_Error |
|
| 1289 | - */ |
|
| 1290 | - protected function _delete_the_ticket($TKT_ID) |
|
| 1291 | - { |
|
| 1292 | - $tkt = EEM_Ticket::instance()->get_one_by_ID($TKT_ID); |
|
| 1293 | - $tkt->_remove_relations('Datetime'); |
|
| 1294 | - // delete all related prices first |
|
| 1295 | - $tkt->delete_related_permanently('Price'); |
|
| 1296 | - return $tkt->delete_permanently(); |
|
| 1297 | - } |
|
| 19 | + /** |
|
| 20 | + * Extend_Events_Admin_Page constructor. |
|
| 21 | + * |
|
| 22 | + * @param bool $routing |
|
| 23 | + */ |
|
| 24 | + public function __construct($routing = true) |
|
| 25 | + { |
|
| 26 | + parent::__construct($routing); |
|
| 27 | + if (! defined('EVENTS_CAF_TEMPLATE_PATH')) { |
|
| 28 | + define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/'); |
|
| 29 | + define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/'); |
|
| 30 | + define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/'); |
|
| 31 | + } |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * Sets routes. |
|
| 37 | + */ |
|
| 38 | + protected function _extend_page_config() |
|
| 39 | + { |
|
| 40 | + $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events'; |
|
| 41 | + // is there a evt_id in the request? |
|
| 42 | + $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID']) |
|
| 43 | + ? $this->_req_data['EVT_ID'] |
|
| 44 | + : 0; |
|
| 45 | + $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id; |
|
| 46 | + // tkt_id? |
|
| 47 | + $tkt_id = ! empty($this->_req_data['TKT_ID']) && ! is_array($this->_req_data['TKT_ID']) |
|
| 48 | + ? $this->_req_data['TKT_ID'] |
|
| 49 | + : 0; |
|
| 50 | + $new_page_routes = array( |
|
| 51 | + 'duplicate_event' => array( |
|
| 52 | + 'func' => '_duplicate_event', |
|
| 53 | + 'capability' => 'ee_edit_event', |
|
| 54 | + 'obj_id' => $evt_id, |
|
| 55 | + 'noheader' => true, |
|
| 56 | + ), |
|
| 57 | + 'ticket_list_table' => array( |
|
| 58 | + 'func' => '_tickets_overview_list_table', |
|
| 59 | + 'capability' => 'ee_read_default_tickets', |
|
| 60 | + ), |
|
| 61 | + 'trash_ticket' => array( |
|
| 62 | + 'func' => '_trash_or_restore_ticket', |
|
| 63 | + 'capability' => 'ee_delete_default_ticket', |
|
| 64 | + 'obj_id' => $tkt_id, |
|
| 65 | + 'noheader' => true, |
|
| 66 | + 'args' => array('trash' => true), |
|
| 67 | + ), |
|
| 68 | + 'trash_tickets' => array( |
|
| 69 | + 'func' => '_trash_or_restore_ticket', |
|
| 70 | + 'capability' => 'ee_delete_default_tickets', |
|
| 71 | + 'noheader' => true, |
|
| 72 | + 'args' => array('trash' => true), |
|
| 73 | + ), |
|
| 74 | + 'restore_ticket' => array( |
|
| 75 | + 'func' => '_trash_or_restore_ticket', |
|
| 76 | + 'capability' => 'ee_delete_default_ticket', |
|
| 77 | + 'obj_id' => $tkt_id, |
|
| 78 | + 'noheader' => true, |
|
| 79 | + ), |
|
| 80 | + 'restore_tickets' => array( |
|
| 81 | + 'func' => '_trash_or_restore_ticket', |
|
| 82 | + 'capability' => 'ee_delete_default_tickets', |
|
| 83 | + 'noheader' => true, |
|
| 84 | + ), |
|
| 85 | + 'delete_ticket' => array( |
|
| 86 | + 'func' => '_delete_ticket', |
|
| 87 | + 'capability' => 'ee_delete_default_ticket', |
|
| 88 | + 'obj_id' => $tkt_id, |
|
| 89 | + 'noheader' => true, |
|
| 90 | + ), |
|
| 91 | + 'delete_tickets' => array( |
|
| 92 | + 'func' => '_delete_ticket', |
|
| 93 | + 'capability' => 'ee_delete_default_tickets', |
|
| 94 | + 'noheader' => true, |
|
| 95 | + ), |
|
| 96 | + 'import_page' => array( |
|
| 97 | + 'func' => '_import_page', |
|
| 98 | + 'capability' => 'import', |
|
| 99 | + ), |
|
| 100 | + 'import' => array( |
|
| 101 | + 'func' => '_import_events', |
|
| 102 | + 'capability' => 'import', |
|
| 103 | + 'noheader' => true, |
|
| 104 | + ), |
|
| 105 | + 'import_events' => array( |
|
| 106 | + 'func' => '_import_events', |
|
| 107 | + 'capability' => 'import', |
|
| 108 | + 'noheader' => true, |
|
| 109 | + ), |
|
| 110 | + 'export_events' => array( |
|
| 111 | + 'func' => '_events_export', |
|
| 112 | + 'capability' => 'export', |
|
| 113 | + 'noheader' => true, |
|
| 114 | + ), |
|
| 115 | + 'export_categories' => array( |
|
| 116 | + 'func' => '_categories_export', |
|
| 117 | + 'capability' => 'export', |
|
| 118 | + 'noheader' => true, |
|
| 119 | + ), |
|
| 120 | + 'sample_export_file' => array( |
|
| 121 | + 'func' => '_sample_export_file', |
|
| 122 | + 'capability' => 'export', |
|
| 123 | + 'noheader' => true, |
|
| 124 | + ), |
|
| 125 | + 'update_template_settings' => array( |
|
| 126 | + 'func' => '_update_template_settings', |
|
| 127 | + 'capability' => 'manage_options', |
|
| 128 | + 'noheader' => true, |
|
| 129 | + ), |
|
| 130 | + ); |
|
| 131 | + $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
| 132 | + // partial route/config override |
|
| 133 | + $this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes; |
|
| 134 | + $this->_page_config['create_new']['metaboxes'][] = '_premium_event_editor_meta_boxes'; |
|
| 135 | + $this->_page_config['create_new']['qtips'][] = 'EE_Event_Editor_Tips'; |
|
| 136 | + $this->_page_config['edit']['qtips'][] = 'EE_Event_Editor_Tips'; |
|
| 137 | + $this->_page_config['edit']['metaboxes'][] = '_premium_event_editor_meta_boxes'; |
|
| 138 | + $this->_page_config['default']['list_table'] = 'Extend_Events_Admin_List_Table'; |
|
| 139 | + // add tickets tab but only if there are more than one default ticket! |
|
| 140 | + $tkt_count = EEM_Ticket::instance()->count_deleted_and_undeleted( |
|
| 141 | + array(array('TKT_is_default' => 1)), |
|
| 142 | + 'TKT_ID', |
|
| 143 | + true |
|
| 144 | + ); |
|
| 145 | + if ($tkt_count > 1) { |
|
| 146 | + $new_page_config = array( |
|
| 147 | + 'ticket_list_table' => array( |
|
| 148 | + 'nav' => array( |
|
| 149 | + 'label' => esc_html__('Default Tickets', 'event_espresso'), |
|
| 150 | + 'order' => 60, |
|
| 151 | + ), |
|
| 152 | + 'list_table' => 'Tickets_List_Table', |
|
| 153 | + 'require_nonce' => false, |
|
| 154 | + ), |
|
| 155 | + ); |
|
| 156 | + } |
|
| 157 | + // template settings |
|
| 158 | + $new_page_config['template_settings'] = array( |
|
| 159 | + 'nav' => array( |
|
| 160 | + 'label' => esc_html__('Templates', 'event_espresso'), |
|
| 161 | + 'order' => 30, |
|
| 162 | + ), |
|
| 163 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 164 | + 'help_tabs' => array( |
|
| 165 | + 'general_settings_templates_help_tab' => array( |
|
| 166 | + 'title' => esc_html__('Templates', 'event_espresso'), |
|
| 167 | + 'filename' => 'general_settings_templates', |
|
| 168 | + ), |
|
| 169 | + ), |
|
| 170 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 171 | + // 'help_tour' => array('Templates_Help_Tour'), |
|
| 172 | + 'require_nonce' => false, |
|
| 173 | + ); |
|
| 174 | + $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
| 175 | + // add filters and actions |
|
| 176 | + // modifying _views |
|
| 177 | + add_filter( |
|
| 178 | + 'FHEE_event_datetime_metabox_add_additional_date_time_template', |
|
| 179 | + array($this, 'add_additional_datetime_button'), |
|
| 180 | + 10, |
|
| 181 | + 2 |
|
| 182 | + ); |
|
| 183 | + add_filter( |
|
| 184 | + 'FHEE_event_datetime_metabox_clone_button_template', |
|
| 185 | + array($this, 'add_datetime_clone_button'), |
|
| 186 | + 10, |
|
| 187 | + 2 |
|
| 188 | + ); |
|
| 189 | + add_filter( |
|
| 190 | + 'FHEE_event_datetime_metabox_timezones_template', |
|
| 191 | + array($this, 'datetime_timezones_template'), |
|
| 192 | + 10, |
|
| 193 | + 2 |
|
| 194 | + ); |
|
| 195 | + // filters for event list table |
|
| 196 | + add_filter('FHEE__Extend_Events_Admin_List_Table__filters', array($this, 'list_table_filters'), 10, 2); |
|
| 197 | + add_filter( |
|
| 198 | + 'FHEE__Events_Admin_List_Table__column_actions__action_links', |
|
| 199 | + array($this, 'extra_list_table_actions'), |
|
| 200 | + 10, |
|
| 201 | + 2 |
|
| 202 | + ); |
|
| 203 | + // legend item |
|
| 204 | + add_filter('FHEE__Events_Admin_Page___event_legend_items__items', array($this, 'additional_legend_items')); |
|
| 205 | + add_action('admin_init', array($this, 'admin_init')); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * admin_init |
|
| 211 | + */ |
|
| 212 | + public function admin_init() |
|
| 213 | + { |
|
| 214 | + EE_Registry::$i18n_js_strings = array_merge( |
|
| 215 | + EE_Registry::$i18n_js_strings, |
|
| 216 | + array( |
|
| 217 | + 'image_confirm' => esc_html__( |
|
| 218 | + 'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
|
| 219 | + 'event_espresso' |
|
| 220 | + ), |
|
| 221 | + 'event_starts_on' => esc_html__('Event Starts on', 'event_espresso'), |
|
| 222 | + 'event_ends_on' => esc_html__('Event Ends on', 'event_espresso'), |
|
| 223 | + 'event_datetime_actions' => esc_html__('Actions', 'event_espresso'), |
|
| 224 | + 'event_clone_dt_msg' => esc_html__('Clone this Event Date and Time', 'event_espresso'), |
|
| 225 | + 'remove_event_dt_msg' => esc_html__('Remove this Event Time', 'event_espresso'), |
|
| 226 | + ) |
|
| 227 | + ); |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * Add per page screen options to the default ticket list table view. |
|
| 233 | + */ |
|
| 234 | + protected function _add_screen_options_ticket_list_table() |
|
| 235 | + { |
|
| 236 | + $this->_per_page_screen_option(); |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * @param string $return |
|
| 242 | + * @param int $id |
|
| 243 | + * @param string $new_title |
|
| 244 | + * @param string $new_slug |
|
| 245 | + * @return string |
|
| 246 | + */ |
|
| 247 | + public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
|
| 248 | + { |
|
| 249 | + $return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug); |
|
| 250 | + // make sure this is only when editing |
|
| 251 | + if (! empty($id)) { |
|
| 252 | + $href = EE_Admin_Page::add_query_args_and_nonce( |
|
| 253 | + array('action' => 'duplicate_event', 'EVT_ID' => $id), |
|
| 254 | + $this->_admin_base_url |
|
| 255 | + ); |
|
| 256 | + $title = esc_attr__('Duplicate Event', 'event_espresso'); |
|
| 257 | + $return .= '<a href="' |
|
| 258 | + . $href |
|
| 259 | + . '" title="' |
|
| 260 | + . $title |
|
| 261 | + . '" id="ee-duplicate-event-button" class="button button-small" value="duplicate_event">' |
|
| 262 | + . $title |
|
| 263 | + . '</a>'; |
|
| 264 | + } |
|
| 265 | + return $return; |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + |
|
| 269 | + /** |
|
| 270 | + * Set the list table views for the default ticket list table view. |
|
| 271 | + */ |
|
| 272 | + public function _set_list_table_views_ticket_list_table() |
|
| 273 | + { |
|
| 274 | + $this->_views = array( |
|
| 275 | + 'all' => array( |
|
| 276 | + 'slug' => 'all', |
|
| 277 | + 'label' => esc_html__('All', 'event_espresso'), |
|
| 278 | + 'count' => 0, |
|
| 279 | + 'bulk_action' => array( |
|
| 280 | + 'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 281 | + ), |
|
| 282 | + ), |
|
| 283 | + 'trashed' => array( |
|
| 284 | + 'slug' => 'trashed', |
|
| 285 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 286 | + 'count' => 0, |
|
| 287 | + 'bulk_action' => array( |
|
| 288 | + 'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'), |
|
| 289 | + 'delete_tickets' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 290 | + ), |
|
| 291 | + ), |
|
| 292 | + ); |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + |
|
| 296 | + /** |
|
| 297 | + * Enqueue scripts and styles for the event editor. |
|
| 298 | + */ |
|
| 299 | + public function load_scripts_styles_edit() |
|
| 300 | + { |
|
| 301 | + wp_register_script( |
|
| 302 | + 'ee-event-editor-heartbeat', |
|
| 303 | + EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js', |
|
| 304 | + array('ee_admin_js', 'heartbeat'), |
|
| 305 | + EVENT_ESPRESSO_VERSION, |
|
| 306 | + true |
|
| 307 | + ); |
|
| 308 | + wp_enqueue_script('ee-accounting'); |
|
| 309 | + // styles |
|
| 310 | + wp_enqueue_style('espresso-ui-theme'); |
|
| 311 | + wp_enqueue_script('event_editor_js'); |
|
| 312 | + wp_enqueue_script('ee-event-editor-heartbeat'); |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + |
|
| 316 | + /** |
|
| 317 | + * Returns template for the additional datetime. |
|
| 318 | + * |
|
| 319 | + * @param $template |
|
| 320 | + * @param $template_args |
|
| 321 | + * @return mixed |
|
| 322 | + * @throws DomainException |
|
| 323 | + */ |
|
| 324 | + public function add_additional_datetime_button($template, $template_args) |
|
| 325 | + { |
|
| 326 | + return EEH_Template::display_template( |
|
| 327 | + EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php', |
|
| 328 | + $template_args, |
|
| 329 | + true |
|
| 330 | + ); |
|
| 331 | + } |
|
| 332 | + |
|
| 333 | + |
|
| 334 | + /** |
|
| 335 | + * Returns the template for cloning a datetime. |
|
| 336 | + * |
|
| 337 | + * @param $template |
|
| 338 | + * @param $template_args |
|
| 339 | + * @return mixed |
|
| 340 | + * @throws DomainException |
|
| 341 | + */ |
|
| 342 | + public function add_datetime_clone_button($template, $template_args) |
|
| 343 | + { |
|
| 344 | + return EEH_Template::display_template( |
|
| 345 | + EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php', |
|
| 346 | + $template_args, |
|
| 347 | + true |
|
| 348 | + ); |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * Returns the template for datetime timezones. |
|
| 354 | + * |
|
| 355 | + * @param $template |
|
| 356 | + * @param $template_args |
|
| 357 | + * @return mixed |
|
| 358 | + * @throws DomainException |
|
| 359 | + */ |
|
| 360 | + public function datetime_timezones_template($template, $template_args) |
|
| 361 | + { |
|
| 362 | + return EEH_Template::display_template( |
|
| 363 | + EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php', |
|
| 364 | + $template_args, |
|
| 365 | + true |
|
| 366 | + ); |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + |
|
| 370 | + /** |
|
| 371 | + * Sets the views for the default list table view. |
|
| 372 | + */ |
|
| 373 | + protected function _set_list_table_views_default() |
|
| 374 | + { |
|
| 375 | + parent::_set_list_table_views_default(); |
|
| 376 | + $new_views = array( |
|
| 377 | + 'today' => array( |
|
| 378 | + 'slug' => 'today', |
|
| 379 | + 'label' => esc_html__('Today', 'event_espresso'), |
|
| 380 | + 'count' => $this->total_events_today(), |
|
| 381 | + 'bulk_action' => array( |
|
| 382 | + 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 383 | + ), |
|
| 384 | + ), |
|
| 385 | + 'month' => array( |
|
| 386 | + 'slug' => 'month', |
|
| 387 | + 'label' => esc_html__('This Month', 'event_espresso'), |
|
| 388 | + 'count' => $this->total_events_this_month(), |
|
| 389 | + 'bulk_action' => array( |
|
| 390 | + 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 391 | + ), |
|
| 392 | + ), |
|
| 393 | + ); |
|
| 394 | + $this->_views = array_merge($this->_views, $new_views); |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + |
|
| 398 | + /** |
|
| 399 | + * Returns the extra action links for the default list table view. |
|
| 400 | + * |
|
| 401 | + * @param array $action_links |
|
| 402 | + * @param \EE_Event $event |
|
| 403 | + * @return array |
|
| 404 | + * @throws EE_Error |
|
| 405 | + */ |
|
| 406 | + public function extra_list_table_actions(array $action_links, \EE_Event $event) |
|
| 407 | + { |
|
| 408 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 409 | + 'ee_read_registrations', |
|
| 410 | + 'espresso_registrations_reports', |
|
| 411 | + $event->ID() |
|
| 412 | + ) |
|
| 413 | + ) { |
|
| 414 | + $reports_query_args = array( |
|
| 415 | + 'action' => 'reports', |
|
| 416 | + 'EVT_ID' => $event->ID(), |
|
| 417 | + ); |
|
| 418 | + $reports_link = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL); |
|
| 419 | + $action_links[] = '<a href="' |
|
| 420 | + . $reports_link |
|
| 421 | + . '" title="' |
|
| 422 | + . esc_attr__('View Report', 'event_espresso') |
|
| 423 | + . '"><div class="dashicons dashicons-chart-bar"></div></a>' |
|
| 424 | + . "\n\t"; |
|
| 425 | + } |
|
| 426 | + if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
| 427 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 428 | + $action_links[] = EEH_MSG_Template::get_message_action_link( |
|
| 429 | + 'see_notifications_for', |
|
| 430 | + null, |
|
| 431 | + array('EVT_ID' => $event->ID()) |
|
| 432 | + ); |
|
| 433 | + } |
|
| 434 | + return $action_links; |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + |
|
| 438 | + /** |
|
| 439 | + * @param $items |
|
| 440 | + * @return mixed |
|
| 441 | + */ |
|
| 442 | + public function additional_legend_items($items) |
|
| 443 | + { |
|
| 444 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 445 | + 'ee_read_registrations', |
|
| 446 | + 'espresso_registrations_reports' |
|
| 447 | + ) |
|
| 448 | + ) { |
|
| 449 | + $items['reports'] = array( |
|
| 450 | + 'class' => 'dashicons dashicons-chart-bar', |
|
| 451 | + 'desc' => esc_html__('Event Reports', 'event_espresso'), |
|
| 452 | + ); |
|
| 453 | + } |
|
| 454 | + if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
| 455 | + $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
| 456 | + if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) { |
|
| 457 | + $items['view_related_messages'] = array( |
|
| 458 | + 'class' => $related_for_icon['css_class'], |
|
| 459 | + 'desc' => $related_for_icon['label'], |
|
| 460 | + ); |
|
| 461 | + } |
|
| 462 | + } |
|
| 463 | + return $items; |
|
| 464 | + } |
|
| 465 | + |
|
| 466 | + |
|
| 467 | + /** |
|
| 468 | + * This is the callback method for the duplicate event route |
|
| 469 | + * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them |
|
| 470 | + * into a new event. We add a hook so that any plugins that add extra event details can hook into this |
|
| 471 | + * action. Note that the dupe will have **DUPLICATE** as its title and slug. |
|
| 472 | + * After duplication the redirect is to the new event edit page. |
|
| 473 | + * |
|
| 474 | + * @return void |
|
| 475 | + * @access protected |
|
| 476 | + * @throws EE_Error If EE_Event is not available with given ID |
|
| 477 | + */ |
|
| 478 | + protected function _duplicate_event() |
|
| 479 | + { |
|
| 480 | + // first make sure the ID for the event is in the request. |
|
| 481 | + // If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?) |
|
| 482 | + if (! isset($this->_req_data['EVT_ID'])) { |
|
| 483 | + EE_Error::add_error( |
|
| 484 | + esc_html__( |
|
| 485 | + 'In order to duplicate an event an Event ID is required. None was given.', |
|
| 486 | + 'event_espresso' |
|
| 487 | + ), |
|
| 488 | + __FILE__, |
|
| 489 | + __FUNCTION__, |
|
| 490 | + __LINE__ |
|
| 491 | + ); |
|
| 492 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 493 | + return; |
|
| 494 | + } |
|
| 495 | + // k we've got EVT_ID so let's use that to get the event we'll duplicate |
|
| 496 | + $orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']); |
|
| 497 | + if (! $orig_event instanceof EE_Event) { |
|
| 498 | + throw new EE_Error( |
|
| 499 | + sprintf( |
|
| 500 | + esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'), |
|
| 501 | + $this->_req_data['EVT_ID'] |
|
| 502 | + ) |
|
| 503 | + ); |
|
| 504 | + } |
|
| 505 | + // k now let's clone the $orig_event before getting relations |
|
| 506 | + $new_event = clone $orig_event; |
|
| 507 | + // original datetimes |
|
| 508 | + $orig_datetimes = $orig_event->get_many_related('Datetime'); |
|
| 509 | + // other original relations |
|
| 510 | + $orig_ven = $orig_event->get_many_related('Venue'); |
|
| 511 | + // reset the ID and modify other details to make it clear this is a dupe |
|
| 512 | + $new_event->set('EVT_ID', 0); |
|
| 513 | + $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso'); |
|
| 514 | + $new_event->set('EVT_name', $new_name); |
|
| 515 | + $new_event->set( |
|
| 516 | + 'EVT_slug', |
|
| 517 | + wp_unique_post_slug( |
|
| 518 | + sanitize_title($orig_event->name()), |
|
| 519 | + 0, |
|
| 520 | + 'publish', |
|
| 521 | + 'espresso_events', |
|
| 522 | + 0 |
|
| 523 | + ) |
|
| 524 | + ); |
|
| 525 | + $new_event->set('status', 'draft'); |
|
| 526 | + // duplicate discussion settings |
|
| 527 | + $new_event->set('comment_status', $orig_event->get('comment_status')); |
|
| 528 | + $new_event->set('ping_status', $orig_event->get('ping_status')); |
|
| 529 | + // save the new event |
|
| 530 | + $new_event->save(); |
|
| 531 | + // venues |
|
| 532 | + foreach ($orig_ven as $ven) { |
|
| 533 | + $new_event->_add_relation_to($ven, 'Venue'); |
|
| 534 | + } |
|
| 535 | + $new_event->save(); |
|
| 536 | + // now we need to get the question group relations and handle that |
|
| 537 | + // first primary question groups |
|
| 538 | + $orig_primary_qgs = $orig_event->get_many_related( |
|
| 539 | + 'Question_Group', |
|
| 540 | + [['Event_Question_Group.EQG_primary' => true]] |
|
| 541 | + ); |
|
| 542 | + if (! empty($orig_primary_qgs)) { |
|
| 543 | + foreach ($orig_primary_qgs as $id => $obj) { |
|
| 544 | + if ($obj instanceof EE_Question_Group) { |
|
| 545 | + $new_event->_add_relation_to($obj, 'Question_Group', ['EQG_primary' => true]); |
|
| 546 | + } |
|
| 547 | + } |
|
| 548 | + } |
|
| 549 | + // next additional attendee question groups |
|
| 550 | + $orig_additional_qgs = $orig_event->get_many_related( |
|
| 551 | + 'Question_Group', |
|
| 552 | + [['Event_Question_Group.EQG_additional' => true]] |
|
| 553 | + ); |
|
| 554 | + if (! empty($orig_additional_qgs)) { |
|
| 555 | + foreach ($orig_additional_qgs as $id => $obj) { |
|
| 556 | + if ($obj instanceof EE_Question_Group) { |
|
| 557 | + $new_event->_add_relation_to($obj, 'Question_Group', ['EQG_additional' => true]); |
|
| 558 | + } |
|
| 559 | + } |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + $new_event->save(); |
|
| 563 | + |
|
| 564 | + // k now that we have the new event saved we can loop through the datetimes and start adding relations. |
|
| 565 | + $cloned_tickets = array(); |
|
| 566 | + foreach ($orig_datetimes as $orig_dtt) { |
|
| 567 | + if (! $orig_dtt instanceof EE_Datetime) { |
|
| 568 | + continue; |
|
| 569 | + } |
|
| 570 | + $new_dtt = clone $orig_dtt; |
|
| 571 | + $orig_tkts = $orig_dtt->tickets(); |
|
| 572 | + // save new dtt then add to event |
|
| 573 | + $new_dtt->set('DTT_ID', 0); |
|
| 574 | + $new_dtt->set('DTT_sold', 0); |
|
| 575 | + $new_dtt->set_reserved(0); |
|
| 576 | + $new_dtt->save(); |
|
| 577 | + $new_event->_add_relation_to($new_dtt, 'Datetime'); |
|
| 578 | + $new_event->save(); |
|
| 579 | + // now let's get the ticket relations setup. |
|
| 580 | + foreach ((array) $orig_tkts as $orig_tkt) { |
|
| 581 | + // it's possible a datetime will have no tickets so let's verify we HAVE a ticket first. |
|
| 582 | + if (! $orig_tkt instanceof EE_Ticket) { |
|
| 583 | + continue; |
|
| 584 | + } |
|
| 585 | + // is this ticket archived? If it is then let's skip |
|
| 586 | + if ($orig_tkt->get('TKT_deleted')) { |
|
| 587 | + continue; |
|
| 588 | + } |
|
| 589 | + // does this original ticket already exist in the clone_tickets cache? |
|
| 590 | + // If so we'll just use the new ticket from it. |
|
| 591 | + if (isset($cloned_tickets[ $orig_tkt->ID() ])) { |
|
| 592 | + $new_tkt = $cloned_tickets[ $orig_tkt->ID() ]; |
|
| 593 | + } else { |
|
| 594 | + $new_tkt = clone $orig_tkt; |
|
| 595 | + // get relations on the $orig_tkt that we need to setup. |
|
| 596 | + $orig_prices = $orig_tkt->prices(); |
|
| 597 | + $new_tkt->set('TKT_ID', 0); |
|
| 598 | + $new_tkt->set('TKT_sold', 0); |
|
| 599 | + $new_tkt->set('TKT_reserved', 0); |
|
| 600 | + $new_tkt->save(); // make sure new ticket has ID. |
|
| 601 | + // price relations on new ticket need to be setup. |
|
| 602 | + foreach ($orig_prices as $orig_price) { |
|
| 603 | + $new_price = clone $orig_price; |
|
| 604 | + $new_price->set('PRC_ID', 0); |
|
| 605 | + $new_price->save(); |
|
| 606 | + $new_tkt->_add_relation_to($new_price, 'Price'); |
|
| 607 | + $new_tkt->save(); |
|
| 608 | + } |
|
| 609 | + |
|
| 610 | + do_action( |
|
| 611 | + 'AHEE__Extend_Events_Admin_Page___duplicate_event__duplicate_ticket__after', |
|
| 612 | + $orig_tkt, |
|
| 613 | + $new_tkt, |
|
| 614 | + $orig_prices, |
|
| 615 | + $orig_event, |
|
| 616 | + $orig_dtt, |
|
| 617 | + $new_dtt |
|
| 618 | + ); |
|
| 619 | + } |
|
| 620 | + // k now we can add the new ticket as a relation to the new datetime |
|
| 621 | + // and make sure its added to our cached $cloned_tickets array |
|
| 622 | + // for use with later datetimes that have the same ticket. |
|
| 623 | + $new_dtt->_add_relation_to($new_tkt, 'Ticket'); |
|
| 624 | + $new_dtt->save(); |
|
| 625 | + $cloned_tickets[ $orig_tkt->ID() ] = $new_tkt; |
|
| 626 | + } |
|
| 627 | + } |
|
| 628 | + // clone taxonomy information |
|
| 629 | + $taxonomies_to_clone_with = apply_filters( |
|
| 630 | + 'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone', |
|
| 631 | + array('espresso_event_categories', 'espresso_event_type', 'post_tag') |
|
| 632 | + ); |
|
| 633 | + // get terms for original event (notice) |
|
| 634 | + $orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with); |
|
| 635 | + // loop through terms and add them to new event. |
|
| 636 | + foreach ($orig_terms as $term) { |
|
| 637 | + wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true); |
|
| 638 | + } |
|
| 639 | + |
|
| 640 | + // duplicate other core WP_Post items for this event. |
|
| 641 | + // post thumbnail (feature image). |
|
| 642 | + $feature_image_id = get_post_thumbnail_id($orig_event->ID()); |
|
| 643 | + if ($feature_image_id) { |
|
| 644 | + update_post_meta($new_event->ID(), '_thumbnail_id', $feature_image_id); |
|
| 645 | + } |
|
| 646 | + |
|
| 647 | + // duplicate page_template setting |
|
| 648 | + $page_template = get_post_meta($orig_event->ID(), '_wp_page_template', true); |
|
| 649 | + if ($page_template) { |
|
| 650 | + update_post_meta($new_event->ID(), '_wp_page_template', $page_template); |
|
| 651 | + } |
|
| 652 | + |
|
| 653 | + do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event); |
|
| 654 | + // now let's redirect to the edit page for this duplicated event if we have a new event id. |
|
| 655 | + if ($new_event->ID()) { |
|
| 656 | + $redirect_args = array( |
|
| 657 | + 'post' => $new_event->ID(), |
|
| 658 | + 'action' => 'edit', |
|
| 659 | + ); |
|
| 660 | + EE_Error::add_success( |
|
| 661 | + esc_html__( |
|
| 662 | + 'Event successfully duplicated. Please review the details below and make any necessary edits', |
|
| 663 | + 'event_espresso' |
|
| 664 | + ) |
|
| 665 | + ); |
|
| 666 | + } else { |
|
| 667 | + $redirect_args = array( |
|
| 668 | + 'action' => 'default', |
|
| 669 | + ); |
|
| 670 | + EE_Error::add_error( |
|
| 671 | + esc_html__('Not able to duplicate event. Something went wrong.', 'event_espresso'), |
|
| 672 | + __FILE__, |
|
| 673 | + __FUNCTION__, |
|
| 674 | + __LINE__ |
|
| 675 | + ); |
|
| 676 | + } |
|
| 677 | + $this->_redirect_after_action(false, '', '', $redirect_args, true); |
|
| 678 | + } |
|
| 679 | + |
|
| 680 | + |
|
| 681 | + /** |
|
| 682 | + * Generates output for the import page. |
|
| 683 | + * |
|
| 684 | + * @throws DomainException |
|
| 685 | + */ |
|
| 686 | + protected function _import_page() |
|
| 687 | + { |
|
| 688 | + $title = esc_html__('Import', 'event_espresso'); |
|
| 689 | + $intro = esc_html__( |
|
| 690 | + 'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ', |
|
| 691 | + 'event_espresso' |
|
| 692 | + ); |
|
| 693 | + $form_url = EVENTS_ADMIN_URL; |
|
| 694 | + $action = 'import_events'; |
|
| 695 | + $type = 'csv'; |
|
| 696 | + $this->_template_args['form'] = EE_Import::instance()->upload_form( |
|
| 697 | + $title, |
|
| 698 | + $intro, |
|
| 699 | + $form_url, |
|
| 700 | + $action, |
|
| 701 | + $type |
|
| 702 | + ); |
|
| 703 | + $this->_template_args['sample_file_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 704 | + array('action' => 'sample_export_file'), |
|
| 705 | + $this->_admin_base_url |
|
| 706 | + ); |
|
| 707 | + $content = EEH_Template::display_template( |
|
| 708 | + EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php', |
|
| 709 | + $this->_template_args, |
|
| 710 | + true |
|
| 711 | + ); |
|
| 712 | + $this->_template_args['admin_page_content'] = $content; |
|
| 713 | + $this->display_admin_page_with_sidebar(); |
|
| 714 | + } |
|
| 715 | + |
|
| 716 | + |
|
| 717 | + /** |
|
| 718 | + * _import_events |
|
| 719 | + * This handles displaying the screen and running imports for importing events. |
|
| 720 | + * |
|
| 721 | + * @return void |
|
| 722 | + */ |
|
| 723 | + protected function _import_events() |
|
| 724 | + { |
|
| 725 | + require_once(EE_CLASSES . 'EE_Import.class.php'); |
|
| 726 | + $success = EE_Import::instance()->import(); |
|
| 727 | + $this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true); |
|
| 728 | + } |
|
| 729 | + |
|
| 730 | + |
|
| 731 | + /** |
|
| 732 | + * _events_export |
|
| 733 | + * Will export all (or just the given event) to a Excel compatible file. |
|
| 734 | + * |
|
| 735 | + * @access protected |
|
| 736 | + * @return void |
|
| 737 | + */ |
|
| 738 | + protected function _events_export() |
|
| 739 | + { |
|
| 740 | + if (isset($this->_req_data['EVT_ID'])) { |
|
| 741 | + $event_ids = $this->_req_data['EVT_ID']; |
|
| 742 | + } elseif (isset($this->_req_data['EVT_IDs'])) { |
|
| 743 | + $event_ids = $this->_req_data['EVT_IDs']; |
|
| 744 | + } else { |
|
| 745 | + $event_ids = null; |
|
| 746 | + } |
|
| 747 | + // todo: I don't like doing this but it'll do until we modify EE_Export Class. |
|
| 748 | + $new_request_args = array( |
|
| 749 | + 'export' => 'report', |
|
| 750 | + 'action' => 'all_event_data', |
|
| 751 | + 'EVT_ID' => $event_ids, |
|
| 752 | + ); |
|
| 753 | + $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
| 754 | + if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 755 | + require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 756 | + $EE_Export = EE_Export::instance($this->_req_data); |
|
| 757 | + $EE_Export->export(); |
|
| 758 | + } |
|
| 759 | + } |
|
| 760 | + |
|
| 761 | + |
|
| 762 | + /** |
|
| 763 | + * handle category exports() |
|
| 764 | + * |
|
| 765 | + * @return void |
|
| 766 | + */ |
|
| 767 | + protected function _categories_export() |
|
| 768 | + { |
|
| 769 | + // todo: I don't like doing this but it'll do until we modify EE_Export Class. |
|
| 770 | + $new_request_args = array( |
|
| 771 | + 'export' => 'report', |
|
| 772 | + 'action' => 'categories', |
|
| 773 | + 'category_ids' => $this->_req_data['EVT_CAT_ID'], |
|
| 774 | + ); |
|
| 775 | + $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
| 776 | + if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 777 | + require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 778 | + $EE_Export = EE_Export::instance($this->_req_data); |
|
| 779 | + $EE_Export->export(); |
|
| 780 | + } |
|
| 781 | + } |
|
| 782 | + |
|
| 783 | + |
|
| 784 | + /** |
|
| 785 | + * Creates a sample CSV file for importing |
|
| 786 | + */ |
|
| 787 | + protected function _sample_export_file() |
|
| 788 | + { |
|
| 789 | + // require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 790 | + EE_Export::instance()->export_sample(); |
|
| 791 | + } |
|
| 792 | + |
|
| 793 | + |
|
| 794 | + /************* Template Settings *************/ |
|
| 795 | + /** |
|
| 796 | + * Generates template settings page output |
|
| 797 | + * |
|
| 798 | + * @throws DomainException |
|
| 799 | + * @throws EE_Error |
|
| 800 | + */ |
|
| 801 | + protected function _template_settings() |
|
| 802 | + { |
|
| 803 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
| 804 | + /** |
|
| 805 | + * Note leaving this filter in for backward compatibility this was moved in 4.6.x |
|
| 806 | + * from General_Settings_Admin_Page to here. |
|
| 807 | + */ |
|
| 808 | + $this->_template_args = apply_filters( |
|
| 809 | + 'FHEE__General_Settings_Admin_Page__template_settings__template_args', |
|
| 810 | + $this->_template_args |
|
| 811 | + ); |
|
| 812 | + $this->_set_add_edit_form_tags('update_template_settings'); |
|
| 813 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 814 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 815 | + EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php', |
|
| 816 | + $this->_template_args, |
|
| 817 | + true |
|
| 818 | + ); |
|
| 819 | + $this->display_admin_page_with_sidebar(); |
|
| 820 | + } |
|
| 821 | + |
|
| 822 | + |
|
| 823 | + /** |
|
| 824 | + * Handler for updating template settings. |
|
| 825 | + * |
|
| 826 | + * @throws InvalidInterfaceException |
|
| 827 | + * @throws InvalidDataTypeException |
|
| 828 | + * @throws InvalidArgumentException |
|
| 829 | + */ |
|
| 830 | + protected function _update_template_settings() |
|
| 831 | + { |
|
| 832 | + /** |
|
| 833 | + * Note leaving this filter in for backward compatibility this was moved in 4.6.x |
|
| 834 | + * from General_Settings_Admin_Page to here. |
|
| 835 | + */ |
|
| 836 | + EE_Registry::instance()->CFG->template_settings = apply_filters( |
|
| 837 | + 'FHEE__General_Settings_Admin_Page__update_template_settings__data', |
|
| 838 | + EE_Registry::instance()->CFG->template_settings, |
|
| 839 | + $this->_req_data |
|
| 840 | + ); |
|
| 841 | + // update custom post type slugs and detect if we need to flush rewrite rules |
|
| 842 | + $old_slug = EE_Registry::instance()->CFG->core->event_cpt_slug; |
|
| 843 | + EE_Registry::instance()->CFG->core->event_cpt_slug = empty($this->_req_data['event_cpt_slug']) |
|
| 844 | + ? EE_Registry::instance()->CFG->core->event_cpt_slug |
|
| 845 | + : EEH_URL::slugify($this->_req_data['event_cpt_slug'], 'events'); |
|
| 846 | + $what = 'Template Settings'; |
|
| 847 | + $success = $this->_update_espresso_configuration( |
|
| 848 | + $what, |
|
| 849 | + EE_Registry::instance()->CFG->template_settings, |
|
| 850 | + __FILE__, |
|
| 851 | + __FUNCTION__, |
|
| 852 | + __LINE__ |
|
| 853 | + ); |
|
| 854 | + if (EE_Registry::instance()->CFG->core->event_cpt_slug != $old_slug) { |
|
| 855 | + /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */ |
|
| 856 | + $rewrite_rules = LoaderFactory::getLoader()->getShared( |
|
| 857 | + 'EventEspresso\core\domain\services\custom_post_types\RewriteRules' |
|
| 858 | + ); |
|
| 859 | + $rewrite_rules->flush(); |
|
| 860 | + } |
|
| 861 | + $this->_redirect_after_action($success, $what, 'updated', array('action' => 'template_settings')); |
|
| 862 | + } |
|
| 863 | + |
|
| 864 | + |
|
| 865 | + /** |
|
| 866 | + * _premium_event_editor_meta_boxes |
|
| 867 | + * add all metaboxes related to the event_editor |
|
| 868 | + * |
|
| 869 | + * @access protected |
|
| 870 | + * @return void |
|
| 871 | + * @throws EE_Error |
|
| 872 | + */ |
|
| 873 | + protected function _premium_event_editor_meta_boxes() |
|
| 874 | + { |
|
| 875 | + $this->verify_cpt_object(); |
|
| 876 | + add_meta_box( |
|
| 877 | + 'espresso_event_editor_event_options', |
|
| 878 | + esc_html__('Event Registration Options', 'event_espresso'), |
|
| 879 | + array($this, 'registration_options_meta_box'), |
|
| 880 | + $this->page_slug, |
|
| 881 | + 'side', |
|
| 882 | + 'core' |
|
| 883 | + ); |
|
| 884 | + } |
|
| 885 | + |
|
| 886 | + |
|
| 887 | + /** |
|
| 888 | + * override caf metabox |
|
| 889 | + * |
|
| 890 | + * @return void |
|
| 891 | + * @throws DomainException |
|
| 892 | + */ |
|
| 893 | + public function registration_options_meta_box() |
|
| 894 | + { |
|
| 895 | + $yes_no_values = array( |
|
| 896 | + array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')), |
|
| 897 | + array('id' => false, 'text' => esc_html__('No', 'event_espresso')), |
|
| 898 | + ); |
|
| 899 | + $default_reg_status_values = EEM_Registration::reg_status_array( |
|
| 900 | + array( |
|
| 901 | + EEM_Registration::status_id_cancelled, |
|
| 902 | + EEM_Registration::status_id_declined, |
|
| 903 | + EEM_Registration::status_id_incomplete, |
|
| 904 | + EEM_Registration::status_id_wait_list, |
|
| 905 | + ), |
|
| 906 | + true |
|
| 907 | + ); |
|
| 908 | + $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false); |
|
| 909 | + $template_args['_event'] = $this->_cpt_model_obj; |
|
| 910 | + $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
|
| 911 | + $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
| 912 | + 'default_reg_status', |
|
| 913 | + $default_reg_status_values, |
|
| 914 | + $this->_cpt_model_obj->default_registration_status() |
|
| 915 | + ); |
|
| 916 | + $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
| 917 | + 'display_desc', |
|
| 918 | + $yes_no_values, |
|
| 919 | + $this->_cpt_model_obj->display_description() |
|
| 920 | + ); |
|
| 921 | + $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
| 922 | + 'display_ticket_selector', |
|
| 923 | + $yes_no_values, |
|
| 924 | + $this->_cpt_model_obj->display_ticket_selector(), |
|
| 925 | + '', |
|
| 926 | + '', |
|
| 927 | + false |
|
| 928 | + ); |
|
| 929 | + $template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input( |
|
| 930 | + 'EVT_default_registration_status', |
|
| 931 | + $default_reg_status_values, |
|
| 932 | + $this->_cpt_model_obj->default_registration_status() |
|
| 933 | + ); |
|
| 934 | + $template_args['additional_registration_options'] = apply_filters( |
|
| 935 | + 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', |
|
| 936 | + '', |
|
| 937 | + $template_args, |
|
| 938 | + $yes_no_values, |
|
| 939 | + $default_reg_status_values |
|
| 940 | + ); |
|
| 941 | + EEH_Template::display_template( |
|
| 942 | + EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
| 943 | + $template_args |
|
| 944 | + ); |
|
| 945 | + } |
|
| 946 | + |
|
| 947 | + |
|
| 948 | + |
|
| 949 | + /** |
|
| 950 | + * wp_list_table_mods for caf |
|
| 951 | + * ============================ |
|
| 952 | + */ |
|
| 953 | + /** |
|
| 954 | + * hook into list table filters and provide filters for caffeinated list table |
|
| 955 | + * |
|
| 956 | + * @param array $old_filters any existing filters present |
|
| 957 | + * @param array $list_table_obj the list table object |
|
| 958 | + * @return array new filters |
|
| 959 | + */ |
|
| 960 | + public function list_table_filters($old_filters, $list_table_obj) |
|
| 961 | + { |
|
| 962 | + $filters = array(); |
|
| 963 | + // first month/year filters |
|
| 964 | + $filters[] = $this->espresso_event_months_dropdown(); |
|
| 965 | + $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
| 966 | + // active status dropdown |
|
| 967 | + if ($status !== 'draft') { |
|
| 968 | + $filters[] = $this->active_status_dropdown( |
|
| 969 | + isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : '' |
|
| 970 | + ); |
|
| 971 | + $filters[] = $this->venuesDropdown( |
|
| 972 | + isset($this->_req_data['venue']) ? $this->_req_data['venue'] : '' |
|
| 973 | + ); |
|
| 974 | + } |
|
| 975 | + // category filter |
|
| 976 | + $filters[] = $this->category_dropdown(); |
|
| 977 | + return array_merge($old_filters, $filters); |
|
| 978 | + } |
|
| 979 | + |
|
| 980 | + |
|
| 981 | + /** |
|
| 982 | + * espresso_event_months_dropdown |
|
| 983 | + * |
|
| 984 | + * @access public |
|
| 985 | + * @return string dropdown listing month/year selections for events. |
|
| 986 | + */ |
|
| 987 | + public function espresso_event_months_dropdown() |
|
| 988 | + { |
|
| 989 | + // what we need to do is get all PRIMARY datetimes for all events to filter on. |
|
| 990 | + // Note we need to include any other filters that are set! |
|
| 991 | + $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
| 992 | + // categories? |
|
| 993 | + $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0 |
|
| 994 | + ? $this->_req_data['EVT_CAT'] |
|
| 995 | + : null; |
|
| 996 | + // active status? |
|
| 997 | + $active_status = isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : null; |
|
| 998 | + $cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : ''; |
|
| 999 | + return EEH_Form_Fields::generate_event_months_dropdown($cur_date, $status, $category, $active_status); |
|
| 1000 | + } |
|
| 1001 | + |
|
| 1002 | + |
|
| 1003 | + /** |
|
| 1004 | + * returns a list of "active" statuses on the event |
|
| 1005 | + * |
|
| 1006 | + * @param string $current_value whatever the current active status is |
|
| 1007 | + * @return string |
|
| 1008 | + */ |
|
| 1009 | + public function active_status_dropdown($current_value = '') |
|
| 1010 | + { |
|
| 1011 | + $select_name = 'active_status'; |
|
| 1012 | + $values = array( |
|
| 1013 | + 'none' => esc_html__('Show Active/Inactive', 'event_espresso'), |
|
| 1014 | + 'active' => esc_html__('Active', 'event_espresso'), |
|
| 1015 | + 'upcoming' => esc_html__('Upcoming', 'event_espresso'), |
|
| 1016 | + 'expired' => esc_html__('Expired', 'event_espresso'), |
|
| 1017 | + 'inactive' => esc_html__('Inactive', 'event_espresso'), |
|
| 1018 | + ); |
|
| 1019 | + |
|
| 1020 | + return EEH_Form_Fields::select_input($select_name, $values, $current_value, '', 'wide'); |
|
| 1021 | + } |
|
| 1022 | + |
|
| 1023 | + /** |
|
| 1024 | + * returns a list of "venues" |
|
| 1025 | + * |
|
| 1026 | + * @param string $current_value whatever the current active status is |
|
| 1027 | + * @return string |
|
| 1028 | + */ |
|
| 1029 | + protected function venuesDropdown($current_value = '') |
|
| 1030 | + { |
|
| 1031 | + $select_name = 'venue'; |
|
| 1032 | + $values = array( |
|
| 1033 | + '' => esc_html__('All Venues', 'event_espresso'), |
|
| 1034 | + ); |
|
| 1035 | + // populate the list of venues. |
|
| 1036 | + $venue_model = EE_Registry::instance()->load_model('Venue'); |
|
| 1037 | + $venues = $venue_model->get_all(array('order_by' => array('VNU_name' => 'ASC'))); |
|
| 1038 | + |
|
| 1039 | + foreach ($venues as $venue) { |
|
| 1040 | + $values[ $venue->ID() ] = $venue->name(); |
|
| 1041 | + } |
|
| 1042 | + |
|
| 1043 | + return EEH_Form_Fields::select_input($select_name, $values, $current_value, '', 'wide'); |
|
| 1044 | + } |
|
| 1045 | + |
|
| 1046 | + |
|
| 1047 | + /** |
|
| 1048 | + * output a dropdown of the categories for the category filter on the event admin list table |
|
| 1049 | + * |
|
| 1050 | + * @access public |
|
| 1051 | + * @return string html |
|
| 1052 | + */ |
|
| 1053 | + public function category_dropdown() |
|
| 1054 | + { |
|
| 1055 | + $cur_cat = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1; |
|
| 1056 | + return EEH_Form_Fields::generate_event_category_dropdown($cur_cat); |
|
| 1057 | + } |
|
| 1058 | + |
|
| 1059 | + |
|
| 1060 | + /** |
|
| 1061 | + * get total number of events today |
|
| 1062 | + * |
|
| 1063 | + * @access public |
|
| 1064 | + * @return int |
|
| 1065 | + * @throws EE_Error |
|
| 1066 | + */ |
|
| 1067 | + public function total_events_today() |
|
| 1068 | + { |
|
| 1069 | + $start = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1070 | + 'DTT_EVT_start', |
|
| 1071 | + date('Y-m-d') . ' 00:00:00', |
|
| 1072 | + 'Y-m-d H:i:s', |
|
| 1073 | + 'UTC' |
|
| 1074 | + ); |
|
| 1075 | + $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1076 | + 'DTT_EVT_start', |
|
| 1077 | + date('Y-m-d') . ' 23:59:59', |
|
| 1078 | + 'Y-m-d H:i:s', |
|
| 1079 | + 'UTC' |
|
| 1080 | + ); |
|
| 1081 | + $where = array( |
|
| 1082 | + 'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)), |
|
| 1083 | + ); |
|
| 1084 | + $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
| 1085 | + return $count; |
|
| 1086 | + } |
|
| 1087 | + |
|
| 1088 | + |
|
| 1089 | + /** |
|
| 1090 | + * get total number of events this month |
|
| 1091 | + * |
|
| 1092 | + * @access public |
|
| 1093 | + * @return int |
|
| 1094 | + * @throws EE_Error |
|
| 1095 | + */ |
|
| 1096 | + public function total_events_this_month() |
|
| 1097 | + { |
|
| 1098 | + // Dates |
|
| 1099 | + $this_year_r = date('Y'); |
|
| 1100 | + $this_month_r = date('m'); |
|
| 1101 | + $days_this_month = date('t'); |
|
| 1102 | + $start = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1103 | + 'DTT_EVT_start', |
|
| 1104 | + $this_year_r . '-' . $this_month_r . '-01 00:00:00', |
|
| 1105 | + 'Y-m-d H:i:s', |
|
| 1106 | + 'UTC' |
|
| 1107 | + ); |
|
| 1108 | + $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1109 | + 'DTT_EVT_start', |
|
| 1110 | + $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59', |
|
| 1111 | + 'Y-m-d H:i:s', |
|
| 1112 | + 'UTC' |
|
| 1113 | + ); |
|
| 1114 | + $where = array( |
|
| 1115 | + 'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)), |
|
| 1116 | + ); |
|
| 1117 | + $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
| 1118 | + return $count; |
|
| 1119 | + } |
|
| 1120 | + |
|
| 1121 | + |
|
| 1122 | + /** DEFAULT TICKETS STUFF **/ |
|
| 1123 | + |
|
| 1124 | + /** |
|
| 1125 | + * Output default tickets list table view. |
|
| 1126 | + */ |
|
| 1127 | + public function _tickets_overview_list_table() |
|
| 1128 | + { |
|
| 1129 | + $this->_search_btn_label = esc_html__('Tickets', 'event_espresso'); |
|
| 1130 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1131 | + } |
|
| 1132 | + |
|
| 1133 | + |
|
| 1134 | + /** |
|
| 1135 | + * @param int $per_page |
|
| 1136 | + * @param bool $count |
|
| 1137 | + * @param bool $trashed |
|
| 1138 | + * @return \EE_Soft_Delete_Base_Class[]|int |
|
| 1139 | + */ |
|
| 1140 | + public function get_default_tickets($per_page = 10, $count = false, $trashed = false) |
|
| 1141 | + { |
|
| 1142 | + $orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby']; |
|
| 1143 | + $order = empty($this->_req_data['order']) ? 'ASC' : $this->_req_data['order']; |
|
| 1144 | + switch ($orderby) { |
|
| 1145 | + case 'TKT_name': |
|
| 1146 | + $orderby = array('TKT_name' => $order); |
|
| 1147 | + break; |
|
| 1148 | + case 'TKT_price': |
|
| 1149 | + $orderby = array('TKT_price' => $order); |
|
| 1150 | + break; |
|
| 1151 | + case 'TKT_uses': |
|
| 1152 | + $orderby = array('TKT_uses' => $order); |
|
| 1153 | + break; |
|
| 1154 | + case 'TKT_min': |
|
| 1155 | + $orderby = array('TKT_min' => $order); |
|
| 1156 | + break; |
|
| 1157 | + case 'TKT_max': |
|
| 1158 | + $orderby = array('TKT_max' => $order); |
|
| 1159 | + break; |
|
| 1160 | + case 'TKT_qty': |
|
| 1161 | + $orderby = array('TKT_qty' => $order); |
|
| 1162 | + break; |
|
| 1163 | + } |
|
| 1164 | + $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
| 1165 | + ? $this->_req_data['paged'] |
|
| 1166 | + : 1; |
|
| 1167 | + $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
| 1168 | + ? $this->_req_data['perpage'] |
|
| 1169 | + : $per_page; |
|
| 1170 | + $_where = array( |
|
| 1171 | + 'TKT_is_default' => 1, |
|
| 1172 | + 'TKT_deleted' => $trashed, |
|
| 1173 | + ); |
|
| 1174 | + $offset = ($current_page - 1) * $per_page; |
|
| 1175 | + $limit = array($offset, $per_page); |
|
| 1176 | + if (isset($this->_req_data['s'])) { |
|
| 1177 | + $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 1178 | + $_where['OR'] = array( |
|
| 1179 | + 'TKT_name' => array('LIKE', $sstr), |
|
| 1180 | + 'TKT_description' => array('LIKE', $sstr), |
|
| 1181 | + ); |
|
| 1182 | + } |
|
| 1183 | + $query_params = array( |
|
| 1184 | + $_where, |
|
| 1185 | + 'order_by' => $orderby, |
|
| 1186 | + 'limit' => $limit, |
|
| 1187 | + 'group_by' => 'TKT_ID', |
|
| 1188 | + ); |
|
| 1189 | + if ($count) { |
|
| 1190 | + return EEM_Ticket::instance()->count_deleted_and_undeleted(array($_where)); |
|
| 1191 | + } else { |
|
| 1192 | + return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params); |
|
| 1193 | + } |
|
| 1194 | + } |
|
| 1195 | + |
|
| 1196 | + |
|
| 1197 | + /** |
|
| 1198 | + * @param bool $trash |
|
| 1199 | + * @throws EE_Error |
|
| 1200 | + */ |
|
| 1201 | + protected function _trash_or_restore_ticket($trash = false) |
|
| 1202 | + { |
|
| 1203 | + $success = 1; |
|
| 1204 | + $TKT = EEM_Ticket::instance(); |
|
| 1205 | + // checkboxes? |
|
| 1206 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 1207 | + // if array has more than one element then success message should be plural |
|
| 1208 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 1209 | + // cycle thru the boxes |
|
| 1210 | + while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 1211 | + if ($trash) { |
|
| 1212 | + if (! $TKT->delete_by_ID($TKT_ID)) { |
|
| 1213 | + $success = 0; |
|
| 1214 | + } |
|
| 1215 | + } else { |
|
| 1216 | + if (! $TKT->restore_by_ID($TKT_ID)) { |
|
| 1217 | + $success = 0; |
|
| 1218 | + } |
|
| 1219 | + } |
|
| 1220 | + } |
|
| 1221 | + } else { |
|
| 1222 | + // grab single id and trash |
|
| 1223 | + $TKT_ID = absint($this->_req_data['TKT_ID']); |
|
| 1224 | + if ($trash) { |
|
| 1225 | + if (! $TKT->delete_by_ID($TKT_ID)) { |
|
| 1226 | + $success = 0; |
|
| 1227 | + } |
|
| 1228 | + } else { |
|
| 1229 | + if (! $TKT->restore_by_ID($TKT_ID)) { |
|
| 1230 | + $success = 0; |
|
| 1231 | + } |
|
| 1232 | + } |
|
| 1233 | + } |
|
| 1234 | + $action_desc = $trash ? 'moved to the trash' : 'restored'; |
|
| 1235 | + $query_args = array( |
|
| 1236 | + 'action' => 'ticket_list_table', |
|
| 1237 | + 'status' => $trash ? '' : 'trashed', |
|
| 1238 | + ); |
|
| 1239 | + $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args); |
|
| 1240 | + } |
|
| 1241 | + |
|
| 1242 | + |
|
| 1243 | + /** |
|
| 1244 | + * Handles trashing default ticket. |
|
| 1245 | + */ |
|
| 1246 | + protected function _delete_ticket() |
|
| 1247 | + { |
|
| 1248 | + $success = 1; |
|
| 1249 | + // checkboxes? |
|
| 1250 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 1251 | + // if array has more than one element then success message should be plural |
|
| 1252 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 1253 | + // cycle thru the boxes |
|
| 1254 | + while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 1255 | + // delete |
|
| 1256 | + if (! $this->_delete_the_ticket($TKT_ID)) { |
|
| 1257 | + $success = 0; |
|
| 1258 | + } |
|
| 1259 | + } |
|
| 1260 | + } else { |
|
| 1261 | + // grab single id and trash |
|
| 1262 | + $TKT_ID = absint($this->_req_data['TKT_ID']); |
|
| 1263 | + if (! $this->_delete_the_ticket($TKT_ID)) { |
|
| 1264 | + $success = 0; |
|
| 1265 | + } |
|
| 1266 | + } |
|
| 1267 | + $action_desc = 'deleted'; |
|
| 1268 | + $query_args = array( |
|
| 1269 | + 'action' => 'ticket_list_table', |
|
| 1270 | + 'status' => 'trashed', |
|
| 1271 | + ); |
|
| 1272 | + // fail safe. If the default ticket count === 1 then we need to redirect to event overview. |
|
| 1273 | + if (EEM_Ticket::instance()->count_deleted_and_undeleted( |
|
| 1274 | + array(array('TKT_is_default' => 1)), |
|
| 1275 | + 'TKT_ID', |
|
| 1276 | + true |
|
| 1277 | + ) |
|
| 1278 | + ) { |
|
| 1279 | + $query_args = array(); |
|
| 1280 | + } |
|
| 1281 | + $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args); |
|
| 1282 | + } |
|
| 1283 | + |
|
| 1284 | + |
|
| 1285 | + /** |
|
| 1286 | + * @param int $TKT_ID |
|
| 1287 | + * @return bool|int |
|
| 1288 | + * @throws EE_Error |
|
| 1289 | + */ |
|
| 1290 | + protected function _delete_the_ticket($TKT_ID) |
|
| 1291 | + { |
|
| 1292 | + $tkt = EEM_Ticket::instance()->get_one_by_ID($TKT_ID); |
|
| 1293 | + $tkt->_remove_relations('Datetime'); |
|
| 1294 | + // delete all related prices first |
|
| 1295 | + $tkt->delete_related_permanently('Price'); |
|
| 1296 | + return $tkt->delete_permanently(); |
|
| 1297 | + } |
|
| 1298 | 1298 | } |
@@ -12,1426 +12,1426 @@ |
||
| 12 | 12 | class Pricing_Admin_Page extends EE_Admin_Page |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * constructor |
|
| 17 | - * |
|
| 18 | - * @Constructor |
|
| 19 | - * @access public |
|
| 20 | - * @param bool $routing |
|
| 21 | - * @return Pricing_Admin_Page |
|
| 22 | - */ |
|
| 23 | - public function __construct($routing = true) |
|
| 24 | - { |
|
| 25 | - parent::__construct($routing); |
|
| 26 | - } |
|
| 27 | - |
|
| 28 | - |
|
| 29 | - protected function _init_page_props() |
|
| 30 | - { |
|
| 31 | - $this->page_slug = PRICING_PG_SLUG; |
|
| 32 | - $this->page_label = PRICING_LABEL; |
|
| 33 | - $this->_admin_base_url = PRICING_ADMIN_URL; |
|
| 34 | - $this->_admin_base_path = PRICING_ADMIN; |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - |
|
| 38 | - protected function _ajax_hooks() |
|
| 39 | - { |
|
| 40 | - add_action('wp_ajax_espresso_update_prices_order', array($this, 'update_price_order')); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - |
|
| 44 | - protected function _define_page_props() |
|
| 45 | - { |
|
| 46 | - $this->_admin_page_title = PRICING_LABEL; |
|
| 47 | - $this->_labels = array( |
|
| 48 | - 'buttons' => array( |
|
| 49 | - 'add' => __('Add New Default Price', 'event_espresso'), |
|
| 50 | - 'edit' => __('Edit Default Price', 'event_espresso'), |
|
| 51 | - 'delete' => __('Delete Default Price', 'event_espresso'), |
|
| 52 | - 'add_type' => __('Add New Default Price Type', 'event_espresso'), |
|
| 53 | - 'edit_type' => __('Edit Price Type', 'event_espresso'), |
|
| 54 | - 'delete_type' => __('Delete Price Type', 'event_espresso'), |
|
| 55 | - ), |
|
| 56 | - ); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * an array for storing request actions and their corresponding methods |
|
| 62 | - * |
|
| 63 | - * @access private |
|
| 64 | - * @return void |
|
| 65 | - */ |
|
| 66 | - protected function _set_page_routes() |
|
| 67 | - { |
|
| 68 | - $prc_id = ! empty($this->_req_data['PRC_ID']) && ! is_array($this->_req_data['PRC_ID']) |
|
| 69 | - ? $this->_req_data['PRC_ID'] : 0; |
|
| 70 | - $prt_id = ! empty($this->_req_data['PRT_ID']) && ! is_array($this->_req_data['PRT_ID']) |
|
| 71 | - ? $this->_req_data['PRT_ID'] : 0; |
|
| 72 | - $this->_page_routes = array( |
|
| 73 | - 'default' => array( |
|
| 74 | - 'func' => '_price_overview_list_table', |
|
| 75 | - 'capability' => 'ee_read_default_prices', |
|
| 76 | - ), |
|
| 77 | - 'add_new_price' => array( |
|
| 78 | - 'func' => '_edit_price_details', |
|
| 79 | - 'args' => array('new_price' => true), |
|
| 80 | - 'capability' => 'ee_edit_default_prices', |
|
| 81 | - ), |
|
| 82 | - 'edit_price' => array( |
|
| 83 | - 'func' => '_edit_price_details', |
|
| 84 | - 'args' => array('new_price' => false), |
|
| 85 | - 'capability' => 'ee_edit_default_price', |
|
| 86 | - 'obj_id' => $prc_id, |
|
| 87 | - ), |
|
| 88 | - 'insert_price' => array( |
|
| 89 | - 'func' => '_insert_or_update_price', |
|
| 90 | - 'args' => array('new_price' => true), |
|
| 91 | - 'noheader' => true, |
|
| 92 | - 'capability' => 'ee_edit_default_prices', |
|
| 93 | - ), |
|
| 94 | - 'update_price' => array( |
|
| 95 | - 'func' => '_insert_or_update_price', |
|
| 96 | - 'args' => array('new_price' => false), |
|
| 97 | - 'noheader' => true, |
|
| 98 | - 'capability' => 'ee_edit_default_price', |
|
| 99 | - 'obj_id' => $prc_id, |
|
| 100 | - ), |
|
| 101 | - 'trash_price' => array( |
|
| 102 | - 'func' => '_trash_or_restore_price', |
|
| 103 | - 'args' => array('trash' => true), |
|
| 104 | - 'noheader' => true, |
|
| 105 | - 'capability' => 'ee_delete_default_price', |
|
| 106 | - 'obj_id' => $prc_id, |
|
| 107 | - ), |
|
| 108 | - 'restore_price' => array( |
|
| 109 | - 'func' => '_trash_or_restore_price', |
|
| 110 | - 'args' => array('trash' => false), |
|
| 111 | - 'noheader' => true, |
|
| 112 | - 'capability' => 'ee_delete_default_price', |
|
| 113 | - 'obj_id' => $prc_id, |
|
| 114 | - ), |
|
| 115 | - 'delete_price' => array( |
|
| 116 | - 'func' => '_delete_price', |
|
| 117 | - 'noheader' => true, |
|
| 118 | - 'capability' => 'ee_delete_default_price', |
|
| 119 | - 'obj_id' => $prc_id, |
|
| 120 | - ), |
|
| 121 | - 'espresso_update_price_order' => array( |
|
| 122 | - 'func' => 'update_price_order', |
|
| 123 | - 'noheader' => true, |
|
| 124 | - 'capability' => 'ee_edit_default_prices', |
|
| 125 | - ), |
|
| 126 | - // price types |
|
| 127 | - 'price_types' => array( |
|
| 128 | - 'func' => '_price_types_overview_list_table', |
|
| 129 | - 'capability' => 'ee_read_default_price_types', |
|
| 130 | - ), |
|
| 131 | - 'add_new_price_type' => array( |
|
| 132 | - 'func' => '_edit_price_type_details', |
|
| 133 | - 'capability' => 'ee_edit_default_price_types', |
|
| 134 | - ), |
|
| 135 | - 'edit_price_type' => array( |
|
| 136 | - 'func' => '_edit_price_type_details', |
|
| 137 | - 'capability' => 'ee_edit_default_price_type', |
|
| 138 | - 'obj_id' => $prt_id, |
|
| 139 | - ), |
|
| 140 | - 'insert_price_type' => array( |
|
| 141 | - 'func' => '_insert_or_update_price_type', |
|
| 142 | - 'args' => array('new_price_type' => true), |
|
| 143 | - 'noheader' => true, |
|
| 144 | - 'capability' => 'ee_edit_default_price_types', |
|
| 145 | - ), |
|
| 146 | - 'update_price_type' => array( |
|
| 147 | - 'func' => '_insert_or_update_price_type', |
|
| 148 | - 'args' => array('new_price_type' => false), |
|
| 149 | - 'noheader' => true, |
|
| 150 | - 'capability' => 'ee_edit_default_price_type', |
|
| 151 | - 'obj_id' => $prt_id, |
|
| 152 | - ), |
|
| 153 | - 'trash_price_type' => array( |
|
| 154 | - 'func' => '_trash_or_restore_price_type', |
|
| 155 | - 'args' => array('trash' => true), |
|
| 156 | - 'noheader' => true, |
|
| 157 | - 'capability' => 'ee_delete_default_price_type', |
|
| 158 | - 'obj_id' => $prt_id, |
|
| 159 | - ), |
|
| 160 | - 'restore_price_type' => array( |
|
| 161 | - 'func' => '_trash_or_restore_price_type', |
|
| 162 | - 'args' => array('trash' => false), |
|
| 163 | - 'noheader' => true, |
|
| 164 | - 'capability' => 'ee_delete_default_price_type', |
|
| 165 | - 'obj_id' => $prt_id, |
|
| 166 | - ), |
|
| 167 | - 'delete_price_type' => array( |
|
| 168 | - 'func' => '_delete_price_type', |
|
| 169 | - 'noheader' => true, |
|
| 170 | - 'capability' => 'ee_delete_default_price_type', |
|
| 171 | - 'obj_id' => $prt_id, |
|
| 172 | - ), |
|
| 173 | - 'tax_settings' => array( |
|
| 174 | - 'func' => '_tax_settings', |
|
| 175 | - 'capability' => 'manage_options', |
|
| 176 | - ), |
|
| 177 | - 'update_tax_settings' => array( |
|
| 178 | - 'func' => '_update_tax_settings', |
|
| 179 | - 'capability' => 'manage_options', |
|
| 180 | - 'noheader' => true, |
|
| 181 | - ), |
|
| 182 | - ); |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - |
|
| 186 | - protected function _set_page_config() |
|
| 187 | - { |
|
| 188 | - |
|
| 189 | - $this->_page_config = array( |
|
| 190 | - 'default' => array( |
|
| 191 | - 'nav' => array( |
|
| 192 | - 'label' => __('Default Pricing', 'event_espresso'), |
|
| 193 | - 'order' => 10, |
|
| 194 | - ), |
|
| 195 | - 'list_table' => 'Prices_List_Table', |
|
| 196 | - 'help_tabs' => array( |
|
| 197 | - 'pricing_default_pricing_help_tab' => array( |
|
| 198 | - 'title' => __('Default Pricing', 'event_espresso'), |
|
| 199 | - 'filename' => 'pricing_default_pricing', |
|
| 200 | - ), |
|
| 201 | - 'pricing_default_pricing_table_column_headings_help_tab' => array( |
|
| 202 | - 'title' => __('Default Pricing Table Column Headings', 'event_espresso'), |
|
| 203 | - 'filename' => 'pricing_default_pricing_table_column_headings', |
|
| 204 | - ), |
|
| 205 | - 'pricing_default_pricing_views_bulk_actions_search_help_tab' => array( |
|
| 206 | - 'title' => __('Default Pricing Views & Bulk Actions & Search', 'event_espresso'), |
|
| 207 | - 'filename' => 'pricing_default_pricing_views_bulk_actions_search', |
|
| 208 | - ), |
|
| 209 | - ), |
|
| 210 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 211 | - // 'help_tour' => array('Pricing_Default_Prices_Help_Tour'), |
|
| 212 | - 'require_nonce' => false, |
|
| 213 | - ), |
|
| 214 | - 'add_new_price' => array( |
|
| 215 | - 'nav' => array( |
|
| 216 | - 'label' => __('Add New Default Price', 'event_espresso'), |
|
| 217 | - 'order' => 20, |
|
| 218 | - 'persistent' => false, |
|
| 219 | - ), |
|
| 220 | - 'help_tabs' => array( |
|
| 221 | - 'add_new_default_price_help_tab' => array( |
|
| 222 | - 'title' => __('Add New Default Price', 'event_espresso'), |
|
| 223 | - 'filename' => 'pricing_add_new_default_price', |
|
| 224 | - ), |
|
| 225 | - ), |
|
| 226 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 227 | - // 'help_tour' => array('Pricing_Add_New_Default_Price_Help_Tour'), |
|
| 228 | - 'metaboxes' => array('_publish_post_box', '_espresso_news_post_box', '_price_details_meta_boxes'), |
|
| 229 | - 'require_nonce' => false, |
|
| 230 | - ), |
|
| 231 | - 'edit_price' => array( |
|
| 232 | - 'nav' => array( |
|
| 233 | - 'label' => __('Edit Default Price', 'event_espresso'), |
|
| 234 | - 'order' => 20, |
|
| 235 | - 'url' => isset($this->_req_data['id']) ? add_query_arg( |
|
| 236 | - array('id' => $this->_req_data['id']), |
|
| 237 | - $this->_current_page_view_url |
|
| 238 | - ) : $this->_admin_base_url, |
|
| 239 | - 'persistent' => false, |
|
| 240 | - ), |
|
| 241 | - 'metaboxes' => array('_publish_post_box', '_espresso_news_post_box', '_price_details_meta_boxes'), |
|
| 242 | - 'help_tabs' => array( |
|
| 243 | - 'edit_default_price_help_tab' => array( |
|
| 244 | - 'title' => __('Edit Default Price', 'event_espresso'), |
|
| 245 | - 'filename' => 'pricing_edit_default_price', |
|
| 246 | - ), |
|
| 247 | - ), |
|
| 248 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 249 | - // 'help_tour' => array('Pricing_Edit_Default_Price_Help_Tour'), |
|
| 250 | - 'require_nonce' => false, |
|
| 251 | - ), |
|
| 252 | - 'price_types' => array( |
|
| 253 | - 'nav' => array( |
|
| 254 | - 'label' => __('Price Types', 'event_espresso'), |
|
| 255 | - 'order' => 30, |
|
| 256 | - ), |
|
| 257 | - 'list_table' => 'Price_Types_List_Table', |
|
| 258 | - 'help_tabs' => array( |
|
| 259 | - 'pricing_price_types_help_tab' => array( |
|
| 260 | - 'title' => __('Price Types', 'event_espresso'), |
|
| 261 | - 'filename' => 'pricing_price_types', |
|
| 262 | - ), |
|
| 263 | - 'pricing_price_types_table_column_headings_help_tab' => array( |
|
| 264 | - 'title' => __('Price Types Table Column Headings', 'event_espresso'), |
|
| 265 | - 'filename' => 'pricing_price_types_table_column_headings', |
|
| 266 | - ), |
|
| 267 | - 'pricing_price_types_views_bulk_actions_search_help_tab' => array( |
|
| 268 | - 'title' => __('Price Types Views & Bulk Actions & Search', 'event_espresso'), |
|
| 269 | - 'filename' => 'pricing_price_types_views_bulk_actions_search', |
|
| 270 | - ), |
|
| 271 | - ), |
|
| 272 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 273 | - // 'help_tour' => array('Pricing_Price_Types_Default_Help_Tour'), |
|
| 274 | - 'metaboxes' => array('_espresso_news_post_box', '_espresso_links_post_box'), |
|
| 275 | - 'require_nonce' => false, |
|
| 276 | - ), |
|
| 277 | - 'add_new_price_type' => array( |
|
| 278 | - 'nav' => array( |
|
| 279 | - 'label' => __('Add New Price Type', 'event_espresso'), |
|
| 280 | - 'order' => 40, |
|
| 281 | - 'persistent' => false, |
|
| 282 | - ), |
|
| 283 | - 'help_tabs' => array( |
|
| 284 | - 'add_new_price_type_help_tab' => array( |
|
| 285 | - 'title' => __('Add New Price Type', 'event_espresso'), |
|
| 286 | - 'filename' => 'pricing_add_new_price_type', |
|
| 287 | - ), |
|
| 288 | - ), |
|
| 289 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 290 | - // 'help_tour' => array('Pricing_Add_New_Price_Type_Help_Tour'), |
|
| 291 | - 'metaboxes' => array( |
|
| 292 | - '_publish_post_box', |
|
| 293 | - '_espresso_news_post_box', |
|
| 294 | - '_price_type_details_meta_boxes', |
|
| 295 | - ), |
|
| 296 | - 'require_nonce' => false, |
|
| 297 | - ), |
|
| 298 | - 'edit_price_type' => array( |
|
| 299 | - 'nav' => array( |
|
| 300 | - 'label' => __('Edit Price Type', 'event_espresso'), |
|
| 301 | - 'order' => 40, |
|
| 302 | - 'persistent' => false, |
|
| 303 | - ), |
|
| 304 | - 'help_tabs' => array( |
|
| 305 | - 'edit_price_type_help_tab' => array( |
|
| 306 | - 'title' => __('Edit Price Type', 'event_espresso'), |
|
| 307 | - 'filename' => 'pricing_edit_price_type', |
|
| 308 | - ), |
|
| 309 | - ), |
|
| 310 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 311 | - // 'help_tour' => array('Pricing_Edit_Price_Type_Help_Tour'), |
|
| 312 | - 'metaboxes' => array('_publish_post_box', '_espresso_news_post_box', '_price_type_details_meta_boxes'), |
|
| 313 | - |
|
| 314 | - 'require_nonce' => false, |
|
| 315 | - ), |
|
| 316 | - 'tax_settings' => array( |
|
| 317 | - 'nav' => array( |
|
| 318 | - 'label' => esc_html__('Tax Settings', 'event_espresso'), |
|
| 319 | - 'order' => 40, |
|
| 320 | - ), |
|
| 321 | - 'labels' => array( |
|
| 322 | - 'publishbox' => esc_html__('Update Tax Settings', 'event_espresso'), |
|
| 323 | - ), |
|
| 324 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 325 | - // 'help_tabs' => array( |
|
| 326 | - // 'registration_form_reg_form_settings_help_tab' => array( |
|
| 327 | - // 'title' => esc_html__('Registration Form Settings', 'event_espresso'), |
|
| 328 | - // 'filename' => 'registration_form_reg_form_settings' |
|
| 329 | - // ), |
|
| 330 | - // ), |
|
| 331 | - // 'help_tour' => array('Registration_Form_Settings_Help_Tour'), |
|
| 332 | - 'require_nonce' => true, |
|
| 333 | - ), |
|
| 334 | - ); |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - |
|
| 338 | - protected function _add_screen_options() |
|
| 339 | - { |
|
| 340 | - // todo |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - |
|
| 344 | - protected function _add_screen_options_default() |
|
| 345 | - { |
|
| 346 | - $this->_per_page_screen_option(); |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - |
|
| 350 | - protected function _add_screen_options_price_types() |
|
| 351 | - { |
|
| 352 | - $page_title = $this->_admin_page_title; |
|
| 353 | - $this->_admin_page_title = __('Price Types', 'event_espresso'); |
|
| 354 | - $this->_per_page_screen_option(); |
|
| 355 | - $this->_admin_page_title = $page_title; |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - |
|
| 359 | - protected function _add_feature_pointers() |
|
| 360 | - { |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - |
|
| 364 | - public function load_scripts_styles() |
|
| 365 | - { |
|
| 366 | - // styles |
|
| 367 | - wp_enqueue_style('espresso-ui-theme'); |
|
| 368 | - wp_register_style( |
|
| 369 | - 'espresso_PRICING', |
|
| 370 | - PRICING_ASSETS_URL . 'espresso_pricing_admin.css', |
|
| 371 | - array(), |
|
| 372 | - EVENT_ESPRESSO_VERSION |
|
| 373 | - ); |
|
| 374 | - wp_enqueue_style('espresso_PRICING'); |
|
| 375 | - |
|
| 376 | - // scripts |
|
| 377 | - wp_enqueue_script('ee_admin_js'); |
|
| 378 | - wp_enqueue_script('jquery-ui-position'); |
|
| 379 | - wp_enqueue_script('jquery-ui-widget'); |
|
| 380 | - // wp_enqueue_script('jquery-ui-dialog'); |
|
| 381 | - // wp_enqueue_script('jquery-ui-draggable'); |
|
| 382 | - // wp_enqueue_script('jquery-ui-datepicker'); |
|
| 383 | - wp_register_script( |
|
| 384 | - 'espresso_PRICING', |
|
| 385 | - PRICING_ASSETS_URL . 'espresso_pricing_admin.js', |
|
| 386 | - array('jquery'), |
|
| 387 | - EVENT_ESPRESSO_VERSION, |
|
| 388 | - true |
|
| 389 | - ); |
|
| 390 | - wp_enqueue_script('espresso_PRICING'); |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - |
|
| 394 | - public function load_scripts_styles_default() |
|
| 395 | - { |
|
| 396 | - wp_enqueue_script('espresso_ajax_table_sorting'); |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - |
|
| 400 | - public function admin_footer_scripts() |
|
| 401 | - { |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - public function admin_init() |
|
| 405 | - { |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - public function admin_notices() |
|
| 409 | - { |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - |
|
| 413 | - protected function _set_list_table_views_default() |
|
| 414 | - { |
|
| 415 | - $this->_views = array( |
|
| 416 | - 'all' => array( |
|
| 417 | - 'slug' => 'all', |
|
| 418 | - 'label' => __('View All Default Pricing', 'event_espresso'), |
|
| 419 | - 'count' => 0, |
|
| 420 | - 'bulk_action' => array( |
|
| 421 | - 'trash_price' => __('Move to Trash', 'event_espresso'), |
|
| 422 | - ), |
|
| 423 | - ), |
|
| 424 | - ); |
|
| 425 | - |
|
| 426 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_default_prices', 'pricing_trash_price')) { |
|
| 427 | - $this->_views['trashed'] = array( |
|
| 428 | - 'slug' => 'trashed', |
|
| 429 | - 'label' => __('Trash', 'event_espresso'), |
|
| 430 | - 'count' => 0, |
|
| 431 | - 'bulk_action' => array( |
|
| 432 | - 'restore_price' => __('Restore from Trash', 'event_espresso'), |
|
| 433 | - 'delete_price' => __('Delete Permanently', 'event_espresso'), |
|
| 434 | - ), |
|
| 435 | - ); |
|
| 436 | - } |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - |
|
| 440 | - protected function _set_list_table_views_price_types() |
|
| 441 | - { |
|
| 442 | - $this->_views = array( |
|
| 443 | - 'all' => array( |
|
| 444 | - 'slug' => 'all', |
|
| 445 | - 'label' => __('All', 'event_espresso'), |
|
| 446 | - 'count' => 0, |
|
| 447 | - 'bulk_action' => array( |
|
| 448 | - 'trash_price_type' => __('Move to Trash', 'event_espresso'), |
|
| 449 | - ), |
|
| 450 | - ), |
|
| 451 | - ); |
|
| 452 | - |
|
| 453 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 454 | - 'ee_delete_default_price_types', |
|
| 455 | - 'pricing_trash_price_type' |
|
| 456 | - )) { |
|
| 457 | - $this->_views['trashed'] = array( |
|
| 458 | - 'slug' => 'trashed', |
|
| 459 | - 'label' => __('Trash', 'event_espresso'), |
|
| 460 | - 'count' => 0, |
|
| 461 | - 'bulk_action' => array( |
|
| 462 | - 'restore_price_type' => __('Restore from Trash', 'event_espresso'), |
|
| 463 | - 'delete_price_type' => __('Delete Permanently', 'event_espresso'), |
|
| 464 | - ), |
|
| 465 | - ); |
|
| 466 | - } |
|
| 467 | - } |
|
| 468 | - |
|
| 469 | - |
|
| 470 | - /** |
|
| 471 | - * generates HTML for main Prices Admin page |
|
| 472 | - * |
|
| 473 | - * @access protected |
|
| 474 | - * @return void |
|
| 475 | - */ |
|
| 476 | - protected function _price_overview_list_table() |
|
| 477 | - { |
|
| 478 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 479 | - 'add_new_price', |
|
| 480 | - 'add', |
|
| 481 | - array(), |
|
| 482 | - 'add-new-h2' |
|
| 483 | - ); |
|
| 484 | - $this->admin_page_title .= $this->_learn_more_about_pricing_link(); |
|
| 485 | - $this->_search_btn_label = __('Default Prices', 'event_espresso'); |
|
| 486 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - |
|
| 490 | - /** |
|
| 491 | - * retrieve data for Prices List table |
|
| 492 | - * |
|
| 493 | - * @access public |
|
| 494 | - * @param int $per_page how many prices displayed per page |
|
| 495 | - * @param boolean $count return the count or objects |
|
| 496 | - * @param boolean $trashed whether the current view is of the trash can - eww yuck! |
|
| 497 | - * @return mixed (int|array) int = count || array of price objects |
|
| 498 | - */ |
|
| 499 | - public function get_prices_overview_data($per_page = 10, $count = false, $trashed = false) |
|
| 500 | - { |
|
| 501 | - |
|
| 502 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 503 | - // start with an empty array |
|
| 504 | - $event_pricing = array(); |
|
| 505 | - |
|
| 506 | - require_once(PRICING_ADMIN . 'Prices_List_Table.class.php'); |
|
| 507 | - require_once(EE_MODELS . 'EEM_Price.model.php'); |
|
| 508 | - // $PRC = EEM_Price::instance(); |
|
| 509 | - |
|
| 510 | - $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? '' : $this->_req_data['orderby']; |
|
| 511 | - $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] |
|
| 512 | - : 'ASC'; |
|
| 513 | - |
|
| 514 | - switch ($this->_req_data['orderby']) { |
|
| 515 | - case 'name': |
|
| 516 | - $orderby = array('PRC_name' => $order); |
|
| 517 | - break; |
|
| 518 | - case 'type': |
|
| 519 | - $orderby = array('Price_Type.PRT_name' => $order); |
|
| 520 | - break; |
|
| 521 | - case 'amount': |
|
| 522 | - $orderby = array('PRC_amount' => $order); |
|
| 523 | - break; |
|
| 524 | - default: |
|
| 525 | - $orderby = array('PRC_order' => $order, 'Price_Type.PRT_order' => $order, 'PRC_ID' => $order); |
|
| 526 | - } |
|
| 527 | - |
|
| 528 | - $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
| 529 | - ? $this->_req_data['paged'] : 1; |
|
| 530 | - $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
| 531 | - ? $this->_req_data['perpage'] : $per_page; |
|
| 532 | - |
|
| 533 | - $_where = array( |
|
| 534 | - 'PRC_is_default' => 1, |
|
| 535 | - 'PRC_deleted' => $trashed, |
|
| 536 | - ); |
|
| 537 | - |
|
| 538 | - $offset = ($current_page - 1) * $per_page; |
|
| 539 | - $limit = array($offset, $per_page); |
|
| 540 | - |
|
| 541 | - if (isset($this->_req_data['s'])) { |
|
| 542 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 543 | - $_where['OR'] = array( |
|
| 544 | - 'PRC_name' => array('LIKE', $sstr), |
|
| 545 | - 'PRC_desc' => array('LIKE', $sstr), |
|
| 546 | - 'PRC_amount' => array('LIKE', $sstr), |
|
| 547 | - 'Price_Type.PRT_name' => array('LIKE', $sstr), |
|
| 548 | - ); |
|
| 549 | - } |
|
| 550 | - |
|
| 551 | - $query_params = array( |
|
| 552 | - $_where, |
|
| 553 | - 'order_by' => $orderby, |
|
| 554 | - 'limit' => $limit, |
|
| 555 | - 'group_by' => 'PRC_ID', |
|
| 556 | - ); |
|
| 557 | - |
|
| 558 | - if ($count) { |
|
| 559 | - return $trashed ? EEM_Price::instance()->count(array($_where)) |
|
| 560 | - : EEM_Price::instance()->count_deleted_and_undeleted(array($_where)); |
|
| 561 | - } else { |
|
| 562 | - return EEM_Price::instance()->get_all_deleted_and_undeleted($query_params); |
|
| 563 | - } |
|
| 564 | - } |
|
| 565 | - |
|
| 566 | - |
|
| 567 | - /** |
|
| 568 | - * _price_details |
|
| 569 | - * |
|
| 570 | - * @access protected |
|
| 571 | - * @return void |
|
| 572 | - */ |
|
| 573 | - protected function _edit_price_details() |
|
| 574 | - { |
|
| 575 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 576 | - // grab price ID |
|
| 577 | - $PRC_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) ? absint($this->_req_data['id']) |
|
| 578 | - : false; |
|
| 579 | - // change page title based on request action |
|
| 580 | - switch ($this->_req_action) { |
|
| 581 | - case 'add_new_price': |
|
| 582 | - $this->_admin_page_title = esc_html__('Add New Price', 'event_espresso'); |
|
| 583 | - break; |
|
| 584 | - case 'edit_price': |
|
| 585 | - $this->_admin_page_title = esc_html__('Edit Price', 'event_espresso'); |
|
| 586 | - break; |
|
| 587 | - default: |
|
| 588 | - $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
|
| 589 | - } |
|
| 590 | - // add PRC_ID to title if editing |
|
| 591 | - $this->_admin_page_title = $PRC_ID ? $this->_admin_page_title . ' # ' . $PRC_ID : $this->_admin_page_title; |
|
| 592 | - |
|
| 593 | - // get prices |
|
| 594 | - require_once(EE_MODELS . 'EEM_Price.model.php'); |
|
| 595 | - $PRC = EEM_Price::instance(); |
|
| 596 | - |
|
| 597 | - if ($PRC_ID) { |
|
| 598 | - $price = $PRC->get_one_by_ID($PRC_ID); |
|
| 599 | - $additional_hidden_fields = array( |
|
| 600 | - 'PRC_ID' => array('type' => 'hidden', 'value' => $PRC_ID), |
|
| 601 | - ); |
|
| 602 | - $this->_set_add_edit_form_tags('update_price', $additional_hidden_fields); |
|
| 603 | - } else { |
|
| 604 | - $price = $PRC->get_new_price(); |
|
| 605 | - $this->_set_add_edit_form_tags('insert_price'); |
|
| 606 | - } |
|
| 607 | - |
|
| 608 | - $this->_template_args['PRC_ID'] = $PRC_ID; |
|
| 609 | - $this->_template_args['price'] = $price; |
|
| 610 | - |
|
| 611 | - // get price types |
|
| 612 | - require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
| 613 | - $PRT = EEM_Price_Type::instance(); |
|
| 614 | - $price_types = $PRT->get_all(array(array('PBT_ID' => array('!=', 1)))); |
|
| 615 | - $price_type_names = array(); |
|
| 616 | - if (empty($price_types)) { |
|
| 617 | - $msg = __( |
|
| 618 | - 'You have no price types defined. Please add a price type before adding a price.', |
|
| 619 | - 'event_espresso' |
|
| 620 | - ); |
|
| 621 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 622 | - exit(); |
|
| 623 | - } else { |
|
| 624 | - foreach ($price_types as $type) { |
|
| 625 | - // if ($type->is_global()) { |
|
| 626 | - $price_type_names[] = array('id' => $type->ID(), 'text' => $type->name()); |
|
| 627 | - // } |
|
| 628 | - } |
|
| 629 | - } |
|
| 630 | - |
|
| 631 | - $this->_template_args['price_types'] = $price_type_names; |
|
| 632 | - $this->_template_args['learn_more_about_pricing_link'] = $this->_learn_more_about_pricing_link(); |
|
| 633 | - |
|
| 634 | - $this->_set_publish_post_box_vars('id', $PRC_ID); |
|
| 635 | - // the details template wrapper |
|
| 636 | - $this->display_admin_page_with_sidebar(); |
|
| 637 | - } |
|
| 638 | - |
|
| 639 | - |
|
| 640 | - /** |
|
| 641 | - * declare price details page metaboxes |
|
| 642 | - * |
|
| 643 | - * @access protected |
|
| 644 | - * @return void |
|
| 645 | - */ |
|
| 646 | - protected function _price_details_meta_boxes() |
|
| 647 | - { |
|
| 648 | - add_meta_box( |
|
| 649 | - 'edit-price-details-mbox', |
|
| 650 | - __('Default Price Details', 'event_espresso'), |
|
| 651 | - array($this, '_edit_price_details_meta_box'), |
|
| 652 | - $this->wp_page_slug, |
|
| 653 | - 'normal', |
|
| 654 | - 'high' |
|
| 655 | - ); |
|
| 656 | - } |
|
| 657 | - |
|
| 658 | - |
|
| 659 | - /** |
|
| 660 | - * _edit_price_details_meta_box |
|
| 661 | - * |
|
| 662 | - * @access public |
|
| 663 | - * @return void |
|
| 664 | - */ |
|
| 665 | - public function _edit_price_details_meta_box() |
|
| 666 | - { |
|
| 667 | - echo EEH_Template::display_template( |
|
| 668 | - PRICING_TEMPLATE_PATH . 'pricing_details_main_meta_box.template.php', |
|
| 669 | - $this->_template_args, |
|
| 670 | - true |
|
| 671 | - ); |
|
| 672 | - } |
|
| 673 | - |
|
| 674 | - |
|
| 675 | - /** |
|
| 676 | - * set_price_column_values |
|
| 677 | - * |
|
| 678 | - * @access protected |
|
| 679 | - * @return array |
|
| 680 | - */ |
|
| 681 | - protected function set_price_column_values() |
|
| 682 | - { |
|
| 683 | - |
|
| 684 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 685 | - |
|
| 686 | - $set_column_values = array( |
|
| 687 | - 'PRT_ID' => absint($this->_req_data['PRT_ID']), |
|
| 688 | - 'PRC_amount' => $this->_req_data['PRC_amount'], |
|
| 689 | - 'PRC_name' => $this->_req_data['PRC_name'], |
|
| 690 | - 'PRC_desc' => $this->_req_data['PRC_desc'], |
|
| 691 | - 'PRC_is_default' => 1, |
|
| 692 | - 'PRC_overrides' => null, |
|
| 693 | - 'PRC_order' => 0, |
|
| 694 | - 'PRC_deleted' => 0, |
|
| 695 | - 'PRC_parent' => 0, |
|
| 696 | - ); |
|
| 697 | - return $set_column_values; |
|
| 698 | - } |
|
| 699 | - |
|
| 700 | - |
|
| 701 | - /** |
|
| 702 | - * insert_or_update_price |
|
| 703 | - * |
|
| 704 | - * @param boolean $insert - whether to insert or update |
|
| 705 | - * @access protected |
|
| 706 | - * @return void |
|
| 707 | - */ |
|
| 708 | - protected function _insert_or_update_price($insert = false) |
|
| 709 | - { |
|
| 710 | - |
|
| 711 | - // echo '<h3>'. __CLASS__ . '->' . __FUNCTION__ . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h3>'; |
|
| 712 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 713 | - |
|
| 714 | - require_once(EE_MODELS . 'EEM_Price.model.php'); |
|
| 715 | - $PRC = EEM_Price::instance(); |
|
| 716 | - |
|
| 717 | - // why be so pessimistic ??? : ( |
|
| 718 | - $success = 0; |
|
| 719 | - |
|
| 720 | - $set_column_values = $this->set_price_column_values(); |
|
| 721 | - // is this a new Price ? |
|
| 722 | - if ($insert) { |
|
| 723 | - // run the insert |
|
| 724 | - if ($PRC_ID = $PRC->insert($set_column_values)) { |
|
| 725 | - // make sure this new price modifier is attached to the ticket but ONLY if it is not a tax type |
|
| 726 | - $PR = EEM_price::instance()->get_one_by_ID($PRC_ID); |
|
| 727 | - if ($PR->type_obj()->base_type() !== EEM_Price_Type::base_type_tax) { |
|
| 728 | - $ticket = EEM_Ticket::instance()->get_one_by_ID(1); |
|
| 729 | - $ticket->_add_relation_to($PR, 'Price'); |
|
| 730 | - $ticket->save(); |
|
| 731 | - } |
|
| 732 | - $success = 1; |
|
| 733 | - } else { |
|
| 734 | - $PRC_ID = false; |
|
| 735 | - $success = 0; |
|
| 736 | - } |
|
| 737 | - $action_desc = 'created'; |
|
| 738 | - } else { |
|
| 739 | - $PRC_ID = absint($this->_req_data['PRC_ID']); |
|
| 740 | - // run the update |
|
| 741 | - $where_cols_n_values = array('PRC_ID' => $PRC_ID); |
|
| 742 | - if ($PRC->update($set_column_values, array($where_cols_n_values))) { |
|
| 743 | - $success = 1; |
|
| 744 | - } |
|
| 745 | - |
|
| 746 | - $PR = EEM_Price::instance()->get_one_by_ID($PRC_ID); |
|
| 747 | - if ($PR->type_obj()->base_type() !== EEM_Price_Type::base_type_tax) { |
|
| 748 | - // if this is $PRC_ID == 1, then we need to update the default ticket attached to this price so the TKT_price value is updated. |
|
| 749 | - if ($PRC_ID === 1) { |
|
| 750 | - $ticket = $PR->get_first_related('Ticket'); |
|
| 751 | - if ($ticket) { |
|
| 752 | - $ticket->set('TKT_price', $PR->get('PRC_amount')); |
|
| 753 | - $ticket->set('TKT_name', $PR->get('PRC_name')); |
|
| 754 | - $ticket->set('TKT_description', $PR->get('PRC_desc')); |
|
| 755 | - $ticket->save(); |
|
| 756 | - } |
|
| 757 | - } else { |
|
| 758 | - // we make sure this price is attached to base ticket. but ONLY if its not a tax ticket type. |
|
| 759 | - $ticket = EEM_Ticket::instance()->get_one_by_ID(1); |
|
| 760 | - $ticket->_add_relation_to($PRC_ID, 'Price'); |
|
| 761 | - $ticket->save(); |
|
| 762 | - } |
|
| 763 | - } |
|
| 764 | - |
|
| 765 | - $action_desc = 'updated'; |
|
| 766 | - } |
|
| 767 | - |
|
| 768 | - $query_args = array('action' => 'edit_price', 'id' => $PRC_ID); |
|
| 769 | - |
|
| 770 | - $this->_redirect_after_action($success, 'Prices', $action_desc, $query_args); |
|
| 771 | - } |
|
| 772 | - |
|
| 773 | - |
|
| 774 | - /** |
|
| 775 | - * _trash_or_restore_price |
|
| 776 | - * |
|
| 777 | - * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE) |
|
| 778 | - * @access protected |
|
| 779 | - * @return void |
|
| 780 | - */ |
|
| 781 | - protected function _trash_or_restore_price($trash = true) |
|
| 782 | - { |
|
| 783 | - |
|
| 784 | - // echo '<h3>'. __CLASS__ . '->' . __FUNCTION__ . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h3>'; |
|
| 785 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 786 | - |
|
| 787 | - require_once(EE_MODELS . 'EEM_Price.model.php'); |
|
| 788 | - $PRC = EEM_Price::instance(); |
|
| 789 | - |
|
| 790 | - $success = 1; |
|
| 791 | - $PRC_deleted = $trash ? true : false; |
|
| 792 | - |
|
| 793 | - // get base ticket for updating |
|
| 794 | - $ticket = EEM_Ticket::instance()->get_one_by_ID(1); |
|
| 795 | - // Checkboxes |
|
| 796 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 797 | - // if array has more than one element than success message should be plural |
|
| 798 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 799 | - // cycle thru checkboxes |
|
| 800 | - while (list($PRC_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 801 | - if (! $PRC->update_by_ID(array('PRC_deleted' => $PRC_deleted), absint($PRC_ID))) { |
|
| 802 | - $success = 0; |
|
| 803 | - } else { |
|
| 804 | - $PR = EEM_Price::instance()->get_one_by_ID($PRC_ID); |
|
| 805 | - if ($PR->type_obj()->base_type() !== EEM_Price_Type::base_type_tax) { |
|
| 806 | - // if trashing then remove relations to base default ticket. If restoring then add back to base default ticket |
|
| 807 | - if ($PRC_deleted) { |
|
| 808 | - $ticket->_remove_relation_to($PRC_ID, 'Price'); |
|
| 809 | - } else { |
|
| 810 | - $ticket->_add_relation_to($PRC_ID, 'Price'); |
|
| 811 | - } |
|
| 812 | - $ticket->save(); |
|
| 813 | - } |
|
| 814 | - } |
|
| 815 | - } |
|
| 816 | - } else { |
|
| 817 | - // grab single id and delete |
|
| 818 | - $PRC_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0; |
|
| 819 | - if (empty($PRC_ID) || ! $PRC->update_by_ID(array('PRC_deleted' => $PRC_deleted), $PRC_ID)) { |
|
| 820 | - $success = 0; |
|
| 821 | - } else { |
|
| 822 | - $PR = EEM_Price::instance()->get_one_by_ID($PRC_ID); |
|
| 823 | - if ($PR->type_obj()->base_type() !== EEM_Price_Type::base_type_tax) { |
|
| 824 | - // if trashing then remove relations to base default ticket. If restoring then add back to base default ticket |
|
| 825 | - if ($PRC_deleted) { |
|
| 826 | - $ticket->_remove_relation_to($PRC_ID, 'Price'); |
|
| 827 | - } else { |
|
| 828 | - $ticket->_add_relation_to($PRC_ID, 'Price'); |
|
| 829 | - } |
|
| 830 | - $ticket->save(); |
|
| 831 | - } |
|
| 832 | - } |
|
| 833 | - } |
|
| 834 | - $query_args = array( |
|
| 835 | - 'action' => 'default', |
|
| 836 | - ); |
|
| 837 | - |
|
| 838 | - if ($success) { |
|
| 839 | - if ($trash) { |
|
| 840 | - $msg = $success == 2 |
|
| 841 | - ? __('The Prices have been trashed.', 'event_espresso') |
|
| 842 | - : __( |
|
| 843 | - 'The Price has been trashed.', |
|
| 844 | - 'event_espresso' |
|
| 845 | - ); |
|
| 846 | - } else { |
|
| 847 | - $msg = $success == 2 |
|
| 848 | - ? __('The Prices have been restored.', 'event_espresso') |
|
| 849 | - : __( |
|
| 850 | - 'The Price has been restored.', |
|
| 851 | - 'event_espresso' |
|
| 852 | - ); |
|
| 853 | - } |
|
| 854 | - |
|
| 855 | - EE_Error::add_success($msg); |
|
| 856 | - } |
|
| 857 | - |
|
| 858 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 859 | - } |
|
| 860 | - |
|
| 861 | - |
|
| 862 | - /** |
|
| 863 | - * _delete_price |
|
| 864 | - * |
|
| 865 | - * @access protected |
|
| 866 | - * @return void |
|
| 867 | - */ |
|
| 868 | - protected function _delete_price() |
|
| 869 | - { |
|
| 870 | - |
|
| 871 | - // echo '<h3>'. __CLASS__ . '->' . __FUNCTION__ . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h3>'; |
|
| 872 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 873 | - |
|
| 874 | - require_once(EE_MODELS . 'EEM_Price.model.php'); |
|
| 875 | - $PRC = EEM_Price::instance(); |
|
| 876 | - |
|
| 877 | - $success = 1; |
|
| 878 | - // Checkboxes |
|
| 879 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 880 | - // if array has more than one element than success message should be plural |
|
| 881 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 882 | - // cycle thru bulk action checkboxes |
|
| 883 | - while (list($PRC_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 884 | - if (! $PRC->delete_permanently_by_ID(absint($PRC_ID))) { |
|
| 885 | - $success = 0; |
|
| 886 | - } |
|
| 887 | - } |
|
| 888 | - } else { |
|
| 889 | - // grab single id and delete |
|
| 890 | - $PRC_ID = absint($this->_req_data['id']); |
|
| 891 | - if (! $PRC->delete_permanently_by_ID($PRC_ID)) { |
|
| 892 | - $success = 0; |
|
| 893 | - } |
|
| 894 | - } |
|
| 895 | - |
|
| 896 | - $this->_redirect_after_action($success, 'Prices', 'deleted', array()); |
|
| 897 | - } |
|
| 898 | - |
|
| 899 | - |
|
| 900 | - public function update_price_order() |
|
| 901 | - { |
|
| 902 | - $success = __('Price order was updated successfully.', 'event_espresso'); |
|
| 903 | - |
|
| 904 | - // grab our row IDs |
|
| 905 | - $row_ids = isset($this->_req_data['row_ids']) && ! empty($this->_req_data['row_ids']) ? explode( |
|
| 906 | - ',', |
|
| 907 | - rtrim( |
|
| 908 | - $this->_req_data['row_ids'], |
|
| 909 | - ',' |
|
| 910 | - ) |
|
| 911 | - ) : false; |
|
| 912 | - |
|
| 913 | - if (is_array($row_ids)) { |
|
| 914 | - for ($i = 0; $i < count($row_ids); $i++) { |
|
| 915 | - // Update the prices when re-ordering |
|
| 916 | - $id = absint($row_ids[ $i ]); |
|
| 917 | - if (EEM_Price::instance()->update( |
|
| 918 | - array('PRC_order' => $i + 1), |
|
| 919 | - array(array('PRC_ID' => $id)) |
|
| 920 | - ) === false) { |
|
| 921 | - $success = false; |
|
| 922 | - } |
|
| 923 | - } |
|
| 924 | - } else { |
|
| 925 | - $success = false; |
|
| 926 | - } |
|
| 927 | - |
|
| 928 | - $errors = ! $success ? __('An error occurred. The price order was not updated.', 'event_espresso') : false; |
|
| 929 | - |
|
| 930 | - echo wp_json_encode(array('return_data' => false, 'success' => $success, 'errors' => $errors)); |
|
| 931 | - die(); |
|
| 932 | - } |
|
| 933 | - |
|
| 934 | - |
|
| 935 | - |
|
| 936 | - |
|
| 937 | - |
|
| 938 | - |
|
| 939 | - /************************************************************************************************************************************************************** |
|
| 15 | + /** |
|
| 16 | + * constructor |
|
| 17 | + * |
|
| 18 | + * @Constructor |
|
| 19 | + * @access public |
|
| 20 | + * @param bool $routing |
|
| 21 | + * @return Pricing_Admin_Page |
|
| 22 | + */ |
|
| 23 | + public function __construct($routing = true) |
|
| 24 | + { |
|
| 25 | + parent::__construct($routing); |
|
| 26 | + } |
|
| 27 | + |
|
| 28 | + |
|
| 29 | + protected function _init_page_props() |
|
| 30 | + { |
|
| 31 | + $this->page_slug = PRICING_PG_SLUG; |
|
| 32 | + $this->page_label = PRICING_LABEL; |
|
| 33 | + $this->_admin_base_url = PRICING_ADMIN_URL; |
|
| 34 | + $this->_admin_base_path = PRICING_ADMIN; |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + |
|
| 38 | + protected function _ajax_hooks() |
|
| 39 | + { |
|
| 40 | + add_action('wp_ajax_espresso_update_prices_order', array($this, 'update_price_order')); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + |
|
| 44 | + protected function _define_page_props() |
|
| 45 | + { |
|
| 46 | + $this->_admin_page_title = PRICING_LABEL; |
|
| 47 | + $this->_labels = array( |
|
| 48 | + 'buttons' => array( |
|
| 49 | + 'add' => __('Add New Default Price', 'event_espresso'), |
|
| 50 | + 'edit' => __('Edit Default Price', 'event_espresso'), |
|
| 51 | + 'delete' => __('Delete Default Price', 'event_espresso'), |
|
| 52 | + 'add_type' => __('Add New Default Price Type', 'event_espresso'), |
|
| 53 | + 'edit_type' => __('Edit Price Type', 'event_espresso'), |
|
| 54 | + 'delete_type' => __('Delete Price Type', 'event_espresso'), |
|
| 55 | + ), |
|
| 56 | + ); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * an array for storing request actions and their corresponding methods |
|
| 62 | + * |
|
| 63 | + * @access private |
|
| 64 | + * @return void |
|
| 65 | + */ |
|
| 66 | + protected function _set_page_routes() |
|
| 67 | + { |
|
| 68 | + $prc_id = ! empty($this->_req_data['PRC_ID']) && ! is_array($this->_req_data['PRC_ID']) |
|
| 69 | + ? $this->_req_data['PRC_ID'] : 0; |
|
| 70 | + $prt_id = ! empty($this->_req_data['PRT_ID']) && ! is_array($this->_req_data['PRT_ID']) |
|
| 71 | + ? $this->_req_data['PRT_ID'] : 0; |
|
| 72 | + $this->_page_routes = array( |
|
| 73 | + 'default' => array( |
|
| 74 | + 'func' => '_price_overview_list_table', |
|
| 75 | + 'capability' => 'ee_read_default_prices', |
|
| 76 | + ), |
|
| 77 | + 'add_new_price' => array( |
|
| 78 | + 'func' => '_edit_price_details', |
|
| 79 | + 'args' => array('new_price' => true), |
|
| 80 | + 'capability' => 'ee_edit_default_prices', |
|
| 81 | + ), |
|
| 82 | + 'edit_price' => array( |
|
| 83 | + 'func' => '_edit_price_details', |
|
| 84 | + 'args' => array('new_price' => false), |
|
| 85 | + 'capability' => 'ee_edit_default_price', |
|
| 86 | + 'obj_id' => $prc_id, |
|
| 87 | + ), |
|
| 88 | + 'insert_price' => array( |
|
| 89 | + 'func' => '_insert_or_update_price', |
|
| 90 | + 'args' => array('new_price' => true), |
|
| 91 | + 'noheader' => true, |
|
| 92 | + 'capability' => 'ee_edit_default_prices', |
|
| 93 | + ), |
|
| 94 | + 'update_price' => array( |
|
| 95 | + 'func' => '_insert_or_update_price', |
|
| 96 | + 'args' => array('new_price' => false), |
|
| 97 | + 'noheader' => true, |
|
| 98 | + 'capability' => 'ee_edit_default_price', |
|
| 99 | + 'obj_id' => $prc_id, |
|
| 100 | + ), |
|
| 101 | + 'trash_price' => array( |
|
| 102 | + 'func' => '_trash_or_restore_price', |
|
| 103 | + 'args' => array('trash' => true), |
|
| 104 | + 'noheader' => true, |
|
| 105 | + 'capability' => 'ee_delete_default_price', |
|
| 106 | + 'obj_id' => $prc_id, |
|
| 107 | + ), |
|
| 108 | + 'restore_price' => array( |
|
| 109 | + 'func' => '_trash_or_restore_price', |
|
| 110 | + 'args' => array('trash' => false), |
|
| 111 | + 'noheader' => true, |
|
| 112 | + 'capability' => 'ee_delete_default_price', |
|
| 113 | + 'obj_id' => $prc_id, |
|
| 114 | + ), |
|
| 115 | + 'delete_price' => array( |
|
| 116 | + 'func' => '_delete_price', |
|
| 117 | + 'noheader' => true, |
|
| 118 | + 'capability' => 'ee_delete_default_price', |
|
| 119 | + 'obj_id' => $prc_id, |
|
| 120 | + ), |
|
| 121 | + 'espresso_update_price_order' => array( |
|
| 122 | + 'func' => 'update_price_order', |
|
| 123 | + 'noheader' => true, |
|
| 124 | + 'capability' => 'ee_edit_default_prices', |
|
| 125 | + ), |
|
| 126 | + // price types |
|
| 127 | + 'price_types' => array( |
|
| 128 | + 'func' => '_price_types_overview_list_table', |
|
| 129 | + 'capability' => 'ee_read_default_price_types', |
|
| 130 | + ), |
|
| 131 | + 'add_new_price_type' => array( |
|
| 132 | + 'func' => '_edit_price_type_details', |
|
| 133 | + 'capability' => 'ee_edit_default_price_types', |
|
| 134 | + ), |
|
| 135 | + 'edit_price_type' => array( |
|
| 136 | + 'func' => '_edit_price_type_details', |
|
| 137 | + 'capability' => 'ee_edit_default_price_type', |
|
| 138 | + 'obj_id' => $prt_id, |
|
| 139 | + ), |
|
| 140 | + 'insert_price_type' => array( |
|
| 141 | + 'func' => '_insert_or_update_price_type', |
|
| 142 | + 'args' => array('new_price_type' => true), |
|
| 143 | + 'noheader' => true, |
|
| 144 | + 'capability' => 'ee_edit_default_price_types', |
|
| 145 | + ), |
|
| 146 | + 'update_price_type' => array( |
|
| 147 | + 'func' => '_insert_or_update_price_type', |
|
| 148 | + 'args' => array('new_price_type' => false), |
|
| 149 | + 'noheader' => true, |
|
| 150 | + 'capability' => 'ee_edit_default_price_type', |
|
| 151 | + 'obj_id' => $prt_id, |
|
| 152 | + ), |
|
| 153 | + 'trash_price_type' => array( |
|
| 154 | + 'func' => '_trash_or_restore_price_type', |
|
| 155 | + 'args' => array('trash' => true), |
|
| 156 | + 'noheader' => true, |
|
| 157 | + 'capability' => 'ee_delete_default_price_type', |
|
| 158 | + 'obj_id' => $prt_id, |
|
| 159 | + ), |
|
| 160 | + 'restore_price_type' => array( |
|
| 161 | + 'func' => '_trash_or_restore_price_type', |
|
| 162 | + 'args' => array('trash' => false), |
|
| 163 | + 'noheader' => true, |
|
| 164 | + 'capability' => 'ee_delete_default_price_type', |
|
| 165 | + 'obj_id' => $prt_id, |
|
| 166 | + ), |
|
| 167 | + 'delete_price_type' => array( |
|
| 168 | + 'func' => '_delete_price_type', |
|
| 169 | + 'noheader' => true, |
|
| 170 | + 'capability' => 'ee_delete_default_price_type', |
|
| 171 | + 'obj_id' => $prt_id, |
|
| 172 | + ), |
|
| 173 | + 'tax_settings' => array( |
|
| 174 | + 'func' => '_tax_settings', |
|
| 175 | + 'capability' => 'manage_options', |
|
| 176 | + ), |
|
| 177 | + 'update_tax_settings' => array( |
|
| 178 | + 'func' => '_update_tax_settings', |
|
| 179 | + 'capability' => 'manage_options', |
|
| 180 | + 'noheader' => true, |
|
| 181 | + ), |
|
| 182 | + ); |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + |
|
| 186 | + protected function _set_page_config() |
|
| 187 | + { |
|
| 188 | + |
|
| 189 | + $this->_page_config = array( |
|
| 190 | + 'default' => array( |
|
| 191 | + 'nav' => array( |
|
| 192 | + 'label' => __('Default Pricing', 'event_espresso'), |
|
| 193 | + 'order' => 10, |
|
| 194 | + ), |
|
| 195 | + 'list_table' => 'Prices_List_Table', |
|
| 196 | + 'help_tabs' => array( |
|
| 197 | + 'pricing_default_pricing_help_tab' => array( |
|
| 198 | + 'title' => __('Default Pricing', 'event_espresso'), |
|
| 199 | + 'filename' => 'pricing_default_pricing', |
|
| 200 | + ), |
|
| 201 | + 'pricing_default_pricing_table_column_headings_help_tab' => array( |
|
| 202 | + 'title' => __('Default Pricing Table Column Headings', 'event_espresso'), |
|
| 203 | + 'filename' => 'pricing_default_pricing_table_column_headings', |
|
| 204 | + ), |
|
| 205 | + 'pricing_default_pricing_views_bulk_actions_search_help_tab' => array( |
|
| 206 | + 'title' => __('Default Pricing Views & Bulk Actions & Search', 'event_espresso'), |
|
| 207 | + 'filename' => 'pricing_default_pricing_views_bulk_actions_search', |
|
| 208 | + ), |
|
| 209 | + ), |
|
| 210 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 211 | + // 'help_tour' => array('Pricing_Default_Prices_Help_Tour'), |
|
| 212 | + 'require_nonce' => false, |
|
| 213 | + ), |
|
| 214 | + 'add_new_price' => array( |
|
| 215 | + 'nav' => array( |
|
| 216 | + 'label' => __('Add New Default Price', 'event_espresso'), |
|
| 217 | + 'order' => 20, |
|
| 218 | + 'persistent' => false, |
|
| 219 | + ), |
|
| 220 | + 'help_tabs' => array( |
|
| 221 | + 'add_new_default_price_help_tab' => array( |
|
| 222 | + 'title' => __('Add New Default Price', 'event_espresso'), |
|
| 223 | + 'filename' => 'pricing_add_new_default_price', |
|
| 224 | + ), |
|
| 225 | + ), |
|
| 226 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 227 | + // 'help_tour' => array('Pricing_Add_New_Default_Price_Help_Tour'), |
|
| 228 | + 'metaboxes' => array('_publish_post_box', '_espresso_news_post_box', '_price_details_meta_boxes'), |
|
| 229 | + 'require_nonce' => false, |
|
| 230 | + ), |
|
| 231 | + 'edit_price' => array( |
|
| 232 | + 'nav' => array( |
|
| 233 | + 'label' => __('Edit Default Price', 'event_espresso'), |
|
| 234 | + 'order' => 20, |
|
| 235 | + 'url' => isset($this->_req_data['id']) ? add_query_arg( |
|
| 236 | + array('id' => $this->_req_data['id']), |
|
| 237 | + $this->_current_page_view_url |
|
| 238 | + ) : $this->_admin_base_url, |
|
| 239 | + 'persistent' => false, |
|
| 240 | + ), |
|
| 241 | + 'metaboxes' => array('_publish_post_box', '_espresso_news_post_box', '_price_details_meta_boxes'), |
|
| 242 | + 'help_tabs' => array( |
|
| 243 | + 'edit_default_price_help_tab' => array( |
|
| 244 | + 'title' => __('Edit Default Price', 'event_espresso'), |
|
| 245 | + 'filename' => 'pricing_edit_default_price', |
|
| 246 | + ), |
|
| 247 | + ), |
|
| 248 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 249 | + // 'help_tour' => array('Pricing_Edit_Default_Price_Help_Tour'), |
|
| 250 | + 'require_nonce' => false, |
|
| 251 | + ), |
|
| 252 | + 'price_types' => array( |
|
| 253 | + 'nav' => array( |
|
| 254 | + 'label' => __('Price Types', 'event_espresso'), |
|
| 255 | + 'order' => 30, |
|
| 256 | + ), |
|
| 257 | + 'list_table' => 'Price_Types_List_Table', |
|
| 258 | + 'help_tabs' => array( |
|
| 259 | + 'pricing_price_types_help_tab' => array( |
|
| 260 | + 'title' => __('Price Types', 'event_espresso'), |
|
| 261 | + 'filename' => 'pricing_price_types', |
|
| 262 | + ), |
|
| 263 | + 'pricing_price_types_table_column_headings_help_tab' => array( |
|
| 264 | + 'title' => __('Price Types Table Column Headings', 'event_espresso'), |
|
| 265 | + 'filename' => 'pricing_price_types_table_column_headings', |
|
| 266 | + ), |
|
| 267 | + 'pricing_price_types_views_bulk_actions_search_help_tab' => array( |
|
| 268 | + 'title' => __('Price Types Views & Bulk Actions & Search', 'event_espresso'), |
|
| 269 | + 'filename' => 'pricing_price_types_views_bulk_actions_search', |
|
| 270 | + ), |
|
| 271 | + ), |
|
| 272 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 273 | + // 'help_tour' => array('Pricing_Price_Types_Default_Help_Tour'), |
|
| 274 | + 'metaboxes' => array('_espresso_news_post_box', '_espresso_links_post_box'), |
|
| 275 | + 'require_nonce' => false, |
|
| 276 | + ), |
|
| 277 | + 'add_new_price_type' => array( |
|
| 278 | + 'nav' => array( |
|
| 279 | + 'label' => __('Add New Price Type', 'event_espresso'), |
|
| 280 | + 'order' => 40, |
|
| 281 | + 'persistent' => false, |
|
| 282 | + ), |
|
| 283 | + 'help_tabs' => array( |
|
| 284 | + 'add_new_price_type_help_tab' => array( |
|
| 285 | + 'title' => __('Add New Price Type', 'event_espresso'), |
|
| 286 | + 'filename' => 'pricing_add_new_price_type', |
|
| 287 | + ), |
|
| 288 | + ), |
|
| 289 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 290 | + // 'help_tour' => array('Pricing_Add_New_Price_Type_Help_Tour'), |
|
| 291 | + 'metaboxes' => array( |
|
| 292 | + '_publish_post_box', |
|
| 293 | + '_espresso_news_post_box', |
|
| 294 | + '_price_type_details_meta_boxes', |
|
| 295 | + ), |
|
| 296 | + 'require_nonce' => false, |
|
| 297 | + ), |
|
| 298 | + 'edit_price_type' => array( |
|
| 299 | + 'nav' => array( |
|
| 300 | + 'label' => __('Edit Price Type', 'event_espresso'), |
|
| 301 | + 'order' => 40, |
|
| 302 | + 'persistent' => false, |
|
| 303 | + ), |
|
| 304 | + 'help_tabs' => array( |
|
| 305 | + 'edit_price_type_help_tab' => array( |
|
| 306 | + 'title' => __('Edit Price Type', 'event_espresso'), |
|
| 307 | + 'filename' => 'pricing_edit_price_type', |
|
| 308 | + ), |
|
| 309 | + ), |
|
| 310 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 311 | + // 'help_tour' => array('Pricing_Edit_Price_Type_Help_Tour'), |
|
| 312 | + 'metaboxes' => array('_publish_post_box', '_espresso_news_post_box', '_price_type_details_meta_boxes'), |
|
| 313 | + |
|
| 314 | + 'require_nonce' => false, |
|
| 315 | + ), |
|
| 316 | + 'tax_settings' => array( |
|
| 317 | + 'nav' => array( |
|
| 318 | + 'label' => esc_html__('Tax Settings', 'event_espresso'), |
|
| 319 | + 'order' => 40, |
|
| 320 | + ), |
|
| 321 | + 'labels' => array( |
|
| 322 | + 'publishbox' => esc_html__('Update Tax Settings', 'event_espresso'), |
|
| 323 | + ), |
|
| 324 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 325 | + // 'help_tabs' => array( |
|
| 326 | + // 'registration_form_reg_form_settings_help_tab' => array( |
|
| 327 | + // 'title' => esc_html__('Registration Form Settings', 'event_espresso'), |
|
| 328 | + // 'filename' => 'registration_form_reg_form_settings' |
|
| 329 | + // ), |
|
| 330 | + // ), |
|
| 331 | + // 'help_tour' => array('Registration_Form_Settings_Help_Tour'), |
|
| 332 | + 'require_nonce' => true, |
|
| 333 | + ), |
|
| 334 | + ); |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + |
|
| 338 | + protected function _add_screen_options() |
|
| 339 | + { |
|
| 340 | + // todo |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + |
|
| 344 | + protected function _add_screen_options_default() |
|
| 345 | + { |
|
| 346 | + $this->_per_page_screen_option(); |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + |
|
| 350 | + protected function _add_screen_options_price_types() |
|
| 351 | + { |
|
| 352 | + $page_title = $this->_admin_page_title; |
|
| 353 | + $this->_admin_page_title = __('Price Types', 'event_espresso'); |
|
| 354 | + $this->_per_page_screen_option(); |
|
| 355 | + $this->_admin_page_title = $page_title; |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + |
|
| 359 | + protected function _add_feature_pointers() |
|
| 360 | + { |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + |
|
| 364 | + public function load_scripts_styles() |
|
| 365 | + { |
|
| 366 | + // styles |
|
| 367 | + wp_enqueue_style('espresso-ui-theme'); |
|
| 368 | + wp_register_style( |
|
| 369 | + 'espresso_PRICING', |
|
| 370 | + PRICING_ASSETS_URL . 'espresso_pricing_admin.css', |
|
| 371 | + array(), |
|
| 372 | + EVENT_ESPRESSO_VERSION |
|
| 373 | + ); |
|
| 374 | + wp_enqueue_style('espresso_PRICING'); |
|
| 375 | + |
|
| 376 | + // scripts |
|
| 377 | + wp_enqueue_script('ee_admin_js'); |
|
| 378 | + wp_enqueue_script('jquery-ui-position'); |
|
| 379 | + wp_enqueue_script('jquery-ui-widget'); |
|
| 380 | + // wp_enqueue_script('jquery-ui-dialog'); |
|
| 381 | + // wp_enqueue_script('jquery-ui-draggable'); |
|
| 382 | + // wp_enqueue_script('jquery-ui-datepicker'); |
|
| 383 | + wp_register_script( |
|
| 384 | + 'espresso_PRICING', |
|
| 385 | + PRICING_ASSETS_URL . 'espresso_pricing_admin.js', |
|
| 386 | + array('jquery'), |
|
| 387 | + EVENT_ESPRESSO_VERSION, |
|
| 388 | + true |
|
| 389 | + ); |
|
| 390 | + wp_enqueue_script('espresso_PRICING'); |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + |
|
| 394 | + public function load_scripts_styles_default() |
|
| 395 | + { |
|
| 396 | + wp_enqueue_script('espresso_ajax_table_sorting'); |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + |
|
| 400 | + public function admin_footer_scripts() |
|
| 401 | + { |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + public function admin_init() |
|
| 405 | + { |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + public function admin_notices() |
|
| 409 | + { |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + |
|
| 413 | + protected function _set_list_table_views_default() |
|
| 414 | + { |
|
| 415 | + $this->_views = array( |
|
| 416 | + 'all' => array( |
|
| 417 | + 'slug' => 'all', |
|
| 418 | + 'label' => __('View All Default Pricing', 'event_espresso'), |
|
| 419 | + 'count' => 0, |
|
| 420 | + 'bulk_action' => array( |
|
| 421 | + 'trash_price' => __('Move to Trash', 'event_espresso'), |
|
| 422 | + ), |
|
| 423 | + ), |
|
| 424 | + ); |
|
| 425 | + |
|
| 426 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_default_prices', 'pricing_trash_price')) { |
|
| 427 | + $this->_views['trashed'] = array( |
|
| 428 | + 'slug' => 'trashed', |
|
| 429 | + 'label' => __('Trash', 'event_espresso'), |
|
| 430 | + 'count' => 0, |
|
| 431 | + 'bulk_action' => array( |
|
| 432 | + 'restore_price' => __('Restore from Trash', 'event_espresso'), |
|
| 433 | + 'delete_price' => __('Delete Permanently', 'event_espresso'), |
|
| 434 | + ), |
|
| 435 | + ); |
|
| 436 | + } |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + |
|
| 440 | + protected function _set_list_table_views_price_types() |
|
| 441 | + { |
|
| 442 | + $this->_views = array( |
|
| 443 | + 'all' => array( |
|
| 444 | + 'slug' => 'all', |
|
| 445 | + 'label' => __('All', 'event_espresso'), |
|
| 446 | + 'count' => 0, |
|
| 447 | + 'bulk_action' => array( |
|
| 448 | + 'trash_price_type' => __('Move to Trash', 'event_espresso'), |
|
| 449 | + ), |
|
| 450 | + ), |
|
| 451 | + ); |
|
| 452 | + |
|
| 453 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 454 | + 'ee_delete_default_price_types', |
|
| 455 | + 'pricing_trash_price_type' |
|
| 456 | + )) { |
|
| 457 | + $this->_views['trashed'] = array( |
|
| 458 | + 'slug' => 'trashed', |
|
| 459 | + 'label' => __('Trash', 'event_espresso'), |
|
| 460 | + 'count' => 0, |
|
| 461 | + 'bulk_action' => array( |
|
| 462 | + 'restore_price_type' => __('Restore from Trash', 'event_espresso'), |
|
| 463 | + 'delete_price_type' => __('Delete Permanently', 'event_espresso'), |
|
| 464 | + ), |
|
| 465 | + ); |
|
| 466 | + } |
|
| 467 | + } |
|
| 468 | + |
|
| 469 | + |
|
| 470 | + /** |
|
| 471 | + * generates HTML for main Prices Admin page |
|
| 472 | + * |
|
| 473 | + * @access protected |
|
| 474 | + * @return void |
|
| 475 | + */ |
|
| 476 | + protected function _price_overview_list_table() |
|
| 477 | + { |
|
| 478 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 479 | + 'add_new_price', |
|
| 480 | + 'add', |
|
| 481 | + array(), |
|
| 482 | + 'add-new-h2' |
|
| 483 | + ); |
|
| 484 | + $this->admin_page_title .= $this->_learn_more_about_pricing_link(); |
|
| 485 | + $this->_search_btn_label = __('Default Prices', 'event_espresso'); |
|
| 486 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + |
|
| 490 | + /** |
|
| 491 | + * retrieve data for Prices List table |
|
| 492 | + * |
|
| 493 | + * @access public |
|
| 494 | + * @param int $per_page how many prices displayed per page |
|
| 495 | + * @param boolean $count return the count or objects |
|
| 496 | + * @param boolean $trashed whether the current view is of the trash can - eww yuck! |
|
| 497 | + * @return mixed (int|array) int = count || array of price objects |
|
| 498 | + */ |
|
| 499 | + public function get_prices_overview_data($per_page = 10, $count = false, $trashed = false) |
|
| 500 | + { |
|
| 501 | + |
|
| 502 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 503 | + // start with an empty array |
|
| 504 | + $event_pricing = array(); |
|
| 505 | + |
|
| 506 | + require_once(PRICING_ADMIN . 'Prices_List_Table.class.php'); |
|
| 507 | + require_once(EE_MODELS . 'EEM_Price.model.php'); |
|
| 508 | + // $PRC = EEM_Price::instance(); |
|
| 509 | + |
|
| 510 | + $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? '' : $this->_req_data['orderby']; |
|
| 511 | + $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] |
|
| 512 | + : 'ASC'; |
|
| 513 | + |
|
| 514 | + switch ($this->_req_data['orderby']) { |
|
| 515 | + case 'name': |
|
| 516 | + $orderby = array('PRC_name' => $order); |
|
| 517 | + break; |
|
| 518 | + case 'type': |
|
| 519 | + $orderby = array('Price_Type.PRT_name' => $order); |
|
| 520 | + break; |
|
| 521 | + case 'amount': |
|
| 522 | + $orderby = array('PRC_amount' => $order); |
|
| 523 | + break; |
|
| 524 | + default: |
|
| 525 | + $orderby = array('PRC_order' => $order, 'Price_Type.PRT_order' => $order, 'PRC_ID' => $order); |
|
| 526 | + } |
|
| 527 | + |
|
| 528 | + $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
| 529 | + ? $this->_req_data['paged'] : 1; |
|
| 530 | + $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
| 531 | + ? $this->_req_data['perpage'] : $per_page; |
|
| 532 | + |
|
| 533 | + $_where = array( |
|
| 534 | + 'PRC_is_default' => 1, |
|
| 535 | + 'PRC_deleted' => $trashed, |
|
| 536 | + ); |
|
| 537 | + |
|
| 538 | + $offset = ($current_page - 1) * $per_page; |
|
| 539 | + $limit = array($offset, $per_page); |
|
| 540 | + |
|
| 541 | + if (isset($this->_req_data['s'])) { |
|
| 542 | + $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 543 | + $_where['OR'] = array( |
|
| 544 | + 'PRC_name' => array('LIKE', $sstr), |
|
| 545 | + 'PRC_desc' => array('LIKE', $sstr), |
|
| 546 | + 'PRC_amount' => array('LIKE', $sstr), |
|
| 547 | + 'Price_Type.PRT_name' => array('LIKE', $sstr), |
|
| 548 | + ); |
|
| 549 | + } |
|
| 550 | + |
|
| 551 | + $query_params = array( |
|
| 552 | + $_where, |
|
| 553 | + 'order_by' => $orderby, |
|
| 554 | + 'limit' => $limit, |
|
| 555 | + 'group_by' => 'PRC_ID', |
|
| 556 | + ); |
|
| 557 | + |
|
| 558 | + if ($count) { |
|
| 559 | + return $trashed ? EEM_Price::instance()->count(array($_where)) |
|
| 560 | + : EEM_Price::instance()->count_deleted_and_undeleted(array($_where)); |
|
| 561 | + } else { |
|
| 562 | + return EEM_Price::instance()->get_all_deleted_and_undeleted($query_params); |
|
| 563 | + } |
|
| 564 | + } |
|
| 565 | + |
|
| 566 | + |
|
| 567 | + /** |
|
| 568 | + * _price_details |
|
| 569 | + * |
|
| 570 | + * @access protected |
|
| 571 | + * @return void |
|
| 572 | + */ |
|
| 573 | + protected function _edit_price_details() |
|
| 574 | + { |
|
| 575 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 576 | + // grab price ID |
|
| 577 | + $PRC_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) ? absint($this->_req_data['id']) |
|
| 578 | + : false; |
|
| 579 | + // change page title based on request action |
|
| 580 | + switch ($this->_req_action) { |
|
| 581 | + case 'add_new_price': |
|
| 582 | + $this->_admin_page_title = esc_html__('Add New Price', 'event_espresso'); |
|
| 583 | + break; |
|
| 584 | + case 'edit_price': |
|
| 585 | + $this->_admin_page_title = esc_html__('Edit Price', 'event_espresso'); |
|
| 586 | + break; |
|
| 587 | + default: |
|
| 588 | + $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
|
| 589 | + } |
|
| 590 | + // add PRC_ID to title if editing |
|
| 591 | + $this->_admin_page_title = $PRC_ID ? $this->_admin_page_title . ' # ' . $PRC_ID : $this->_admin_page_title; |
|
| 592 | + |
|
| 593 | + // get prices |
|
| 594 | + require_once(EE_MODELS . 'EEM_Price.model.php'); |
|
| 595 | + $PRC = EEM_Price::instance(); |
|
| 596 | + |
|
| 597 | + if ($PRC_ID) { |
|
| 598 | + $price = $PRC->get_one_by_ID($PRC_ID); |
|
| 599 | + $additional_hidden_fields = array( |
|
| 600 | + 'PRC_ID' => array('type' => 'hidden', 'value' => $PRC_ID), |
|
| 601 | + ); |
|
| 602 | + $this->_set_add_edit_form_tags('update_price', $additional_hidden_fields); |
|
| 603 | + } else { |
|
| 604 | + $price = $PRC->get_new_price(); |
|
| 605 | + $this->_set_add_edit_form_tags('insert_price'); |
|
| 606 | + } |
|
| 607 | + |
|
| 608 | + $this->_template_args['PRC_ID'] = $PRC_ID; |
|
| 609 | + $this->_template_args['price'] = $price; |
|
| 610 | + |
|
| 611 | + // get price types |
|
| 612 | + require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
| 613 | + $PRT = EEM_Price_Type::instance(); |
|
| 614 | + $price_types = $PRT->get_all(array(array('PBT_ID' => array('!=', 1)))); |
|
| 615 | + $price_type_names = array(); |
|
| 616 | + if (empty($price_types)) { |
|
| 617 | + $msg = __( |
|
| 618 | + 'You have no price types defined. Please add a price type before adding a price.', |
|
| 619 | + 'event_espresso' |
|
| 620 | + ); |
|
| 621 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 622 | + exit(); |
|
| 623 | + } else { |
|
| 624 | + foreach ($price_types as $type) { |
|
| 625 | + // if ($type->is_global()) { |
|
| 626 | + $price_type_names[] = array('id' => $type->ID(), 'text' => $type->name()); |
|
| 627 | + // } |
|
| 628 | + } |
|
| 629 | + } |
|
| 630 | + |
|
| 631 | + $this->_template_args['price_types'] = $price_type_names; |
|
| 632 | + $this->_template_args['learn_more_about_pricing_link'] = $this->_learn_more_about_pricing_link(); |
|
| 633 | + |
|
| 634 | + $this->_set_publish_post_box_vars('id', $PRC_ID); |
|
| 635 | + // the details template wrapper |
|
| 636 | + $this->display_admin_page_with_sidebar(); |
|
| 637 | + } |
|
| 638 | + |
|
| 639 | + |
|
| 640 | + /** |
|
| 641 | + * declare price details page metaboxes |
|
| 642 | + * |
|
| 643 | + * @access protected |
|
| 644 | + * @return void |
|
| 645 | + */ |
|
| 646 | + protected function _price_details_meta_boxes() |
|
| 647 | + { |
|
| 648 | + add_meta_box( |
|
| 649 | + 'edit-price-details-mbox', |
|
| 650 | + __('Default Price Details', 'event_espresso'), |
|
| 651 | + array($this, '_edit_price_details_meta_box'), |
|
| 652 | + $this->wp_page_slug, |
|
| 653 | + 'normal', |
|
| 654 | + 'high' |
|
| 655 | + ); |
|
| 656 | + } |
|
| 657 | + |
|
| 658 | + |
|
| 659 | + /** |
|
| 660 | + * _edit_price_details_meta_box |
|
| 661 | + * |
|
| 662 | + * @access public |
|
| 663 | + * @return void |
|
| 664 | + */ |
|
| 665 | + public function _edit_price_details_meta_box() |
|
| 666 | + { |
|
| 667 | + echo EEH_Template::display_template( |
|
| 668 | + PRICING_TEMPLATE_PATH . 'pricing_details_main_meta_box.template.php', |
|
| 669 | + $this->_template_args, |
|
| 670 | + true |
|
| 671 | + ); |
|
| 672 | + } |
|
| 673 | + |
|
| 674 | + |
|
| 675 | + /** |
|
| 676 | + * set_price_column_values |
|
| 677 | + * |
|
| 678 | + * @access protected |
|
| 679 | + * @return array |
|
| 680 | + */ |
|
| 681 | + protected function set_price_column_values() |
|
| 682 | + { |
|
| 683 | + |
|
| 684 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 685 | + |
|
| 686 | + $set_column_values = array( |
|
| 687 | + 'PRT_ID' => absint($this->_req_data['PRT_ID']), |
|
| 688 | + 'PRC_amount' => $this->_req_data['PRC_amount'], |
|
| 689 | + 'PRC_name' => $this->_req_data['PRC_name'], |
|
| 690 | + 'PRC_desc' => $this->_req_data['PRC_desc'], |
|
| 691 | + 'PRC_is_default' => 1, |
|
| 692 | + 'PRC_overrides' => null, |
|
| 693 | + 'PRC_order' => 0, |
|
| 694 | + 'PRC_deleted' => 0, |
|
| 695 | + 'PRC_parent' => 0, |
|
| 696 | + ); |
|
| 697 | + return $set_column_values; |
|
| 698 | + } |
|
| 699 | + |
|
| 700 | + |
|
| 701 | + /** |
|
| 702 | + * insert_or_update_price |
|
| 703 | + * |
|
| 704 | + * @param boolean $insert - whether to insert or update |
|
| 705 | + * @access protected |
|
| 706 | + * @return void |
|
| 707 | + */ |
|
| 708 | + protected function _insert_or_update_price($insert = false) |
|
| 709 | + { |
|
| 710 | + |
|
| 711 | + // echo '<h3>'. __CLASS__ . '->' . __FUNCTION__ . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h3>'; |
|
| 712 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 713 | + |
|
| 714 | + require_once(EE_MODELS . 'EEM_Price.model.php'); |
|
| 715 | + $PRC = EEM_Price::instance(); |
|
| 716 | + |
|
| 717 | + // why be so pessimistic ??? : ( |
|
| 718 | + $success = 0; |
|
| 719 | + |
|
| 720 | + $set_column_values = $this->set_price_column_values(); |
|
| 721 | + // is this a new Price ? |
|
| 722 | + if ($insert) { |
|
| 723 | + // run the insert |
|
| 724 | + if ($PRC_ID = $PRC->insert($set_column_values)) { |
|
| 725 | + // make sure this new price modifier is attached to the ticket but ONLY if it is not a tax type |
|
| 726 | + $PR = EEM_price::instance()->get_one_by_ID($PRC_ID); |
|
| 727 | + if ($PR->type_obj()->base_type() !== EEM_Price_Type::base_type_tax) { |
|
| 728 | + $ticket = EEM_Ticket::instance()->get_one_by_ID(1); |
|
| 729 | + $ticket->_add_relation_to($PR, 'Price'); |
|
| 730 | + $ticket->save(); |
|
| 731 | + } |
|
| 732 | + $success = 1; |
|
| 733 | + } else { |
|
| 734 | + $PRC_ID = false; |
|
| 735 | + $success = 0; |
|
| 736 | + } |
|
| 737 | + $action_desc = 'created'; |
|
| 738 | + } else { |
|
| 739 | + $PRC_ID = absint($this->_req_data['PRC_ID']); |
|
| 740 | + // run the update |
|
| 741 | + $where_cols_n_values = array('PRC_ID' => $PRC_ID); |
|
| 742 | + if ($PRC->update($set_column_values, array($where_cols_n_values))) { |
|
| 743 | + $success = 1; |
|
| 744 | + } |
|
| 745 | + |
|
| 746 | + $PR = EEM_Price::instance()->get_one_by_ID($PRC_ID); |
|
| 747 | + if ($PR->type_obj()->base_type() !== EEM_Price_Type::base_type_tax) { |
|
| 748 | + // if this is $PRC_ID == 1, then we need to update the default ticket attached to this price so the TKT_price value is updated. |
|
| 749 | + if ($PRC_ID === 1) { |
|
| 750 | + $ticket = $PR->get_first_related('Ticket'); |
|
| 751 | + if ($ticket) { |
|
| 752 | + $ticket->set('TKT_price', $PR->get('PRC_amount')); |
|
| 753 | + $ticket->set('TKT_name', $PR->get('PRC_name')); |
|
| 754 | + $ticket->set('TKT_description', $PR->get('PRC_desc')); |
|
| 755 | + $ticket->save(); |
|
| 756 | + } |
|
| 757 | + } else { |
|
| 758 | + // we make sure this price is attached to base ticket. but ONLY if its not a tax ticket type. |
|
| 759 | + $ticket = EEM_Ticket::instance()->get_one_by_ID(1); |
|
| 760 | + $ticket->_add_relation_to($PRC_ID, 'Price'); |
|
| 761 | + $ticket->save(); |
|
| 762 | + } |
|
| 763 | + } |
|
| 764 | + |
|
| 765 | + $action_desc = 'updated'; |
|
| 766 | + } |
|
| 767 | + |
|
| 768 | + $query_args = array('action' => 'edit_price', 'id' => $PRC_ID); |
|
| 769 | + |
|
| 770 | + $this->_redirect_after_action($success, 'Prices', $action_desc, $query_args); |
|
| 771 | + } |
|
| 772 | + |
|
| 773 | + |
|
| 774 | + /** |
|
| 775 | + * _trash_or_restore_price |
|
| 776 | + * |
|
| 777 | + * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE) |
|
| 778 | + * @access protected |
|
| 779 | + * @return void |
|
| 780 | + */ |
|
| 781 | + protected function _trash_or_restore_price($trash = true) |
|
| 782 | + { |
|
| 783 | + |
|
| 784 | + // echo '<h3>'. __CLASS__ . '->' . __FUNCTION__ . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h3>'; |
|
| 785 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 786 | + |
|
| 787 | + require_once(EE_MODELS . 'EEM_Price.model.php'); |
|
| 788 | + $PRC = EEM_Price::instance(); |
|
| 789 | + |
|
| 790 | + $success = 1; |
|
| 791 | + $PRC_deleted = $trash ? true : false; |
|
| 792 | + |
|
| 793 | + // get base ticket for updating |
|
| 794 | + $ticket = EEM_Ticket::instance()->get_one_by_ID(1); |
|
| 795 | + // Checkboxes |
|
| 796 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 797 | + // if array has more than one element than success message should be plural |
|
| 798 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 799 | + // cycle thru checkboxes |
|
| 800 | + while (list($PRC_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 801 | + if (! $PRC->update_by_ID(array('PRC_deleted' => $PRC_deleted), absint($PRC_ID))) { |
|
| 802 | + $success = 0; |
|
| 803 | + } else { |
|
| 804 | + $PR = EEM_Price::instance()->get_one_by_ID($PRC_ID); |
|
| 805 | + if ($PR->type_obj()->base_type() !== EEM_Price_Type::base_type_tax) { |
|
| 806 | + // if trashing then remove relations to base default ticket. If restoring then add back to base default ticket |
|
| 807 | + if ($PRC_deleted) { |
|
| 808 | + $ticket->_remove_relation_to($PRC_ID, 'Price'); |
|
| 809 | + } else { |
|
| 810 | + $ticket->_add_relation_to($PRC_ID, 'Price'); |
|
| 811 | + } |
|
| 812 | + $ticket->save(); |
|
| 813 | + } |
|
| 814 | + } |
|
| 815 | + } |
|
| 816 | + } else { |
|
| 817 | + // grab single id and delete |
|
| 818 | + $PRC_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0; |
|
| 819 | + if (empty($PRC_ID) || ! $PRC->update_by_ID(array('PRC_deleted' => $PRC_deleted), $PRC_ID)) { |
|
| 820 | + $success = 0; |
|
| 821 | + } else { |
|
| 822 | + $PR = EEM_Price::instance()->get_one_by_ID($PRC_ID); |
|
| 823 | + if ($PR->type_obj()->base_type() !== EEM_Price_Type::base_type_tax) { |
|
| 824 | + // if trashing then remove relations to base default ticket. If restoring then add back to base default ticket |
|
| 825 | + if ($PRC_deleted) { |
|
| 826 | + $ticket->_remove_relation_to($PRC_ID, 'Price'); |
|
| 827 | + } else { |
|
| 828 | + $ticket->_add_relation_to($PRC_ID, 'Price'); |
|
| 829 | + } |
|
| 830 | + $ticket->save(); |
|
| 831 | + } |
|
| 832 | + } |
|
| 833 | + } |
|
| 834 | + $query_args = array( |
|
| 835 | + 'action' => 'default', |
|
| 836 | + ); |
|
| 837 | + |
|
| 838 | + if ($success) { |
|
| 839 | + if ($trash) { |
|
| 840 | + $msg = $success == 2 |
|
| 841 | + ? __('The Prices have been trashed.', 'event_espresso') |
|
| 842 | + : __( |
|
| 843 | + 'The Price has been trashed.', |
|
| 844 | + 'event_espresso' |
|
| 845 | + ); |
|
| 846 | + } else { |
|
| 847 | + $msg = $success == 2 |
|
| 848 | + ? __('The Prices have been restored.', 'event_espresso') |
|
| 849 | + : __( |
|
| 850 | + 'The Price has been restored.', |
|
| 851 | + 'event_espresso' |
|
| 852 | + ); |
|
| 853 | + } |
|
| 854 | + |
|
| 855 | + EE_Error::add_success($msg); |
|
| 856 | + } |
|
| 857 | + |
|
| 858 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 859 | + } |
|
| 860 | + |
|
| 861 | + |
|
| 862 | + /** |
|
| 863 | + * _delete_price |
|
| 864 | + * |
|
| 865 | + * @access protected |
|
| 866 | + * @return void |
|
| 867 | + */ |
|
| 868 | + protected function _delete_price() |
|
| 869 | + { |
|
| 870 | + |
|
| 871 | + // echo '<h3>'. __CLASS__ . '->' . __FUNCTION__ . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h3>'; |
|
| 872 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 873 | + |
|
| 874 | + require_once(EE_MODELS . 'EEM_Price.model.php'); |
|
| 875 | + $PRC = EEM_Price::instance(); |
|
| 876 | + |
|
| 877 | + $success = 1; |
|
| 878 | + // Checkboxes |
|
| 879 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 880 | + // if array has more than one element than success message should be plural |
|
| 881 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 882 | + // cycle thru bulk action checkboxes |
|
| 883 | + while (list($PRC_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 884 | + if (! $PRC->delete_permanently_by_ID(absint($PRC_ID))) { |
|
| 885 | + $success = 0; |
|
| 886 | + } |
|
| 887 | + } |
|
| 888 | + } else { |
|
| 889 | + // grab single id and delete |
|
| 890 | + $PRC_ID = absint($this->_req_data['id']); |
|
| 891 | + if (! $PRC->delete_permanently_by_ID($PRC_ID)) { |
|
| 892 | + $success = 0; |
|
| 893 | + } |
|
| 894 | + } |
|
| 895 | + |
|
| 896 | + $this->_redirect_after_action($success, 'Prices', 'deleted', array()); |
|
| 897 | + } |
|
| 898 | + |
|
| 899 | + |
|
| 900 | + public function update_price_order() |
|
| 901 | + { |
|
| 902 | + $success = __('Price order was updated successfully.', 'event_espresso'); |
|
| 903 | + |
|
| 904 | + // grab our row IDs |
|
| 905 | + $row_ids = isset($this->_req_data['row_ids']) && ! empty($this->_req_data['row_ids']) ? explode( |
|
| 906 | + ',', |
|
| 907 | + rtrim( |
|
| 908 | + $this->_req_data['row_ids'], |
|
| 909 | + ',' |
|
| 910 | + ) |
|
| 911 | + ) : false; |
|
| 912 | + |
|
| 913 | + if (is_array($row_ids)) { |
|
| 914 | + for ($i = 0; $i < count($row_ids); $i++) { |
|
| 915 | + // Update the prices when re-ordering |
|
| 916 | + $id = absint($row_ids[ $i ]); |
|
| 917 | + if (EEM_Price::instance()->update( |
|
| 918 | + array('PRC_order' => $i + 1), |
|
| 919 | + array(array('PRC_ID' => $id)) |
|
| 920 | + ) === false) { |
|
| 921 | + $success = false; |
|
| 922 | + } |
|
| 923 | + } |
|
| 924 | + } else { |
|
| 925 | + $success = false; |
|
| 926 | + } |
|
| 927 | + |
|
| 928 | + $errors = ! $success ? __('An error occurred. The price order was not updated.', 'event_espresso') : false; |
|
| 929 | + |
|
| 930 | + echo wp_json_encode(array('return_data' => false, 'success' => $success, 'errors' => $errors)); |
|
| 931 | + die(); |
|
| 932 | + } |
|
| 933 | + |
|
| 934 | + |
|
| 935 | + |
|
| 936 | + |
|
| 937 | + |
|
| 938 | + |
|
| 939 | + /************************************************************************************************************************************************************** |
|
| 940 | 940 | ******************************************************************** TICKET PRICE TYPES ****************************************************************** |
| 941 | 941 | **************************************************************************************************************************************************************/ |
| 942 | 942 | |
| 943 | 943 | |
| 944 | - /** |
|
| 945 | - * generates HTML for main Prices Admin page |
|
| 946 | - * |
|
| 947 | - * @access protected |
|
| 948 | - * @return void |
|
| 949 | - */ |
|
| 950 | - protected function _price_types_overview_list_table() |
|
| 951 | - { |
|
| 952 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 953 | - 'add_new_price_type', |
|
| 954 | - 'add_type', |
|
| 955 | - array(), |
|
| 956 | - 'add-new-h2' |
|
| 957 | - ); |
|
| 958 | - $this->admin_page_title .= $this->_learn_more_about_pricing_link(); |
|
| 959 | - $this->_search_btn_label = __('Price Types', 'event_espresso'); |
|
| 960 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 961 | - } |
|
| 962 | - |
|
| 963 | - |
|
| 964 | - /** |
|
| 965 | - * retrieve data for Price Types List table |
|
| 966 | - * |
|
| 967 | - * @access public |
|
| 968 | - * @param int $per_page how many prices displayed per page |
|
| 969 | - * @param boolean $count return the count or objects |
|
| 970 | - * @param boolean $trashed whether the current view is of the trash can - eww yuck! |
|
| 971 | - * @return mixed (int|array) int = count || array of price objects |
|
| 972 | - */ |
|
| 973 | - public function get_price_types_overview_data($per_page = 10, $count = false, $trashed = false) |
|
| 974 | - { |
|
| 975 | - |
|
| 976 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 977 | - // start with an empty array |
|
| 978 | - |
|
| 979 | - require_once(PRICING_ADMIN . 'Price_Types_List_Table.class.php'); |
|
| 980 | - require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
| 981 | - |
|
| 982 | - $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? '' : $this->_req_data['orderby']; |
|
| 983 | - $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] |
|
| 984 | - : 'ASC'; |
|
| 985 | - switch ($this->_req_data['orderby']) { |
|
| 986 | - case 'name': |
|
| 987 | - $orderby = array('PRT_name' => $order); |
|
| 988 | - break; |
|
| 989 | - default: |
|
| 990 | - $orderby = array('PRT_order' => $order); |
|
| 991 | - } |
|
| 992 | - |
|
| 993 | - |
|
| 994 | - $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
| 995 | - ? $this->_req_data['paged'] : 1; |
|
| 996 | - $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
| 997 | - ? $this->_req_data['perpage'] : $per_page; |
|
| 998 | - |
|
| 999 | - $offset = ($current_page - 1) * $per_page; |
|
| 1000 | - $limit = array($offset, $per_page); |
|
| 1001 | - |
|
| 1002 | - $_where = array('PRT_deleted' => $trashed, 'PBT_ID' => array('!=', 1)); |
|
| 1003 | - |
|
| 1004 | - if (isset($this->_req_data['s'])) { |
|
| 1005 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 1006 | - $_where['OR'] = array( |
|
| 1007 | - 'PRT_name' => array('LIKE', $sstr), |
|
| 1008 | - ); |
|
| 1009 | - } |
|
| 1010 | - $query_params = array( |
|
| 1011 | - $_where, |
|
| 1012 | - 'order_by' => $orderby, |
|
| 1013 | - 'limit' => $limit, |
|
| 1014 | - ); |
|
| 1015 | - if ($count) { |
|
| 1016 | - return EEM_Price_Type::instance()->count_deleted_and_undeleted($query_params); |
|
| 1017 | - } else { |
|
| 1018 | - return EEM_Price_Type::instance()->get_all_deleted_and_undeleted($query_params); |
|
| 1019 | - } |
|
| 1020 | - |
|
| 1021 | - // EEH_Debug_Tools::printr( $price_types, '$price_types <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
| 1022 | - } |
|
| 1023 | - |
|
| 1024 | - |
|
| 1025 | - /** |
|
| 1026 | - * _edit_price_type_details |
|
| 1027 | - * |
|
| 1028 | - * @access protected |
|
| 1029 | - * @return void |
|
| 1030 | - */ |
|
| 1031 | - protected function _edit_price_type_details() |
|
| 1032 | - { |
|
| 1033 | - |
|
| 1034 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1035 | - |
|
| 1036 | - |
|
| 1037 | - // grab price type ID |
|
| 1038 | - $PRT_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) ? absint($this->_req_data['id']) |
|
| 1039 | - : false; |
|
| 1040 | - // change page title based on request action |
|
| 1041 | - switch ($this->_req_action) { |
|
| 1042 | - case 'add_new_price_type': |
|
| 1043 | - $this->_admin_page_title = esc_html__('Add New Price Type', 'event_espresso'); |
|
| 1044 | - break; |
|
| 1045 | - case 'edit_price_type': |
|
| 1046 | - $this->_admin_page_title = esc_html__('Edit Price Type', 'event_espresso'); |
|
| 1047 | - break; |
|
| 1048 | - default: |
|
| 1049 | - $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
|
| 1050 | - } |
|
| 1051 | - // add PRT_ID to title if editing |
|
| 1052 | - $this->_admin_page_title = $PRT_ID ? $this->_admin_page_title . ' # ' . $PRT_ID : $this->_admin_page_title; |
|
| 1053 | - |
|
| 1054 | - if ($PRT_ID) { |
|
| 1055 | - $price_type = EEM_Price_Type::instance()->get_one_by_ID($PRT_ID); |
|
| 1056 | - $additional_hidden_fields = array('PRT_ID' => array('type' => 'hidden', 'value' => $PRT_ID)); |
|
| 1057 | - $this->_set_add_edit_form_tags('update_price_type', $additional_hidden_fields); |
|
| 1058 | - } else { |
|
| 1059 | - $price_type = EEM_Price_Type::instance()->get_new_price_type(); |
|
| 1060 | - $this->_set_add_edit_form_tags('insert_price_type'); |
|
| 1061 | - } |
|
| 1062 | - |
|
| 1063 | - $this->_template_args['PRT_ID'] = $PRT_ID; |
|
| 1064 | - $this->_template_args['price_type'] = $price_type; |
|
| 1065 | - |
|
| 1066 | - |
|
| 1067 | - $base_types = EEM_Price_Type::instance()->get_base_types(); |
|
| 1068 | - $select_values = array(); |
|
| 1069 | - foreach ($base_types as $ref => $text) { |
|
| 1070 | - if ($ref == EEM_Price_Type::base_type_base_price) { |
|
| 1071 | - // do not allow creation of base_type_base_prices because that's a system only base type. |
|
| 1072 | - continue; |
|
| 1073 | - } |
|
| 1074 | - $values[] = array('id' => $ref, 'text' => $text); |
|
| 1075 | - } |
|
| 1076 | - |
|
| 1077 | - |
|
| 1078 | - $this->_template_args['base_type_select'] = EEH_Form_Fields::select_input( |
|
| 1079 | - 'base_type', |
|
| 1080 | - $values, |
|
| 1081 | - $price_type->base_type(), |
|
| 1082 | - 'id="price-type-base-type-slct"' |
|
| 1083 | - ); |
|
| 1084 | - $this->_template_args['learn_more_about_pricing_link'] = $this->_learn_more_about_pricing_link(); |
|
| 1085 | - $redirect_URL = add_query_arg(array('action' => 'price_types'), $this->_admin_base_url); |
|
| 1086 | - $this->_set_publish_post_box_vars('id', $PRT_ID, false, $redirect_URL); |
|
| 1087 | - // the details template wrapper |
|
| 1088 | - $this->display_admin_page_with_sidebar(); |
|
| 1089 | - } |
|
| 1090 | - |
|
| 1091 | - |
|
| 1092 | - /** |
|
| 1093 | - * declare price type details page metaboxes |
|
| 1094 | - * |
|
| 1095 | - * @access protected |
|
| 1096 | - * @return void |
|
| 1097 | - */ |
|
| 1098 | - protected function _price_type_details_meta_boxes() |
|
| 1099 | - { |
|
| 1100 | - add_meta_box( |
|
| 1101 | - 'edit-price-details-mbox', |
|
| 1102 | - __('Price Type Details', 'event_espresso'), |
|
| 1103 | - array($this, '_edit_price_type_details_meta_box'), |
|
| 1104 | - $this->wp_page_slug, |
|
| 1105 | - 'normal', |
|
| 1106 | - 'high' |
|
| 1107 | - ); |
|
| 1108 | - } |
|
| 1109 | - |
|
| 1110 | - |
|
| 1111 | - /** |
|
| 1112 | - * _edit_price_type_details_meta_box |
|
| 1113 | - * |
|
| 1114 | - * @access public |
|
| 1115 | - * @return void |
|
| 1116 | - */ |
|
| 1117 | - public function _edit_price_type_details_meta_box() |
|
| 1118 | - { |
|
| 1119 | - echo EEH_Template::display_template( |
|
| 1120 | - PRICING_TEMPLATE_PATH . 'pricing_type_details_main_meta_box.template.php', |
|
| 1121 | - $this->_template_args, |
|
| 1122 | - true |
|
| 1123 | - ); |
|
| 1124 | - } |
|
| 1125 | - |
|
| 1126 | - |
|
| 1127 | - /** |
|
| 1128 | - * set_price_type_column_values |
|
| 1129 | - * |
|
| 1130 | - * @access protected |
|
| 1131 | - * @return void |
|
| 1132 | - */ |
|
| 1133 | - protected function set_price_type_column_values() |
|
| 1134 | - { |
|
| 1135 | - |
|
| 1136 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1137 | - |
|
| 1138 | - $base_type = ! empty($this->_req_data['base_type']) ? $this->_req_data['base_type'] |
|
| 1139 | - : EEM_Price_Type::base_type_base_price; |
|
| 1140 | - |
|
| 1141 | - switch ($base_type) { |
|
| 1142 | - case EEM_Price_Type::base_type_base_price: |
|
| 1143 | - $this->_req_data['PBT_ID'] = EEM_Price_Type::base_type_base_price; |
|
| 1144 | - $this->_req_data['PRT_is_percent'] = 0; |
|
| 1145 | - $this->_req_data['PRT_order'] = 0; |
|
| 1146 | - break; |
|
| 1147 | - |
|
| 1148 | - case EEM_Price_Type::base_type_discount: |
|
| 1149 | - $this->_req_data['PBT_ID'] = EEM_Price_Type::base_type_discount; |
|
| 1150 | - break; |
|
| 1151 | - |
|
| 1152 | - case EEM_Price_Type::base_type_surcharge: |
|
| 1153 | - $this->_req_data['PBT_ID'] = EEM_Price_Type::base_type_surcharge; |
|
| 1154 | - break; |
|
| 1155 | - |
|
| 1156 | - case EEM_Price_Type::base_type_tax: |
|
| 1157 | - $this->_req_data['PBT_ID'] = EEM_Price_Type::base_type_tax; |
|
| 1158 | - $this->_req_data['PRT_is_percent'] = 1; |
|
| 1159 | - break; |
|
| 1160 | - }/**/ |
|
| 1161 | - |
|
| 1162 | - $set_column_values = array( |
|
| 1163 | - 'PRT_name' => $this->_req_data['PRT_name'], |
|
| 1164 | - 'PBT_ID' => absint($this->_req_data['PBT_ID']), |
|
| 1165 | - 'PRT_is_percent' => absint($this->_req_data['PRT_is_percent']), |
|
| 1166 | - 'PRT_order' => absint($this->_req_data['PRT_order']), |
|
| 1167 | - 'PRT_deleted' => 0, |
|
| 1168 | - ); |
|
| 1169 | - |
|
| 1170 | - return $set_column_values; |
|
| 1171 | - } |
|
| 1172 | - |
|
| 1173 | - |
|
| 1174 | - /** |
|
| 1175 | - * _insert_or_update_price_type |
|
| 1176 | - * |
|
| 1177 | - * @param boolean $new_price_type - whether to insert or update |
|
| 1178 | - * @access protected |
|
| 1179 | - * @return void |
|
| 1180 | - */ |
|
| 1181 | - protected function _insert_or_update_price_type($new_price_type = false) |
|
| 1182 | - { |
|
| 1183 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1184 | - |
|
| 1185 | - require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
| 1186 | - $PRT = EEM_Price_Type::instance(); |
|
| 1187 | - |
|
| 1188 | - // why be so pessimistic ??? : ( |
|
| 1189 | - $success = 0; |
|
| 1190 | - |
|
| 1191 | - $set_column_values = $this->set_price_type_column_values(); |
|
| 1192 | - // is this a new Price ? |
|
| 1193 | - if ($new_price_type) { |
|
| 1194 | - // run the insert |
|
| 1195 | - if ($PRT_ID = $PRT->insert($set_column_values)) { |
|
| 1196 | - $success = 1; |
|
| 1197 | - } |
|
| 1198 | - $action_desc = 'created'; |
|
| 1199 | - } else { |
|
| 1200 | - $PRT_ID = absint($this->_req_data['PRT_ID']); |
|
| 1201 | - // run the update |
|
| 1202 | - $where_cols_n_values = array('PRT_ID' => $PRT_ID); |
|
| 1203 | - if ($PRT->update($set_column_values, array($where_cols_n_values))) { |
|
| 1204 | - $success = 1; |
|
| 1205 | - } |
|
| 1206 | - $action_desc = 'updated'; |
|
| 1207 | - } |
|
| 1208 | - |
|
| 1209 | - $query_args = array('action' => 'edit_price_type', 'id' => $PRT_ID); |
|
| 1210 | - $this->_redirect_after_action($success, 'Price Type', $action_desc, $query_args); |
|
| 1211 | - } |
|
| 1212 | - |
|
| 1213 | - |
|
| 1214 | - /** |
|
| 1215 | - * _trash_or_restore_price_type |
|
| 1216 | - * |
|
| 1217 | - * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE) |
|
| 1218 | - * @access protected |
|
| 1219 | - * @return void |
|
| 1220 | - */ |
|
| 1221 | - protected function _trash_or_restore_price_type($trash = true) |
|
| 1222 | - { |
|
| 1223 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1224 | - |
|
| 1225 | - require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
| 1226 | - $PRT = EEM_Price_Type::instance(); |
|
| 1227 | - |
|
| 1228 | - $success = 1; |
|
| 1229 | - $PRT_deleted = $trash ? true : false; |
|
| 1230 | - // Checkboxes |
|
| 1231 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 1232 | - // if array has more than one element than success message should be plural |
|
| 1233 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 1234 | - $what = count($this->_req_data['checkbox']) > 1 ? 'Price Types' : 'Price Type'; |
|
| 1235 | - // cycle thru checkboxes |
|
| 1236 | - while (list($PRT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 1237 | - if (! $PRT->update_by_ID(array('PRT_deleted' => $PRT_deleted), $PRT_ID)) { |
|
| 1238 | - $success = 0; |
|
| 1239 | - } |
|
| 1240 | - } |
|
| 1241 | - } else { |
|
| 1242 | - // grab single id and delete |
|
| 1243 | - $PRT_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0; |
|
| 1244 | - if (empty($PRT_ID) || ! $PRT->update_by_ID(array('PRT_deleted' => $PRT_deleted), $PRT_ID)) { |
|
| 1245 | - $success = 0; |
|
| 1246 | - } |
|
| 1247 | - $what = 'Price Type'; |
|
| 1248 | - } |
|
| 1249 | - |
|
| 1250 | - $query_args = array('action' => 'price_types'); |
|
| 1251 | - if ($success) { |
|
| 1252 | - if ($trash) { |
|
| 1253 | - $msg = $success > 1 |
|
| 1254 | - ? __('The Price Types have been trashed.', 'event_espresso') |
|
| 1255 | - : __( |
|
| 1256 | - 'The Price Type has been trashed.', |
|
| 1257 | - 'event_espresso' |
|
| 1258 | - ); |
|
| 1259 | - } else { |
|
| 1260 | - $msg = $success > 1 |
|
| 1261 | - ? __('The Price Types have been restored.', 'event_espresso') |
|
| 1262 | - : __( |
|
| 1263 | - 'The Price Type has been restored.', |
|
| 1264 | - 'event_espresso' |
|
| 1265 | - ); |
|
| 1266 | - } |
|
| 1267 | - EE_Error::add_success($msg); |
|
| 1268 | - } |
|
| 1269 | - |
|
| 1270 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 1271 | - } |
|
| 1272 | - |
|
| 1273 | - |
|
| 1274 | - /** |
|
| 1275 | - * _delete_price_type |
|
| 1276 | - * |
|
| 1277 | - * @access protected |
|
| 1278 | - * @return void |
|
| 1279 | - */ |
|
| 1280 | - protected function _delete_price_type() |
|
| 1281 | - { |
|
| 1282 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1283 | - |
|
| 1284 | - $PRT = EEM_Price_Type::instance(); |
|
| 1285 | - |
|
| 1286 | - $success = 1; |
|
| 1287 | - // Checkboxes |
|
| 1288 | - if (! empty($this->_req_data['checkbox'])) { |
|
| 1289 | - // if array has more than one element than success message should be plural |
|
| 1290 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 1291 | - $what = $PRT->item_name($success); |
|
| 1292 | - // cycle thru bulk action checkboxes |
|
| 1293 | - while (list($PRT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 1294 | - if (! $PRT->delete_permanently_by_ID($PRT_ID)) { |
|
| 1295 | - $success = 0; |
|
| 1296 | - } |
|
| 1297 | - } |
|
| 1298 | - } |
|
| 1299 | - |
|
| 1300 | - |
|
| 1301 | - $query_args = array('action' => 'price_types'); |
|
| 1302 | - $this->_redirect_after_action($success, $what, 'deleted', $query_args); |
|
| 1303 | - } |
|
| 1304 | - |
|
| 1305 | - |
|
| 1306 | - /** |
|
| 1307 | - * _learn_more_about_pricing_link |
|
| 1308 | - * |
|
| 1309 | - * @access protected |
|
| 1310 | - * @return string |
|
| 1311 | - */ |
|
| 1312 | - protected function _learn_more_about_pricing_link() |
|
| 1313 | - { |
|
| 1314 | - return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' . __( |
|
| 1315 | - 'learn more about how pricing works', |
|
| 1316 | - 'event_espresso' |
|
| 1317 | - ) . '</a>'; |
|
| 1318 | - } |
|
| 1319 | - |
|
| 1320 | - |
|
| 1321 | - protected function _tax_settings() |
|
| 1322 | - { |
|
| 1323 | - $this->_set_add_edit_form_tags('update_tax_settings'); |
|
| 1324 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 1325 | - $this->_template_args['admin_page_content'] = $this->tax_settings_form()->get_html(); |
|
| 1326 | - $this->display_admin_page_with_sidebar(); |
|
| 1327 | - } |
|
| 1328 | - |
|
| 1329 | - |
|
| 1330 | - /** |
|
| 1331 | - * @return \EE_Form_Section_Proper |
|
| 1332 | - * @throws \EE_Error |
|
| 1333 | - */ |
|
| 1334 | - protected function tax_settings_form() |
|
| 1335 | - { |
|
| 1336 | - return new EE_Form_Section_Proper( |
|
| 1337 | - array( |
|
| 1338 | - 'name' => 'tax_settings_form', |
|
| 1339 | - 'html_id' => 'tax_settings_form', |
|
| 1340 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
| 1341 | - 'subsections' => apply_filters( |
|
| 1342 | - 'FHEE__Pricing_Admin_Page__tax_settings_form__form_subsections', |
|
| 1343 | - array( |
|
| 1344 | - 'tax_settings' => new EE_Form_Section_Proper( |
|
| 1345 | - array( |
|
| 1346 | - 'name' => 'tax_settings_tbl', |
|
| 1347 | - 'html_id' => 'tax_settings_tbl', |
|
| 1348 | - 'html_class' => 'form-table', |
|
| 1349 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 1350 | - 'subsections' => array( |
|
| 1351 | - 'prices_displayed_including_taxes' => new EE_Yes_No_Input( |
|
| 1352 | - array( |
|
| 1353 | - 'html_label_text' => __( |
|
| 1354 | - "Show Prices With Taxes Included?", |
|
| 1355 | - 'event_espresso' |
|
| 1356 | - ), |
|
| 1357 | - 'html_help_text' => __( |
|
| 1358 | - 'Indicates whether or not to display prices with the taxes included', |
|
| 1359 | - 'event_espresso' |
|
| 1360 | - ), |
|
| 1361 | - 'default' => isset( |
|
| 1362 | - EE_Registry::instance() |
|
| 1363 | - ->CFG |
|
| 1364 | - ->tax_settings |
|
| 1365 | - ->prices_displayed_including_taxes |
|
| 1366 | - ) |
|
| 1367 | - ? EE_Registry::instance() |
|
| 1368 | - ->CFG |
|
| 1369 | - ->tax_settings |
|
| 1370 | - ->prices_displayed_including_taxes |
|
| 1371 | - : true, |
|
| 1372 | - 'display_html_label_text' => false, |
|
| 1373 | - ) |
|
| 1374 | - ), |
|
| 1375 | - ), |
|
| 1376 | - ) |
|
| 1377 | - ), |
|
| 1378 | - ) |
|
| 1379 | - ), |
|
| 1380 | - ) |
|
| 1381 | - ); |
|
| 1382 | - } |
|
| 1383 | - |
|
| 1384 | - |
|
| 1385 | - /** |
|
| 1386 | - * _update_tax_settings |
|
| 1387 | - * |
|
| 1388 | - * @since 4.9.13 |
|
| 1389 | - * @return void |
|
| 1390 | - */ |
|
| 1391 | - public function _update_tax_settings() |
|
| 1392 | - { |
|
| 1393 | - if (! isset(EE_Registry::instance()->CFG->tax_settings)) { |
|
| 1394 | - EE_Registry::instance()->CFG->tax_settings = new EE_Tax_Config(); |
|
| 1395 | - } |
|
| 1396 | - try { |
|
| 1397 | - $tax_form = $this->tax_settings_form(); |
|
| 1398 | - // check for form submission |
|
| 1399 | - if ($tax_form->was_submitted()) { |
|
| 1400 | - // capture form data |
|
| 1401 | - $tax_form->receive_form_submission(); |
|
| 1402 | - // validate form data |
|
| 1403 | - if ($tax_form->is_valid()) { |
|
| 1404 | - // grab validated data from form |
|
| 1405 | - $valid_data = $tax_form->valid_data(); |
|
| 1406 | - // set data on config |
|
| 1407 | - EE_Registry::instance() |
|
| 1408 | - ->CFG |
|
| 1409 | - ->tax_settings |
|
| 1410 | - ->prices_displayed_including_taxes |
|
| 1411 | - = $valid_data['tax_settings']['prices_displayed_including_taxes']; |
|
| 1412 | - } else { |
|
| 1413 | - if ($tax_form->submission_error_message() !== '') { |
|
| 1414 | - EE_Error::add_error( |
|
| 1415 | - $tax_form->submission_error_message(), |
|
| 1416 | - __FILE__, |
|
| 1417 | - __FUNCTION__, |
|
| 1418 | - __LINE__ |
|
| 1419 | - ); |
|
| 1420 | - } |
|
| 1421 | - } |
|
| 1422 | - } |
|
| 1423 | - } catch (EE_Error $e) { |
|
| 1424 | - EE_Error::add_error($e->get_error(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1425 | - } |
|
| 1426 | - |
|
| 1427 | - $what = 'Tax Settings'; |
|
| 1428 | - $success = $this->_update_espresso_configuration( |
|
| 1429 | - $what, |
|
| 1430 | - EE_Registry::instance()->CFG->tax_settings, |
|
| 1431 | - __FILE__, |
|
| 1432 | - __FUNCTION__, |
|
| 1433 | - __LINE__ |
|
| 1434 | - ); |
|
| 1435 | - $this->_redirect_after_action($success, $what, 'updated', array('action' => 'tax_settings')); |
|
| 1436 | - } |
|
| 944 | + /** |
|
| 945 | + * generates HTML for main Prices Admin page |
|
| 946 | + * |
|
| 947 | + * @access protected |
|
| 948 | + * @return void |
|
| 949 | + */ |
|
| 950 | + protected function _price_types_overview_list_table() |
|
| 951 | + { |
|
| 952 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 953 | + 'add_new_price_type', |
|
| 954 | + 'add_type', |
|
| 955 | + array(), |
|
| 956 | + 'add-new-h2' |
|
| 957 | + ); |
|
| 958 | + $this->admin_page_title .= $this->_learn_more_about_pricing_link(); |
|
| 959 | + $this->_search_btn_label = __('Price Types', 'event_espresso'); |
|
| 960 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 961 | + } |
|
| 962 | + |
|
| 963 | + |
|
| 964 | + /** |
|
| 965 | + * retrieve data for Price Types List table |
|
| 966 | + * |
|
| 967 | + * @access public |
|
| 968 | + * @param int $per_page how many prices displayed per page |
|
| 969 | + * @param boolean $count return the count or objects |
|
| 970 | + * @param boolean $trashed whether the current view is of the trash can - eww yuck! |
|
| 971 | + * @return mixed (int|array) int = count || array of price objects |
|
| 972 | + */ |
|
| 973 | + public function get_price_types_overview_data($per_page = 10, $count = false, $trashed = false) |
|
| 974 | + { |
|
| 975 | + |
|
| 976 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 977 | + // start with an empty array |
|
| 978 | + |
|
| 979 | + require_once(PRICING_ADMIN . 'Price_Types_List_Table.class.php'); |
|
| 980 | + require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
| 981 | + |
|
| 982 | + $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? '' : $this->_req_data['orderby']; |
|
| 983 | + $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] |
|
| 984 | + : 'ASC'; |
|
| 985 | + switch ($this->_req_data['orderby']) { |
|
| 986 | + case 'name': |
|
| 987 | + $orderby = array('PRT_name' => $order); |
|
| 988 | + break; |
|
| 989 | + default: |
|
| 990 | + $orderby = array('PRT_order' => $order); |
|
| 991 | + } |
|
| 992 | + |
|
| 993 | + |
|
| 994 | + $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
| 995 | + ? $this->_req_data['paged'] : 1; |
|
| 996 | + $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
| 997 | + ? $this->_req_data['perpage'] : $per_page; |
|
| 998 | + |
|
| 999 | + $offset = ($current_page - 1) * $per_page; |
|
| 1000 | + $limit = array($offset, $per_page); |
|
| 1001 | + |
|
| 1002 | + $_where = array('PRT_deleted' => $trashed, 'PBT_ID' => array('!=', 1)); |
|
| 1003 | + |
|
| 1004 | + if (isset($this->_req_data['s'])) { |
|
| 1005 | + $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 1006 | + $_where['OR'] = array( |
|
| 1007 | + 'PRT_name' => array('LIKE', $sstr), |
|
| 1008 | + ); |
|
| 1009 | + } |
|
| 1010 | + $query_params = array( |
|
| 1011 | + $_where, |
|
| 1012 | + 'order_by' => $orderby, |
|
| 1013 | + 'limit' => $limit, |
|
| 1014 | + ); |
|
| 1015 | + if ($count) { |
|
| 1016 | + return EEM_Price_Type::instance()->count_deleted_and_undeleted($query_params); |
|
| 1017 | + } else { |
|
| 1018 | + return EEM_Price_Type::instance()->get_all_deleted_and_undeleted($query_params); |
|
| 1019 | + } |
|
| 1020 | + |
|
| 1021 | + // EEH_Debug_Tools::printr( $price_types, '$price_types <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
| 1022 | + } |
|
| 1023 | + |
|
| 1024 | + |
|
| 1025 | + /** |
|
| 1026 | + * _edit_price_type_details |
|
| 1027 | + * |
|
| 1028 | + * @access protected |
|
| 1029 | + * @return void |
|
| 1030 | + */ |
|
| 1031 | + protected function _edit_price_type_details() |
|
| 1032 | + { |
|
| 1033 | + |
|
| 1034 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1035 | + |
|
| 1036 | + |
|
| 1037 | + // grab price type ID |
|
| 1038 | + $PRT_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) ? absint($this->_req_data['id']) |
|
| 1039 | + : false; |
|
| 1040 | + // change page title based on request action |
|
| 1041 | + switch ($this->_req_action) { |
|
| 1042 | + case 'add_new_price_type': |
|
| 1043 | + $this->_admin_page_title = esc_html__('Add New Price Type', 'event_espresso'); |
|
| 1044 | + break; |
|
| 1045 | + case 'edit_price_type': |
|
| 1046 | + $this->_admin_page_title = esc_html__('Edit Price Type', 'event_espresso'); |
|
| 1047 | + break; |
|
| 1048 | + default: |
|
| 1049 | + $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
|
| 1050 | + } |
|
| 1051 | + // add PRT_ID to title if editing |
|
| 1052 | + $this->_admin_page_title = $PRT_ID ? $this->_admin_page_title . ' # ' . $PRT_ID : $this->_admin_page_title; |
|
| 1053 | + |
|
| 1054 | + if ($PRT_ID) { |
|
| 1055 | + $price_type = EEM_Price_Type::instance()->get_one_by_ID($PRT_ID); |
|
| 1056 | + $additional_hidden_fields = array('PRT_ID' => array('type' => 'hidden', 'value' => $PRT_ID)); |
|
| 1057 | + $this->_set_add_edit_form_tags('update_price_type', $additional_hidden_fields); |
|
| 1058 | + } else { |
|
| 1059 | + $price_type = EEM_Price_Type::instance()->get_new_price_type(); |
|
| 1060 | + $this->_set_add_edit_form_tags('insert_price_type'); |
|
| 1061 | + } |
|
| 1062 | + |
|
| 1063 | + $this->_template_args['PRT_ID'] = $PRT_ID; |
|
| 1064 | + $this->_template_args['price_type'] = $price_type; |
|
| 1065 | + |
|
| 1066 | + |
|
| 1067 | + $base_types = EEM_Price_Type::instance()->get_base_types(); |
|
| 1068 | + $select_values = array(); |
|
| 1069 | + foreach ($base_types as $ref => $text) { |
|
| 1070 | + if ($ref == EEM_Price_Type::base_type_base_price) { |
|
| 1071 | + // do not allow creation of base_type_base_prices because that's a system only base type. |
|
| 1072 | + continue; |
|
| 1073 | + } |
|
| 1074 | + $values[] = array('id' => $ref, 'text' => $text); |
|
| 1075 | + } |
|
| 1076 | + |
|
| 1077 | + |
|
| 1078 | + $this->_template_args['base_type_select'] = EEH_Form_Fields::select_input( |
|
| 1079 | + 'base_type', |
|
| 1080 | + $values, |
|
| 1081 | + $price_type->base_type(), |
|
| 1082 | + 'id="price-type-base-type-slct"' |
|
| 1083 | + ); |
|
| 1084 | + $this->_template_args['learn_more_about_pricing_link'] = $this->_learn_more_about_pricing_link(); |
|
| 1085 | + $redirect_URL = add_query_arg(array('action' => 'price_types'), $this->_admin_base_url); |
|
| 1086 | + $this->_set_publish_post_box_vars('id', $PRT_ID, false, $redirect_URL); |
|
| 1087 | + // the details template wrapper |
|
| 1088 | + $this->display_admin_page_with_sidebar(); |
|
| 1089 | + } |
|
| 1090 | + |
|
| 1091 | + |
|
| 1092 | + /** |
|
| 1093 | + * declare price type details page metaboxes |
|
| 1094 | + * |
|
| 1095 | + * @access protected |
|
| 1096 | + * @return void |
|
| 1097 | + */ |
|
| 1098 | + protected function _price_type_details_meta_boxes() |
|
| 1099 | + { |
|
| 1100 | + add_meta_box( |
|
| 1101 | + 'edit-price-details-mbox', |
|
| 1102 | + __('Price Type Details', 'event_espresso'), |
|
| 1103 | + array($this, '_edit_price_type_details_meta_box'), |
|
| 1104 | + $this->wp_page_slug, |
|
| 1105 | + 'normal', |
|
| 1106 | + 'high' |
|
| 1107 | + ); |
|
| 1108 | + } |
|
| 1109 | + |
|
| 1110 | + |
|
| 1111 | + /** |
|
| 1112 | + * _edit_price_type_details_meta_box |
|
| 1113 | + * |
|
| 1114 | + * @access public |
|
| 1115 | + * @return void |
|
| 1116 | + */ |
|
| 1117 | + public function _edit_price_type_details_meta_box() |
|
| 1118 | + { |
|
| 1119 | + echo EEH_Template::display_template( |
|
| 1120 | + PRICING_TEMPLATE_PATH . 'pricing_type_details_main_meta_box.template.php', |
|
| 1121 | + $this->_template_args, |
|
| 1122 | + true |
|
| 1123 | + ); |
|
| 1124 | + } |
|
| 1125 | + |
|
| 1126 | + |
|
| 1127 | + /** |
|
| 1128 | + * set_price_type_column_values |
|
| 1129 | + * |
|
| 1130 | + * @access protected |
|
| 1131 | + * @return void |
|
| 1132 | + */ |
|
| 1133 | + protected function set_price_type_column_values() |
|
| 1134 | + { |
|
| 1135 | + |
|
| 1136 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1137 | + |
|
| 1138 | + $base_type = ! empty($this->_req_data['base_type']) ? $this->_req_data['base_type'] |
|
| 1139 | + : EEM_Price_Type::base_type_base_price; |
|
| 1140 | + |
|
| 1141 | + switch ($base_type) { |
|
| 1142 | + case EEM_Price_Type::base_type_base_price: |
|
| 1143 | + $this->_req_data['PBT_ID'] = EEM_Price_Type::base_type_base_price; |
|
| 1144 | + $this->_req_data['PRT_is_percent'] = 0; |
|
| 1145 | + $this->_req_data['PRT_order'] = 0; |
|
| 1146 | + break; |
|
| 1147 | + |
|
| 1148 | + case EEM_Price_Type::base_type_discount: |
|
| 1149 | + $this->_req_data['PBT_ID'] = EEM_Price_Type::base_type_discount; |
|
| 1150 | + break; |
|
| 1151 | + |
|
| 1152 | + case EEM_Price_Type::base_type_surcharge: |
|
| 1153 | + $this->_req_data['PBT_ID'] = EEM_Price_Type::base_type_surcharge; |
|
| 1154 | + break; |
|
| 1155 | + |
|
| 1156 | + case EEM_Price_Type::base_type_tax: |
|
| 1157 | + $this->_req_data['PBT_ID'] = EEM_Price_Type::base_type_tax; |
|
| 1158 | + $this->_req_data['PRT_is_percent'] = 1; |
|
| 1159 | + break; |
|
| 1160 | + }/**/ |
|
| 1161 | + |
|
| 1162 | + $set_column_values = array( |
|
| 1163 | + 'PRT_name' => $this->_req_data['PRT_name'], |
|
| 1164 | + 'PBT_ID' => absint($this->_req_data['PBT_ID']), |
|
| 1165 | + 'PRT_is_percent' => absint($this->_req_data['PRT_is_percent']), |
|
| 1166 | + 'PRT_order' => absint($this->_req_data['PRT_order']), |
|
| 1167 | + 'PRT_deleted' => 0, |
|
| 1168 | + ); |
|
| 1169 | + |
|
| 1170 | + return $set_column_values; |
|
| 1171 | + } |
|
| 1172 | + |
|
| 1173 | + |
|
| 1174 | + /** |
|
| 1175 | + * _insert_or_update_price_type |
|
| 1176 | + * |
|
| 1177 | + * @param boolean $new_price_type - whether to insert or update |
|
| 1178 | + * @access protected |
|
| 1179 | + * @return void |
|
| 1180 | + */ |
|
| 1181 | + protected function _insert_or_update_price_type($new_price_type = false) |
|
| 1182 | + { |
|
| 1183 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1184 | + |
|
| 1185 | + require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
| 1186 | + $PRT = EEM_Price_Type::instance(); |
|
| 1187 | + |
|
| 1188 | + // why be so pessimistic ??? : ( |
|
| 1189 | + $success = 0; |
|
| 1190 | + |
|
| 1191 | + $set_column_values = $this->set_price_type_column_values(); |
|
| 1192 | + // is this a new Price ? |
|
| 1193 | + if ($new_price_type) { |
|
| 1194 | + // run the insert |
|
| 1195 | + if ($PRT_ID = $PRT->insert($set_column_values)) { |
|
| 1196 | + $success = 1; |
|
| 1197 | + } |
|
| 1198 | + $action_desc = 'created'; |
|
| 1199 | + } else { |
|
| 1200 | + $PRT_ID = absint($this->_req_data['PRT_ID']); |
|
| 1201 | + // run the update |
|
| 1202 | + $where_cols_n_values = array('PRT_ID' => $PRT_ID); |
|
| 1203 | + if ($PRT->update($set_column_values, array($where_cols_n_values))) { |
|
| 1204 | + $success = 1; |
|
| 1205 | + } |
|
| 1206 | + $action_desc = 'updated'; |
|
| 1207 | + } |
|
| 1208 | + |
|
| 1209 | + $query_args = array('action' => 'edit_price_type', 'id' => $PRT_ID); |
|
| 1210 | + $this->_redirect_after_action($success, 'Price Type', $action_desc, $query_args); |
|
| 1211 | + } |
|
| 1212 | + |
|
| 1213 | + |
|
| 1214 | + /** |
|
| 1215 | + * _trash_or_restore_price_type |
|
| 1216 | + * |
|
| 1217 | + * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE) |
|
| 1218 | + * @access protected |
|
| 1219 | + * @return void |
|
| 1220 | + */ |
|
| 1221 | + protected function _trash_or_restore_price_type($trash = true) |
|
| 1222 | + { |
|
| 1223 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1224 | + |
|
| 1225 | + require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
| 1226 | + $PRT = EEM_Price_Type::instance(); |
|
| 1227 | + |
|
| 1228 | + $success = 1; |
|
| 1229 | + $PRT_deleted = $trash ? true : false; |
|
| 1230 | + // Checkboxes |
|
| 1231 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 1232 | + // if array has more than one element than success message should be plural |
|
| 1233 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 1234 | + $what = count($this->_req_data['checkbox']) > 1 ? 'Price Types' : 'Price Type'; |
|
| 1235 | + // cycle thru checkboxes |
|
| 1236 | + while (list($PRT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 1237 | + if (! $PRT->update_by_ID(array('PRT_deleted' => $PRT_deleted), $PRT_ID)) { |
|
| 1238 | + $success = 0; |
|
| 1239 | + } |
|
| 1240 | + } |
|
| 1241 | + } else { |
|
| 1242 | + // grab single id and delete |
|
| 1243 | + $PRT_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0; |
|
| 1244 | + if (empty($PRT_ID) || ! $PRT->update_by_ID(array('PRT_deleted' => $PRT_deleted), $PRT_ID)) { |
|
| 1245 | + $success = 0; |
|
| 1246 | + } |
|
| 1247 | + $what = 'Price Type'; |
|
| 1248 | + } |
|
| 1249 | + |
|
| 1250 | + $query_args = array('action' => 'price_types'); |
|
| 1251 | + if ($success) { |
|
| 1252 | + if ($trash) { |
|
| 1253 | + $msg = $success > 1 |
|
| 1254 | + ? __('The Price Types have been trashed.', 'event_espresso') |
|
| 1255 | + : __( |
|
| 1256 | + 'The Price Type has been trashed.', |
|
| 1257 | + 'event_espresso' |
|
| 1258 | + ); |
|
| 1259 | + } else { |
|
| 1260 | + $msg = $success > 1 |
|
| 1261 | + ? __('The Price Types have been restored.', 'event_espresso') |
|
| 1262 | + : __( |
|
| 1263 | + 'The Price Type has been restored.', |
|
| 1264 | + 'event_espresso' |
|
| 1265 | + ); |
|
| 1266 | + } |
|
| 1267 | + EE_Error::add_success($msg); |
|
| 1268 | + } |
|
| 1269 | + |
|
| 1270 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 1271 | + } |
|
| 1272 | + |
|
| 1273 | + |
|
| 1274 | + /** |
|
| 1275 | + * _delete_price_type |
|
| 1276 | + * |
|
| 1277 | + * @access protected |
|
| 1278 | + * @return void |
|
| 1279 | + */ |
|
| 1280 | + protected function _delete_price_type() |
|
| 1281 | + { |
|
| 1282 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1283 | + |
|
| 1284 | + $PRT = EEM_Price_Type::instance(); |
|
| 1285 | + |
|
| 1286 | + $success = 1; |
|
| 1287 | + // Checkboxes |
|
| 1288 | + if (! empty($this->_req_data['checkbox'])) { |
|
| 1289 | + // if array has more than one element than success message should be plural |
|
| 1290 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 1291 | + $what = $PRT->item_name($success); |
|
| 1292 | + // cycle thru bulk action checkboxes |
|
| 1293 | + while (list($PRT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 1294 | + if (! $PRT->delete_permanently_by_ID($PRT_ID)) { |
|
| 1295 | + $success = 0; |
|
| 1296 | + } |
|
| 1297 | + } |
|
| 1298 | + } |
|
| 1299 | + |
|
| 1300 | + |
|
| 1301 | + $query_args = array('action' => 'price_types'); |
|
| 1302 | + $this->_redirect_after_action($success, $what, 'deleted', $query_args); |
|
| 1303 | + } |
|
| 1304 | + |
|
| 1305 | + |
|
| 1306 | + /** |
|
| 1307 | + * _learn_more_about_pricing_link |
|
| 1308 | + * |
|
| 1309 | + * @access protected |
|
| 1310 | + * @return string |
|
| 1311 | + */ |
|
| 1312 | + protected function _learn_more_about_pricing_link() |
|
| 1313 | + { |
|
| 1314 | + return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' . __( |
|
| 1315 | + 'learn more about how pricing works', |
|
| 1316 | + 'event_espresso' |
|
| 1317 | + ) . '</a>'; |
|
| 1318 | + } |
|
| 1319 | + |
|
| 1320 | + |
|
| 1321 | + protected function _tax_settings() |
|
| 1322 | + { |
|
| 1323 | + $this->_set_add_edit_form_tags('update_tax_settings'); |
|
| 1324 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 1325 | + $this->_template_args['admin_page_content'] = $this->tax_settings_form()->get_html(); |
|
| 1326 | + $this->display_admin_page_with_sidebar(); |
|
| 1327 | + } |
|
| 1328 | + |
|
| 1329 | + |
|
| 1330 | + /** |
|
| 1331 | + * @return \EE_Form_Section_Proper |
|
| 1332 | + * @throws \EE_Error |
|
| 1333 | + */ |
|
| 1334 | + protected function tax_settings_form() |
|
| 1335 | + { |
|
| 1336 | + return new EE_Form_Section_Proper( |
|
| 1337 | + array( |
|
| 1338 | + 'name' => 'tax_settings_form', |
|
| 1339 | + 'html_id' => 'tax_settings_form', |
|
| 1340 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
| 1341 | + 'subsections' => apply_filters( |
|
| 1342 | + 'FHEE__Pricing_Admin_Page__tax_settings_form__form_subsections', |
|
| 1343 | + array( |
|
| 1344 | + 'tax_settings' => new EE_Form_Section_Proper( |
|
| 1345 | + array( |
|
| 1346 | + 'name' => 'tax_settings_tbl', |
|
| 1347 | + 'html_id' => 'tax_settings_tbl', |
|
| 1348 | + 'html_class' => 'form-table', |
|
| 1349 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 1350 | + 'subsections' => array( |
|
| 1351 | + 'prices_displayed_including_taxes' => new EE_Yes_No_Input( |
|
| 1352 | + array( |
|
| 1353 | + 'html_label_text' => __( |
|
| 1354 | + "Show Prices With Taxes Included?", |
|
| 1355 | + 'event_espresso' |
|
| 1356 | + ), |
|
| 1357 | + 'html_help_text' => __( |
|
| 1358 | + 'Indicates whether or not to display prices with the taxes included', |
|
| 1359 | + 'event_espresso' |
|
| 1360 | + ), |
|
| 1361 | + 'default' => isset( |
|
| 1362 | + EE_Registry::instance() |
|
| 1363 | + ->CFG |
|
| 1364 | + ->tax_settings |
|
| 1365 | + ->prices_displayed_including_taxes |
|
| 1366 | + ) |
|
| 1367 | + ? EE_Registry::instance() |
|
| 1368 | + ->CFG |
|
| 1369 | + ->tax_settings |
|
| 1370 | + ->prices_displayed_including_taxes |
|
| 1371 | + : true, |
|
| 1372 | + 'display_html_label_text' => false, |
|
| 1373 | + ) |
|
| 1374 | + ), |
|
| 1375 | + ), |
|
| 1376 | + ) |
|
| 1377 | + ), |
|
| 1378 | + ) |
|
| 1379 | + ), |
|
| 1380 | + ) |
|
| 1381 | + ); |
|
| 1382 | + } |
|
| 1383 | + |
|
| 1384 | + |
|
| 1385 | + /** |
|
| 1386 | + * _update_tax_settings |
|
| 1387 | + * |
|
| 1388 | + * @since 4.9.13 |
|
| 1389 | + * @return void |
|
| 1390 | + */ |
|
| 1391 | + public function _update_tax_settings() |
|
| 1392 | + { |
|
| 1393 | + if (! isset(EE_Registry::instance()->CFG->tax_settings)) { |
|
| 1394 | + EE_Registry::instance()->CFG->tax_settings = new EE_Tax_Config(); |
|
| 1395 | + } |
|
| 1396 | + try { |
|
| 1397 | + $tax_form = $this->tax_settings_form(); |
|
| 1398 | + // check for form submission |
|
| 1399 | + if ($tax_form->was_submitted()) { |
|
| 1400 | + // capture form data |
|
| 1401 | + $tax_form->receive_form_submission(); |
|
| 1402 | + // validate form data |
|
| 1403 | + if ($tax_form->is_valid()) { |
|
| 1404 | + // grab validated data from form |
|
| 1405 | + $valid_data = $tax_form->valid_data(); |
|
| 1406 | + // set data on config |
|
| 1407 | + EE_Registry::instance() |
|
| 1408 | + ->CFG |
|
| 1409 | + ->tax_settings |
|
| 1410 | + ->prices_displayed_including_taxes |
|
| 1411 | + = $valid_data['tax_settings']['prices_displayed_including_taxes']; |
|
| 1412 | + } else { |
|
| 1413 | + if ($tax_form->submission_error_message() !== '') { |
|
| 1414 | + EE_Error::add_error( |
|
| 1415 | + $tax_form->submission_error_message(), |
|
| 1416 | + __FILE__, |
|
| 1417 | + __FUNCTION__, |
|
| 1418 | + __LINE__ |
|
| 1419 | + ); |
|
| 1420 | + } |
|
| 1421 | + } |
|
| 1422 | + } |
|
| 1423 | + } catch (EE_Error $e) { |
|
| 1424 | + EE_Error::add_error($e->get_error(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1425 | + } |
|
| 1426 | + |
|
| 1427 | + $what = 'Tax Settings'; |
|
| 1428 | + $success = $this->_update_espresso_configuration( |
|
| 1429 | + $what, |
|
| 1430 | + EE_Registry::instance()->CFG->tax_settings, |
|
| 1431 | + __FILE__, |
|
| 1432 | + __FUNCTION__, |
|
| 1433 | + __LINE__ |
|
| 1434 | + ); |
|
| 1435 | + $this->_redirect_after_action($success, $what, 'updated', array('action' => 'tax_settings')); |
|
| 1436 | + } |
|
| 1437 | 1437 | } |