@@ -632,7 +632,7 @@ |
||
| 632 | 632 | * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array |
| 633 | 633 | * or EEH_MSG_Template::convert_payment_status_to_message_type |
| 634 | 634 | * @param string $payment_status The payment status being matched. |
| 635 | - * @return bool|string The payment message type slug matching the status or false if no match. |
|
| 635 | + * @return string|false The payment message type slug matching the status or false if no match. |
|
| 636 | 636 | * @throws EE_Error |
| 637 | 637 | * @throws InvalidArgumentException |
| 638 | 638 | * @throws ReflectionException |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | $error_msg = __('Please note that a system message failed to send due to a technical issue.', |
| 160 | 160 | 'event_espresso'); |
| 161 | 161 | // add specific message for developers if WP_DEBUG in on |
| 162 | - $error_msg .= '||' . $e->getMessage(); |
|
| 162 | + $error_msg .= '||'.$e->getMessage(); |
|
| 163 | 163 | EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
| 164 | 164 | } |
| 165 | 165 | } |
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | $error_msg = __('Please note that a system message failed to send due to a technical issue.', |
| 243 | 243 | 'event_espresso'); |
| 244 | 244 | // add specific message for developers if WP_DEBUG in on |
| 245 | - $error_msg .= '||' . $e->getMessage(); |
|
| 245 | + $error_msg .= '||'.$e->getMessage(); |
|
| 246 | 246 | EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
| 247 | 247 | } |
| 248 | 248 | } |
@@ -273,7 +273,7 @@ discard block |
||
| 273 | 273 | $transient_key = EE_Registry::instance()->REQ->get('key'); |
| 274 | 274 | |
| 275 | 275 | //now let's verify transient, if not valid exit immediately |
| 276 | - if (! get_transient($transient_key)) { |
|
| 276 | + if ( ! get_transient($transient_key)) { |
|
| 277 | 277 | /** |
| 278 | 278 | * trigger error so this gets in the error logs. This is important because it happens on a non-user |
| 279 | 279 | * request. |
@@ -286,7 +286,7 @@ discard block |
||
| 286 | 286 | |
| 287 | 287 | if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) { |
| 288 | 288 | |
| 289 | - $method = 'batch_' . $cron_type . '_from_queue'; |
|
| 289 | + $method = 'batch_'.$cron_type.'_from_queue'; |
|
| 290 | 290 | if (method_exists(self::$_MSG_PROCESSOR, $method)) { |
| 291 | 291 | self::$_MSG_PROCESSOR->$method(); |
| 292 | 292 | } else { |
@@ -395,9 +395,9 @@ discard block |
||
| 395 | 395 | 'messages/validators/html', |
| 396 | 396 | 'shortcodes', |
| 397 | 397 | ); |
| 398 | - $paths = array(); |
|
| 398 | + $paths = array(); |
|
| 399 | 399 | foreach ($dir_ref as $index => $dir) { |
| 400 | - $paths[$index] = EE_LIBRARIES . $dir; |
|
| 400 | + $paths[$index] = EE_LIBRARIES.$dir; |
|
| 401 | 401 | } |
| 402 | 402 | self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths); |
| 403 | 403 | } |
@@ -416,7 +416,7 @@ discard block |
||
| 416 | 416 | */ |
| 417 | 417 | protected static function _load_controller() |
| 418 | 418 | { |
| 419 | - if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) { |
|
| 419 | + if ( ! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) { |
|
| 420 | 420 | EE_Registry::instance()->load_core('Request_Handler'); |
| 421 | 421 | self::set_autoloaders(); |
| 422 | 422 | self::$_EEMSG = EE_Registry::instance()->load_lib('messages'); |
@@ -500,7 +500,7 @@ discard block |
||
| 500 | 500 | public static function maybe_registration(EE_Registration $registration, $extra_details = array()) |
| 501 | 501 | { |
| 502 | 502 | |
| 503 | - if (! self::_verify_registration_notification_send($registration, $extra_details)) { |
|
| 503 | + if ( ! self::_verify_registration_notification_send($registration, $extra_details)) { |
|
| 504 | 504 | //no messages please |
| 505 | 505 | return; |
| 506 | 506 | } |
@@ -567,7 +567,7 @@ discard block |
||
| 567 | 567 | // array( '$extra_details' => $extra_details ) |
| 568 | 568 | //); |
| 569 | 569 | // currently only using this to send messages for the primary registrant |
| 570 | - if (! $registration->is_primary_registrant()) { |
|
| 570 | + if ( ! $registration->is_primary_registrant()) { |
|
| 571 | 571 | return false; |
| 572 | 572 | } |
| 573 | 573 | // first we check if we're in admin and not doing front ajax |
@@ -580,7 +580,7 @@ discard block |
||
| 580 | 580 | } else { |
| 581 | 581 | // frontend request (either regular or via AJAX) |
| 582 | 582 | // TXN is NOT finalized ? |
| 583 | - if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) { |
|
| 583 | + if ( ! isset($extra_details['finalized']) || $extra_details['finalized'] === false) { |
|
| 584 | 584 | return false; |
| 585 | 585 | } |
| 586 | 586 | // return visit but nothing changed ??? |
@@ -670,12 +670,12 @@ discard block |
||
| 670 | 670 | } |
| 671 | 671 | |
| 672 | 672 | //make sure any incoming request data is set on the REQ so that it gets picked up later. |
| 673 | - $req_data = (array)$req_data; |
|
| 673 | + $req_data = (array) $req_data; |
|
| 674 | 674 | foreach ($req_data as $request_key => $request_value) { |
| 675 | 675 | EE_Registry::instance()->REQ->set($request_key, $request_value); |
| 676 | 676 | } |
| 677 | 677 | |
| 678 | - if (! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request()) { |
|
| 678 | + if ( ! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request()) { |
|
| 679 | 679 | return false; |
| 680 | 680 | } |
| 681 | 681 | |
@@ -708,13 +708,13 @@ discard block |
||
| 708 | 708 | self::_load_controller(); |
| 709 | 709 | |
| 710 | 710 | $msgID = EE_Registry::instance()->REQ->get('MSG_ID'); |
| 711 | - if (! $msgID) { |
|
| 711 | + if ( ! $msgID) { |
|
| 712 | 712 | EE_Error::add_error(__('Something went wrong because there is no "MSG_ID" value in the request', |
| 713 | 713 | 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
| 714 | 714 | return false; |
| 715 | 715 | } |
| 716 | 716 | |
| 717 | - self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array)$msgID); |
|
| 717 | + self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array) $msgID); |
|
| 718 | 718 | |
| 719 | 719 | //setup success message. |
| 720 | 720 | $count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
@@ -819,7 +819,7 @@ discard block |
||
| 819 | 819 | public static function send_newsletter_message($registrations, $grp_id) |
| 820 | 820 | { |
| 821 | 821 | //make sure mtp is id and set it in the EE_Request Handler later messages setup. |
| 822 | - EE_Registry::instance()->REQ->set('GRP_ID', (int)$grp_id); |
|
| 822 | + EE_Registry::instance()->REQ->set('GRP_ID', (int) $grp_id); |
|
| 823 | 823 | self::_load_controller(); |
| 824 | 824 | self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations); |
| 825 | 825 | } |
@@ -879,14 +879,14 @@ discard block |
||
| 879 | 879 | //get the message template group. |
| 880 | 880 | $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
| 881 | 881 | //if we don't have an EE_Message_Template_Group then return |
| 882 | - if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
| 882 | + if ( ! $msg_template_group instanceof EE_Message_Template_Group) { |
|
| 883 | 883 | // remove EVT_ID from query params so that global templates get picked up |
| 884 | 884 | unset($template_query_params['Event.EVT_ID']); |
| 885 | 885 | //get global template as the fallback |
| 886 | 886 | $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
| 887 | 887 | } |
| 888 | 888 | //if we don't have an EE_Message_Template_Group then return |
| 889 | - if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
| 889 | + if ( ! $msg_template_group instanceof EE_Message_Template_Group) { |
|
| 890 | 890 | return ''; |
| 891 | 891 | } |
| 892 | 892 | // generate the URL |
@@ -923,7 +923,7 @@ discard block |
||
| 923 | 923 | public static function preview_message($type, $context, $messenger, $send = false) |
| 924 | 924 | { |
| 925 | 925 | self::_load_controller(); |
| 926 | - $mtg = new EE_Message_To_Generate( |
|
| 926 | + $mtg = new EE_Message_To_Generate( |
|
| 927 | 927 | $messenger, |
| 928 | 928 | $type, |
| 929 | 929 | array(), |
@@ -1005,7 +1005,7 @@ discard block |
||
| 1005 | 1005 | public static function generate_now($message_ids) |
| 1006 | 1006 | { |
| 1007 | 1007 | self::_load_controller(); |
| 1008 | - $messages = EEM_Message::instance()->get_all( |
|
| 1008 | + $messages = EEM_Message::instance()->get_all( |
|
| 1009 | 1009 | array( |
| 1010 | 1010 | 0 => array( |
| 1011 | 1011 | 'MSG_ID' => array('IN', $message_ids), |
@@ -1018,7 +1018,7 @@ discard block |
||
| 1018 | 1018 | $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages); |
| 1019 | 1019 | } |
| 1020 | 1020 | |
| 1021 | - if (! $generated_queue instanceof EE_Messages_Queue) { |
|
| 1021 | + if ( ! $generated_queue instanceof EE_Messages_Queue) { |
|
| 1022 | 1022 | EE_Error::add_error( |
| 1023 | 1023 | __('The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.', |
| 1024 | 1024 | 'event_espresso'), |
@@ -1045,7 +1045,7 @@ discard block |
||
| 1045 | 1045 | public static function send_now($message_ids) |
| 1046 | 1046 | { |
| 1047 | 1047 | self::_load_controller(); |
| 1048 | - $messages = EEM_Message::instance()->get_all( |
|
| 1048 | + $messages = EEM_Message::instance()->get_all( |
|
| 1049 | 1049 | array( |
| 1050 | 1050 | 0 => array( |
| 1051 | 1051 | 'MSG_ID' => array('IN', $message_ids), |
@@ -1061,7 +1061,7 @@ discard block |
||
| 1061 | 1061 | $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages); |
| 1062 | 1062 | } |
| 1063 | 1063 | |
| 1064 | - if (! $sent_queue instanceof EE_Messages_Queue) { |
|
| 1064 | + if ( ! $sent_queue instanceof EE_Messages_Queue) { |
|
| 1065 | 1065 | EE_Error::add_error( |
| 1066 | 1066 | __('The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.', |
| 1067 | 1067 | 'event_espresso'), |
@@ -1200,7 +1200,7 @@ discard block |
||
| 1200 | 1200 | __FILE__, __FUNCTION__, __LINE__ |
| 1201 | 1201 | ); |
| 1202 | 1202 | } |
| 1203 | - return (bool)$queue_count; |
|
| 1203 | + return (bool) $queue_count; |
|
| 1204 | 1204 | } |
| 1205 | 1205 | |
| 1206 | 1206 | |
@@ -1231,7 +1231,7 @@ discard block |
||
| 1231 | 1231 | $info['TXN_status'] = $transaction->status_ID(); |
| 1232 | 1232 | $info['TXN_reg_steps'] = $transaction->reg_steps(); |
| 1233 | 1233 | if ($transaction->ID()) { |
| 1234 | - $index = 'EE_Transaction: ' . $transaction->ID(); |
|
| 1234 | + $index = 'EE_Transaction: '.$transaction->ID(); |
|
| 1235 | 1235 | EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index); |
| 1236 | 1236 | } |
| 1237 | 1237 | } |
@@ -18,1250 +18,1250 @@ |
||
| 18 | 18 | class EED_Messages extends EED_Module |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * This holds the EE_messages controller |
|
| 23 | - * |
|
| 24 | - * @deprecated 4.9.0 |
|
| 25 | - * @var EE_messages $_EEMSG |
|
| 26 | - */ |
|
| 27 | - protected static $_EEMSG; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * @type EE_Message_Resource_Manager $_message_resource_manager |
|
| 31 | - */ |
|
| 32 | - protected static $_message_resource_manager; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * This holds the EE_Messages_Processor business class. |
|
| 36 | - * |
|
| 37 | - * @type EE_Messages_Processor |
|
| 38 | - */ |
|
| 39 | - protected static $_MSG_PROCESSOR; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * holds all the paths for various messages components. |
|
| 43 | - * Utilized by autoloader registry |
|
| 44 | - * |
|
| 45 | - * @var array |
|
| 46 | - */ |
|
| 47 | - protected static $_MSG_PATHS; |
|
| 48 | - |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * This will hold an array of messages template packs that are registered in the messages system. |
|
| 52 | - * Format is: |
|
| 53 | - * array( |
|
| 54 | - * 'template_pack_dbref' => EE_Messages_Template_Pack (instance) |
|
| 55 | - * ) |
|
| 56 | - * |
|
| 57 | - * @var EE_Messages_Template_Pack[] |
|
| 58 | - */ |
|
| 59 | - protected static $_TMP_PACKS = array(); |
|
| 60 | - |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @return EED_Messages |
|
| 64 | - */ |
|
| 65 | - public static function instance() |
|
| 66 | - { |
|
| 67 | - return parent::get_instance(__CLASS__); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
| 73 | - * |
|
| 74 | - * @since 4.5.0 |
|
| 75 | - * @return void |
|
| 76 | - */ |
|
| 77 | - public static function set_hooks() |
|
| 78 | - { |
|
| 79 | - //actions |
|
| 80 | - add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
| 81 | - add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
| 82 | - array('EED_Messages', 'maybe_registration'), 10, 2); |
|
| 83 | - //filters |
|
| 84 | - add_filter('FHEE__EE_Registration__receipt_url__receipt_url', |
|
| 85 | - array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
| 86 | - add_filter('FHEE__EE_Registration__invoice_url__invoice_url', |
|
| 87 | - array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
| 88 | - //register routes |
|
| 89 | - self::_register_routes(); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 94 | - * |
|
| 95 | - * @access public |
|
| 96 | - * @return void |
|
| 97 | - */ |
|
| 98 | - public static function set_hooks_admin() |
|
| 99 | - { |
|
| 100 | - //actions |
|
| 101 | - add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
| 102 | - add_action('AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
| 103 | - array('EED_Messages', 'payment_reminder'), 10); |
|
| 104 | - add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
| 105 | - array('EED_Messages', 'maybe_registration'), 10, 3); |
|
| 106 | - add_action('AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
| 107 | - array('EED_Messages', 'send_newsletter_message'), 10, 2); |
|
| 108 | - add_action('AHEE__EES_Espresso_Cancelled__process_shortcode__transaction', |
|
| 109 | - array('EED_Messages', 'cancelled_registration'), 10); |
|
| 110 | - add_action('AHEE__EE_Admin_Page___process_admin_payment_notification', |
|
| 111 | - array('EED_Messages', 'process_admin_payment'), 10, 1); |
|
| 112 | - //filters |
|
| 113 | - add_filter('FHEE__EE_Admin_Page___process_resend_registration__success', |
|
| 114 | - array('EED_Messages', 'process_resend'), 10, 2); |
|
| 115 | - add_filter('FHEE__EE_Registration__receipt_url__receipt_url', |
|
| 116 | - array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
| 117 | - add_filter('FHEE__EE_Registration__invoice_url__invoice_url', |
|
| 118 | - array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * All the message triggers done by route go in here. |
|
| 124 | - * |
|
| 125 | - * @since 4.5.0 |
|
| 126 | - * @return void |
|
| 127 | - */ |
|
| 128 | - protected static function _register_routes() |
|
| 129 | - { |
|
| 130 | - EE_Config::register_route('msg_url_trigger', 'Messages', 'run'); |
|
| 131 | - EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request'); |
|
| 132 | - EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger'); |
|
| 133 | - EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger'); |
|
| 134 | - do_action('AHEE__EED_Messages___register_routes'); |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * This is called when a browser display trigger is executed. |
|
| 140 | - * The browser display trigger is typically used when a already generated message is displayed directly in the |
|
| 141 | - * browser. |
|
| 142 | - * |
|
| 143 | - * @since 4.9.0 |
|
| 144 | - * @param WP $WP |
|
| 145 | - * @throws EE_Error |
|
| 146 | - * @throws InvalidArgumentException |
|
| 147 | - * @throws ReflectionException |
|
| 148 | - * @throws InvalidDataTypeException |
|
| 149 | - * @throws InvalidInterfaceException |
|
| 150 | - */ |
|
| 151 | - public function browser_trigger($WP) |
|
| 152 | - { |
|
| 153 | - //ensure controller is loaded |
|
| 154 | - self::_load_controller(); |
|
| 155 | - $token = EE_Registry::instance()->REQ->get('token'); |
|
| 156 | - try { |
|
| 157 | - $mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager); |
|
| 158 | - self::$_MSG_PROCESSOR->generate_and_send_now($mtg); |
|
| 159 | - } catch (EE_Error $e) { |
|
| 160 | - $error_msg = __('Please note that a system message failed to send due to a technical issue.', |
|
| 161 | - 'event_espresso'); |
|
| 162 | - // add specific message for developers if WP_DEBUG in on |
|
| 163 | - $error_msg .= '||' . $e->getMessage(); |
|
| 164 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * This is called when a browser error trigger is executed. |
|
| 171 | - * When triggered this will grab the EE_Message matching the token in the request and use that to get the error |
|
| 172 | - * message and display it. |
|
| 173 | - * |
|
| 174 | - * @since 4.9.0 |
|
| 175 | - * @param $WP |
|
| 176 | - * @throws EE_Error |
|
| 177 | - * @throws InvalidArgumentException |
|
| 178 | - * @throws InvalidDataTypeException |
|
| 179 | - * @throws InvalidInterfaceException |
|
| 180 | - */ |
|
| 181 | - public function browser_error_trigger($WP) |
|
| 182 | - { |
|
| 183 | - $token = EE_Registry::instance()->REQ->get('token'); |
|
| 184 | - if ($token) { |
|
| 185 | - $message = EEM_Message::instance()->get_one_by_token($token); |
|
| 186 | - if ($message instanceof EE_Message) { |
|
| 187 | - header('HTTP/1.1 200 OK'); |
|
| 188 | - $error_msg = nl2br($message->error_message()); |
|
| 189 | - ?> |
|
| 21 | + /** |
|
| 22 | + * This holds the EE_messages controller |
|
| 23 | + * |
|
| 24 | + * @deprecated 4.9.0 |
|
| 25 | + * @var EE_messages $_EEMSG |
|
| 26 | + */ |
|
| 27 | + protected static $_EEMSG; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * @type EE_Message_Resource_Manager $_message_resource_manager |
|
| 31 | + */ |
|
| 32 | + protected static $_message_resource_manager; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * This holds the EE_Messages_Processor business class. |
|
| 36 | + * |
|
| 37 | + * @type EE_Messages_Processor |
|
| 38 | + */ |
|
| 39 | + protected static $_MSG_PROCESSOR; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * holds all the paths for various messages components. |
|
| 43 | + * Utilized by autoloader registry |
|
| 44 | + * |
|
| 45 | + * @var array |
|
| 46 | + */ |
|
| 47 | + protected static $_MSG_PATHS; |
|
| 48 | + |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * This will hold an array of messages template packs that are registered in the messages system. |
|
| 52 | + * Format is: |
|
| 53 | + * array( |
|
| 54 | + * 'template_pack_dbref' => EE_Messages_Template_Pack (instance) |
|
| 55 | + * ) |
|
| 56 | + * |
|
| 57 | + * @var EE_Messages_Template_Pack[] |
|
| 58 | + */ |
|
| 59 | + protected static $_TMP_PACKS = array(); |
|
| 60 | + |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @return EED_Messages |
|
| 64 | + */ |
|
| 65 | + public static function instance() |
|
| 66 | + { |
|
| 67 | + return parent::get_instance(__CLASS__); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
| 73 | + * |
|
| 74 | + * @since 4.5.0 |
|
| 75 | + * @return void |
|
| 76 | + */ |
|
| 77 | + public static function set_hooks() |
|
| 78 | + { |
|
| 79 | + //actions |
|
| 80 | + add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
| 81 | + add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
| 82 | + array('EED_Messages', 'maybe_registration'), 10, 2); |
|
| 83 | + //filters |
|
| 84 | + add_filter('FHEE__EE_Registration__receipt_url__receipt_url', |
|
| 85 | + array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
| 86 | + add_filter('FHEE__EE_Registration__invoice_url__invoice_url', |
|
| 87 | + array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
| 88 | + //register routes |
|
| 89 | + self::_register_routes(); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 94 | + * |
|
| 95 | + * @access public |
|
| 96 | + * @return void |
|
| 97 | + */ |
|
| 98 | + public static function set_hooks_admin() |
|
| 99 | + { |
|
| 100 | + //actions |
|
| 101 | + add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
| 102 | + add_action('AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
| 103 | + array('EED_Messages', 'payment_reminder'), 10); |
|
| 104 | + add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
| 105 | + array('EED_Messages', 'maybe_registration'), 10, 3); |
|
| 106 | + add_action('AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
| 107 | + array('EED_Messages', 'send_newsletter_message'), 10, 2); |
|
| 108 | + add_action('AHEE__EES_Espresso_Cancelled__process_shortcode__transaction', |
|
| 109 | + array('EED_Messages', 'cancelled_registration'), 10); |
|
| 110 | + add_action('AHEE__EE_Admin_Page___process_admin_payment_notification', |
|
| 111 | + array('EED_Messages', 'process_admin_payment'), 10, 1); |
|
| 112 | + //filters |
|
| 113 | + add_filter('FHEE__EE_Admin_Page___process_resend_registration__success', |
|
| 114 | + array('EED_Messages', 'process_resend'), 10, 2); |
|
| 115 | + add_filter('FHEE__EE_Registration__receipt_url__receipt_url', |
|
| 116 | + array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
| 117 | + add_filter('FHEE__EE_Registration__invoice_url__invoice_url', |
|
| 118 | + array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * All the message triggers done by route go in here. |
|
| 124 | + * |
|
| 125 | + * @since 4.5.0 |
|
| 126 | + * @return void |
|
| 127 | + */ |
|
| 128 | + protected static function _register_routes() |
|
| 129 | + { |
|
| 130 | + EE_Config::register_route('msg_url_trigger', 'Messages', 'run'); |
|
| 131 | + EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request'); |
|
| 132 | + EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger'); |
|
| 133 | + EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger'); |
|
| 134 | + do_action('AHEE__EED_Messages___register_routes'); |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * This is called when a browser display trigger is executed. |
|
| 140 | + * The browser display trigger is typically used when a already generated message is displayed directly in the |
|
| 141 | + * browser. |
|
| 142 | + * |
|
| 143 | + * @since 4.9.0 |
|
| 144 | + * @param WP $WP |
|
| 145 | + * @throws EE_Error |
|
| 146 | + * @throws InvalidArgumentException |
|
| 147 | + * @throws ReflectionException |
|
| 148 | + * @throws InvalidDataTypeException |
|
| 149 | + * @throws InvalidInterfaceException |
|
| 150 | + */ |
|
| 151 | + public function browser_trigger($WP) |
|
| 152 | + { |
|
| 153 | + //ensure controller is loaded |
|
| 154 | + self::_load_controller(); |
|
| 155 | + $token = EE_Registry::instance()->REQ->get('token'); |
|
| 156 | + try { |
|
| 157 | + $mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager); |
|
| 158 | + self::$_MSG_PROCESSOR->generate_and_send_now($mtg); |
|
| 159 | + } catch (EE_Error $e) { |
|
| 160 | + $error_msg = __('Please note that a system message failed to send due to a technical issue.', |
|
| 161 | + 'event_espresso'); |
|
| 162 | + // add specific message for developers if WP_DEBUG in on |
|
| 163 | + $error_msg .= '||' . $e->getMessage(); |
|
| 164 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * This is called when a browser error trigger is executed. |
|
| 171 | + * When triggered this will grab the EE_Message matching the token in the request and use that to get the error |
|
| 172 | + * message and display it. |
|
| 173 | + * |
|
| 174 | + * @since 4.9.0 |
|
| 175 | + * @param $WP |
|
| 176 | + * @throws EE_Error |
|
| 177 | + * @throws InvalidArgumentException |
|
| 178 | + * @throws InvalidDataTypeException |
|
| 179 | + * @throws InvalidInterfaceException |
|
| 180 | + */ |
|
| 181 | + public function browser_error_trigger($WP) |
|
| 182 | + { |
|
| 183 | + $token = EE_Registry::instance()->REQ->get('token'); |
|
| 184 | + if ($token) { |
|
| 185 | + $message = EEM_Message::instance()->get_one_by_token($token); |
|
| 186 | + if ($message instanceof EE_Message) { |
|
| 187 | + header('HTTP/1.1 200 OK'); |
|
| 188 | + $error_msg = nl2br($message->error_message()); |
|
| 189 | + ?> |
|
| 190 | 190 | <!DOCTYPE html> |
| 191 | 191 | <html> |
| 192 | 192 | <head></head> |
| 193 | 193 | <body> |
| 194 | 194 | <?php echo empty($error_msg) |
| 195 | - ? esc_html__('Unfortunately, we were unable to capture the error message for this message.', |
|
| 196 | - 'event_espresso') |
|
| 197 | - : wp_kses( |
|
| 198 | - $error_msg, |
|
| 199 | - array( |
|
| 200 | - 'a' => array( |
|
| 201 | - 'href' => array(), |
|
| 202 | - 'title' => array(), |
|
| 203 | - ), |
|
| 204 | - 'span' => array(), |
|
| 205 | - 'div' => array(), |
|
| 206 | - 'p' => array(), |
|
| 207 | - 'strong' => array(), |
|
| 208 | - 'em' => array(), |
|
| 209 | - 'br' => array(), |
|
| 210 | - ) |
|
| 211 | - ); ?> |
|
| 195 | + ? esc_html__('Unfortunately, we were unable to capture the error message for this message.', |
|
| 196 | + 'event_espresso') |
|
| 197 | + : wp_kses( |
|
| 198 | + $error_msg, |
|
| 199 | + array( |
|
| 200 | + 'a' => array( |
|
| 201 | + 'href' => array(), |
|
| 202 | + 'title' => array(), |
|
| 203 | + ), |
|
| 204 | + 'span' => array(), |
|
| 205 | + 'div' => array(), |
|
| 206 | + 'p' => array(), |
|
| 207 | + 'strong' => array(), |
|
| 208 | + 'em' => array(), |
|
| 209 | + 'br' => array(), |
|
| 210 | + ) |
|
| 211 | + ); ?> |
|
| 212 | 212 | </body> |
| 213 | 213 | </html> |
| 214 | 214 | <?php |
| 215 | - exit; |
|
| 216 | - } |
|
| 217 | - } |
|
| 218 | - return; |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - |
|
| 222 | - /** |
|
| 223 | - * This runs when the msg_url_trigger route has initiated. |
|
| 224 | - * |
|
| 225 | - * @since 4.5.0 |
|
| 226 | - * @param WP $WP |
|
| 227 | - * @throws EE_Error |
|
| 228 | - * @throws InvalidArgumentException |
|
| 229 | - * @throws ReflectionException |
|
| 230 | - * @throws InvalidDataTypeException |
|
| 231 | - * @throws InvalidInterfaceException |
|
| 232 | - */ |
|
| 233 | - public function run($WP) |
|
| 234 | - { |
|
| 235 | - //ensure controller is loaded |
|
| 236 | - self::_load_controller(); |
|
| 237 | - // attempt to process message |
|
| 238 | - try { |
|
| 239 | - /** @type EE_Message_To_Generate_From_Request $message_to_generate */ |
|
| 240 | - $message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request'); |
|
| 241 | - self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate); |
|
| 242 | - } catch (EE_Error $e) { |
|
| 243 | - $error_msg = __('Please note that a system message failed to send due to a technical issue.', |
|
| 244 | - 'event_espresso'); |
|
| 245 | - // add specific message for developers if WP_DEBUG in on |
|
| 246 | - $error_msg .= '||' . $e->getMessage(); |
|
| 247 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 248 | - } |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - |
|
| 252 | - /** |
|
| 253 | - * This is triggered by the 'msg_cron_trigger' route. |
|
| 254 | - * |
|
| 255 | - * @param WP $WP |
|
| 256 | - */ |
|
| 257 | - public function execute_batch_request($WP) |
|
| 258 | - { |
|
| 259 | - $this->run_cron(); |
|
| 260 | - header('HTTP/1.1 200 OK'); |
|
| 261 | - exit(); |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - |
|
| 265 | - /** |
|
| 266 | - * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp |
|
| 267 | - * request. |
|
| 268 | - */ |
|
| 269 | - public function run_cron() |
|
| 270 | - { |
|
| 271 | - self::_load_controller(); |
|
| 272 | - //get required vars |
|
| 273 | - $cron_type = EE_Registry::instance()->REQ->get('type'); |
|
| 274 | - $transient_key = EE_Registry::instance()->REQ->get('key'); |
|
| 275 | - |
|
| 276 | - //now let's verify transient, if not valid exit immediately |
|
| 277 | - if (! get_transient($transient_key)) { |
|
| 278 | - /** |
|
| 279 | - * trigger error so this gets in the error logs. This is important because it happens on a non-user |
|
| 280 | - * request. |
|
| 281 | - */ |
|
| 282 | - trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso')); |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - //if made it here, lets' delete the transient to keep the db clean |
|
| 286 | - delete_transient($transient_key); |
|
| 287 | - |
|
| 288 | - if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) { |
|
| 289 | - |
|
| 290 | - $method = 'batch_' . $cron_type . '_from_queue'; |
|
| 291 | - if (method_exists(self::$_MSG_PROCESSOR, $method)) { |
|
| 292 | - self::$_MSG_PROCESSOR->$method(); |
|
| 293 | - } else { |
|
| 294 | - //no matching task |
|
| 295 | - /** |
|
| 296 | - * trigger error so this gets in the error logs. This is important because it happens on a non user |
|
| 297 | - * request. |
|
| 298 | - */ |
|
| 299 | - trigger_error(esc_attr(sprintf(__('There is no task corresponding to this route %s', 'event_espresso'), |
|
| 300 | - $cron_type))); |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - do_action('FHEE__EED_Messages__run_cron__end'); |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - |
|
| 308 | - /** |
|
| 309 | - * This is used to retrieve the template pack for the given name. |
|
| 310 | - * Retrieved packs are cached on the static $_TMP_PACKS array. If there is no class matching the given name then |
|
| 311 | - * the default template pack is returned. |
|
| 312 | - * |
|
| 313 | - * @deprecated 4.9.0 @see EEH_MSG_Template::get_template_pack() |
|
| 314 | - * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used |
|
| 315 | - * in generating the Pack class name). |
|
| 316 | - * @return EE_Messages_Template_Pack |
|
| 317 | - * @throws EE_Error |
|
| 318 | - * @throws InvalidArgumentException |
|
| 319 | - * @throws ReflectionException |
|
| 320 | - * @throws InvalidDataTypeException |
|
| 321 | - * @throws InvalidInterfaceException |
|
| 322 | - */ |
|
| 323 | - public static function get_template_pack($template_pack_name) |
|
| 324 | - { |
|
| 325 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 326 | - return EEH_MSG_Template::get_template_pack($template_pack_name); |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - |
|
| 330 | - /** |
|
| 331 | - * Retrieves an array of all template packs. |
|
| 332 | - * Array is in the format array( 'dbref' => EE_Messages_Template_Pack ) |
|
| 333 | - * |
|
| 334 | - * @deprecated 4.9.0 @see EEH_MSG_Template_Pack::get_template_pack_collection |
|
| 335 | - * @return EE_Messages_Template_Pack[] |
|
| 336 | - * @throws EE_Error |
|
| 337 | - * @throws InvalidArgumentException |
|
| 338 | - * @throws ReflectionException |
|
| 339 | - * @throws InvalidDataTypeException |
|
| 340 | - * @throws InvalidInterfaceException |
|
| 341 | - */ |
|
| 342 | - public static function get_template_packs() |
|
| 343 | - { |
|
| 344 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 345 | - |
|
| 346 | - //for backward compat, let's make sure this returns in the same format as originally. |
|
| 347 | - $template_pack_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
| 348 | - $template_pack_collection->rewind(); |
|
| 349 | - $template_packs = array(); |
|
| 350 | - while ($template_pack_collection->valid()) { |
|
| 351 | - $template_packs[$template_pack_collection->current()->dbref] = $template_pack_collection->current(); |
|
| 352 | - $template_pack_collection->next(); |
|
| 353 | - } |
|
| 354 | - return $template_packs; |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - |
|
| 358 | - /** |
|
| 359 | - * This simply makes sure the autoloaders are registered for the EE_messages system. |
|
| 360 | - * |
|
| 361 | - * @since 4.5.0 |
|
| 362 | - * @return void |
|
| 363 | - * @throws EE_Error |
|
| 364 | - */ |
|
| 365 | - public static function set_autoloaders() |
|
| 366 | - { |
|
| 367 | - if (empty(self::$_MSG_PATHS)) { |
|
| 368 | - self::_set_messages_paths(); |
|
| 369 | - foreach (self::$_MSG_PATHS as $path) { |
|
| 370 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path); |
|
| 371 | - } |
|
| 372 | - // add aliases |
|
| 373 | - EEH_Autoloader::add_alias('EE_messages', 'EE_messages'); |
|
| 374 | - EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger'); |
|
| 375 | - } |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - |
|
| 379 | - /** |
|
| 380 | - * Take care of adding all the paths for the messages components to the $_MSG_PATHS property |
|
| 381 | - * for use by the Messages Autoloaders |
|
| 382 | - * |
|
| 383 | - * @since 4.5.0 |
|
| 384 | - * @return void. |
|
| 385 | - */ |
|
| 386 | - protected static function _set_messages_paths() |
|
| 387 | - { |
|
| 388 | - $dir_ref = array( |
|
| 389 | - 'messages/message_type', |
|
| 390 | - 'messages/messenger', |
|
| 391 | - 'messages/defaults', |
|
| 392 | - 'messages/defaults/email', |
|
| 393 | - 'messages/data_class', |
|
| 394 | - 'messages/validators', |
|
| 395 | - 'messages/validators/email', |
|
| 396 | - 'messages/validators/html', |
|
| 397 | - 'shortcodes', |
|
| 398 | - ); |
|
| 399 | - $paths = array(); |
|
| 400 | - foreach ($dir_ref as $index => $dir) { |
|
| 401 | - $paths[$index] = EE_LIBRARIES . $dir; |
|
| 402 | - } |
|
| 403 | - self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths); |
|
| 404 | - } |
|
| 405 | - |
|
| 406 | - |
|
| 407 | - /** |
|
| 408 | - * Takes care of loading dependencies |
|
| 409 | - * |
|
| 410 | - * @since 4.5.0 |
|
| 411 | - * @return void |
|
| 412 | - * @throws EE_Error |
|
| 413 | - * @throws InvalidArgumentException |
|
| 414 | - * @throws ReflectionException |
|
| 415 | - * @throws InvalidDataTypeException |
|
| 416 | - * @throws InvalidInterfaceException |
|
| 417 | - */ |
|
| 418 | - protected static function _load_controller() |
|
| 419 | - { |
|
| 420 | - if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) { |
|
| 421 | - EE_Registry::instance()->load_core('Request_Handler'); |
|
| 422 | - self::set_autoloaders(); |
|
| 423 | - self::$_EEMSG = EE_Registry::instance()->load_lib('messages'); |
|
| 424 | - self::$_MSG_PROCESSOR = EE_Registry::instance()->load_lib('Messages_Processor'); |
|
| 425 | - self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 426 | - } |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - |
|
| 430 | - /** |
|
| 431 | - * @param EE_Transaction $transaction |
|
| 432 | - * @throws EE_Error |
|
| 433 | - * @throws InvalidArgumentException |
|
| 434 | - * @throws InvalidDataTypeException |
|
| 435 | - * @throws InvalidInterfaceException |
|
| 436 | - * @throws ReflectionException |
|
| 437 | - */ |
|
| 438 | - public static function payment_reminder(EE_Transaction $transaction) |
|
| 439 | - { |
|
| 440 | - self::_load_controller(); |
|
| 441 | - $data = array($transaction, null); |
|
| 442 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data); |
|
| 443 | - } |
|
| 444 | - |
|
| 445 | - |
|
| 446 | - /** |
|
| 447 | - * Any messages triggers for after successful gateway payments should go in here. |
|
| 448 | - * |
|
| 449 | - * @param EE_Transaction $transaction object |
|
| 450 | - * @param EE_Payment $payment object |
|
| 451 | - * @return void |
|
| 452 | - * @throws EE_Error |
|
| 453 | - * @throws InvalidArgumentException |
|
| 454 | - * @throws ReflectionException |
|
| 455 | - * @throws InvalidDataTypeException |
|
| 456 | - * @throws InvalidInterfaceException |
|
| 457 | - */ |
|
| 458 | - public static function payment(EE_Transaction $transaction, EE_Payment $payment) |
|
| 459 | - { |
|
| 460 | - self::_load_controller(); |
|
| 461 | - $data = array($transaction, $payment); |
|
| 462 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 463 | - $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
| 464 | - //if payment amount is less than 0 then switch to payment_refund message type. |
|
| 465 | - $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
| 466 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
| 467 | - } |
|
| 468 | - |
|
| 469 | - |
|
| 470 | - /** |
|
| 471 | - * @param EE_Transaction $transaction |
|
| 472 | - * @throws EE_Error |
|
| 473 | - * @throws InvalidArgumentException |
|
| 474 | - * @throws InvalidDataTypeException |
|
| 475 | - * @throws InvalidInterfaceException |
|
| 476 | - * @throws ReflectionException |
|
| 477 | - */ |
|
| 478 | - public static function cancelled_registration(EE_Transaction $transaction) |
|
| 479 | - { |
|
| 480 | - self::_load_controller(); |
|
| 481 | - $data = array($transaction, null); |
|
| 482 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data); |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - |
|
| 486 | - |
|
| 487 | - /** |
|
| 488 | - * Trigger for Registration messages |
|
| 489 | - * Note that what registration message type is sent depends on what the reg status is for the registrations on the |
|
| 490 | - * incoming transaction. |
|
| 491 | - * |
|
| 492 | - * @param EE_Registration $registration |
|
| 493 | - * @param array $extra_details |
|
| 494 | - * @return void |
|
| 495 | - * @throws EE_Error |
|
| 496 | - * @throws InvalidArgumentException |
|
| 497 | - * @throws InvalidDataTypeException |
|
| 498 | - * @throws InvalidInterfaceException |
|
| 499 | - * @throws ReflectionException |
|
| 500 | - * @throws EntityNotFoundException |
|
| 501 | - */ |
|
| 502 | - public static function maybe_registration(EE_Registration $registration, $extra_details = array()) |
|
| 503 | - { |
|
| 504 | - |
|
| 505 | - if (! self::_verify_registration_notification_send($registration, $extra_details)) { |
|
| 506 | - //no messages please |
|
| 507 | - return; |
|
| 508 | - } |
|
| 509 | - |
|
| 510 | - // get all non-trashed registrations so we make sure we send messages for the right status. |
|
| 511 | - $all_registrations = $registration->transaction()->registrations( |
|
| 512 | - array( |
|
| 513 | - array('REG_deleted' => false), |
|
| 514 | - 'order_by' => array( |
|
| 515 | - 'Event.EVT_name' => 'ASC', |
|
| 516 | - 'Attendee.ATT_lname' => 'ASC', |
|
| 517 | - 'Attendee.ATT_fname' => 'ASC' |
|
| 518 | - ) |
|
| 519 | - ) |
|
| 520 | - ); |
|
| 521 | - //cached array of statuses so we only trigger messages once per status. |
|
| 522 | - $statuses_sent = array(); |
|
| 523 | - self::_load_controller(); |
|
| 524 | - $mtgs = array(); |
|
| 525 | - |
|
| 526 | - //loop through registrations and trigger messages once per status. |
|
| 527 | - foreach ($all_registrations as $reg) { |
|
| 528 | - |
|
| 529 | - //already triggered? |
|
| 530 | - if (in_array($reg->status_ID(), $statuses_sent)) { |
|
| 531 | - continue; |
|
| 532 | - } |
|
| 533 | - |
|
| 534 | - $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID()); |
|
| 535 | - $mtgs = array_merge( |
|
| 536 | - $mtgs, |
|
| 537 | - self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
| 538 | - $message_type, |
|
| 539 | - array($registration->transaction(), null, $reg->status_ID()) |
|
| 540 | - ) |
|
| 541 | - ); |
|
| 542 | - $statuses_sent[] = $reg->status_ID(); |
|
| 543 | - } |
|
| 544 | - |
|
| 545 | - if (count($statuses_sent) > 1) { |
|
| 546 | - $mtgs = array_merge( |
|
| 547 | - $mtgs, |
|
| 548 | - self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
| 549 | - 'registration_summary', |
|
| 550 | - array($registration->transaction(), null) |
|
| 551 | - ) |
|
| 552 | - ); |
|
| 553 | - } |
|
| 554 | - |
|
| 555 | - //batch queue and initiate request |
|
| 556 | - self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs); |
|
| 557 | - self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
| 558 | - } |
|
| 559 | - |
|
| 560 | - |
|
| 561 | - /** |
|
| 562 | - * This is a helper method used to very whether a registration notification should be sent or |
|
| 563 | - * not. Prevents duplicate notifications going out for registration context notifications. |
|
| 564 | - * |
|
| 565 | - * @param EE_Registration $registration [description] |
|
| 566 | - * @param array $extra_details [description] |
|
| 567 | - * @return bool true = send away, false = nope halt the presses. |
|
| 568 | - */ |
|
| 569 | - protected static function _verify_registration_notification_send( |
|
| 570 | - EE_Registration $registration, |
|
| 571 | - $extra_details = array() |
|
| 572 | - ) { |
|
| 573 | - //self::log( |
|
| 574 | - // __CLASS__, __FUNCTION__, __LINE__, |
|
| 575 | - // $registration->transaction(), |
|
| 576 | - // array( '$extra_details' => $extra_details ) |
|
| 577 | - //); |
|
| 578 | - // currently only using this to send messages for the primary registrant |
|
| 579 | - if (! $registration->is_primary_registrant()) { |
|
| 580 | - return false; |
|
| 581 | - } |
|
| 582 | - // first we check if we're in admin and not doing front ajax |
|
| 583 | - if (is_admin() && ! EE_FRONT_AJAX) { |
|
| 584 | - //make sure appropriate admin params are set for sending messages |
|
| 585 | - if (empty($_REQUEST['txn_reg_status_change']['send_notifications']) || ! absint($_REQUEST['txn_reg_status_change']['send_notifications'])) { |
|
| 586 | - //no messages sent please. |
|
| 587 | - return false; |
|
| 588 | - } |
|
| 589 | - } else { |
|
| 590 | - // frontend request (either regular or via AJAX) |
|
| 591 | - // TXN is NOT finalized ? |
|
| 592 | - if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) { |
|
| 593 | - return false; |
|
| 594 | - } |
|
| 595 | - // return visit but nothing changed ??? |
|
| 596 | - if ( |
|
| 597 | - isset($extra_details['revisit'], $extra_details['status_updates']) && |
|
| 598 | - $extra_details['revisit'] && ! $extra_details['status_updates'] |
|
| 599 | - ) { |
|
| 600 | - return false; |
|
| 601 | - } |
|
| 602 | - // NOT sending messages && reg status is something other than "Not-Approved" |
|
| 603 | - if ( |
|
| 604 | - ! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) && |
|
| 605 | - $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
| 606 | - ) { |
|
| 607 | - return false; |
|
| 608 | - } |
|
| 609 | - } |
|
| 610 | - // release the kraken |
|
| 611 | - return true; |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - |
|
| 615 | - /** |
|
| 616 | - * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that |
|
| 617 | - * status id. |
|
| 618 | - * |
|
| 619 | - * @deprecated 4.9.0 Use EEH_MSG_Template::reg_status_to_message_type_array() |
|
| 620 | - * or EEH_MSG_Template::convert_reg_status_to_message_type |
|
| 621 | - * @param string $reg_status |
|
| 622 | - * @return array |
|
| 623 | - * @throws EE_Error |
|
| 624 | - * @throws InvalidArgumentException |
|
| 625 | - * @throws ReflectionException |
|
| 626 | - * @throws InvalidDataTypeException |
|
| 627 | - * @throws InvalidInterfaceException |
|
| 628 | - */ |
|
| 629 | - protected static function _get_reg_status_array($reg_status = '') |
|
| 630 | - { |
|
| 631 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 632 | - return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
| 633 | - ? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
| 634 | - : EEH_MSG_Template::reg_status_to_message_type_array(); |
|
| 635 | - } |
|
| 636 | - |
|
| 637 | - |
|
| 638 | - /** |
|
| 639 | - * Simply returns the payment message type for the given payment status. |
|
| 640 | - * |
|
| 641 | - * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array |
|
| 642 | - * or EEH_MSG_Template::convert_payment_status_to_message_type |
|
| 643 | - * @param string $payment_status The payment status being matched. |
|
| 644 | - * @return bool|string The payment message type slug matching the status or false if no match. |
|
| 645 | - * @throws EE_Error |
|
| 646 | - * @throws InvalidArgumentException |
|
| 647 | - * @throws ReflectionException |
|
| 648 | - * @throws InvalidDataTypeException |
|
| 649 | - * @throws InvalidInterfaceException |
|
| 650 | - */ |
|
| 651 | - protected static function _get_payment_message_type($payment_status) |
|
| 652 | - { |
|
| 653 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 654 | - return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
| 655 | - ? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
| 656 | - : false; |
|
| 657 | - } |
|
| 658 | - |
|
| 659 | - |
|
| 660 | - /** |
|
| 661 | - * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
| 662 | - * |
|
| 663 | - * @access public |
|
| 664 | - * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages |
|
| 665 | - * @return bool success/fail |
|
| 666 | - * @throws EE_Error |
|
| 667 | - * @throws InvalidArgumentException |
|
| 668 | - * @throws InvalidDataTypeException |
|
| 669 | - * @throws InvalidInterfaceException |
|
| 670 | - * @throws ReflectionException |
|
| 671 | - */ |
|
| 672 | - public static function process_resend($req_data) |
|
| 673 | - { |
|
| 674 | - self::_load_controller(); |
|
| 675 | - |
|
| 676 | - //if $msgID in this request then skip to the new resend_message |
|
| 677 | - if (EE_Registry::instance()->REQ->get('MSG_ID')) { |
|
| 678 | - return self::resend_message(); |
|
| 679 | - } |
|
| 680 | - |
|
| 681 | - //make sure any incoming request data is set on the REQ so that it gets picked up later. |
|
| 682 | - $req_data = (array)$req_data; |
|
| 683 | - foreach ($req_data as $request_key => $request_value) { |
|
| 684 | - EE_Registry::instance()->REQ->set($request_key, $request_value); |
|
| 685 | - } |
|
| 686 | - |
|
| 687 | - if (! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request()) { |
|
| 688 | - return false; |
|
| 689 | - } |
|
| 690 | - |
|
| 691 | - try { |
|
| 692 | - self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send); |
|
| 693 | - self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
| 694 | - } catch (EE_Error $e) { |
|
| 695 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 696 | - return false; |
|
| 697 | - } |
|
| 698 | - EE_Error::add_success( |
|
| 699 | - __('Messages have been successfully queued for generation and sending.', 'event_espresso') |
|
| 700 | - ); |
|
| 701 | - return true; //everything got queued. |
|
| 702 | - } |
|
| 703 | - |
|
| 704 | - |
|
| 705 | - /** |
|
| 706 | - * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
| 707 | - * |
|
| 708 | - * @return bool |
|
| 709 | - * @throws EE_Error |
|
| 710 | - * @throws InvalidArgumentException |
|
| 711 | - * @throws InvalidDataTypeException |
|
| 712 | - * @throws InvalidInterfaceException |
|
| 713 | - * @throws ReflectionException |
|
| 714 | - */ |
|
| 715 | - public static function resend_message() |
|
| 716 | - { |
|
| 717 | - self::_load_controller(); |
|
| 718 | - |
|
| 719 | - $msgID = EE_Registry::instance()->REQ->get('MSG_ID'); |
|
| 720 | - if (! $msgID) { |
|
| 721 | - EE_Error::add_error(__('Something went wrong because there is no "MSG_ID" value in the request', |
|
| 722 | - 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 723 | - return false; |
|
| 724 | - } |
|
| 725 | - |
|
| 726 | - self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array)$msgID); |
|
| 727 | - |
|
| 728 | - //setup success message. |
|
| 729 | - $count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
| 730 | - EE_Error::add_success(sprintf( |
|
| 731 | - _n( |
|
| 732 | - 'There was %d message queued for resending.', |
|
| 733 | - 'There were %d messages queued for resending.', |
|
| 734 | - $count_ready_for_resend, |
|
| 735 | - 'event_espresso' |
|
| 736 | - ), |
|
| 737 | - $count_ready_for_resend |
|
| 738 | - )); |
|
| 739 | - return true; |
|
| 740 | - } |
|
| 741 | - |
|
| 742 | - |
|
| 743 | - /** |
|
| 744 | - * Message triggers for manual payment applied by admin |
|
| 745 | - * |
|
| 746 | - * @param EE_Payment $payment EE_payment object |
|
| 747 | - * @return bool success/fail |
|
| 748 | - * @throws EE_Error |
|
| 749 | - * @throws InvalidArgumentException |
|
| 750 | - * @throws ReflectionException |
|
| 751 | - * @throws InvalidDataTypeException |
|
| 752 | - * @throws InvalidInterfaceException |
|
| 753 | - */ |
|
| 754 | - public static function process_admin_payment(EE_Payment $payment) |
|
| 755 | - { |
|
| 756 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 757 | - //we need to get the transaction object |
|
| 758 | - $transaction = $payment->transaction(); |
|
| 759 | - if ($transaction instanceof EE_Transaction) { |
|
| 760 | - $data = array($transaction, $payment); |
|
| 761 | - $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
| 762 | - |
|
| 763 | - //if payment amount is less than 0 then switch to payment_refund message type. |
|
| 764 | - $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
| 765 | - |
|
| 766 | - //if payment_refund is selected, but the status is NOT accepted. Then change message type to false so NO message notification goes out. |
|
| 767 | - $message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved ? false : $message_type; |
|
| 768 | - |
|
| 769 | - self::_load_controller(); |
|
| 770 | - |
|
| 771 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
| 772 | - |
|
| 773 | - //get count of queued for generation |
|
| 774 | - $count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(array( |
|
| 775 | - EEM_Message::status_incomplete, |
|
| 776 | - EEM_Message::status_idle, |
|
| 777 | - )); |
|
| 778 | - |
|
| 779 | - if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) { |
|
| 780 | - add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
| 781 | - return true; |
|
| 782 | - } else { |
|
| 783 | - $count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::instance()->stati_indicating_failed_sending()); |
|
| 784 | - /** |
|
| 785 | - * Verify that there are actually errors. If not then we return a success message because the queue might have been emptied due to successful |
|
| 786 | - * IMMEDIATE generation. |
|
| 787 | - */ |
|
| 788 | - if ($count_failed > 0) { |
|
| 789 | - EE_Error::add_error(sprintf( |
|
| 790 | - _n( |
|
| 791 | - 'The payment notification generation failed.', |
|
| 792 | - '%d payment notifications failed being sent.', |
|
| 793 | - $count_failed, |
|
| 794 | - 'event_espresso' |
|
| 795 | - ), |
|
| 796 | - $count_failed |
|
| 797 | - ), __FILE__, __FUNCTION__, __LINE__); |
|
| 798 | - |
|
| 799 | - return false; |
|
| 800 | - } else { |
|
| 801 | - add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
| 802 | - return true; |
|
| 803 | - } |
|
| 804 | - } |
|
| 805 | - } else { |
|
| 806 | - EE_Error::add_error( |
|
| 807 | - 'Unable to generate the payment notification because the given value for the transaction is invalid.', |
|
| 808 | - 'event_espresso' |
|
| 809 | - ); |
|
| 810 | - return false; |
|
| 811 | - } |
|
| 812 | - } |
|
| 813 | - |
|
| 814 | - |
|
| 815 | - /** |
|
| 816 | - * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger |
|
| 817 | - * |
|
| 818 | - * @since 4.3.0 |
|
| 819 | - * @param EE_Registration[] $registrations an array of EE_Registration objects |
|
| 820 | - * @param int $grp_id a specific message template group id. |
|
| 821 | - * @return void |
|
| 822 | - * @throws EE_Error |
|
| 823 | - * @throws InvalidArgumentException |
|
| 824 | - * @throws InvalidDataTypeException |
|
| 825 | - * @throws InvalidInterfaceException |
|
| 826 | - * @throws ReflectionException |
|
| 827 | - */ |
|
| 828 | - public static function send_newsletter_message($registrations, $grp_id) |
|
| 829 | - { |
|
| 830 | - //make sure mtp is id and set it in the EE_Request Handler later messages setup. |
|
| 831 | - EE_Registry::instance()->REQ->set('GRP_ID', (int)$grp_id); |
|
| 832 | - self::_load_controller(); |
|
| 833 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations); |
|
| 834 | - } |
|
| 835 | - |
|
| 836 | - |
|
| 837 | - /** |
|
| 838 | - * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url |
|
| 839 | - * |
|
| 840 | - * @since 4.3.0 |
|
| 841 | - * @param string $registration_message_trigger_url |
|
| 842 | - * @param EE_Registration $registration |
|
| 843 | - * @param string $messenger |
|
| 844 | - * @param string $message_type |
|
| 845 | - * @return string |
|
| 846 | - * @throws EE_Error |
|
| 847 | - * @throws InvalidArgumentException |
|
| 848 | - * @throws InvalidDataTypeException |
|
| 849 | - * @throws InvalidInterfaceException |
|
| 850 | - */ |
|
| 851 | - public static function registration_message_trigger_url( |
|
| 852 | - $registration_message_trigger_url, |
|
| 853 | - EE_Registration $registration, |
|
| 854 | - $messenger = 'html', |
|
| 855 | - $message_type = 'invoice' |
|
| 856 | - ) { |
|
| 857 | - // whitelist $messenger |
|
| 858 | - switch ($messenger) { |
|
| 859 | - case 'pdf' : |
|
| 860 | - $sending_messenger = 'pdf'; |
|
| 861 | - $generating_messenger = 'html'; |
|
| 862 | - break; |
|
| 863 | - case 'html' : |
|
| 864 | - default : |
|
| 865 | - $sending_messenger = 'html'; |
|
| 866 | - $generating_messenger = 'html'; |
|
| 867 | - break; |
|
| 868 | - } |
|
| 869 | - // whitelist $message_type |
|
| 870 | - switch ($message_type) { |
|
| 871 | - case 'receipt' : |
|
| 872 | - $message_type = 'receipt'; |
|
| 873 | - break; |
|
| 874 | - case 'invoice' : |
|
| 875 | - default : |
|
| 876 | - $message_type = 'invoice'; |
|
| 877 | - break; |
|
| 878 | - } |
|
| 879 | - // verify that both the messenger AND the message type are active |
|
| 880 | - if (EEH_MSG_Template::is_messenger_active($sending_messenger) && EEH_MSG_Template::is_mt_active($message_type)) { |
|
| 881 | - //need to get the correct message template group for this (i.e. is there a custom invoice for the event this registration is registered for?) |
|
| 882 | - $template_query_params = array( |
|
| 883 | - 'MTP_is_active' => true, |
|
| 884 | - 'MTP_messenger' => $generating_messenger, |
|
| 885 | - 'MTP_message_type' => $message_type, |
|
| 886 | - 'Event.EVT_ID' => $registration->event_ID(), |
|
| 887 | - ); |
|
| 888 | - //get the message template group. |
|
| 889 | - $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
| 890 | - //if we don't have an EE_Message_Template_Group then return |
|
| 891 | - if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
| 892 | - // remove EVT_ID from query params so that global templates get picked up |
|
| 893 | - unset($template_query_params['Event.EVT_ID']); |
|
| 894 | - //get global template as the fallback |
|
| 895 | - $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
| 896 | - } |
|
| 897 | - //if we don't have an EE_Message_Template_Group then return |
|
| 898 | - if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
| 899 | - return ''; |
|
| 900 | - } |
|
| 901 | - // generate the URL |
|
| 902 | - $registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger( |
|
| 903 | - $sending_messenger, |
|
| 904 | - $generating_messenger, |
|
| 905 | - 'purchaser', |
|
| 906 | - $message_type, |
|
| 907 | - $registration, |
|
| 908 | - $msg_template_group->ID(), |
|
| 909 | - $registration->transaction_ID() |
|
| 910 | - ); |
|
| 911 | - |
|
| 912 | - } |
|
| 913 | - return $registration_message_trigger_url; |
|
| 914 | - } |
|
| 915 | - |
|
| 916 | - |
|
| 917 | - /** |
|
| 918 | - * Use to generate and return a message preview! |
|
| 919 | - * |
|
| 920 | - * @param string $type This should correspond with a valid message type |
|
| 921 | - * @param string $context This should correspond with a valid context for the message type |
|
| 922 | - * @param string $messenger This should correspond with a valid messenger. |
|
| 923 | - * @param bool $send true we will do a test send using the messenger delivery, false we just do a regular |
|
| 924 | - * preview |
|
| 925 | - * @return bool|string The body of the message or if send is requested, sends. |
|
| 926 | - * @throws EE_Error |
|
| 927 | - * @throws InvalidArgumentException |
|
| 928 | - * @throws InvalidDataTypeException |
|
| 929 | - * @throws InvalidInterfaceException |
|
| 930 | - * @throws ReflectionException |
|
| 931 | - */ |
|
| 932 | - public static function preview_message($type, $context, $messenger, $send = false) |
|
| 933 | - { |
|
| 934 | - self::_load_controller(); |
|
| 935 | - $mtg = new EE_Message_To_Generate( |
|
| 936 | - $messenger, |
|
| 937 | - $type, |
|
| 938 | - array(), |
|
| 939 | - $context, |
|
| 940 | - true |
|
| 941 | - ); |
|
| 942 | - $generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send); |
|
| 943 | - if ($generated_preview_queue instanceof EE_Messages_Queue) { |
|
| 944 | - //loop through all content for the preview and remove any persisted records. |
|
| 945 | - $content = ''; |
|
| 946 | - foreach ($generated_preview_queue->get_message_repository() as $message) { |
|
| 947 | - $content = $message->content(); |
|
| 948 | - if ($message->ID() > 0 && $message->STS_ID() !== EEM_Message::status_failed) { |
|
| 949 | - $message->delete(); |
|
| 950 | - } |
|
| 951 | - } |
|
| 952 | - return $content; |
|
| 953 | - } else { |
|
| 954 | - return $generated_preview_queue; |
|
| 955 | - } |
|
| 956 | - } |
|
| 957 | - |
|
| 958 | - |
|
| 959 | - /** |
|
| 960 | - * This is a method that allows for sending a message using a messenger matching the string given and the provided |
|
| 961 | - * EE_Message_Queue object. The EE_Message_Queue object is used to create a single aggregate EE_Message via the |
|
| 962 | - * content found in the EE_Message objects in the queue. |
|
| 963 | - * |
|
| 964 | - * @since 4.9.0 |
|
| 965 | - * @param string $messenger a string matching a valid active messenger in the system |
|
| 966 | - * @param string $message_type Although it seems contrary to the name of the method, a message |
|
| 967 | - * type name is still required to send along the message type to the |
|
| 968 | - * messenger because this is used for determining what specific |
|
| 969 | - * variations might be loaded for the generated message. |
|
| 970 | - * @param EE_Messages_Queue $queue |
|
| 971 | - * @param string $custom_subject Can be used to set what the custom subject string will be on the |
|
| 972 | - * aggregate EE_Message object. |
|
| 973 | - * @return bool success or fail. |
|
| 974 | - * @throws EE_Error |
|
| 975 | - * @throws InvalidArgumentException |
|
| 976 | - * @throws ReflectionException |
|
| 977 | - * @throws InvalidDataTypeException |
|
| 978 | - * @throws InvalidInterfaceException |
|
| 979 | - */ |
|
| 980 | - public static function send_message_with_messenger_only( |
|
| 981 | - $messenger, |
|
| 982 | - $message_type, |
|
| 983 | - EE_Messages_Queue $queue, |
|
| 984 | - $custom_subject = '' |
|
| 985 | - ) { |
|
| 986 | - self::_load_controller(); |
|
| 987 | - /** @type EE_Message_To_Generate_From_Queue $message_to_generate */ |
|
| 988 | - $message_to_generate = EE_Registry::instance()->load_lib( |
|
| 989 | - 'Message_To_Generate_From_Queue', |
|
| 990 | - array( |
|
| 991 | - $messenger, |
|
| 992 | - $message_type, |
|
| 993 | - $queue, |
|
| 994 | - $custom_subject, |
|
| 995 | - ) |
|
| 996 | - ); |
|
| 997 | - return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate); |
|
| 998 | - } |
|
| 999 | - |
|
| 1000 | - |
|
| 1001 | - /** |
|
| 1002 | - * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation) |
|
| 1003 | - * |
|
| 1004 | - * @since 4.9.0 |
|
| 1005 | - * @param array $message_ids An array of message ids |
|
| 1006 | - * @return bool|EE_Messages_Queue false if nothing was generated, EE_Messages_Queue containing generated |
|
| 1007 | - * messages. |
|
| 1008 | - * @throws EE_Error |
|
| 1009 | - * @throws InvalidArgumentException |
|
| 1010 | - * @throws InvalidDataTypeException |
|
| 1011 | - * @throws InvalidInterfaceException |
|
| 1012 | - * @throws ReflectionException |
|
| 1013 | - */ |
|
| 1014 | - public static function generate_now($message_ids) |
|
| 1015 | - { |
|
| 1016 | - self::_load_controller(); |
|
| 1017 | - $messages = EEM_Message::instance()->get_all( |
|
| 1018 | - array( |
|
| 1019 | - 0 => array( |
|
| 1020 | - 'MSG_ID' => array('IN', $message_ids), |
|
| 1021 | - 'STS_ID' => EEM_Message::status_incomplete, |
|
| 1022 | - ), |
|
| 1023 | - ) |
|
| 1024 | - ); |
|
| 1025 | - $generated_queue = false; |
|
| 1026 | - if ($messages) { |
|
| 1027 | - $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages); |
|
| 1028 | - } |
|
| 1029 | - |
|
| 1030 | - if (! $generated_queue instanceof EE_Messages_Queue) { |
|
| 1031 | - EE_Error::add_error( |
|
| 1032 | - __('The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.', |
|
| 1033 | - 'event_espresso'), |
|
| 1034 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1035 | - ); |
|
| 1036 | - } |
|
| 1037 | - return $generated_queue; |
|
| 1038 | - } |
|
| 1039 | - |
|
| 1040 | - |
|
| 1041 | - /** |
|
| 1042 | - * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or, |
|
| 1043 | - * EEM_Message::status_idle |
|
| 1044 | - * |
|
| 1045 | - * @since 4.9.0 |
|
| 1046 | - * @param $message_ids |
|
| 1047 | - * @return bool|EE_Messages_Queue false if no messages sent. |
|
| 1048 | - * @throws EE_Error |
|
| 1049 | - * @throws InvalidArgumentException |
|
| 1050 | - * @throws InvalidDataTypeException |
|
| 1051 | - * @throws InvalidInterfaceException |
|
| 1052 | - * @throws ReflectionException |
|
| 1053 | - */ |
|
| 1054 | - public static function send_now($message_ids) |
|
| 1055 | - { |
|
| 1056 | - self::_load_controller(); |
|
| 1057 | - $messages = EEM_Message::instance()->get_all( |
|
| 1058 | - array( |
|
| 1059 | - 0 => array( |
|
| 1060 | - 'MSG_ID' => array('IN', $message_ids), |
|
| 1061 | - 'STS_ID' => array( |
|
| 1062 | - 'IN', |
|
| 1063 | - array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry), |
|
| 1064 | - ), |
|
| 1065 | - ), |
|
| 1066 | - ) |
|
| 1067 | - ); |
|
| 1068 | - $sent_queue = false; |
|
| 1069 | - if ($messages) { |
|
| 1070 | - $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages); |
|
| 1071 | - } |
|
| 1072 | - |
|
| 1073 | - if (! $sent_queue instanceof EE_Messages_Queue) { |
|
| 1074 | - EE_Error::add_error( |
|
| 1075 | - __('The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.', |
|
| 1076 | - 'event_espresso'), |
|
| 1077 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1078 | - ); |
|
| 1079 | - } else { |
|
| 1080 | - //can count how many sent by using the messages in the queue |
|
| 1081 | - $sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent()); |
|
| 1082 | - if ($sent_count > 0) { |
|
| 1083 | - EE_Error::add_success( |
|
| 1084 | - sprintf( |
|
| 1085 | - _n( |
|
| 1086 | - 'There was %d message successfully sent.', |
|
| 1087 | - 'There were %d messages successfully sent.', |
|
| 1088 | - $sent_count, |
|
| 1089 | - 'event_espresso' |
|
| 1090 | - ), |
|
| 1091 | - $sent_count |
|
| 1092 | - ) |
|
| 1093 | - ); |
|
| 1094 | - } else { |
|
| 1095 | - EE_Error::overwrite_errors(); |
|
| 1096 | - EE_Error::add_error( |
|
| 1097 | - __('No message was sent because of problems with sending. Either all the messages you selected were not a sendable message, they were ALREADY sent on a different scheduled task, or there was an error. |
|
| 215 | + exit; |
|
| 216 | + } |
|
| 217 | + } |
|
| 218 | + return; |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + |
|
| 222 | + /** |
|
| 223 | + * This runs when the msg_url_trigger route has initiated. |
|
| 224 | + * |
|
| 225 | + * @since 4.5.0 |
|
| 226 | + * @param WP $WP |
|
| 227 | + * @throws EE_Error |
|
| 228 | + * @throws InvalidArgumentException |
|
| 229 | + * @throws ReflectionException |
|
| 230 | + * @throws InvalidDataTypeException |
|
| 231 | + * @throws InvalidInterfaceException |
|
| 232 | + */ |
|
| 233 | + public function run($WP) |
|
| 234 | + { |
|
| 235 | + //ensure controller is loaded |
|
| 236 | + self::_load_controller(); |
|
| 237 | + // attempt to process message |
|
| 238 | + try { |
|
| 239 | + /** @type EE_Message_To_Generate_From_Request $message_to_generate */ |
|
| 240 | + $message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request'); |
|
| 241 | + self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate); |
|
| 242 | + } catch (EE_Error $e) { |
|
| 243 | + $error_msg = __('Please note that a system message failed to send due to a technical issue.', |
|
| 244 | + 'event_espresso'); |
|
| 245 | + // add specific message for developers if WP_DEBUG in on |
|
| 246 | + $error_msg .= '||' . $e->getMessage(); |
|
| 247 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 248 | + } |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + |
|
| 252 | + /** |
|
| 253 | + * This is triggered by the 'msg_cron_trigger' route. |
|
| 254 | + * |
|
| 255 | + * @param WP $WP |
|
| 256 | + */ |
|
| 257 | + public function execute_batch_request($WP) |
|
| 258 | + { |
|
| 259 | + $this->run_cron(); |
|
| 260 | + header('HTTP/1.1 200 OK'); |
|
| 261 | + exit(); |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + |
|
| 265 | + /** |
|
| 266 | + * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp |
|
| 267 | + * request. |
|
| 268 | + */ |
|
| 269 | + public function run_cron() |
|
| 270 | + { |
|
| 271 | + self::_load_controller(); |
|
| 272 | + //get required vars |
|
| 273 | + $cron_type = EE_Registry::instance()->REQ->get('type'); |
|
| 274 | + $transient_key = EE_Registry::instance()->REQ->get('key'); |
|
| 275 | + |
|
| 276 | + //now let's verify transient, if not valid exit immediately |
|
| 277 | + if (! get_transient($transient_key)) { |
|
| 278 | + /** |
|
| 279 | + * trigger error so this gets in the error logs. This is important because it happens on a non-user |
|
| 280 | + * request. |
|
| 281 | + */ |
|
| 282 | + trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso')); |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + //if made it here, lets' delete the transient to keep the db clean |
|
| 286 | + delete_transient($transient_key); |
|
| 287 | + |
|
| 288 | + if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) { |
|
| 289 | + |
|
| 290 | + $method = 'batch_' . $cron_type . '_from_queue'; |
|
| 291 | + if (method_exists(self::$_MSG_PROCESSOR, $method)) { |
|
| 292 | + self::$_MSG_PROCESSOR->$method(); |
|
| 293 | + } else { |
|
| 294 | + //no matching task |
|
| 295 | + /** |
|
| 296 | + * trigger error so this gets in the error logs. This is important because it happens on a non user |
|
| 297 | + * request. |
|
| 298 | + */ |
|
| 299 | + trigger_error(esc_attr(sprintf(__('There is no task corresponding to this route %s', 'event_espresso'), |
|
| 300 | + $cron_type))); |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + do_action('FHEE__EED_Messages__run_cron__end'); |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + |
|
| 308 | + /** |
|
| 309 | + * This is used to retrieve the template pack for the given name. |
|
| 310 | + * Retrieved packs are cached on the static $_TMP_PACKS array. If there is no class matching the given name then |
|
| 311 | + * the default template pack is returned. |
|
| 312 | + * |
|
| 313 | + * @deprecated 4.9.0 @see EEH_MSG_Template::get_template_pack() |
|
| 314 | + * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used |
|
| 315 | + * in generating the Pack class name). |
|
| 316 | + * @return EE_Messages_Template_Pack |
|
| 317 | + * @throws EE_Error |
|
| 318 | + * @throws InvalidArgumentException |
|
| 319 | + * @throws ReflectionException |
|
| 320 | + * @throws InvalidDataTypeException |
|
| 321 | + * @throws InvalidInterfaceException |
|
| 322 | + */ |
|
| 323 | + public static function get_template_pack($template_pack_name) |
|
| 324 | + { |
|
| 325 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 326 | + return EEH_MSG_Template::get_template_pack($template_pack_name); |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + |
|
| 330 | + /** |
|
| 331 | + * Retrieves an array of all template packs. |
|
| 332 | + * Array is in the format array( 'dbref' => EE_Messages_Template_Pack ) |
|
| 333 | + * |
|
| 334 | + * @deprecated 4.9.0 @see EEH_MSG_Template_Pack::get_template_pack_collection |
|
| 335 | + * @return EE_Messages_Template_Pack[] |
|
| 336 | + * @throws EE_Error |
|
| 337 | + * @throws InvalidArgumentException |
|
| 338 | + * @throws ReflectionException |
|
| 339 | + * @throws InvalidDataTypeException |
|
| 340 | + * @throws InvalidInterfaceException |
|
| 341 | + */ |
|
| 342 | + public static function get_template_packs() |
|
| 343 | + { |
|
| 344 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 345 | + |
|
| 346 | + //for backward compat, let's make sure this returns in the same format as originally. |
|
| 347 | + $template_pack_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
| 348 | + $template_pack_collection->rewind(); |
|
| 349 | + $template_packs = array(); |
|
| 350 | + while ($template_pack_collection->valid()) { |
|
| 351 | + $template_packs[$template_pack_collection->current()->dbref] = $template_pack_collection->current(); |
|
| 352 | + $template_pack_collection->next(); |
|
| 353 | + } |
|
| 354 | + return $template_packs; |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + |
|
| 358 | + /** |
|
| 359 | + * This simply makes sure the autoloaders are registered for the EE_messages system. |
|
| 360 | + * |
|
| 361 | + * @since 4.5.0 |
|
| 362 | + * @return void |
|
| 363 | + * @throws EE_Error |
|
| 364 | + */ |
|
| 365 | + public static function set_autoloaders() |
|
| 366 | + { |
|
| 367 | + if (empty(self::$_MSG_PATHS)) { |
|
| 368 | + self::_set_messages_paths(); |
|
| 369 | + foreach (self::$_MSG_PATHS as $path) { |
|
| 370 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path); |
|
| 371 | + } |
|
| 372 | + // add aliases |
|
| 373 | + EEH_Autoloader::add_alias('EE_messages', 'EE_messages'); |
|
| 374 | + EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger'); |
|
| 375 | + } |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + |
|
| 379 | + /** |
|
| 380 | + * Take care of adding all the paths for the messages components to the $_MSG_PATHS property |
|
| 381 | + * for use by the Messages Autoloaders |
|
| 382 | + * |
|
| 383 | + * @since 4.5.0 |
|
| 384 | + * @return void. |
|
| 385 | + */ |
|
| 386 | + protected static function _set_messages_paths() |
|
| 387 | + { |
|
| 388 | + $dir_ref = array( |
|
| 389 | + 'messages/message_type', |
|
| 390 | + 'messages/messenger', |
|
| 391 | + 'messages/defaults', |
|
| 392 | + 'messages/defaults/email', |
|
| 393 | + 'messages/data_class', |
|
| 394 | + 'messages/validators', |
|
| 395 | + 'messages/validators/email', |
|
| 396 | + 'messages/validators/html', |
|
| 397 | + 'shortcodes', |
|
| 398 | + ); |
|
| 399 | + $paths = array(); |
|
| 400 | + foreach ($dir_ref as $index => $dir) { |
|
| 401 | + $paths[$index] = EE_LIBRARIES . $dir; |
|
| 402 | + } |
|
| 403 | + self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths); |
|
| 404 | + } |
|
| 405 | + |
|
| 406 | + |
|
| 407 | + /** |
|
| 408 | + * Takes care of loading dependencies |
|
| 409 | + * |
|
| 410 | + * @since 4.5.0 |
|
| 411 | + * @return void |
|
| 412 | + * @throws EE_Error |
|
| 413 | + * @throws InvalidArgumentException |
|
| 414 | + * @throws ReflectionException |
|
| 415 | + * @throws InvalidDataTypeException |
|
| 416 | + * @throws InvalidInterfaceException |
|
| 417 | + */ |
|
| 418 | + protected static function _load_controller() |
|
| 419 | + { |
|
| 420 | + if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) { |
|
| 421 | + EE_Registry::instance()->load_core('Request_Handler'); |
|
| 422 | + self::set_autoloaders(); |
|
| 423 | + self::$_EEMSG = EE_Registry::instance()->load_lib('messages'); |
|
| 424 | + self::$_MSG_PROCESSOR = EE_Registry::instance()->load_lib('Messages_Processor'); |
|
| 425 | + self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 426 | + } |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + |
|
| 430 | + /** |
|
| 431 | + * @param EE_Transaction $transaction |
|
| 432 | + * @throws EE_Error |
|
| 433 | + * @throws InvalidArgumentException |
|
| 434 | + * @throws InvalidDataTypeException |
|
| 435 | + * @throws InvalidInterfaceException |
|
| 436 | + * @throws ReflectionException |
|
| 437 | + */ |
|
| 438 | + public static function payment_reminder(EE_Transaction $transaction) |
|
| 439 | + { |
|
| 440 | + self::_load_controller(); |
|
| 441 | + $data = array($transaction, null); |
|
| 442 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data); |
|
| 443 | + } |
|
| 444 | + |
|
| 445 | + |
|
| 446 | + /** |
|
| 447 | + * Any messages triggers for after successful gateway payments should go in here. |
|
| 448 | + * |
|
| 449 | + * @param EE_Transaction $transaction object |
|
| 450 | + * @param EE_Payment $payment object |
|
| 451 | + * @return void |
|
| 452 | + * @throws EE_Error |
|
| 453 | + * @throws InvalidArgumentException |
|
| 454 | + * @throws ReflectionException |
|
| 455 | + * @throws InvalidDataTypeException |
|
| 456 | + * @throws InvalidInterfaceException |
|
| 457 | + */ |
|
| 458 | + public static function payment(EE_Transaction $transaction, EE_Payment $payment) |
|
| 459 | + { |
|
| 460 | + self::_load_controller(); |
|
| 461 | + $data = array($transaction, $payment); |
|
| 462 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 463 | + $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
| 464 | + //if payment amount is less than 0 then switch to payment_refund message type. |
|
| 465 | + $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
| 466 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
| 467 | + } |
|
| 468 | + |
|
| 469 | + |
|
| 470 | + /** |
|
| 471 | + * @param EE_Transaction $transaction |
|
| 472 | + * @throws EE_Error |
|
| 473 | + * @throws InvalidArgumentException |
|
| 474 | + * @throws InvalidDataTypeException |
|
| 475 | + * @throws InvalidInterfaceException |
|
| 476 | + * @throws ReflectionException |
|
| 477 | + */ |
|
| 478 | + public static function cancelled_registration(EE_Transaction $transaction) |
|
| 479 | + { |
|
| 480 | + self::_load_controller(); |
|
| 481 | + $data = array($transaction, null); |
|
| 482 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data); |
|
| 483 | + } |
|
| 484 | + |
|
| 485 | + |
|
| 486 | + |
|
| 487 | + /** |
|
| 488 | + * Trigger for Registration messages |
|
| 489 | + * Note that what registration message type is sent depends on what the reg status is for the registrations on the |
|
| 490 | + * incoming transaction. |
|
| 491 | + * |
|
| 492 | + * @param EE_Registration $registration |
|
| 493 | + * @param array $extra_details |
|
| 494 | + * @return void |
|
| 495 | + * @throws EE_Error |
|
| 496 | + * @throws InvalidArgumentException |
|
| 497 | + * @throws InvalidDataTypeException |
|
| 498 | + * @throws InvalidInterfaceException |
|
| 499 | + * @throws ReflectionException |
|
| 500 | + * @throws EntityNotFoundException |
|
| 501 | + */ |
|
| 502 | + public static function maybe_registration(EE_Registration $registration, $extra_details = array()) |
|
| 503 | + { |
|
| 504 | + |
|
| 505 | + if (! self::_verify_registration_notification_send($registration, $extra_details)) { |
|
| 506 | + //no messages please |
|
| 507 | + return; |
|
| 508 | + } |
|
| 509 | + |
|
| 510 | + // get all non-trashed registrations so we make sure we send messages for the right status. |
|
| 511 | + $all_registrations = $registration->transaction()->registrations( |
|
| 512 | + array( |
|
| 513 | + array('REG_deleted' => false), |
|
| 514 | + 'order_by' => array( |
|
| 515 | + 'Event.EVT_name' => 'ASC', |
|
| 516 | + 'Attendee.ATT_lname' => 'ASC', |
|
| 517 | + 'Attendee.ATT_fname' => 'ASC' |
|
| 518 | + ) |
|
| 519 | + ) |
|
| 520 | + ); |
|
| 521 | + //cached array of statuses so we only trigger messages once per status. |
|
| 522 | + $statuses_sent = array(); |
|
| 523 | + self::_load_controller(); |
|
| 524 | + $mtgs = array(); |
|
| 525 | + |
|
| 526 | + //loop through registrations and trigger messages once per status. |
|
| 527 | + foreach ($all_registrations as $reg) { |
|
| 528 | + |
|
| 529 | + //already triggered? |
|
| 530 | + if (in_array($reg->status_ID(), $statuses_sent)) { |
|
| 531 | + continue; |
|
| 532 | + } |
|
| 533 | + |
|
| 534 | + $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID()); |
|
| 535 | + $mtgs = array_merge( |
|
| 536 | + $mtgs, |
|
| 537 | + self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
| 538 | + $message_type, |
|
| 539 | + array($registration->transaction(), null, $reg->status_ID()) |
|
| 540 | + ) |
|
| 541 | + ); |
|
| 542 | + $statuses_sent[] = $reg->status_ID(); |
|
| 543 | + } |
|
| 544 | + |
|
| 545 | + if (count($statuses_sent) > 1) { |
|
| 546 | + $mtgs = array_merge( |
|
| 547 | + $mtgs, |
|
| 548 | + self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
| 549 | + 'registration_summary', |
|
| 550 | + array($registration->transaction(), null) |
|
| 551 | + ) |
|
| 552 | + ); |
|
| 553 | + } |
|
| 554 | + |
|
| 555 | + //batch queue and initiate request |
|
| 556 | + self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs); |
|
| 557 | + self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
| 558 | + } |
|
| 559 | + |
|
| 560 | + |
|
| 561 | + /** |
|
| 562 | + * This is a helper method used to very whether a registration notification should be sent or |
|
| 563 | + * not. Prevents duplicate notifications going out for registration context notifications. |
|
| 564 | + * |
|
| 565 | + * @param EE_Registration $registration [description] |
|
| 566 | + * @param array $extra_details [description] |
|
| 567 | + * @return bool true = send away, false = nope halt the presses. |
|
| 568 | + */ |
|
| 569 | + protected static function _verify_registration_notification_send( |
|
| 570 | + EE_Registration $registration, |
|
| 571 | + $extra_details = array() |
|
| 572 | + ) { |
|
| 573 | + //self::log( |
|
| 574 | + // __CLASS__, __FUNCTION__, __LINE__, |
|
| 575 | + // $registration->transaction(), |
|
| 576 | + // array( '$extra_details' => $extra_details ) |
|
| 577 | + //); |
|
| 578 | + // currently only using this to send messages for the primary registrant |
|
| 579 | + if (! $registration->is_primary_registrant()) { |
|
| 580 | + return false; |
|
| 581 | + } |
|
| 582 | + // first we check if we're in admin and not doing front ajax |
|
| 583 | + if (is_admin() && ! EE_FRONT_AJAX) { |
|
| 584 | + //make sure appropriate admin params are set for sending messages |
|
| 585 | + if (empty($_REQUEST['txn_reg_status_change']['send_notifications']) || ! absint($_REQUEST['txn_reg_status_change']['send_notifications'])) { |
|
| 586 | + //no messages sent please. |
|
| 587 | + return false; |
|
| 588 | + } |
|
| 589 | + } else { |
|
| 590 | + // frontend request (either regular or via AJAX) |
|
| 591 | + // TXN is NOT finalized ? |
|
| 592 | + if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) { |
|
| 593 | + return false; |
|
| 594 | + } |
|
| 595 | + // return visit but nothing changed ??? |
|
| 596 | + if ( |
|
| 597 | + isset($extra_details['revisit'], $extra_details['status_updates']) && |
|
| 598 | + $extra_details['revisit'] && ! $extra_details['status_updates'] |
|
| 599 | + ) { |
|
| 600 | + return false; |
|
| 601 | + } |
|
| 602 | + // NOT sending messages && reg status is something other than "Not-Approved" |
|
| 603 | + if ( |
|
| 604 | + ! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) && |
|
| 605 | + $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
| 606 | + ) { |
|
| 607 | + return false; |
|
| 608 | + } |
|
| 609 | + } |
|
| 610 | + // release the kraken |
|
| 611 | + return true; |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + |
|
| 615 | + /** |
|
| 616 | + * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that |
|
| 617 | + * status id. |
|
| 618 | + * |
|
| 619 | + * @deprecated 4.9.0 Use EEH_MSG_Template::reg_status_to_message_type_array() |
|
| 620 | + * or EEH_MSG_Template::convert_reg_status_to_message_type |
|
| 621 | + * @param string $reg_status |
|
| 622 | + * @return array |
|
| 623 | + * @throws EE_Error |
|
| 624 | + * @throws InvalidArgumentException |
|
| 625 | + * @throws ReflectionException |
|
| 626 | + * @throws InvalidDataTypeException |
|
| 627 | + * @throws InvalidInterfaceException |
|
| 628 | + */ |
|
| 629 | + protected static function _get_reg_status_array($reg_status = '') |
|
| 630 | + { |
|
| 631 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 632 | + return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
| 633 | + ? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
| 634 | + : EEH_MSG_Template::reg_status_to_message_type_array(); |
|
| 635 | + } |
|
| 636 | + |
|
| 637 | + |
|
| 638 | + /** |
|
| 639 | + * Simply returns the payment message type for the given payment status. |
|
| 640 | + * |
|
| 641 | + * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array |
|
| 642 | + * or EEH_MSG_Template::convert_payment_status_to_message_type |
|
| 643 | + * @param string $payment_status The payment status being matched. |
|
| 644 | + * @return bool|string The payment message type slug matching the status or false if no match. |
|
| 645 | + * @throws EE_Error |
|
| 646 | + * @throws InvalidArgumentException |
|
| 647 | + * @throws ReflectionException |
|
| 648 | + * @throws InvalidDataTypeException |
|
| 649 | + * @throws InvalidInterfaceException |
|
| 650 | + */ |
|
| 651 | + protected static function _get_payment_message_type($payment_status) |
|
| 652 | + { |
|
| 653 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 654 | + return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
| 655 | + ? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
| 656 | + : false; |
|
| 657 | + } |
|
| 658 | + |
|
| 659 | + |
|
| 660 | + /** |
|
| 661 | + * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
| 662 | + * |
|
| 663 | + * @access public |
|
| 664 | + * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages |
|
| 665 | + * @return bool success/fail |
|
| 666 | + * @throws EE_Error |
|
| 667 | + * @throws InvalidArgumentException |
|
| 668 | + * @throws InvalidDataTypeException |
|
| 669 | + * @throws InvalidInterfaceException |
|
| 670 | + * @throws ReflectionException |
|
| 671 | + */ |
|
| 672 | + public static function process_resend($req_data) |
|
| 673 | + { |
|
| 674 | + self::_load_controller(); |
|
| 675 | + |
|
| 676 | + //if $msgID in this request then skip to the new resend_message |
|
| 677 | + if (EE_Registry::instance()->REQ->get('MSG_ID')) { |
|
| 678 | + return self::resend_message(); |
|
| 679 | + } |
|
| 680 | + |
|
| 681 | + //make sure any incoming request data is set on the REQ so that it gets picked up later. |
|
| 682 | + $req_data = (array)$req_data; |
|
| 683 | + foreach ($req_data as $request_key => $request_value) { |
|
| 684 | + EE_Registry::instance()->REQ->set($request_key, $request_value); |
|
| 685 | + } |
|
| 686 | + |
|
| 687 | + if (! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request()) { |
|
| 688 | + return false; |
|
| 689 | + } |
|
| 690 | + |
|
| 691 | + try { |
|
| 692 | + self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send); |
|
| 693 | + self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
| 694 | + } catch (EE_Error $e) { |
|
| 695 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 696 | + return false; |
|
| 697 | + } |
|
| 698 | + EE_Error::add_success( |
|
| 699 | + __('Messages have been successfully queued for generation and sending.', 'event_espresso') |
|
| 700 | + ); |
|
| 701 | + return true; //everything got queued. |
|
| 702 | + } |
|
| 703 | + |
|
| 704 | + |
|
| 705 | + /** |
|
| 706 | + * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
| 707 | + * |
|
| 708 | + * @return bool |
|
| 709 | + * @throws EE_Error |
|
| 710 | + * @throws InvalidArgumentException |
|
| 711 | + * @throws InvalidDataTypeException |
|
| 712 | + * @throws InvalidInterfaceException |
|
| 713 | + * @throws ReflectionException |
|
| 714 | + */ |
|
| 715 | + public static function resend_message() |
|
| 716 | + { |
|
| 717 | + self::_load_controller(); |
|
| 718 | + |
|
| 719 | + $msgID = EE_Registry::instance()->REQ->get('MSG_ID'); |
|
| 720 | + if (! $msgID) { |
|
| 721 | + EE_Error::add_error(__('Something went wrong because there is no "MSG_ID" value in the request', |
|
| 722 | + 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 723 | + return false; |
|
| 724 | + } |
|
| 725 | + |
|
| 726 | + self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array)$msgID); |
|
| 727 | + |
|
| 728 | + //setup success message. |
|
| 729 | + $count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
| 730 | + EE_Error::add_success(sprintf( |
|
| 731 | + _n( |
|
| 732 | + 'There was %d message queued for resending.', |
|
| 733 | + 'There were %d messages queued for resending.', |
|
| 734 | + $count_ready_for_resend, |
|
| 735 | + 'event_espresso' |
|
| 736 | + ), |
|
| 737 | + $count_ready_for_resend |
|
| 738 | + )); |
|
| 739 | + return true; |
|
| 740 | + } |
|
| 741 | + |
|
| 742 | + |
|
| 743 | + /** |
|
| 744 | + * Message triggers for manual payment applied by admin |
|
| 745 | + * |
|
| 746 | + * @param EE_Payment $payment EE_payment object |
|
| 747 | + * @return bool success/fail |
|
| 748 | + * @throws EE_Error |
|
| 749 | + * @throws InvalidArgumentException |
|
| 750 | + * @throws ReflectionException |
|
| 751 | + * @throws InvalidDataTypeException |
|
| 752 | + * @throws InvalidInterfaceException |
|
| 753 | + */ |
|
| 754 | + public static function process_admin_payment(EE_Payment $payment) |
|
| 755 | + { |
|
| 756 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 757 | + //we need to get the transaction object |
|
| 758 | + $transaction = $payment->transaction(); |
|
| 759 | + if ($transaction instanceof EE_Transaction) { |
|
| 760 | + $data = array($transaction, $payment); |
|
| 761 | + $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
| 762 | + |
|
| 763 | + //if payment amount is less than 0 then switch to payment_refund message type. |
|
| 764 | + $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
| 765 | + |
|
| 766 | + //if payment_refund is selected, but the status is NOT accepted. Then change message type to false so NO message notification goes out. |
|
| 767 | + $message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved ? false : $message_type; |
|
| 768 | + |
|
| 769 | + self::_load_controller(); |
|
| 770 | + |
|
| 771 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
| 772 | + |
|
| 773 | + //get count of queued for generation |
|
| 774 | + $count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(array( |
|
| 775 | + EEM_Message::status_incomplete, |
|
| 776 | + EEM_Message::status_idle, |
|
| 777 | + )); |
|
| 778 | + |
|
| 779 | + if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) { |
|
| 780 | + add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
| 781 | + return true; |
|
| 782 | + } else { |
|
| 783 | + $count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::instance()->stati_indicating_failed_sending()); |
|
| 784 | + /** |
|
| 785 | + * Verify that there are actually errors. If not then we return a success message because the queue might have been emptied due to successful |
|
| 786 | + * IMMEDIATE generation. |
|
| 787 | + */ |
|
| 788 | + if ($count_failed > 0) { |
|
| 789 | + EE_Error::add_error(sprintf( |
|
| 790 | + _n( |
|
| 791 | + 'The payment notification generation failed.', |
|
| 792 | + '%d payment notifications failed being sent.', |
|
| 793 | + $count_failed, |
|
| 794 | + 'event_espresso' |
|
| 795 | + ), |
|
| 796 | + $count_failed |
|
| 797 | + ), __FILE__, __FUNCTION__, __LINE__); |
|
| 798 | + |
|
| 799 | + return false; |
|
| 800 | + } else { |
|
| 801 | + add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
| 802 | + return true; |
|
| 803 | + } |
|
| 804 | + } |
|
| 805 | + } else { |
|
| 806 | + EE_Error::add_error( |
|
| 807 | + 'Unable to generate the payment notification because the given value for the transaction is invalid.', |
|
| 808 | + 'event_espresso' |
|
| 809 | + ); |
|
| 810 | + return false; |
|
| 811 | + } |
|
| 812 | + } |
|
| 813 | + |
|
| 814 | + |
|
| 815 | + /** |
|
| 816 | + * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger |
|
| 817 | + * |
|
| 818 | + * @since 4.3.0 |
|
| 819 | + * @param EE_Registration[] $registrations an array of EE_Registration objects |
|
| 820 | + * @param int $grp_id a specific message template group id. |
|
| 821 | + * @return void |
|
| 822 | + * @throws EE_Error |
|
| 823 | + * @throws InvalidArgumentException |
|
| 824 | + * @throws InvalidDataTypeException |
|
| 825 | + * @throws InvalidInterfaceException |
|
| 826 | + * @throws ReflectionException |
|
| 827 | + */ |
|
| 828 | + public static function send_newsletter_message($registrations, $grp_id) |
|
| 829 | + { |
|
| 830 | + //make sure mtp is id and set it in the EE_Request Handler later messages setup. |
|
| 831 | + EE_Registry::instance()->REQ->set('GRP_ID', (int)$grp_id); |
|
| 832 | + self::_load_controller(); |
|
| 833 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations); |
|
| 834 | + } |
|
| 835 | + |
|
| 836 | + |
|
| 837 | + /** |
|
| 838 | + * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url |
|
| 839 | + * |
|
| 840 | + * @since 4.3.0 |
|
| 841 | + * @param string $registration_message_trigger_url |
|
| 842 | + * @param EE_Registration $registration |
|
| 843 | + * @param string $messenger |
|
| 844 | + * @param string $message_type |
|
| 845 | + * @return string |
|
| 846 | + * @throws EE_Error |
|
| 847 | + * @throws InvalidArgumentException |
|
| 848 | + * @throws InvalidDataTypeException |
|
| 849 | + * @throws InvalidInterfaceException |
|
| 850 | + */ |
|
| 851 | + public static function registration_message_trigger_url( |
|
| 852 | + $registration_message_trigger_url, |
|
| 853 | + EE_Registration $registration, |
|
| 854 | + $messenger = 'html', |
|
| 855 | + $message_type = 'invoice' |
|
| 856 | + ) { |
|
| 857 | + // whitelist $messenger |
|
| 858 | + switch ($messenger) { |
|
| 859 | + case 'pdf' : |
|
| 860 | + $sending_messenger = 'pdf'; |
|
| 861 | + $generating_messenger = 'html'; |
|
| 862 | + break; |
|
| 863 | + case 'html' : |
|
| 864 | + default : |
|
| 865 | + $sending_messenger = 'html'; |
|
| 866 | + $generating_messenger = 'html'; |
|
| 867 | + break; |
|
| 868 | + } |
|
| 869 | + // whitelist $message_type |
|
| 870 | + switch ($message_type) { |
|
| 871 | + case 'receipt' : |
|
| 872 | + $message_type = 'receipt'; |
|
| 873 | + break; |
|
| 874 | + case 'invoice' : |
|
| 875 | + default : |
|
| 876 | + $message_type = 'invoice'; |
|
| 877 | + break; |
|
| 878 | + } |
|
| 879 | + // verify that both the messenger AND the message type are active |
|
| 880 | + if (EEH_MSG_Template::is_messenger_active($sending_messenger) && EEH_MSG_Template::is_mt_active($message_type)) { |
|
| 881 | + //need to get the correct message template group for this (i.e. is there a custom invoice for the event this registration is registered for?) |
|
| 882 | + $template_query_params = array( |
|
| 883 | + 'MTP_is_active' => true, |
|
| 884 | + 'MTP_messenger' => $generating_messenger, |
|
| 885 | + 'MTP_message_type' => $message_type, |
|
| 886 | + 'Event.EVT_ID' => $registration->event_ID(), |
|
| 887 | + ); |
|
| 888 | + //get the message template group. |
|
| 889 | + $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
| 890 | + //if we don't have an EE_Message_Template_Group then return |
|
| 891 | + if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
| 892 | + // remove EVT_ID from query params so that global templates get picked up |
|
| 893 | + unset($template_query_params['Event.EVT_ID']); |
|
| 894 | + //get global template as the fallback |
|
| 895 | + $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
| 896 | + } |
|
| 897 | + //if we don't have an EE_Message_Template_Group then return |
|
| 898 | + if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
| 899 | + return ''; |
|
| 900 | + } |
|
| 901 | + // generate the URL |
|
| 902 | + $registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger( |
|
| 903 | + $sending_messenger, |
|
| 904 | + $generating_messenger, |
|
| 905 | + 'purchaser', |
|
| 906 | + $message_type, |
|
| 907 | + $registration, |
|
| 908 | + $msg_template_group->ID(), |
|
| 909 | + $registration->transaction_ID() |
|
| 910 | + ); |
|
| 911 | + |
|
| 912 | + } |
|
| 913 | + return $registration_message_trigger_url; |
|
| 914 | + } |
|
| 915 | + |
|
| 916 | + |
|
| 917 | + /** |
|
| 918 | + * Use to generate and return a message preview! |
|
| 919 | + * |
|
| 920 | + * @param string $type This should correspond with a valid message type |
|
| 921 | + * @param string $context This should correspond with a valid context for the message type |
|
| 922 | + * @param string $messenger This should correspond with a valid messenger. |
|
| 923 | + * @param bool $send true we will do a test send using the messenger delivery, false we just do a regular |
|
| 924 | + * preview |
|
| 925 | + * @return bool|string The body of the message or if send is requested, sends. |
|
| 926 | + * @throws EE_Error |
|
| 927 | + * @throws InvalidArgumentException |
|
| 928 | + * @throws InvalidDataTypeException |
|
| 929 | + * @throws InvalidInterfaceException |
|
| 930 | + * @throws ReflectionException |
|
| 931 | + */ |
|
| 932 | + public static function preview_message($type, $context, $messenger, $send = false) |
|
| 933 | + { |
|
| 934 | + self::_load_controller(); |
|
| 935 | + $mtg = new EE_Message_To_Generate( |
|
| 936 | + $messenger, |
|
| 937 | + $type, |
|
| 938 | + array(), |
|
| 939 | + $context, |
|
| 940 | + true |
|
| 941 | + ); |
|
| 942 | + $generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send); |
|
| 943 | + if ($generated_preview_queue instanceof EE_Messages_Queue) { |
|
| 944 | + //loop through all content for the preview and remove any persisted records. |
|
| 945 | + $content = ''; |
|
| 946 | + foreach ($generated_preview_queue->get_message_repository() as $message) { |
|
| 947 | + $content = $message->content(); |
|
| 948 | + if ($message->ID() > 0 && $message->STS_ID() !== EEM_Message::status_failed) { |
|
| 949 | + $message->delete(); |
|
| 950 | + } |
|
| 951 | + } |
|
| 952 | + return $content; |
|
| 953 | + } else { |
|
| 954 | + return $generated_preview_queue; |
|
| 955 | + } |
|
| 956 | + } |
|
| 957 | + |
|
| 958 | + |
|
| 959 | + /** |
|
| 960 | + * This is a method that allows for sending a message using a messenger matching the string given and the provided |
|
| 961 | + * EE_Message_Queue object. The EE_Message_Queue object is used to create a single aggregate EE_Message via the |
|
| 962 | + * content found in the EE_Message objects in the queue. |
|
| 963 | + * |
|
| 964 | + * @since 4.9.0 |
|
| 965 | + * @param string $messenger a string matching a valid active messenger in the system |
|
| 966 | + * @param string $message_type Although it seems contrary to the name of the method, a message |
|
| 967 | + * type name is still required to send along the message type to the |
|
| 968 | + * messenger because this is used for determining what specific |
|
| 969 | + * variations might be loaded for the generated message. |
|
| 970 | + * @param EE_Messages_Queue $queue |
|
| 971 | + * @param string $custom_subject Can be used to set what the custom subject string will be on the |
|
| 972 | + * aggregate EE_Message object. |
|
| 973 | + * @return bool success or fail. |
|
| 974 | + * @throws EE_Error |
|
| 975 | + * @throws InvalidArgumentException |
|
| 976 | + * @throws ReflectionException |
|
| 977 | + * @throws InvalidDataTypeException |
|
| 978 | + * @throws InvalidInterfaceException |
|
| 979 | + */ |
|
| 980 | + public static function send_message_with_messenger_only( |
|
| 981 | + $messenger, |
|
| 982 | + $message_type, |
|
| 983 | + EE_Messages_Queue $queue, |
|
| 984 | + $custom_subject = '' |
|
| 985 | + ) { |
|
| 986 | + self::_load_controller(); |
|
| 987 | + /** @type EE_Message_To_Generate_From_Queue $message_to_generate */ |
|
| 988 | + $message_to_generate = EE_Registry::instance()->load_lib( |
|
| 989 | + 'Message_To_Generate_From_Queue', |
|
| 990 | + array( |
|
| 991 | + $messenger, |
|
| 992 | + $message_type, |
|
| 993 | + $queue, |
|
| 994 | + $custom_subject, |
|
| 995 | + ) |
|
| 996 | + ); |
|
| 997 | + return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate); |
|
| 998 | + } |
|
| 999 | + |
|
| 1000 | + |
|
| 1001 | + /** |
|
| 1002 | + * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation) |
|
| 1003 | + * |
|
| 1004 | + * @since 4.9.0 |
|
| 1005 | + * @param array $message_ids An array of message ids |
|
| 1006 | + * @return bool|EE_Messages_Queue false if nothing was generated, EE_Messages_Queue containing generated |
|
| 1007 | + * messages. |
|
| 1008 | + * @throws EE_Error |
|
| 1009 | + * @throws InvalidArgumentException |
|
| 1010 | + * @throws InvalidDataTypeException |
|
| 1011 | + * @throws InvalidInterfaceException |
|
| 1012 | + * @throws ReflectionException |
|
| 1013 | + */ |
|
| 1014 | + public static function generate_now($message_ids) |
|
| 1015 | + { |
|
| 1016 | + self::_load_controller(); |
|
| 1017 | + $messages = EEM_Message::instance()->get_all( |
|
| 1018 | + array( |
|
| 1019 | + 0 => array( |
|
| 1020 | + 'MSG_ID' => array('IN', $message_ids), |
|
| 1021 | + 'STS_ID' => EEM_Message::status_incomplete, |
|
| 1022 | + ), |
|
| 1023 | + ) |
|
| 1024 | + ); |
|
| 1025 | + $generated_queue = false; |
|
| 1026 | + if ($messages) { |
|
| 1027 | + $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages); |
|
| 1028 | + } |
|
| 1029 | + |
|
| 1030 | + if (! $generated_queue instanceof EE_Messages_Queue) { |
|
| 1031 | + EE_Error::add_error( |
|
| 1032 | + __('The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.', |
|
| 1033 | + 'event_espresso'), |
|
| 1034 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1035 | + ); |
|
| 1036 | + } |
|
| 1037 | + return $generated_queue; |
|
| 1038 | + } |
|
| 1039 | + |
|
| 1040 | + |
|
| 1041 | + /** |
|
| 1042 | + * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or, |
|
| 1043 | + * EEM_Message::status_idle |
|
| 1044 | + * |
|
| 1045 | + * @since 4.9.0 |
|
| 1046 | + * @param $message_ids |
|
| 1047 | + * @return bool|EE_Messages_Queue false if no messages sent. |
|
| 1048 | + * @throws EE_Error |
|
| 1049 | + * @throws InvalidArgumentException |
|
| 1050 | + * @throws InvalidDataTypeException |
|
| 1051 | + * @throws InvalidInterfaceException |
|
| 1052 | + * @throws ReflectionException |
|
| 1053 | + */ |
|
| 1054 | + public static function send_now($message_ids) |
|
| 1055 | + { |
|
| 1056 | + self::_load_controller(); |
|
| 1057 | + $messages = EEM_Message::instance()->get_all( |
|
| 1058 | + array( |
|
| 1059 | + 0 => array( |
|
| 1060 | + 'MSG_ID' => array('IN', $message_ids), |
|
| 1061 | + 'STS_ID' => array( |
|
| 1062 | + 'IN', |
|
| 1063 | + array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry), |
|
| 1064 | + ), |
|
| 1065 | + ), |
|
| 1066 | + ) |
|
| 1067 | + ); |
|
| 1068 | + $sent_queue = false; |
|
| 1069 | + if ($messages) { |
|
| 1070 | + $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages); |
|
| 1071 | + } |
|
| 1072 | + |
|
| 1073 | + if (! $sent_queue instanceof EE_Messages_Queue) { |
|
| 1074 | + EE_Error::add_error( |
|
| 1075 | + __('The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.', |
|
| 1076 | + 'event_espresso'), |
|
| 1077 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1078 | + ); |
|
| 1079 | + } else { |
|
| 1080 | + //can count how many sent by using the messages in the queue |
|
| 1081 | + $sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent()); |
|
| 1082 | + if ($sent_count > 0) { |
|
| 1083 | + EE_Error::add_success( |
|
| 1084 | + sprintf( |
|
| 1085 | + _n( |
|
| 1086 | + 'There was %d message successfully sent.', |
|
| 1087 | + 'There were %d messages successfully sent.', |
|
| 1088 | + $sent_count, |
|
| 1089 | + 'event_espresso' |
|
| 1090 | + ), |
|
| 1091 | + $sent_count |
|
| 1092 | + ) |
|
| 1093 | + ); |
|
| 1094 | + } else { |
|
| 1095 | + EE_Error::overwrite_errors(); |
|
| 1096 | + EE_Error::add_error( |
|
| 1097 | + __('No message was sent because of problems with sending. Either all the messages you selected were not a sendable message, they were ALREADY sent on a different scheduled task, or there was an error. |
|
| 1098 | 1098 | If there was an error, you can look at the messages in the message activity list table for any error messages.', |
| 1099 | - 'event_espresso'), |
|
| 1100 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1101 | - ); |
|
| 1102 | - } |
|
| 1103 | - } |
|
| 1104 | - return $sent_queue; |
|
| 1105 | - } |
|
| 1106 | - |
|
| 1107 | - |
|
| 1108 | - /** |
|
| 1109 | - * Generate and send immediately from the given $message_ids |
|
| 1110 | - * |
|
| 1111 | - * @param array $message_ids EE_Message entity ids. |
|
| 1112 | - * @throws EE_Error |
|
| 1113 | - * @throws InvalidArgumentException |
|
| 1114 | - * @throws InvalidDataTypeException |
|
| 1115 | - * @throws InvalidInterfaceException |
|
| 1116 | - * @throws ReflectionException |
|
| 1117 | - */ |
|
| 1118 | - public static function generate_and_send_now(array $message_ids) |
|
| 1119 | - { |
|
| 1120 | - $generated_queue = self::generate_now($message_ids); |
|
| 1121 | - //now let's just trigger sending immediately from this queue. |
|
| 1122 | - $messages_sent = $generated_queue instanceof EE_Messages_Queue |
|
| 1123 | - ? $generated_queue->execute() |
|
| 1124 | - : 0; |
|
| 1125 | - if ($messages_sent) { |
|
| 1126 | - EE_Error::add_success( |
|
| 1127 | - esc_html( |
|
| 1128 | - sprintf( |
|
| 1129 | - _n( |
|
| 1130 | - 'There was %d message successfully generated and sent.', |
|
| 1131 | - 'There were %d messages successfully generated and sent.', |
|
| 1132 | - $messages_sent, |
|
| 1133 | - 'event_espresso' |
|
| 1134 | - ), |
|
| 1135 | - $messages_sent |
|
| 1136 | - ) |
|
| 1137 | - ) |
|
| 1138 | - ); |
|
| 1139 | - //errors would be added via the generate_now method. |
|
| 1140 | - } |
|
| 1141 | - } |
|
| 1142 | - |
|
| 1143 | - |
|
| 1144 | - /** |
|
| 1145 | - * This will queue the incoming message ids for resending. |
|
| 1146 | - * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued. |
|
| 1147 | - * |
|
| 1148 | - * @since 4.9.0 |
|
| 1149 | - * @param array $message_ids An array of EE_Message IDs |
|
| 1150 | - * @return bool true means messages were successfully queued for resending, false means none were queued for |
|
| 1151 | - * resending. |
|
| 1152 | - * @throws EE_Error |
|
| 1153 | - * @throws InvalidArgumentException |
|
| 1154 | - * @throws InvalidDataTypeException |
|
| 1155 | - * @throws InvalidInterfaceException |
|
| 1156 | - * @throws ReflectionException |
|
| 1157 | - */ |
|
| 1158 | - public static function queue_for_resending($message_ids) |
|
| 1159 | - { |
|
| 1160 | - self::_load_controller(); |
|
| 1161 | - self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids); |
|
| 1162 | - |
|
| 1163 | - //get queue and count |
|
| 1164 | - $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
| 1165 | - |
|
| 1166 | - if ( |
|
| 1167 | - $queue_count > 0 |
|
| 1168 | - ) { |
|
| 1169 | - EE_Error::add_success( |
|
| 1170 | - sprintf( |
|
| 1171 | - _n( |
|
| 1172 | - '%d message successfully queued for resending.', |
|
| 1173 | - '%d messages successfully queued for resending.', |
|
| 1174 | - $queue_count, |
|
| 1175 | - 'event_espresso' |
|
| 1176 | - ), |
|
| 1177 | - $queue_count |
|
| 1178 | - ) |
|
| 1179 | - ); |
|
| 1180 | - /** |
|
| 1181 | - * @see filter usage in EE_Messages_Queue::initiate_request_by_priority |
|
| 1182 | - */ |
|
| 1183 | - } elseif ( |
|
| 1184 | - apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true) |
|
| 1185 | - || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
| 1186 | - ) { |
|
| 1187 | - $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent); |
|
| 1188 | - if ($queue_count > 0) { |
|
| 1189 | - EE_Error::add_success( |
|
| 1190 | - sprintf( |
|
| 1191 | - _n( |
|
| 1192 | - '%d message successfully sent.', |
|
| 1193 | - '%d messages successfully sent.', |
|
| 1194 | - $queue_count, |
|
| 1195 | - 'event_espresso' |
|
| 1196 | - ), |
|
| 1197 | - $queue_count |
|
| 1198 | - ) |
|
| 1199 | - ); |
|
| 1200 | - } else { |
|
| 1201 | - EE_Error::add_error( |
|
| 1202 | - __('No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
| 1203 | - 'event_espresso'), |
|
| 1204 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1205 | - ); |
|
| 1206 | - } |
|
| 1207 | - } else { |
|
| 1208 | - EE_Error::add_error( |
|
| 1209 | - __('No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
| 1210 | - 'event_espresso'), |
|
| 1211 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1212 | - ); |
|
| 1213 | - } |
|
| 1214 | - return (bool)$queue_count; |
|
| 1215 | - } |
|
| 1216 | - |
|
| 1217 | - |
|
| 1218 | - /** |
|
| 1219 | - * debug |
|
| 1220 | - * |
|
| 1221 | - * @param string $class |
|
| 1222 | - * @param string $func |
|
| 1223 | - * @param string $line |
|
| 1224 | - * @param \EE_Transaction $transaction |
|
| 1225 | - * @param array $info |
|
| 1226 | - * @param bool $display_request |
|
| 1227 | - * @throws EE_Error |
|
| 1228 | - * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
| 1229 | - */ |
|
| 1230 | - protected static function log( |
|
| 1231 | - $class = '', |
|
| 1232 | - $func = '', |
|
| 1233 | - $line = '', |
|
| 1234 | - EE_Transaction $transaction, |
|
| 1235 | - $info = array(), |
|
| 1236 | - $display_request = false |
|
| 1237 | - ) { |
|
| 1238 | - if (defined('EE_DEBUG') && EE_DEBUG) { |
|
| 1239 | - if ($transaction instanceof EE_Transaction) { |
|
| 1240 | - // don't serialize objects |
|
| 1241 | - $info = EEH_Debug_Tools::strip_objects($info); |
|
| 1242 | - $info['TXN_status'] = $transaction->status_ID(); |
|
| 1243 | - $info['TXN_reg_steps'] = $transaction->reg_steps(); |
|
| 1244 | - if ($transaction->ID()) { |
|
| 1245 | - $index = 'EE_Transaction: ' . $transaction->ID(); |
|
| 1246 | - EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index); |
|
| 1247 | - } |
|
| 1248 | - } |
|
| 1249 | - } |
|
| 1250 | - |
|
| 1251 | - } |
|
| 1252 | - |
|
| 1253 | - |
|
| 1254 | - /** |
|
| 1255 | - * Resets all the static properties in this class when called. |
|
| 1256 | - */ |
|
| 1257 | - public static function reset() |
|
| 1258 | - { |
|
| 1259 | - self::$_EEMSG = null; |
|
| 1260 | - self::$_message_resource_manager = null; |
|
| 1261 | - self::$_MSG_PROCESSOR = null; |
|
| 1262 | - self::$_MSG_PATHS = null; |
|
| 1263 | - self::$_TMP_PACKS = array(); |
|
| 1264 | - } |
|
| 1099 | + 'event_espresso'), |
|
| 1100 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1101 | + ); |
|
| 1102 | + } |
|
| 1103 | + } |
|
| 1104 | + return $sent_queue; |
|
| 1105 | + } |
|
| 1106 | + |
|
| 1107 | + |
|
| 1108 | + /** |
|
| 1109 | + * Generate and send immediately from the given $message_ids |
|
| 1110 | + * |
|
| 1111 | + * @param array $message_ids EE_Message entity ids. |
|
| 1112 | + * @throws EE_Error |
|
| 1113 | + * @throws InvalidArgumentException |
|
| 1114 | + * @throws InvalidDataTypeException |
|
| 1115 | + * @throws InvalidInterfaceException |
|
| 1116 | + * @throws ReflectionException |
|
| 1117 | + */ |
|
| 1118 | + public static function generate_and_send_now(array $message_ids) |
|
| 1119 | + { |
|
| 1120 | + $generated_queue = self::generate_now($message_ids); |
|
| 1121 | + //now let's just trigger sending immediately from this queue. |
|
| 1122 | + $messages_sent = $generated_queue instanceof EE_Messages_Queue |
|
| 1123 | + ? $generated_queue->execute() |
|
| 1124 | + : 0; |
|
| 1125 | + if ($messages_sent) { |
|
| 1126 | + EE_Error::add_success( |
|
| 1127 | + esc_html( |
|
| 1128 | + sprintf( |
|
| 1129 | + _n( |
|
| 1130 | + 'There was %d message successfully generated and sent.', |
|
| 1131 | + 'There were %d messages successfully generated and sent.', |
|
| 1132 | + $messages_sent, |
|
| 1133 | + 'event_espresso' |
|
| 1134 | + ), |
|
| 1135 | + $messages_sent |
|
| 1136 | + ) |
|
| 1137 | + ) |
|
| 1138 | + ); |
|
| 1139 | + //errors would be added via the generate_now method. |
|
| 1140 | + } |
|
| 1141 | + } |
|
| 1142 | + |
|
| 1143 | + |
|
| 1144 | + /** |
|
| 1145 | + * This will queue the incoming message ids for resending. |
|
| 1146 | + * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued. |
|
| 1147 | + * |
|
| 1148 | + * @since 4.9.0 |
|
| 1149 | + * @param array $message_ids An array of EE_Message IDs |
|
| 1150 | + * @return bool true means messages were successfully queued for resending, false means none were queued for |
|
| 1151 | + * resending. |
|
| 1152 | + * @throws EE_Error |
|
| 1153 | + * @throws InvalidArgumentException |
|
| 1154 | + * @throws InvalidDataTypeException |
|
| 1155 | + * @throws InvalidInterfaceException |
|
| 1156 | + * @throws ReflectionException |
|
| 1157 | + */ |
|
| 1158 | + public static function queue_for_resending($message_ids) |
|
| 1159 | + { |
|
| 1160 | + self::_load_controller(); |
|
| 1161 | + self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids); |
|
| 1162 | + |
|
| 1163 | + //get queue and count |
|
| 1164 | + $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
| 1165 | + |
|
| 1166 | + if ( |
|
| 1167 | + $queue_count > 0 |
|
| 1168 | + ) { |
|
| 1169 | + EE_Error::add_success( |
|
| 1170 | + sprintf( |
|
| 1171 | + _n( |
|
| 1172 | + '%d message successfully queued for resending.', |
|
| 1173 | + '%d messages successfully queued for resending.', |
|
| 1174 | + $queue_count, |
|
| 1175 | + 'event_espresso' |
|
| 1176 | + ), |
|
| 1177 | + $queue_count |
|
| 1178 | + ) |
|
| 1179 | + ); |
|
| 1180 | + /** |
|
| 1181 | + * @see filter usage in EE_Messages_Queue::initiate_request_by_priority |
|
| 1182 | + */ |
|
| 1183 | + } elseif ( |
|
| 1184 | + apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true) |
|
| 1185 | + || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
| 1186 | + ) { |
|
| 1187 | + $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent); |
|
| 1188 | + if ($queue_count > 0) { |
|
| 1189 | + EE_Error::add_success( |
|
| 1190 | + sprintf( |
|
| 1191 | + _n( |
|
| 1192 | + '%d message successfully sent.', |
|
| 1193 | + '%d messages successfully sent.', |
|
| 1194 | + $queue_count, |
|
| 1195 | + 'event_espresso' |
|
| 1196 | + ), |
|
| 1197 | + $queue_count |
|
| 1198 | + ) |
|
| 1199 | + ); |
|
| 1200 | + } else { |
|
| 1201 | + EE_Error::add_error( |
|
| 1202 | + __('No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
| 1203 | + 'event_espresso'), |
|
| 1204 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1205 | + ); |
|
| 1206 | + } |
|
| 1207 | + } else { |
|
| 1208 | + EE_Error::add_error( |
|
| 1209 | + __('No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
| 1210 | + 'event_espresso'), |
|
| 1211 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1212 | + ); |
|
| 1213 | + } |
|
| 1214 | + return (bool)$queue_count; |
|
| 1215 | + } |
|
| 1216 | + |
|
| 1217 | + |
|
| 1218 | + /** |
|
| 1219 | + * debug |
|
| 1220 | + * |
|
| 1221 | + * @param string $class |
|
| 1222 | + * @param string $func |
|
| 1223 | + * @param string $line |
|
| 1224 | + * @param \EE_Transaction $transaction |
|
| 1225 | + * @param array $info |
|
| 1226 | + * @param bool $display_request |
|
| 1227 | + * @throws EE_Error |
|
| 1228 | + * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
| 1229 | + */ |
|
| 1230 | + protected static function log( |
|
| 1231 | + $class = '', |
|
| 1232 | + $func = '', |
|
| 1233 | + $line = '', |
|
| 1234 | + EE_Transaction $transaction, |
|
| 1235 | + $info = array(), |
|
| 1236 | + $display_request = false |
|
| 1237 | + ) { |
|
| 1238 | + if (defined('EE_DEBUG') && EE_DEBUG) { |
|
| 1239 | + if ($transaction instanceof EE_Transaction) { |
|
| 1240 | + // don't serialize objects |
|
| 1241 | + $info = EEH_Debug_Tools::strip_objects($info); |
|
| 1242 | + $info['TXN_status'] = $transaction->status_ID(); |
|
| 1243 | + $info['TXN_reg_steps'] = $transaction->reg_steps(); |
|
| 1244 | + if ($transaction->ID()) { |
|
| 1245 | + $index = 'EE_Transaction: ' . $transaction->ID(); |
|
| 1246 | + EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index); |
|
| 1247 | + } |
|
| 1248 | + } |
|
| 1249 | + } |
|
| 1250 | + |
|
| 1251 | + } |
|
| 1252 | + |
|
| 1253 | + |
|
| 1254 | + /** |
|
| 1255 | + * Resets all the static properties in this class when called. |
|
| 1256 | + */ |
|
| 1257 | + public static function reset() |
|
| 1258 | + { |
|
| 1259 | + self::$_EEMSG = null; |
|
| 1260 | + self::$_message_resource_manager = null; |
|
| 1261 | + self::$_MSG_PROCESSOR = null; |
|
| 1262 | + self::$_MSG_PATHS = null; |
|
| 1263 | + self::$_TMP_PACKS = array(); |
|
| 1264 | + } |
|
| 1265 | 1265 | |
| 1266 | 1266 | } |
| 1267 | 1267 | // End of file EED_Messages.module.php |
@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | use EventEspresso\core\exceptions\InvalidInterfaceException; |
| 6 | 6 | |
| 7 | 7 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 8 | - exit('NO direct script access allowed'); |
|
| 8 | + exit('NO direct script access allowed'); |
|
| 9 | 9 | } |
| 10 | 10 | |
| 11 | 11 | /** |
@@ -23,2559 +23,2559 @@ discard block |
||
| 23 | 23 | class Messages_Admin_Page extends EE_Admin_Page |
| 24 | 24 | { |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @type EE_Message_Resource_Manager $_message_resource_manager |
|
| 28 | - */ |
|
| 29 | - protected $_message_resource_manager; |
|
| 26 | + /** |
|
| 27 | + * @type EE_Message_Resource_Manager $_message_resource_manager |
|
| 28 | + */ |
|
| 29 | + protected $_message_resource_manager; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * @type string $_active_message_type_name |
|
| 33 | - */ |
|
| 34 | - protected $_active_message_type_name = ''; |
|
| 31 | + /** |
|
| 32 | + * @type string $_active_message_type_name |
|
| 33 | + */ |
|
| 34 | + protected $_active_message_type_name = ''; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @type EE_messenger $_active_messenger |
|
| 38 | - */ |
|
| 39 | - protected $_active_messenger; |
|
| 40 | - protected $_activate_state; |
|
| 41 | - protected $_activate_meta_box_type; |
|
| 42 | - protected $_current_message_meta_box; |
|
| 43 | - protected $_current_message_meta_box_object; |
|
| 44 | - protected $_context_switcher; |
|
| 45 | - protected $_shortcodes = array(); |
|
| 46 | - protected $_active_messengers = array(); |
|
| 47 | - protected $_active_message_types = array(); |
|
| 36 | + /** |
|
| 37 | + * @type EE_messenger $_active_messenger |
|
| 38 | + */ |
|
| 39 | + protected $_active_messenger; |
|
| 40 | + protected $_activate_state; |
|
| 41 | + protected $_activate_meta_box_type; |
|
| 42 | + protected $_current_message_meta_box; |
|
| 43 | + protected $_current_message_meta_box_object; |
|
| 44 | + protected $_context_switcher; |
|
| 45 | + protected $_shortcodes = array(); |
|
| 46 | + protected $_active_messengers = array(); |
|
| 47 | + protected $_active_message_types = array(); |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @var EE_Message_Template_Group $_message_template_group |
|
| 51 | - */ |
|
| 52 | - protected $_message_template_group; |
|
| 53 | - protected $_m_mt_settings = array(); |
|
| 49 | + /** |
|
| 50 | + * @var EE_Message_Template_Group $_message_template_group |
|
| 51 | + */ |
|
| 52 | + protected $_message_template_group; |
|
| 53 | + protected $_m_mt_settings = array(); |
|
| 54 | 54 | |
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * This is set via the _set_message_template_group method and holds whatever the template pack for the group is. |
|
| 58 | - * IF there is no group then it gets automatically set to the Default template pack. |
|
| 59 | - * |
|
| 60 | - * @since 4.5.0 |
|
| 61 | - * |
|
| 62 | - * @var EE_Messages_Template_Pack |
|
| 63 | - */ |
|
| 64 | - protected $_template_pack; |
|
| 56 | + /** |
|
| 57 | + * This is set via the _set_message_template_group method and holds whatever the template pack for the group is. |
|
| 58 | + * IF there is no group then it gets automatically set to the Default template pack. |
|
| 59 | + * |
|
| 60 | + * @since 4.5.0 |
|
| 61 | + * |
|
| 62 | + * @var EE_Messages_Template_Pack |
|
| 63 | + */ |
|
| 64 | + protected $_template_pack; |
|
| 65 | 65 | |
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * This is set via the _set_message_template_group method and holds whatever the template pack variation for the |
|
| 69 | - * group is. If there is no group then it automatically gets set to default. |
|
| 70 | - * |
|
| 71 | - * @since 4.5.0 |
|
| 72 | - * |
|
| 73 | - * @var string |
|
| 74 | - */ |
|
| 75 | - protected $_variation; |
|
| 67 | + /** |
|
| 68 | + * This is set via the _set_message_template_group method and holds whatever the template pack variation for the |
|
| 69 | + * group is. If there is no group then it automatically gets set to default. |
|
| 70 | + * |
|
| 71 | + * @since 4.5.0 |
|
| 72 | + * |
|
| 73 | + * @var string |
|
| 74 | + */ |
|
| 75 | + protected $_variation; |
|
| 76 | 76 | |
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * @param bool $routing |
|
| 80 | - * @throws EE_Error |
|
| 81 | - */ |
|
| 82 | - public function __construct($routing = true) |
|
| 83 | - { |
|
| 84 | - //make sure messages autoloader is running |
|
| 85 | - EED_Messages::set_autoloaders(); |
|
| 86 | - parent::__construct($routing); |
|
| 87 | - } |
|
| 78 | + /** |
|
| 79 | + * @param bool $routing |
|
| 80 | + * @throws EE_Error |
|
| 81 | + */ |
|
| 82 | + public function __construct($routing = true) |
|
| 83 | + { |
|
| 84 | + //make sure messages autoloader is running |
|
| 85 | + EED_Messages::set_autoloaders(); |
|
| 86 | + parent::__construct($routing); |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | 89 | |
| 90 | - protected function _init_page_props() |
|
| 91 | - { |
|
| 92 | - $this->page_slug = EE_MSG_PG_SLUG; |
|
| 93 | - $this->page_label = esc_html__('Messages Settings', 'event_espresso'); |
|
| 94 | - $this->_admin_base_url = EE_MSG_ADMIN_URL; |
|
| 95 | - $this->_admin_base_path = EE_MSG_ADMIN; |
|
| 96 | - |
|
| 97 | - $this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array(); |
|
| 98 | - |
|
| 99 | - $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null; |
|
| 100 | - $this->_load_message_resource_manager(); |
|
| 101 | - } |
|
| 90 | + protected function _init_page_props() |
|
| 91 | + { |
|
| 92 | + $this->page_slug = EE_MSG_PG_SLUG; |
|
| 93 | + $this->page_label = esc_html__('Messages Settings', 'event_espresso'); |
|
| 94 | + $this->_admin_base_url = EE_MSG_ADMIN_URL; |
|
| 95 | + $this->_admin_base_path = EE_MSG_ADMIN; |
|
| 96 | + |
|
| 97 | + $this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array(); |
|
| 98 | + |
|
| 99 | + $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null; |
|
| 100 | + $this->_load_message_resource_manager(); |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | 103 | |
| 104 | - /** |
|
| 105 | - * loads messenger objects into the $_active_messengers property (so we can access the needed methods) |
|
| 106 | - * |
|
| 107 | - * @throws EE_Error |
|
| 108 | - * @throws InvalidDataTypeException |
|
| 109 | - * @throws InvalidInterfaceException |
|
| 110 | - * @throws InvalidArgumentException |
|
| 111 | - * @throws ReflectionException |
|
| 112 | - */ |
|
| 113 | - protected function _load_message_resource_manager() |
|
| 114 | - { |
|
| 115 | - $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 116 | - } |
|
| 104 | + /** |
|
| 105 | + * loads messenger objects into the $_active_messengers property (so we can access the needed methods) |
|
| 106 | + * |
|
| 107 | + * @throws EE_Error |
|
| 108 | + * @throws InvalidDataTypeException |
|
| 109 | + * @throws InvalidInterfaceException |
|
| 110 | + * @throws InvalidArgumentException |
|
| 111 | + * @throws ReflectionException |
|
| 112 | + */ |
|
| 113 | + protected function _load_message_resource_manager() |
|
| 114 | + { |
|
| 115 | + $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | 118 | |
| 119 | - /** |
|
| 120 | - * @deprecated 4.9.9.rc.014 |
|
| 121 | - * @return array |
|
| 122 | - * @throws EE_Error |
|
| 123 | - * @throws InvalidArgumentException |
|
| 124 | - * @throws InvalidDataTypeException |
|
| 125 | - * @throws InvalidInterfaceException |
|
| 126 | - */ |
|
| 127 | - public function get_messengers_for_list_table() |
|
| 128 | - { |
|
| 129 | - EE_Error::doing_it_wrong( |
|
| 130 | - __METHOD__, |
|
| 131 | - sprintf( |
|
| 132 | - esc_html__( |
|
| 133 | - 'This method is no longer in use. There is no replacement for it. The method was used to generate a set of values for use in creating a messenger filter dropdown which is now generated differently via %s', |
|
| 134 | - 'event_espresso' |
|
| 135 | - ), |
|
| 136 | - 'Messages_Admin_Page::get_messengers_select_input()' |
|
| 137 | - ), |
|
| 138 | - '4.9.9.rc.014' |
|
| 139 | - ); |
|
| 140 | - |
|
| 141 | - $m_values = array(); |
|
| 142 | - $active_messengers = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger')); |
|
| 143 | - //setup messengers for selects |
|
| 144 | - $i = 1; |
|
| 145 | - foreach ($active_messengers as $active_messenger) { |
|
| 146 | - if ($active_messenger instanceof EE_Message) { |
|
| 147 | - $m_values[$i]['id'] = $active_messenger->messenger(); |
|
| 148 | - $m_values[$i]['text'] = ucwords($active_messenger->messenger_label()); |
|
| 149 | - $i++; |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - return $m_values; |
|
| 154 | - } |
|
| 119 | + /** |
|
| 120 | + * @deprecated 4.9.9.rc.014 |
|
| 121 | + * @return array |
|
| 122 | + * @throws EE_Error |
|
| 123 | + * @throws InvalidArgumentException |
|
| 124 | + * @throws InvalidDataTypeException |
|
| 125 | + * @throws InvalidInterfaceException |
|
| 126 | + */ |
|
| 127 | + public function get_messengers_for_list_table() |
|
| 128 | + { |
|
| 129 | + EE_Error::doing_it_wrong( |
|
| 130 | + __METHOD__, |
|
| 131 | + sprintf( |
|
| 132 | + esc_html__( |
|
| 133 | + 'This method is no longer in use. There is no replacement for it. The method was used to generate a set of values for use in creating a messenger filter dropdown which is now generated differently via %s', |
|
| 134 | + 'event_espresso' |
|
| 135 | + ), |
|
| 136 | + 'Messages_Admin_Page::get_messengers_select_input()' |
|
| 137 | + ), |
|
| 138 | + '4.9.9.rc.014' |
|
| 139 | + ); |
|
| 140 | + |
|
| 141 | + $m_values = array(); |
|
| 142 | + $active_messengers = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger')); |
|
| 143 | + //setup messengers for selects |
|
| 144 | + $i = 1; |
|
| 145 | + foreach ($active_messengers as $active_messenger) { |
|
| 146 | + if ($active_messenger instanceof EE_Message) { |
|
| 147 | + $m_values[$i]['id'] = $active_messenger->messenger(); |
|
| 148 | + $m_values[$i]['text'] = ucwords($active_messenger->messenger_label()); |
|
| 149 | + $i++; |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + return $m_values; |
|
| 154 | + } |
|
| 155 | 155 | |
| 156 | 156 | |
| 157 | - /** |
|
| 158 | - * @deprecated 4.9.9.rc.014 |
|
| 159 | - * @return array |
|
| 160 | - * @throws EE_Error |
|
| 161 | - * @throws InvalidArgumentException |
|
| 162 | - * @throws InvalidDataTypeException |
|
| 163 | - * @throws InvalidInterfaceException |
|
| 164 | - */ |
|
| 165 | - public function get_message_types_for_list_table() |
|
| 166 | - { |
|
| 167 | - EE_Error::doing_it_wrong( |
|
| 168 | - __METHOD__, |
|
| 169 | - sprintf( |
|
| 170 | - esc_html__( |
|
| 171 | - 'This method is no longer in use. There is no replacement for it. The method was used to generate a set of values for use in creating a message type filter dropdown which is now generated differently via %s', |
|
| 172 | - 'event_espresso' |
|
| 173 | - ), |
|
| 174 | - 'Messages_Admin_Page::get_message_types_select_input()' |
|
| 175 | - ), |
|
| 176 | - '4.9.9.rc.014' |
|
| 177 | - ); |
|
| 178 | - |
|
| 179 | - $mt_values = array(); |
|
| 180 | - $active_messages = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type')); |
|
| 181 | - $i = 1; |
|
| 182 | - foreach ($active_messages as $active_message) { |
|
| 183 | - if ($active_message instanceof EE_Message) { |
|
| 184 | - $mt_values[$i]['id'] = $active_message->message_type(); |
|
| 185 | - $mt_values[$i]['text'] = ucwords($active_message->message_type_label()); |
|
| 186 | - $i++; |
|
| 187 | - } |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - return $mt_values; |
|
| 191 | - } |
|
| 157 | + /** |
|
| 158 | + * @deprecated 4.9.9.rc.014 |
|
| 159 | + * @return array |
|
| 160 | + * @throws EE_Error |
|
| 161 | + * @throws InvalidArgumentException |
|
| 162 | + * @throws InvalidDataTypeException |
|
| 163 | + * @throws InvalidInterfaceException |
|
| 164 | + */ |
|
| 165 | + public function get_message_types_for_list_table() |
|
| 166 | + { |
|
| 167 | + EE_Error::doing_it_wrong( |
|
| 168 | + __METHOD__, |
|
| 169 | + sprintf( |
|
| 170 | + esc_html__( |
|
| 171 | + 'This method is no longer in use. There is no replacement for it. The method was used to generate a set of values for use in creating a message type filter dropdown which is now generated differently via %s', |
|
| 172 | + 'event_espresso' |
|
| 173 | + ), |
|
| 174 | + 'Messages_Admin_Page::get_message_types_select_input()' |
|
| 175 | + ), |
|
| 176 | + '4.9.9.rc.014' |
|
| 177 | + ); |
|
| 178 | + |
|
| 179 | + $mt_values = array(); |
|
| 180 | + $active_messages = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type')); |
|
| 181 | + $i = 1; |
|
| 182 | + foreach ($active_messages as $active_message) { |
|
| 183 | + if ($active_message instanceof EE_Message) { |
|
| 184 | + $mt_values[$i]['id'] = $active_message->message_type(); |
|
| 185 | + $mt_values[$i]['text'] = ucwords($active_message->message_type_label()); |
|
| 186 | + $i++; |
|
| 187 | + } |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + return $mt_values; |
|
| 191 | + } |
|
| 192 | 192 | |
| 193 | 193 | |
| 194 | - /** |
|
| 195 | - * @deprecated 4.9.9.rc.014 |
|
| 196 | - * @return array |
|
| 197 | - * @throws EE_Error |
|
| 198 | - * @throws InvalidArgumentException |
|
| 199 | - * @throws InvalidDataTypeException |
|
| 200 | - * @throws InvalidInterfaceException |
|
| 201 | - */ |
|
| 202 | - public function get_contexts_for_message_types_for_list_table() |
|
| 203 | - { |
|
| 204 | - EE_Error::doing_it_wrong( |
|
| 205 | - __METHOD__, |
|
| 206 | - sprintf( |
|
| 207 | - esc_html__( |
|
| 208 | - 'This method is no longer in use. There is no replacement for it. The method was used to generate a set of values for use in creating a message type context filter dropdown which is now generated differently via %s', |
|
| 209 | - 'event_espresso' |
|
| 210 | - ), |
|
| 211 | - 'Messages_Admin_Page::get_contexts_for_message_types_select_input()' |
|
| 212 | - ), |
|
| 213 | - '4.9.9.rc.014' |
|
| 214 | - ); |
|
| 215 | - |
|
| 216 | - $contexts = array(); |
|
| 217 | - $active_message_contexts = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context')); |
|
| 218 | - foreach ($active_message_contexts as $active_message) { |
|
| 219 | - if ($active_message instanceof EE_Message) { |
|
| 220 | - $message_type = $active_message->message_type_object(); |
|
| 221 | - if ($message_type instanceof EE_message_type) { |
|
| 222 | - $message_type_contexts = $message_type->get_contexts(); |
|
| 223 | - foreach ($message_type_contexts as $context => $context_details) { |
|
| 224 | - $contexts[$context] = $context_details['label']; |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - } |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - return $contexts; |
|
| 231 | - } |
|
| 194 | + /** |
|
| 195 | + * @deprecated 4.9.9.rc.014 |
|
| 196 | + * @return array |
|
| 197 | + * @throws EE_Error |
|
| 198 | + * @throws InvalidArgumentException |
|
| 199 | + * @throws InvalidDataTypeException |
|
| 200 | + * @throws InvalidInterfaceException |
|
| 201 | + */ |
|
| 202 | + public function get_contexts_for_message_types_for_list_table() |
|
| 203 | + { |
|
| 204 | + EE_Error::doing_it_wrong( |
|
| 205 | + __METHOD__, |
|
| 206 | + sprintf( |
|
| 207 | + esc_html__( |
|
| 208 | + 'This method is no longer in use. There is no replacement for it. The method was used to generate a set of values for use in creating a message type context filter dropdown which is now generated differently via %s', |
|
| 209 | + 'event_espresso' |
|
| 210 | + ), |
|
| 211 | + 'Messages_Admin_Page::get_contexts_for_message_types_select_input()' |
|
| 212 | + ), |
|
| 213 | + '4.9.9.rc.014' |
|
| 214 | + ); |
|
| 215 | + |
|
| 216 | + $contexts = array(); |
|
| 217 | + $active_message_contexts = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context')); |
|
| 218 | + foreach ($active_message_contexts as $active_message) { |
|
| 219 | + if ($active_message instanceof EE_Message) { |
|
| 220 | + $message_type = $active_message->message_type_object(); |
|
| 221 | + if ($message_type instanceof EE_message_type) { |
|
| 222 | + $message_type_contexts = $message_type->get_contexts(); |
|
| 223 | + foreach ($message_type_contexts as $context => $context_details) { |
|
| 224 | + $contexts[$context] = $context_details['label']; |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + return $contexts; |
|
| 231 | + } |
|
| 232 | 232 | |
| 233 | 233 | |
| 234 | - /** |
|
| 235 | - * Generate select input with provided messenger options array. |
|
| 236 | - * |
|
| 237 | - * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger |
|
| 238 | - * labels. |
|
| 239 | - * @return string |
|
| 240 | - * @throws EE_Error |
|
| 241 | - */ |
|
| 242 | - public function get_messengers_select_input($messenger_options) |
|
| 243 | - { |
|
| 244 | - //if empty or just one value then just return an empty string |
|
| 245 | - if (empty($messenger_options) |
|
| 246 | - || ! is_array($messenger_options) |
|
| 247 | - || count($messenger_options) === 1 |
|
| 248 | - ) { |
|
| 249 | - return ''; |
|
| 250 | - } |
|
| 251 | - //merge in default |
|
| 252 | - $messenger_options = array_merge( |
|
| 253 | - array('none_selected' => esc_html__('Show All Messengers', 'event_espresso')), |
|
| 254 | - $messenger_options |
|
| 255 | - ); |
|
| 256 | - $input = new EE_Select_Input( |
|
| 257 | - $messenger_options, |
|
| 258 | - array( |
|
| 259 | - 'html_name' => 'ee_messenger_filter_by', |
|
| 260 | - 'html_id' => 'ee_messenger_filter_by', |
|
| 261 | - 'html_class' => 'wide', |
|
| 262 | - 'default' => isset($this->_req_data['ee_messenger_filter_by']) |
|
| 263 | - ? sanitize_title($this->_req_data['ee_messenger_filter_by']) |
|
| 264 | - : 'none_selected' |
|
| 265 | - ) |
|
| 266 | - ); |
|
| 267 | - |
|
| 268 | - return $input->get_html_for_input(); |
|
| 269 | - } |
|
| 234 | + /** |
|
| 235 | + * Generate select input with provided messenger options array. |
|
| 236 | + * |
|
| 237 | + * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger |
|
| 238 | + * labels. |
|
| 239 | + * @return string |
|
| 240 | + * @throws EE_Error |
|
| 241 | + */ |
|
| 242 | + public function get_messengers_select_input($messenger_options) |
|
| 243 | + { |
|
| 244 | + //if empty or just one value then just return an empty string |
|
| 245 | + if (empty($messenger_options) |
|
| 246 | + || ! is_array($messenger_options) |
|
| 247 | + || count($messenger_options) === 1 |
|
| 248 | + ) { |
|
| 249 | + return ''; |
|
| 250 | + } |
|
| 251 | + //merge in default |
|
| 252 | + $messenger_options = array_merge( |
|
| 253 | + array('none_selected' => esc_html__('Show All Messengers', 'event_espresso')), |
|
| 254 | + $messenger_options |
|
| 255 | + ); |
|
| 256 | + $input = new EE_Select_Input( |
|
| 257 | + $messenger_options, |
|
| 258 | + array( |
|
| 259 | + 'html_name' => 'ee_messenger_filter_by', |
|
| 260 | + 'html_id' => 'ee_messenger_filter_by', |
|
| 261 | + 'html_class' => 'wide', |
|
| 262 | + 'default' => isset($this->_req_data['ee_messenger_filter_by']) |
|
| 263 | + ? sanitize_title($this->_req_data['ee_messenger_filter_by']) |
|
| 264 | + : 'none_selected' |
|
| 265 | + ) |
|
| 266 | + ); |
|
| 267 | + |
|
| 268 | + return $input->get_html_for_input(); |
|
| 269 | + } |
|
| 270 | 270 | |
| 271 | 271 | |
| 272 | - /** |
|
| 273 | - * Generate select input with provided message type options array. |
|
| 274 | - * |
|
| 275 | - * @param array $message_type_options Array of message types indexed by message type slug, and values are the |
|
| 276 | - * message type labels |
|
| 277 | - * @return string |
|
| 278 | - * @throws EE_Error |
|
| 279 | - */ |
|
| 280 | - public function get_message_types_select_input($message_type_options) |
|
| 281 | - { |
|
| 282 | - //if empty or count of options is 1 then just return an empty string |
|
| 283 | - if (empty($message_type_options) |
|
| 284 | - || ! is_array($message_type_options) |
|
| 285 | - || count($message_type_options) === 1 |
|
| 286 | - ) { |
|
| 287 | - return ''; |
|
| 288 | - } |
|
| 289 | - //merge in default |
|
| 290 | - $message_type_options = array_merge( |
|
| 291 | - array('none_selected' => esc_html__('Show All Message Types', 'event_espresso')), |
|
| 292 | - $message_type_options |
|
| 293 | - ); |
|
| 294 | - $input = new EE_Select_Input( |
|
| 295 | - $message_type_options, |
|
| 296 | - array( |
|
| 297 | - 'html_name' => 'ee_message_type_filter_by', |
|
| 298 | - 'html_id' => 'ee_message_type_filter_by', |
|
| 299 | - 'html_class' => 'wide', |
|
| 300 | - 'default' => isset($this->_req_data['ee_message_type_filter_by']) |
|
| 301 | - ? sanitize_title($this->_req_data['ee_message_type_filter_by']) |
|
| 302 | - : 'none_selected', |
|
| 303 | - ) |
|
| 304 | - ); |
|
| 305 | - |
|
| 306 | - return $input->get_html_for_input(); |
|
| 307 | - } |
|
| 272 | + /** |
|
| 273 | + * Generate select input with provided message type options array. |
|
| 274 | + * |
|
| 275 | + * @param array $message_type_options Array of message types indexed by message type slug, and values are the |
|
| 276 | + * message type labels |
|
| 277 | + * @return string |
|
| 278 | + * @throws EE_Error |
|
| 279 | + */ |
|
| 280 | + public function get_message_types_select_input($message_type_options) |
|
| 281 | + { |
|
| 282 | + //if empty or count of options is 1 then just return an empty string |
|
| 283 | + if (empty($message_type_options) |
|
| 284 | + || ! is_array($message_type_options) |
|
| 285 | + || count($message_type_options) === 1 |
|
| 286 | + ) { |
|
| 287 | + return ''; |
|
| 288 | + } |
|
| 289 | + //merge in default |
|
| 290 | + $message_type_options = array_merge( |
|
| 291 | + array('none_selected' => esc_html__('Show All Message Types', 'event_espresso')), |
|
| 292 | + $message_type_options |
|
| 293 | + ); |
|
| 294 | + $input = new EE_Select_Input( |
|
| 295 | + $message_type_options, |
|
| 296 | + array( |
|
| 297 | + 'html_name' => 'ee_message_type_filter_by', |
|
| 298 | + 'html_id' => 'ee_message_type_filter_by', |
|
| 299 | + 'html_class' => 'wide', |
|
| 300 | + 'default' => isset($this->_req_data['ee_message_type_filter_by']) |
|
| 301 | + ? sanitize_title($this->_req_data['ee_message_type_filter_by']) |
|
| 302 | + : 'none_selected', |
|
| 303 | + ) |
|
| 304 | + ); |
|
| 305 | + |
|
| 306 | + return $input->get_html_for_input(); |
|
| 307 | + } |
|
| 308 | 308 | |
| 309 | 309 | |
| 310 | - /** |
|
| 311 | - * Generate select input with provide message type contexts array. |
|
| 312 | - * |
|
| 313 | - * @param array $context_options Array of message type contexts indexed by context slug, and values are the |
|
| 314 | - * context label. |
|
| 315 | - * @return string |
|
| 316 | - * @throws EE_Error |
|
| 317 | - */ |
|
| 318 | - public function get_contexts_for_message_types_select_input($context_options) |
|
| 319 | - { |
|
| 320 | - //if empty or count of options is one then just return empty string |
|
| 321 | - if (empty($context_options) |
|
| 322 | - || ! is_array($context_options) |
|
| 323 | - || count($context_options) === 1 |
|
| 324 | - ) { |
|
| 325 | - return ''; |
|
| 326 | - } |
|
| 327 | - //merge in default |
|
| 328 | - $context_options = array_merge( |
|
| 329 | - array('none_selected' => esc_html__('Show all Contexts', 'event_espresso')), |
|
| 330 | - $context_options |
|
| 331 | - ); |
|
| 332 | - $input = new EE_Select_Input( |
|
| 333 | - $context_options, |
|
| 334 | - array( |
|
| 335 | - 'html_name' => 'ee_context_filter_by', |
|
| 336 | - 'html_id' => 'ee_context_filter_by', |
|
| 337 | - 'html_class' => 'wide', |
|
| 338 | - 'default' => isset($this->_req_data['ee_context_filter_by']) |
|
| 339 | - ? sanitize_title($this->_req_data['ee_context_filter_by']) |
|
| 340 | - : 'none_selected', |
|
| 341 | - ) |
|
| 342 | - ); |
|
| 343 | - |
|
| 344 | - return $input->get_html_for_input(); |
|
| 345 | - } |
|
| 310 | + /** |
|
| 311 | + * Generate select input with provide message type contexts array. |
|
| 312 | + * |
|
| 313 | + * @param array $context_options Array of message type contexts indexed by context slug, and values are the |
|
| 314 | + * context label. |
|
| 315 | + * @return string |
|
| 316 | + * @throws EE_Error |
|
| 317 | + */ |
|
| 318 | + public function get_contexts_for_message_types_select_input($context_options) |
|
| 319 | + { |
|
| 320 | + //if empty or count of options is one then just return empty string |
|
| 321 | + if (empty($context_options) |
|
| 322 | + || ! is_array($context_options) |
|
| 323 | + || count($context_options) === 1 |
|
| 324 | + ) { |
|
| 325 | + return ''; |
|
| 326 | + } |
|
| 327 | + //merge in default |
|
| 328 | + $context_options = array_merge( |
|
| 329 | + array('none_selected' => esc_html__('Show all Contexts', 'event_espresso')), |
|
| 330 | + $context_options |
|
| 331 | + ); |
|
| 332 | + $input = new EE_Select_Input( |
|
| 333 | + $context_options, |
|
| 334 | + array( |
|
| 335 | + 'html_name' => 'ee_context_filter_by', |
|
| 336 | + 'html_id' => 'ee_context_filter_by', |
|
| 337 | + 'html_class' => 'wide', |
|
| 338 | + 'default' => isset($this->_req_data['ee_context_filter_by']) |
|
| 339 | + ? sanitize_title($this->_req_data['ee_context_filter_by']) |
|
| 340 | + : 'none_selected', |
|
| 341 | + ) |
|
| 342 | + ); |
|
| 343 | + |
|
| 344 | + return $input->get_html_for_input(); |
|
| 345 | + } |
|
| 346 | 346 | |
| 347 | 347 | |
| 348 | - protected function _ajax_hooks() |
|
| 349 | - { |
|
| 350 | - add_action('wp_ajax_activate_messenger', array($this, 'activate_messenger_toggle')); |
|
| 351 | - add_action('wp_ajax_activate_mt', array($this, 'activate_mt_toggle')); |
|
| 352 | - add_action('wp_ajax_ee_msgs_save_settings', array($this, 'save_settings')); |
|
| 353 | - add_action('wp_ajax_ee_msgs_update_mt_form', array($this, 'update_mt_form')); |
|
| 354 | - add_action('wp_ajax_switch_template_pack', array($this, 'switch_template_pack')); |
|
| 355 | - add_action('wp_ajax_toggle_context_template', array($this, 'toggle_context_template')); |
|
| 356 | - } |
|
| 348 | + protected function _ajax_hooks() |
|
| 349 | + { |
|
| 350 | + add_action('wp_ajax_activate_messenger', array($this, 'activate_messenger_toggle')); |
|
| 351 | + add_action('wp_ajax_activate_mt', array($this, 'activate_mt_toggle')); |
|
| 352 | + add_action('wp_ajax_ee_msgs_save_settings', array($this, 'save_settings')); |
|
| 353 | + add_action('wp_ajax_ee_msgs_update_mt_form', array($this, 'update_mt_form')); |
|
| 354 | + add_action('wp_ajax_switch_template_pack', array($this, 'switch_template_pack')); |
|
| 355 | + add_action('wp_ajax_toggle_context_template', array($this, 'toggle_context_template')); |
|
| 356 | + } |
|
| 357 | 357 | |
| 358 | 358 | |
| 359 | - protected function _define_page_props() |
|
| 360 | - { |
|
| 361 | - $this->_admin_page_title = $this->page_label; |
|
| 362 | - $this->_labels = array( |
|
| 363 | - 'buttons' => array( |
|
| 364 | - 'add' => esc_html__('Add New Message Template', 'event_espresso'), |
|
| 365 | - 'edit' => esc_html__('Edit Message Template', 'event_espresso'), |
|
| 366 | - 'delete' => esc_html__('Delete Message Template', 'event_espresso') |
|
| 367 | - ), |
|
| 368 | - 'publishbox' => esc_html__('Update Actions', 'event_espresso') |
|
| 369 | - ); |
|
| 370 | - } |
|
| 359 | + protected function _define_page_props() |
|
| 360 | + { |
|
| 361 | + $this->_admin_page_title = $this->page_label; |
|
| 362 | + $this->_labels = array( |
|
| 363 | + 'buttons' => array( |
|
| 364 | + 'add' => esc_html__('Add New Message Template', 'event_espresso'), |
|
| 365 | + 'edit' => esc_html__('Edit Message Template', 'event_espresso'), |
|
| 366 | + 'delete' => esc_html__('Delete Message Template', 'event_espresso') |
|
| 367 | + ), |
|
| 368 | + 'publishbox' => esc_html__('Update Actions', 'event_espresso') |
|
| 369 | + ); |
|
| 370 | + } |
|
| 371 | 371 | |
| 372 | 372 | |
| 373 | - /** |
|
| 374 | - * an array for storing key => value pairs of request actions and their corresponding methods |
|
| 375 | - * @access protected |
|
| 376 | - * @return void |
|
| 377 | - */ |
|
| 378 | - protected function _set_page_routes() |
|
| 379 | - { |
|
| 380 | - $grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID']) |
|
| 381 | - ? $this->_req_data['GRP_ID'] |
|
| 382 | - : 0; |
|
| 383 | - $grp_id = empty($grp_id) && ! empty($this->_req_data['id']) |
|
| 384 | - ? $this->_req_data['id'] |
|
| 385 | - : $grp_id; |
|
| 386 | - $msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID']) |
|
| 387 | - ? $this->_req_data['MSG_ID'] |
|
| 388 | - : 0; |
|
| 389 | - |
|
| 390 | - $this->_page_routes = array( |
|
| 391 | - 'default' => array( |
|
| 392 | - 'func' => '_message_queue_list_table', |
|
| 393 | - 'capability' => 'ee_read_global_messages' |
|
| 394 | - ), |
|
| 395 | - 'global_mtps' => array( |
|
| 396 | - 'func' => '_ee_default_messages_overview_list_table', |
|
| 397 | - 'capability' => 'ee_read_global_messages' |
|
| 398 | - ), |
|
| 399 | - 'custom_mtps' => array( |
|
| 400 | - 'func' => '_custom_mtps_preview', |
|
| 401 | - 'capability' => 'ee_read_messages' |
|
| 402 | - ), |
|
| 403 | - 'add_new_message_template' => array( |
|
| 404 | - 'func' => '_add_message_template', |
|
| 405 | - 'capability' => 'ee_edit_messages', |
|
| 406 | - 'noheader' => true |
|
| 407 | - ), |
|
| 408 | - 'edit_message_template' => array( |
|
| 409 | - 'func' => '_edit_message_template', |
|
| 410 | - 'capability' => 'ee_edit_message', |
|
| 411 | - 'obj_id' => $grp_id |
|
| 412 | - ), |
|
| 413 | - 'preview_message' => array( |
|
| 414 | - 'func' => '_preview_message', |
|
| 415 | - 'capability' => 'ee_read_message', |
|
| 416 | - 'obj_id' => $grp_id, |
|
| 417 | - 'noheader' => true, |
|
| 418 | - 'headers_sent_route' => 'display_preview_message' |
|
| 419 | - ), |
|
| 420 | - 'display_preview_message' => array( |
|
| 421 | - 'func' => '_display_preview_message', |
|
| 422 | - 'capability' => 'ee_read_message', |
|
| 423 | - 'obj_id' => $grp_id |
|
| 424 | - ), |
|
| 425 | - 'insert_message_template' => array( |
|
| 426 | - 'func' => '_insert_or_update_message_template', |
|
| 427 | - 'capability' => 'ee_edit_messages', |
|
| 428 | - 'args' => array('new_template' => true), |
|
| 429 | - 'noheader' => true |
|
| 430 | - ), |
|
| 431 | - 'update_message_template' => array( |
|
| 432 | - 'func' => '_insert_or_update_message_template', |
|
| 433 | - 'capability' => 'ee_edit_message', |
|
| 434 | - 'obj_id' => $grp_id, |
|
| 435 | - 'args' => array('new_template' => false), |
|
| 436 | - 'noheader' => true |
|
| 437 | - ), |
|
| 438 | - 'trash_message_template' => array( |
|
| 439 | - 'func' => '_trash_or_restore_message_template', |
|
| 440 | - 'capability' => 'ee_delete_message', |
|
| 441 | - 'obj_id' => $grp_id, |
|
| 442 | - 'args' => array('trash' => true, 'all' => true), |
|
| 443 | - 'noheader' => true |
|
| 444 | - ), |
|
| 445 | - 'trash_message_template_context' => array( |
|
| 446 | - 'func' => '_trash_or_restore_message_template', |
|
| 447 | - 'capability' => 'ee_delete_message', |
|
| 448 | - 'obj_id' => $grp_id, |
|
| 449 | - 'args' => array('trash' => true), |
|
| 450 | - 'noheader' => true |
|
| 451 | - ), |
|
| 452 | - 'restore_message_template' => array( |
|
| 453 | - 'func' => '_trash_or_restore_message_template', |
|
| 454 | - 'capability' => 'ee_delete_message', |
|
| 455 | - 'obj_id' => $grp_id, |
|
| 456 | - 'args' => array('trash' => false, 'all' => true), |
|
| 457 | - 'noheader' => true |
|
| 458 | - ), |
|
| 459 | - 'restore_message_template_context' => array( |
|
| 460 | - 'func' => '_trash_or_restore_message_template', |
|
| 461 | - 'capability' => 'ee_delete_message', |
|
| 462 | - 'obj_id' => $grp_id, |
|
| 463 | - 'args' => array('trash' => false), |
|
| 464 | - 'noheader' => true |
|
| 465 | - ), |
|
| 466 | - 'delete_message_template' => array( |
|
| 467 | - 'func' => '_delete_message_template', |
|
| 468 | - 'capability' => 'ee_delete_message', |
|
| 469 | - 'obj_id' => $grp_id, |
|
| 470 | - 'noheader' => true |
|
| 471 | - ), |
|
| 472 | - 'reset_to_default' => array( |
|
| 473 | - 'func' => '_reset_to_default_template', |
|
| 474 | - 'capability' => 'ee_edit_message', |
|
| 475 | - 'obj_id' => $grp_id, |
|
| 476 | - 'noheader' => true |
|
| 477 | - ), |
|
| 478 | - 'settings' => array( |
|
| 479 | - 'func' => '_settings', |
|
| 480 | - 'capability' => 'manage_options' |
|
| 481 | - ), |
|
| 482 | - 'update_global_settings' => array( |
|
| 483 | - 'func' => '_update_global_settings', |
|
| 484 | - 'capability' => 'manage_options', |
|
| 485 | - 'noheader' => true |
|
| 486 | - ), |
|
| 487 | - 'generate_now' => array( |
|
| 488 | - 'func' => '_generate_now', |
|
| 489 | - 'capability' => 'ee_send_message', |
|
| 490 | - 'noheader' => true |
|
| 491 | - ), |
|
| 492 | - 'generate_and_send_now' => array( |
|
| 493 | - 'func' => '_generate_and_send_now', |
|
| 494 | - 'capability' => 'ee_send_message', |
|
| 495 | - 'noheader' => true |
|
| 496 | - ), |
|
| 497 | - 'queue_for_resending' => array( |
|
| 498 | - 'func' => '_queue_for_resending', |
|
| 499 | - 'capability' => 'ee_send_message', |
|
| 500 | - 'noheader' => true |
|
| 501 | - ), |
|
| 502 | - 'send_now' => array( |
|
| 503 | - 'func' => '_send_now', |
|
| 504 | - 'capability' => 'ee_send_message', |
|
| 505 | - 'noheader' => true |
|
| 506 | - ), |
|
| 507 | - 'delete_ee_message' => array( |
|
| 508 | - 'func' => '_delete_ee_messages', |
|
| 509 | - 'capability' => 'ee_delete_messages', |
|
| 510 | - 'noheader' => true |
|
| 511 | - ), |
|
| 512 | - 'delete_ee_messages' => array( |
|
| 513 | - 'func' => '_delete_ee_messages', |
|
| 514 | - 'capability' => 'ee_delete_messages', |
|
| 515 | - 'noheader' => true, |
|
| 516 | - 'obj_id' => $msg_id |
|
| 517 | - ) |
|
| 518 | - ); |
|
| 519 | - } |
|
| 373 | + /** |
|
| 374 | + * an array for storing key => value pairs of request actions and their corresponding methods |
|
| 375 | + * @access protected |
|
| 376 | + * @return void |
|
| 377 | + */ |
|
| 378 | + protected function _set_page_routes() |
|
| 379 | + { |
|
| 380 | + $grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID']) |
|
| 381 | + ? $this->_req_data['GRP_ID'] |
|
| 382 | + : 0; |
|
| 383 | + $grp_id = empty($grp_id) && ! empty($this->_req_data['id']) |
|
| 384 | + ? $this->_req_data['id'] |
|
| 385 | + : $grp_id; |
|
| 386 | + $msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID']) |
|
| 387 | + ? $this->_req_data['MSG_ID'] |
|
| 388 | + : 0; |
|
| 389 | + |
|
| 390 | + $this->_page_routes = array( |
|
| 391 | + 'default' => array( |
|
| 392 | + 'func' => '_message_queue_list_table', |
|
| 393 | + 'capability' => 'ee_read_global_messages' |
|
| 394 | + ), |
|
| 395 | + 'global_mtps' => array( |
|
| 396 | + 'func' => '_ee_default_messages_overview_list_table', |
|
| 397 | + 'capability' => 'ee_read_global_messages' |
|
| 398 | + ), |
|
| 399 | + 'custom_mtps' => array( |
|
| 400 | + 'func' => '_custom_mtps_preview', |
|
| 401 | + 'capability' => 'ee_read_messages' |
|
| 402 | + ), |
|
| 403 | + 'add_new_message_template' => array( |
|
| 404 | + 'func' => '_add_message_template', |
|
| 405 | + 'capability' => 'ee_edit_messages', |
|
| 406 | + 'noheader' => true |
|
| 407 | + ), |
|
| 408 | + 'edit_message_template' => array( |
|
| 409 | + 'func' => '_edit_message_template', |
|
| 410 | + 'capability' => 'ee_edit_message', |
|
| 411 | + 'obj_id' => $grp_id |
|
| 412 | + ), |
|
| 413 | + 'preview_message' => array( |
|
| 414 | + 'func' => '_preview_message', |
|
| 415 | + 'capability' => 'ee_read_message', |
|
| 416 | + 'obj_id' => $grp_id, |
|
| 417 | + 'noheader' => true, |
|
| 418 | + 'headers_sent_route' => 'display_preview_message' |
|
| 419 | + ), |
|
| 420 | + 'display_preview_message' => array( |
|
| 421 | + 'func' => '_display_preview_message', |
|
| 422 | + 'capability' => 'ee_read_message', |
|
| 423 | + 'obj_id' => $grp_id |
|
| 424 | + ), |
|
| 425 | + 'insert_message_template' => array( |
|
| 426 | + 'func' => '_insert_or_update_message_template', |
|
| 427 | + 'capability' => 'ee_edit_messages', |
|
| 428 | + 'args' => array('new_template' => true), |
|
| 429 | + 'noheader' => true |
|
| 430 | + ), |
|
| 431 | + 'update_message_template' => array( |
|
| 432 | + 'func' => '_insert_or_update_message_template', |
|
| 433 | + 'capability' => 'ee_edit_message', |
|
| 434 | + 'obj_id' => $grp_id, |
|
| 435 | + 'args' => array('new_template' => false), |
|
| 436 | + 'noheader' => true |
|
| 437 | + ), |
|
| 438 | + 'trash_message_template' => array( |
|
| 439 | + 'func' => '_trash_or_restore_message_template', |
|
| 440 | + 'capability' => 'ee_delete_message', |
|
| 441 | + 'obj_id' => $grp_id, |
|
| 442 | + 'args' => array('trash' => true, 'all' => true), |
|
| 443 | + 'noheader' => true |
|
| 444 | + ), |
|
| 445 | + 'trash_message_template_context' => array( |
|
| 446 | + 'func' => '_trash_or_restore_message_template', |
|
| 447 | + 'capability' => 'ee_delete_message', |
|
| 448 | + 'obj_id' => $grp_id, |
|
| 449 | + 'args' => array('trash' => true), |
|
| 450 | + 'noheader' => true |
|
| 451 | + ), |
|
| 452 | + 'restore_message_template' => array( |
|
| 453 | + 'func' => '_trash_or_restore_message_template', |
|
| 454 | + 'capability' => 'ee_delete_message', |
|
| 455 | + 'obj_id' => $grp_id, |
|
| 456 | + 'args' => array('trash' => false, 'all' => true), |
|
| 457 | + 'noheader' => true |
|
| 458 | + ), |
|
| 459 | + 'restore_message_template_context' => array( |
|
| 460 | + 'func' => '_trash_or_restore_message_template', |
|
| 461 | + 'capability' => 'ee_delete_message', |
|
| 462 | + 'obj_id' => $grp_id, |
|
| 463 | + 'args' => array('trash' => false), |
|
| 464 | + 'noheader' => true |
|
| 465 | + ), |
|
| 466 | + 'delete_message_template' => array( |
|
| 467 | + 'func' => '_delete_message_template', |
|
| 468 | + 'capability' => 'ee_delete_message', |
|
| 469 | + 'obj_id' => $grp_id, |
|
| 470 | + 'noheader' => true |
|
| 471 | + ), |
|
| 472 | + 'reset_to_default' => array( |
|
| 473 | + 'func' => '_reset_to_default_template', |
|
| 474 | + 'capability' => 'ee_edit_message', |
|
| 475 | + 'obj_id' => $grp_id, |
|
| 476 | + 'noheader' => true |
|
| 477 | + ), |
|
| 478 | + 'settings' => array( |
|
| 479 | + 'func' => '_settings', |
|
| 480 | + 'capability' => 'manage_options' |
|
| 481 | + ), |
|
| 482 | + 'update_global_settings' => array( |
|
| 483 | + 'func' => '_update_global_settings', |
|
| 484 | + 'capability' => 'manage_options', |
|
| 485 | + 'noheader' => true |
|
| 486 | + ), |
|
| 487 | + 'generate_now' => array( |
|
| 488 | + 'func' => '_generate_now', |
|
| 489 | + 'capability' => 'ee_send_message', |
|
| 490 | + 'noheader' => true |
|
| 491 | + ), |
|
| 492 | + 'generate_and_send_now' => array( |
|
| 493 | + 'func' => '_generate_and_send_now', |
|
| 494 | + 'capability' => 'ee_send_message', |
|
| 495 | + 'noheader' => true |
|
| 496 | + ), |
|
| 497 | + 'queue_for_resending' => array( |
|
| 498 | + 'func' => '_queue_for_resending', |
|
| 499 | + 'capability' => 'ee_send_message', |
|
| 500 | + 'noheader' => true |
|
| 501 | + ), |
|
| 502 | + 'send_now' => array( |
|
| 503 | + 'func' => '_send_now', |
|
| 504 | + 'capability' => 'ee_send_message', |
|
| 505 | + 'noheader' => true |
|
| 506 | + ), |
|
| 507 | + 'delete_ee_message' => array( |
|
| 508 | + 'func' => '_delete_ee_messages', |
|
| 509 | + 'capability' => 'ee_delete_messages', |
|
| 510 | + 'noheader' => true |
|
| 511 | + ), |
|
| 512 | + 'delete_ee_messages' => array( |
|
| 513 | + 'func' => '_delete_ee_messages', |
|
| 514 | + 'capability' => 'ee_delete_messages', |
|
| 515 | + 'noheader' => true, |
|
| 516 | + 'obj_id' => $msg_id |
|
| 517 | + ) |
|
| 518 | + ); |
|
| 519 | + } |
|
| 520 | 520 | |
| 521 | 521 | |
| 522 | - protected function _set_page_config() |
|
| 523 | - { |
|
| 524 | - $this->_page_config = array( |
|
| 525 | - 'default' => array( |
|
| 526 | - 'nav' => array( |
|
| 527 | - 'label' => esc_html__('Message Activity', 'event_espresso'), |
|
| 528 | - 'order' => 10 |
|
| 529 | - ), |
|
| 530 | - 'list_table' => 'EE_Message_List_Table', |
|
| 531 | - // 'qtips' => array( 'EE_Message_List_Table_Tips' ), |
|
| 532 | - 'require_nonce' => false |
|
| 533 | - ), |
|
| 534 | - 'global_mtps' => array( |
|
| 535 | - 'nav' => array( |
|
| 536 | - 'label' => esc_html__('Default Message Templates', 'event_espresso'), |
|
| 537 | - 'order' => 20 |
|
| 538 | - ), |
|
| 539 | - 'list_table' => 'Messages_Template_List_Table', |
|
| 540 | - 'help_tabs' => array( |
|
| 541 | - 'messages_overview_help_tab' => array( |
|
| 542 | - 'title' => esc_html__('Messages Overview', 'event_espresso'), |
|
| 543 | - 'filename' => 'messages_overview' |
|
| 544 | - ), |
|
| 545 | - 'messages_overview_messages_table_column_headings_help_tab' => array( |
|
| 546 | - 'title' => esc_html__('Messages Table Column Headings', 'event_espresso'), |
|
| 547 | - 'filename' => 'messages_overview_table_column_headings' |
|
| 548 | - ), |
|
| 549 | - 'messages_overview_messages_filters_help_tab' => array( |
|
| 550 | - 'title' => esc_html__('Message Filters', 'event_espresso'), |
|
| 551 | - 'filename' => 'messages_overview_filters' |
|
| 552 | - ), |
|
| 553 | - 'messages_overview_messages_views_help_tab' => array( |
|
| 554 | - 'title' => esc_html__('Message Views', 'event_espresso'), |
|
| 555 | - 'filename' => 'messages_overview_views' |
|
| 556 | - ), |
|
| 557 | - 'message_overview_message_types_help_tab' => array( |
|
| 558 | - 'title' => esc_html__('Message Types', 'event_espresso'), |
|
| 559 | - 'filename' => 'messages_overview_types' |
|
| 560 | - ), |
|
| 561 | - 'messages_overview_messengers_help_tab' => array( |
|
| 562 | - 'title' => esc_html__('Messengers', 'event_espresso'), |
|
| 563 | - 'filename' => 'messages_overview_messengers', |
|
| 564 | - ), |
|
| 565 | - ), |
|
| 566 | - 'help_tour' => array('Messages_Overview_Help_Tour'), |
|
| 567 | - 'require_nonce' => false |
|
| 568 | - ), |
|
| 569 | - 'custom_mtps' => array( |
|
| 570 | - 'nav' => array( |
|
| 571 | - 'label' => esc_html__('Custom Message Templates', 'event_espresso'), |
|
| 572 | - 'order' => 30 |
|
| 573 | - ), |
|
| 574 | - 'help_tabs' => array(), |
|
| 575 | - 'help_tour' => array(), |
|
| 576 | - 'require_nonce' => false |
|
| 577 | - ), |
|
| 578 | - 'add_new_message_template' => array( |
|
| 579 | - 'nav' => array( |
|
| 580 | - 'label' => esc_html__('Add New Message Templates', 'event_espresso'), |
|
| 581 | - 'order' => 5, |
|
| 582 | - 'persistent' => false |
|
| 583 | - ), |
|
| 584 | - 'require_nonce' => false |
|
| 585 | - ), |
|
| 586 | - 'edit_message_template' => array( |
|
| 587 | - 'labels' => array( |
|
| 588 | - 'buttons' => array( |
|
| 589 | - 'reset' => esc_html__('Reset Templates'), |
|
| 590 | - ), |
|
| 591 | - 'publishbox' => esc_html__('Update Actions', 'event_espresso') |
|
| 592 | - ), |
|
| 593 | - 'nav' => array( |
|
| 594 | - 'label' => esc_html__('Edit Message Templates', 'event_espresso'), |
|
| 595 | - 'order' => 5, |
|
| 596 | - 'persistent' => false, |
|
| 597 | - 'url' => '' |
|
| 598 | - ), |
|
| 599 | - 'metaboxes' => array('_publish_post_box', '_register_edit_meta_boxes'), |
|
| 600 | - 'has_metaboxes' => true, |
|
| 601 | - 'help_tour' => array('Message_Templates_Edit_Help_Tour'), |
|
| 602 | - 'help_tabs' => array( |
|
| 603 | - 'edit_message_template' => array( |
|
| 604 | - 'title' => esc_html__('Message Template Editor', 'event_espresso'), |
|
| 605 | - 'callback' => 'edit_message_template_help_tab' |
|
| 606 | - ), |
|
| 607 | - 'message_templates_help_tab' => array( |
|
| 608 | - 'title' => esc_html__('Message Templates', 'event_espresso'), |
|
| 609 | - 'filename' => 'messages_templates' |
|
| 610 | - ), |
|
| 611 | - 'message_template_shortcodes' => array( |
|
| 612 | - 'title' => esc_html__('Message Shortcodes', 'event_espresso'), |
|
| 613 | - 'callback' => 'message_template_shortcodes_help_tab' |
|
| 614 | - ), |
|
| 615 | - 'message_preview_help_tab' => array( |
|
| 616 | - 'title' => esc_html__('Message Preview', 'event_espresso'), |
|
| 617 | - 'filename' => 'messages_preview' |
|
| 618 | - ), |
|
| 619 | - 'messages_overview_other_help_tab' => array( |
|
| 620 | - 'title' => esc_html__('Messages Other', 'event_espresso'), |
|
| 621 | - 'filename' => 'messages_overview_other', |
|
| 622 | - ), |
|
| 623 | - ), |
|
| 624 | - 'require_nonce' => false |
|
| 625 | - ), |
|
| 626 | - 'display_preview_message' => array( |
|
| 627 | - 'nav' => array( |
|
| 628 | - 'label' => esc_html__('Message Preview', 'event_espresso'), |
|
| 629 | - 'order' => 5, |
|
| 630 | - 'url' => '', |
|
| 631 | - 'persistent' => false |
|
| 632 | - ), |
|
| 633 | - 'help_tabs' => array( |
|
| 634 | - 'preview_message' => array( |
|
| 635 | - 'title' => esc_html__('About Previews', 'event_espresso'), |
|
| 636 | - 'callback' => 'preview_message_help_tab' |
|
| 637 | - ) |
|
| 638 | - ), |
|
| 639 | - 'require_nonce' => false |
|
| 640 | - ), |
|
| 641 | - 'settings' => array( |
|
| 642 | - 'nav' => array( |
|
| 643 | - 'label' => esc_html__('Settings', 'event_espresso'), |
|
| 644 | - 'order' => 40 |
|
| 645 | - ), |
|
| 646 | - 'metaboxes' => array('_messages_settings_metaboxes'), |
|
| 647 | - 'help_tabs' => array( |
|
| 648 | - 'messages_settings_help_tab' => array( |
|
| 649 | - 'title' => esc_html__('Messages Settings', 'event_espresso'), |
|
| 650 | - 'filename' => 'messages_settings' |
|
| 651 | - ), |
|
| 652 | - 'messages_settings_message_types_help_tab' => array( |
|
| 653 | - 'title' => esc_html__('Activating / Deactivating Message Types', 'event_espresso'), |
|
| 654 | - 'filename' => 'messages_settings_message_types' |
|
| 655 | - ), |
|
| 656 | - 'messages_settings_messengers_help_tab' => array( |
|
| 657 | - 'title' => esc_html__('Activating / Deactivating Messengers', 'event_espresso'), |
|
| 658 | - 'filename' => 'messages_settings_messengers' |
|
| 659 | - ), |
|
| 660 | - ), |
|
| 661 | - 'help_tour' => array('Messages_Settings_Help_Tour'), |
|
| 662 | - 'require_nonce' => false |
|
| 663 | - ) |
|
| 664 | - ); |
|
| 665 | - } |
|
| 522 | + protected function _set_page_config() |
|
| 523 | + { |
|
| 524 | + $this->_page_config = array( |
|
| 525 | + 'default' => array( |
|
| 526 | + 'nav' => array( |
|
| 527 | + 'label' => esc_html__('Message Activity', 'event_espresso'), |
|
| 528 | + 'order' => 10 |
|
| 529 | + ), |
|
| 530 | + 'list_table' => 'EE_Message_List_Table', |
|
| 531 | + // 'qtips' => array( 'EE_Message_List_Table_Tips' ), |
|
| 532 | + 'require_nonce' => false |
|
| 533 | + ), |
|
| 534 | + 'global_mtps' => array( |
|
| 535 | + 'nav' => array( |
|
| 536 | + 'label' => esc_html__('Default Message Templates', 'event_espresso'), |
|
| 537 | + 'order' => 20 |
|
| 538 | + ), |
|
| 539 | + 'list_table' => 'Messages_Template_List_Table', |
|
| 540 | + 'help_tabs' => array( |
|
| 541 | + 'messages_overview_help_tab' => array( |
|
| 542 | + 'title' => esc_html__('Messages Overview', 'event_espresso'), |
|
| 543 | + 'filename' => 'messages_overview' |
|
| 544 | + ), |
|
| 545 | + 'messages_overview_messages_table_column_headings_help_tab' => array( |
|
| 546 | + 'title' => esc_html__('Messages Table Column Headings', 'event_espresso'), |
|
| 547 | + 'filename' => 'messages_overview_table_column_headings' |
|
| 548 | + ), |
|
| 549 | + 'messages_overview_messages_filters_help_tab' => array( |
|
| 550 | + 'title' => esc_html__('Message Filters', 'event_espresso'), |
|
| 551 | + 'filename' => 'messages_overview_filters' |
|
| 552 | + ), |
|
| 553 | + 'messages_overview_messages_views_help_tab' => array( |
|
| 554 | + 'title' => esc_html__('Message Views', 'event_espresso'), |
|
| 555 | + 'filename' => 'messages_overview_views' |
|
| 556 | + ), |
|
| 557 | + 'message_overview_message_types_help_tab' => array( |
|
| 558 | + 'title' => esc_html__('Message Types', 'event_espresso'), |
|
| 559 | + 'filename' => 'messages_overview_types' |
|
| 560 | + ), |
|
| 561 | + 'messages_overview_messengers_help_tab' => array( |
|
| 562 | + 'title' => esc_html__('Messengers', 'event_espresso'), |
|
| 563 | + 'filename' => 'messages_overview_messengers', |
|
| 564 | + ), |
|
| 565 | + ), |
|
| 566 | + 'help_tour' => array('Messages_Overview_Help_Tour'), |
|
| 567 | + 'require_nonce' => false |
|
| 568 | + ), |
|
| 569 | + 'custom_mtps' => array( |
|
| 570 | + 'nav' => array( |
|
| 571 | + 'label' => esc_html__('Custom Message Templates', 'event_espresso'), |
|
| 572 | + 'order' => 30 |
|
| 573 | + ), |
|
| 574 | + 'help_tabs' => array(), |
|
| 575 | + 'help_tour' => array(), |
|
| 576 | + 'require_nonce' => false |
|
| 577 | + ), |
|
| 578 | + 'add_new_message_template' => array( |
|
| 579 | + 'nav' => array( |
|
| 580 | + 'label' => esc_html__('Add New Message Templates', 'event_espresso'), |
|
| 581 | + 'order' => 5, |
|
| 582 | + 'persistent' => false |
|
| 583 | + ), |
|
| 584 | + 'require_nonce' => false |
|
| 585 | + ), |
|
| 586 | + 'edit_message_template' => array( |
|
| 587 | + 'labels' => array( |
|
| 588 | + 'buttons' => array( |
|
| 589 | + 'reset' => esc_html__('Reset Templates'), |
|
| 590 | + ), |
|
| 591 | + 'publishbox' => esc_html__('Update Actions', 'event_espresso') |
|
| 592 | + ), |
|
| 593 | + 'nav' => array( |
|
| 594 | + 'label' => esc_html__('Edit Message Templates', 'event_espresso'), |
|
| 595 | + 'order' => 5, |
|
| 596 | + 'persistent' => false, |
|
| 597 | + 'url' => '' |
|
| 598 | + ), |
|
| 599 | + 'metaboxes' => array('_publish_post_box', '_register_edit_meta_boxes'), |
|
| 600 | + 'has_metaboxes' => true, |
|
| 601 | + 'help_tour' => array('Message_Templates_Edit_Help_Tour'), |
|
| 602 | + 'help_tabs' => array( |
|
| 603 | + 'edit_message_template' => array( |
|
| 604 | + 'title' => esc_html__('Message Template Editor', 'event_espresso'), |
|
| 605 | + 'callback' => 'edit_message_template_help_tab' |
|
| 606 | + ), |
|
| 607 | + 'message_templates_help_tab' => array( |
|
| 608 | + 'title' => esc_html__('Message Templates', 'event_espresso'), |
|
| 609 | + 'filename' => 'messages_templates' |
|
| 610 | + ), |
|
| 611 | + 'message_template_shortcodes' => array( |
|
| 612 | + 'title' => esc_html__('Message Shortcodes', 'event_espresso'), |
|
| 613 | + 'callback' => 'message_template_shortcodes_help_tab' |
|
| 614 | + ), |
|
| 615 | + 'message_preview_help_tab' => array( |
|
| 616 | + 'title' => esc_html__('Message Preview', 'event_espresso'), |
|
| 617 | + 'filename' => 'messages_preview' |
|
| 618 | + ), |
|
| 619 | + 'messages_overview_other_help_tab' => array( |
|
| 620 | + 'title' => esc_html__('Messages Other', 'event_espresso'), |
|
| 621 | + 'filename' => 'messages_overview_other', |
|
| 622 | + ), |
|
| 623 | + ), |
|
| 624 | + 'require_nonce' => false |
|
| 625 | + ), |
|
| 626 | + 'display_preview_message' => array( |
|
| 627 | + 'nav' => array( |
|
| 628 | + 'label' => esc_html__('Message Preview', 'event_espresso'), |
|
| 629 | + 'order' => 5, |
|
| 630 | + 'url' => '', |
|
| 631 | + 'persistent' => false |
|
| 632 | + ), |
|
| 633 | + 'help_tabs' => array( |
|
| 634 | + 'preview_message' => array( |
|
| 635 | + 'title' => esc_html__('About Previews', 'event_espresso'), |
|
| 636 | + 'callback' => 'preview_message_help_tab' |
|
| 637 | + ) |
|
| 638 | + ), |
|
| 639 | + 'require_nonce' => false |
|
| 640 | + ), |
|
| 641 | + 'settings' => array( |
|
| 642 | + 'nav' => array( |
|
| 643 | + 'label' => esc_html__('Settings', 'event_espresso'), |
|
| 644 | + 'order' => 40 |
|
| 645 | + ), |
|
| 646 | + 'metaboxes' => array('_messages_settings_metaboxes'), |
|
| 647 | + 'help_tabs' => array( |
|
| 648 | + 'messages_settings_help_tab' => array( |
|
| 649 | + 'title' => esc_html__('Messages Settings', 'event_espresso'), |
|
| 650 | + 'filename' => 'messages_settings' |
|
| 651 | + ), |
|
| 652 | + 'messages_settings_message_types_help_tab' => array( |
|
| 653 | + 'title' => esc_html__('Activating / Deactivating Message Types', 'event_espresso'), |
|
| 654 | + 'filename' => 'messages_settings_message_types' |
|
| 655 | + ), |
|
| 656 | + 'messages_settings_messengers_help_tab' => array( |
|
| 657 | + 'title' => esc_html__('Activating / Deactivating Messengers', 'event_espresso'), |
|
| 658 | + 'filename' => 'messages_settings_messengers' |
|
| 659 | + ), |
|
| 660 | + ), |
|
| 661 | + 'help_tour' => array('Messages_Settings_Help_Tour'), |
|
| 662 | + 'require_nonce' => false |
|
| 663 | + ) |
|
| 664 | + ); |
|
| 665 | + } |
|
| 666 | 666 | |
| 667 | 667 | |
| 668 | - protected function _add_screen_options() |
|
| 669 | - { |
|
| 670 | - //todo |
|
| 671 | - } |
|
| 668 | + protected function _add_screen_options() |
|
| 669 | + { |
|
| 670 | + //todo |
|
| 671 | + } |
|
| 672 | 672 | |
| 673 | 673 | |
| 674 | - protected function _add_screen_options_global_mtps() |
|
| 675 | - { |
|
| 676 | - /** |
|
| 677 | - * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options |
|
| 678 | - * uses the $_admin_page_title property and we want different outputs in the different spots. |
|
| 679 | - */ |
|
| 680 | - $page_title = $this->_admin_page_title; |
|
| 681 | - $this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso'); |
|
| 682 | - $this->_per_page_screen_option(); |
|
| 683 | - $this->_admin_page_title = $page_title; |
|
| 684 | - } |
|
| 674 | + protected function _add_screen_options_global_mtps() |
|
| 675 | + { |
|
| 676 | + /** |
|
| 677 | + * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options |
|
| 678 | + * uses the $_admin_page_title property and we want different outputs in the different spots. |
|
| 679 | + */ |
|
| 680 | + $page_title = $this->_admin_page_title; |
|
| 681 | + $this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso'); |
|
| 682 | + $this->_per_page_screen_option(); |
|
| 683 | + $this->_admin_page_title = $page_title; |
|
| 684 | + } |
|
| 685 | 685 | |
| 686 | 686 | |
| 687 | - protected function _add_screen_options_default() |
|
| 688 | - { |
|
| 689 | - $this->_admin_page_title = esc_html__('Message Activity', 'event_espresso'); |
|
| 690 | - $this->_per_page_screen_option(); |
|
| 691 | - } |
|
| 687 | + protected function _add_screen_options_default() |
|
| 688 | + { |
|
| 689 | + $this->_admin_page_title = esc_html__('Message Activity', 'event_espresso'); |
|
| 690 | + $this->_per_page_screen_option(); |
|
| 691 | + } |
|
| 692 | 692 | |
| 693 | 693 | |
| 694 | - //none of the below group are currently used for Messages |
|
| 695 | - protected function _add_feature_pointers() |
|
| 696 | - { |
|
| 697 | - } |
|
| 694 | + //none of the below group are currently used for Messages |
|
| 695 | + protected function _add_feature_pointers() |
|
| 696 | + { |
|
| 697 | + } |
|
| 698 | 698 | |
| 699 | - public function admin_init() |
|
| 700 | - { |
|
| 701 | - } |
|
| 699 | + public function admin_init() |
|
| 700 | + { |
|
| 701 | + } |
|
| 702 | 702 | |
| 703 | - public function admin_notices() |
|
| 704 | - { |
|
| 705 | - } |
|
| 703 | + public function admin_notices() |
|
| 704 | + { |
|
| 705 | + } |
|
| 706 | 706 | |
| 707 | - public function admin_footer_scripts() |
|
| 708 | - { |
|
| 709 | - } |
|
| 707 | + public function admin_footer_scripts() |
|
| 708 | + { |
|
| 709 | + } |
|
| 710 | 710 | |
| 711 | 711 | |
| 712 | - public function messages_help_tab() |
|
| 713 | - { |
|
| 714 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php'); |
|
| 715 | - } |
|
| 712 | + public function messages_help_tab() |
|
| 713 | + { |
|
| 714 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php'); |
|
| 715 | + } |
|
| 716 | 716 | |
| 717 | 717 | |
| 718 | - public function messengers_help_tab() |
|
| 719 | - { |
|
| 720 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php'); |
|
| 721 | - } |
|
| 718 | + public function messengers_help_tab() |
|
| 719 | + { |
|
| 720 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php'); |
|
| 721 | + } |
|
| 722 | 722 | |
| 723 | 723 | |
| 724 | - public function message_types_help_tab() |
|
| 725 | - { |
|
| 726 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php'); |
|
| 727 | - } |
|
| 724 | + public function message_types_help_tab() |
|
| 725 | + { |
|
| 726 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php'); |
|
| 727 | + } |
|
| 728 | 728 | |
| 729 | 729 | |
| 730 | - public function messages_overview_help_tab() |
|
| 731 | - { |
|
| 732 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php'); |
|
| 733 | - } |
|
| 730 | + public function messages_overview_help_tab() |
|
| 731 | + { |
|
| 732 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php'); |
|
| 733 | + } |
|
| 734 | 734 | |
| 735 | 735 | |
| 736 | - public function message_templates_help_tab() |
|
| 737 | - { |
|
| 738 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php'); |
|
| 739 | - } |
|
| 736 | + public function message_templates_help_tab() |
|
| 737 | + { |
|
| 738 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php'); |
|
| 739 | + } |
|
| 740 | 740 | |
| 741 | 741 | |
| 742 | - public function edit_message_template_help_tab() |
|
| 743 | - { |
|
| 744 | - $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="' |
|
| 745 | - . esc_attr__('Editor Title', 'event_espresso') |
|
| 746 | - . '" />'; |
|
| 747 | - $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="' |
|
| 748 | - . esc_attr__('Context Switcher and Preview', 'event_espresso') |
|
| 749 | - . '" />'; |
|
| 750 | - $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="' |
|
| 751 | - . esc_attr__('Message Template Form Fields', 'event_espresso') |
|
| 752 | - . '" />'; |
|
| 753 | - $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="' |
|
| 754 | - . esc_attr__('Shortcodes Metabox', 'event_espresso') |
|
| 755 | - . '" />'; |
|
| 756 | - $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="' |
|
| 757 | - . esc_attr__('Publish Metabox', 'event_espresso') |
|
| 758 | - . '" />'; |
|
| 759 | - EEH_Template::display_template( |
|
| 760 | - EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php', |
|
| 761 | - $args |
|
| 762 | - ); |
|
| 763 | - } |
|
| 742 | + public function edit_message_template_help_tab() |
|
| 743 | + { |
|
| 744 | + $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="' |
|
| 745 | + . esc_attr__('Editor Title', 'event_espresso') |
|
| 746 | + . '" />'; |
|
| 747 | + $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="' |
|
| 748 | + . esc_attr__('Context Switcher and Preview', 'event_espresso') |
|
| 749 | + . '" />'; |
|
| 750 | + $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="' |
|
| 751 | + . esc_attr__('Message Template Form Fields', 'event_espresso') |
|
| 752 | + . '" />'; |
|
| 753 | + $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="' |
|
| 754 | + . esc_attr__('Shortcodes Metabox', 'event_espresso') |
|
| 755 | + . '" />'; |
|
| 756 | + $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="' |
|
| 757 | + . esc_attr__('Publish Metabox', 'event_espresso') |
|
| 758 | + . '" />'; |
|
| 759 | + EEH_Template::display_template( |
|
| 760 | + EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php', |
|
| 761 | + $args |
|
| 762 | + ); |
|
| 763 | + } |
|
| 764 | 764 | |
| 765 | 765 | |
| 766 | - public function message_template_shortcodes_help_tab() |
|
| 767 | - { |
|
| 768 | - $this->_set_shortcodes(); |
|
| 769 | - $args['shortcodes'] = $this->_shortcodes; |
|
| 770 | - EEH_Template::display_template( |
|
| 771 | - EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php', |
|
| 772 | - $args |
|
| 773 | - ); |
|
| 774 | - } |
|
| 766 | + public function message_template_shortcodes_help_tab() |
|
| 767 | + { |
|
| 768 | + $this->_set_shortcodes(); |
|
| 769 | + $args['shortcodes'] = $this->_shortcodes; |
|
| 770 | + EEH_Template::display_template( |
|
| 771 | + EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php', |
|
| 772 | + $args |
|
| 773 | + ); |
|
| 774 | + } |
|
| 775 | 775 | |
| 776 | 776 | |
| 777 | - public function preview_message_help_tab() |
|
| 778 | - { |
|
| 779 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php'); |
|
| 780 | - } |
|
| 777 | + public function preview_message_help_tab() |
|
| 778 | + { |
|
| 779 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php'); |
|
| 780 | + } |
|
| 781 | 781 | |
| 782 | 782 | |
| 783 | - public function settings_help_tab() |
|
| 784 | - { |
|
| 785 | - $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' |
|
| 786 | - . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />'; |
|
| 787 | - $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' |
|
| 788 | - . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />'; |
|
| 789 | - $args['img3'] = '<div class="switch">' |
|
| 790 | - . '<input class="ee-on-off-toggle ee-toggle-round-flat"' |
|
| 791 | - . ' type="checkbox" checked="checked">' |
|
| 792 | - . '<label for="ee-on-off-toggle-on"></label>' |
|
| 793 | - . '</div>'; |
|
| 794 | - $args['img4'] = '<div class="switch">' |
|
| 795 | - . '<input class="ee-on-off-toggle ee-toggle-round-flat"' |
|
| 796 | - . ' type="checkbox">' |
|
| 797 | - . '<label for="ee-on-off-toggle-on"></label>' |
|
| 798 | - . '</div>'; |
|
| 799 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args); |
|
| 800 | - } |
|
| 783 | + public function settings_help_tab() |
|
| 784 | + { |
|
| 785 | + $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' |
|
| 786 | + . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />'; |
|
| 787 | + $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' |
|
| 788 | + . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />'; |
|
| 789 | + $args['img3'] = '<div class="switch">' |
|
| 790 | + . '<input class="ee-on-off-toggle ee-toggle-round-flat"' |
|
| 791 | + . ' type="checkbox" checked="checked">' |
|
| 792 | + . '<label for="ee-on-off-toggle-on"></label>' |
|
| 793 | + . '</div>'; |
|
| 794 | + $args['img4'] = '<div class="switch">' |
|
| 795 | + . '<input class="ee-on-off-toggle ee-toggle-round-flat"' |
|
| 796 | + . ' type="checkbox">' |
|
| 797 | + . '<label for="ee-on-off-toggle-on"></label>' |
|
| 798 | + . '</div>'; |
|
| 799 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args); |
|
| 800 | + } |
|
| 801 | 801 | |
| 802 | 802 | |
| 803 | - public function load_scripts_styles() |
|
| 804 | - { |
|
| 805 | - wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION); |
|
| 806 | - wp_enqueue_style('espresso_ee_msg'); |
|
| 807 | - |
|
| 808 | - wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js', |
|
| 809 | - array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true); |
|
| 810 | - wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js', |
|
| 811 | - array('ee-dialog'), EVENT_ESPRESSO_VERSION); |
|
| 812 | - } |
|
| 803 | + public function load_scripts_styles() |
|
| 804 | + { |
|
| 805 | + wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION); |
|
| 806 | + wp_enqueue_style('espresso_ee_msg'); |
|
| 807 | + |
|
| 808 | + wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js', |
|
| 809 | + array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true); |
|
| 810 | + wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js', |
|
| 811 | + array('ee-dialog'), EVENT_ESPRESSO_VERSION); |
|
| 812 | + } |
|
| 813 | 813 | |
| 814 | 814 | |
| 815 | - public function load_scripts_styles_default() |
|
| 816 | - { |
|
| 817 | - wp_enqueue_script('ee-msg-list-table-js'); |
|
| 818 | - } |
|
| 815 | + public function load_scripts_styles_default() |
|
| 816 | + { |
|
| 817 | + wp_enqueue_script('ee-msg-list-table-js'); |
|
| 818 | + } |
|
| 819 | 819 | |
| 820 | 820 | |
| 821 | - public function wp_editor_css($mce_css) |
|
| 822 | - { |
|
| 823 | - //if we're on the edit_message_template route |
|
| 824 | - if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) { |
|
| 825 | - $message_type_name = $this->_active_message_type_name; |
|
| 821 | + public function wp_editor_css($mce_css) |
|
| 822 | + { |
|
| 823 | + //if we're on the edit_message_template route |
|
| 824 | + if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) { |
|
| 825 | + $message_type_name = $this->_active_message_type_name; |
|
| 826 | 826 | |
| 827 | - //we're going to REPLACE the existing mce css |
|
| 828 | - //we need to get the css file location from the active messenger |
|
| 829 | - $mce_css = $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true, |
|
| 830 | - 'wpeditor', $this->_variation); |
|
| 831 | - } |
|
| 832 | - |
|
| 833 | - return $mce_css; |
|
| 834 | - } |
|
| 827 | + //we're going to REPLACE the existing mce css |
|
| 828 | + //we need to get the css file location from the active messenger |
|
| 829 | + $mce_css = $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true, |
|
| 830 | + 'wpeditor', $this->_variation); |
|
| 831 | + } |
|
| 832 | + |
|
| 833 | + return $mce_css; |
|
| 834 | + } |
|
| 835 | 835 | |
| 836 | 836 | |
| 837 | - public function load_scripts_styles_edit_message_template() |
|
| 838 | - { |
|
| 839 | - |
|
| 840 | - $this->_set_shortcodes(); |
|
| 841 | - |
|
| 842 | - EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf( |
|
| 843 | - esc_html__( |
|
| 844 | - 'Are you sure you want to reset the %s %s message templates? Remember continuing will reset the templates for all contexts in this messenger and message type group.', |
|
| 845 | - 'event_espresso' |
|
| 846 | - ), |
|
| 847 | - $this->_message_template_group->messenger_obj()->label['singular'], |
|
| 848 | - $this->_message_template_group->message_type_obj()->label['singular'] |
|
| 849 | - ); |
|
| 850 | - EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__( |
|
| 851 | - 'Switching the template pack for a messages template will reset the content for the template so the new layout is loaded. Any custom content in the existing template will be lost. Are you sure you wish to do this?', |
|
| 852 | - 'event_espresso' |
|
| 853 | - ); |
|
| 854 | - EE_Registry::$i18n_js_strings['server_error'] = esc_html__( |
|
| 855 | - 'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.', |
|
| 856 | - 'event_espresso' |
|
| 857 | - ); |
|
| 858 | - |
|
| 859 | - wp_register_script( |
|
| 860 | - 'ee_msgs_edit_js', |
|
| 861 | - EE_MSG_ASSETS_URL . 'ee_message_editor.js', |
|
| 862 | - array('jquery'), |
|
| 863 | - EVENT_ESPRESSO_VERSION |
|
| 864 | - ); |
|
| 865 | - |
|
| 866 | - wp_enqueue_script('ee_admin_js'); |
|
| 867 | - wp_enqueue_script('ee_msgs_edit_js'); |
|
| 868 | - |
|
| 869 | - //add in special css for tiny_mce |
|
| 870 | - add_filter('mce_css', array($this, 'wp_editor_css')); |
|
| 871 | - } |
|
| 837 | + public function load_scripts_styles_edit_message_template() |
|
| 838 | + { |
|
| 839 | + |
|
| 840 | + $this->_set_shortcodes(); |
|
| 841 | + |
|
| 842 | + EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf( |
|
| 843 | + esc_html__( |
|
| 844 | + 'Are you sure you want to reset the %s %s message templates? Remember continuing will reset the templates for all contexts in this messenger and message type group.', |
|
| 845 | + 'event_espresso' |
|
| 846 | + ), |
|
| 847 | + $this->_message_template_group->messenger_obj()->label['singular'], |
|
| 848 | + $this->_message_template_group->message_type_obj()->label['singular'] |
|
| 849 | + ); |
|
| 850 | + EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__( |
|
| 851 | + 'Switching the template pack for a messages template will reset the content for the template so the new layout is loaded. Any custom content in the existing template will be lost. Are you sure you wish to do this?', |
|
| 852 | + 'event_espresso' |
|
| 853 | + ); |
|
| 854 | + EE_Registry::$i18n_js_strings['server_error'] = esc_html__( |
|
| 855 | + 'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.', |
|
| 856 | + 'event_espresso' |
|
| 857 | + ); |
|
| 858 | + |
|
| 859 | + wp_register_script( |
|
| 860 | + 'ee_msgs_edit_js', |
|
| 861 | + EE_MSG_ASSETS_URL . 'ee_message_editor.js', |
|
| 862 | + array('jquery'), |
|
| 863 | + EVENT_ESPRESSO_VERSION |
|
| 864 | + ); |
|
| 865 | + |
|
| 866 | + wp_enqueue_script('ee_admin_js'); |
|
| 867 | + wp_enqueue_script('ee_msgs_edit_js'); |
|
| 868 | + |
|
| 869 | + //add in special css for tiny_mce |
|
| 870 | + add_filter('mce_css', array($this, 'wp_editor_css')); |
|
| 871 | + } |
|
| 872 | 872 | |
| 873 | 873 | |
| 874 | - public function load_scripts_styles_display_preview_message() |
|
| 875 | - { |
|
| 876 | - |
|
| 877 | - $this->_set_message_template_group(); |
|
| 878 | - |
|
| 879 | - if (isset($this->_req_data['messenger'])) { |
|
| 880 | - $this->_active_messenger = $this->_message_resource_manager->get_active_messenger( |
|
| 881 | - $this->_req_data['messenger'] |
|
| 882 | - ); |
|
| 883 | - } |
|
| 884 | - |
|
| 885 | - $message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : ''; |
|
| 886 | - |
|
| 887 | - |
|
| 888 | - wp_enqueue_style('espresso_preview_css', |
|
| 889 | - $this->_active_messenger->get_variation( |
|
| 890 | - $this->_template_pack, |
|
| 891 | - $message_type_name, |
|
| 892 | - true, |
|
| 893 | - 'preview', |
|
| 894 | - $this->_variation |
|
| 895 | - ) |
|
| 896 | - ); |
|
| 897 | - } |
|
| 874 | + public function load_scripts_styles_display_preview_message() |
|
| 875 | + { |
|
| 876 | + |
|
| 877 | + $this->_set_message_template_group(); |
|
| 878 | + |
|
| 879 | + if (isset($this->_req_data['messenger'])) { |
|
| 880 | + $this->_active_messenger = $this->_message_resource_manager->get_active_messenger( |
|
| 881 | + $this->_req_data['messenger'] |
|
| 882 | + ); |
|
| 883 | + } |
|
| 884 | + |
|
| 885 | + $message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : ''; |
|
| 886 | + |
|
| 887 | + |
|
| 888 | + wp_enqueue_style('espresso_preview_css', |
|
| 889 | + $this->_active_messenger->get_variation( |
|
| 890 | + $this->_template_pack, |
|
| 891 | + $message_type_name, |
|
| 892 | + true, |
|
| 893 | + 'preview', |
|
| 894 | + $this->_variation |
|
| 895 | + ) |
|
| 896 | + ); |
|
| 897 | + } |
|
| 898 | 898 | |
| 899 | 899 | |
| 900 | - public function load_scripts_styles_settings() |
|
| 901 | - { |
|
| 902 | - wp_register_style( |
|
| 903 | - 'ee-message-settings', |
|
| 904 | - EE_MSG_ASSETS_URL . 'ee_message_settings.css', |
|
| 905 | - array(), |
|
| 906 | - EVENT_ESPRESSO_VERSION |
|
| 907 | - ); |
|
| 908 | - wp_enqueue_style('ee-text-links'); |
|
| 909 | - wp_enqueue_style('ee-message-settings'); |
|
| 910 | - wp_enqueue_script('ee-messages-settings'); |
|
| 911 | - } |
|
| 900 | + public function load_scripts_styles_settings() |
|
| 901 | + { |
|
| 902 | + wp_register_style( |
|
| 903 | + 'ee-message-settings', |
|
| 904 | + EE_MSG_ASSETS_URL . 'ee_message_settings.css', |
|
| 905 | + array(), |
|
| 906 | + EVENT_ESPRESSO_VERSION |
|
| 907 | + ); |
|
| 908 | + wp_enqueue_style('ee-text-links'); |
|
| 909 | + wp_enqueue_style('ee-message-settings'); |
|
| 910 | + wp_enqueue_script('ee-messages-settings'); |
|
| 911 | + } |
|
| 912 | 912 | |
| 913 | 913 | |
| 914 | - /** |
|
| 915 | - * set views array for List Table |
|
| 916 | - */ |
|
| 917 | - public function _set_list_table_views_global_mtps() |
|
| 918 | - { |
|
| 919 | - $this->_views = array( |
|
| 920 | - 'in_use' => array( |
|
| 921 | - 'slug' => 'in_use', |
|
| 922 | - 'label' => esc_html__('In Use', 'event_espresso'), |
|
| 923 | - 'count' => 0, |
|
| 924 | - ) |
|
| 925 | - ); |
|
| 926 | - } |
|
| 914 | + /** |
|
| 915 | + * set views array for List Table |
|
| 916 | + */ |
|
| 917 | + public function _set_list_table_views_global_mtps() |
|
| 918 | + { |
|
| 919 | + $this->_views = array( |
|
| 920 | + 'in_use' => array( |
|
| 921 | + 'slug' => 'in_use', |
|
| 922 | + 'label' => esc_html__('In Use', 'event_espresso'), |
|
| 923 | + 'count' => 0, |
|
| 924 | + ) |
|
| 925 | + ); |
|
| 926 | + } |
|
| 927 | 927 | |
| 928 | 928 | |
| 929 | - /** |
|
| 930 | - * Set views array for the Custom Template List Table |
|
| 931 | - */ |
|
| 932 | - public function _set_list_table_views_custom_mtps() |
|
| 933 | - { |
|
| 934 | - $this->_set_list_table_views_global_mtps(); |
|
| 935 | - $this->_views['in_use']['bulk_action'] = array( |
|
| 936 | - 'trash_message_template' => esc_html__('Move to Trash', 'event_espresso') |
|
| 937 | - ); |
|
| 938 | - } |
|
| 929 | + /** |
|
| 930 | + * Set views array for the Custom Template List Table |
|
| 931 | + */ |
|
| 932 | + public function _set_list_table_views_custom_mtps() |
|
| 933 | + { |
|
| 934 | + $this->_set_list_table_views_global_mtps(); |
|
| 935 | + $this->_views['in_use']['bulk_action'] = array( |
|
| 936 | + 'trash_message_template' => esc_html__('Move to Trash', 'event_espresso') |
|
| 937 | + ); |
|
| 938 | + } |
|
| 939 | 939 | |
| 940 | 940 | |
| 941 | - /** |
|
| 942 | - * set views array for message queue list table |
|
| 943 | - * |
|
| 944 | - * @throws InvalidDataTypeException |
|
| 945 | - * @throws InvalidInterfaceException |
|
| 946 | - * @throws InvalidArgumentException |
|
| 947 | - * @throws EE_Error |
|
| 948 | - * @throws ReflectionException |
|
| 949 | - */ |
|
| 950 | - public function _set_list_table_views_default() |
|
| 951 | - { |
|
| 952 | - EE_Registry::instance()->load_helper('Template'); |
|
| 953 | - |
|
| 954 | - $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can( |
|
| 955 | - 'ee_send_message', |
|
| 956 | - 'message_list_table_bulk_actions' |
|
| 957 | - ) |
|
| 958 | - ? array( |
|
| 959 | - 'generate_now' => esc_html__('Generate Now', 'event_espresso'), |
|
| 960 | - 'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'), |
|
| 961 | - 'queue_for_resending' => esc_html__('Queue for Resending', 'event_espresso'), |
|
| 962 | - 'send_now' => esc_html__('Send Now', 'event_espresso') |
|
| 963 | - ) |
|
| 964 | - : array(); |
|
| 965 | - |
|
| 966 | - $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can( |
|
| 967 | - 'ee_delete_messages', |
|
| 968 | - 'message_list_table_bulk_actions' |
|
| 969 | - ) |
|
| 970 | - ? array('delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso')) |
|
| 971 | - : array(); |
|
| 972 | - |
|
| 973 | - |
|
| 974 | - $this->_views = array( |
|
| 975 | - 'all' => array( |
|
| 976 | - 'slug' => 'all', |
|
| 977 | - 'label' => esc_html__('All', 'event_espresso'), |
|
| 978 | - 'count' => 0, |
|
| 979 | - 'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action) |
|
| 980 | - ) |
|
| 981 | - ); |
|
| 982 | - |
|
| 983 | - |
|
| 984 | - foreach (EEM_Message::instance()->all_statuses() as $status) { |
|
| 985 | - if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) { |
|
| 986 | - continue; |
|
| 987 | - } |
|
| 988 | - $status_bulk_actions = $common_bulk_actions; |
|
| 989 | - //unset bulk actions not applying to status |
|
| 990 | - if (! empty($status_bulk_actions)) { |
|
| 991 | - switch ($status) { |
|
| 992 | - case EEM_Message::status_idle: |
|
| 993 | - case EEM_Message::status_resend: |
|
| 994 | - $status_bulk_actions['send_now'] = $common_bulk_actions['send_now']; |
|
| 995 | - break; |
|
| 941 | + /** |
|
| 942 | + * set views array for message queue list table |
|
| 943 | + * |
|
| 944 | + * @throws InvalidDataTypeException |
|
| 945 | + * @throws InvalidInterfaceException |
|
| 946 | + * @throws InvalidArgumentException |
|
| 947 | + * @throws EE_Error |
|
| 948 | + * @throws ReflectionException |
|
| 949 | + */ |
|
| 950 | + public function _set_list_table_views_default() |
|
| 951 | + { |
|
| 952 | + EE_Registry::instance()->load_helper('Template'); |
|
| 953 | + |
|
| 954 | + $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can( |
|
| 955 | + 'ee_send_message', |
|
| 956 | + 'message_list_table_bulk_actions' |
|
| 957 | + ) |
|
| 958 | + ? array( |
|
| 959 | + 'generate_now' => esc_html__('Generate Now', 'event_espresso'), |
|
| 960 | + 'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'), |
|
| 961 | + 'queue_for_resending' => esc_html__('Queue for Resending', 'event_espresso'), |
|
| 962 | + 'send_now' => esc_html__('Send Now', 'event_espresso') |
|
| 963 | + ) |
|
| 964 | + : array(); |
|
| 965 | + |
|
| 966 | + $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can( |
|
| 967 | + 'ee_delete_messages', |
|
| 968 | + 'message_list_table_bulk_actions' |
|
| 969 | + ) |
|
| 970 | + ? array('delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso')) |
|
| 971 | + : array(); |
|
| 972 | + |
|
| 973 | + |
|
| 974 | + $this->_views = array( |
|
| 975 | + 'all' => array( |
|
| 976 | + 'slug' => 'all', |
|
| 977 | + 'label' => esc_html__('All', 'event_espresso'), |
|
| 978 | + 'count' => 0, |
|
| 979 | + 'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action) |
|
| 980 | + ) |
|
| 981 | + ); |
|
| 982 | + |
|
| 983 | + |
|
| 984 | + foreach (EEM_Message::instance()->all_statuses() as $status) { |
|
| 985 | + if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) { |
|
| 986 | + continue; |
|
| 987 | + } |
|
| 988 | + $status_bulk_actions = $common_bulk_actions; |
|
| 989 | + //unset bulk actions not applying to status |
|
| 990 | + if (! empty($status_bulk_actions)) { |
|
| 991 | + switch ($status) { |
|
| 992 | + case EEM_Message::status_idle: |
|
| 993 | + case EEM_Message::status_resend: |
|
| 994 | + $status_bulk_actions['send_now'] = $common_bulk_actions['send_now']; |
|
| 995 | + break; |
|
| 996 | 996 | |
| 997 | - case EEM_Message::status_failed: |
|
| 998 | - case EEM_Message::status_debug_only: |
|
| 999 | - case EEM_Message::status_messenger_executing: |
|
| 1000 | - $status_bulk_actions = array(); |
|
| 1001 | - break; |
|
| 997 | + case EEM_Message::status_failed: |
|
| 998 | + case EEM_Message::status_debug_only: |
|
| 999 | + case EEM_Message::status_messenger_executing: |
|
| 1000 | + $status_bulk_actions = array(); |
|
| 1001 | + break; |
|
| 1002 | 1002 | |
| 1003 | - case EEM_Message::status_incomplete: |
|
| 1004 | - unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']); |
|
| 1005 | - break; |
|
| 1003 | + case EEM_Message::status_incomplete: |
|
| 1004 | + unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']); |
|
| 1005 | + break; |
|
| 1006 | 1006 | |
| 1007 | - case EEM_Message::status_retry: |
|
| 1008 | - case EEM_Message::status_sent: |
|
| 1009 | - unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']); |
|
| 1010 | - break; |
|
| 1011 | - } |
|
| 1012 | - } |
|
| 1007 | + case EEM_Message::status_retry: |
|
| 1008 | + case EEM_Message::status_sent: |
|
| 1009 | + unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']); |
|
| 1010 | + break; |
|
| 1011 | + } |
|
| 1012 | + } |
|
| 1013 | 1013 | |
| 1014 | - //skip adding messenger executing status to views because it will be included with the Failed view. |
|
| 1015 | - if ( $status === EEM_Message::status_messenger_executing ) { |
|
| 1016 | - continue; |
|
| 1017 | - } |
|
| 1014 | + //skip adding messenger executing status to views because it will be included with the Failed view. |
|
| 1015 | + if ( $status === EEM_Message::status_messenger_executing ) { |
|
| 1016 | + continue; |
|
| 1017 | + } |
|
| 1018 | 1018 | |
| 1019 | - $this->_views[strtolower($status)] = array( |
|
| 1020 | - 'slug' => strtolower($status), |
|
| 1021 | - 'label' => EEH_Template::pretty_status($status, false, 'sentence'), |
|
| 1022 | - 'count' => 0, |
|
| 1023 | - 'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action) |
|
| 1024 | - ); |
|
| 1025 | - } |
|
| 1026 | - } |
|
| 1019 | + $this->_views[strtolower($status)] = array( |
|
| 1020 | + 'slug' => strtolower($status), |
|
| 1021 | + 'label' => EEH_Template::pretty_status($status, false, 'sentence'), |
|
| 1022 | + 'count' => 0, |
|
| 1023 | + 'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action) |
|
| 1024 | + ); |
|
| 1025 | + } |
|
| 1026 | + } |
|
| 1027 | 1027 | |
| 1028 | 1028 | |
| 1029 | - protected function _ee_default_messages_overview_list_table() |
|
| 1030 | - { |
|
| 1031 | - $this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso'); |
|
| 1032 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1033 | - } |
|
| 1029 | + protected function _ee_default_messages_overview_list_table() |
|
| 1030 | + { |
|
| 1031 | + $this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso'); |
|
| 1032 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1033 | + } |
|
| 1034 | 1034 | |
| 1035 | 1035 | |
| 1036 | - protected function _message_queue_list_table() |
|
| 1037 | - { |
|
| 1038 | - $this->_search_btn_label = esc_html__('Message Activity', 'event_espresso'); |
|
| 1039 | - $this->_template_args['per_column'] = 6; |
|
| 1040 | - $this->_template_args['after_list_table'] = $this->_display_legend($this->_message_legend_items()); |
|
| 1041 | - $this->_template_args['before_list_table'] = '<h3>' |
|
| 1042 | - . EEM_Message::instance()->get_pretty_label_for_results() |
|
| 1043 | - . '</h3>'; |
|
| 1044 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1045 | - } |
|
| 1036 | + protected function _message_queue_list_table() |
|
| 1037 | + { |
|
| 1038 | + $this->_search_btn_label = esc_html__('Message Activity', 'event_espresso'); |
|
| 1039 | + $this->_template_args['per_column'] = 6; |
|
| 1040 | + $this->_template_args['after_list_table'] = $this->_display_legend($this->_message_legend_items()); |
|
| 1041 | + $this->_template_args['before_list_table'] = '<h3>' |
|
| 1042 | + . EEM_Message::instance()->get_pretty_label_for_results() |
|
| 1043 | + . '</h3>'; |
|
| 1044 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1045 | + } |
|
| 1046 | 1046 | |
| 1047 | 1047 | |
| 1048 | - protected function _message_legend_items() |
|
| 1049 | - { |
|
| 1050 | - |
|
| 1051 | - $action_css_classes = EEH_MSG_Template::get_message_action_icons(); |
|
| 1052 | - $action_items = array(); |
|
| 1053 | - |
|
| 1054 | - foreach ($action_css_classes as $action_item => $action_details) { |
|
| 1055 | - if ($action_item === 'see_notifications_for') { |
|
| 1056 | - continue; |
|
| 1057 | - } |
|
| 1058 | - $action_items[$action_item] = array( |
|
| 1059 | - 'class' => $action_details['css_class'], |
|
| 1060 | - 'desc' => $action_details['label'] |
|
| 1061 | - ); |
|
| 1062 | - } |
|
| 1063 | - |
|
| 1064 | - /** @type array $status_items status legend setup */ |
|
| 1065 | - $status_items = array( |
|
| 1066 | - 'sent_status' => array( |
|
| 1067 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent, |
|
| 1068 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence') |
|
| 1069 | - ), |
|
| 1070 | - 'idle_status' => array( |
|
| 1071 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle, |
|
| 1072 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence') |
|
| 1073 | - ), |
|
| 1074 | - 'failed_status' => array( |
|
| 1075 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed, |
|
| 1076 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence') |
|
| 1077 | - ), |
|
| 1078 | - 'messenger_executing_status' => array( |
|
| 1079 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing, |
|
| 1080 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence') |
|
| 1081 | - ), |
|
| 1082 | - 'resend_status' => array( |
|
| 1083 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend, |
|
| 1084 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence') |
|
| 1085 | - ), |
|
| 1086 | - 'incomplete_status' => array( |
|
| 1087 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete, |
|
| 1088 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence') |
|
| 1089 | - ), |
|
| 1090 | - 'retry_status' => array( |
|
| 1091 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry, |
|
| 1092 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence') |
|
| 1093 | - ) |
|
| 1094 | - ); |
|
| 1095 | - if (EEM_Message::debug()) { |
|
| 1096 | - $status_items['debug_only_status'] = array( |
|
| 1097 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only, |
|
| 1098 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence') |
|
| 1099 | - ); |
|
| 1100 | - } |
|
| 1101 | - |
|
| 1102 | - return array_merge($action_items, $status_items); |
|
| 1103 | - } |
|
| 1048 | + protected function _message_legend_items() |
|
| 1049 | + { |
|
| 1050 | + |
|
| 1051 | + $action_css_classes = EEH_MSG_Template::get_message_action_icons(); |
|
| 1052 | + $action_items = array(); |
|
| 1053 | + |
|
| 1054 | + foreach ($action_css_classes as $action_item => $action_details) { |
|
| 1055 | + if ($action_item === 'see_notifications_for') { |
|
| 1056 | + continue; |
|
| 1057 | + } |
|
| 1058 | + $action_items[$action_item] = array( |
|
| 1059 | + 'class' => $action_details['css_class'], |
|
| 1060 | + 'desc' => $action_details['label'] |
|
| 1061 | + ); |
|
| 1062 | + } |
|
| 1063 | + |
|
| 1064 | + /** @type array $status_items status legend setup */ |
|
| 1065 | + $status_items = array( |
|
| 1066 | + 'sent_status' => array( |
|
| 1067 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent, |
|
| 1068 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence') |
|
| 1069 | + ), |
|
| 1070 | + 'idle_status' => array( |
|
| 1071 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle, |
|
| 1072 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence') |
|
| 1073 | + ), |
|
| 1074 | + 'failed_status' => array( |
|
| 1075 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed, |
|
| 1076 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence') |
|
| 1077 | + ), |
|
| 1078 | + 'messenger_executing_status' => array( |
|
| 1079 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing, |
|
| 1080 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence') |
|
| 1081 | + ), |
|
| 1082 | + 'resend_status' => array( |
|
| 1083 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend, |
|
| 1084 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence') |
|
| 1085 | + ), |
|
| 1086 | + 'incomplete_status' => array( |
|
| 1087 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete, |
|
| 1088 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence') |
|
| 1089 | + ), |
|
| 1090 | + 'retry_status' => array( |
|
| 1091 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry, |
|
| 1092 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence') |
|
| 1093 | + ) |
|
| 1094 | + ); |
|
| 1095 | + if (EEM_Message::debug()) { |
|
| 1096 | + $status_items['debug_only_status'] = array( |
|
| 1097 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only, |
|
| 1098 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence') |
|
| 1099 | + ); |
|
| 1100 | + } |
|
| 1101 | + |
|
| 1102 | + return array_merge($action_items, $status_items); |
|
| 1103 | + } |
|
| 1104 | 1104 | |
| 1105 | 1105 | |
| 1106 | - protected function _custom_mtps_preview() |
|
| 1107 | - { |
|
| 1108 | - $this->_admin_page_title = esc_html__('Custom Message Templates (Preview)', 'event_espresso'); |
|
| 1109 | - $this->_template_args['preview_img'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"' |
|
| 1110 | - . ' alt="' . esc_attr__('Preview Custom Message Templates screenshot', 'event_espresso') . '" />'; |
|
| 1111 | - $this->_template_args['preview_text'] = '<strong>' |
|
| 1112 | - . esc_html__( |
|
| 1113 | - 'Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.', |
|
| 1114 | - 'event_espresso' |
|
| 1115 | - ) |
|
| 1116 | - . '</strong>'; |
|
| 1106 | + protected function _custom_mtps_preview() |
|
| 1107 | + { |
|
| 1108 | + $this->_admin_page_title = esc_html__('Custom Message Templates (Preview)', 'event_espresso'); |
|
| 1109 | + $this->_template_args['preview_img'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"' |
|
| 1110 | + . ' alt="' . esc_attr__('Preview Custom Message Templates screenshot', 'event_espresso') . '" />'; |
|
| 1111 | + $this->_template_args['preview_text'] = '<strong>' |
|
| 1112 | + . esc_html__( |
|
| 1113 | + 'Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.', |
|
| 1114 | + 'event_espresso' |
|
| 1115 | + ) |
|
| 1116 | + . '</strong>'; |
|
| 1117 | 1117 | |
| 1118 | - $this->display_admin_caf_preview_page('custom_message_types', false); |
|
| 1119 | - } |
|
| 1118 | + $this->display_admin_caf_preview_page('custom_message_types', false); |
|
| 1119 | + } |
|
| 1120 | 1120 | |
| 1121 | 1121 | |
| 1122 | - /** |
|
| 1123 | - * get_message_templates |
|
| 1124 | - * This gets all the message templates for listing on the overview list. |
|
| 1125 | - * |
|
| 1126 | - * @access public |
|
| 1127 | - * @param int $perpage the amount of templates groups to show per page |
|
| 1128 | - * @param string $type the current _view we're getting templates for |
|
| 1129 | - * @param bool $count return count? |
|
| 1130 | - * @param bool $all disregard any paging info (get all data); |
|
| 1131 | - * @param bool $global whether to return just global (true) or custom templates (false) |
|
| 1132 | - * @return array |
|
| 1133 | - * @throws EE_Error |
|
| 1134 | - * @throws InvalidArgumentException |
|
| 1135 | - * @throws InvalidDataTypeException |
|
| 1136 | - * @throws InvalidInterfaceException |
|
| 1137 | - */ |
|
| 1138 | - public function get_message_templates( |
|
| 1139 | - $perpage = 10, |
|
| 1140 | - $type = 'in_use', |
|
| 1141 | - $count = false, |
|
| 1142 | - $all = false, |
|
| 1143 | - $global = true) |
|
| 1144 | - { |
|
| 1145 | - |
|
| 1146 | - $MTP = EEM_Message_Template_Group::instance(); |
|
| 1147 | - |
|
| 1148 | - $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby']; |
|
| 1149 | - $orderby = $this->_req_data['orderby']; |
|
| 1150 | - |
|
| 1151 | - $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) |
|
| 1152 | - ? $this->_req_data['order'] |
|
| 1153 | - : 'ASC'; |
|
| 1154 | - |
|
| 1155 | - $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
| 1156 | - ? $this->_req_data['paged'] |
|
| 1157 | - : 1; |
|
| 1158 | - $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
| 1159 | - ? $this->_req_data['perpage'] |
|
| 1160 | - : $perpage; |
|
| 1161 | - |
|
| 1162 | - $offset = ($current_page - 1) * $per_page; |
|
| 1163 | - $limit = $all ? null : array($offset, $per_page); |
|
| 1164 | - |
|
| 1165 | - |
|
| 1166 | - //options will match what is in the _views array property |
|
| 1167 | - switch ($type) { |
|
| 1168 | - case 'in_use': |
|
| 1169 | - $templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true); |
|
| 1170 | - break; |
|
| 1171 | - default: |
|
| 1172 | - $templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global); |
|
| 1173 | - } |
|
| 1174 | - |
|
| 1175 | - return $templates; |
|
| 1176 | - } |
|
| 1122 | + /** |
|
| 1123 | + * get_message_templates |
|
| 1124 | + * This gets all the message templates for listing on the overview list. |
|
| 1125 | + * |
|
| 1126 | + * @access public |
|
| 1127 | + * @param int $perpage the amount of templates groups to show per page |
|
| 1128 | + * @param string $type the current _view we're getting templates for |
|
| 1129 | + * @param bool $count return count? |
|
| 1130 | + * @param bool $all disregard any paging info (get all data); |
|
| 1131 | + * @param bool $global whether to return just global (true) or custom templates (false) |
|
| 1132 | + * @return array |
|
| 1133 | + * @throws EE_Error |
|
| 1134 | + * @throws InvalidArgumentException |
|
| 1135 | + * @throws InvalidDataTypeException |
|
| 1136 | + * @throws InvalidInterfaceException |
|
| 1137 | + */ |
|
| 1138 | + public function get_message_templates( |
|
| 1139 | + $perpage = 10, |
|
| 1140 | + $type = 'in_use', |
|
| 1141 | + $count = false, |
|
| 1142 | + $all = false, |
|
| 1143 | + $global = true) |
|
| 1144 | + { |
|
| 1145 | + |
|
| 1146 | + $MTP = EEM_Message_Template_Group::instance(); |
|
| 1147 | + |
|
| 1148 | + $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby']; |
|
| 1149 | + $orderby = $this->_req_data['orderby']; |
|
| 1150 | + |
|
| 1151 | + $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) |
|
| 1152 | + ? $this->_req_data['order'] |
|
| 1153 | + : 'ASC'; |
|
| 1154 | + |
|
| 1155 | + $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
| 1156 | + ? $this->_req_data['paged'] |
|
| 1157 | + : 1; |
|
| 1158 | + $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
| 1159 | + ? $this->_req_data['perpage'] |
|
| 1160 | + : $perpage; |
|
| 1161 | + |
|
| 1162 | + $offset = ($current_page - 1) * $per_page; |
|
| 1163 | + $limit = $all ? null : array($offset, $per_page); |
|
| 1164 | + |
|
| 1165 | + |
|
| 1166 | + //options will match what is in the _views array property |
|
| 1167 | + switch ($type) { |
|
| 1168 | + case 'in_use': |
|
| 1169 | + $templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true); |
|
| 1170 | + break; |
|
| 1171 | + default: |
|
| 1172 | + $templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global); |
|
| 1173 | + } |
|
| 1174 | + |
|
| 1175 | + return $templates; |
|
| 1176 | + } |
|
| 1177 | 1177 | |
| 1178 | 1178 | |
| 1179 | - /** |
|
| 1180 | - * filters etc might need a list of installed message_types |
|
| 1181 | - * @return array an array of message type objects |
|
| 1182 | - */ |
|
| 1183 | - public function get_installed_message_types() |
|
| 1184 | - { |
|
| 1185 | - $installed_message_types = $this->_message_resource_manager->installed_message_types(); |
|
| 1186 | - $installed = array(); |
|
| 1187 | - |
|
| 1188 | - foreach ($installed_message_types as $message_type) { |
|
| 1189 | - $installed[$message_type->name] = $message_type; |
|
| 1190 | - } |
|
| 1191 | - |
|
| 1192 | - return $installed; |
|
| 1193 | - } |
|
| 1179 | + /** |
|
| 1180 | + * filters etc might need a list of installed message_types |
|
| 1181 | + * @return array an array of message type objects |
|
| 1182 | + */ |
|
| 1183 | + public function get_installed_message_types() |
|
| 1184 | + { |
|
| 1185 | + $installed_message_types = $this->_message_resource_manager->installed_message_types(); |
|
| 1186 | + $installed = array(); |
|
| 1187 | + |
|
| 1188 | + foreach ($installed_message_types as $message_type) { |
|
| 1189 | + $installed[$message_type->name] = $message_type; |
|
| 1190 | + } |
|
| 1191 | + |
|
| 1192 | + return $installed; |
|
| 1193 | + } |
|
| 1194 | 1194 | |
| 1195 | 1195 | |
| 1196 | - /** |
|
| 1197 | - * _add_message_template |
|
| 1198 | - * |
|
| 1199 | - * This is used when creating a custom template. All Custom Templates start based off another template. |
|
| 1200 | - * |
|
| 1201 | - * @param string $message_type |
|
| 1202 | - * @param string $messenger |
|
| 1203 | - * @param string $GRP_ID |
|
| 1204 | - * |
|
| 1205 | - * @throws EE_error |
|
| 1206 | - */ |
|
| 1207 | - protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '') |
|
| 1208 | - { |
|
| 1209 | - //set values override any request data |
|
| 1210 | - $message_type = ! empty($message_type) ? $message_type : ''; |
|
| 1211 | - $message_type = empty($message_type) && ! empty($this->_req_data['message_type']) |
|
| 1212 | - ? $this->_req_data['message_type'] |
|
| 1213 | - : $message_type; |
|
| 1214 | - |
|
| 1215 | - $messenger = ! empty($messenger) ? $messenger : ''; |
|
| 1216 | - $messenger = empty($messenger) && ! empty($this->_req_data['messenger']) |
|
| 1217 | - ? $this->_req_data['messenger'] |
|
| 1218 | - : $messenger; |
|
| 1219 | - |
|
| 1220 | - $GRP_ID = ! empty($GRP_ID) ? $GRP_ID : ''; |
|
| 1221 | - $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : $GRP_ID; |
|
| 1222 | - |
|
| 1223 | - //we need messenger and message type. They should be coming from the event editor. If not here then return error |
|
| 1224 | - if (empty($message_type) || empty($messenger)) { |
|
| 1225 | - throw new EE_Error( |
|
| 1226 | - esc_html__( |
|
| 1227 | - 'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type', |
|
| 1228 | - 'event_espresso' |
|
| 1229 | - ) |
|
| 1230 | - ); |
|
| 1231 | - } |
|
| 1232 | - |
|
| 1233 | - //we need the GRP_ID for the template being used as the base for the new template |
|
| 1234 | - if (empty($GRP_ID)) { |
|
| 1235 | - throw new EE_Error( |
|
| 1236 | - esc_html__( |
|
| 1237 | - 'In order to create a custom message template the GRP_ID of the template being used as a base is needed', |
|
| 1238 | - 'event_espresso' |
|
| 1239 | - ) |
|
| 1240 | - ); |
|
| 1241 | - } |
|
| 1242 | - |
|
| 1243 | - //let's just make sure the template gets generated! |
|
| 1244 | - |
|
| 1245 | - //we need to reassign some variables for what the insert is expecting |
|
| 1246 | - $this->_req_data['MTP_messenger'] = $messenger; |
|
| 1247 | - $this->_req_data['MTP_message_type'] = $message_type; |
|
| 1248 | - $this->_req_data['GRP_ID'] = $GRP_ID; |
|
| 1249 | - $this->_insert_or_update_message_template(true); |
|
| 1250 | - } |
|
| 1196 | + /** |
|
| 1197 | + * _add_message_template |
|
| 1198 | + * |
|
| 1199 | + * This is used when creating a custom template. All Custom Templates start based off another template. |
|
| 1200 | + * |
|
| 1201 | + * @param string $message_type |
|
| 1202 | + * @param string $messenger |
|
| 1203 | + * @param string $GRP_ID |
|
| 1204 | + * |
|
| 1205 | + * @throws EE_error |
|
| 1206 | + */ |
|
| 1207 | + protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '') |
|
| 1208 | + { |
|
| 1209 | + //set values override any request data |
|
| 1210 | + $message_type = ! empty($message_type) ? $message_type : ''; |
|
| 1211 | + $message_type = empty($message_type) && ! empty($this->_req_data['message_type']) |
|
| 1212 | + ? $this->_req_data['message_type'] |
|
| 1213 | + : $message_type; |
|
| 1214 | + |
|
| 1215 | + $messenger = ! empty($messenger) ? $messenger : ''; |
|
| 1216 | + $messenger = empty($messenger) && ! empty($this->_req_data['messenger']) |
|
| 1217 | + ? $this->_req_data['messenger'] |
|
| 1218 | + : $messenger; |
|
| 1219 | + |
|
| 1220 | + $GRP_ID = ! empty($GRP_ID) ? $GRP_ID : ''; |
|
| 1221 | + $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : $GRP_ID; |
|
| 1222 | + |
|
| 1223 | + //we need messenger and message type. They should be coming from the event editor. If not here then return error |
|
| 1224 | + if (empty($message_type) || empty($messenger)) { |
|
| 1225 | + throw new EE_Error( |
|
| 1226 | + esc_html__( |
|
| 1227 | + 'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type', |
|
| 1228 | + 'event_espresso' |
|
| 1229 | + ) |
|
| 1230 | + ); |
|
| 1231 | + } |
|
| 1232 | + |
|
| 1233 | + //we need the GRP_ID for the template being used as the base for the new template |
|
| 1234 | + if (empty($GRP_ID)) { |
|
| 1235 | + throw new EE_Error( |
|
| 1236 | + esc_html__( |
|
| 1237 | + 'In order to create a custom message template the GRP_ID of the template being used as a base is needed', |
|
| 1238 | + 'event_espresso' |
|
| 1239 | + ) |
|
| 1240 | + ); |
|
| 1241 | + } |
|
| 1242 | + |
|
| 1243 | + //let's just make sure the template gets generated! |
|
| 1244 | + |
|
| 1245 | + //we need to reassign some variables for what the insert is expecting |
|
| 1246 | + $this->_req_data['MTP_messenger'] = $messenger; |
|
| 1247 | + $this->_req_data['MTP_message_type'] = $message_type; |
|
| 1248 | + $this->_req_data['GRP_ID'] = $GRP_ID; |
|
| 1249 | + $this->_insert_or_update_message_template(true); |
|
| 1250 | + } |
|
| 1251 | 1251 | |
| 1252 | 1252 | |
| 1253 | - /** |
|
| 1254 | - * public wrapper for the _add_message_template method |
|
| 1255 | - * |
|
| 1256 | - * @param string $message_type message type slug |
|
| 1257 | - * @param string $messenger messenger slug |
|
| 1258 | - * @param int $GRP_ID GRP_ID for the related message template group this new template will be based |
|
| 1259 | - * off of. |
|
| 1260 | - * @throws EE_error |
|
| 1261 | - */ |
|
| 1262 | - public function add_message_template($message_type, $messenger, $GRP_ID) |
|
| 1263 | - { |
|
| 1264 | - $this->_add_message_template($message_type, $messenger, $GRP_ID); |
|
| 1265 | - } |
|
| 1253 | + /** |
|
| 1254 | + * public wrapper for the _add_message_template method |
|
| 1255 | + * |
|
| 1256 | + * @param string $message_type message type slug |
|
| 1257 | + * @param string $messenger messenger slug |
|
| 1258 | + * @param int $GRP_ID GRP_ID for the related message template group this new template will be based |
|
| 1259 | + * off of. |
|
| 1260 | + * @throws EE_error |
|
| 1261 | + */ |
|
| 1262 | + public function add_message_template($message_type, $messenger, $GRP_ID) |
|
| 1263 | + { |
|
| 1264 | + $this->_add_message_template($message_type, $messenger, $GRP_ID); |
|
| 1265 | + } |
|
| 1266 | 1266 | |
| 1267 | 1267 | |
| 1268 | - /** |
|
| 1269 | - * _edit_message_template |
|
| 1270 | - * |
|
| 1271 | - * @access protected |
|
| 1272 | - * @return void |
|
| 1273 | - * @throws InvalidIdentifierException |
|
| 1274 | - * @throws DomainException |
|
| 1275 | - * @throws EE_Error |
|
| 1276 | - * @throws InvalidArgumentException |
|
| 1277 | - * @throws ReflectionException |
|
| 1278 | - * @throws InvalidDataTypeException |
|
| 1279 | - * @throws InvalidInterfaceException |
|
| 1280 | - */ |
|
| 1281 | - protected function _edit_message_template() |
|
| 1282 | - { |
|
| 1283 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1284 | - $template_fields = ''; |
|
| 1285 | - $sidebar_fields = ''; |
|
| 1286 | - //we filter the tinyMCE settings to remove the validation since message templates by their nature will not have |
|
| 1287 | - // valid html in the templates. |
|
| 1288 | - add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2); |
|
| 1289 | - |
|
| 1290 | - $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) |
|
| 1291 | - ? absint($this->_req_data['id']) |
|
| 1292 | - : false; |
|
| 1293 | - |
|
| 1294 | - $this->_set_shortcodes(); //this also sets the _message_template property. |
|
| 1295 | - $message_template_group = $this->_message_template_group; |
|
| 1296 | - $c_label = $message_template_group->context_label(); |
|
| 1297 | - $c_config = $message_template_group->contexts_config(); |
|
| 1298 | - |
|
| 1299 | - reset($c_config); |
|
| 1300 | - $context = isset($this->_req_data['context']) && ! empty($this->_req_data['context']) |
|
| 1301 | - ? strtolower($this->_req_data['context']) |
|
| 1302 | - : key($c_config); |
|
| 1303 | - |
|
| 1304 | - |
|
| 1305 | - if (empty($GRP_ID)) { |
|
| 1306 | - $action = 'insert_message_template'; |
|
| 1307 | - $edit_message_template_form_url = add_query_arg( |
|
| 1308 | - array('action' => $action, 'noheader' => true), |
|
| 1309 | - EE_MSG_ADMIN_URL |
|
| 1310 | - ); |
|
| 1311 | - } else { |
|
| 1312 | - $action = 'update_message_template'; |
|
| 1313 | - $edit_message_template_form_url = add_query_arg( |
|
| 1314 | - array('action' => $action, 'noheader' => true), |
|
| 1315 | - EE_MSG_ADMIN_URL |
|
| 1316 | - ); |
|
| 1317 | - } |
|
| 1318 | - |
|
| 1319 | - //set active messenger for this view |
|
| 1320 | - $this->_active_messenger = $this->_message_resource_manager->get_active_messenger( |
|
| 1321 | - $message_template_group->messenger() |
|
| 1322 | - ); |
|
| 1323 | - $this->_active_message_type_name = $message_template_group->message_type(); |
|
| 1324 | - |
|
| 1325 | - |
|
| 1326 | - //Do we have any validation errors? |
|
| 1327 | - $validators = $this->_get_transient(); |
|
| 1328 | - $v_fields = ! empty($validators) ? array_keys($validators) : array(); |
|
| 1329 | - |
|
| 1330 | - |
|
| 1331 | - //we need to assemble the title from Various details |
|
| 1332 | - $context_label = sprintf( |
|
| 1333 | - esc_html__('(%s %s)', 'event_espresso'), |
|
| 1334 | - $c_config[$context]['label'], |
|
| 1335 | - ucwords($c_label['label']) |
|
| 1336 | - ); |
|
| 1337 | - |
|
| 1338 | - $title = sprintf( |
|
| 1339 | - esc_html__(' %s %s Template %s', 'event_espresso'), |
|
| 1340 | - ucwords($message_template_group->messenger_obj()->label['singular']), |
|
| 1341 | - ucwords($message_template_group->message_type_obj()->label['singular']), |
|
| 1342 | - $context_label |
|
| 1343 | - ); |
|
| 1344 | - |
|
| 1345 | - $this->_template_args['GRP_ID'] = $GRP_ID; |
|
| 1346 | - $this->_template_args['message_template'] = $message_template_group; |
|
| 1347 | - $this->_template_args['is_extra_fields'] = false; |
|
| 1348 | - |
|
| 1349 | - |
|
| 1350 | - //let's get EEH_MSG_Template so we can get template form fields |
|
| 1351 | - $template_field_structure = EEH_MSG_Template::get_fields( |
|
| 1352 | - $message_template_group->messenger(), |
|
| 1353 | - $message_template_group->message_type() |
|
| 1354 | - ); |
|
| 1355 | - |
|
| 1356 | - if ( ! $template_field_structure) { |
|
| 1357 | - $template_field_structure = false; |
|
| 1358 | - $template_fields = esc_html__( |
|
| 1359 | - 'There was an error in assembling the fields for this display (you should see an error message)', |
|
| 1360 | - 'event_espresso' |
|
| 1361 | - ); |
|
| 1362 | - } |
|
| 1363 | - |
|
| 1364 | - |
|
| 1365 | - $message_templates = $message_template_group->context_templates(); |
|
| 1366 | - |
|
| 1367 | - |
|
| 1368 | - //if we have the extra key.. then we need to remove the content index from the template_field_structure as it |
|
| 1369 | - // will get handled in the "extra" array. |
|
| 1370 | - if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) { |
|
| 1371 | - foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) { |
|
| 1372 | - unset($template_field_structure[$context][$reference_field]); |
|
| 1373 | - } |
|
| 1374 | - } |
|
| 1375 | - |
|
| 1376 | - //let's loop through the template_field_structure and actually assemble the input fields! |
|
| 1377 | - if ( ! empty($template_field_structure)) { |
|
| 1378 | - foreach ($template_field_structure[$context] as $template_field => $field_setup_array) { |
|
| 1379 | - //if this is an 'extra' template field then we need to remove any existing fields that are keyed up in |
|
| 1380 | - // the extra array and reset them. |
|
| 1381 | - if ($template_field === 'extra') { |
|
| 1382 | - $this->_template_args['is_extra_fields'] = true; |
|
| 1383 | - foreach ($field_setup_array as $reference_field => $new_fields_array) { |
|
| 1384 | - $message_template = $message_templates[$context][$reference_field]; |
|
| 1385 | - $content = $message_template instanceof EE_Message_Template |
|
| 1386 | - ? $message_template->get('MTP_content') |
|
| 1387 | - : ''; |
|
| 1388 | - foreach ($new_fields_array as $extra_field => $extra_array) { |
|
| 1389 | - //let's verify if we need this extra field via the shortcodes parameter. |
|
| 1390 | - $continue = false; |
|
| 1391 | - if (isset($extra_array['shortcodes_required'])) { |
|
| 1392 | - foreach ((array)$extra_array['shortcodes_required'] as $shortcode) { |
|
| 1393 | - if ( ! array_key_exists($shortcode, $this->_shortcodes)) { |
|
| 1394 | - $continue = true; |
|
| 1395 | - } |
|
| 1396 | - } |
|
| 1397 | - if ($continue) { |
|
| 1398 | - continue; |
|
| 1399 | - } |
|
| 1400 | - } |
|
| 1268 | + /** |
|
| 1269 | + * _edit_message_template |
|
| 1270 | + * |
|
| 1271 | + * @access protected |
|
| 1272 | + * @return void |
|
| 1273 | + * @throws InvalidIdentifierException |
|
| 1274 | + * @throws DomainException |
|
| 1275 | + * @throws EE_Error |
|
| 1276 | + * @throws InvalidArgumentException |
|
| 1277 | + * @throws ReflectionException |
|
| 1278 | + * @throws InvalidDataTypeException |
|
| 1279 | + * @throws InvalidInterfaceException |
|
| 1280 | + */ |
|
| 1281 | + protected function _edit_message_template() |
|
| 1282 | + { |
|
| 1283 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1284 | + $template_fields = ''; |
|
| 1285 | + $sidebar_fields = ''; |
|
| 1286 | + //we filter the tinyMCE settings to remove the validation since message templates by their nature will not have |
|
| 1287 | + // valid html in the templates. |
|
| 1288 | + add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2); |
|
| 1289 | + |
|
| 1290 | + $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) |
|
| 1291 | + ? absint($this->_req_data['id']) |
|
| 1292 | + : false; |
|
| 1293 | + |
|
| 1294 | + $this->_set_shortcodes(); //this also sets the _message_template property. |
|
| 1295 | + $message_template_group = $this->_message_template_group; |
|
| 1296 | + $c_label = $message_template_group->context_label(); |
|
| 1297 | + $c_config = $message_template_group->contexts_config(); |
|
| 1298 | + |
|
| 1299 | + reset($c_config); |
|
| 1300 | + $context = isset($this->_req_data['context']) && ! empty($this->_req_data['context']) |
|
| 1301 | + ? strtolower($this->_req_data['context']) |
|
| 1302 | + : key($c_config); |
|
| 1303 | + |
|
| 1304 | + |
|
| 1305 | + if (empty($GRP_ID)) { |
|
| 1306 | + $action = 'insert_message_template'; |
|
| 1307 | + $edit_message_template_form_url = add_query_arg( |
|
| 1308 | + array('action' => $action, 'noheader' => true), |
|
| 1309 | + EE_MSG_ADMIN_URL |
|
| 1310 | + ); |
|
| 1311 | + } else { |
|
| 1312 | + $action = 'update_message_template'; |
|
| 1313 | + $edit_message_template_form_url = add_query_arg( |
|
| 1314 | + array('action' => $action, 'noheader' => true), |
|
| 1315 | + EE_MSG_ADMIN_URL |
|
| 1316 | + ); |
|
| 1317 | + } |
|
| 1318 | + |
|
| 1319 | + //set active messenger for this view |
|
| 1320 | + $this->_active_messenger = $this->_message_resource_manager->get_active_messenger( |
|
| 1321 | + $message_template_group->messenger() |
|
| 1322 | + ); |
|
| 1323 | + $this->_active_message_type_name = $message_template_group->message_type(); |
|
| 1324 | + |
|
| 1325 | + |
|
| 1326 | + //Do we have any validation errors? |
|
| 1327 | + $validators = $this->_get_transient(); |
|
| 1328 | + $v_fields = ! empty($validators) ? array_keys($validators) : array(); |
|
| 1329 | + |
|
| 1330 | + |
|
| 1331 | + //we need to assemble the title from Various details |
|
| 1332 | + $context_label = sprintf( |
|
| 1333 | + esc_html__('(%s %s)', 'event_espresso'), |
|
| 1334 | + $c_config[$context]['label'], |
|
| 1335 | + ucwords($c_label['label']) |
|
| 1336 | + ); |
|
| 1337 | + |
|
| 1338 | + $title = sprintf( |
|
| 1339 | + esc_html__(' %s %s Template %s', 'event_espresso'), |
|
| 1340 | + ucwords($message_template_group->messenger_obj()->label['singular']), |
|
| 1341 | + ucwords($message_template_group->message_type_obj()->label['singular']), |
|
| 1342 | + $context_label |
|
| 1343 | + ); |
|
| 1344 | + |
|
| 1345 | + $this->_template_args['GRP_ID'] = $GRP_ID; |
|
| 1346 | + $this->_template_args['message_template'] = $message_template_group; |
|
| 1347 | + $this->_template_args['is_extra_fields'] = false; |
|
| 1348 | + |
|
| 1349 | + |
|
| 1350 | + //let's get EEH_MSG_Template so we can get template form fields |
|
| 1351 | + $template_field_structure = EEH_MSG_Template::get_fields( |
|
| 1352 | + $message_template_group->messenger(), |
|
| 1353 | + $message_template_group->message_type() |
|
| 1354 | + ); |
|
| 1355 | + |
|
| 1356 | + if ( ! $template_field_structure) { |
|
| 1357 | + $template_field_structure = false; |
|
| 1358 | + $template_fields = esc_html__( |
|
| 1359 | + 'There was an error in assembling the fields for this display (you should see an error message)', |
|
| 1360 | + 'event_espresso' |
|
| 1361 | + ); |
|
| 1362 | + } |
|
| 1363 | + |
|
| 1364 | + |
|
| 1365 | + $message_templates = $message_template_group->context_templates(); |
|
| 1366 | + |
|
| 1367 | + |
|
| 1368 | + //if we have the extra key.. then we need to remove the content index from the template_field_structure as it |
|
| 1369 | + // will get handled in the "extra" array. |
|
| 1370 | + if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) { |
|
| 1371 | + foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) { |
|
| 1372 | + unset($template_field_structure[$context][$reference_field]); |
|
| 1373 | + } |
|
| 1374 | + } |
|
| 1375 | + |
|
| 1376 | + //let's loop through the template_field_structure and actually assemble the input fields! |
|
| 1377 | + if ( ! empty($template_field_structure)) { |
|
| 1378 | + foreach ($template_field_structure[$context] as $template_field => $field_setup_array) { |
|
| 1379 | + //if this is an 'extra' template field then we need to remove any existing fields that are keyed up in |
|
| 1380 | + // the extra array and reset them. |
|
| 1381 | + if ($template_field === 'extra') { |
|
| 1382 | + $this->_template_args['is_extra_fields'] = true; |
|
| 1383 | + foreach ($field_setup_array as $reference_field => $new_fields_array) { |
|
| 1384 | + $message_template = $message_templates[$context][$reference_field]; |
|
| 1385 | + $content = $message_template instanceof EE_Message_Template |
|
| 1386 | + ? $message_template->get('MTP_content') |
|
| 1387 | + : ''; |
|
| 1388 | + foreach ($new_fields_array as $extra_field => $extra_array) { |
|
| 1389 | + //let's verify if we need this extra field via the shortcodes parameter. |
|
| 1390 | + $continue = false; |
|
| 1391 | + if (isset($extra_array['shortcodes_required'])) { |
|
| 1392 | + foreach ((array)$extra_array['shortcodes_required'] as $shortcode) { |
|
| 1393 | + if ( ! array_key_exists($shortcode, $this->_shortcodes)) { |
|
| 1394 | + $continue = true; |
|
| 1395 | + } |
|
| 1396 | + } |
|
| 1397 | + if ($continue) { |
|
| 1398 | + continue; |
|
| 1399 | + } |
|
| 1400 | + } |
|
| 1401 | 1401 | |
| 1402 | - $field_id = $reference_field |
|
| 1403 | - . '-' |
|
| 1404 | - . $extra_field |
|
| 1405 | - . '-content'; |
|
| 1406 | - $template_form_fields[$field_id] = $extra_array; |
|
| 1407 | - $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' |
|
| 1408 | - . $reference_field |
|
| 1409 | - . '][content][' |
|
| 1410 | - . $extra_field . ']'; |
|
| 1411 | - $css_class = isset($extra_array['css_class']) |
|
| 1412 | - ? $extra_array['css_class'] |
|
| 1413 | - : ''; |
|
| 1402 | + $field_id = $reference_field |
|
| 1403 | + . '-' |
|
| 1404 | + . $extra_field |
|
| 1405 | + . '-content'; |
|
| 1406 | + $template_form_fields[$field_id] = $extra_array; |
|
| 1407 | + $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' |
|
| 1408 | + . $reference_field |
|
| 1409 | + . '][content][' |
|
| 1410 | + . $extra_field . ']'; |
|
| 1411 | + $css_class = isset($extra_array['css_class']) |
|
| 1412 | + ? $extra_array['css_class'] |
|
| 1413 | + : ''; |
|
| 1414 | 1414 | |
| 1415 | - $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
|
| 1416 | - && in_array($extra_field, $v_fields, true) |
|
| 1417 | - && |
|
| 1418 | - ( |
|
| 1419 | - is_array($validators[$extra_field]) |
|
| 1420 | - && isset($validators[$extra_field]['msg']) |
|
| 1421 | - ) |
|
| 1422 | - ? 'validate-error ' . $css_class |
|
| 1423 | - : $css_class; |
|
| 1415 | + $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
|
| 1416 | + && in_array($extra_field, $v_fields, true) |
|
| 1417 | + && |
|
| 1418 | + ( |
|
| 1419 | + is_array($validators[$extra_field]) |
|
| 1420 | + && isset($validators[$extra_field]['msg']) |
|
| 1421 | + ) |
|
| 1422 | + ? 'validate-error ' . $css_class |
|
| 1423 | + : $css_class; |
|
| 1424 | 1424 | |
| 1425 | - $template_form_fields[$field_id]['value'] = ! empty($message_templates) |
|
| 1426 | - && isset($content[$extra_field]) |
|
| 1427 | - ? stripslashes(html_entity_decode($content[$extra_field], ENT_QUOTES, "UTF-8")) |
|
| 1428 | - : ''; |
|
| 1425 | + $template_form_fields[$field_id]['value'] = ! empty($message_templates) |
|
| 1426 | + && isset($content[$extra_field]) |
|
| 1427 | + ? stripslashes(html_entity_decode($content[$extra_field], ENT_QUOTES, "UTF-8")) |
|
| 1428 | + : ''; |
|
| 1429 | 1429 | |
| 1430 | - //do we have a validation error? if we do then let's use that value instead |
|
| 1431 | - $template_form_fields[$field_id]['value'] = isset($validators[$extra_field]) |
|
| 1432 | - ? $validators[$extra_field]['value'] |
|
| 1433 | - : $template_form_fields[$field_id]['value']; |
|
| 1430 | + //do we have a validation error? if we do then let's use that value instead |
|
| 1431 | + $template_form_fields[$field_id]['value'] = isset($validators[$extra_field]) |
|
| 1432 | + ? $validators[$extra_field]['value'] |
|
| 1433 | + : $template_form_fields[$field_id]['value']; |
|
| 1434 | 1434 | |
| 1435 | 1435 | |
| 1436 | - $template_form_fields[$field_id]['db-col'] = 'MTP_content'; |
|
| 1436 | + $template_form_fields[$field_id]['db-col'] = 'MTP_content'; |
|
| 1437 | 1437 | |
| 1438 | - //shortcode selector |
|
| 1439 | - $field_name_to_use = $extra_field === 'main' |
|
| 1440 | - ? 'content' |
|
| 1441 | - : $extra_field; |
|
| 1442 | - $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector( |
|
| 1443 | - $field_name_to_use, |
|
| 1444 | - $field_id |
|
| 1445 | - ); |
|
| 1438 | + //shortcode selector |
|
| 1439 | + $field_name_to_use = $extra_field === 'main' |
|
| 1440 | + ? 'content' |
|
| 1441 | + : $extra_field; |
|
| 1442 | + $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector( |
|
| 1443 | + $field_name_to_use, |
|
| 1444 | + $field_id |
|
| 1445 | + ); |
|
| 1446 | 1446 | |
| 1447 | - if (isset($extra_array['input']) && $extra_array['input'] === 'wp_editor') { |
|
| 1448 | - //we want to decode the entities |
|
| 1449 | - $template_form_fields[$field_id]['value'] = stripslashes( |
|
| 1450 | - html_entity_decode( |
|
| 1451 | - $template_form_fields[$field_id]['value'], |
|
| 1452 | - ENT_QUOTES, |
|
| 1453 | - "UTF-8") |
|
| 1454 | - ); |
|
| 1447 | + if (isset($extra_array['input']) && $extra_array['input'] === 'wp_editor') { |
|
| 1448 | + //we want to decode the entities |
|
| 1449 | + $template_form_fields[$field_id]['value'] = stripslashes( |
|
| 1450 | + html_entity_decode( |
|
| 1451 | + $template_form_fields[$field_id]['value'], |
|
| 1452 | + ENT_QUOTES, |
|
| 1453 | + "UTF-8") |
|
| 1454 | + ); |
|
| 1455 | 1455 | |
| 1456 | - }/**/ |
|
| 1457 | - } |
|
| 1458 | - $templatefield_MTP_id = $reference_field . '-MTP_ID'; |
|
| 1459 | - $templatefield_templatename_id = $reference_field . '-name'; |
|
| 1456 | + }/**/ |
|
| 1457 | + } |
|
| 1458 | + $templatefield_MTP_id = $reference_field . '-MTP_ID'; |
|
| 1459 | + $templatefield_templatename_id = $reference_field . '-name'; |
|
| 1460 | 1460 | |
| 1461 | - $template_form_fields[$templatefield_MTP_id] = array( |
|
| 1462 | - 'name' => 'MTP_template_fields[' . $reference_field . '][MTP_ID]', |
|
| 1463 | - 'label' => null, |
|
| 1464 | - 'input' => 'hidden', |
|
| 1465 | - 'type' => 'int', |
|
| 1466 | - 'required' => false, |
|
| 1467 | - 'validation' => false, |
|
| 1468 | - 'value' => ! empty($message_templates) ? $message_template->ID() : '', |
|
| 1469 | - 'css_class' => '', |
|
| 1470 | - 'format' => '%d', |
|
| 1471 | - 'db-col' => 'MTP_ID' |
|
| 1472 | - ); |
|
| 1461 | + $template_form_fields[$templatefield_MTP_id] = array( |
|
| 1462 | + 'name' => 'MTP_template_fields[' . $reference_field . '][MTP_ID]', |
|
| 1463 | + 'label' => null, |
|
| 1464 | + 'input' => 'hidden', |
|
| 1465 | + 'type' => 'int', |
|
| 1466 | + 'required' => false, |
|
| 1467 | + 'validation' => false, |
|
| 1468 | + 'value' => ! empty($message_templates) ? $message_template->ID() : '', |
|
| 1469 | + 'css_class' => '', |
|
| 1470 | + 'format' => '%d', |
|
| 1471 | + 'db-col' => 'MTP_ID' |
|
| 1472 | + ); |
|
| 1473 | 1473 | |
| 1474 | - $template_form_fields[$templatefield_templatename_id] = array( |
|
| 1475 | - 'name' => 'MTP_template_fields[' . $reference_field . '][name]', |
|
| 1476 | - 'label' => null, |
|
| 1477 | - 'input' => 'hidden', |
|
| 1478 | - 'type' => 'string', |
|
| 1479 | - 'required' => false, |
|
| 1480 | - 'validation' => true, |
|
| 1481 | - 'value' => $reference_field, |
|
| 1482 | - 'css_class' => '', |
|
| 1483 | - 'format' => '%s', |
|
| 1484 | - 'db-col' => 'MTP_template_field' |
|
| 1485 | - ); |
|
| 1486 | - } |
|
| 1487 | - continue; //skip the next stuff, we got the necessary fields here for this dataset. |
|
| 1488 | - } else { |
|
| 1489 | - $field_id = $template_field . '-content'; |
|
| 1490 | - $template_form_fields[$field_id] = $field_setup_array; |
|
| 1491 | - $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $template_field . '][content]'; |
|
| 1492 | - $message_template = isset($message_templates[$context][$template_field]) |
|
| 1493 | - ? $message_templates[$context][$template_field] |
|
| 1494 | - : null; |
|
| 1495 | - $template_form_fields[$field_id]['value'] = ! empty($message_templates) |
|
| 1496 | - && is_array($message_templates[$context]) |
|
| 1497 | - && $message_template instanceof EE_Message_Template |
|
| 1498 | - ? $message_template->get('MTP_content') |
|
| 1499 | - : ''; |
|
| 1474 | + $template_form_fields[$templatefield_templatename_id] = array( |
|
| 1475 | + 'name' => 'MTP_template_fields[' . $reference_field . '][name]', |
|
| 1476 | + 'label' => null, |
|
| 1477 | + 'input' => 'hidden', |
|
| 1478 | + 'type' => 'string', |
|
| 1479 | + 'required' => false, |
|
| 1480 | + 'validation' => true, |
|
| 1481 | + 'value' => $reference_field, |
|
| 1482 | + 'css_class' => '', |
|
| 1483 | + 'format' => '%s', |
|
| 1484 | + 'db-col' => 'MTP_template_field' |
|
| 1485 | + ); |
|
| 1486 | + } |
|
| 1487 | + continue; //skip the next stuff, we got the necessary fields here for this dataset. |
|
| 1488 | + } else { |
|
| 1489 | + $field_id = $template_field . '-content'; |
|
| 1490 | + $template_form_fields[$field_id] = $field_setup_array; |
|
| 1491 | + $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $template_field . '][content]'; |
|
| 1492 | + $message_template = isset($message_templates[$context][$template_field]) |
|
| 1493 | + ? $message_templates[$context][$template_field] |
|
| 1494 | + : null; |
|
| 1495 | + $template_form_fields[$field_id]['value'] = ! empty($message_templates) |
|
| 1496 | + && is_array($message_templates[$context]) |
|
| 1497 | + && $message_template instanceof EE_Message_Template |
|
| 1498 | + ? $message_template->get('MTP_content') |
|
| 1499 | + : ''; |
|
| 1500 | 1500 | |
| 1501 | - //do we have a validator error for this field? if we do then we'll use that value instead |
|
| 1502 | - $template_form_fields[$field_id]['value'] = isset($validators[$template_field]) |
|
| 1503 | - ? $validators[$template_field]['value'] |
|
| 1504 | - : $template_form_fields[$field_id]['value']; |
|
| 1501 | + //do we have a validator error for this field? if we do then we'll use that value instead |
|
| 1502 | + $template_form_fields[$field_id]['value'] = isset($validators[$template_field]) |
|
| 1503 | + ? $validators[$template_field]['value'] |
|
| 1504 | + : $template_form_fields[$field_id]['value']; |
|
| 1505 | 1505 | |
| 1506 | 1506 | |
| 1507 | - $template_form_fields[$field_id]['db-col'] = 'MTP_content'; |
|
| 1508 | - $css_class = isset($field_setup_array['css_class']) |
|
| 1509 | - ? $field_setup_array['css_class'] |
|
| 1510 | - : ''; |
|
| 1511 | - $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
|
| 1512 | - && in_array($template_field, $v_fields, true) |
|
| 1513 | - && isset($validators[$template_field]['msg']) |
|
| 1514 | - ? 'validate-error ' . $css_class |
|
| 1515 | - : $css_class; |
|
| 1507 | + $template_form_fields[$field_id]['db-col'] = 'MTP_content'; |
|
| 1508 | + $css_class = isset($field_setup_array['css_class']) |
|
| 1509 | + ? $field_setup_array['css_class'] |
|
| 1510 | + : ''; |
|
| 1511 | + $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
|
| 1512 | + && in_array($template_field, $v_fields, true) |
|
| 1513 | + && isset($validators[$template_field]['msg']) |
|
| 1514 | + ? 'validate-error ' . $css_class |
|
| 1515 | + : $css_class; |
|
| 1516 | 1516 | |
| 1517 | - //shortcode selector |
|
| 1518 | - $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector( |
|
| 1519 | - $template_field, $field_id |
|
| 1520 | - ); |
|
| 1521 | - } |
|
| 1517 | + //shortcode selector |
|
| 1518 | + $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector( |
|
| 1519 | + $template_field, $field_id |
|
| 1520 | + ); |
|
| 1521 | + } |
|
| 1522 | 1522 | |
| 1523 | - //k took care of content field(s) now let's take care of others. |
|
| 1523 | + //k took care of content field(s) now let's take care of others. |
|
| 1524 | 1524 | |
| 1525 | - $templatefield_MTP_id = $template_field . '-MTP_ID'; |
|
| 1526 | - $templatefield_field_templatename_id = $template_field . '-name'; |
|
| 1525 | + $templatefield_MTP_id = $template_field . '-MTP_ID'; |
|
| 1526 | + $templatefield_field_templatename_id = $template_field . '-name'; |
|
| 1527 | 1527 | |
| 1528 | - //foreach template field there are actually two form fields created |
|
| 1529 | - $template_form_fields[$templatefield_MTP_id] = array( |
|
| 1530 | - 'name' => 'MTP_template_fields[' . $template_field . '][MTP_ID]', |
|
| 1531 | - 'label' => null, |
|
| 1532 | - 'input' => 'hidden', |
|
| 1533 | - 'type' => 'int', |
|
| 1534 | - 'required' => false, |
|
| 1535 | - 'validation' => true, |
|
| 1536 | - 'value' => $message_template instanceof EE_Message_Template ? $message_template->ID() : '', |
|
| 1537 | - 'css_class' => '', |
|
| 1538 | - 'format' => '%d', |
|
| 1539 | - 'db-col' => 'MTP_ID' |
|
| 1540 | - ); |
|
| 1528 | + //foreach template field there are actually two form fields created |
|
| 1529 | + $template_form_fields[$templatefield_MTP_id] = array( |
|
| 1530 | + 'name' => 'MTP_template_fields[' . $template_field . '][MTP_ID]', |
|
| 1531 | + 'label' => null, |
|
| 1532 | + 'input' => 'hidden', |
|
| 1533 | + 'type' => 'int', |
|
| 1534 | + 'required' => false, |
|
| 1535 | + 'validation' => true, |
|
| 1536 | + 'value' => $message_template instanceof EE_Message_Template ? $message_template->ID() : '', |
|
| 1537 | + 'css_class' => '', |
|
| 1538 | + 'format' => '%d', |
|
| 1539 | + 'db-col' => 'MTP_ID' |
|
| 1540 | + ); |
|
| 1541 | 1541 | |
| 1542 | - $template_form_fields[$templatefield_field_templatename_id] = array( |
|
| 1543 | - 'name' => 'MTP_template_fields[' . $template_field . '][name]', |
|
| 1544 | - 'label' => null, |
|
| 1545 | - 'input' => 'hidden', |
|
| 1546 | - 'type' => 'string', |
|
| 1547 | - 'required' => false, |
|
| 1548 | - 'validation' => true, |
|
| 1549 | - 'value' => $template_field, |
|
| 1550 | - 'css_class' => '', |
|
| 1551 | - 'format' => '%s', |
|
| 1552 | - 'db-col' => 'MTP_template_field' |
|
| 1553 | - ); |
|
| 1542 | + $template_form_fields[$templatefield_field_templatename_id] = array( |
|
| 1543 | + 'name' => 'MTP_template_fields[' . $template_field . '][name]', |
|
| 1544 | + 'label' => null, |
|
| 1545 | + 'input' => 'hidden', |
|
| 1546 | + 'type' => 'string', |
|
| 1547 | + 'required' => false, |
|
| 1548 | + 'validation' => true, |
|
| 1549 | + 'value' => $template_field, |
|
| 1550 | + 'css_class' => '', |
|
| 1551 | + 'format' => '%s', |
|
| 1552 | + 'db-col' => 'MTP_template_field' |
|
| 1553 | + ); |
|
| 1554 | 1554 | |
| 1555 | - } |
|
| 1555 | + } |
|
| 1556 | 1556 | |
| 1557 | - //add other fields |
|
| 1558 | - $template_form_fields['ee-msg-current-context'] = array( |
|
| 1559 | - 'name' => 'MTP_context', |
|
| 1560 | - 'label' => null, |
|
| 1561 | - 'input' => 'hidden', |
|
| 1562 | - 'type' => 'string', |
|
| 1563 | - 'required' => false, |
|
| 1564 | - 'validation' => true, |
|
| 1565 | - 'value' => $context, |
|
| 1566 | - 'css_class' => '', |
|
| 1567 | - 'format' => '%s', |
|
| 1568 | - 'db-col' => 'MTP_context' |
|
| 1569 | - ); |
|
| 1557 | + //add other fields |
|
| 1558 | + $template_form_fields['ee-msg-current-context'] = array( |
|
| 1559 | + 'name' => 'MTP_context', |
|
| 1560 | + 'label' => null, |
|
| 1561 | + 'input' => 'hidden', |
|
| 1562 | + 'type' => 'string', |
|
| 1563 | + 'required' => false, |
|
| 1564 | + 'validation' => true, |
|
| 1565 | + 'value' => $context, |
|
| 1566 | + 'css_class' => '', |
|
| 1567 | + 'format' => '%s', |
|
| 1568 | + 'db-col' => 'MTP_context' |
|
| 1569 | + ); |
|
| 1570 | 1570 | |
| 1571 | - $template_form_fields['ee-msg-grp-id'] = array( |
|
| 1572 | - 'name' => 'GRP_ID', |
|
| 1573 | - 'label' => null, |
|
| 1574 | - 'input' => 'hidden', |
|
| 1575 | - 'type' => 'int', |
|
| 1576 | - 'required' => false, |
|
| 1577 | - 'validation' => true, |
|
| 1578 | - 'value' => $GRP_ID, |
|
| 1579 | - 'css_class' => '', |
|
| 1580 | - 'format' => '%d', |
|
| 1581 | - 'db-col' => 'GRP_ID' |
|
| 1582 | - ); |
|
| 1571 | + $template_form_fields['ee-msg-grp-id'] = array( |
|
| 1572 | + 'name' => 'GRP_ID', |
|
| 1573 | + 'label' => null, |
|
| 1574 | + 'input' => 'hidden', |
|
| 1575 | + 'type' => 'int', |
|
| 1576 | + 'required' => false, |
|
| 1577 | + 'validation' => true, |
|
| 1578 | + 'value' => $GRP_ID, |
|
| 1579 | + 'css_class' => '', |
|
| 1580 | + 'format' => '%d', |
|
| 1581 | + 'db-col' => 'GRP_ID' |
|
| 1582 | + ); |
|
| 1583 | 1583 | |
| 1584 | - $template_form_fields['ee-msg-messenger'] = array( |
|
| 1585 | - 'name' => 'MTP_messenger', |
|
| 1586 | - 'label' => null, |
|
| 1587 | - 'input' => 'hidden', |
|
| 1588 | - 'type' => 'string', |
|
| 1589 | - 'required' => false, |
|
| 1590 | - 'validation' => true, |
|
| 1591 | - 'value' => $message_template_group->messenger(), |
|
| 1592 | - 'css_class' => '', |
|
| 1593 | - 'format' => '%s', |
|
| 1594 | - 'db-col' => 'MTP_messenger' |
|
| 1595 | - ); |
|
| 1584 | + $template_form_fields['ee-msg-messenger'] = array( |
|
| 1585 | + 'name' => 'MTP_messenger', |
|
| 1586 | + 'label' => null, |
|
| 1587 | + 'input' => 'hidden', |
|
| 1588 | + 'type' => 'string', |
|
| 1589 | + 'required' => false, |
|
| 1590 | + 'validation' => true, |
|
| 1591 | + 'value' => $message_template_group->messenger(), |
|
| 1592 | + 'css_class' => '', |
|
| 1593 | + 'format' => '%s', |
|
| 1594 | + 'db-col' => 'MTP_messenger' |
|
| 1595 | + ); |
|
| 1596 | 1596 | |
| 1597 | - $template_form_fields['ee-msg-message-type'] = array( |
|
| 1598 | - 'name' => 'MTP_message_type', |
|
| 1599 | - 'label' => null, |
|
| 1600 | - 'input' => 'hidden', |
|
| 1601 | - 'type' => 'string', |
|
| 1602 | - 'required' => false, |
|
| 1603 | - 'validation' => true, |
|
| 1604 | - 'value' => $message_template_group->message_type(), |
|
| 1605 | - 'css_class' => '', |
|
| 1606 | - 'format' => '%s', |
|
| 1607 | - 'db-col' => 'MTP_message_type' |
|
| 1608 | - ); |
|
| 1597 | + $template_form_fields['ee-msg-message-type'] = array( |
|
| 1598 | + 'name' => 'MTP_message_type', |
|
| 1599 | + 'label' => null, |
|
| 1600 | + 'input' => 'hidden', |
|
| 1601 | + 'type' => 'string', |
|
| 1602 | + 'required' => false, |
|
| 1603 | + 'validation' => true, |
|
| 1604 | + 'value' => $message_template_group->message_type(), |
|
| 1605 | + 'css_class' => '', |
|
| 1606 | + 'format' => '%s', |
|
| 1607 | + 'db-col' => 'MTP_message_type' |
|
| 1608 | + ); |
|
| 1609 | 1609 | |
| 1610 | - $sidebar_form_fields['ee-msg-is-global'] = array( |
|
| 1611 | - 'name' => 'MTP_is_global', |
|
| 1612 | - 'label' => esc_html__('Global Template', 'event_espresso'), |
|
| 1613 | - 'input' => 'hidden', |
|
| 1614 | - 'type' => 'int', |
|
| 1615 | - 'required' => false, |
|
| 1616 | - 'validation' => true, |
|
| 1617 | - 'value' => $message_template_group->get('MTP_is_global'), |
|
| 1618 | - 'css_class' => '', |
|
| 1619 | - 'format' => '%d', |
|
| 1620 | - 'db-col' => 'MTP_is_global' |
|
| 1621 | - ); |
|
| 1610 | + $sidebar_form_fields['ee-msg-is-global'] = array( |
|
| 1611 | + 'name' => 'MTP_is_global', |
|
| 1612 | + 'label' => esc_html__('Global Template', 'event_espresso'), |
|
| 1613 | + 'input' => 'hidden', |
|
| 1614 | + 'type' => 'int', |
|
| 1615 | + 'required' => false, |
|
| 1616 | + 'validation' => true, |
|
| 1617 | + 'value' => $message_template_group->get('MTP_is_global'), |
|
| 1618 | + 'css_class' => '', |
|
| 1619 | + 'format' => '%d', |
|
| 1620 | + 'db-col' => 'MTP_is_global' |
|
| 1621 | + ); |
|
| 1622 | 1622 | |
| 1623 | - $sidebar_form_fields['ee-msg-is-override'] = array( |
|
| 1624 | - 'name' => 'MTP_is_override', |
|
| 1625 | - 'label' => esc_html__('Override all custom', 'event_espresso'), |
|
| 1626 | - 'input' => $message_template_group->is_global() ? 'checkbox' : 'hidden', |
|
| 1627 | - 'type' => 'int', |
|
| 1628 | - 'required' => false, |
|
| 1629 | - 'validation' => true, |
|
| 1630 | - 'value' => $message_template_group->get('MTP_is_override'), |
|
| 1631 | - 'css_class' => '', |
|
| 1632 | - 'format' => '%d', |
|
| 1633 | - 'db-col' => 'MTP_is_override' |
|
| 1634 | - ); |
|
| 1623 | + $sidebar_form_fields['ee-msg-is-override'] = array( |
|
| 1624 | + 'name' => 'MTP_is_override', |
|
| 1625 | + 'label' => esc_html__('Override all custom', 'event_espresso'), |
|
| 1626 | + 'input' => $message_template_group->is_global() ? 'checkbox' : 'hidden', |
|
| 1627 | + 'type' => 'int', |
|
| 1628 | + 'required' => false, |
|
| 1629 | + 'validation' => true, |
|
| 1630 | + 'value' => $message_template_group->get('MTP_is_override'), |
|
| 1631 | + 'css_class' => '', |
|
| 1632 | + 'format' => '%d', |
|
| 1633 | + 'db-col' => 'MTP_is_override' |
|
| 1634 | + ); |
|
| 1635 | 1635 | |
| 1636 | - $sidebar_form_fields['ee-msg-is-active'] = array( |
|
| 1637 | - 'name' => 'MTP_is_active', |
|
| 1638 | - 'label' => esc_html__('Active Template', 'event_espresso'), |
|
| 1639 | - 'input' => 'hidden', |
|
| 1640 | - 'type' => 'int', |
|
| 1641 | - 'required' => false, |
|
| 1642 | - 'validation' => true, |
|
| 1643 | - 'value' => $message_template_group->is_active(), |
|
| 1644 | - 'css_class' => '', |
|
| 1645 | - 'format' => '%d', |
|
| 1646 | - 'db-col' => 'MTP_is_active' |
|
| 1647 | - ); |
|
| 1636 | + $sidebar_form_fields['ee-msg-is-active'] = array( |
|
| 1637 | + 'name' => 'MTP_is_active', |
|
| 1638 | + 'label' => esc_html__('Active Template', 'event_espresso'), |
|
| 1639 | + 'input' => 'hidden', |
|
| 1640 | + 'type' => 'int', |
|
| 1641 | + 'required' => false, |
|
| 1642 | + 'validation' => true, |
|
| 1643 | + 'value' => $message_template_group->is_active(), |
|
| 1644 | + 'css_class' => '', |
|
| 1645 | + 'format' => '%d', |
|
| 1646 | + 'db-col' => 'MTP_is_active' |
|
| 1647 | + ); |
|
| 1648 | 1648 | |
| 1649 | - $sidebar_form_fields['ee-msg-deleted'] = array( |
|
| 1650 | - 'name' => 'MTP_deleted', |
|
| 1651 | - 'label' => null, |
|
| 1652 | - 'input' => 'hidden', |
|
| 1653 | - 'type' => 'int', |
|
| 1654 | - 'required' => false, |
|
| 1655 | - 'validation' => true, |
|
| 1656 | - 'value' => $message_template_group->get('MTP_deleted'), |
|
| 1657 | - 'css_class' => '', |
|
| 1658 | - 'format' => '%d', |
|
| 1659 | - 'db-col' => 'MTP_deleted' |
|
| 1660 | - ); |
|
| 1661 | - $sidebar_form_fields['ee-msg-author'] = array( |
|
| 1662 | - 'name' => 'MTP_user_id', |
|
| 1663 | - 'label' => esc_html__('Author', 'event_espresso'), |
|
| 1664 | - 'input' => 'hidden', |
|
| 1665 | - 'type' => 'int', |
|
| 1666 | - 'required' => false, |
|
| 1667 | - 'validation' => false, |
|
| 1668 | - 'value' => $message_template_group->user(), |
|
| 1669 | - 'format' => '%d', |
|
| 1670 | - 'db-col' => 'MTP_user_id' |
|
| 1671 | - ); |
|
| 1649 | + $sidebar_form_fields['ee-msg-deleted'] = array( |
|
| 1650 | + 'name' => 'MTP_deleted', |
|
| 1651 | + 'label' => null, |
|
| 1652 | + 'input' => 'hidden', |
|
| 1653 | + 'type' => 'int', |
|
| 1654 | + 'required' => false, |
|
| 1655 | + 'validation' => true, |
|
| 1656 | + 'value' => $message_template_group->get('MTP_deleted'), |
|
| 1657 | + 'css_class' => '', |
|
| 1658 | + 'format' => '%d', |
|
| 1659 | + 'db-col' => 'MTP_deleted' |
|
| 1660 | + ); |
|
| 1661 | + $sidebar_form_fields['ee-msg-author'] = array( |
|
| 1662 | + 'name' => 'MTP_user_id', |
|
| 1663 | + 'label' => esc_html__('Author', 'event_espresso'), |
|
| 1664 | + 'input' => 'hidden', |
|
| 1665 | + 'type' => 'int', |
|
| 1666 | + 'required' => false, |
|
| 1667 | + 'validation' => false, |
|
| 1668 | + 'value' => $message_template_group->user(), |
|
| 1669 | + 'format' => '%d', |
|
| 1670 | + 'db-col' => 'MTP_user_id' |
|
| 1671 | + ); |
|
| 1672 | 1672 | |
| 1673 | - $sidebar_form_fields['ee-msg-route'] = array( |
|
| 1674 | - 'name' => 'action', |
|
| 1675 | - 'input' => 'hidden', |
|
| 1676 | - 'type' => 'string', |
|
| 1677 | - 'value' => $action |
|
| 1678 | - ); |
|
| 1673 | + $sidebar_form_fields['ee-msg-route'] = array( |
|
| 1674 | + 'name' => 'action', |
|
| 1675 | + 'input' => 'hidden', |
|
| 1676 | + 'type' => 'string', |
|
| 1677 | + 'value' => $action |
|
| 1678 | + ); |
|
| 1679 | 1679 | |
| 1680 | - $sidebar_form_fields['ee-msg-id'] = array( |
|
| 1681 | - 'name' => 'id', |
|
| 1682 | - 'input' => 'hidden', |
|
| 1683 | - 'type' => 'int', |
|
| 1684 | - 'value' => $GRP_ID |
|
| 1685 | - ); |
|
| 1686 | - $sidebar_form_fields['ee-msg-evt-nonce'] = array( |
|
| 1687 | - 'name' => $action . '_nonce', |
|
| 1688 | - 'input' => 'hidden', |
|
| 1689 | - 'type' => 'string', |
|
| 1690 | - 'value' => wp_create_nonce($action . '_nonce') |
|
| 1691 | - ); |
|
| 1680 | + $sidebar_form_fields['ee-msg-id'] = array( |
|
| 1681 | + 'name' => 'id', |
|
| 1682 | + 'input' => 'hidden', |
|
| 1683 | + 'type' => 'int', |
|
| 1684 | + 'value' => $GRP_ID |
|
| 1685 | + ); |
|
| 1686 | + $sidebar_form_fields['ee-msg-evt-nonce'] = array( |
|
| 1687 | + 'name' => $action . '_nonce', |
|
| 1688 | + 'input' => 'hidden', |
|
| 1689 | + 'type' => 'string', |
|
| 1690 | + 'value' => wp_create_nonce($action . '_nonce') |
|
| 1691 | + ); |
|
| 1692 | 1692 | |
| 1693 | - if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) { |
|
| 1694 | - $sidebar_form_fields['ee-msg-template-switch'] = array( |
|
| 1695 | - 'name' => 'template_switch', |
|
| 1696 | - 'input' => 'hidden', |
|
| 1697 | - 'type' => 'int', |
|
| 1698 | - 'value' => 1 |
|
| 1699 | - ); |
|
| 1700 | - } |
|
| 1693 | + if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) { |
|
| 1694 | + $sidebar_form_fields['ee-msg-template-switch'] = array( |
|
| 1695 | + 'name' => 'template_switch', |
|
| 1696 | + 'input' => 'hidden', |
|
| 1697 | + 'type' => 'int', |
|
| 1698 | + 'value' => 1 |
|
| 1699 | + ); |
|
| 1700 | + } |
|
| 1701 | 1701 | |
| 1702 | 1702 | |
| 1703 | - $template_fields = $this->_generate_admin_form_fields($template_form_fields); |
|
| 1704 | - $sidebar_fields = $this->_generate_admin_form_fields($sidebar_form_fields); |
|
| 1703 | + $template_fields = $this->_generate_admin_form_fields($template_form_fields); |
|
| 1704 | + $sidebar_fields = $this->_generate_admin_form_fields($sidebar_form_fields); |
|
| 1705 | 1705 | |
| 1706 | 1706 | |
| 1707 | - } //end if ( !empty($template_field_structure) ) |
|
| 1708 | - |
|
| 1709 | - //set extra content for publish box |
|
| 1710 | - $this->_template_args['publish_box_extra_content'] = $sidebar_fields; |
|
| 1711 | - $this->_set_publish_post_box_vars( |
|
| 1712 | - 'id', |
|
| 1713 | - $GRP_ID, |
|
| 1714 | - false, |
|
| 1715 | - add_query_arg( |
|
| 1716 | - array('action' => 'global_mtps'), |
|
| 1717 | - $this->_admin_base_url |
|
| 1718 | - ) |
|
| 1719 | - ); |
|
| 1720 | - |
|
| 1721 | - //add preview button |
|
| 1722 | - $preview_url = parent::add_query_args_and_nonce( |
|
| 1723 | - array( |
|
| 1724 | - 'message_type' => $message_template_group->message_type(), |
|
| 1725 | - 'messenger' => $message_template_group->messenger(), |
|
| 1726 | - 'context' => $context, |
|
| 1727 | - 'GRP_ID' => $GRP_ID, |
|
| 1728 | - 'action' => 'preview_message' |
|
| 1729 | - ), |
|
| 1730 | - $this->_admin_base_url |
|
| 1731 | - ); |
|
| 1732 | - $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">' |
|
| 1733 | - . esc_html__('Preview', 'event_espresso') |
|
| 1734 | - . '</a>'; |
|
| 1735 | - |
|
| 1736 | - |
|
| 1737 | - //setup context switcher |
|
| 1738 | - $context_switcher_args = array( |
|
| 1739 | - 'page' => 'espresso_messages', |
|
| 1740 | - 'action' => 'edit_message_template', |
|
| 1741 | - 'id' => $GRP_ID, |
|
| 1742 | - 'context' => $context, |
|
| 1743 | - 'extra' => $preview_button |
|
| 1744 | - ); |
|
| 1745 | - $this->_set_context_switcher($message_template_group, $context_switcher_args); |
|
| 1746 | - |
|
| 1747 | - |
|
| 1748 | - //main box |
|
| 1749 | - $this->_template_args['template_fields'] = $template_fields; |
|
| 1750 | - $this->_template_args['sidebar_box_id'] = 'details'; |
|
| 1751 | - $this->_template_args['action'] = $action; |
|
| 1752 | - $this->_template_args['context'] = $context; |
|
| 1753 | - $this->_template_args['edit_message_template_form_url'] = $edit_message_template_form_url; |
|
| 1754 | - $this->_template_args['learn_more_about_message_templates_link'] = |
|
| 1755 | - $this->_learn_more_about_message_templates_link(); |
|
| 1756 | - |
|
| 1757 | - |
|
| 1758 | - $this->_template_args['before_admin_page_content'] = $this->add_context_switcher(); |
|
| 1759 | - $this->_template_args['before_admin_page_content'] .= $this->add_active_context_element( |
|
| 1760 | - $message_template_group, |
|
| 1761 | - $context, |
|
| 1762 | - $context_label |
|
| 1763 | - ); |
|
| 1764 | - $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before(); |
|
| 1765 | - $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after(); |
|
| 1766 | - |
|
| 1767 | - $this->_template_path = $this->_template_args['GRP_ID'] |
|
| 1768 | - ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php' |
|
| 1769 | - : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php'; |
|
| 1770 | - |
|
| 1771 | - //send along EE_Message_Template_Group object for further template use. |
|
| 1772 | - $this->_template_args['MTP'] = $message_template_group; |
|
| 1773 | - |
|
| 1774 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 1775 | - $this->_template_path, |
|
| 1776 | - $this->_template_args, |
|
| 1777 | - true |
|
| 1778 | - ); |
|
| 1779 | - |
|
| 1780 | - |
|
| 1781 | - //finally, let's set the admin_page title |
|
| 1782 | - $this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title); |
|
| 1783 | - |
|
| 1784 | - |
|
| 1785 | - //we need to take care of setting the shortcodes property for use elsewhere. |
|
| 1786 | - $this->_set_shortcodes(); |
|
| 1787 | - |
|
| 1788 | - |
|
| 1789 | - //final template wrapper |
|
| 1790 | - $this->display_admin_page_with_sidebar(); |
|
| 1791 | - } |
|
| 1707 | + } //end if ( !empty($template_field_structure) ) |
|
| 1708 | + |
|
| 1709 | + //set extra content for publish box |
|
| 1710 | + $this->_template_args['publish_box_extra_content'] = $sidebar_fields; |
|
| 1711 | + $this->_set_publish_post_box_vars( |
|
| 1712 | + 'id', |
|
| 1713 | + $GRP_ID, |
|
| 1714 | + false, |
|
| 1715 | + add_query_arg( |
|
| 1716 | + array('action' => 'global_mtps'), |
|
| 1717 | + $this->_admin_base_url |
|
| 1718 | + ) |
|
| 1719 | + ); |
|
| 1720 | + |
|
| 1721 | + //add preview button |
|
| 1722 | + $preview_url = parent::add_query_args_and_nonce( |
|
| 1723 | + array( |
|
| 1724 | + 'message_type' => $message_template_group->message_type(), |
|
| 1725 | + 'messenger' => $message_template_group->messenger(), |
|
| 1726 | + 'context' => $context, |
|
| 1727 | + 'GRP_ID' => $GRP_ID, |
|
| 1728 | + 'action' => 'preview_message' |
|
| 1729 | + ), |
|
| 1730 | + $this->_admin_base_url |
|
| 1731 | + ); |
|
| 1732 | + $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">' |
|
| 1733 | + . esc_html__('Preview', 'event_espresso') |
|
| 1734 | + . '</a>'; |
|
| 1735 | + |
|
| 1736 | + |
|
| 1737 | + //setup context switcher |
|
| 1738 | + $context_switcher_args = array( |
|
| 1739 | + 'page' => 'espresso_messages', |
|
| 1740 | + 'action' => 'edit_message_template', |
|
| 1741 | + 'id' => $GRP_ID, |
|
| 1742 | + 'context' => $context, |
|
| 1743 | + 'extra' => $preview_button |
|
| 1744 | + ); |
|
| 1745 | + $this->_set_context_switcher($message_template_group, $context_switcher_args); |
|
| 1746 | + |
|
| 1747 | + |
|
| 1748 | + //main box |
|
| 1749 | + $this->_template_args['template_fields'] = $template_fields; |
|
| 1750 | + $this->_template_args['sidebar_box_id'] = 'details'; |
|
| 1751 | + $this->_template_args['action'] = $action; |
|
| 1752 | + $this->_template_args['context'] = $context; |
|
| 1753 | + $this->_template_args['edit_message_template_form_url'] = $edit_message_template_form_url; |
|
| 1754 | + $this->_template_args['learn_more_about_message_templates_link'] = |
|
| 1755 | + $this->_learn_more_about_message_templates_link(); |
|
| 1756 | + |
|
| 1757 | + |
|
| 1758 | + $this->_template_args['before_admin_page_content'] = $this->add_context_switcher(); |
|
| 1759 | + $this->_template_args['before_admin_page_content'] .= $this->add_active_context_element( |
|
| 1760 | + $message_template_group, |
|
| 1761 | + $context, |
|
| 1762 | + $context_label |
|
| 1763 | + ); |
|
| 1764 | + $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before(); |
|
| 1765 | + $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after(); |
|
| 1766 | + |
|
| 1767 | + $this->_template_path = $this->_template_args['GRP_ID'] |
|
| 1768 | + ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php' |
|
| 1769 | + : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php'; |
|
| 1770 | + |
|
| 1771 | + //send along EE_Message_Template_Group object for further template use. |
|
| 1772 | + $this->_template_args['MTP'] = $message_template_group; |
|
| 1773 | + |
|
| 1774 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 1775 | + $this->_template_path, |
|
| 1776 | + $this->_template_args, |
|
| 1777 | + true |
|
| 1778 | + ); |
|
| 1779 | + |
|
| 1780 | + |
|
| 1781 | + //finally, let's set the admin_page title |
|
| 1782 | + $this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title); |
|
| 1783 | + |
|
| 1784 | + |
|
| 1785 | + //we need to take care of setting the shortcodes property for use elsewhere. |
|
| 1786 | + $this->_set_shortcodes(); |
|
| 1787 | + |
|
| 1788 | + |
|
| 1789 | + //final template wrapper |
|
| 1790 | + $this->display_admin_page_with_sidebar(); |
|
| 1791 | + } |
|
| 1792 | 1792 | |
| 1793 | 1793 | |
| 1794 | - public function filter_tinymce_init($mceInit, $editor_id) |
|
| 1795 | - { |
|
| 1796 | - return $mceInit; |
|
| 1797 | - } |
|
| 1794 | + public function filter_tinymce_init($mceInit, $editor_id) |
|
| 1795 | + { |
|
| 1796 | + return $mceInit; |
|
| 1797 | + } |
|
| 1798 | 1798 | |
| 1799 | 1799 | |
| 1800 | - public function add_context_switcher() |
|
| 1801 | - { |
|
| 1802 | - return $this->_context_switcher; |
|
| 1803 | - } |
|
| 1800 | + public function add_context_switcher() |
|
| 1801 | + { |
|
| 1802 | + return $this->_context_switcher; |
|
| 1803 | + } |
|
| 1804 | 1804 | |
| 1805 | 1805 | |
| 1806 | - /** |
|
| 1807 | - * Adds the activation/deactivation toggle for the message template context. |
|
| 1808 | - * |
|
| 1809 | - * @param EE_Message_Template_Group $message_template_group |
|
| 1810 | - * @param string $context |
|
| 1811 | - * @param string $context_label |
|
| 1812 | - * @return string |
|
| 1813 | - * @throws DomainException |
|
| 1814 | - * @throws EE_Error |
|
| 1815 | - * @throws InvalidIdentifierException |
|
| 1816 | - */ |
|
| 1817 | - protected function add_active_context_element( |
|
| 1818 | - EE_Message_Template_Group $message_template_group, |
|
| 1819 | - $context, |
|
| 1820 | - $context_label |
|
| 1821 | - ) { |
|
| 1822 | - $template_args = array( |
|
| 1823 | - 'context' => $context, |
|
| 1824 | - 'nonce' => wp_create_nonce('activate_' . $context . '_toggle_nonce'), |
|
| 1825 | - 'is_active' => $message_template_group->is_context_active($context), |
|
| 1826 | - 'on_off_action' => $message_template_group->is_context_active($context) |
|
| 1827 | - ? 'context-off' |
|
| 1828 | - : 'context-on', |
|
| 1829 | - 'context_label' => str_replace(array('(', ')'), '', $context_label), |
|
| 1830 | - 'message_template_group_id' => $message_template_group->ID() |
|
| 1831 | - ); |
|
| 1832 | - return EEH_Template::display_template( |
|
| 1833 | - EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php', |
|
| 1834 | - $template_args, |
|
| 1835 | - true |
|
| 1836 | - ); |
|
| 1837 | - } |
|
| 1806 | + /** |
|
| 1807 | + * Adds the activation/deactivation toggle for the message template context. |
|
| 1808 | + * |
|
| 1809 | + * @param EE_Message_Template_Group $message_template_group |
|
| 1810 | + * @param string $context |
|
| 1811 | + * @param string $context_label |
|
| 1812 | + * @return string |
|
| 1813 | + * @throws DomainException |
|
| 1814 | + * @throws EE_Error |
|
| 1815 | + * @throws InvalidIdentifierException |
|
| 1816 | + */ |
|
| 1817 | + protected function add_active_context_element( |
|
| 1818 | + EE_Message_Template_Group $message_template_group, |
|
| 1819 | + $context, |
|
| 1820 | + $context_label |
|
| 1821 | + ) { |
|
| 1822 | + $template_args = array( |
|
| 1823 | + 'context' => $context, |
|
| 1824 | + 'nonce' => wp_create_nonce('activate_' . $context . '_toggle_nonce'), |
|
| 1825 | + 'is_active' => $message_template_group->is_context_active($context), |
|
| 1826 | + 'on_off_action' => $message_template_group->is_context_active($context) |
|
| 1827 | + ? 'context-off' |
|
| 1828 | + : 'context-on', |
|
| 1829 | + 'context_label' => str_replace(array('(', ')'), '', $context_label), |
|
| 1830 | + 'message_template_group_id' => $message_template_group->ID() |
|
| 1831 | + ); |
|
| 1832 | + return EEH_Template::display_template( |
|
| 1833 | + EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php', |
|
| 1834 | + $template_args, |
|
| 1835 | + true |
|
| 1836 | + ); |
|
| 1837 | + } |
|
| 1838 | 1838 | |
| 1839 | 1839 | |
| 1840 | - /** |
|
| 1841 | - * Ajax callback for `toggle_context_template` ajax action. |
|
| 1842 | - * Handles toggling the message context on or off. |
|
| 1843 | - * @throws EE_Error |
|
| 1844 | - * @throws InvalidArgumentException |
|
| 1845 | - * @throws InvalidDataTypeException |
|
| 1846 | - * @throws InvalidIdentifierException |
|
| 1847 | - * @throws InvalidInterfaceException |
|
| 1848 | - */ |
|
| 1849 | - public function toggle_context_template() |
|
| 1850 | - { |
|
| 1851 | - $success = true; |
|
| 1852 | - //check for required data |
|
| 1853 | - if (!isset( |
|
| 1854 | - $this->_req_data['message_template_group_id'], |
|
| 1855 | - $this->_req_data['context'], |
|
| 1856 | - $this->_req_data['status'] |
|
| 1857 | - )) { |
|
| 1858 | - EE_Error::add_error( |
|
| 1859 | - esc_html__('Required data for doing this action is not available.', 'event_espresso'), |
|
| 1860 | - __FILE__, |
|
| 1861 | - __FUNCTION__, |
|
| 1862 | - __LINE__ |
|
| 1863 | - ); |
|
| 1864 | - $success = false; |
|
| 1865 | - } |
|
| 1840 | + /** |
|
| 1841 | + * Ajax callback for `toggle_context_template` ajax action. |
|
| 1842 | + * Handles toggling the message context on or off. |
|
| 1843 | + * @throws EE_Error |
|
| 1844 | + * @throws InvalidArgumentException |
|
| 1845 | + * @throws InvalidDataTypeException |
|
| 1846 | + * @throws InvalidIdentifierException |
|
| 1847 | + * @throws InvalidInterfaceException |
|
| 1848 | + */ |
|
| 1849 | + public function toggle_context_template() |
|
| 1850 | + { |
|
| 1851 | + $success = true; |
|
| 1852 | + //check for required data |
|
| 1853 | + if (!isset( |
|
| 1854 | + $this->_req_data['message_template_group_id'], |
|
| 1855 | + $this->_req_data['context'], |
|
| 1856 | + $this->_req_data['status'] |
|
| 1857 | + )) { |
|
| 1858 | + EE_Error::add_error( |
|
| 1859 | + esc_html__('Required data for doing this action is not available.', 'event_espresso'), |
|
| 1860 | + __FILE__, |
|
| 1861 | + __FUNCTION__, |
|
| 1862 | + __LINE__ |
|
| 1863 | + ); |
|
| 1864 | + $success = false; |
|
| 1865 | + } |
|
| 1866 | 1866 | |
| 1867 | - $nonce = isset($this->_req_data['toggle_context_nonce']) |
|
| 1868 | - ? sanitize_text_field($this->_req_data['toggle_context_nonce']) |
|
| 1869 | - : ''; |
|
| 1870 | - $nonce_ref = 'activate_' . $this->_req_data['context'] . '_toggle_nonce'; |
|
| 1871 | - $this->_verify_nonce($nonce, $nonce_ref); |
|
| 1872 | - $status = $this->_req_data['status']; |
|
| 1873 | - if ($status !== 'off' && $status !=='on') { |
|
| 1874 | - EE_Error::add_error( |
|
| 1875 | - sprintf( |
|
| 1876 | - esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'), |
|
| 1877 | - $this->_req_data['status'] |
|
| 1878 | - ), |
|
| 1879 | - __FILE__, |
|
| 1880 | - __FUNCTION__, |
|
| 1881 | - __LINE__ |
|
| 1882 | - ); |
|
| 1883 | - $success = false; |
|
| 1884 | - } |
|
| 1885 | - $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID( |
|
| 1886 | - $this->_req_data['message_template_group_id'] |
|
| 1887 | - ); |
|
| 1888 | - if (! $message_template_group instanceof EE_Message_Template_Group) { |
|
| 1889 | - EE_Error::add_error( |
|
| 1890 | - sprintf( |
|
| 1891 | - esc_html__( |
|
| 1892 | - 'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"', |
|
| 1893 | - 'event_espresso' |
|
| 1894 | - ), |
|
| 1895 | - $this->_req_data['message_template_group_id'], |
|
| 1896 | - 'EE_Message_Template_Group' |
|
| 1897 | - ), |
|
| 1898 | - __FILE__, |
|
| 1899 | - __FUNCTION__, |
|
| 1900 | - __LINE__ |
|
| 1901 | - ); |
|
| 1902 | - $success = false; |
|
| 1903 | - } |
|
| 1904 | - if ($success) { |
|
| 1905 | - $success = $status === 'off' |
|
| 1906 | - ? $message_template_group->deactivate_context($this->_req_data['context']) |
|
| 1907 | - : $message_template_group->activate_context($this->_req_data['context']); |
|
| 1908 | - } |
|
| 1909 | - $this->_template_args['success'] = $success; |
|
| 1910 | - $this->_return_json(); |
|
| 1911 | - } |
|
| 1867 | + $nonce = isset($this->_req_data['toggle_context_nonce']) |
|
| 1868 | + ? sanitize_text_field($this->_req_data['toggle_context_nonce']) |
|
| 1869 | + : ''; |
|
| 1870 | + $nonce_ref = 'activate_' . $this->_req_data['context'] . '_toggle_nonce'; |
|
| 1871 | + $this->_verify_nonce($nonce, $nonce_ref); |
|
| 1872 | + $status = $this->_req_data['status']; |
|
| 1873 | + if ($status !== 'off' && $status !=='on') { |
|
| 1874 | + EE_Error::add_error( |
|
| 1875 | + sprintf( |
|
| 1876 | + esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'), |
|
| 1877 | + $this->_req_data['status'] |
|
| 1878 | + ), |
|
| 1879 | + __FILE__, |
|
| 1880 | + __FUNCTION__, |
|
| 1881 | + __LINE__ |
|
| 1882 | + ); |
|
| 1883 | + $success = false; |
|
| 1884 | + } |
|
| 1885 | + $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID( |
|
| 1886 | + $this->_req_data['message_template_group_id'] |
|
| 1887 | + ); |
|
| 1888 | + if (! $message_template_group instanceof EE_Message_Template_Group) { |
|
| 1889 | + EE_Error::add_error( |
|
| 1890 | + sprintf( |
|
| 1891 | + esc_html__( |
|
| 1892 | + 'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"', |
|
| 1893 | + 'event_espresso' |
|
| 1894 | + ), |
|
| 1895 | + $this->_req_data['message_template_group_id'], |
|
| 1896 | + 'EE_Message_Template_Group' |
|
| 1897 | + ), |
|
| 1898 | + __FILE__, |
|
| 1899 | + __FUNCTION__, |
|
| 1900 | + __LINE__ |
|
| 1901 | + ); |
|
| 1902 | + $success = false; |
|
| 1903 | + } |
|
| 1904 | + if ($success) { |
|
| 1905 | + $success = $status === 'off' |
|
| 1906 | + ? $message_template_group->deactivate_context($this->_req_data['context']) |
|
| 1907 | + : $message_template_group->activate_context($this->_req_data['context']); |
|
| 1908 | + } |
|
| 1909 | + $this->_template_args['success'] = $success; |
|
| 1910 | + $this->_return_json(); |
|
| 1911 | + } |
|
| 1912 | 1912 | |
| 1913 | 1913 | |
| 1914 | 1914 | |
| 1915 | - public function _add_form_element_before() |
|
| 1916 | - { |
|
| 1917 | - return '<form method="post" action="' |
|
| 1918 | - . $this->_template_args["edit_message_template_form_url"] |
|
| 1919 | - . '" id="ee-msg-edit-frm">'; |
|
| 1920 | - } |
|
| 1915 | + public function _add_form_element_before() |
|
| 1916 | + { |
|
| 1917 | + return '<form method="post" action="' |
|
| 1918 | + . $this->_template_args["edit_message_template_form_url"] |
|
| 1919 | + . '" id="ee-msg-edit-frm">'; |
|
| 1920 | + } |
|
| 1921 | 1921 | |
| 1922 | - public function _add_form_element_after() |
|
| 1923 | - { |
|
| 1924 | - return '</form>'; |
|
| 1925 | - } |
|
| 1922 | + public function _add_form_element_after() |
|
| 1923 | + { |
|
| 1924 | + return '</form>'; |
|
| 1925 | + } |
|
| 1926 | 1926 | |
| 1927 | 1927 | |
| 1928 | - /** |
|
| 1929 | - * This executes switching the template pack for a message template. |
|
| 1930 | - * |
|
| 1931 | - * @since 4.5.0 |
|
| 1932 | - * @throws EE_Error |
|
| 1933 | - * @throws InvalidDataTypeException |
|
| 1934 | - * @throws InvalidInterfaceException |
|
| 1935 | - * @throws InvalidArgumentException |
|
| 1936 | - * @throws ReflectionException |
|
| 1937 | - */ |
|
| 1938 | - public function switch_template_pack() |
|
| 1939 | - { |
|
| 1940 | - $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 1941 | - $template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : ''; |
|
| 1942 | - |
|
| 1943 | - //verify we have needed values. |
|
| 1944 | - if (empty($GRP_ID) || empty($template_pack)) { |
|
| 1945 | - $this->_template_args['error'] = true; |
|
| 1946 | - EE_Error::add_error( |
|
| 1947 | - esc_html__('The required date for switching templates is not available.', 'event_espresso'), |
|
| 1948 | - __FILE__, |
|
| 1949 | - __FUNCTION__, |
|
| 1950 | - __LINE__ |
|
| 1951 | - ); |
|
| 1952 | - } else { |
|
| 1953 | - //get template, set the new template_pack and then reset to default |
|
| 1954 | - /** @type EE_Message_Template_Group $message_template_group */ |
|
| 1955 | - $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
|
| 1928 | + /** |
|
| 1929 | + * This executes switching the template pack for a message template. |
|
| 1930 | + * |
|
| 1931 | + * @since 4.5.0 |
|
| 1932 | + * @throws EE_Error |
|
| 1933 | + * @throws InvalidDataTypeException |
|
| 1934 | + * @throws InvalidInterfaceException |
|
| 1935 | + * @throws InvalidArgumentException |
|
| 1936 | + * @throws ReflectionException |
|
| 1937 | + */ |
|
| 1938 | + public function switch_template_pack() |
|
| 1939 | + { |
|
| 1940 | + $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 1941 | + $template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : ''; |
|
| 1942 | + |
|
| 1943 | + //verify we have needed values. |
|
| 1944 | + if (empty($GRP_ID) || empty($template_pack)) { |
|
| 1945 | + $this->_template_args['error'] = true; |
|
| 1946 | + EE_Error::add_error( |
|
| 1947 | + esc_html__('The required date for switching templates is not available.', 'event_espresso'), |
|
| 1948 | + __FILE__, |
|
| 1949 | + __FUNCTION__, |
|
| 1950 | + __LINE__ |
|
| 1951 | + ); |
|
| 1952 | + } else { |
|
| 1953 | + //get template, set the new template_pack and then reset to default |
|
| 1954 | + /** @type EE_Message_Template_Group $message_template_group */ |
|
| 1955 | + $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
|
| 1956 | 1956 | |
| 1957 | - $message_template_group->set_template_pack_name($template_pack); |
|
| 1958 | - $this->_req_data['msgr'] = $message_template_group->messenger(); |
|
| 1959 | - $this->_req_data['mt'] = $message_template_group->message_type(); |
|
| 1957 | + $message_template_group->set_template_pack_name($template_pack); |
|
| 1958 | + $this->_req_data['msgr'] = $message_template_group->messenger(); |
|
| 1959 | + $this->_req_data['mt'] = $message_template_group->message_type(); |
|
| 1960 | 1960 | |
| 1961 | - $query_args = $this->_reset_to_default_template(); |
|
| 1961 | + $query_args = $this->_reset_to_default_template(); |
|
| 1962 | 1962 | |
| 1963 | - if (empty($query_args['id'])) { |
|
| 1964 | - EE_Error::add_error( |
|
| 1965 | - esc_html__( |
|
| 1966 | - 'Something went wrong with switching the template pack. Please try again or contact EE support', |
|
| 1967 | - 'event_espresso' |
|
| 1968 | - ), |
|
| 1969 | - __FILE__, |
|
| 1970 | - __FUNCTION__, |
|
| 1971 | - __LINE__ |
|
| 1972 | - ); |
|
| 1973 | - $this->_template_args['error'] = true; |
|
| 1974 | - } else { |
|
| 1975 | - $template_label = $message_template_group->get_template_pack()->label; |
|
| 1976 | - $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels(); |
|
| 1977 | - EE_Error::add_success( |
|
| 1978 | - sprintf( |
|
| 1979 | - esc_html__( |
|
| 1980 | - 'This message template has been successfully switched to use the %1$s %2$s. Please wait while the page reloads with your new template.', |
|
| 1981 | - 'event_espresso' |
|
| 1982 | - ), |
|
| 1983 | - $template_label, |
|
| 1984 | - $template_pack_labels->template_pack |
|
| 1985 | - ) |
|
| 1986 | - ); |
|
| 1987 | - //generate the redirect url for js. |
|
| 1988 | - $url = self::add_query_args_and_nonce($query_args, |
|
| 1989 | - $this->_admin_base_url); |
|
| 1990 | - $this->_template_args['data']['redirect_url'] = $url; |
|
| 1991 | - $this->_template_args['success'] = true; |
|
| 1992 | - } |
|
| 1963 | + if (empty($query_args['id'])) { |
|
| 1964 | + EE_Error::add_error( |
|
| 1965 | + esc_html__( |
|
| 1966 | + 'Something went wrong with switching the template pack. Please try again or contact EE support', |
|
| 1967 | + 'event_espresso' |
|
| 1968 | + ), |
|
| 1969 | + __FILE__, |
|
| 1970 | + __FUNCTION__, |
|
| 1971 | + __LINE__ |
|
| 1972 | + ); |
|
| 1973 | + $this->_template_args['error'] = true; |
|
| 1974 | + } else { |
|
| 1975 | + $template_label = $message_template_group->get_template_pack()->label; |
|
| 1976 | + $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels(); |
|
| 1977 | + EE_Error::add_success( |
|
| 1978 | + sprintf( |
|
| 1979 | + esc_html__( |
|
| 1980 | + 'This message template has been successfully switched to use the %1$s %2$s. Please wait while the page reloads with your new template.', |
|
| 1981 | + 'event_espresso' |
|
| 1982 | + ), |
|
| 1983 | + $template_label, |
|
| 1984 | + $template_pack_labels->template_pack |
|
| 1985 | + ) |
|
| 1986 | + ); |
|
| 1987 | + //generate the redirect url for js. |
|
| 1988 | + $url = self::add_query_args_and_nonce($query_args, |
|
| 1989 | + $this->_admin_base_url); |
|
| 1990 | + $this->_template_args['data']['redirect_url'] = $url; |
|
| 1991 | + $this->_template_args['success'] = true; |
|
| 1992 | + } |
|
| 1993 | 1993 | |
| 1994 | - $this->_return_json(); |
|
| 1994 | + $this->_return_json(); |
|
| 1995 | 1995 | |
| 1996 | - } |
|
| 1997 | - } |
|
| 1996 | + } |
|
| 1997 | + } |
|
| 1998 | 1998 | |
| 1999 | 1999 | |
| 2000 | - /** |
|
| 2001 | - * This handles resetting the template for the given messenger/message_type so that users can start from scratch if |
|
| 2002 | - * they want. |
|
| 2003 | - * |
|
| 2004 | - * @access protected |
|
| 2005 | - * @return array|null |
|
| 2006 | - * @throws EE_Error |
|
| 2007 | - * @throws InvalidArgumentException |
|
| 2008 | - * @throws InvalidDataTypeException |
|
| 2009 | - * @throws InvalidInterfaceException |
|
| 2010 | - */ |
|
| 2011 | - protected function _reset_to_default_template() |
|
| 2012 | - { |
|
| 2013 | - |
|
| 2014 | - $templates = array(); |
|
| 2015 | - $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 2016 | - //we need to make sure we've got the info we need. |
|
| 2017 | - if ( ! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) { |
|
| 2018 | - EE_Error::add_error( |
|
| 2019 | - esc_html__( |
|
| 2020 | - 'In order to reset the template to its default we require the messenger, message type, and message template GRP_ID to know what is being reset. At least one of these is missing.', |
|
| 2021 | - 'event_espresso' |
|
| 2022 | - ), |
|
| 2023 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 2024 | - ); |
|
| 2025 | - } |
|
| 2026 | - |
|
| 2027 | - // all templates will be reset to whatever the defaults are |
|
| 2028 | - // for the global template matching the messenger and message type. |
|
| 2029 | - $success = ! empty($GRP_ID) ? true : false; |
|
| 2030 | - |
|
| 2031 | - if ($success) { |
|
| 2000 | + /** |
|
| 2001 | + * This handles resetting the template for the given messenger/message_type so that users can start from scratch if |
|
| 2002 | + * they want. |
|
| 2003 | + * |
|
| 2004 | + * @access protected |
|
| 2005 | + * @return array|null |
|
| 2006 | + * @throws EE_Error |
|
| 2007 | + * @throws InvalidArgumentException |
|
| 2008 | + * @throws InvalidDataTypeException |
|
| 2009 | + * @throws InvalidInterfaceException |
|
| 2010 | + */ |
|
| 2011 | + protected function _reset_to_default_template() |
|
| 2012 | + { |
|
| 2013 | + |
|
| 2014 | + $templates = array(); |
|
| 2015 | + $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 2016 | + //we need to make sure we've got the info we need. |
|
| 2017 | + if ( ! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) { |
|
| 2018 | + EE_Error::add_error( |
|
| 2019 | + esc_html__( |
|
| 2020 | + 'In order to reset the template to its default we require the messenger, message type, and message template GRP_ID to know what is being reset. At least one of these is missing.', |
|
| 2021 | + 'event_espresso' |
|
| 2022 | + ), |
|
| 2023 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 2024 | + ); |
|
| 2025 | + } |
|
| 2026 | + |
|
| 2027 | + // all templates will be reset to whatever the defaults are |
|
| 2028 | + // for the global template matching the messenger and message type. |
|
| 2029 | + $success = ! empty($GRP_ID) ? true : false; |
|
| 2030 | + |
|
| 2031 | + if ($success) { |
|
| 2032 | 2032 | |
| 2033 | - //let's first determine if the incoming template is a global template, |
|
| 2034 | - // if it isn't then we need to get the global template matching messenger and message type. |
|
| 2035 | - //$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID ); |
|
| 2033 | + //let's first determine if the incoming template is a global template, |
|
| 2034 | + // if it isn't then we need to get the global template matching messenger and message type. |
|
| 2035 | + //$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID ); |
|
| 2036 | 2036 | |
| 2037 | 2037 | |
| 2038 | - //note this is ONLY deleting the template fields (Message Template rows) NOT the message template group. |
|
| 2039 | - $success = $this->_delete_mtp_permanently($GRP_ID, false); |
|
| 2038 | + //note this is ONLY deleting the template fields (Message Template rows) NOT the message template group. |
|
| 2039 | + $success = $this->_delete_mtp_permanently($GRP_ID, false); |
|
| 2040 | 2040 | |
| 2041 | - if ($success) { |
|
| 2042 | - // if successfully deleted, lets generate the new ones. |
|
| 2043 | - // Note. We set GLOBAL to true, because resets on ANY template |
|
| 2044 | - // will use the related global template defaults for regeneration. |
|
| 2045 | - // This means that if a custom template is reset it resets to whatever the related global template is. |
|
| 2046 | - // HOWEVER, we DO keep the template pack and template variation set |
|
| 2047 | - // for the current custom template when resetting. |
|
| 2048 | - $templates = $this->_generate_new_templates( |
|
| 2049 | - $this->_req_data['msgr'], |
|
| 2050 | - $this->_req_data['mt'], |
|
| 2051 | - $GRP_ID, |
|
| 2052 | - true |
|
| 2053 | - ); |
|
| 2054 | - } |
|
| 2041 | + if ($success) { |
|
| 2042 | + // if successfully deleted, lets generate the new ones. |
|
| 2043 | + // Note. We set GLOBAL to true, because resets on ANY template |
|
| 2044 | + // will use the related global template defaults for regeneration. |
|
| 2045 | + // This means that if a custom template is reset it resets to whatever the related global template is. |
|
| 2046 | + // HOWEVER, we DO keep the template pack and template variation set |
|
| 2047 | + // for the current custom template when resetting. |
|
| 2048 | + $templates = $this->_generate_new_templates( |
|
| 2049 | + $this->_req_data['msgr'], |
|
| 2050 | + $this->_req_data['mt'], |
|
| 2051 | + $GRP_ID, |
|
| 2052 | + true |
|
| 2053 | + ); |
|
| 2054 | + } |
|
| 2055 | 2055 | |
| 2056 | - } |
|
| 2057 | - |
|
| 2058 | - //any error messages? |
|
| 2059 | - if ( ! $success) { |
|
| 2060 | - EE_Error::add_error( |
|
| 2061 | - esc_html__('Something went wrong with deleting existing templates. Unable to reset to default', |
|
| 2062 | - 'event_espresso'), |
|
| 2063 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 2064 | - ); |
|
| 2065 | - } |
|
| 2066 | - |
|
| 2067 | - //all good, let's add a success message! |
|
| 2068 | - if ($success && ! empty($templates)) { |
|
| 2069 | - //the info for the template we generated is the first element in the returned array |
|
| 2070 | - // $templates = $templates[0]; |
|
| 2071 | - EE_Error::overwrite_success(); |
|
| 2072 | - EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso')); |
|
| 2073 | - } |
|
| 2074 | - |
|
| 2075 | - |
|
| 2076 | - $query_args = array( |
|
| 2077 | - 'id' => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null, |
|
| 2078 | - 'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null, |
|
| 2079 | - 'action' => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps' |
|
| 2080 | - ); |
|
| 2081 | - |
|
| 2082 | - //if called via ajax then we return query args otherwise redirect |
|
| 2083 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2084 | - return $query_args; |
|
| 2085 | - } else { |
|
| 2086 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 2056 | + } |
|
| 2057 | + |
|
| 2058 | + //any error messages? |
|
| 2059 | + if ( ! $success) { |
|
| 2060 | + EE_Error::add_error( |
|
| 2061 | + esc_html__('Something went wrong with deleting existing templates. Unable to reset to default', |
|
| 2062 | + 'event_espresso'), |
|
| 2063 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 2064 | + ); |
|
| 2065 | + } |
|
| 2066 | + |
|
| 2067 | + //all good, let's add a success message! |
|
| 2068 | + if ($success && ! empty($templates)) { |
|
| 2069 | + //the info for the template we generated is the first element in the returned array |
|
| 2070 | + // $templates = $templates[0]; |
|
| 2071 | + EE_Error::overwrite_success(); |
|
| 2072 | + EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso')); |
|
| 2073 | + } |
|
| 2074 | + |
|
| 2075 | + |
|
| 2076 | + $query_args = array( |
|
| 2077 | + 'id' => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null, |
|
| 2078 | + 'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null, |
|
| 2079 | + 'action' => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps' |
|
| 2080 | + ); |
|
| 2081 | + |
|
| 2082 | + //if called via ajax then we return query args otherwise redirect |
|
| 2083 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2084 | + return $query_args; |
|
| 2085 | + } else { |
|
| 2086 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 2087 | 2087 | |
| 2088 | - return null; |
|
| 2089 | - } |
|
| 2090 | - } |
|
| 2088 | + return null; |
|
| 2089 | + } |
|
| 2090 | + } |
|
| 2091 | 2091 | |
| 2092 | 2092 | |
| 2093 | - /** |
|
| 2094 | - * Retrieve and set the message preview for display. |
|
| 2095 | - * |
|
| 2096 | - * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview. |
|
| 2097 | - * @return string |
|
| 2098 | - * @throws ReflectionException |
|
| 2099 | - * @throws EE_Error |
|
| 2100 | - * @throws InvalidArgumentException |
|
| 2101 | - * @throws InvalidDataTypeException |
|
| 2102 | - * @throws InvalidInterfaceException |
|
| 2103 | - */ |
|
| 2104 | - public function _preview_message($send = false) |
|
| 2105 | - { |
|
| 2106 | - //first make sure we've got the necessary parameters |
|
| 2107 | - if ( |
|
| 2108 | - ! isset( |
|
| 2109 | - $this->_req_data['message_type'], |
|
| 2110 | - $this->_req_data['messenger'], |
|
| 2111 | - $this->_req_data['messenger'], |
|
| 2112 | - $this->_req_data['GRP_ID'] |
|
| 2113 | - ) |
|
| 2114 | - ) { |
|
| 2115 | - EE_Error::add_error( |
|
| 2116 | - esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'), |
|
| 2117 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 2118 | - ); |
|
| 2119 | - } |
|
| 2120 | - |
|
| 2121 | - EE_Registry::instance()->REQ->set('GRP_ID', $this->_req_data['GRP_ID']); |
|
| 2122 | - |
|
| 2123 | - |
|
| 2124 | - //get the preview! |
|
| 2125 | - $preview = EED_Messages::preview_message($this->_req_data['message_type'], $this->_req_data['context'], |
|
| 2126 | - $this->_req_data['messenger'], $send); |
|
| 2127 | - |
|
| 2128 | - if ($send) { |
|
| 2129 | - return $preview; |
|
| 2130 | - } |
|
| 2131 | - |
|
| 2132 | - //let's add a button to go back to the edit view |
|
| 2133 | - $query_args = array( |
|
| 2134 | - 'id' => $this->_req_data['GRP_ID'], |
|
| 2135 | - 'context' => $this->_req_data['context'], |
|
| 2136 | - 'action' => 'edit_message_template' |
|
| 2137 | - ); |
|
| 2138 | - $go_back_url = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 2139 | - $preview_button = '<a href="' |
|
| 2140 | - . $go_back_url |
|
| 2141 | - . '" class="button-secondary messages-preview-go-back-button">' |
|
| 2142 | - . esc_html__('Go Back to Edit', 'event_espresso') |
|
| 2143 | - . '</a>'; |
|
| 2144 | - $message_types = $this->get_installed_message_types(); |
|
| 2145 | - $active_messenger = $this->_message_resource_manager->get_active_messenger( |
|
| 2146 | - $this->_req_data['messenger'] |
|
| 2147 | - ); |
|
| 2148 | - $active_messenger_label = $active_messenger instanceof EE_messenger |
|
| 2149 | - ? ucwords($active_messenger->label['singular']) |
|
| 2150 | - : esc_html__('Unknown Messenger', 'event_espresso'); |
|
| 2151 | - //let's provide a helpful title for context |
|
| 2152 | - $preview_title = sprintf( |
|
| 2153 | - esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'), |
|
| 2154 | - $active_messenger_label, |
|
| 2155 | - ucwords($message_types[$this->_req_data['message_type']]->label['singular']) |
|
| 2156 | - ); |
|
| 2157 | - //setup display of preview. |
|
| 2158 | - $this->_admin_page_title = $preview_title; |
|
| 2159 | - $this->_template_args['admin_page_content'] = $preview_button . '<br />' . stripslashes($preview); |
|
| 2160 | - $this->_template_args['data']['force_json'] = true; |
|
| 2161 | - |
|
| 2162 | - return ''; |
|
| 2163 | - } |
|
| 2093 | + /** |
|
| 2094 | + * Retrieve and set the message preview for display. |
|
| 2095 | + * |
|
| 2096 | + * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview. |
|
| 2097 | + * @return string |
|
| 2098 | + * @throws ReflectionException |
|
| 2099 | + * @throws EE_Error |
|
| 2100 | + * @throws InvalidArgumentException |
|
| 2101 | + * @throws InvalidDataTypeException |
|
| 2102 | + * @throws InvalidInterfaceException |
|
| 2103 | + */ |
|
| 2104 | + public function _preview_message($send = false) |
|
| 2105 | + { |
|
| 2106 | + //first make sure we've got the necessary parameters |
|
| 2107 | + if ( |
|
| 2108 | + ! isset( |
|
| 2109 | + $this->_req_data['message_type'], |
|
| 2110 | + $this->_req_data['messenger'], |
|
| 2111 | + $this->_req_data['messenger'], |
|
| 2112 | + $this->_req_data['GRP_ID'] |
|
| 2113 | + ) |
|
| 2114 | + ) { |
|
| 2115 | + EE_Error::add_error( |
|
| 2116 | + esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'), |
|
| 2117 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 2118 | + ); |
|
| 2119 | + } |
|
| 2120 | + |
|
| 2121 | + EE_Registry::instance()->REQ->set('GRP_ID', $this->_req_data['GRP_ID']); |
|
| 2122 | + |
|
| 2123 | + |
|
| 2124 | + //get the preview! |
|
| 2125 | + $preview = EED_Messages::preview_message($this->_req_data['message_type'], $this->_req_data['context'], |
|
| 2126 | + $this->_req_data['messenger'], $send); |
|
| 2127 | + |
|
| 2128 | + if ($send) { |
|
| 2129 | + return $preview; |
|
| 2130 | + } |
|
| 2131 | + |
|
| 2132 | + //let's add a button to go back to the edit view |
|
| 2133 | + $query_args = array( |
|
| 2134 | + 'id' => $this->_req_data['GRP_ID'], |
|
| 2135 | + 'context' => $this->_req_data['context'], |
|
| 2136 | + 'action' => 'edit_message_template' |
|
| 2137 | + ); |
|
| 2138 | + $go_back_url = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 2139 | + $preview_button = '<a href="' |
|
| 2140 | + . $go_back_url |
|
| 2141 | + . '" class="button-secondary messages-preview-go-back-button">' |
|
| 2142 | + . esc_html__('Go Back to Edit', 'event_espresso') |
|
| 2143 | + . '</a>'; |
|
| 2144 | + $message_types = $this->get_installed_message_types(); |
|
| 2145 | + $active_messenger = $this->_message_resource_manager->get_active_messenger( |
|
| 2146 | + $this->_req_data['messenger'] |
|
| 2147 | + ); |
|
| 2148 | + $active_messenger_label = $active_messenger instanceof EE_messenger |
|
| 2149 | + ? ucwords($active_messenger->label['singular']) |
|
| 2150 | + : esc_html__('Unknown Messenger', 'event_espresso'); |
|
| 2151 | + //let's provide a helpful title for context |
|
| 2152 | + $preview_title = sprintf( |
|
| 2153 | + esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'), |
|
| 2154 | + $active_messenger_label, |
|
| 2155 | + ucwords($message_types[$this->_req_data['message_type']]->label['singular']) |
|
| 2156 | + ); |
|
| 2157 | + //setup display of preview. |
|
| 2158 | + $this->_admin_page_title = $preview_title; |
|
| 2159 | + $this->_template_args['admin_page_content'] = $preview_button . '<br />' . stripslashes($preview); |
|
| 2160 | + $this->_template_args['data']['force_json'] = true; |
|
| 2161 | + |
|
| 2162 | + return ''; |
|
| 2163 | + } |
|
| 2164 | 2164 | |
| 2165 | 2165 | |
| 2166 | - /** |
|
| 2167 | - * The initial _preview_message is on a no headers route. It will optionally call this if necessary otherwise it |
|
| 2168 | - * gets called automatically. |
|
| 2169 | - * |
|
| 2170 | - * @since 4.5.0 |
|
| 2171 | - * |
|
| 2172 | - * @return string |
|
| 2173 | - */ |
|
| 2174 | - protected function _display_preview_message() |
|
| 2175 | - { |
|
| 2176 | - $this->display_admin_page_with_no_sidebar(); |
|
| 2177 | - } |
|
| 2166 | + /** |
|
| 2167 | + * The initial _preview_message is on a no headers route. It will optionally call this if necessary otherwise it |
|
| 2168 | + * gets called automatically. |
|
| 2169 | + * |
|
| 2170 | + * @since 4.5.0 |
|
| 2171 | + * |
|
| 2172 | + * @return string |
|
| 2173 | + */ |
|
| 2174 | + protected function _display_preview_message() |
|
| 2175 | + { |
|
| 2176 | + $this->display_admin_page_with_no_sidebar(); |
|
| 2177 | + } |
|
| 2178 | 2178 | |
| 2179 | 2179 | |
| 2180 | - /** |
|
| 2181 | - * registers metaboxes that should show up on the "edit_message_template" page |
|
| 2182 | - * |
|
| 2183 | - * @access protected |
|
| 2184 | - * @return void |
|
| 2185 | - */ |
|
| 2186 | - protected function _register_edit_meta_boxes() |
|
| 2187 | - { |
|
| 2188 | - add_meta_box( |
|
| 2189 | - 'mtp_valid_shortcodes', |
|
| 2190 | - esc_html__('Valid Shortcodes', 'event_espresso'), |
|
| 2191 | - array($this, 'shortcode_meta_box'), |
|
| 2192 | - $this->_current_screen->id, |
|
| 2193 | - 'side', |
|
| 2194 | - 'default'); |
|
| 2195 | - add_meta_box( |
|
| 2196 | - 'mtp_extra_actions', |
|
| 2197 | - esc_html__('Extra Actions', 'event_espresso'), |
|
| 2198 | - array($this, 'extra_actions_meta_box'), |
|
| 2199 | - $this->_current_screen->id, |
|
| 2200 | - 'side', |
|
| 2201 | - 'high' |
|
| 2202 | - ); |
|
| 2203 | - add_meta_box( |
|
| 2204 | - 'mtp_templates', |
|
| 2205 | - esc_html__('Template Styles', 'event_espresso'), |
|
| 2206 | - array($this, 'template_pack_meta_box'), |
|
| 2207 | - $this->_current_screen->id, |
|
| 2208 | - 'side', |
|
| 2209 | - 'high' |
|
| 2210 | - ); |
|
| 2211 | - } |
|
| 2180 | + /** |
|
| 2181 | + * registers metaboxes that should show up on the "edit_message_template" page |
|
| 2182 | + * |
|
| 2183 | + * @access protected |
|
| 2184 | + * @return void |
|
| 2185 | + */ |
|
| 2186 | + protected function _register_edit_meta_boxes() |
|
| 2187 | + { |
|
| 2188 | + add_meta_box( |
|
| 2189 | + 'mtp_valid_shortcodes', |
|
| 2190 | + esc_html__('Valid Shortcodes', 'event_espresso'), |
|
| 2191 | + array($this, 'shortcode_meta_box'), |
|
| 2192 | + $this->_current_screen->id, |
|
| 2193 | + 'side', |
|
| 2194 | + 'default'); |
|
| 2195 | + add_meta_box( |
|
| 2196 | + 'mtp_extra_actions', |
|
| 2197 | + esc_html__('Extra Actions', 'event_espresso'), |
|
| 2198 | + array($this, 'extra_actions_meta_box'), |
|
| 2199 | + $this->_current_screen->id, |
|
| 2200 | + 'side', |
|
| 2201 | + 'high' |
|
| 2202 | + ); |
|
| 2203 | + add_meta_box( |
|
| 2204 | + 'mtp_templates', |
|
| 2205 | + esc_html__('Template Styles', 'event_espresso'), |
|
| 2206 | + array($this, 'template_pack_meta_box'), |
|
| 2207 | + $this->_current_screen->id, |
|
| 2208 | + 'side', |
|
| 2209 | + 'high' |
|
| 2210 | + ); |
|
| 2211 | + } |
|
| 2212 | 2212 | |
| 2213 | 2213 | |
| 2214 | - /** |
|
| 2215 | - * metabox content for all template pack and variation selection. |
|
| 2216 | - * |
|
| 2217 | - * @since 4.5.0 |
|
| 2218 | - * @return string |
|
| 2219 | - * @throws DomainException |
|
| 2220 | - * @throws EE_Error |
|
| 2221 | - * @throws InvalidArgumentException |
|
| 2222 | - * @throws ReflectionException |
|
| 2223 | - * @throws InvalidDataTypeException |
|
| 2224 | - * @throws InvalidInterfaceException |
|
| 2225 | - */ |
|
| 2226 | - public function template_pack_meta_box() |
|
| 2227 | - { |
|
| 2228 | - $this->_set_message_template_group(); |
|
| 2229 | - |
|
| 2230 | - $tp_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
| 2231 | - |
|
| 2232 | - $tp_select_values = array(); |
|
| 2233 | - |
|
| 2234 | - foreach ($tp_collection as $tp) { |
|
| 2235 | - //only include template packs that support this messenger and message type! |
|
| 2236 | - $supports = $tp->get_supports(); |
|
| 2237 | - if ( |
|
| 2238 | - ! isset($supports[$this->_message_template_group->messenger()]) |
|
| 2239 | - || ! in_array( |
|
| 2240 | - $this->_message_template_group->message_type(), |
|
| 2241 | - $supports[$this->_message_template_group->messenger()], |
|
| 2242 | - true |
|
| 2243 | - ) |
|
| 2244 | - ) { |
|
| 2245 | - //not supported |
|
| 2246 | - continue; |
|
| 2247 | - } |
|
| 2214 | + /** |
|
| 2215 | + * metabox content for all template pack and variation selection. |
|
| 2216 | + * |
|
| 2217 | + * @since 4.5.0 |
|
| 2218 | + * @return string |
|
| 2219 | + * @throws DomainException |
|
| 2220 | + * @throws EE_Error |
|
| 2221 | + * @throws InvalidArgumentException |
|
| 2222 | + * @throws ReflectionException |
|
| 2223 | + * @throws InvalidDataTypeException |
|
| 2224 | + * @throws InvalidInterfaceException |
|
| 2225 | + */ |
|
| 2226 | + public function template_pack_meta_box() |
|
| 2227 | + { |
|
| 2228 | + $this->_set_message_template_group(); |
|
| 2229 | + |
|
| 2230 | + $tp_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
| 2231 | + |
|
| 2232 | + $tp_select_values = array(); |
|
| 2233 | + |
|
| 2234 | + foreach ($tp_collection as $tp) { |
|
| 2235 | + //only include template packs that support this messenger and message type! |
|
| 2236 | + $supports = $tp->get_supports(); |
|
| 2237 | + if ( |
|
| 2238 | + ! isset($supports[$this->_message_template_group->messenger()]) |
|
| 2239 | + || ! in_array( |
|
| 2240 | + $this->_message_template_group->message_type(), |
|
| 2241 | + $supports[$this->_message_template_group->messenger()], |
|
| 2242 | + true |
|
| 2243 | + ) |
|
| 2244 | + ) { |
|
| 2245 | + //not supported |
|
| 2246 | + continue; |
|
| 2247 | + } |
|
| 2248 | 2248 | |
| 2249 | - $tp_select_values[] = array( |
|
| 2250 | - 'text' => $tp->label, |
|
| 2251 | - 'id' => $tp->dbref |
|
| 2252 | - ); |
|
| 2253 | - } |
|
| 2254 | - |
|
| 2255 | - //if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by |
|
| 2256 | - // the default template pack. This still allows for the odd template pack to override. |
|
| 2257 | - if (empty($tp_select_values)) { |
|
| 2258 | - $tp_select_values[] = array( |
|
| 2259 | - 'text' => esc_html__('Default', 'event_espresso'), |
|
| 2260 | - 'id' => 'default' |
|
| 2261 | - ); |
|
| 2262 | - } |
|
| 2263 | - |
|
| 2264 | - //setup variation select values for the currently selected template. |
|
| 2265 | - $variations = $this->_message_template_group->get_template_pack()->get_variations( |
|
| 2266 | - $this->_message_template_group->messenger(), |
|
| 2267 | - $this->_message_template_group->message_type() |
|
| 2268 | - ); |
|
| 2269 | - $variations_select_values = array(); |
|
| 2270 | - foreach ($variations as $variation => $label) { |
|
| 2271 | - $variations_select_values[] = array( |
|
| 2272 | - 'text' => $label, |
|
| 2273 | - 'id' => $variation |
|
| 2274 | - ); |
|
| 2275 | - } |
|
| 2276 | - |
|
| 2277 | - $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels(); |
|
| 2278 | - |
|
| 2279 | - $template_args['template_packs_selector'] = EEH_Form_Fields::select_input( |
|
| 2280 | - 'MTP_template_pack', |
|
| 2281 | - $tp_select_values, |
|
| 2282 | - $this->_message_template_group->get_template_pack_name() |
|
| 2283 | - ); |
|
| 2284 | - $template_args['variations_selector'] = EEH_Form_Fields::select_input( |
|
| 2285 | - 'MTP_template_variation', |
|
| 2286 | - $variations_select_values, |
|
| 2287 | - $this->_message_template_group->get_template_pack_variation() |
|
| 2288 | - ); |
|
| 2289 | - $template_args['template_pack_label'] = $template_pack_labels->template_pack; |
|
| 2290 | - $template_args['template_variation_label'] = $template_pack_labels->template_variation; |
|
| 2291 | - $template_args['template_pack_description'] = $template_pack_labels->template_pack_description; |
|
| 2292 | - $template_args['template_variation_description'] = $template_pack_labels->template_variation_description; |
|
| 2293 | - |
|
| 2294 | - $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php'; |
|
| 2295 | - |
|
| 2296 | - EEH_Template::display_template($template, $template_args); |
|
| 2297 | - } |
|
| 2249 | + $tp_select_values[] = array( |
|
| 2250 | + 'text' => $tp->label, |
|
| 2251 | + 'id' => $tp->dbref |
|
| 2252 | + ); |
|
| 2253 | + } |
|
| 2254 | + |
|
| 2255 | + //if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by |
|
| 2256 | + // the default template pack. This still allows for the odd template pack to override. |
|
| 2257 | + if (empty($tp_select_values)) { |
|
| 2258 | + $tp_select_values[] = array( |
|
| 2259 | + 'text' => esc_html__('Default', 'event_espresso'), |
|
| 2260 | + 'id' => 'default' |
|
| 2261 | + ); |
|
| 2262 | + } |
|
| 2263 | + |
|
| 2264 | + //setup variation select values for the currently selected template. |
|
| 2265 | + $variations = $this->_message_template_group->get_template_pack()->get_variations( |
|
| 2266 | + $this->_message_template_group->messenger(), |
|
| 2267 | + $this->_message_template_group->message_type() |
|
| 2268 | + ); |
|
| 2269 | + $variations_select_values = array(); |
|
| 2270 | + foreach ($variations as $variation => $label) { |
|
| 2271 | + $variations_select_values[] = array( |
|
| 2272 | + 'text' => $label, |
|
| 2273 | + 'id' => $variation |
|
| 2274 | + ); |
|
| 2275 | + } |
|
| 2276 | + |
|
| 2277 | + $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels(); |
|
| 2278 | + |
|
| 2279 | + $template_args['template_packs_selector'] = EEH_Form_Fields::select_input( |
|
| 2280 | + 'MTP_template_pack', |
|
| 2281 | + $tp_select_values, |
|
| 2282 | + $this->_message_template_group->get_template_pack_name() |
|
| 2283 | + ); |
|
| 2284 | + $template_args['variations_selector'] = EEH_Form_Fields::select_input( |
|
| 2285 | + 'MTP_template_variation', |
|
| 2286 | + $variations_select_values, |
|
| 2287 | + $this->_message_template_group->get_template_pack_variation() |
|
| 2288 | + ); |
|
| 2289 | + $template_args['template_pack_label'] = $template_pack_labels->template_pack; |
|
| 2290 | + $template_args['template_variation_label'] = $template_pack_labels->template_variation; |
|
| 2291 | + $template_args['template_pack_description'] = $template_pack_labels->template_pack_description; |
|
| 2292 | + $template_args['template_variation_description'] = $template_pack_labels->template_variation_description; |
|
| 2293 | + |
|
| 2294 | + $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php'; |
|
| 2295 | + |
|
| 2296 | + EEH_Template::display_template($template, $template_args); |
|
| 2297 | + } |
|
| 2298 | 2298 | |
| 2299 | 2299 | |
| 2300 | - /** |
|
| 2301 | - * This meta box holds any extra actions related to Message Templates |
|
| 2302 | - * For now, this includes Resetting templates to defaults and sending a test email. |
|
| 2303 | - * |
|
| 2304 | - * @access public |
|
| 2305 | - * @return void |
|
| 2306 | - * @throws EE_Error |
|
| 2307 | - */ |
|
| 2308 | - public function extra_actions_meta_box() |
|
| 2309 | - { |
|
| 2310 | - $template_form_fields = array(); |
|
| 2311 | - |
|
| 2312 | - $extra_args = array( |
|
| 2313 | - 'msgr' => $this->_message_template_group->messenger(), |
|
| 2314 | - 'mt' => $this->_message_template_group->message_type(), |
|
| 2315 | - 'GRP_ID' => $this->_message_template_group->GRP_ID() |
|
| 2316 | - ); |
|
| 2317 | - //first we need to see if there are any fields |
|
| 2318 | - $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields(); |
|
| 2319 | - |
|
| 2320 | - if ( ! empty($fields)) { |
|
| 2321 | - //yup there be fields |
|
| 2322 | - foreach ($fields as $field => $config) { |
|
| 2323 | - $field_id = $this->_message_template_group->messenger() . '_' . $field; |
|
| 2324 | - $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings(); |
|
| 2325 | - $default = isset($config['default']) ? $config['default'] : ''; |
|
| 2326 | - $default = isset($config['value']) ? $config['value'] : $default; |
|
| 2300 | + /** |
|
| 2301 | + * This meta box holds any extra actions related to Message Templates |
|
| 2302 | + * For now, this includes Resetting templates to defaults and sending a test email. |
|
| 2303 | + * |
|
| 2304 | + * @access public |
|
| 2305 | + * @return void |
|
| 2306 | + * @throws EE_Error |
|
| 2307 | + */ |
|
| 2308 | + public function extra_actions_meta_box() |
|
| 2309 | + { |
|
| 2310 | + $template_form_fields = array(); |
|
| 2311 | + |
|
| 2312 | + $extra_args = array( |
|
| 2313 | + 'msgr' => $this->_message_template_group->messenger(), |
|
| 2314 | + 'mt' => $this->_message_template_group->message_type(), |
|
| 2315 | + 'GRP_ID' => $this->_message_template_group->GRP_ID() |
|
| 2316 | + ); |
|
| 2317 | + //first we need to see if there are any fields |
|
| 2318 | + $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields(); |
|
| 2319 | + |
|
| 2320 | + if ( ! empty($fields)) { |
|
| 2321 | + //yup there be fields |
|
| 2322 | + foreach ($fields as $field => $config) { |
|
| 2323 | + $field_id = $this->_message_template_group->messenger() . '_' . $field; |
|
| 2324 | + $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings(); |
|
| 2325 | + $default = isset($config['default']) ? $config['default'] : ''; |
|
| 2326 | + $default = isset($config['value']) ? $config['value'] : $default; |
|
| 2327 | 2327 | |
| 2328 | - // if type is hidden and the value is empty |
|
| 2329 | - // something may have gone wrong so let's correct with the defaults |
|
| 2330 | - $fix = $config['input'] === 'hidden' |
|
| 2331 | - && isset($existing[$field]) |
|
| 2332 | - && empty($existing[$field]) |
|
| 2333 | - ? $default |
|
| 2334 | - : ''; |
|
| 2335 | - $existing[$field] = isset($existing[$field]) && empty($fix) |
|
| 2336 | - ? $existing[$field] |
|
| 2337 | - : $fix; |
|
| 2328 | + // if type is hidden and the value is empty |
|
| 2329 | + // something may have gone wrong so let's correct with the defaults |
|
| 2330 | + $fix = $config['input'] === 'hidden' |
|
| 2331 | + && isset($existing[$field]) |
|
| 2332 | + && empty($existing[$field]) |
|
| 2333 | + ? $default |
|
| 2334 | + : ''; |
|
| 2335 | + $existing[$field] = isset($existing[$field]) && empty($fix) |
|
| 2336 | + ? $existing[$field] |
|
| 2337 | + : $fix; |
|
| 2338 | 2338 | |
| 2339 | - $template_form_fields[$field_id] = array( |
|
| 2340 | - 'name' => 'test_settings_fld[' . $field . ']', |
|
| 2341 | - 'label' => $config['label'], |
|
| 2342 | - 'input' => $config['input'], |
|
| 2343 | - 'type' => $config['type'], |
|
| 2344 | - 'required' => $config['required'], |
|
| 2345 | - 'validation' => $config['validation'], |
|
| 2346 | - 'value' => isset($existing[$field]) ? $existing[$field] : $default, |
|
| 2347 | - 'css_class' => $config['css_class'], |
|
| 2348 | - 'options' => isset($config['options']) ? $config['options'] : array(), |
|
| 2349 | - 'default' => $default, |
|
| 2350 | - 'format' => $config['format'] |
|
| 2351 | - ); |
|
| 2352 | - } |
|
| 2353 | - } |
|
| 2354 | - |
|
| 2355 | - $test_settings_fields = ! empty($template_form_fields) |
|
| 2356 | - ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds') |
|
| 2357 | - : ''; |
|
| 2358 | - |
|
| 2359 | - $test_settings_html = ''; |
|
| 2360 | - //print out $test_settings_fields |
|
| 2361 | - if ( ! empty($test_settings_fields)) { |
|
| 2362 | - echo $test_settings_fields; |
|
| 2363 | - $test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" '; |
|
| 2364 | - $test_settings_html .= 'name="test_button" value="'; |
|
| 2365 | - $test_settings_html .= esc_html__('Test Send', 'event_espresso'); |
|
| 2366 | - $test_settings_html .= '" /><div style="clear:both"></div>'; |
|
| 2367 | - } |
|
| 2368 | - |
|
| 2369 | - //and button |
|
| 2370 | - $test_settings_html .= '<p>' |
|
| 2371 | - . esc_html__('Need to reset this message type and start over?', 'event_espresso') |
|
| 2372 | - . '</p>'; |
|
| 2373 | - $test_settings_html .= '<div class="publishing-action alignright resetbutton">'; |
|
| 2374 | - $test_settings_html .= $this->get_action_link_or_button( |
|
| 2375 | - 'reset_to_default', |
|
| 2376 | - 'reset', |
|
| 2377 | - $extra_args, |
|
| 2378 | - 'button-primary reset-default-button' |
|
| 2379 | - ); |
|
| 2380 | - $test_settings_html .= '</div><div style="clear:both"></div>'; |
|
| 2381 | - echo $test_settings_html; |
|
| 2382 | - } |
|
| 2339 | + $template_form_fields[$field_id] = array( |
|
| 2340 | + 'name' => 'test_settings_fld[' . $field . ']', |
|
| 2341 | + 'label' => $config['label'], |
|
| 2342 | + 'input' => $config['input'], |
|
| 2343 | + 'type' => $config['type'], |
|
| 2344 | + 'required' => $config['required'], |
|
| 2345 | + 'validation' => $config['validation'], |
|
| 2346 | + 'value' => isset($existing[$field]) ? $existing[$field] : $default, |
|
| 2347 | + 'css_class' => $config['css_class'], |
|
| 2348 | + 'options' => isset($config['options']) ? $config['options'] : array(), |
|
| 2349 | + 'default' => $default, |
|
| 2350 | + 'format' => $config['format'] |
|
| 2351 | + ); |
|
| 2352 | + } |
|
| 2353 | + } |
|
| 2354 | + |
|
| 2355 | + $test_settings_fields = ! empty($template_form_fields) |
|
| 2356 | + ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds') |
|
| 2357 | + : ''; |
|
| 2358 | + |
|
| 2359 | + $test_settings_html = ''; |
|
| 2360 | + //print out $test_settings_fields |
|
| 2361 | + if ( ! empty($test_settings_fields)) { |
|
| 2362 | + echo $test_settings_fields; |
|
| 2363 | + $test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" '; |
|
| 2364 | + $test_settings_html .= 'name="test_button" value="'; |
|
| 2365 | + $test_settings_html .= esc_html__('Test Send', 'event_espresso'); |
|
| 2366 | + $test_settings_html .= '" /><div style="clear:both"></div>'; |
|
| 2367 | + } |
|
| 2368 | + |
|
| 2369 | + //and button |
|
| 2370 | + $test_settings_html .= '<p>' |
|
| 2371 | + . esc_html__('Need to reset this message type and start over?', 'event_espresso') |
|
| 2372 | + . '</p>'; |
|
| 2373 | + $test_settings_html .= '<div class="publishing-action alignright resetbutton">'; |
|
| 2374 | + $test_settings_html .= $this->get_action_link_or_button( |
|
| 2375 | + 'reset_to_default', |
|
| 2376 | + 'reset', |
|
| 2377 | + $extra_args, |
|
| 2378 | + 'button-primary reset-default-button' |
|
| 2379 | + ); |
|
| 2380 | + $test_settings_html .= '</div><div style="clear:both"></div>'; |
|
| 2381 | + echo $test_settings_html; |
|
| 2382 | + } |
|
| 2383 | 2383 | |
| 2384 | 2384 | |
| 2385 | - /** |
|
| 2386 | - * This returns the shortcode selector skeleton for a given context and field. |
|
| 2387 | - * |
|
| 2388 | - * @since 4.9.rc.000 |
|
| 2389 | - * @param string $field The name of the field retrieving shortcodes for. |
|
| 2390 | - * @param string $linked_input_id The css id of the input that the shortcodes get added to. |
|
| 2391 | - * @return string |
|
| 2392 | - * @throws DomainException |
|
| 2393 | - * @throws EE_Error |
|
| 2394 | - * @throws InvalidArgumentException |
|
| 2395 | - * @throws ReflectionException |
|
| 2396 | - * @throws InvalidDataTypeException |
|
| 2397 | - * @throws InvalidInterfaceException |
|
| 2398 | - */ |
|
| 2399 | - protected function _get_shortcode_selector($field, $linked_input_id) |
|
| 2400 | - { |
|
| 2401 | - $template_args = array( |
|
| 2402 | - 'shortcodes' => $this->_get_shortcodes(array($field), true), |
|
| 2403 | - 'fieldname' => $field, |
|
| 2404 | - 'linked_input_id' => $linked_input_id |
|
| 2405 | - ); |
|
| 2406 | - |
|
| 2407 | - return EEH_Template::display_template( |
|
| 2408 | - EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php', |
|
| 2409 | - $template_args, |
|
| 2410 | - true |
|
| 2411 | - ); |
|
| 2412 | - } |
|
| 2385 | + /** |
|
| 2386 | + * This returns the shortcode selector skeleton for a given context and field. |
|
| 2387 | + * |
|
| 2388 | + * @since 4.9.rc.000 |
|
| 2389 | + * @param string $field The name of the field retrieving shortcodes for. |
|
| 2390 | + * @param string $linked_input_id The css id of the input that the shortcodes get added to. |
|
| 2391 | + * @return string |
|
| 2392 | + * @throws DomainException |
|
| 2393 | + * @throws EE_Error |
|
| 2394 | + * @throws InvalidArgumentException |
|
| 2395 | + * @throws ReflectionException |
|
| 2396 | + * @throws InvalidDataTypeException |
|
| 2397 | + * @throws InvalidInterfaceException |
|
| 2398 | + */ |
|
| 2399 | + protected function _get_shortcode_selector($field, $linked_input_id) |
|
| 2400 | + { |
|
| 2401 | + $template_args = array( |
|
| 2402 | + 'shortcodes' => $this->_get_shortcodes(array($field), true), |
|
| 2403 | + 'fieldname' => $field, |
|
| 2404 | + 'linked_input_id' => $linked_input_id |
|
| 2405 | + ); |
|
| 2406 | + |
|
| 2407 | + return EEH_Template::display_template( |
|
| 2408 | + EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php', |
|
| 2409 | + $template_args, |
|
| 2410 | + true |
|
| 2411 | + ); |
|
| 2412 | + } |
|
| 2413 | 2413 | |
| 2414 | 2414 | |
| 2415 | - /** |
|
| 2416 | - * This just takes care of returning the meta box content for shortcodes (only used on the edit message template |
|
| 2417 | - * page) |
|
| 2418 | - * |
|
| 2419 | - * @access public |
|
| 2420 | - * @return void |
|
| 2421 | - * @throws EE_Error |
|
| 2422 | - * @throws InvalidArgumentException |
|
| 2423 | - * @throws ReflectionException |
|
| 2424 | - * @throws InvalidDataTypeException |
|
| 2425 | - * @throws InvalidInterfaceException |
|
| 2426 | - */ |
|
| 2427 | - public function shortcode_meta_box() |
|
| 2428 | - { |
|
| 2429 | - $shortcodes = $this->_get_shortcodes(array(), false); //just make sure shortcodes property is set |
|
| 2430 | - //$messenger = $this->_message_template_group->messenger_obj(); |
|
| 2431 | - //now let's set the content depending on the status of the shortcodes array |
|
| 2432 | - if (empty($shortcodes)) { |
|
| 2433 | - $content = '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>'; |
|
| 2434 | - echo $content; |
|
| 2435 | - } else { |
|
| 2436 | - //$alt = 0; |
|
| 2437 | - ?> |
|
| 2415 | + /** |
|
| 2416 | + * This just takes care of returning the meta box content for shortcodes (only used on the edit message template |
|
| 2417 | + * page) |
|
| 2418 | + * |
|
| 2419 | + * @access public |
|
| 2420 | + * @return void |
|
| 2421 | + * @throws EE_Error |
|
| 2422 | + * @throws InvalidArgumentException |
|
| 2423 | + * @throws ReflectionException |
|
| 2424 | + * @throws InvalidDataTypeException |
|
| 2425 | + * @throws InvalidInterfaceException |
|
| 2426 | + */ |
|
| 2427 | + public function shortcode_meta_box() |
|
| 2428 | + { |
|
| 2429 | + $shortcodes = $this->_get_shortcodes(array(), false); //just make sure shortcodes property is set |
|
| 2430 | + //$messenger = $this->_message_template_group->messenger_obj(); |
|
| 2431 | + //now let's set the content depending on the status of the shortcodes array |
|
| 2432 | + if (empty($shortcodes)) { |
|
| 2433 | + $content = '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>'; |
|
| 2434 | + echo $content; |
|
| 2435 | + } else { |
|
| 2436 | + //$alt = 0; |
|
| 2437 | + ?> |
|
| 2438 | 2438 | <div style="float:right; margin-top:10px"><?php echo $this->_get_help_tab_link('message_template_shortcodes'); ?></div> |
| 2439 | 2439 | <p class="small-text"><?php printf( |
| 2440 | - esc_html__( |
|
| 2441 | - 'You can view the shortcodes usable in your template by clicking the %s icon next to each field.', |
|
| 2442 | - 'event_espresso' |
|
| 2443 | - ), |
|
| 2444 | - '<span class="dashicons dashicons-menu"></span>' |
|
| 2445 | - ); ?></p> |
|
| 2440 | + esc_html__( |
|
| 2441 | + 'You can view the shortcodes usable in your template by clicking the %s icon next to each field.', |
|
| 2442 | + 'event_espresso' |
|
| 2443 | + ), |
|
| 2444 | + '<span class="dashicons dashicons-menu"></span>' |
|
| 2445 | + ); ?></p> |
|
| 2446 | 2446 | <?php |
| 2447 | - } |
|
| 2447 | + } |
|
| 2448 | 2448 | |
| 2449 | 2449 | |
| 2450 | - } |
|
| 2450 | + } |
|
| 2451 | 2451 | |
| 2452 | 2452 | |
| 2453 | - /** |
|
| 2454 | - * used to set the $_shortcodes property for when its needed elsewhere. |
|
| 2455 | - * |
|
| 2456 | - * @access protected |
|
| 2457 | - * @return void |
|
| 2458 | - * @throws EE_Error |
|
| 2459 | - * @throws InvalidArgumentException |
|
| 2460 | - * @throws ReflectionException |
|
| 2461 | - * @throws InvalidDataTypeException |
|
| 2462 | - * @throws InvalidInterfaceException |
|
| 2463 | - */ |
|
| 2464 | - protected function _set_shortcodes() |
|
| 2465 | - { |
|
| 2466 | - |
|
| 2467 | - //no need to run this if the property is already set |
|
| 2468 | - if ( ! empty($this->_shortcodes)) { |
|
| 2469 | - return; |
|
| 2470 | - } |
|
| 2471 | - |
|
| 2472 | - $this->_shortcodes = $this->_get_shortcodes(); |
|
| 2473 | - } |
|
| 2453 | + /** |
|
| 2454 | + * used to set the $_shortcodes property for when its needed elsewhere. |
|
| 2455 | + * |
|
| 2456 | + * @access protected |
|
| 2457 | + * @return void |
|
| 2458 | + * @throws EE_Error |
|
| 2459 | + * @throws InvalidArgumentException |
|
| 2460 | + * @throws ReflectionException |
|
| 2461 | + * @throws InvalidDataTypeException |
|
| 2462 | + * @throws InvalidInterfaceException |
|
| 2463 | + */ |
|
| 2464 | + protected function _set_shortcodes() |
|
| 2465 | + { |
|
| 2466 | + |
|
| 2467 | + //no need to run this if the property is already set |
|
| 2468 | + if ( ! empty($this->_shortcodes)) { |
|
| 2469 | + return; |
|
| 2470 | + } |
|
| 2471 | + |
|
| 2472 | + $this->_shortcodes = $this->_get_shortcodes(); |
|
| 2473 | + } |
|
| 2474 | 2474 | |
| 2475 | 2475 | |
| 2476 | - /** |
|
| 2477 | - * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes |
|
| 2478 | - * property) |
|
| 2479 | - * |
|
| 2480 | - * @access protected |
|
| 2481 | - * @param array $fields include an array of specific field names that you want to be used to get the shortcodes |
|
| 2482 | - * for. Defaults to all (for the given context) |
|
| 2483 | - * @param boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes |
|
| 2484 | - * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is |
|
| 2485 | - * true just an array of shortcode/label pairs. |
|
| 2486 | - * @throws EE_Error |
|
| 2487 | - * @throws InvalidArgumentException |
|
| 2488 | - * @throws ReflectionException |
|
| 2489 | - * @throws InvalidDataTypeException |
|
| 2490 | - * @throws InvalidInterfaceException |
|
| 2491 | - */ |
|
| 2492 | - protected function _get_shortcodes($fields = array(), $merged = true) |
|
| 2493 | - { |
|
| 2494 | - $this->_set_message_template_group(); |
|
| 2495 | - |
|
| 2496 | - //we need the messenger and message template to retrieve the valid shortcodes array. |
|
| 2497 | - $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) |
|
| 2498 | - ? absint($this->_req_data['id']) |
|
| 2499 | - : false; |
|
| 2500 | - $context = isset($this->_req_data['context']) |
|
| 2501 | - ? $this->_req_data['context'] |
|
| 2502 | - : key($this->_message_template_group->contexts_config()); |
|
| 2503 | - |
|
| 2504 | - return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array(); |
|
| 2505 | - } |
|
| 2476 | + /** |
|
| 2477 | + * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes |
|
| 2478 | + * property) |
|
| 2479 | + * |
|
| 2480 | + * @access protected |
|
| 2481 | + * @param array $fields include an array of specific field names that you want to be used to get the shortcodes |
|
| 2482 | + * for. Defaults to all (for the given context) |
|
| 2483 | + * @param boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes |
|
| 2484 | + * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is |
|
| 2485 | + * true just an array of shortcode/label pairs. |
|
| 2486 | + * @throws EE_Error |
|
| 2487 | + * @throws InvalidArgumentException |
|
| 2488 | + * @throws ReflectionException |
|
| 2489 | + * @throws InvalidDataTypeException |
|
| 2490 | + * @throws InvalidInterfaceException |
|
| 2491 | + */ |
|
| 2492 | + protected function _get_shortcodes($fields = array(), $merged = true) |
|
| 2493 | + { |
|
| 2494 | + $this->_set_message_template_group(); |
|
| 2495 | + |
|
| 2496 | + //we need the messenger and message template to retrieve the valid shortcodes array. |
|
| 2497 | + $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) |
|
| 2498 | + ? absint($this->_req_data['id']) |
|
| 2499 | + : false; |
|
| 2500 | + $context = isset($this->_req_data['context']) |
|
| 2501 | + ? $this->_req_data['context'] |
|
| 2502 | + : key($this->_message_template_group->contexts_config()); |
|
| 2503 | + |
|
| 2504 | + return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array(); |
|
| 2505 | + } |
|
| 2506 | 2506 | |
| 2507 | 2507 | |
| 2508 | - /** |
|
| 2509 | - * This sets the _message_template property (containing the called message_template object) |
|
| 2510 | - * |
|
| 2511 | - * @access protected |
|
| 2512 | - * @return void |
|
| 2513 | - * @throws EE_Error |
|
| 2514 | - * @throws InvalidArgumentException |
|
| 2515 | - * @throws ReflectionException |
|
| 2516 | - * @throws InvalidDataTypeException |
|
| 2517 | - * @throws InvalidInterfaceException |
|
| 2518 | - */ |
|
| 2519 | - protected function _set_message_template_group() |
|
| 2520 | - { |
|
| 2521 | - |
|
| 2522 | - if ( ! empty($this->_message_template_group)) { |
|
| 2523 | - return; |
|
| 2524 | - } //get out if this is already set. |
|
| 2525 | - |
|
| 2526 | - $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false; |
|
| 2527 | - $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID; |
|
| 2528 | - |
|
| 2529 | - //let's get the message templates |
|
| 2530 | - $MTP = EEM_Message_Template_Group::instance(); |
|
| 2531 | - |
|
| 2532 | - if (empty($GRP_ID)) { |
|
| 2533 | - $this->_message_template_group = $MTP->create_default_object(); |
|
| 2534 | - } else { |
|
| 2535 | - $this->_message_template_group = $MTP->get_one_by_ID($GRP_ID); |
|
| 2536 | - } |
|
| 2537 | - |
|
| 2538 | - $this->_template_pack = $this->_message_template_group->get_template_pack(); |
|
| 2539 | - $this->_variation = $this->_message_template_group->get_template_pack_variation(); |
|
| 2540 | - |
|
| 2541 | - } |
|
| 2508 | + /** |
|
| 2509 | + * This sets the _message_template property (containing the called message_template object) |
|
| 2510 | + * |
|
| 2511 | + * @access protected |
|
| 2512 | + * @return void |
|
| 2513 | + * @throws EE_Error |
|
| 2514 | + * @throws InvalidArgumentException |
|
| 2515 | + * @throws ReflectionException |
|
| 2516 | + * @throws InvalidDataTypeException |
|
| 2517 | + * @throws InvalidInterfaceException |
|
| 2518 | + */ |
|
| 2519 | + protected function _set_message_template_group() |
|
| 2520 | + { |
|
| 2521 | + |
|
| 2522 | + if ( ! empty($this->_message_template_group)) { |
|
| 2523 | + return; |
|
| 2524 | + } //get out if this is already set. |
|
| 2525 | + |
|
| 2526 | + $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false; |
|
| 2527 | + $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID; |
|
| 2528 | + |
|
| 2529 | + //let's get the message templates |
|
| 2530 | + $MTP = EEM_Message_Template_Group::instance(); |
|
| 2531 | + |
|
| 2532 | + if (empty($GRP_ID)) { |
|
| 2533 | + $this->_message_template_group = $MTP->create_default_object(); |
|
| 2534 | + } else { |
|
| 2535 | + $this->_message_template_group = $MTP->get_one_by_ID($GRP_ID); |
|
| 2536 | + } |
|
| 2537 | + |
|
| 2538 | + $this->_template_pack = $this->_message_template_group->get_template_pack(); |
|
| 2539 | + $this->_variation = $this->_message_template_group->get_template_pack_variation(); |
|
| 2540 | + |
|
| 2541 | + } |
|
| 2542 | 2542 | |
| 2543 | 2543 | |
| 2544 | - /** |
|
| 2545 | - * sets up a context switcher for edit forms |
|
| 2546 | - * |
|
| 2547 | - * @access protected |
|
| 2548 | - * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form |
|
| 2549 | - * @param array $args various things the context switcher needs. |
|
| 2550 | - * @throws EE_Error |
|
| 2551 | - */ |
|
| 2552 | - protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args) |
|
| 2553 | - { |
|
| 2554 | - $context_details = $template_group_object->contexts_config(); |
|
| 2555 | - $context_label = $template_group_object->context_label(); |
|
| 2556 | - ob_start(); |
|
| 2557 | - ?> |
|
| 2544 | + /** |
|
| 2545 | + * sets up a context switcher for edit forms |
|
| 2546 | + * |
|
| 2547 | + * @access protected |
|
| 2548 | + * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form |
|
| 2549 | + * @param array $args various things the context switcher needs. |
|
| 2550 | + * @throws EE_Error |
|
| 2551 | + */ |
|
| 2552 | + protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args) |
|
| 2553 | + { |
|
| 2554 | + $context_details = $template_group_object->contexts_config(); |
|
| 2555 | + $context_label = $template_group_object->context_label(); |
|
| 2556 | + ob_start(); |
|
| 2557 | + ?> |
|
| 2558 | 2558 | <div class="ee-msg-switcher-container"> |
| 2559 | 2559 | <form method="get" action="<?php echo EE_MSG_ADMIN_URL; ?>" id="ee-msg-context-switcher-frm"> |
| 2560 | 2560 | <?php |
| 2561 | - foreach ($args as $name => $value) { |
|
| 2562 | - if ($name === 'context' || empty($value) || $name === 'extra') { |
|
| 2563 | - continue; |
|
| 2564 | - } |
|
| 2565 | - ?> |
|
| 2561 | + foreach ($args as $name => $value) { |
|
| 2562 | + if ($name === 'context' || empty($value) || $name === 'extra') { |
|
| 2563 | + continue; |
|
| 2564 | + } |
|
| 2565 | + ?> |
|
| 2566 | 2566 | <input type="hidden" name="<?php echo $name; ?>" value="<?php echo $value; ?>"/> |
| 2567 | 2567 | <?php |
| 2568 | - } |
|
| 2569 | - //setup nonce_url |
|
| 2570 | - wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false); |
|
| 2571 | - ?> |
|
| 2568 | + } |
|
| 2569 | + //setup nonce_url |
|
| 2570 | + wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false); |
|
| 2571 | + ?> |
|
| 2572 | 2572 | <select name="context"> |
| 2573 | 2573 | <?php |
| 2574 | - $context_templates = $template_group_object->context_templates(); |
|
| 2575 | - if (is_array($context_templates)) : |
|
| 2576 | - foreach ($context_templates as $context => $template_fields) : |
|
| 2577 | - $checked = ($context === $args['context']) ? 'selected="selected"' : ''; |
|
| 2578 | - ?> |
|
| 2574 | + $context_templates = $template_group_object->context_templates(); |
|
| 2575 | + if (is_array($context_templates)) : |
|
| 2576 | + foreach ($context_templates as $context => $template_fields) : |
|
| 2577 | + $checked = ($context === $args['context']) ? 'selected="selected"' : ''; |
|
| 2578 | + ?> |
|
| 2579 | 2579 | <option value="<?php echo $context; ?>" <?php echo $checked; ?>> |
| 2580 | 2580 | <?php echo $context_details[$context]['label']; ?> |
| 2581 | 2581 | </option> |
@@ -2588,1838 +2588,1838 @@ discard block |
||
| 2588 | 2588 | <?php echo $args['extra']; ?> |
| 2589 | 2589 | </div> <!-- end .ee-msg-switcher-container --> |
| 2590 | 2590 | <?php |
| 2591 | - $output = ob_get_contents(); |
|
| 2592 | - ob_clean(); |
|
| 2593 | - $this->_context_switcher = $output; |
|
| 2594 | - } |
|
| 2591 | + $output = ob_get_contents(); |
|
| 2592 | + ob_clean(); |
|
| 2593 | + $this->_context_switcher = $output; |
|
| 2594 | + } |
|
| 2595 | 2595 | |
| 2596 | 2596 | |
| 2597 | - /** |
|
| 2598 | - * utility for sanitizing new values coming in. |
|
| 2599 | - * Note: this is only used when updating a context. |
|
| 2600 | - * |
|
| 2601 | - * @access protected |
|
| 2602 | - * |
|
| 2603 | - * @param int $index This helps us know which template field to select from the request array. |
|
| 2604 | - * |
|
| 2605 | - * @return array |
|
| 2606 | - */ |
|
| 2607 | - protected function _set_message_template_column_values($index) |
|
| 2608 | - { |
|
| 2609 | - if (is_array($this->_req_data['MTP_template_fields'][$index]['content'])) { |
|
| 2610 | - foreach ($this->_req_data['MTP_template_fields'][$index]['content'] as $field => $value) { |
|
| 2611 | - $this->_req_data['MTP_template_fields'][$index]['content'][$field] = $value; |
|
| 2612 | - } |
|
| 2613 | - } |
|
| 2614 | - |
|
| 2615 | - |
|
| 2616 | - $set_column_values = array( |
|
| 2617 | - 'MTP_ID' => absint($this->_req_data['MTP_template_fields'][$index]['MTP_ID']), |
|
| 2618 | - 'GRP_ID' => absint($this->_req_data['GRP_ID']), |
|
| 2619 | - 'MTP_user_id' => absint($this->_req_data['MTP_user_id']), |
|
| 2620 | - 'MTP_messenger' => strtolower($this->_req_data['MTP_messenger']), |
|
| 2621 | - 'MTP_message_type' => strtolower($this->_req_data['MTP_message_type']), |
|
| 2622 | - 'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][$index]['name']), |
|
| 2623 | - 'MTP_context' => strtolower($this->_req_data['MTP_context']), |
|
| 2624 | - 'MTP_content' => $this->_req_data['MTP_template_fields'][$index]['content'], |
|
| 2625 | - 'MTP_is_global' => isset($this->_req_data['MTP_is_global']) |
|
| 2626 | - ? absint($this->_req_data['MTP_is_global']) |
|
| 2627 | - : 0, |
|
| 2628 | - 'MTP_is_override' => isset($this->_req_data['MTP_is_override']) |
|
| 2629 | - ? absint($this->_req_data['MTP_is_override']) |
|
| 2630 | - : 0, |
|
| 2631 | - 'MTP_deleted' => absint($this->_req_data['MTP_deleted']), |
|
| 2632 | - 'MTP_is_active' => absint($this->_req_data['MTP_is_active']) |
|
| 2633 | - ); |
|
| 2634 | - |
|
| 2635 | - |
|
| 2636 | - return $set_column_values; |
|
| 2637 | - } |
|
| 2597 | + /** |
|
| 2598 | + * utility for sanitizing new values coming in. |
|
| 2599 | + * Note: this is only used when updating a context. |
|
| 2600 | + * |
|
| 2601 | + * @access protected |
|
| 2602 | + * |
|
| 2603 | + * @param int $index This helps us know which template field to select from the request array. |
|
| 2604 | + * |
|
| 2605 | + * @return array |
|
| 2606 | + */ |
|
| 2607 | + protected function _set_message_template_column_values($index) |
|
| 2608 | + { |
|
| 2609 | + if (is_array($this->_req_data['MTP_template_fields'][$index]['content'])) { |
|
| 2610 | + foreach ($this->_req_data['MTP_template_fields'][$index]['content'] as $field => $value) { |
|
| 2611 | + $this->_req_data['MTP_template_fields'][$index]['content'][$field] = $value; |
|
| 2612 | + } |
|
| 2613 | + } |
|
| 2614 | + |
|
| 2615 | + |
|
| 2616 | + $set_column_values = array( |
|
| 2617 | + 'MTP_ID' => absint($this->_req_data['MTP_template_fields'][$index]['MTP_ID']), |
|
| 2618 | + 'GRP_ID' => absint($this->_req_data['GRP_ID']), |
|
| 2619 | + 'MTP_user_id' => absint($this->_req_data['MTP_user_id']), |
|
| 2620 | + 'MTP_messenger' => strtolower($this->_req_data['MTP_messenger']), |
|
| 2621 | + 'MTP_message_type' => strtolower($this->_req_data['MTP_message_type']), |
|
| 2622 | + 'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][$index]['name']), |
|
| 2623 | + 'MTP_context' => strtolower($this->_req_data['MTP_context']), |
|
| 2624 | + 'MTP_content' => $this->_req_data['MTP_template_fields'][$index]['content'], |
|
| 2625 | + 'MTP_is_global' => isset($this->_req_data['MTP_is_global']) |
|
| 2626 | + ? absint($this->_req_data['MTP_is_global']) |
|
| 2627 | + : 0, |
|
| 2628 | + 'MTP_is_override' => isset($this->_req_data['MTP_is_override']) |
|
| 2629 | + ? absint($this->_req_data['MTP_is_override']) |
|
| 2630 | + : 0, |
|
| 2631 | + 'MTP_deleted' => absint($this->_req_data['MTP_deleted']), |
|
| 2632 | + 'MTP_is_active' => absint($this->_req_data['MTP_is_active']) |
|
| 2633 | + ); |
|
| 2634 | + |
|
| 2635 | + |
|
| 2636 | + return $set_column_values; |
|
| 2637 | + } |
|
| 2638 | 2638 | |
| 2639 | 2639 | |
| 2640 | - protected function _insert_or_update_message_template($new = false) |
|
| 2641 | - { |
|
| 2642 | - |
|
| 2643 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2644 | - $success = 0; |
|
| 2645 | - $override = false; |
|
| 2646 | - |
|
| 2647 | - //setup notices description |
|
| 2648 | - $messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : ''; |
|
| 2649 | - |
|
| 2650 | - //need the message type and messenger objects to be able to use the labels for the notices |
|
| 2651 | - $messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug); |
|
| 2652 | - $messenger_label = $messenger_object instanceof EE_messenger |
|
| 2653 | - ? ucwords($messenger_object->label['singular']) |
|
| 2654 | - : ''; |
|
| 2655 | - |
|
| 2656 | - $message_type_slug = ! empty($this->_req_data['MTP_message_type']) |
|
| 2657 | - ? $this->_req_data['MTP_message_type'] |
|
| 2658 | - : ''; |
|
| 2659 | - $message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug); |
|
| 2660 | - |
|
| 2661 | - $message_type_label = $message_type_object instanceof EE_message_type |
|
| 2662 | - ? ucwords($message_type_object->label['singular']) |
|
| 2663 | - : ''; |
|
| 2664 | - |
|
| 2665 | - $context_slug = ! empty($this->_req_data['MTP_context']) |
|
| 2666 | - ? $this->_req_data['MTP_context'] |
|
| 2667 | - : ''; |
|
| 2668 | - $context = ucwords(str_replace('_', ' ', $context_slug)); |
|
| 2669 | - |
|
| 2670 | - $item_desc = $messenger_label && $message_type_label |
|
| 2671 | - ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' ' |
|
| 2672 | - : ''; |
|
| 2673 | - $item_desc .= 'Message Template'; |
|
| 2674 | - $query_args = array(); |
|
| 2675 | - $edit_array = array(); |
|
| 2676 | - $action_desc = ''; |
|
| 2677 | - |
|
| 2678 | - //if this is "new" then we need to generate the default contexts for the selected messenger/message_type for |
|
| 2679 | - // user to edit. |
|
| 2680 | - if ($new) { |
|
| 2681 | - $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 2682 | - if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) { |
|
| 2683 | - if (empty($edit_array)) { |
|
| 2684 | - $success = 0; |
|
| 2685 | - } else { |
|
| 2686 | - $success = 1; |
|
| 2687 | - $edit_array = $edit_array[0]; |
|
| 2688 | - $query_args = array( |
|
| 2689 | - 'id' => $edit_array['GRP_ID'], |
|
| 2690 | - 'context' => $edit_array['MTP_context'], |
|
| 2691 | - 'action' => 'edit_message_template' |
|
| 2692 | - ); |
|
| 2693 | - } |
|
| 2694 | - } |
|
| 2695 | - $action_desc = 'created'; |
|
| 2696 | - } else { |
|
| 2697 | - $MTPG = EEM_Message_Template_Group::instance(); |
|
| 2698 | - $MTP = EEM_Message_Template::instance(); |
|
| 2640 | + protected function _insert_or_update_message_template($new = false) |
|
| 2641 | + { |
|
| 2642 | + |
|
| 2643 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2644 | + $success = 0; |
|
| 2645 | + $override = false; |
|
| 2646 | + |
|
| 2647 | + //setup notices description |
|
| 2648 | + $messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : ''; |
|
| 2649 | + |
|
| 2650 | + //need the message type and messenger objects to be able to use the labels for the notices |
|
| 2651 | + $messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug); |
|
| 2652 | + $messenger_label = $messenger_object instanceof EE_messenger |
|
| 2653 | + ? ucwords($messenger_object->label['singular']) |
|
| 2654 | + : ''; |
|
| 2655 | + |
|
| 2656 | + $message_type_slug = ! empty($this->_req_data['MTP_message_type']) |
|
| 2657 | + ? $this->_req_data['MTP_message_type'] |
|
| 2658 | + : ''; |
|
| 2659 | + $message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug); |
|
| 2660 | + |
|
| 2661 | + $message_type_label = $message_type_object instanceof EE_message_type |
|
| 2662 | + ? ucwords($message_type_object->label['singular']) |
|
| 2663 | + : ''; |
|
| 2664 | + |
|
| 2665 | + $context_slug = ! empty($this->_req_data['MTP_context']) |
|
| 2666 | + ? $this->_req_data['MTP_context'] |
|
| 2667 | + : ''; |
|
| 2668 | + $context = ucwords(str_replace('_', ' ', $context_slug)); |
|
| 2669 | + |
|
| 2670 | + $item_desc = $messenger_label && $message_type_label |
|
| 2671 | + ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' ' |
|
| 2672 | + : ''; |
|
| 2673 | + $item_desc .= 'Message Template'; |
|
| 2674 | + $query_args = array(); |
|
| 2675 | + $edit_array = array(); |
|
| 2676 | + $action_desc = ''; |
|
| 2677 | + |
|
| 2678 | + //if this is "new" then we need to generate the default contexts for the selected messenger/message_type for |
|
| 2679 | + // user to edit. |
|
| 2680 | + if ($new) { |
|
| 2681 | + $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 2682 | + if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) { |
|
| 2683 | + if (empty($edit_array)) { |
|
| 2684 | + $success = 0; |
|
| 2685 | + } else { |
|
| 2686 | + $success = 1; |
|
| 2687 | + $edit_array = $edit_array[0]; |
|
| 2688 | + $query_args = array( |
|
| 2689 | + 'id' => $edit_array['GRP_ID'], |
|
| 2690 | + 'context' => $edit_array['MTP_context'], |
|
| 2691 | + 'action' => 'edit_message_template' |
|
| 2692 | + ); |
|
| 2693 | + } |
|
| 2694 | + } |
|
| 2695 | + $action_desc = 'created'; |
|
| 2696 | + } else { |
|
| 2697 | + $MTPG = EEM_Message_Template_Group::instance(); |
|
| 2698 | + $MTP = EEM_Message_Template::instance(); |
|
| 2699 | 2699 | |
| 2700 | 2700 | |
| 2701 | - //run update for each template field in displayed context |
|
| 2702 | - if ( ! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) { |
|
| 2703 | - EE_Error::add_error( |
|
| 2704 | - esc_html__( |
|
| 2705 | - 'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.', |
|
| 2706 | - 'event_espresso' |
|
| 2707 | - ), |
|
| 2708 | - __FILE__, |
|
| 2709 | - __FUNCTION__, |
|
| 2710 | - __LINE__ |
|
| 2711 | - ); |
|
| 2712 | - $success = 0; |
|
| 2701 | + //run update for each template field in displayed context |
|
| 2702 | + if ( ! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) { |
|
| 2703 | + EE_Error::add_error( |
|
| 2704 | + esc_html__( |
|
| 2705 | + 'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.', |
|
| 2706 | + 'event_espresso' |
|
| 2707 | + ), |
|
| 2708 | + __FILE__, |
|
| 2709 | + __FUNCTION__, |
|
| 2710 | + __LINE__ |
|
| 2711 | + ); |
|
| 2712 | + $success = 0; |
|
| 2713 | 2713 | |
| 2714 | - } else { |
|
| 2715 | - //first validate all fields! |
|
| 2716 | - $validates = $MTPG->validate($this->_req_data['MTP_template_fields'], $context_slug, $messenger_slug, |
|
| 2717 | - $message_type_slug); |
|
| 2714 | + } else { |
|
| 2715 | + //first validate all fields! |
|
| 2716 | + $validates = $MTPG->validate($this->_req_data['MTP_template_fields'], $context_slug, $messenger_slug, |
|
| 2717 | + $message_type_slug); |
|
| 2718 | 2718 | |
| 2719 | - //if $validate returned error messages (i.e. is_array()) then we need to process them and setup an |
|
| 2720 | - // appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array. |
|
| 2721 | - // WE need to make sure there is no actual error messages in validates. |
|
| 2722 | - if (is_array($validates) && ! empty($validates)) { |
|
| 2723 | - //add the transient so when the form loads we know which fields to highlight |
|
| 2724 | - $this->_add_transient('edit_message_template', $validates); |
|
| 2719 | + //if $validate returned error messages (i.e. is_array()) then we need to process them and setup an |
|
| 2720 | + // appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array. |
|
| 2721 | + // WE need to make sure there is no actual error messages in validates. |
|
| 2722 | + if (is_array($validates) && ! empty($validates)) { |
|
| 2723 | + //add the transient so when the form loads we know which fields to highlight |
|
| 2724 | + $this->_add_transient('edit_message_template', $validates); |
|
| 2725 | 2725 | |
| 2726 | - $success = 0; |
|
| 2726 | + $success = 0; |
|
| 2727 | 2727 | |
| 2728 | - //setup notices |
|
| 2729 | - foreach ($validates as $field => $error) { |
|
| 2730 | - if (isset($error['msg'])) { |
|
| 2731 | - EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__); |
|
| 2732 | - } |
|
| 2733 | - } |
|
| 2728 | + //setup notices |
|
| 2729 | + foreach ($validates as $field => $error) { |
|
| 2730 | + if (isset($error['msg'])) { |
|
| 2731 | + EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__); |
|
| 2732 | + } |
|
| 2733 | + } |
|
| 2734 | 2734 | |
| 2735 | - } else { |
|
| 2736 | - $set_column_values = array(); |
|
| 2737 | - foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) { |
|
| 2738 | - $set_column_values = $this->_set_message_template_column_values($template_field); |
|
| 2735 | + } else { |
|
| 2736 | + $set_column_values = array(); |
|
| 2737 | + foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) { |
|
| 2738 | + $set_column_values = $this->_set_message_template_column_values($template_field); |
|
| 2739 | 2739 | |
| 2740 | - $where_cols_n_values = array( |
|
| 2741 | - 'MTP_ID' => $this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'] |
|
| 2742 | - ); |
|
| 2740 | + $where_cols_n_values = array( |
|
| 2741 | + 'MTP_ID' => $this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'] |
|
| 2742 | + ); |
|
| 2743 | 2743 | |
| 2744 | - $message_template_fields = array( |
|
| 2745 | - 'GRP_ID' => $set_column_values['GRP_ID'], |
|
| 2746 | - 'MTP_template_field' => $set_column_values['MTP_template_field'], |
|
| 2747 | - 'MTP_context' => $set_column_values['MTP_context'], |
|
| 2748 | - 'MTP_content' => $set_column_values['MTP_content'] |
|
| 2749 | - ); |
|
| 2750 | - if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) { |
|
| 2751 | - if ($updated === false) { |
|
| 2752 | - EE_Error::add_error( |
|
| 2753 | - sprintf( |
|
| 2754 | - esc_html__('%s field was NOT updated for some reason', 'event_espresso'), |
|
| 2755 | - $template_field |
|
| 2756 | - ), |
|
| 2757 | - __FILE__, |
|
| 2758 | - __FUNCTION__, |
|
| 2759 | - __LINE__ |
|
| 2760 | - ); |
|
| 2761 | - } else { |
|
| 2762 | - $success = 1; |
|
| 2763 | - } |
|
| 2764 | - } else { |
|
| 2765 | - //only do this logic if we don't have a MTP_ID for this field |
|
| 2766 | - if (empty($this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'])) { |
|
| 2767 | - //this has already been through the template field validator and sanitized, so it will be |
|
| 2768 | - //safe to insert this field. Why insert? This typically happens when we introduce a new |
|
| 2769 | - //message template field in a messenger/message type and existing users don't have the |
|
| 2770 | - //default setup for it. |
|
| 2771 | - //@link https://events.codebasehq.com/projects/event-espresso/tickets/9465 |
|
| 2772 | - $updated = $MTP->insert($message_template_fields); |
|
| 2773 | - if (! $updated || is_wp_error($updated)) { |
|
| 2774 | - EE_Error::add_error( |
|
| 2775 | - sprintf( |
|
| 2776 | - esc_html__('%s field could not be updated.', 'event_espresso'), |
|
| 2777 | - $template_field |
|
| 2778 | - ), |
|
| 2779 | - __FILE__, |
|
| 2780 | - __FUNCTION__, |
|
| 2781 | - __LINE__ |
|
| 2782 | - ); |
|
| 2783 | - $success = 0; |
|
| 2784 | - } else { |
|
| 2785 | - $success = 1; |
|
| 2786 | - } |
|
| 2787 | - } |
|
| 2788 | - } |
|
| 2789 | - $action_desc = 'updated'; |
|
| 2790 | - } |
|
| 2744 | + $message_template_fields = array( |
|
| 2745 | + 'GRP_ID' => $set_column_values['GRP_ID'], |
|
| 2746 | + 'MTP_template_field' => $set_column_values['MTP_template_field'], |
|
| 2747 | + 'MTP_context' => $set_column_values['MTP_context'], |
|
| 2748 | + 'MTP_content' => $set_column_values['MTP_content'] |
|
| 2749 | + ); |
|
| 2750 | + if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) { |
|
| 2751 | + if ($updated === false) { |
|
| 2752 | + EE_Error::add_error( |
|
| 2753 | + sprintf( |
|
| 2754 | + esc_html__('%s field was NOT updated for some reason', 'event_espresso'), |
|
| 2755 | + $template_field |
|
| 2756 | + ), |
|
| 2757 | + __FILE__, |
|
| 2758 | + __FUNCTION__, |
|
| 2759 | + __LINE__ |
|
| 2760 | + ); |
|
| 2761 | + } else { |
|
| 2762 | + $success = 1; |
|
| 2763 | + } |
|
| 2764 | + } else { |
|
| 2765 | + //only do this logic if we don't have a MTP_ID for this field |
|
| 2766 | + if (empty($this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'])) { |
|
| 2767 | + //this has already been through the template field validator and sanitized, so it will be |
|
| 2768 | + //safe to insert this field. Why insert? This typically happens when we introduce a new |
|
| 2769 | + //message template field in a messenger/message type and existing users don't have the |
|
| 2770 | + //default setup for it. |
|
| 2771 | + //@link https://events.codebasehq.com/projects/event-espresso/tickets/9465 |
|
| 2772 | + $updated = $MTP->insert($message_template_fields); |
|
| 2773 | + if (! $updated || is_wp_error($updated)) { |
|
| 2774 | + EE_Error::add_error( |
|
| 2775 | + sprintf( |
|
| 2776 | + esc_html__('%s field could not be updated.', 'event_espresso'), |
|
| 2777 | + $template_field |
|
| 2778 | + ), |
|
| 2779 | + __FILE__, |
|
| 2780 | + __FUNCTION__, |
|
| 2781 | + __LINE__ |
|
| 2782 | + ); |
|
| 2783 | + $success = 0; |
|
| 2784 | + } else { |
|
| 2785 | + $success = 1; |
|
| 2786 | + } |
|
| 2787 | + } |
|
| 2788 | + } |
|
| 2789 | + $action_desc = 'updated'; |
|
| 2790 | + } |
|
| 2791 | 2791 | |
| 2792 | - //we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs) |
|
| 2793 | - $mtpg_fields = array( |
|
| 2794 | - 'MTP_user_id' => $set_column_values['MTP_user_id'], |
|
| 2795 | - 'MTP_messenger' => $set_column_values['MTP_messenger'], |
|
| 2796 | - 'MTP_message_type' => $set_column_values['MTP_message_type'], |
|
| 2797 | - 'MTP_is_global' => $set_column_values['MTP_is_global'], |
|
| 2798 | - 'MTP_is_override' => $set_column_values['MTP_is_override'], |
|
| 2799 | - 'MTP_deleted' => $set_column_values['MTP_deleted'], |
|
| 2800 | - 'MTP_is_active' => $set_column_values['MTP_is_active'], |
|
| 2801 | - 'MTP_name' => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name']) |
|
| 2802 | - ? $this->_req_data['ee_msg_non_global_fields']['MTP_name'] |
|
| 2803 | - : '', |
|
| 2804 | - 'MTP_description' => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description']) |
|
| 2805 | - ? $this->_req_data['ee_msg_non_global_fields']['MTP_description'] |
|
| 2806 | - : '' |
|
| 2807 | - ); |
|
| 2792 | + //we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs) |
|
| 2793 | + $mtpg_fields = array( |
|
| 2794 | + 'MTP_user_id' => $set_column_values['MTP_user_id'], |
|
| 2795 | + 'MTP_messenger' => $set_column_values['MTP_messenger'], |
|
| 2796 | + 'MTP_message_type' => $set_column_values['MTP_message_type'], |
|
| 2797 | + 'MTP_is_global' => $set_column_values['MTP_is_global'], |
|
| 2798 | + 'MTP_is_override' => $set_column_values['MTP_is_override'], |
|
| 2799 | + 'MTP_deleted' => $set_column_values['MTP_deleted'], |
|
| 2800 | + 'MTP_is_active' => $set_column_values['MTP_is_active'], |
|
| 2801 | + 'MTP_name' => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name']) |
|
| 2802 | + ? $this->_req_data['ee_msg_non_global_fields']['MTP_name'] |
|
| 2803 | + : '', |
|
| 2804 | + 'MTP_description' => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description']) |
|
| 2805 | + ? $this->_req_data['ee_msg_non_global_fields']['MTP_description'] |
|
| 2806 | + : '' |
|
| 2807 | + ); |
|
| 2808 | 2808 | |
| 2809 | - $mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']); |
|
| 2810 | - $updated = $MTPG->update($mtpg_fields, array($mtpg_where)); |
|
| 2809 | + $mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']); |
|
| 2810 | + $updated = $MTPG->update($mtpg_fields, array($mtpg_where)); |
|
| 2811 | 2811 | |
| 2812 | - if ($updated === false) { |
|
| 2813 | - EE_Error::add_error( |
|
| 2814 | - sprintf( |
|
| 2815 | - esc_html__( |
|
| 2816 | - 'The Message Template Group (%d) was NOT updated for some reason', |
|
| 2817 | - 'event_espresso' |
|
| 2818 | - ), |
|
| 2819 | - $set_column_values['GRP_ID'] |
|
| 2820 | - ), |
|
| 2821 | - __FILE__, |
|
| 2822 | - __FUNCTION__, |
|
| 2823 | - __LINE__ |
|
| 2824 | - ); |
|
| 2825 | - } else { |
|
| 2826 | - //k now we need to ensure the template_pack and template_variation fields are set. |
|
| 2827 | - $template_pack = ! empty($this->_req_data['MTP_template_pack']) |
|
| 2828 | - ? $this->_req_data['MTP_template_pack'] |
|
| 2829 | - : 'default'; |
|
| 2812 | + if ($updated === false) { |
|
| 2813 | + EE_Error::add_error( |
|
| 2814 | + sprintf( |
|
| 2815 | + esc_html__( |
|
| 2816 | + 'The Message Template Group (%d) was NOT updated for some reason', |
|
| 2817 | + 'event_espresso' |
|
| 2818 | + ), |
|
| 2819 | + $set_column_values['GRP_ID'] |
|
| 2820 | + ), |
|
| 2821 | + __FILE__, |
|
| 2822 | + __FUNCTION__, |
|
| 2823 | + __LINE__ |
|
| 2824 | + ); |
|
| 2825 | + } else { |
|
| 2826 | + //k now we need to ensure the template_pack and template_variation fields are set. |
|
| 2827 | + $template_pack = ! empty($this->_req_data['MTP_template_pack']) |
|
| 2828 | + ? $this->_req_data['MTP_template_pack'] |
|
| 2829 | + : 'default'; |
|
| 2830 | 2830 | |
| 2831 | - $template_variation = ! empty($this->_req_data['MTP_template_variation']) |
|
| 2832 | - ? $this->_req_data['MTP_template_variation'] |
|
| 2833 | - : 'default'; |
|
| 2831 | + $template_variation = ! empty($this->_req_data['MTP_template_variation']) |
|
| 2832 | + ? $this->_req_data['MTP_template_variation'] |
|
| 2833 | + : 'default'; |
|
| 2834 | 2834 | |
| 2835 | - $mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']); |
|
| 2836 | - if ($mtpg_obj instanceof EE_Message_Template_Group) { |
|
| 2837 | - $mtpg_obj->set_template_pack_name($template_pack); |
|
| 2838 | - $mtpg_obj->set_template_pack_variation($template_variation); |
|
| 2839 | - } |
|
| 2840 | - $success = 1; |
|
| 2841 | - } |
|
| 2842 | - } |
|
| 2843 | - } |
|
| 2835 | + $mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']); |
|
| 2836 | + if ($mtpg_obj instanceof EE_Message_Template_Group) { |
|
| 2837 | + $mtpg_obj->set_template_pack_name($template_pack); |
|
| 2838 | + $mtpg_obj->set_template_pack_variation($template_variation); |
|
| 2839 | + } |
|
| 2840 | + $success = 1; |
|
| 2841 | + } |
|
| 2842 | + } |
|
| 2843 | + } |
|
| 2844 | 2844 | |
| 2845 | - } |
|
| 2846 | - |
|
| 2847 | - //we return things differently if doing ajax |
|
| 2848 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2849 | - $this->_template_args['success'] = $success; |
|
| 2850 | - $this->_template_args['error'] = ! $success ? true : false; |
|
| 2851 | - $this->_template_args['content'] = ''; |
|
| 2852 | - $this->_template_args['data'] = array( |
|
| 2853 | - 'grpID' => $edit_array['GRP_ID'], |
|
| 2854 | - 'templateName' => $edit_array['template_name'] |
|
| 2855 | - ); |
|
| 2856 | - if ($success) { |
|
| 2857 | - EE_Error::overwrite_success(); |
|
| 2858 | - EE_Error::add_success( |
|
| 2859 | - esc_html__( |
|
| 2860 | - 'The new template has been created and automatically selected for this event. You can edit the new template by clicking the edit button. Note before this template is assigned to this event, the event must be saved.', |
|
| 2861 | - 'event_espresso' |
|
| 2862 | - ) |
|
| 2863 | - ); |
|
| 2864 | - } |
|
| 2845 | + } |
|
| 2846 | + |
|
| 2847 | + //we return things differently if doing ajax |
|
| 2848 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2849 | + $this->_template_args['success'] = $success; |
|
| 2850 | + $this->_template_args['error'] = ! $success ? true : false; |
|
| 2851 | + $this->_template_args['content'] = ''; |
|
| 2852 | + $this->_template_args['data'] = array( |
|
| 2853 | + 'grpID' => $edit_array['GRP_ID'], |
|
| 2854 | + 'templateName' => $edit_array['template_name'] |
|
| 2855 | + ); |
|
| 2856 | + if ($success) { |
|
| 2857 | + EE_Error::overwrite_success(); |
|
| 2858 | + EE_Error::add_success( |
|
| 2859 | + esc_html__( |
|
| 2860 | + 'The new template has been created and automatically selected for this event. You can edit the new template by clicking the edit button. Note before this template is assigned to this event, the event must be saved.', |
|
| 2861 | + 'event_espresso' |
|
| 2862 | + ) |
|
| 2863 | + ); |
|
| 2864 | + } |
|
| 2865 | 2865 | |
| 2866 | - $this->_return_json(); |
|
| 2867 | - } |
|
| 2868 | - |
|
| 2869 | - |
|
| 2870 | - //was a test send triggered? |
|
| 2871 | - if (isset($this->_req_data['test_button'])) { |
|
| 2872 | - EE_Error::overwrite_success(); |
|
| 2873 | - $this->_do_test_send($context_slug, $messenger_slug, $message_type_slug); |
|
| 2874 | - $override = true; |
|
| 2875 | - } |
|
| 2876 | - |
|
| 2877 | - if (empty($query_args)) { |
|
| 2878 | - $query_args = array( |
|
| 2879 | - 'id' => $this->_req_data['GRP_ID'], |
|
| 2880 | - 'context' => $context_slug, |
|
| 2881 | - 'action' => 'edit_message_template' |
|
| 2882 | - ); |
|
| 2883 | - } |
|
| 2884 | - |
|
| 2885 | - $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override); |
|
| 2886 | - } |
|
| 2866 | + $this->_return_json(); |
|
| 2867 | + } |
|
| 2868 | + |
|
| 2869 | + |
|
| 2870 | + //was a test send triggered? |
|
| 2871 | + if (isset($this->_req_data['test_button'])) { |
|
| 2872 | + EE_Error::overwrite_success(); |
|
| 2873 | + $this->_do_test_send($context_slug, $messenger_slug, $message_type_slug); |
|
| 2874 | + $override = true; |
|
| 2875 | + } |
|
| 2876 | + |
|
| 2877 | + if (empty($query_args)) { |
|
| 2878 | + $query_args = array( |
|
| 2879 | + 'id' => $this->_req_data['GRP_ID'], |
|
| 2880 | + 'context' => $context_slug, |
|
| 2881 | + 'action' => 'edit_message_template' |
|
| 2882 | + ); |
|
| 2883 | + } |
|
| 2884 | + |
|
| 2885 | + $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override); |
|
| 2886 | + } |
|
| 2887 | 2887 | |
| 2888 | 2888 | |
| 2889 | - /** |
|
| 2890 | - * processes a test send request to do an actual messenger delivery test for the given message template being tested |
|
| 2891 | - * |
|
| 2892 | - * @param string $context what context being tested |
|
| 2893 | - * @param string $messenger messenger being tested |
|
| 2894 | - * @param string $message_type message type being tested |
|
| 2895 | - * @throws EE_Error |
|
| 2896 | - * @throws InvalidArgumentException |
|
| 2897 | - * @throws InvalidDataTypeException |
|
| 2898 | - * @throws InvalidInterfaceException |
|
| 2899 | - */ |
|
| 2900 | - protected function _do_test_send($context, $messenger, $message_type) |
|
| 2901 | - { |
|
| 2902 | - //set things up for preview |
|
| 2903 | - $this->_req_data['messenger'] = $messenger; |
|
| 2904 | - $this->_req_data['message_type'] = $message_type; |
|
| 2905 | - $this->_req_data['context'] = $context; |
|
| 2906 | - $this->_req_data['GRP_ID'] = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : ''; |
|
| 2907 | - $active_messenger = $this->_message_resource_manager->get_active_messenger($messenger); |
|
| 2908 | - |
|
| 2909 | - //let's save any existing fields that might be required by the messenger |
|
| 2910 | - if ( |
|
| 2911 | - isset($this->_req_data['test_settings_fld']) |
|
| 2912 | - && $active_messenger instanceof EE_messenger |
|
| 2913 | - && apply_filters( |
|
| 2914 | - 'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings', |
|
| 2915 | - true, |
|
| 2916 | - $this->_req_data['test_settings_fld'], |
|
| 2917 | - $active_messenger |
|
| 2918 | - ) |
|
| 2919 | - ) { |
|
| 2920 | - $active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']); |
|
| 2921 | - } |
|
| 2922 | - |
|
| 2923 | - $success = $this->_preview_message(true); |
|
| 2924 | - |
|
| 2925 | - if ($success) { |
|
| 2926 | - EE_Error::add_success(__('Test message sent', 'event_espresso')); |
|
| 2927 | - } else { |
|
| 2928 | - EE_Error::add_error( |
|
| 2929 | - esc_html__('The test message was not sent', 'event_espresso'), |
|
| 2930 | - __FILE__, |
|
| 2931 | - __FUNCTION__, |
|
| 2932 | - __LINE__ |
|
| 2933 | - ); |
|
| 2934 | - } |
|
| 2935 | - } |
|
| 2889 | + /** |
|
| 2890 | + * processes a test send request to do an actual messenger delivery test for the given message template being tested |
|
| 2891 | + * |
|
| 2892 | + * @param string $context what context being tested |
|
| 2893 | + * @param string $messenger messenger being tested |
|
| 2894 | + * @param string $message_type message type being tested |
|
| 2895 | + * @throws EE_Error |
|
| 2896 | + * @throws InvalidArgumentException |
|
| 2897 | + * @throws InvalidDataTypeException |
|
| 2898 | + * @throws InvalidInterfaceException |
|
| 2899 | + */ |
|
| 2900 | + protected function _do_test_send($context, $messenger, $message_type) |
|
| 2901 | + { |
|
| 2902 | + //set things up for preview |
|
| 2903 | + $this->_req_data['messenger'] = $messenger; |
|
| 2904 | + $this->_req_data['message_type'] = $message_type; |
|
| 2905 | + $this->_req_data['context'] = $context; |
|
| 2906 | + $this->_req_data['GRP_ID'] = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : ''; |
|
| 2907 | + $active_messenger = $this->_message_resource_manager->get_active_messenger($messenger); |
|
| 2908 | + |
|
| 2909 | + //let's save any existing fields that might be required by the messenger |
|
| 2910 | + if ( |
|
| 2911 | + isset($this->_req_data['test_settings_fld']) |
|
| 2912 | + && $active_messenger instanceof EE_messenger |
|
| 2913 | + && apply_filters( |
|
| 2914 | + 'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings', |
|
| 2915 | + true, |
|
| 2916 | + $this->_req_data['test_settings_fld'], |
|
| 2917 | + $active_messenger |
|
| 2918 | + ) |
|
| 2919 | + ) { |
|
| 2920 | + $active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']); |
|
| 2921 | + } |
|
| 2922 | + |
|
| 2923 | + $success = $this->_preview_message(true); |
|
| 2924 | + |
|
| 2925 | + if ($success) { |
|
| 2926 | + EE_Error::add_success(__('Test message sent', 'event_espresso')); |
|
| 2927 | + } else { |
|
| 2928 | + EE_Error::add_error( |
|
| 2929 | + esc_html__('The test message was not sent', 'event_espresso'), |
|
| 2930 | + __FILE__, |
|
| 2931 | + __FUNCTION__, |
|
| 2932 | + __LINE__ |
|
| 2933 | + ); |
|
| 2934 | + } |
|
| 2935 | + } |
|
| 2936 | 2936 | |
| 2937 | 2937 | |
| 2938 | - /** |
|
| 2939 | - * _generate_new_templates |
|
| 2940 | - * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will |
|
| 2941 | - * automatically create the defaults for the event. The user would then be redirected to edit the default context |
|
| 2942 | - * for the event. |
|
| 2943 | - * |
|
| 2944 | - * |
|
| 2945 | - * @param string $messenger the messenger we are generating templates for |
|
| 2946 | - * @param array $message_types array of message types that the templates are generated for. |
|
| 2947 | - * @param int $GRP_ID If this is a custom template being generated then a GRP_ID needs to be included to |
|
| 2948 | - * indicate the message_template_group being used as the base. |
|
| 2949 | - * |
|
| 2950 | - * @param bool $global |
|
| 2951 | - * |
|
| 2952 | - * @return array|bool array of data required for the redirect to the correct edit page or bool if |
|
| 2953 | - * encountering problems. |
|
| 2954 | - * @throws EE_Error |
|
| 2955 | - */ |
|
| 2956 | - protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false) |
|
| 2957 | - { |
|
| 2958 | - |
|
| 2959 | - //if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we |
|
| 2960 | - // just don't generate any templates. |
|
| 2961 | - if (empty($message_types)) { |
|
| 2962 | - return true; |
|
| 2963 | - } |
|
| 2964 | - |
|
| 2965 | - return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global); |
|
| 2966 | - } |
|
| 2938 | + /** |
|
| 2939 | + * _generate_new_templates |
|
| 2940 | + * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will |
|
| 2941 | + * automatically create the defaults for the event. The user would then be redirected to edit the default context |
|
| 2942 | + * for the event. |
|
| 2943 | + * |
|
| 2944 | + * |
|
| 2945 | + * @param string $messenger the messenger we are generating templates for |
|
| 2946 | + * @param array $message_types array of message types that the templates are generated for. |
|
| 2947 | + * @param int $GRP_ID If this is a custom template being generated then a GRP_ID needs to be included to |
|
| 2948 | + * indicate the message_template_group being used as the base. |
|
| 2949 | + * |
|
| 2950 | + * @param bool $global |
|
| 2951 | + * |
|
| 2952 | + * @return array|bool array of data required for the redirect to the correct edit page or bool if |
|
| 2953 | + * encountering problems. |
|
| 2954 | + * @throws EE_Error |
|
| 2955 | + */ |
|
| 2956 | + protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false) |
|
| 2957 | + { |
|
| 2958 | + |
|
| 2959 | + //if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we |
|
| 2960 | + // just don't generate any templates. |
|
| 2961 | + if (empty($message_types)) { |
|
| 2962 | + return true; |
|
| 2963 | + } |
|
| 2964 | + |
|
| 2965 | + return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global); |
|
| 2966 | + } |
|
| 2967 | 2967 | |
| 2968 | 2968 | |
| 2969 | - /** |
|
| 2970 | - * [_trash_or_restore_message_template] |
|
| 2971 | - * |
|
| 2972 | - * @param boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE) |
|
| 2973 | - * @param boolean $all whether this is going to trash/restore all contexts within a template group (TRUE) OR just |
|
| 2974 | - * an individual context (FALSE). |
|
| 2975 | - * @return void |
|
| 2976 | - * @throws EE_Error |
|
| 2977 | - * @throws InvalidArgumentException |
|
| 2978 | - * @throws InvalidDataTypeException |
|
| 2979 | - * @throws InvalidInterfaceException |
|
| 2980 | - */ |
|
| 2981 | - protected function _trash_or_restore_message_template($trash = true, $all = false) |
|
| 2982 | - { |
|
| 2983 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2984 | - $MTP = EEM_Message_Template_Group::instance(); |
|
| 2985 | - |
|
| 2986 | - $success = 1; |
|
| 2987 | - |
|
| 2988 | - //incoming GRP_IDs |
|
| 2989 | - if ($all) { |
|
| 2990 | - //Checkboxes |
|
| 2991 | - if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 2992 | - //if array has more than one element then success message should be plural. |
|
| 2993 | - //todo: what about nonce? |
|
| 2994 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 2969 | + /** |
|
| 2970 | + * [_trash_or_restore_message_template] |
|
| 2971 | + * |
|
| 2972 | + * @param boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE) |
|
| 2973 | + * @param boolean $all whether this is going to trash/restore all contexts within a template group (TRUE) OR just |
|
| 2974 | + * an individual context (FALSE). |
|
| 2975 | + * @return void |
|
| 2976 | + * @throws EE_Error |
|
| 2977 | + * @throws InvalidArgumentException |
|
| 2978 | + * @throws InvalidDataTypeException |
|
| 2979 | + * @throws InvalidInterfaceException |
|
| 2980 | + */ |
|
| 2981 | + protected function _trash_or_restore_message_template($trash = true, $all = false) |
|
| 2982 | + { |
|
| 2983 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2984 | + $MTP = EEM_Message_Template_Group::instance(); |
|
| 2985 | + |
|
| 2986 | + $success = 1; |
|
| 2987 | + |
|
| 2988 | + //incoming GRP_IDs |
|
| 2989 | + if ($all) { |
|
| 2990 | + //Checkboxes |
|
| 2991 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 2992 | + //if array has more than one element then success message should be plural. |
|
| 2993 | + //todo: what about nonce? |
|
| 2994 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 2995 | 2995 | |
| 2996 | - //cycle through checkboxes |
|
| 2997 | - while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 2998 | - $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID); |
|
| 2999 | - if ( ! $trashed_or_restored) { |
|
| 3000 | - $success = 0; |
|
| 3001 | - } |
|
| 3002 | - } |
|
| 3003 | - } else { |
|
| 3004 | - //grab single GRP_ID and handle |
|
| 3005 | - $GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0; |
|
| 3006 | - if ( ! empty($GRP_ID)) { |
|
| 3007 | - $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID); |
|
| 3008 | - if ( ! $trashed_or_restored) { |
|
| 3009 | - $success = 0; |
|
| 3010 | - } |
|
| 3011 | - } else { |
|
| 3012 | - $success = 0; |
|
| 3013 | - } |
|
| 3014 | - } |
|
| 2996 | + //cycle through checkboxes |
|
| 2997 | + while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 2998 | + $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID); |
|
| 2999 | + if ( ! $trashed_or_restored) { |
|
| 3000 | + $success = 0; |
|
| 3001 | + } |
|
| 3002 | + } |
|
| 3003 | + } else { |
|
| 3004 | + //grab single GRP_ID and handle |
|
| 3005 | + $GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0; |
|
| 3006 | + if ( ! empty($GRP_ID)) { |
|
| 3007 | + $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID); |
|
| 3008 | + if ( ! $trashed_or_restored) { |
|
| 3009 | + $success = 0; |
|
| 3010 | + } |
|
| 3011 | + } else { |
|
| 3012 | + $success = 0; |
|
| 3013 | + } |
|
| 3014 | + } |
|
| 3015 | 3015 | |
| 3016 | - } |
|
| 3016 | + } |
|
| 3017 | 3017 | |
| 3018 | - $action_desc = $trash |
|
| 3019 | - ? esc_html__('moved to the trash', 'event_espresso') |
|
| 3020 | - : esc_html__('restored', 'event_espresso'); |
|
| 3018 | + $action_desc = $trash |
|
| 3019 | + ? esc_html__('moved to the trash', 'event_espresso') |
|
| 3020 | + : esc_html__('restored', 'event_espresso'); |
|
| 3021 | 3021 | |
| 3022 | - $action_desc = ! empty($this->_req_data['template_switch']) ? esc_html__('switched') : $action_desc; |
|
| 3022 | + $action_desc = ! empty($this->_req_data['template_switch']) ? esc_html__('switched') : $action_desc; |
|
| 3023 | 3023 | |
| 3024 | - $item_desc = $all ? _n('Message Template Group', 'Message Template Groups', $success, |
|
| 3025 | - 'event_espresso') : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso'); |
|
| 3024 | + $item_desc = $all ? _n('Message Template Group', 'Message Template Groups', $success, |
|
| 3025 | + 'event_espresso') : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso'); |
|
| 3026 | 3026 | |
| 3027 | - $item_desc = ! empty($this->_req_data['template_switch']) ? _n('template', 'templates', $success, |
|
| 3028 | - 'event_espresso') : $item_desc; |
|
| 3027 | + $item_desc = ! empty($this->_req_data['template_switch']) ? _n('template', 'templates', $success, |
|
| 3028 | + 'event_espresso') : $item_desc; |
|
| 3029 | 3029 | |
| 3030 | - $this->_redirect_after_action($success, $item_desc, $action_desc, array()); |
|
| 3030 | + $this->_redirect_after_action($success, $item_desc, $action_desc, array()); |
|
| 3031 | 3031 | |
| 3032 | - } |
|
| 3032 | + } |
|
| 3033 | 3033 | |
| 3034 | 3034 | |
| 3035 | - /** |
|
| 3036 | - * [_delete_message_template] |
|
| 3037 | - * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group. |
|
| 3038 | - * |
|
| 3039 | - * @return void |
|
| 3040 | - * @throws EE_Error |
|
| 3041 | - * @throws InvalidArgumentException |
|
| 3042 | - * @throws InvalidDataTypeException |
|
| 3043 | - * @throws InvalidInterfaceException |
|
| 3044 | - */ |
|
| 3045 | - protected function _delete_message_template() |
|
| 3046 | - { |
|
| 3047 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3048 | - |
|
| 3049 | - //checkboxes |
|
| 3050 | - if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 3051 | - //if array has more than one element then success message should be plural |
|
| 3052 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 3035 | + /** |
|
| 3036 | + * [_delete_message_template] |
|
| 3037 | + * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group. |
|
| 3038 | + * |
|
| 3039 | + * @return void |
|
| 3040 | + * @throws EE_Error |
|
| 3041 | + * @throws InvalidArgumentException |
|
| 3042 | + * @throws InvalidDataTypeException |
|
| 3043 | + * @throws InvalidInterfaceException |
|
| 3044 | + */ |
|
| 3045 | + protected function _delete_message_template() |
|
| 3046 | + { |
|
| 3047 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3048 | + |
|
| 3049 | + //checkboxes |
|
| 3050 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 3051 | + //if array has more than one element then success message should be plural |
|
| 3052 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 3053 | 3053 | |
| 3054 | - //cycle through bulk action checkboxes |
|
| 3055 | - while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 3056 | - $success = $this->_delete_mtp_permanently($GRP_ID); |
|
| 3057 | - } |
|
| 3058 | - } else { |
|
| 3059 | - //grab single grp_id and delete |
|
| 3060 | - $GRP_ID = absint($this->_req_data['id']); |
|
| 3061 | - $success = $this->_delete_mtp_permanently($GRP_ID); |
|
| 3062 | - } |
|
| 3063 | - |
|
| 3064 | - $this->_redirect_after_action($success, 'Message Templates', 'deleted', array()); |
|
| 3065 | - |
|
| 3066 | - } |
|
| 3054 | + //cycle through bulk action checkboxes |
|
| 3055 | + while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 3056 | + $success = $this->_delete_mtp_permanently($GRP_ID); |
|
| 3057 | + } |
|
| 3058 | + } else { |
|
| 3059 | + //grab single grp_id and delete |
|
| 3060 | + $GRP_ID = absint($this->_req_data['id']); |
|
| 3061 | + $success = $this->_delete_mtp_permanently($GRP_ID); |
|
| 3062 | + } |
|
| 3063 | + |
|
| 3064 | + $this->_redirect_after_action($success, 'Message Templates', 'deleted', array()); |
|
| 3065 | + |
|
| 3066 | + } |
|
| 3067 | 3067 | |
| 3068 | 3068 | |
| 3069 | - /** |
|
| 3070 | - * helper for permanently deleting a mtP group and all related message_templates |
|
| 3071 | - * |
|
| 3072 | - * @param int $GRP_ID The group being deleted |
|
| 3073 | - * @param bool $include_group whether to delete the Message Template Group as well. |
|
| 3074 | - * @return bool boolean to indicate the success of the deletes or not. |
|
| 3075 | - * @throws EE_Error |
|
| 3076 | - * @throws InvalidArgumentException |
|
| 3077 | - * @throws InvalidDataTypeException |
|
| 3078 | - * @throws InvalidInterfaceException |
|
| 3079 | - */ |
|
| 3080 | - private function _delete_mtp_permanently($GRP_ID, $include_group = true) |
|
| 3081 | - { |
|
| 3082 | - $success = 1; |
|
| 3083 | - $MTPG = EEM_Message_Template_Group::instance(); |
|
| 3084 | - //first let's GET this group |
|
| 3085 | - $MTG = $MTPG->get_one_by_ID($GRP_ID); |
|
| 3086 | - //then delete permanently all the related Message Templates |
|
| 3087 | - $deleted = $MTG->delete_related_permanently('Message_Template'); |
|
| 3088 | - |
|
| 3089 | - if ($deleted === 0) { |
|
| 3090 | - $success = 0; |
|
| 3091 | - } |
|
| 3092 | - |
|
| 3093 | - //now delete permanently this particular group |
|
| 3094 | - |
|
| 3095 | - if ($include_group && ! $MTG->delete_permanently()) { |
|
| 3096 | - $success = 0; |
|
| 3097 | - } |
|
| 3098 | - |
|
| 3099 | - return $success; |
|
| 3100 | - } |
|
| 3069 | + /** |
|
| 3070 | + * helper for permanently deleting a mtP group and all related message_templates |
|
| 3071 | + * |
|
| 3072 | + * @param int $GRP_ID The group being deleted |
|
| 3073 | + * @param bool $include_group whether to delete the Message Template Group as well. |
|
| 3074 | + * @return bool boolean to indicate the success of the deletes or not. |
|
| 3075 | + * @throws EE_Error |
|
| 3076 | + * @throws InvalidArgumentException |
|
| 3077 | + * @throws InvalidDataTypeException |
|
| 3078 | + * @throws InvalidInterfaceException |
|
| 3079 | + */ |
|
| 3080 | + private function _delete_mtp_permanently($GRP_ID, $include_group = true) |
|
| 3081 | + { |
|
| 3082 | + $success = 1; |
|
| 3083 | + $MTPG = EEM_Message_Template_Group::instance(); |
|
| 3084 | + //first let's GET this group |
|
| 3085 | + $MTG = $MTPG->get_one_by_ID($GRP_ID); |
|
| 3086 | + //then delete permanently all the related Message Templates |
|
| 3087 | + $deleted = $MTG->delete_related_permanently('Message_Template'); |
|
| 3088 | + |
|
| 3089 | + if ($deleted === 0) { |
|
| 3090 | + $success = 0; |
|
| 3091 | + } |
|
| 3092 | + |
|
| 3093 | + //now delete permanently this particular group |
|
| 3094 | + |
|
| 3095 | + if ($include_group && ! $MTG->delete_permanently()) { |
|
| 3096 | + $success = 0; |
|
| 3097 | + } |
|
| 3098 | + |
|
| 3099 | + return $success; |
|
| 3100 | + } |
|
| 3101 | 3101 | |
| 3102 | 3102 | |
| 3103 | - /** |
|
| 3104 | - * _learn_more_about_message_templates_link |
|
| 3105 | - * @access protected |
|
| 3106 | - * @return string |
|
| 3107 | - */ |
|
| 3108 | - protected function _learn_more_about_message_templates_link() |
|
| 3109 | - { |
|
| 3110 | - return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' |
|
| 3111 | - . esc_html__('learn more about how message templates works', 'event_espresso') |
|
| 3112 | - . '</a>'; |
|
| 3113 | - } |
|
| 3103 | + /** |
|
| 3104 | + * _learn_more_about_message_templates_link |
|
| 3105 | + * @access protected |
|
| 3106 | + * @return string |
|
| 3107 | + */ |
|
| 3108 | + protected function _learn_more_about_message_templates_link() |
|
| 3109 | + { |
|
| 3110 | + return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' |
|
| 3111 | + . esc_html__('learn more about how message templates works', 'event_espresso') |
|
| 3112 | + . '</a>'; |
|
| 3113 | + } |
|
| 3114 | 3114 | |
| 3115 | 3115 | |
| 3116 | - /** |
|
| 3117 | - * Used for setting up messenger/message type activation. This loads up the initial view. The rest is handled by |
|
| 3118 | - * ajax and other routes. |
|
| 3119 | - * |
|
| 3120 | - * @return void |
|
| 3121 | - * @throws DomainException |
|
| 3122 | - */ |
|
| 3123 | - protected function _settings() |
|
| 3124 | - { |
|
| 3125 | - |
|
| 3126 | - |
|
| 3127 | - $this->_set_m_mt_settings(); |
|
| 3128 | - |
|
| 3129 | - $selected_messenger = isset($this->_req_data['selected_messenger']) |
|
| 3130 | - ? $this->_req_data['selected_messenger'] |
|
| 3131 | - : 'email'; |
|
| 3132 | - |
|
| 3133 | - //let's setup the messenger tabs |
|
| 3134 | - $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links( |
|
| 3135 | - $this->_m_mt_settings['messenger_tabs'], |
|
| 3136 | - 'messenger_links', |
|
| 3137 | - '|', |
|
| 3138 | - $selected_messenger |
|
| 3139 | - ); |
|
| 3140 | - $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">'; |
|
| 3141 | - $this->_template_args['after_admin_page_content'] = '</div><!-- end .ui-widget -->'; |
|
| 3142 | - |
|
| 3143 | - $this->display_admin_page_with_sidebar(); |
|
| 3144 | - |
|
| 3145 | - } |
|
| 3116 | + /** |
|
| 3117 | + * Used for setting up messenger/message type activation. This loads up the initial view. The rest is handled by |
|
| 3118 | + * ajax and other routes. |
|
| 3119 | + * |
|
| 3120 | + * @return void |
|
| 3121 | + * @throws DomainException |
|
| 3122 | + */ |
|
| 3123 | + protected function _settings() |
|
| 3124 | + { |
|
| 3125 | + |
|
| 3126 | + |
|
| 3127 | + $this->_set_m_mt_settings(); |
|
| 3128 | + |
|
| 3129 | + $selected_messenger = isset($this->_req_data['selected_messenger']) |
|
| 3130 | + ? $this->_req_data['selected_messenger'] |
|
| 3131 | + : 'email'; |
|
| 3132 | + |
|
| 3133 | + //let's setup the messenger tabs |
|
| 3134 | + $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links( |
|
| 3135 | + $this->_m_mt_settings['messenger_tabs'], |
|
| 3136 | + 'messenger_links', |
|
| 3137 | + '|', |
|
| 3138 | + $selected_messenger |
|
| 3139 | + ); |
|
| 3140 | + $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">'; |
|
| 3141 | + $this->_template_args['after_admin_page_content'] = '</div><!-- end .ui-widget -->'; |
|
| 3142 | + |
|
| 3143 | + $this->display_admin_page_with_sidebar(); |
|
| 3144 | + |
|
| 3145 | + } |
|
| 3146 | 3146 | |
| 3147 | 3147 | |
| 3148 | - /** |
|
| 3149 | - * This sets the $_m_mt_settings property for when needed (used on the Messages settings page) |
|
| 3150 | - * |
|
| 3151 | - * @access protected |
|
| 3152 | - * @return void |
|
| 3153 | - * @throws DomainException |
|
| 3154 | - */ |
|
| 3155 | - protected function _set_m_mt_settings() |
|
| 3156 | - { |
|
| 3157 | - //first if this is already set then lets get out no need to regenerate data. |
|
| 3158 | - if ( ! empty($this->_m_mt_settings)) { |
|
| 3159 | - return; |
|
| 3160 | - } |
|
| 3161 | - |
|
| 3162 | - //get all installed messengers and message_types |
|
| 3163 | - /** @type EE_messenger[] $messengers */ |
|
| 3164 | - $messengers = $this->_message_resource_manager->installed_messengers(); |
|
| 3165 | - /** @type EE_message_type[] $message_types */ |
|
| 3166 | - $message_types = $this->_message_resource_manager->installed_message_types(); |
|
| 3167 | - |
|
| 3168 | - |
|
| 3169 | - //assemble the array for the _tab_text_links helper |
|
| 3170 | - |
|
| 3171 | - foreach ($messengers as $messenger) { |
|
| 3172 | - $this->_m_mt_settings['messenger_tabs'][$messenger->name] = array( |
|
| 3173 | - 'label' => ucwords($messenger->label['singular']), |
|
| 3174 | - 'class' => $this->_message_resource_manager->is_messenger_active($messenger->name) |
|
| 3175 | - ? 'messenger-active' |
|
| 3176 | - : '', |
|
| 3177 | - 'href' => $messenger->name, |
|
| 3178 | - 'title' => esc_html__('Modify this Messenger', 'event_espresso'), |
|
| 3179 | - 'slug' => $messenger->name, |
|
| 3180 | - 'obj' => $messenger |
|
| 3181 | - ); |
|
| 3148 | + /** |
|
| 3149 | + * This sets the $_m_mt_settings property for when needed (used on the Messages settings page) |
|
| 3150 | + * |
|
| 3151 | + * @access protected |
|
| 3152 | + * @return void |
|
| 3153 | + * @throws DomainException |
|
| 3154 | + */ |
|
| 3155 | + protected function _set_m_mt_settings() |
|
| 3156 | + { |
|
| 3157 | + //first if this is already set then lets get out no need to regenerate data. |
|
| 3158 | + if ( ! empty($this->_m_mt_settings)) { |
|
| 3159 | + return; |
|
| 3160 | + } |
|
| 3161 | + |
|
| 3162 | + //get all installed messengers and message_types |
|
| 3163 | + /** @type EE_messenger[] $messengers */ |
|
| 3164 | + $messengers = $this->_message_resource_manager->installed_messengers(); |
|
| 3165 | + /** @type EE_message_type[] $message_types */ |
|
| 3166 | + $message_types = $this->_message_resource_manager->installed_message_types(); |
|
| 3167 | + |
|
| 3168 | + |
|
| 3169 | + //assemble the array for the _tab_text_links helper |
|
| 3170 | + |
|
| 3171 | + foreach ($messengers as $messenger) { |
|
| 3172 | + $this->_m_mt_settings['messenger_tabs'][$messenger->name] = array( |
|
| 3173 | + 'label' => ucwords($messenger->label['singular']), |
|
| 3174 | + 'class' => $this->_message_resource_manager->is_messenger_active($messenger->name) |
|
| 3175 | + ? 'messenger-active' |
|
| 3176 | + : '', |
|
| 3177 | + 'href' => $messenger->name, |
|
| 3178 | + 'title' => esc_html__('Modify this Messenger', 'event_espresso'), |
|
| 3179 | + 'slug' => $messenger->name, |
|
| 3180 | + 'obj' => $messenger |
|
| 3181 | + ); |
|
| 3182 | 3182 | |
| 3183 | 3183 | |
| 3184 | - $message_types_for_messenger = $messenger->get_valid_message_types(); |
|
| 3184 | + $message_types_for_messenger = $messenger->get_valid_message_types(); |
|
| 3185 | 3185 | |
| 3186 | - foreach ($message_types as $message_type) { |
|
| 3187 | - //first we need to verify that this message type is valid with this messenger. Cause if it isn't then |
|
| 3188 | - // it shouldn't show in either the inactive OR active metabox. |
|
| 3189 | - if ( ! in_array($message_type->name, $message_types_for_messenger, true)) { |
|
| 3190 | - continue; |
|
| 3191 | - } |
|
| 3186 | + foreach ($message_types as $message_type) { |
|
| 3187 | + //first we need to verify that this message type is valid with this messenger. Cause if it isn't then |
|
| 3188 | + // it shouldn't show in either the inactive OR active metabox. |
|
| 3189 | + if ( ! in_array($message_type->name, $message_types_for_messenger, true)) { |
|
| 3190 | + continue; |
|
| 3191 | + } |
|
| 3192 | 3192 | |
| 3193 | - $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger( |
|
| 3194 | - $messenger->name, |
|
| 3195 | - $message_type->name |
|
| 3196 | - ) |
|
| 3197 | - ? 'active' |
|
| 3198 | - : 'inactive'; |
|
| 3193 | + $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger( |
|
| 3194 | + $messenger->name, |
|
| 3195 | + $message_type->name |
|
| 3196 | + ) |
|
| 3197 | + ? 'active' |
|
| 3198 | + : 'inactive'; |
|
| 3199 | 3199 | |
| 3200 | - $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array( |
|
| 3201 | - 'label' => ucwords($message_type->label['singular']), |
|
| 3202 | - 'class' => 'message-type-' . $a_or_i, |
|
| 3203 | - 'slug_id' => $message_type->name . '-messagetype-' . $messenger->name, |
|
| 3204 | - 'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'), |
|
| 3205 | - 'href' => 'espresso_' . $message_type->name . '_message_type_settings', |
|
| 3206 | - 'title' => $a_or_i === 'active' |
|
| 3207 | - ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso') |
|
| 3208 | - : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'), |
|
| 3209 | - 'content' => $a_or_i === 'active' |
|
| 3210 | - ? $this->_message_type_settings_content($message_type, $messenger, true) |
|
| 3211 | - : $this->_message_type_settings_content($message_type, $messenger), |
|
| 3212 | - 'slug' => $message_type->name, |
|
| 3213 | - 'active' => $a_or_i === 'active', |
|
| 3214 | - 'obj' => $message_type |
|
| 3215 | - ); |
|
| 3216 | - } |
|
| 3217 | - } |
|
| 3218 | - } |
|
| 3200 | + $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array( |
|
| 3201 | + 'label' => ucwords($message_type->label['singular']), |
|
| 3202 | + 'class' => 'message-type-' . $a_or_i, |
|
| 3203 | + 'slug_id' => $message_type->name . '-messagetype-' . $messenger->name, |
|
| 3204 | + 'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'), |
|
| 3205 | + 'href' => 'espresso_' . $message_type->name . '_message_type_settings', |
|
| 3206 | + 'title' => $a_or_i === 'active' |
|
| 3207 | + ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso') |
|
| 3208 | + : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'), |
|
| 3209 | + 'content' => $a_or_i === 'active' |
|
| 3210 | + ? $this->_message_type_settings_content($message_type, $messenger, true) |
|
| 3211 | + : $this->_message_type_settings_content($message_type, $messenger), |
|
| 3212 | + 'slug' => $message_type->name, |
|
| 3213 | + 'active' => $a_or_i === 'active', |
|
| 3214 | + 'obj' => $message_type |
|
| 3215 | + ); |
|
| 3216 | + } |
|
| 3217 | + } |
|
| 3218 | + } |
|
| 3219 | 3219 | |
| 3220 | 3220 | |
| 3221 | - /** |
|
| 3222 | - * This just prepares the content for the message type settings |
|
| 3223 | - * |
|
| 3224 | - * @param EE_message_type $message_type The message type object |
|
| 3225 | - * @param EE_messenger $messenger The messenger object |
|
| 3226 | - * @param boolean $active Whether the message type is active or not |
|
| 3227 | - * @return string html output for the content |
|
| 3228 | - * @throws DomainException |
|
| 3229 | - */ |
|
| 3230 | - protected function _message_type_settings_content($message_type, $messenger, $active = false) |
|
| 3231 | - { |
|
| 3232 | - //get message type fields |
|
| 3233 | - $fields = $message_type->get_admin_settings_fields(); |
|
| 3234 | - $settings_template_args['template_form_fields'] = ''; |
|
| 3235 | - |
|
| 3236 | - if ( ! empty($fields) && $active) { |
|
| 3221 | + /** |
|
| 3222 | + * This just prepares the content for the message type settings |
|
| 3223 | + * |
|
| 3224 | + * @param EE_message_type $message_type The message type object |
|
| 3225 | + * @param EE_messenger $messenger The messenger object |
|
| 3226 | + * @param boolean $active Whether the message type is active or not |
|
| 3227 | + * @return string html output for the content |
|
| 3228 | + * @throws DomainException |
|
| 3229 | + */ |
|
| 3230 | + protected function _message_type_settings_content($message_type, $messenger, $active = false) |
|
| 3231 | + { |
|
| 3232 | + //get message type fields |
|
| 3233 | + $fields = $message_type->get_admin_settings_fields(); |
|
| 3234 | + $settings_template_args['template_form_fields'] = ''; |
|
| 3235 | + |
|
| 3236 | + if ( ! empty($fields) && $active) { |
|
| 3237 | 3237 | |
| 3238 | - $existing_settings = $message_type->get_existing_admin_settings($messenger->name); |
|
| 3238 | + $existing_settings = $message_type->get_existing_admin_settings($messenger->name); |
|
| 3239 | 3239 | |
| 3240 | - foreach ($fields as $fldname => $fldprops) { |
|
| 3241 | - $field_id = $messenger->name . '-' . $message_type->name . '-' . $fldname; |
|
| 3242 | - $template_form_field[$field_id] = array( |
|
| 3243 | - 'name' => 'message_type_settings[' . $fldname . ']', |
|
| 3244 | - 'label' => $fldprops['label'], |
|
| 3245 | - 'input' => $fldprops['field_type'], |
|
| 3246 | - 'type' => $fldprops['value_type'], |
|
| 3247 | - 'required' => $fldprops['required'], |
|
| 3248 | - 'validation' => $fldprops['validation'], |
|
| 3249 | - 'value' => isset($existing_settings[$fldname]) |
|
| 3250 | - ? $existing_settings[$fldname] |
|
| 3251 | - : $fldprops['default'], |
|
| 3252 | - 'options' => isset($fldprops['options']) |
|
| 3253 | - ? $fldprops['options'] |
|
| 3254 | - : array(), |
|
| 3255 | - 'default' => isset($existing_settings[$fldname]) |
|
| 3256 | - ? $existing_settings[$fldname] |
|
| 3257 | - : $fldprops['default'], |
|
| 3258 | - 'css_class' => 'no-drag', |
|
| 3259 | - 'format' => $fldprops['format'] |
|
| 3260 | - ); |
|
| 3261 | - } |
|
| 3240 | + foreach ($fields as $fldname => $fldprops) { |
|
| 3241 | + $field_id = $messenger->name . '-' . $message_type->name . '-' . $fldname; |
|
| 3242 | + $template_form_field[$field_id] = array( |
|
| 3243 | + 'name' => 'message_type_settings[' . $fldname . ']', |
|
| 3244 | + 'label' => $fldprops['label'], |
|
| 3245 | + 'input' => $fldprops['field_type'], |
|
| 3246 | + 'type' => $fldprops['value_type'], |
|
| 3247 | + 'required' => $fldprops['required'], |
|
| 3248 | + 'validation' => $fldprops['validation'], |
|
| 3249 | + 'value' => isset($existing_settings[$fldname]) |
|
| 3250 | + ? $existing_settings[$fldname] |
|
| 3251 | + : $fldprops['default'], |
|
| 3252 | + 'options' => isset($fldprops['options']) |
|
| 3253 | + ? $fldprops['options'] |
|
| 3254 | + : array(), |
|
| 3255 | + 'default' => isset($existing_settings[$fldname]) |
|
| 3256 | + ? $existing_settings[$fldname] |
|
| 3257 | + : $fldprops['default'], |
|
| 3258 | + 'css_class' => 'no-drag', |
|
| 3259 | + 'format' => $fldprops['format'] |
|
| 3260 | + ); |
|
| 3261 | + } |
|
| 3262 | 3262 | |
| 3263 | 3263 | |
| 3264 | - $settings_template_args['template_form_fields'] = ! empty($template_form_field) |
|
| 3265 | - ? $this->_generate_admin_form_fields( |
|
| 3266 | - $template_form_field, |
|
| 3267 | - 'string', |
|
| 3268 | - 'ee_mt_activate_form' |
|
| 3269 | - ) |
|
| 3270 | - : ''; |
|
| 3271 | - } |
|
| 3272 | - |
|
| 3273 | - $settings_template_args['description'] = $message_type->description; |
|
| 3274 | - //we also need some hidden fields |
|
| 3275 | - $settings_template_args['hidden_fields'] = array( |
|
| 3276 | - 'message_type_settings[messenger]' => array( |
|
| 3277 | - 'type' => 'hidden', |
|
| 3278 | - 'value' => $messenger->name |
|
| 3279 | - ), |
|
| 3280 | - 'message_type_settings[message_type]' => array( |
|
| 3281 | - 'type' => 'hidden', |
|
| 3282 | - 'value' => $message_type->name |
|
| 3283 | - ), |
|
| 3284 | - 'type' => array( |
|
| 3285 | - 'type' => 'hidden', |
|
| 3286 | - 'value' => 'message_type' |
|
| 3287 | - ) |
|
| 3288 | - ); |
|
| 3289 | - |
|
| 3290 | - $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields( |
|
| 3291 | - $settings_template_args['hidden_fields'], |
|
| 3292 | - 'array' |
|
| 3293 | - ); |
|
| 3294 | - $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields']) |
|
| 3295 | - ? ' hidden' |
|
| 3296 | - : ''; |
|
| 3297 | - |
|
| 3298 | - |
|
| 3299 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php'; |
|
| 3300 | - $content = EEH_Template::display_template($template, $settings_template_args, true); |
|
| 3301 | - |
|
| 3302 | - return $content; |
|
| 3303 | - } |
|
| 3264 | + $settings_template_args['template_form_fields'] = ! empty($template_form_field) |
|
| 3265 | + ? $this->_generate_admin_form_fields( |
|
| 3266 | + $template_form_field, |
|
| 3267 | + 'string', |
|
| 3268 | + 'ee_mt_activate_form' |
|
| 3269 | + ) |
|
| 3270 | + : ''; |
|
| 3271 | + } |
|
| 3272 | + |
|
| 3273 | + $settings_template_args['description'] = $message_type->description; |
|
| 3274 | + //we also need some hidden fields |
|
| 3275 | + $settings_template_args['hidden_fields'] = array( |
|
| 3276 | + 'message_type_settings[messenger]' => array( |
|
| 3277 | + 'type' => 'hidden', |
|
| 3278 | + 'value' => $messenger->name |
|
| 3279 | + ), |
|
| 3280 | + 'message_type_settings[message_type]' => array( |
|
| 3281 | + 'type' => 'hidden', |
|
| 3282 | + 'value' => $message_type->name |
|
| 3283 | + ), |
|
| 3284 | + 'type' => array( |
|
| 3285 | + 'type' => 'hidden', |
|
| 3286 | + 'value' => 'message_type' |
|
| 3287 | + ) |
|
| 3288 | + ); |
|
| 3289 | + |
|
| 3290 | + $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields( |
|
| 3291 | + $settings_template_args['hidden_fields'], |
|
| 3292 | + 'array' |
|
| 3293 | + ); |
|
| 3294 | + $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields']) |
|
| 3295 | + ? ' hidden' |
|
| 3296 | + : ''; |
|
| 3297 | + |
|
| 3298 | + |
|
| 3299 | + $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php'; |
|
| 3300 | + $content = EEH_Template::display_template($template, $settings_template_args, true); |
|
| 3301 | + |
|
| 3302 | + return $content; |
|
| 3303 | + } |
|
| 3304 | 3304 | |
| 3305 | 3305 | |
| 3306 | - /** |
|
| 3307 | - * Generate all the metaboxes for the message types and register them for the messages settings page. |
|
| 3308 | - * |
|
| 3309 | - * @access protected |
|
| 3310 | - * @return void |
|
| 3311 | - * @throws DomainException |
|
| 3312 | - */ |
|
| 3313 | - protected function _messages_settings_metaboxes() |
|
| 3314 | - { |
|
| 3315 | - $this->_set_m_mt_settings(); |
|
| 3316 | - $m_boxes = $mt_boxes = array(); |
|
| 3317 | - $m_template_args = $mt_template_args = array(); |
|
| 3318 | - |
|
| 3319 | - $selected_messenger = isset($this->_req_data['selected_messenger']) |
|
| 3320 | - ? $this->_req_data['selected_messenger'] |
|
| 3321 | - : 'email'; |
|
| 3322 | - |
|
| 3323 | - if (isset($this->_m_mt_settings['messenger_tabs'])) { |
|
| 3324 | - foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) { |
|
| 3325 | - $hide_on_message = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden'; |
|
| 3326 | - $hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : ''; |
|
| 3327 | - //messenger meta boxes |
|
| 3328 | - $active = $selected_messenger === $messenger; |
|
| 3329 | - $active_mt_tabs = isset( |
|
| 3330 | - $this->_m_mt_settings['message_type_tabs'][$messenger]['active'] |
|
| 3331 | - ) |
|
| 3332 | - ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active'] |
|
| 3333 | - : ''; |
|
| 3334 | - $m_boxes[$messenger . '_a_box'] = sprintf( |
|
| 3335 | - esc_html__('%s Settings', 'event_espresso'), |
|
| 3336 | - $tab_array['label'] |
|
| 3337 | - ); |
|
| 3338 | - $m_template_args[$messenger . '_a_box'] = array( |
|
| 3339 | - 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
|
| 3340 | - 'inactive_message_types' => isset( |
|
| 3341 | - $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'] |
|
| 3342 | - ) |
|
| 3343 | - ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 3344 | - : '', |
|
| 3345 | - 'content' => $this->_get_messenger_box_content($tab_array['obj']), |
|
| 3346 | - 'hidden' => $active ? '' : ' hidden', |
|
| 3347 | - 'hide_on_message' => $hide_on_message, |
|
| 3348 | - 'messenger' => $messenger, |
|
| 3349 | - 'active' => $active |
|
| 3350 | - ); |
|
| 3351 | - // message type meta boxes |
|
| 3352 | - // (which is really just the inactive container for each messenger |
|
| 3353 | - // showing inactive message types for that messenger) |
|
| 3354 | - $mt_boxes[$messenger . '_i_box'] = esc_html__('Inactive Message Types', 'event_espresso'); |
|
| 3355 | - $mt_template_args[$messenger . '_i_box'] = array( |
|
| 3356 | - 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
|
| 3357 | - 'inactive_message_types' => isset( |
|
| 3358 | - $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'] |
|
| 3359 | - ) |
|
| 3360 | - ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 3361 | - : '', |
|
| 3362 | - 'hidden' => $active ? '' : ' hidden', |
|
| 3363 | - 'hide_on_message' => $hide_on_message, |
|
| 3364 | - 'hide_off_message' => $hide_off_message, |
|
| 3365 | - 'messenger' => $messenger, |
|
| 3366 | - 'active' => $active |
|
| 3367 | - ); |
|
| 3368 | - } |
|
| 3369 | - } |
|
| 3370 | - |
|
| 3371 | - |
|
| 3372 | - //register messenger metaboxes |
|
| 3373 | - $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php'; |
|
| 3374 | - foreach ($m_boxes as $box => $label) { |
|
| 3375 | - $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]); |
|
| 3376 | - $msgr = str_replace('_a_box', '', $box); |
|
| 3377 | - add_meta_box( |
|
| 3378 | - 'espresso_' . $msgr . '_settings', |
|
| 3379 | - $label, |
|
| 3380 | - function ($post, $metabox) { |
|
| 3381 | - echo EEH_Template::display_template( |
|
| 3382 | - $metabox["args"]["template_path"], |
|
| 3383 | - $metabox["args"]["template_args"], |
|
| 3384 | - true |
|
| 3385 | - ); |
|
| 3386 | - }, |
|
| 3387 | - $this->_current_screen->id, |
|
| 3388 | - 'normal', |
|
| 3389 | - 'high', |
|
| 3390 | - $callback_args |
|
| 3391 | - ); |
|
| 3392 | - } |
|
| 3393 | - |
|
| 3394 | - //register message type metaboxes |
|
| 3395 | - $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php'; |
|
| 3396 | - foreach ($mt_boxes as $box => $label) { |
|
| 3397 | - $callback_args = array( |
|
| 3398 | - 'template_path' => $mt_template_path, |
|
| 3399 | - 'template_args' => $mt_template_args[$box] |
|
| 3400 | - ); |
|
| 3401 | - $mt = str_replace('_i_box', '', $box); |
|
| 3402 | - add_meta_box( |
|
| 3403 | - 'espresso_' . $mt . '_inactive_mts', |
|
| 3404 | - $label, |
|
| 3405 | - function ($post, $metabox) { |
|
| 3406 | - echo EEH_Template::display_template( |
|
| 3407 | - $metabox["args"]["template_path"], |
|
| 3408 | - $metabox["args"]["template_args"], |
|
| 3409 | - true |
|
| 3410 | - ); |
|
| 3411 | - }, |
|
| 3412 | - $this->_current_screen->id, |
|
| 3413 | - 'side', |
|
| 3414 | - 'high', |
|
| 3415 | - $callback_args |
|
| 3416 | - ); |
|
| 3417 | - } |
|
| 3418 | - |
|
| 3419 | - //register metabox for global messages settings but only when on the main site. On single site installs this |
|
| 3420 | - // will always result in the metabox showing, on multisite installs the metabox will only show on the main site. |
|
| 3421 | - if (is_main_site()) { |
|
| 3422 | - add_meta_box( |
|
| 3423 | - 'espresso_global_message_settings', |
|
| 3424 | - esc_html__('Global Message Settings', 'event_espresso'), |
|
| 3425 | - array($this, 'global_messages_settings_metabox_content'), |
|
| 3426 | - $this->_current_screen->id, |
|
| 3427 | - 'normal', |
|
| 3428 | - 'low', |
|
| 3429 | - array() |
|
| 3430 | - ); |
|
| 3431 | - } |
|
| 3432 | - |
|
| 3433 | - } |
|
| 3306 | + /** |
|
| 3307 | + * Generate all the metaboxes for the message types and register them for the messages settings page. |
|
| 3308 | + * |
|
| 3309 | + * @access protected |
|
| 3310 | + * @return void |
|
| 3311 | + * @throws DomainException |
|
| 3312 | + */ |
|
| 3313 | + protected function _messages_settings_metaboxes() |
|
| 3314 | + { |
|
| 3315 | + $this->_set_m_mt_settings(); |
|
| 3316 | + $m_boxes = $mt_boxes = array(); |
|
| 3317 | + $m_template_args = $mt_template_args = array(); |
|
| 3318 | + |
|
| 3319 | + $selected_messenger = isset($this->_req_data['selected_messenger']) |
|
| 3320 | + ? $this->_req_data['selected_messenger'] |
|
| 3321 | + : 'email'; |
|
| 3322 | + |
|
| 3323 | + if (isset($this->_m_mt_settings['messenger_tabs'])) { |
|
| 3324 | + foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) { |
|
| 3325 | + $hide_on_message = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden'; |
|
| 3326 | + $hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : ''; |
|
| 3327 | + //messenger meta boxes |
|
| 3328 | + $active = $selected_messenger === $messenger; |
|
| 3329 | + $active_mt_tabs = isset( |
|
| 3330 | + $this->_m_mt_settings['message_type_tabs'][$messenger]['active'] |
|
| 3331 | + ) |
|
| 3332 | + ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active'] |
|
| 3333 | + : ''; |
|
| 3334 | + $m_boxes[$messenger . '_a_box'] = sprintf( |
|
| 3335 | + esc_html__('%s Settings', 'event_espresso'), |
|
| 3336 | + $tab_array['label'] |
|
| 3337 | + ); |
|
| 3338 | + $m_template_args[$messenger . '_a_box'] = array( |
|
| 3339 | + 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
|
| 3340 | + 'inactive_message_types' => isset( |
|
| 3341 | + $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'] |
|
| 3342 | + ) |
|
| 3343 | + ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 3344 | + : '', |
|
| 3345 | + 'content' => $this->_get_messenger_box_content($tab_array['obj']), |
|
| 3346 | + 'hidden' => $active ? '' : ' hidden', |
|
| 3347 | + 'hide_on_message' => $hide_on_message, |
|
| 3348 | + 'messenger' => $messenger, |
|
| 3349 | + 'active' => $active |
|
| 3350 | + ); |
|
| 3351 | + // message type meta boxes |
|
| 3352 | + // (which is really just the inactive container for each messenger |
|
| 3353 | + // showing inactive message types for that messenger) |
|
| 3354 | + $mt_boxes[$messenger . '_i_box'] = esc_html__('Inactive Message Types', 'event_espresso'); |
|
| 3355 | + $mt_template_args[$messenger . '_i_box'] = array( |
|
| 3356 | + 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
|
| 3357 | + 'inactive_message_types' => isset( |
|
| 3358 | + $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'] |
|
| 3359 | + ) |
|
| 3360 | + ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 3361 | + : '', |
|
| 3362 | + 'hidden' => $active ? '' : ' hidden', |
|
| 3363 | + 'hide_on_message' => $hide_on_message, |
|
| 3364 | + 'hide_off_message' => $hide_off_message, |
|
| 3365 | + 'messenger' => $messenger, |
|
| 3366 | + 'active' => $active |
|
| 3367 | + ); |
|
| 3368 | + } |
|
| 3369 | + } |
|
| 3370 | + |
|
| 3371 | + |
|
| 3372 | + //register messenger metaboxes |
|
| 3373 | + $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php'; |
|
| 3374 | + foreach ($m_boxes as $box => $label) { |
|
| 3375 | + $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]); |
|
| 3376 | + $msgr = str_replace('_a_box', '', $box); |
|
| 3377 | + add_meta_box( |
|
| 3378 | + 'espresso_' . $msgr . '_settings', |
|
| 3379 | + $label, |
|
| 3380 | + function ($post, $metabox) { |
|
| 3381 | + echo EEH_Template::display_template( |
|
| 3382 | + $metabox["args"]["template_path"], |
|
| 3383 | + $metabox["args"]["template_args"], |
|
| 3384 | + true |
|
| 3385 | + ); |
|
| 3386 | + }, |
|
| 3387 | + $this->_current_screen->id, |
|
| 3388 | + 'normal', |
|
| 3389 | + 'high', |
|
| 3390 | + $callback_args |
|
| 3391 | + ); |
|
| 3392 | + } |
|
| 3393 | + |
|
| 3394 | + //register message type metaboxes |
|
| 3395 | + $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php'; |
|
| 3396 | + foreach ($mt_boxes as $box => $label) { |
|
| 3397 | + $callback_args = array( |
|
| 3398 | + 'template_path' => $mt_template_path, |
|
| 3399 | + 'template_args' => $mt_template_args[$box] |
|
| 3400 | + ); |
|
| 3401 | + $mt = str_replace('_i_box', '', $box); |
|
| 3402 | + add_meta_box( |
|
| 3403 | + 'espresso_' . $mt . '_inactive_mts', |
|
| 3404 | + $label, |
|
| 3405 | + function ($post, $metabox) { |
|
| 3406 | + echo EEH_Template::display_template( |
|
| 3407 | + $metabox["args"]["template_path"], |
|
| 3408 | + $metabox["args"]["template_args"], |
|
| 3409 | + true |
|
| 3410 | + ); |
|
| 3411 | + }, |
|
| 3412 | + $this->_current_screen->id, |
|
| 3413 | + 'side', |
|
| 3414 | + 'high', |
|
| 3415 | + $callback_args |
|
| 3416 | + ); |
|
| 3417 | + } |
|
| 3418 | + |
|
| 3419 | + //register metabox for global messages settings but only when on the main site. On single site installs this |
|
| 3420 | + // will always result in the metabox showing, on multisite installs the metabox will only show on the main site. |
|
| 3421 | + if (is_main_site()) { |
|
| 3422 | + add_meta_box( |
|
| 3423 | + 'espresso_global_message_settings', |
|
| 3424 | + esc_html__('Global Message Settings', 'event_espresso'), |
|
| 3425 | + array($this, 'global_messages_settings_metabox_content'), |
|
| 3426 | + $this->_current_screen->id, |
|
| 3427 | + 'normal', |
|
| 3428 | + 'low', |
|
| 3429 | + array() |
|
| 3430 | + ); |
|
| 3431 | + } |
|
| 3432 | + |
|
| 3433 | + } |
|
| 3434 | 3434 | |
| 3435 | 3435 | |
| 3436 | - /** |
|
| 3437 | - * This generates the content for the global messages settings metabox. |
|
| 3438 | - * |
|
| 3439 | - * @return string |
|
| 3440 | - * @throws EE_Error |
|
| 3441 | - * @throws InvalidArgumentException |
|
| 3442 | - * @throws ReflectionException |
|
| 3443 | - * @throws InvalidDataTypeException |
|
| 3444 | - * @throws InvalidInterfaceException |
|
| 3445 | - */ |
|
| 3446 | - public function global_messages_settings_metabox_content() |
|
| 3447 | - { |
|
| 3448 | - $form = $this->_generate_global_settings_form(); |
|
| 3449 | - echo $form->form_open( |
|
| 3450 | - $this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL), |
|
| 3451 | - 'POST' |
|
| 3452 | - ) |
|
| 3453 | - . $form->get_html() |
|
| 3454 | - . $form->form_close(); |
|
| 3455 | - } |
|
| 3436 | + /** |
|
| 3437 | + * This generates the content for the global messages settings metabox. |
|
| 3438 | + * |
|
| 3439 | + * @return string |
|
| 3440 | + * @throws EE_Error |
|
| 3441 | + * @throws InvalidArgumentException |
|
| 3442 | + * @throws ReflectionException |
|
| 3443 | + * @throws InvalidDataTypeException |
|
| 3444 | + * @throws InvalidInterfaceException |
|
| 3445 | + */ |
|
| 3446 | + public function global_messages_settings_metabox_content() |
|
| 3447 | + { |
|
| 3448 | + $form = $this->_generate_global_settings_form(); |
|
| 3449 | + echo $form->form_open( |
|
| 3450 | + $this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL), |
|
| 3451 | + 'POST' |
|
| 3452 | + ) |
|
| 3453 | + . $form->get_html() |
|
| 3454 | + . $form->form_close(); |
|
| 3455 | + } |
|
| 3456 | 3456 | |
| 3457 | 3457 | |
| 3458 | - /** |
|
| 3459 | - * This generates and returns the form object for the global messages settings. |
|
| 3460 | - * |
|
| 3461 | - * @return EE_Form_Section_Proper |
|
| 3462 | - * @throws EE_Error |
|
| 3463 | - * @throws InvalidArgumentException |
|
| 3464 | - * @throws ReflectionException |
|
| 3465 | - * @throws InvalidDataTypeException |
|
| 3466 | - * @throws InvalidInterfaceException |
|
| 3467 | - */ |
|
| 3468 | - protected function _generate_global_settings_form() |
|
| 3469 | - { |
|
| 3470 | - EE_Registry::instance()->load_helper('HTML'); |
|
| 3471 | - /** @var EE_Network_Core_Config $network_config */ |
|
| 3472 | - $network_config = EE_Registry::instance()->NET_CFG->core; |
|
| 3473 | - |
|
| 3474 | - return new EE_Form_Section_Proper( |
|
| 3475 | - array( |
|
| 3476 | - 'name' => 'global_messages_settings', |
|
| 3477 | - 'html_id' => 'global_messages_settings', |
|
| 3478 | - 'html_class' => 'form-table', |
|
| 3479 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 3480 | - 'subsections' => apply_filters( |
|
| 3481 | - 'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections', |
|
| 3482 | - array( |
|
| 3483 | - 'do_messages_on_same_request' => new EE_Select_Input( |
|
| 3484 | - array( |
|
| 3485 | - true => esc_html__("On the same request", "event_espresso"), |
|
| 3486 | - false => esc_html__("On a separate request", "event_espresso") |
|
| 3487 | - ), |
|
| 3488 | - array( |
|
| 3489 | - 'default' => $network_config->do_messages_on_same_request, |
|
| 3490 | - 'html_label_text' => esc_html__( |
|
| 3491 | - 'Generate and send all messages:', |
|
| 3492 | - 'event_espresso' |
|
| 3493 | - ), |
|
| 3494 | - 'html_help_text' => esc_html__( |
|
| 3495 | - 'By default the messages system uses a more efficient means of processing messages on separate requests and utilizes the wp-cron scheduling system. This makes things execute faster for people registering for your events. However, if the wp-cron system is disabled on your site and there is no alternative in place, then you can change this so messages are always executed on the same request.', |
|
| 3496 | - 'event_espresso' |
|
| 3497 | - ), |
|
| 3498 | - ) |
|
| 3499 | - ), |
|
| 3500 | - 'delete_threshold' => new EE_Select_Input( |
|
| 3501 | - array( |
|
| 3502 | - 0 => esc_html__('Forever', 'event_espresso'), |
|
| 3503 | - 3 => esc_html__('3 Months', 'event_espresso'), |
|
| 3504 | - 6 => esc_html__('6 Months', 'event_espresso'), |
|
| 3505 | - 9 => esc_html__('9 Months', 'event_espresso'), |
|
| 3506 | - 12 => esc_html__('12 Months', 'event_espresso'), |
|
| 3507 | - 24 => esc_html__('24 Months', 'event_espresso'), |
|
| 3508 | - 36 => esc_html__('36 Months', 'event_espresso') |
|
| 3509 | - ), |
|
| 3510 | - array( |
|
| 3511 | - 'default' => EE_Registry::instance()->CFG->messages->delete_threshold, |
|
| 3512 | - 'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'), |
|
| 3513 | - 'html_help_text' => esc_html__( |
|
| 3514 | - 'You can control how long a record of processed messages is kept via this option.', |
|
| 3515 | - 'event_espresso' |
|
| 3516 | - ), |
|
| 3517 | - ) |
|
| 3518 | - ), |
|
| 3519 | - 'update_settings' => new EE_Submit_Input( |
|
| 3520 | - array( |
|
| 3521 | - 'default' => esc_html__('Update', 'event_espresso'), |
|
| 3522 | - 'html_label_text' => ' ' |
|
| 3523 | - ) |
|
| 3524 | - ) |
|
| 3525 | - ) |
|
| 3526 | - ) |
|
| 3527 | - ) |
|
| 3528 | - ); |
|
| 3529 | - } |
|
| 3458 | + /** |
|
| 3459 | + * This generates and returns the form object for the global messages settings. |
|
| 3460 | + * |
|
| 3461 | + * @return EE_Form_Section_Proper |
|
| 3462 | + * @throws EE_Error |
|
| 3463 | + * @throws InvalidArgumentException |
|
| 3464 | + * @throws ReflectionException |
|
| 3465 | + * @throws InvalidDataTypeException |
|
| 3466 | + * @throws InvalidInterfaceException |
|
| 3467 | + */ |
|
| 3468 | + protected function _generate_global_settings_form() |
|
| 3469 | + { |
|
| 3470 | + EE_Registry::instance()->load_helper('HTML'); |
|
| 3471 | + /** @var EE_Network_Core_Config $network_config */ |
|
| 3472 | + $network_config = EE_Registry::instance()->NET_CFG->core; |
|
| 3473 | + |
|
| 3474 | + return new EE_Form_Section_Proper( |
|
| 3475 | + array( |
|
| 3476 | + 'name' => 'global_messages_settings', |
|
| 3477 | + 'html_id' => 'global_messages_settings', |
|
| 3478 | + 'html_class' => 'form-table', |
|
| 3479 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 3480 | + 'subsections' => apply_filters( |
|
| 3481 | + 'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections', |
|
| 3482 | + array( |
|
| 3483 | + 'do_messages_on_same_request' => new EE_Select_Input( |
|
| 3484 | + array( |
|
| 3485 | + true => esc_html__("On the same request", "event_espresso"), |
|
| 3486 | + false => esc_html__("On a separate request", "event_espresso") |
|
| 3487 | + ), |
|
| 3488 | + array( |
|
| 3489 | + 'default' => $network_config->do_messages_on_same_request, |
|
| 3490 | + 'html_label_text' => esc_html__( |
|
| 3491 | + 'Generate and send all messages:', |
|
| 3492 | + 'event_espresso' |
|
| 3493 | + ), |
|
| 3494 | + 'html_help_text' => esc_html__( |
|
| 3495 | + 'By default the messages system uses a more efficient means of processing messages on separate requests and utilizes the wp-cron scheduling system. This makes things execute faster for people registering for your events. However, if the wp-cron system is disabled on your site and there is no alternative in place, then you can change this so messages are always executed on the same request.', |
|
| 3496 | + 'event_espresso' |
|
| 3497 | + ), |
|
| 3498 | + ) |
|
| 3499 | + ), |
|
| 3500 | + 'delete_threshold' => new EE_Select_Input( |
|
| 3501 | + array( |
|
| 3502 | + 0 => esc_html__('Forever', 'event_espresso'), |
|
| 3503 | + 3 => esc_html__('3 Months', 'event_espresso'), |
|
| 3504 | + 6 => esc_html__('6 Months', 'event_espresso'), |
|
| 3505 | + 9 => esc_html__('9 Months', 'event_espresso'), |
|
| 3506 | + 12 => esc_html__('12 Months', 'event_espresso'), |
|
| 3507 | + 24 => esc_html__('24 Months', 'event_espresso'), |
|
| 3508 | + 36 => esc_html__('36 Months', 'event_espresso') |
|
| 3509 | + ), |
|
| 3510 | + array( |
|
| 3511 | + 'default' => EE_Registry::instance()->CFG->messages->delete_threshold, |
|
| 3512 | + 'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'), |
|
| 3513 | + 'html_help_text' => esc_html__( |
|
| 3514 | + 'You can control how long a record of processed messages is kept via this option.', |
|
| 3515 | + 'event_espresso' |
|
| 3516 | + ), |
|
| 3517 | + ) |
|
| 3518 | + ), |
|
| 3519 | + 'update_settings' => new EE_Submit_Input( |
|
| 3520 | + array( |
|
| 3521 | + 'default' => esc_html__('Update', 'event_espresso'), |
|
| 3522 | + 'html_label_text' => ' ' |
|
| 3523 | + ) |
|
| 3524 | + ) |
|
| 3525 | + ) |
|
| 3526 | + ) |
|
| 3527 | + ) |
|
| 3528 | + ); |
|
| 3529 | + } |
|
| 3530 | 3530 | |
| 3531 | 3531 | |
| 3532 | - /** |
|
| 3533 | - * This handles updating the global settings set on the admin page. |
|
| 3534 | - * |
|
| 3535 | - * @throws EE_Error |
|
| 3536 | - * @throws InvalidDataTypeException |
|
| 3537 | - * @throws InvalidInterfaceException |
|
| 3538 | - * @throws InvalidArgumentException |
|
| 3539 | - * @throws ReflectionException |
|
| 3540 | - */ |
|
| 3541 | - protected function _update_global_settings() |
|
| 3542 | - { |
|
| 3543 | - /** @var EE_Network_Core_Config $network_config */ |
|
| 3544 | - $network_config = EE_Registry::instance()->NET_CFG->core; |
|
| 3545 | - $messages_config = EE_Registry::instance()->CFG->messages; |
|
| 3546 | - $form = $this->_generate_global_settings_form(); |
|
| 3547 | - if ($form->was_submitted()) { |
|
| 3548 | - $form->receive_form_submission(); |
|
| 3549 | - if ($form->is_valid()) { |
|
| 3550 | - $valid_data = $form->valid_data(); |
|
| 3551 | - foreach ($valid_data as $property => $value) { |
|
| 3552 | - $setter = 'set_' . $property; |
|
| 3553 | - if (method_exists($network_config, $setter)) { |
|
| 3554 | - $network_config->{$setter}($value); |
|
| 3555 | - } else if ( |
|
| 3556 | - property_exists($network_config, $property) |
|
| 3557 | - && $network_config->{$property} !== $value |
|
| 3558 | - ) { |
|
| 3559 | - $network_config->{$property} = $value; |
|
| 3560 | - } else if ( |
|
| 3561 | - property_exists($messages_config, $property) |
|
| 3562 | - && $messages_config->{$property} !== $value |
|
| 3563 | - ) { |
|
| 3564 | - $messages_config->{$property} = $value; |
|
| 3565 | - } |
|
| 3566 | - } |
|
| 3567 | - //only update if the form submission was valid! |
|
| 3568 | - EE_Registry::instance()->NET_CFG->update_config(true, false); |
|
| 3569 | - EE_Registry::instance()->CFG->update_espresso_config(); |
|
| 3570 | - EE_Error::overwrite_success(); |
|
| 3571 | - EE_Error::add_success(__('Global message settings were updated', 'event_espresso')); |
|
| 3572 | - } |
|
| 3573 | - } |
|
| 3574 | - $this->_redirect_after_action(0, '', '', array('action' => 'settings'), true); |
|
| 3575 | - } |
|
| 3532 | + /** |
|
| 3533 | + * This handles updating the global settings set on the admin page. |
|
| 3534 | + * |
|
| 3535 | + * @throws EE_Error |
|
| 3536 | + * @throws InvalidDataTypeException |
|
| 3537 | + * @throws InvalidInterfaceException |
|
| 3538 | + * @throws InvalidArgumentException |
|
| 3539 | + * @throws ReflectionException |
|
| 3540 | + */ |
|
| 3541 | + protected function _update_global_settings() |
|
| 3542 | + { |
|
| 3543 | + /** @var EE_Network_Core_Config $network_config */ |
|
| 3544 | + $network_config = EE_Registry::instance()->NET_CFG->core; |
|
| 3545 | + $messages_config = EE_Registry::instance()->CFG->messages; |
|
| 3546 | + $form = $this->_generate_global_settings_form(); |
|
| 3547 | + if ($form->was_submitted()) { |
|
| 3548 | + $form->receive_form_submission(); |
|
| 3549 | + if ($form->is_valid()) { |
|
| 3550 | + $valid_data = $form->valid_data(); |
|
| 3551 | + foreach ($valid_data as $property => $value) { |
|
| 3552 | + $setter = 'set_' . $property; |
|
| 3553 | + if (method_exists($network_config, $setter)) { |
|
| 3554 | + $network_config->{$setter}($value); |
|
| 3555 | + } else if ( |
|
| 3556 | + property_exists($network_config, $property) |
|
| 3557 | + && $network_config->{$property} !== $value |
|
| 3558 | + ) { |
|
| 3559 | + $network_config->{$property} = $value; |
|
| 3560 | + } else if ( |
|
| 3561 | + property_exists($messages_config, $property) |
|
| 3562 | + && $messages_config->{$property} !== $value |
|
| 3563 | + ) { |
|
| 3564 | + $messages_config->{$property} = $value; |
|
| 3565 | + } |
|
| 3566 | + } |
|
| 3567 | + //only update if the form submission was valid! |
|
| 3568 | + EE_Registry::instance()->NET_CFG->update_config(true, false); |
|
| 3569 | + EE_Registry::instance()->CFG->update_espresso_config(); |
|
| 3570 | + EE_Error::overwrite_success(); |
|
| 3571 | + EE_Error::add_success(__('Global message settings were updated', 'event_espresso')); |
|
| 3572 | + } |
|
| 3573 | + } |
|
| 3574 | + $this->_redirect_after_action(0, '', '', array('action' => 'settings'), true); |
|
| 3575 | + } |
|
| 3576 | 3576 | |
| 3577 | 3577 | |
| 3578 | - /** |
|
| 3579 | - * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate |
|
| 3580 | - * |
|
| 3581 | - * @param array $tab_array This is an array of message type tab details used to generate the tabs |
|
| 3582 | - * @return string html formatted tabs |
|
| 3583 | - * @throws DomainException |
|
| 3584 | - */ |
|
| 3585 | - protected function _get_mt_tabs($tab_array) |
|
| 3586 | - { |
|
| 3587 | - $tab_array = (array)$tab_array; |
|
| 3588 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php'; |
|
| 3589 | - $tabs = ''; |
|
| 3590 | - |
|
| 3591 | - foreach ($tab_array as $tab) { |
|
| 3592 | - $tabs .= EEH_Template::display_template($template, $tab, true); |
|
| 3593 | - } |
|
| 3594 | - |
|
| 3595 | - return $tabs; |
|
| 3596 | - } |
|
| 3578 | + /** |
|
| 3579 | + * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate |
|
| 3580 | + * |
|
| 3581 | + * @param array $tab_array This is an array of message type tab details used to generate the tabs |
|
| 3582 | + * @return string html formatted tabs |
|
| 3583 | + * @throws DomainException |
|
| 3584 | + */ |
|
| 3585 | + protected function _get_mt_tabs($tab_array) |
|
| 3586 | + { |
|
| 3587 | + $tab_array = (array)$tab_array; |
|
| 3588 | + $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php'; |
|
| 3589 | + $tabs = ''; |
|
| 3590 | + |
|
| 3591 | + foreach ($tab_array as $tab) { |
|
| 3592 | + $tabs .= EEH_Template::display_template($template, $tab, true); |
|
| 3593 | + } |
|
| 3594 | + |
|
| 3595 | + return $tabs; |
|
| 3596 | + } |
|
| 3597 | 3597 | |
| 3598 | 3598 | |
| 3599 | - /** |
|
| 3600 | - * This prepares the content of the messenger meta box admin settings |
|
| 3601 | - * |
|
| 3602 | - * @param EE_messenger $messenger The messenger we're setting up content for |
|
| 3603 | - * @return string html formatted content |
|
| 3604 | - * @throws DomainException |
|
| 3605 | - */ |
|
| 3606 | - protected function _get_messenger_box_content(EE_messenger $messenger) |
|
| 3607 | - { |
|
| 3599 | + /** |
|
| 3600 | + * This prepares the content of the messenger meta box admin settings |
|
| 3601 | + * |
|
| 3602 | + * @param EE_messenger $messenger The messenger we're setting up content for |
|
| 3603 | + * @return string html formatted content |
|
| 3604 | + * @throws DomainException |
|
| 3605 | + */ |
|
| 3606 | + protected function _get_messenger_box_content(EE_messenger $messenger) |
|
| 3607 | + { |
|
| 3608 | 3608 | |
| 3609 | - $fields = $messenger->get_admin_settings_fields(); |
|
| 3610 | - $settings_template_args['template_form_fields'] = ''; |
|
| 3609 | + $fields = $messenger->get_admin_settings_fields(); |
|
| 3610 | + $settings_template_args['template_form_fields'] = ''; |
|
| 3611 | 3611 | |
| 3612 | - //is $messenger active? |
|
| 3613 | - $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3612 | + //is $messenger active? |
|
| 3613 | + $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3614 | 3614 | |
| 3615 | 3615 | |
| 3616 | - if ( ! empty($fields)) { |
|
| 3616 | + if ( ! empty($fields)) { |
|
| 3617 | 3617 | |
| 3618 | - $existing_settings = $messenger->get_existing_admin_settings(); |
|
| 3618 | + $existing_settings = $messenger->get_existing_admin_settings(); |
|
| 3619 | 3619 | |
| 3620 | - foreach ($fields as $fldname => $fldprops) { |
|
| 3621 | - $field_id = $messenger->name . '-' . $fldname; |
|
| 3622 | - $template_form_field[$field_id] = array( |
|
| 3623 | - 'name' => 'messenger_settings[' . $field_id . ']', |
|
| 3624 | - 'label' => $fldprops['label'], |
|
| 3625 | - 'input' => $fldprops['field_type'], |
|
| 3626 | - 'type' => $fldprops['value_type'], |
|
| 3627 | - 'required' => $fldprops['required'], |
|
| 3628 | - 'validation' => $fldprops['validation'], |
|
| 3629 | - 'value' => isset($existing_settings[$field_id]) |
|
| 3630 | - ? $existing_settings[$field_id] |
|
| 3631 | - : $fldprops['default'], |
|
| 3632 | - 'css_class' => '', |
|
| 3633 | - 'format' => $fldprops['format'] |
|
| 3634 | - ); |
|
| 3635 | - } |
|
| 3620 | + foreach ($fields as $fldname => $fldprops) { |
|
| 3621 | + $field_id = $messenger->name . '-' . $fldname; |
|
| 3622 | + $template_form_field[$field_id] = array( |
|
| 3623 | + 'name' => 'messenger_settings[' . $field_id . ']', |
|
| 3624 | + 'label' => $fldprops['label'], |
|
| 3625 | + 'input' => $fldprops['field_type'], |
|
| 3626 | + 'type' => $fldprops['value_type'], |
|
| 3627 | + 'required' => $fldprops['required'], |
|
| 3628 | + 'validation' => $fldprops['validation'], |
|
| 3629 | + 'value' => isset($existing_settings[$field_id]) |
|
| 3630 | + ? $existing_settings[$field_id] |
|
| 3631 | + : $fldprops['default'], |
|
| 3632 | + 'css_class' => '', |
|
| 3633 | + 'format' => $fldprops['format'] |
|
| 3634 | + ); |
|
| 3635 | + } |
|
| 3636 | 3636 | |
| 3637 | 3637 | |
| 3638 | - $settings_template_args['template_form_fields'] = ! empty($template_form_field) |
|
| 3639 | - ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form') |
|
| 3640 | - : ''; |
|
| 3641 | - } |
|
| 3642 | - |
|
| 3643 | - //we also need some hidden fields |
|
| 3644 | - $settings_template_args['hidden_fields'] = array( |
|
| 3645 | - 'messenger_settings[messenger]' => array( |
|
| 3646 | - 'type' => 'hidden', |
|
| 3647 | - 'value' => $messenger->name |
|
| 3648 | - ), |
|
| 3649 | - 'type' => array( |
|
| 3650 | - 'type' => 'hidden', |
|
| 3651 | - 'value' => 'messenger' |
|
| 3652 | - ) |
|
| 3653 | - ); |
|
| 3654 | - |
|
| 3655 | - //make sure any active message types that are existing are included in the hidden fields |
|
| 3656 | - if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) { |
|
| 3657 | - foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) { |
|
| 3658 | - $settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array( |
|
| 3659 | - 'type' => 'hidden', |
|
| 3660 | - 'value' => $mt |
|
| 3661 | - ); |
|
| 3662 | - } |
|
| 3663 | - } |
|
| 3664 | - $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields( |
|
| 3665 | - $settings_template_args['hidden_fields'], |
|
| 3666 | - 'array' |
|
| 3667 | - ); |
|
| 3668 | - $active = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3669 | - |
|
| 3670 | - $settings_template_args['messenger'] = $messenger->name; |
|
| 3671 | - $settings_template_args['description'] = $messenger->description; |
|
| 3672 | - $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden'; |
|
| 3673 | - |
|
| 3674 | - |
|
| 3675 | - $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active( |
|
| 3676 | - $messenger->name |
|
| 3677 | - ) |
|
| 3678 | - ? $settings_template_args['show_hide_edit_form'] |
|
| 3679 | - : ' hidden'; |
|
| 3680 | - |
|
| 3681 | - $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields']) |
|
| 3682 | - ? ' hidden' |
|
| 3683 | - : $settings_template_args['show_hide_edit_form']; |
|
| 3684 | - |
|
| 3685 | - |
|
| 3686 | - $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on'; |
|
| 3687 | - $settings_template_args['nonce'] = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce'); |
|
| 3688 | - $settings_template_args['on_off_status'] = $active ? true : false; |
|
| 3689 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php'; |
|
| 3690 | - $content = EEH_Template::display_template( |
|
| 3691 | - $template, |
|
| 3692 | - $settings_template_args, |
|
| 3693 | - true |
|
| 3694 | - ); |
|
| 3695 | - |
|
| 3696 | - return $content; |
|
| 3697 | - } |
|
| 3638 | + $settings_template_args['template_form_fields'] = ! empty($template_form_field) |
|
| 3639 | + ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form') |
|
| 3640 | + : ''; |
|
| 3641 | + } |
|
| 3642 | + |
|
| 3643 | + //we also need some hidden fields |
|
| 3644 | + $settings_template_args['hidden_fields'] = array( |
|
| 3645 | + 'messenger_settings[messenger]' => array( |
|
| 3646 | + 'type' => 'hidden', |
|
| 3647 | + 'value' => $messenger->name |
|
| 3648 | + ), |
|
| 3649 | + 'type' => array( |
|
| 3650 | + 'type' => 'hidden', |
|
| 3651 | + 'value' => 'messenger' |
|
| 3652 | + ) |
|
| 3653 | + ); |
|
| 3654 | + |
|
| 3655 | + //make sure any active message types that are existing are included in the hidden fields |
|
| 3656 | + if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) { |
|
| 3657 | + foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) { |
|
| 3658 | + $settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array( |
|
| 3659 | + 'type' => 'hidden', |
|
| 3660 | + 'value' => $mt |
|
| 3661 | + ); |
|
| 3662 | + } |
|
| 3663 | + } |
|
| 3664 | + $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields( |
|
| 3665 | + $settings_template_args['hidden_fields'], |
|
| 3666 | + 'array' |
|
| 3667 | + ); |
|
| 3668 | + $active = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3669 | + |
|
| 3670 | + $settings_template_args['messenger'] = $messenger->name; |
|
| 3671 | + $settings_template_args['description'] = $messenger->description; |
|
| 3672 | + $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden'; |
|
| 3673 | + |
|
| 3674 | + |
|
| 3675 | + $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active( |
|
| 3676 | + $messenger->name |
|
| 3677 | + ) |
|
| 3678 | + ? $settings_template_args['show_hide_edit_form'] |
|
| 3679 | + : ' hidden'; |
|
| 3680 | + |
|
| 3681 | + $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields']) |
|
| 3682 | + ? ' hidden' |
|
| 3683 | + : $settings_template_args['show_hide_edit_form']; |
|
| 3684 | + |
|
| 3685 | + |
|
| 3686 | + $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on'; |
|
| 3687 | + $settings_template_args['nonce'] = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce'); |
|
| 3688 | + $settings_template_args['on_off_status'] = $active ? true : false; |
|
| 3689 | + $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php'; |
|
| 3690 | + $content = EEH_Template::display_template( |
|
| 3691 | + $template, |
|
| 3692 | + $settings_template_args, |
|
| 3693 | + true |
|
| 3694 | + ); |
|
| 3695 | + |
|
| 3696 | + return $content; |
|
| 3697 | + } |
|
| 3698 | 3698 | |
| 3699 | 3699 | |
| 3700 | - /** |
|
| 3701 | - * used by ajax on the messages settings page to activate|deactivate the messenger |
|
| 3702 | - * |
|
| 3703 | - * @throws DomainException |
|
| 3704 | - * @throws EE_Error |
|
| 3705 | - * @throws InvalidDataTypeException |
|
| 3706 | - * @throws InvalidInterfaceException |
|
| 3707 | - * @throws InvalidArgumentException |
|
| 3708 | - * @throws ReflectionException |
|
| 3709 | - */ |
|
| 3710 | - public function activate_messenger_toggle() |
|
| 3711 | - { |
|
| 3712 | - $success = true; |
|
| 3713 | - $this->_prep_default_response_for_messenger_or_message_type_toggle(); |
|
| 3714 | - //let's check that we have required data |
|
| 3715 | - if ( ! isset($this->_req_data['messenger'])) { |
|
| 3716 | - EE_Error::add_error( |
|
| 3717 | - esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'), |
|
| 3718 | - __FILE__, |
|
| 3719 | - __FUNCTION__, |
|
| 3720 | - __LINE__ |
|
| 3721 | - ); |
|
| 3722 | - $success = false; |
|
| 3723 | - } |
|
| 3724 | - |
|
| 3725 | - //do a nonce check here since we're not arriving via a normal route |
|
| 3726 | - $nonce = isset($this->_req_data['activate_nonce']) |
|
| 3727 | - ? sanitize_text_field($this->_req_data['activate_nonce']) |
|
| 3728 | - : ''; |
|
| 3729 | - $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce'; |
|
| 3730 | - |
|
| 3731 | - $this->_verify_nonce($nonce, $nonce_ref); |
|
| 3732 | - |
|
| 3733 | - |
|
| 3734 | - if ( ! isset($this->_req_data['status'])) { |
|
| 3735 | - EE_Error::add_error( |
|
| 3736 | - esc_html__( |
|
| 3737 | - 'Messenger status needed to know whether activation or deactivation is happening. No status is given', |
|
| 3738 | - 'event_espresso' |
|
| 3739 | - ), |
|
| 3740 | - __FILE__, |
|
| 3741 | - __FUNCTION__, |
|
| 3742 | - __LINE__ |
|
| 3743 | - ); |
|
| 3744 | - $success = false; |
|
| 3745 | - } |
|
| 3746 | - |
|
| 3747 | - //do check to verify we have a valid status. |
|
| 3748 | - $status = $this->_req_data['status']; |
|
| 3749 | - |
|
| 3750 | - if ($status !== 'off' && $status !== 'on') { |
|
| 3751 | - EE_Error::add_error( |
|
| 3752 | - sprintf( |
|
| 3753 | - esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'), |
|
| 3754 | - $this->_req_data['status'] |
|
| 3755 | - ), |
|
| 3756 | - __FILE__, |
|
| 3757 | - __FUNCTION__, |
|
| 3758 | - __LINE__ |
|
| 3759 | - ); |
|
| 3760 | - $success = false; |
|
| 3761 | - } |
|
| 3762 | - |
|
| 3763 | - if ($success) { |
|
| 3764 | - //made it here? Stop dawdling then!! |
|
| 3765 | - $success = $status === 'off' |
|
| 3766 | - ? $this->_deactivate_messenger($this->_req_data['messenger']) |
|
| 3767 | - : $this->_activate_messenger($this->_req_data['messenger']); |
|
| 3768 | - } |
|
| 3769 | - |
|
| 3770 | - $this->_template_args['success'] = $success; |
|
| 3771 | - |
|
| 3772 | - //no special instructions so let's just do the json return (which should automatically do all the special stuff). |
|
| 3773 | - $this->_return_json(); |
|
| 3774 | - |
|
| 3775 | - } |
|
| 3700 | + /** |
|
| 3701 | + * used by ajax on the messages settings page to activate|deactivate the messenger |
|
| 3702 | + * |
|
| 3703 | + * @throws DomainException |
|
| 3704 | + * @throws EE_Error |
|
| 3705 | + * @throws InvalidDataTypeException |
|
| 3706 | + * @throws InvalidInterfaceException |
|
| 3707 | + * @throws InvalidArgumentException |
|
| 3708 | + * @throws ReflectionException |
|
| 3709 | + */ |
|
| 3710 | + public function activate_messenger_toggle() |
|
| 3711 | + { |
|
| 3712 | + $success = true; |
|
| 3713 | + $this->_prep_default_response_for_messenger_or_message_type_toggle(); |
|
| 3714 | + //let's check that we have required data |
|
| 3715 | + if ( ! isset($this->_req_data['messenger'])) { |
|
| 3716 | + EE_Error::add_error( |
|
| 3717 | + esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'), |
|
| 3718 | + __FILE__, |
|
| 3719 | + __FUNCTION__, |
|
| 3720 | + __LINE__ |
|
| 3721 | + ); |
|
| 3722 | + $success = false; |
|
| 3723 | + } |
|
| 3724 | + |
|
| 3725 | + //do a nonce check here since we're not arriving via a normal route |
|
| 3726 | + $nonce = isset($this->_req_data['activate_nonce']) |
|
| 3727 | + ? sanitize_text_field($this->_req_data['activate_nonce']) |
|
| 3728 | + : ''; |
|
| 3729 | + $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce'; |
|
| 3730 | + |
|
| 3731 | + $this->_verify_nonce($nonce, $nonce_ref); |
|
| 3732 | + |
|
| 3733 | + |
|
| 3734 | + if ( ! isset($this->_req_data['status'])) { |
|
| 3735 | + EE_Error::add_error( |
|
| 3736 | + esc_html__( |
|
| 3737 | + 'Messenger status needed to know whether activation or deactivation is happening. No status is given', |
|
| 3738 | + 'event_espresso' |
|
| 3739 | + ), |
|
| 3740 | + __FILE__, |
|
| 3741 | + __FUNCTION__, |
|
| 3742 | + __LINE__ |
|
| 3743 | + ); |
|
| 3744 | + $success = false; |
|
| 3745 | + } |
|
| 3746 | + |
|
| 3747 | + //do check to verify we have a valid status. |
|
| 3748 | + $status = $this->_req_data['status']; |
|
| 3749 | + |
|
| 3750 | + if ($status !== 'off' && $status !== 'on') { |
|
| 3751 | + EE_Error::add_error( |
|
| 3752 | + sprintf( |
|
| 3753 | + esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'), |
|
| 3754 | + $this->_req_data['status'] |
|
| 3755 | + ), |
|
| 3756 | + __FILE__, |
|
| 3757 | + __FUNCTION__, |
|
| 3758 | + __LINE__ |
|
| 3759 | + ); |
|
| 3760 | + $success = false; |
|
| 3761 | + } |
|
| 3762 | + |
|
| 3763 | + if ($success) { |
|
| 3764 | + //made it here? Stop dawdling then!! |
|
| 3765 | + $success = $status === 'off' |
|
| 3766 | + ? $this->_deactivate_messenger($this->_req_data['messenger']) |
|
| 3767 | + : $this->_activate_messenger($this->_req_data['messenger']); |
|
| 3768 | + } |
|
| 3769 | + |
|
| 3770 | + $this->_template_args['success'] = $success; |
|
| 3771 | + |
|
| 3772 | + //no special instructions so let's just do the json return (which should automatically do all the special stuff). |
|
| 3773 | + $this->_return_json(); |
|
| 3774 | + |
|
| 3775 | + } |
|
| 3776 | 3776 | |
| 3777 | 3777 | |
| 3778 | - /** |
|
| 3779 | - * used by ajax from the messages settings page to activate|deactivate a message type |
|
| 3780 | - * |
|
| 3781 | - * @throws DomainException |
|
| 3782 | - * @throws EE_Error |
|
| 3783 | - * @throws ReflectionException |
|
| 3784 | - * @throws InvalidDataTypeException |
|
| 3785 | - * @throws InvalidInterfaceException |
|
| 3786 | - * @throws InvalidArgumentException |
|
| 3787 | - */ |
|
| 3788 | - public function activate_mt_toggle() |
|
| 3789 | - { |
|
| 3790 | - $success = true; |
|
| 3791 | - $this->_prep_default_response_for_messenger_or_message_type_toggle(); |
|
| 3792 | - |
|
| 3793 | - //let's make sure we have the necessary data |
|
| 3794 | - if ( ! isset($this->_req_data['message_type'])) { |
|
| 3795 | - EE_Error::add_error( |
|
| 3796 | - esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'), |
|
| 3797 | - __FILE__, |
|
| 3798 | - __FUNCTION__, |
|
| 3799 | - __LINE__ |
|
| 3800 | - ); |
|
| 3801 | - $success = false; |
|
| 3802 | - } |
|
| 3803 | - |
|
| 3804 | - if ( ! isset($this->_req_data['messenger'])) { |
|
| 3805 | - EE_Error::add_error( |
|
| 3806 | - esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'), |
|
| 3807 | - __FILE__, |
|
| 3808 | - __FUNCTION__, |
|
| 3809 | - __LINE__ |
|
| 3810 | - ); |
|
| 3811 | - $success = false; |
|
| 3812 | - } |
|
| 3813 | - |
|
| 3814 | - if ( ! isset($this->_req_data['status'])) { |
|
| 3815 | - EE_Error::add_error( |
|
| 3816 | - esc_html__('Messenger status needed to know whether activation or deactivation is happening. No status is given', |
|
| 3817 | - 'event_espresso'), |
|
| 3818 | - __FILE__, |
|
| 3819 | - __FUNCTION__, |
|
| 3820 | - __LINE__ |
|
| 3821 | - ); |
|
| 3822 | - $success = false; |
|
| 3823 | - } |
|
| 3824 | - |
|
| 3825 | - |
|
| 3826 | - //do check to verify we have a valid status. |
|
| 3827 | - $status = $this->_req_data['status']; |
|
| 3828 | - |
|
| 3829 | - if ($status !== 'activate' && $status !== 'deactivate') { |
|
| 3830 | - EE_Error::add_error( |
|
| 3831 | - sprintf( |
|
| 3832 | - esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'), |
|
| 3833 | - $this->_req_data['status'] |
|
| 3834 | - ), |
|
| 3835 | - __FILE__, |
|
| 3836 | - __FUNCTION__, |
|
| 3837 | - __LINE__ |
|
| 3838 | - ); |
|
| 3839 | - $success = false; |
|
| 3840 | - } |
|
| 3841 | - |
|
| 3842 | - |
|
| 3843 | - //do a nonce check here since we're not arriving via a normal route |
|
| 3844 | - $nonce = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : ''; |
|
| 3845 | - $nonce_ref = $this->_req_data['message_type'] . '_nonce'; |
|
| 3846 | - |
|
| 3847 | - $this->_verify_nonce($nonce, $nonce_ref); |
|
| 3848 | - |
|
| 3849 | - if ($success) { |
|
| 3850 | - //made it here? um, what are you waiting for then? |
|
| 3851 | - $success = $status === 'deactivate' |
|
| 3852 | - ? $this->_deactivate_message_type_for_messenger( |
|
| 3853 | - $this->_req_data['messenger'], |
|
| 3854 | - $this->_req_data['message_type'] |
|
| 3855 | - ) |
|
| 3856 | - : $this->_activate_message_type_for_messenger( |
|
| 3857 | - $this->_req_data['messenger'], |
|
| 3858 | - $this->_req_data['message_type'] |
|
| 3859 | - ); |
|
| 3860 | - } |
|
| 3861 | - |
|
| 3862 | - $this->_template_args['success'] = $success; |
|
| 3863 | - $this->_return_json(); |
|
| 3864 | - } |
|
| 3778 | + /** |
|
| 3779 | + * used by ajax from the messages settings page to activate|deactivate a message type |
|
| 3780 | + * |
|
| 3781 | + * @throws DomainException |
|
| 3782 | + * @throws EE_Error |
|
| 3783 | + * @throws ReflectionException |
|
| 3784 | + * @throws InvalidDataTypeException |
|
| 3785 | + * @throws InvalidInterfaceException |
|
| 3786 | + * @throws InvalidArgumentException |
|
| 3787 | + */ |
|
| 3788 | + public function activate_mt_toggle() |
|
| 3789 | + { |
|
| 3790 | + $success = true; |
|
| 3791 | + $this->_prep_default_response_for_messenger_or_message_type_toggle(); |
|
| 3792 | + |
|
| 3793 | + //let's make sure we have the necessary data |
|
| 3794 | + if ( ! isset($this->_req_data['message_type'])) { |
|
| 3795 | + EE_Error::add_error( |
|
| 3796 | + esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'), |
|
| 3797 | + __FILE__, |
|
| 3798 | + __FUNCTION__, |
|
| 3799 | + __LINE__ |
|
| 3800 | + ); |
|
| 3801 | + $success = false; |
|
| 3802 | + } |
|
| 3803 | + |
|
| 3804 | + if ( ! isset($this->_req_data['messenger'])) { |
|
| 3805 | + EE_Error::add_error( |
|
| 3806 | + esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'), |
|
| 3807 | + __FILE__, |
|
| 3808 | + __FUNCTION__, |
|
| 3809 | + __LINE__ |
|
| 3810 | + ); |
|
| 3811 | + $success = false; |
|
| 3812 | + } |
|
| 3813 | + |
|
| 3814 | + if ( ! isset($this->_req_data['status'])) { |
|
| 3815 | + EE_Error::add_error( |
|
| 3816 | + esc_html__('Messenger status needed to know whether activation or deactivation is happening. No status is given', |
|
| 3817 | + 'event_espresso'), |
|
| 3818 | + __FILE__, |
|
| 3819 | + __FUNCTION__, |
|
| 3820 | + __LINE__ |
|
| 3821 | + ); |
|
| 3822 | + $success = false; |
|
| 3823 | + } |
|
| 3824 | + |
|
| 3825 | + |
|
| 3826 | + //do check to verify we have a valid status. |
|
| 3827 | + $status = $this->_req_data['status']; |
|
| 3828 | + |
|
| 3829 | + if ($status !== 'activate' && $status !== 'deactivate') { |
|
| 3830 | + EE_Error::add_error( |
|
| 3831 | + sprintf( |
|
| 3832 | + esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'), |
|
| 3833 | + $this->_req_data['status'] |
|
| 3834 | + ), |
|
| 3835 | + __FILE__, |
|
| 3836 | + __FUNCTION__, |
|
| 3837 | + __LINE__ |
|
| 3838 | + ); |
|
| 3839 | + $success = false; |
|
| 3840 | + } |
|
| 3841 | + |
|
| 3842 | + |
|
| 3843 | + //do a nonce check here since we're not arriving via a normal route |
|
| 3844 | + $nonce = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : ''; |
|
| 3845 | + $nonce_ref = $this->_req_data['message_type'] . '_nonce'; |
|
| 3846 | + |
|
| 3847 | + $this->_verify_nonce($nonce, $nonce_ref); |
|
| 3848 | + |
|
| 3849 | + if ($success) { |
|
| 3850 | + //made it here? um, what are you waiting for then? |
|
| 3851 | + $success = $status === 'deactivate' |
|
| 3852 | + ? $this->_deactivate_message_type_for_messenger( |
|
| 3853 | + $this->_req_data['messenger'], |
|
| 3854 | + $this->_req_data['message_type'] |
|
| 3855 | + ) |
|
| 3856 | + : $this->_activate_message_type_for_messenger( |
|
| 3857 | + $this->_req_data['messenger'], |
|
| 3858 | + $this->_req_data['message_type'] |
|
| 3859 | + ); |
|
| 3860 | + } |
|
| 3861 | + |
|
| 3862 | + $this->_template_args['success'] = $success; |
|
| 3863 | + $this->_return_json(); |
|
| 3864 | + } |
|
| 3865 | 3865 | |
| 3866 | 3866 | |
| 3867 | - /** |
|
| 3868 | - * Takes care of processing activating a messenger and preparing the appropriate response. |
|
| 3869 | - * |
|
| 3870 | - * @param string $messenger_name The name of the messenger being activated |
|
| 3871 | - * @return bool |
|
| 3872 | - * @throws DomainException |
|
| 3873 | - * @throws EE_Error |
|
| 3874 | - * @throws InvalidArgumentException |
|
| 3875 | - * @throws ReflectionException |
|
| 3876 | - * @throws InvalidDataTypeException |
|
| 3877 | - * @throws InvalidInterfaceException |
|
| 3878 | - */ |
|
| 3879 | - protected function _activate_messenger($messenger_name) |
|
| 3880 | - { |
|
| 3881 | - /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3882 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3883 | - $message_types_to_activate = $active_messenger instanceof EE_Messenger |
|
| 3884 | - ? $active_messenger->get_default_message_types() |
|
| 3885 | - : array(); |
|
| 3886 | - |
|
| 3887 | - //ensure is active |
|
| 3888 | - $this->_message_resource_manager->activate_messenger($messenger_name, $message_types_to_activate); |
|
| 3889 | - |
|
| 3890 | - //set response_data for reload |
|
| 3891 | - foreach ($message_types_to_activate as $message_type_name) { |
|
| 3892 | - /** @var EE_message_type $message_type */ |
|
| 3893 | - $message_type = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3894 | - if ($this->_message_resource_manager->is_message_type_active_for_messenger( |
|
| 3895 | - $messenger_name, |
|
| 3896 | - $message_type_name |
|
| 3897 | - ) |
|
| 3898 | - && $message_type instanceof EE_message_type |
|
| 3899 | - ) { |
|
| 3900 | - $this->_template_args['data']['active_mts'][] = $message_type_name; |
|
| 3901 | - if ($message_type->get_admin_settings_fields()) { |
|
| 3902 | - $this->_template_args['data']['mt_reload'][] = $message_type_name; |
|
| 3903 | - } |
|
| 3904 | - } |
|
| 3905 | - } |
|
| 3906 | - |
|
| 3907 | - //add success message for activating messenger |
|
| 3908 | - return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger); |
|
| 3909 | - |
|
| 3910 | - } |
|
| 3867 | + /** |
|
| 3868 | + * Takes care of processing activating a messenger and preparing the appropriate response. |
|
| 3869 | + * |
|
| 3870 | + * @param string $messenger_name The name of the messenger being activated |
|
| 3871 | + * @return bool |
|
| 3872 | + * @throws DomainException |
|
| 3873 | + * @throws EE_Error |
|
| 3874 | + * @throws InvalidArgumentException |
|
| 3875 | + * @throws ReflectionException |
|
| 3876 | + * @throws InvalidDataTypeException |
|
| 3877 | + * @throws InvalidInterfaceException |
|
| 3878 | + */ |
|
| 3879 | + protected function _activate_messenger($messenger_name) |
|
| 3880 | + { |
|
| 3881 | + /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3882 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3883 | + $message_types_to_activate = $active_messenger instanceof EE_Messenger |
|
| 3884 | + ? $active_messenger->get_default_message_types() |
|
| 3885 | + : array(); |
|
| 3886 | + |
|
| 3887 | + //ensure is active |
|
| 3888 | + $this->_message_resource_manager->activate_messenger($messenger_name, $message_types_to_activate); |
|
| 3889 | + |
|
| 3890 | + //set response_data for reload |
|
| 3891 | + foreach ($message_types_to_activate as $message_type_name) { |
|
| 3892 | + /** @var EE_message_type $message_type */ |
|
| 3893 | + $message_type = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3894 | + if ($this->_message_resource_manager->is_message_type_active_for_messenger( |
|
| 3895 | + $messenger_name, |
|
| 3896 | + $message_type_name |
|
| 3897 | + ) |
|
| 3898 | + && $message_type instanceof EE_message_type |
|
| 3899 | + ) { |
|
| 3900 | + $this->_template_args['data']['active_mts'][] = $message_type_name; |
|
| 3901 | + if ($message_type->get_admin_settings_fields()) { |
|
| 3902 | + $this->_template_args['data']['mt_reload'][] = $message_type_name; |
|
| 3903 | + } |
|
| 3904 | + } |
|
| 3905 | + } |
|
| 3906 | + |
|
| 3907 | + //add success message for activating messenger |
|
| 3908 | + return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger); |
|
| 3909 | + |
|
| 3910 | + } |
|
| 3911 | 3911 | |
| 3912 | 3912 | |
| 3913 | - /** |
|
| 3914 | - * Takes care of processing deactivating a messenger and preparing the appropriate response. |
|
| 3915 | - * |
|
| 3916 | - * @param string $messenger_name The name of the messenger being activated |
|
| 3917 | - * @return bool |
|
| 3918 | - * @throws DomainException |
|
| 3919 | - * @throws EE_Error |
|
| 3920 | - * @throws InvalidArgumentException |
|
| 3921 | - * @throws ReflectionException |
|
| 3922 | - * @throws InvalidDataTypeException |
|
| 3923 | - * @throws InvalidInterfaceException |
|
| 3924 | - */ |
|
| 3925 | - protected function _deactivate_messenger($messenger_name) |
|
| 3926 | - { |
|
| 3927 | - /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3928 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3929 | - $this->_message_resource_manager->deactivate_messenger($messenger_name); |
|
| 3930 | - |
|
| 3931 | - return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger); |
|
| 3932 | - } |
|
| 3913 | + /** |
|
| 3914 | + * Takes care of processing deactivating a messenger and preparing the appropriate response. |
|
| 3915 | + * |
|
| 3916 | + * @param string $messenger_name The name of the messenger being activated |
|
| 3917 | + * @return bool |
|
| 3918 | + * @throws DomainException |
|
| 3919 | + * @throws EE_Error |
|
| 3920 | + * @throws InvalidArgumentException |
|
| 3921 | + * @throws ReflectionException |
|
| 3922 | + * @throws InvalidDataTypeException |
|
| 3923 | + * @throws InvalidInterfaceException |
|
| 3924 | + */ |
|
| 3925 | + protected function _deactivate_messenger($messenger_name) |
|
| 3926 | + { |
|
| 3927 | + /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3928 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3929 | + $this->_message_resource_manager->deactivate_messenger($messenger_name); |
|
| 3930 | + |
|
| 3931 | + return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger); |
|
| 3932 | + } |
|
| 3933 | 3933 | |
| 3934 | 3934 | |
| 3935 | - /** |
|
| 3936 | - * Takes care of processing activating a message type for a messenger and preparing the appropriate response. |
|
| 3937 | - * |
|
| 3938 | - * @param string $messenger_name The name of the messenger the message type is being activated for. |
|
| 3939 | - * @param string $message_type_name The name of the message type being activated for the messenger |
|
| 3940 | - * @return bool |
|
| 3941 | - * @throws DomainException |
|
| 3942 | - * @throws EE_Error |
|
| 3943 | - * @throws InvalidArgumentException |
|
| 3944 | - * @throws ReflectionException |
|
| 3945 | - * @throws InvalidDataTypeException |
|
| 3946 | - * @throws InvalidInterfaceException |
|
| 3947 | - */ |
|
| 3948 | - protected function _activate_message_type_for_messenger($messenger_name, $message_type_name) |
|
| 3949 | - { |
|
| 3950 | - /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3951 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3952 | - /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */ |
|
| 3953 | - $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3954 | - |
|
| 3955 | - //ensure is active |
|
| 3956 | - $this->_message_resource_manager->activate_messenger($messenger_name, $message_type_name); |
|
| 3957 | - |
|
| 3958 | - //set response for load |
|
| 3959 | - if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name, |
|
| 3960 | - $message_type_name) |
|
| 3961 | - ) { |
|
| 3962 | - $this->_template_args['data']['active_mts'][] = $message_type_name; |
|
| 3963 | - if ($message_type_to_activate->get_admin_settings_fields()) { |
|
| 3964 | - $this->_template_args['data']['mt_reload'][] = $message_type_name; |
|
| 3965 | - } |
|
| 3966 | - } |
|
| 3967 | - |
|
| 3968 | - return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger, |
|
| 3969 | - $message_type_to_activate); |
|
| 3970 | - } |
|
| 3935 | + /** |
|
| 3936 | + * Takes care of processing activating a message type for a messenger and preparing the appropriate response. |
|
| 3937 | + * |
|
| 3938 | + * @param string $messenger_name The name of the messenger the message type is being activated for. |
|
| 3939 | + * @param string $message_type_name The name of the message type being activated for the messenger |
|
| 3940 | + * @return bool |
|
| 3941 | + * @throws DomainException |
|
| 3942 | + * @throws EE_Error |
|
| 3943 | + * @throws InvalidArgumentException |
|
| 3944 | + * @throws ReflectionException |
|
| 3945 | + * @throws InvalidDataTypeException |
|
| 3946 | + * @throws InvalidInterfaceException |
|
| 3947 | + */ |
|
| 3948 | + protected function _activate_message_type_for_messenger($messenger_name, $message_type_name) |
|
| 3949 | + { |
|
| 3950 | + /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3951 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3952 | + /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */ |
|
| 3953 | + $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3954 | + |
|
| 3955 | + //ensure is active |
|
| 3956 | + $this->_message_resource_manager->activate_messenger($messenger_name, $message_type_name); |
|
| 3957 | + |
|
| 3958 | + //set response for load |
|
| 3959 | + if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name, |
|
| 3960 | + $message_type_name) |
|
| 3961 | + ) { |
|
| 3962 | + $this->_template_args['data']['active_mts'][] = $message_type_name; |
|
| 3963 | + if ($message_type_to_activate->get_admin_settings_fields()) { |
|
| 3964 | + $this->_template_args['data']['mt_reload'][] = $message_type_name; |
|
| 3965 | + } |
|
| 3966 | + } |
|
| 3967 | + |
|
| 3968 | + return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger, |
|
| 3969 | + $message_type_to_activate); |
|
| 3970 | + } |
|
| 3971 | 3971 | |
| 3972 | 3972 | |
| 3973 | - /** |
|
| 3974 | - * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response. |
|
| 3975 | - * |
|
| 3976 | - * @param string $messenger_name The name of the messenger the message type is being deactivated for. |
|
| 3977 | - * @param string $message_type_name The name of the message type being deactivated for the messenger |
|
| 3978 | - * @return bool |
|
| 3979 | - * @throws DomainException |
|
| 3980 | - * @throws EE_Error |
|
| 3981 | - * @throws InvalidArgumentException |
|
| 3982 | - * @throws ReflectionException |
|
| 3983 | - * @throws InvalidDataTypeException |
|
| 3984 | - * @throws InvalidInterfaceException |
|
| 3985 | - */ |
|
| 3986 | - protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name) |
|
| 3987 | - { |
|
| 3988 | - /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3989 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3990 | - /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */ |
|
| 3991 | - $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3992 | - $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name); |
|
| 3993 | - |
|
| 3994 | - return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger, |
|
| 3995 | - $message_type_to_deactivate); |
|
| 3996 | - } |
|
| 3973 | + /** |
|
| 3974 | + * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response. |
|
| 3975 | + * |
|
| 3976 | + * @param string $messenger_name The name of the messenger the message type is being deactivated for. |
|
| 3977 | + * @param string $message_type_name The name of the message type being deactivated for the messenger |
|
| 3978 | + * @return bool |
|
| 3979 | + * @throws DomainException |
|
| 3980 | + * @throws EE_Error |
|
| 3981 | + * @throws InvalidArgumentException |
|
| 3982 | + * @throws ReflectionException |
|
| 3983 | + * @throws InvalidDataTypeException |
|
| 3984 | + * @throws InvalidInterfaceException |
|
| 3985 | + */ |
|
| 3986 | + protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name) |
|
| 3987 | + { |
|
| 3988 | + /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3989 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3990 | + /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */ |
|
| 3991 | + $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3992 | + $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name); |
|
| 3993 | + |
|
| 3994 | + return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger, |
|
| 3995 | + $message_type_to_deactivate); |
|
| 3996 | + } |
|
| 3997 | 3997 | |
| 3998 | 3998 | |
| 3999 | - /** |
|
| 4000 | - * This just initializes the defaults for activating messenger and message type responses. |
|
| 4001 | - */ |
|
| 4002 | - protected function _prep_default_response_for_messenger_or_message_type_toggle() |
|
| 4003 | - { |
|
| 4004 | - $this->_template_args['data']['active_mts'] = array(); |
|
| 4005 | - $this->_template_args['data']['mt_reload'] = array(); |
|
| 4006 | - } |
|
| 3999 | + /** |
|
| 4000 | + * This just initializes the defaults for activating messenger and message type responses. |
|
| 4001 | + */ |
|
| 4002 | + protected function _prep_default_response_for_messenger_or_message_type_toggle() |
|
| 4003 | + { |
|
| 4004 | + $this->_template_args['data']['active_mts'] = array(); |
|
| 4005 | + $this->_template_args['data']['mt_reload'] = array(); |
|
| 4006 | + } |
|
| 4007 | 4007 | |
| 4008 | 4008 | |
| 4009 | - /** |
|
| 4010 | - * Setup appropriate response for activating a messenger and/or message types |
|
| 4011 | - * |
|
| 4012 | - * @param EE_messenger $messenger |
|
| 4013 | - * @param EE_message_type|null $message_type |
|
| 4014 | - * @return bool |
|
| 4015 | - * @throws DomainException |
|
| 4016 | - * @throws EE_Error |
|
| 4017 | - * @throws InvalidArgumentException |
|
| 4018 | - * @throws ReflectionException |
|
| 4019 | - * @throws InvalidDataTypeException |
|
| 4020 | - * @throws InvalidInterfaceException |
|
| 4021 | - */ |
|
| 4022 | - protected function _setup_response_message_for_activating_messenger_with_message_types( |
|
| 4023 | - $messenger, |
|
| 4024 | - EE_Message_Type $message_type = null |
|
| 4025 | - ) { |
|
| 4026 | - //if $messenger isn't a valid messenger object then get out. |
|
| 4027 | - if ( ! $messenger instanceof EE_Messenger) { |
|
| 4028 | - EE_Error::add_error( |
|
| 4029 | - esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'), |
|
| 4030 | - __FILE__, |
|
| 4031 | - __FUNCTION__, |
|
| 4032 | - __LINE__ |
|
| 4033 | - ); |
|
| 4009 | + /** |
|
| 4010 | + * Setup appropriate response for activating a messenger and/or message types |
|
| 4011 | + * |
|
| 4012 | + * @param EE_messenger $messenger |
|
| 4013 | + * @param EE_message_type|null $message_type |
|
| 4014 | + * @return bool |
|
| 4015 | + * @throws DomainException |
|
| 4016 | + * @throws EE_Error |
|
| 4017 | + * @throws InvalidArgumentException |
|
| 4018 | + * @throws ReflectionException |
|
| 4019 | + * @throws InvalidDataTypeException |
|
| 4020 | + * @throws InvalidInterfaceException |
|
| 4021 | + */ |
|
| 4022 | + protected function _setup_response_message_for_activating_messenger_with_message_types( |
|
| 4023 | + $messenger, |
|
| 4024 | + EE_Message_Type $message_type = null |
|
| 4025 | + ) { |
|
| 4026 | + //if $messenger isn't a valid messenger object then get out. |
|
| 4027 | + if ( ! $messenger instanceof EE_Messenger) { |
|
| 4028 | + EE_Error::add_error( |
|
| 4029 | + esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'), |
|
| 4030 | + __FILE__, |
|
| 4031 | + __FUNCTION__, |
|
| 4032 | + __LINE__ |
|
| 4033 | + ); |
|
| 4034 | 4034 | |
| 4035 | - return false; |
|
| 4036 | - } |
|
| 4037 | - //activated |
|
| 4038 | - if ($this->_template_args['data']['active_mts']) { |
|
| 4039 | - EE_Error::overwrite_success(); |
|
| 4040 | - //activated a message type with the messenger |
|
| 4041 | - if ($message_type instanceof EE_message_type) { |
|
| 4042 | - EE_Error::add_success( |
|
| 4043 | - sprintf( |
|
| 4044 | - esc_html__('%s message type has been successfully activated with the %s messenger', 'event_espresso'), |
|
| 4045 | - ucwords($message_type->label['singular']), |
|
| 4046 | - ucwords($messenger->label['singular']) |
|
| 4047 | - ) |
|
| 4048 | - ); |
|
| 4035 | + return false; |
|
| 4036 | + } |
|
| 4037 | + //activated |
|
| 4038 | + if ($this->_template_args['data']['active_mts']) { |
|
| 4039 | + EE_Error::overwrite_success(); |
|
| 4040 | + //activated a message type with the messenger |
|
| 4041 | + if ($message_type instanceof EE_message_type) { |
|
| 4042 | + EE_Error::add_success( |
|
| 4043 | + sprintf( |
|
| 4044 | + esc_html__('%s message type has been successfully activated with the %s messenger', 'event_espresso'), |
|
| 4045 | + ucwords($message_type->label['singular']), |
|
| 4046 | + ucwords($messenger->label['singular']) |
|
| 4047 | + ) |
|
| 4048 | + ); |
|
| 4049 | 4049 | |
| 4050 | - //if message type was invoice then let's make sure we activate the invoice payment method. |
|
| 4051 | - if ($message_type->name === 'invoice') { |
|
| 4052 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 4053 | - $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
| 4054 | - if ($pm instanceof EE_Payment_Method) { |
|
| 4055 | - EE_Error::add_attention( |
|
| 4056 | - esc_html__( |
|
| 4057 | - 'Activating the invoice message type also automatically activates the invoice payment method. If you do not wish the invoice payment method to be active, or to change its settings, visit the payment method admin page.', |
|
| 4058 | - 'event_espresso' |
|
| 4059 | - ) |
|
| 4060 | - ); |
|
| 4061 | - } |
|
| 4062 | - } |
|
| 4063 | - //just toggles the entire messenger |
|
| 4064 | - } else { |
|
| 4065 | - EE_Error::add_success( |
|
| 4066 | - sprintf( |
|
| 4067 | - esc_html__('%s messenger has been successfully activated', 'event_espresso'), |
|
| 4068 | - ucwords($messenger->label['singular']) |
|
| 4069 | - ) |
|
| 4070 | - ); |
|
| 4071 | - } |
|
| 4050 | + //if message type was invoice then let's make sure we activate the invoice payment method. |
|
| 4051 | + if ($message_type->name === 'invoice') { |
|
| 4052 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 4053 | + $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
| 4054 | + if ($pm instanceof EE_Payment_Method) { |
|
| 4055 | + EE_Error::add_attention( |
|
| 4056 | + esc_html__( |
|
| 4057 | + 'Activating the invoice message type also automatically activates the invoice payment method. If you do not wish the invoice payment method to be active, or to change its settings, visit the payment method admin page.', |
|
| 4058 | + 'event_espresso' |
|
| 4059 | + ) |
|
| 4060 | + ); |
|
| 4061 | + } |
|
| 4062 | + } |
|
| 4063 | + //just toggles the entire messenger |
|
| 4064 | + } else { |
|
| 4065 | + EE_Error::add_success( |
|
| 4066 | + sprintf( |
|
| 4067 | + esc_html__('%s messenger has been successfully activated', 'event_espresso'), |
|
| 4068 | + ucwords($messenger->label['singular']) |
|
| 4069 | + ) |
|
| 4070 | + ); |
|
| 4071 | + } |
|
| 4072 | 4072 | |
| 4073 | - return true; |
|
| 4073 | + return true; |
|
| 4074 | 4074 | |
| 4075 | - //possible error condition. This will happen when our active_mts data is empty because it is validated for actual active |
|
| 4076 | - //message types after the activation process. However its possible some messengers don't HAVE any default_message_types |
|
| 4077 | - //in which case we just give a success message for the messenger being successfully activated. |
|
| 4078 | - } else { |
|
| 4079 | - if ( ! $messenger->get_default_message_types()) { |
|
| 4080 | - //messenger doesn't have any default message types so still a success. |
|
| 4081 | - EE_Error::add_success( |
|
| 4082 | - sprintf( |
|
| 4083 | - esc_html__('%s messenger was successfully activated.', 'event_espresso'), |
|
| 4084 | - ucwords($messenger->label['singular']) |
|
| 4085 | - ) |
|
| 4086 | - ); |
|
| 4075 | + //possible error condition. This will happen when our active_mts data is empty because it is validated for actual active |
|
| 4076 | + //message types after the activation process. However its possible some messengers don't HAVE any default_message_types |
|
| 4077 | + //in which case we just give a success message for the messenger being successfully activated. |
|
| 4078 | + } else { |
|
| 4079 | + if ( ! $messenger->get_default_message_types()) { |
|
| 4080 | + //messenger doesn't have any default message types so still a success. |
|
| 4081 | + EE_Error::add_success( |
|
| 4082 | + sprintf( |
|
| 4083 | + esc_html__('%s messenger was successfully activated.', 'event_espresso'), |
|
| 4084 | + ucwords($messenger->label['singular']) |
|
| 4085 | + ) |
|
| 4086 | + ); |
|
| 4087 | 4087 | |
| 4088 | - return true; |
|
| 4089 | - } else { |
|
| 4090 | - EE_Error::add_error( |
|
| 4091 | - $message_type instanceof EE_message_type |
|
| 4092 | - ? sprintf( |
|
| 4093 | - esc_html__('%s message type was not successfully activated with the %s messenger', 'event_espresso'), |
|
| 4094 | - ucwords($message_type->label['singular']), |
|
| 4095 | - ucwords($messenger->label['singular']) |
|
| 4096 | - ) |
|
| 4097 | - : sprintf( |
|
| 4098 | - esc_html__('%s messenger was not successfully activated', 'event_espresso'), |
|
| 4099 | - ucwords($messenger->label['singular']) |
|
| 4100 | - ), |
|
| 4101 | - __FILE__, |
|
| 4102 | - __FUNCTION__, |
|
| 4103 | - __LINE__ |
|
| 4104 | - ); |
|
| 4088 | + return true; |
|
| 4089 | + } else { |
|
| 4090 | + EE_Error::add_error( |
|
| 4091 | + $message_type instanceof EE_message_type |
|
| 4092 | + ? sprintf( |
|
| 4093 | + esc_html__('%s message type was not successfully activated with the %s messenger', 'event_espresso'), |
|
| 4094 | + ucwords($message_type->label['singular']), |
|
| 4095 | + ucwords($messenger->label['singular']) |
|
| 4096 | + ) |
|
| 4097 | + : sprintf( |
|
| 4098 | + esc_html__('%s messenger was not successfully activated', 'event_espresso'), |
|
| 4099 | + ucwords($messenger->label['singular']) |
|
| 4100 | + ), |
|
| 4101 | + __FILE__, |
|
| 4102 | + __FUNCTION__, |
|
| 4103 | + __LINE__ |
|
| 4104 | + ); |
|
| 4105 | 4105 | |
| 4106 | - return false; |
|
| 4107 | - } |
|
| 4108 | - } |
|
| 4109 | - } |
|
| 4106 | + return false; |
|
| 4107 | + } |
|
| 4108 | + } |
|
| 4109 | + } |
|
| 4110 | 4110 | |
| 4111 | 4111 | |
| 4112 | - /** |
|
| 4113 | - * This sets up the appropriate response for deactivating a messenger and/or message type. |
|
| 4114 | - * |
|
| 4115 | - * @param EE_messenger $messenger |
|
| 4116 | - * @param EE_message_type|null $message_type |
|
| 4117 | - * @return bool |
|
| 4118 | - * @throws DomainException |
|
| 4119 | - * @throws EE_Error |
|
| 4120 | - * @throws InvalidArgumentException |
|
| 4121 | - * @throws ReflectionException |
|
| 4122 | - * @throws InvalidDataTypeException |
|
| 4123 | - * @throws InvalidInterfaceException |
|
| 4124 | - */ |
|
| 4125 | - protected function _setup_response_message_for_deactivating_messenger_with_message_types( |
|
| 4126 | - $messenger, |
|
| 4127 | - EE_message_type $message_type = null |
|
| 4128 | - ) { |
|
| 4129 | - EE_Error::overwrite_success(); |
|
| 4130 | - |
|
| 4131 | - //if $messenger isn't a valid messenger object then get out. |
|
| 4132 | - if ( ! $messenger instanceof EE_Messenger) { |
|
| 4133 | - EE_Error::add_error( |
|
| 4134 | - esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'), |
|
| 4135 | - __FILE__, |
|
| 4136 | - __FUNCTION__, |
|
| 4137 | - __LINE__ |
|
| 4138 | - ); |
|
| 4112 | + /** |
|
| 4113 | + * This sets up the appropriate response for deactivating a messenger and/or message type. |
|
| 4114 | + * |
|
| 4115 | + * @param EE_messenger $messenger |
|
| 4116 | + * @param EE_message_type|null $message_type |
|
| 4117 | + * @return bool |
|
| 4118 | + * @throws DomainException |
|
| 4119 | + * @throws EE_Error |
|
| 4120 | + * @throws InvalidArgumentException |
|
| 4121 | + * @throws ReflectionException |
|
| 4122 | + * @throws InvalidDataTypeException |
|
| 4123 | + * @throws InvalidInterfaceException |
|
| 4124 | + */ |
|
| 4125 | + protected function _setup_response_message_for_deactivating_messenger_with_message_types( |
|
| 4126 | + $messenger, |
|
| 4127 | + EE_message_type $message_type = null |
|
| 4128 | + ) { |
|
| 4129 | + EE_Error::overwrite_success(); |
|
| 4130 | + |
|
| 4131 | + //if $messenger isn't a valid messenger object then get out. |
|
| 4132 | + if ( ! $messenger instanceof EE_Messenger) { |
|
| 4133 | + EE_Error::add_error( |
|
| 4134 | + esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'), |
|
| 4135 | + __FILE__, |
|
| 4136 | + __FUNCTION__, |
|
| 4137 | + __LINE__ |
|
| 4138 | + ); |
|
| 4139 | 4139 | |
| 4140 | - return false; |
|
| 4141 | - } |
|
| 4142 | - |
|
| 4143 | - if ($message_type instanceof EE_message_type) { |
|
| 4144 | - $message_type_name = $message_type->name; |
|
| 4145 | - EE_Error::add_success( |
|
| 4146 | - sprintf( |
|
| 4147 | - esc_html__('%s message type has been successfully deactivated for the %s messenger.', 'event_espresso'), |
|
| 4148 | - ucwords($message_type->label['singular']), |
|
| 4149 | - ucwords($messenger->label['singular']) |
|
| 4150 | - ) |
|
| 4151 | - ); |
|
| 4152 | - } else { |
|
| 4153 | - $message_type_name = ''; |
|
| 4154 | - EE_Error::add_success( |
|
| 4155 | - sprintf( |
|
| 4156 | - esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'), |
|
| 4157 | - ucwords($messenger->label['singular']) |
|
| 4158 | - ) |
|
| 4159 | - ); |
|
| 4160 | - } |
|
| 4161 | - |
|
| 4162 | - //if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method. |
|
| 4163 | - if ($messenger->name === 'html' || $message_type_name === 'invoice') { |
|
| 4164 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 4165 | - $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice'); |
|
| 4166 | - if ($count_updated > 0) { |
|
| 4167 | - $msg = $message_type_name === 'invoice' |
|
| 4168 | - ? esc_html__( |
|
| 4169 | - 'Deactivating the invoice message type also automatically deactivates the invoice payment method. In order for invoices to be generated the invoice message type must be active. If you completed this action by mistake, simply reactivate the invoice message type and then visit the payment methods admin page to reactivate the invoice payment method.', |
|
| 4170 | - 'event_espresso' |
|
| 4171 | - ) |
|
| 4172 | - : esc_html__( |
|
| 4173 | - 'Deactivating the html messenger also automatically deactivates the invoice payment method. In order for invoices to be generated the html messenger must be be active. If you completed this action by mistake, simply reactivate the html messenger, then visit the payment methods admin page to reactivate the invoice payment method.', |
|
| 4174 | - 'event_espresso' |
|
| 4175 | - ); |
|
| 4176 | - EE_Error::add_attention($msg); |
|
| 4177 | - } |
|
| 4178 | - } |
|
| 4179 | - |
|
| 4180 | - return true; |
|
| 4181 | - } |
|
| 4140 | + return false; |
|
| 4141 | + } |
|
| 4142 | + |
|
| 4143 | + if ($message_type instanceof EE_message_type) { |
|
| 4144 | + $message_type_name = $message_type->name; |
|
| 4145 | + EE_Error::add_success( |
|
| 4146 | + sprintf( |
|
| 4147 | + esc_html__('%s message type has been successfully deactivated for the %s messenger.', 'event_espresso'), |
|
| 4148 | + ucwords($message_type->label['singular']), |
|
| 4149 | + ucwords($messenger->label['singular']) |
|
| 4150 | + ) |
|
| 4151 | + ); |
|
| 4152 | + } else { |
|
| 4153 | + $message_type_name = ''; |
|
| 4154 | + EE_Error::add_success( |
|
| 4155 | + sprintf( |
|
| 4156 | + esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'), |
|
| 4157 | + ucwords($messenger->label['singular']) |
|
| 4158 | + ) |
|
| 4159 | + ); |
|
| 4160 | + } |
|
| 4161 | + |
|
| 4162 | + //if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method. |
|
| 4163 | + if ($messenger->name === 'html' || $message_type_name === 'invoice') { |
|
| 4164 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 4165 | + $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice'); |
|
| 4166 | + if ($count_updated > 0) { |
|
| 4167 | + $msg = $message_type_name === 'invoice' |
|
| 4168 | + ? esc_html__( |
|
| 4169 | + 'Deactivating the invoice message type also automatically deactivates the invoice payment method. In order for invoices to be generated the invoice message type must be active. If you completed this action by mistake, simply reactivate the invoice message type and then visit the payment methods admin page to reactivate the invoice payment method.', |
|
| 4170 | + 'event_espresso' |
|
| 4171 | + ) |
|
| 4172 | + : esc_html__( |
|
| 4173 | + 'Deactivating the html messenger also automatically deactivates the invoice payment method. In order for invoices to be generated the html messenger must be be active. If you completed this action by mistake, simply reactivate the html messenger, then visit the payment methods admin page to reactivate the invoice payment method.', |
|
| 4174 | + 'event_espresso' |
|
| 4175 | + ); |
|
| 4176 | + EE_Error::add_attention($msg); |
|
| 4177 | + } |
|
| 4178 | + } |
|
| 4179 | + |
|
| 4180 | + return true; |
|
| 4181 | + } |
|
| 4182 | 4182 | |
| 4183 | 4183 | |
| 4184 | - /** |
|
| 4185 | - * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax) |
|
| 4186 | - * |
|
| 4187 | - * @throws DomainException |
|
| 4188 | - */ |
|
| 4189 | - public function update_mt_form() |
|
| 4190 | - { |
|
| 4191 | - if ( ! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) { |
|
| 4192 | - EE_Error::add_error( |
|
| 4193 | - esc_html__('Require message type or messenger to send an updated form', 'event_espresso'), |
|
| 4194 | - __FILE__, |
|
| 4195 | - __FUNCTION__, |
|
| 4196 | - __LINE__ |
|
| 4197 | - ); |
|
| 4198 | - $this->_return_json(); |
|
| 4199 | - } |
|
| 4200 | - |
|
| 4201 | - $message_types = $this->get_installed_message_types(); |
|
| 4202 | - |
|
| 4203 | - $message_type = $message_types[$this->_req_data['message_type']]; |
|
| 4204 | - $messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); |
|
| 4205 | - |
|
| 4206 | - $content = $this->_message_type_settings_content( |
|
| 4207 | - $message_type, |
|
| 4208 | - $messenger, |
|
| 4209 | - true |
|
| 4210 | - ); |
|
| 4211 | - $this->_template_args['success'] = true; |
|
| 4212 | - $this->_template_args['content'] = $content; |
|
| 4213 | - $this->_return_json(); |
|
| 4214 | - } |
|
| 4184 | + /** |
|
| 4185 | + * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax) |
|
| 4186 | + * |
|
| 4187 | + * @throws DomainException |
|
| 4188 | + */ |
|
| 4189 | + public function update_mt_form() |
|
| 4190 | + { |
|
| 4191 | + if ( ! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) { |
|
| 4192 | + EE_Error::add_error( |
|
| 4193 | + esc_html__('Require message type or messenger to send an updated form', 'event_espresso'), |
|
| 4194 | + __FILE__, |
|
| 4195 | + __FUNCTION__, |
|
| 4196 | + __LINE__ |
|
| 4197 | + ); |
|
| 4198 | + $this->_return_json(); |
|
| 4199 | + } |
|
| 4200 | + |
|
| 4201 | + $message_types = $this->get_installed_message_types(); |
|
| 4202 | + |
|
| 4203 | + $message_type = $message_types[$this->_req_data['message_type']]; |
|
| 4204 | + $messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); |
|
| 4205 | + |
|
| 4206 | + $content = $this->_message_type_settings_content( |
|
| 4207 | + $message_type, |
|
| 4208 | + $messenger, |
|
| 4209 | + true |
|
| 4210 | + ); |
|
| 4211 | + $this->_template_args['success'] = true; |
|
| 4212 | + $this->_template_args['content'] = $content; |
|
| 4213 | + $this->_return_json(); |
|
| 4214 | + } |
|
| 4215 | 4215 | |
| 4216 | 4216 | |
| 4217 | - /** |
|
| 4218 | - * this handles saving the settings for a messenger or message type |
|
| 4219 | - * |
|
| 4220 | - */ |
|
| 4221 | - public function save_settings() |
|
| 4222 | - { |
|
| 4223 | - if ( ! isset($this->_req_data['type'])) { |
|
| 4224 | - EE_Error::add_error( |
|
| 4225 | - esc_html__( |
|
| 4226 | - 'Cannot save settings because type is unknown (messenger settings or messsage type settings?)', |
|
| 4227 | - 'event_espresso' |
|
| 4228 | - ), |
|
| 4229 | - __FILE__, |
|
| 4230 | - __FUNCTION__, |
|
| 4231 | - __LINE__ |
|
| 4232 | - ); |
|
| 4233 | - $this->_template_args['error'] = true; |
|
| 4234 | - $this->_return_json(); |
|
| 4235 | - } |
|
| 4236 | - |
|
| 4237 | - |
|
| 4238 | - if ($this->_req_data['type'] === 'messenger') { |
|
| 4239 | - //this should be an array. |
|
| 4240 | - $settings = $this->_req_data['messenger_settings']; |
|
| 4241 | - $messenger = $settings['messenger']; |
|
| 4242 | - //let's setup the settings data |
|
| 4243 | - foreach ($settings as $key => $value) { |
|
| 4244 | - switch ($key) { |
|
| 4245 | - case 'messenger' : |
|
| 4246 | - unset($settings['messenger']); |
|
| 4247 | - break; |
|
| 4248 | - case 'message_types' : |
|
| 4249 | - unset($settings['message_types']); |
|
| 4250 | - break; |
|
| 4251 | - default : |
|
| 4252 | - $settings[$key] = $value; |
|
| 4253 | - break; |
|
| 4254 | - } |
|
| 4255 | - } |
|
| 4256 | - $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings); |
|
| 4257 | - } elseif ($this->_req_data['type'] === 'message_type') { |
|
| 4258 | - $settings = $this->_req_data['message_type_settings']; |
|
| 4259 | - $messenger = $settings['messenger']; |
|
| 4260 | - $message_type = $settings['message_type']; |
|
| 4217 | + /** |
|
| 4218 | + * this handles saving the settings for a messenger or message type |
|
| 4219 | + * |
|
| 4220 | + */ |
|
| 4221 | + public function save_settings() |
|
| 4222 | + { |
|
| 4223 | + if ( ! isset($this->_req_data['type'])) { |
|
| 4224 | + EE_Error::add_error( |
|
| 4225 | + esc_html__( |
|
| 4226 | + 'Cannot save settings because type is unknown (messenger settings or messsage type settings?)', |
|
| 4227 | + 'event_espresso' |
|
| 4228 | + ), |
|
| 4229 | + __FILE__, |
|
| 4230 | + __FUNCTION__, |
|
| 4231 | + __LINE__ |
|
| 4232 | + ); |
|
| 4233 | + $this->_template_args['error'] = true; |
|
| 4234 | + $this->_return_json(); |
|
| 4235 | + } |
|
| 4236 | + |
|
| 4237 | + |
|
| 4238 | + if ($this->_req_data['type'] === 'messenger') { |
|
| 4239 | + //this should be an array. |
|
| 4240 | + $settings = $this->_req_data['messenger_settings']; |
|
| 4241 | + $messenger = $settings['messenger']; |
|
| 4242 | + //let's setup the settings data |
|
| 4243 | + foreach ($settings as $key => $value) { |
|
| 4244 | + switch ($key) { |
|
| 4245 | + case 'messenger' : |
|
| 4246 | + unset($settings['messenger']); |
|
| 4247 | + break; |
|
| 4248 | + case 'message_types' : |
|
| 4249 | + unset($settings['message_types']); |
|
| 4250 | + break; |
|
| 4251 | + default : |
|
| 4252 | + $settings[$key] = $value; |
|
| 4253 | + break; |
|
| 4254 | + } |
|
| 4255 | + } |
|
| 4256 | + $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings); |
|
| 4257 | + } elseif ($this->_req_data['type'] === 'message_type') { |
|
| 4258 | + $settings = $this->_req_data['message_type_settings']; |
|
| 4259 | + $messenger = $settings['messenger']; |
|
| 4260 | + $message_type = $settings['message_type']; |
|
| 4261 | 4261 | |
| 4262 | - foreach ($settings as $key => $value) { |
|
| 4263 | - switch ($key) { |
|
| 4264 | - case 'messenger' : |
|
| 4265 | - unset($settings['messenger']); |
|
| 4266 | - break; |
|
| 4267 | - case 'message_type' : |
|
| 4268 | - unset($settings['message_type']); |
|
| 4269 | - break; |
|
| 4270 | - default : |
|
| 4271 | - $settings[$key] = $value; |
|
| 4272 | - break; |
|
| 4273 | - } |
|
| 4274 | - } |
|
| 4262 | + foreach ($settings as $key => $value) { |
|
| 4263 | + switch ($key) { |
|
| 4264 | + case 'messenger' : |
|
| 4265 | + unset($settings['messenger']); |
|
| 4266 | + break; |
|
| 4267 | + case 'message_type' : |
|
| 4268 | + unset($settings['message_type']); |
|
| 4269 | + break; |
|
| 4270 | + default : |
|
| 4271 | + $settings[$key] = $value; |
|
| 4272 | + break; |
|
| 4273 | + } |
|
| 4274 | + } |
|
| 4275 | 4275 | |
| 4276 | - $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings); |
|
| 4277 | - } |
|
| 4278 | - |
|
| 4279 | - //okay we should have the data all setup. Now we just update! |
|
| 4280 | - $success = $this->_message_resource_manager->update_active_messengers_option(); |
|
| 4281 | - |
|
| 4282 | - if ($success) { |
|
| 4283 | - EE_Error::add_success(__('Settings updated', 'event_espresso')); |
|
| 4284 | - } else { |
|
| 4285 | - EE_Error::add_error( |
|
| 4286 | - esc_html__( |
|
| 4287 | - 'Settings did not get updated', |
|
| 4288 | - 'event_espresso' |
|
| 4289 | - ), |
|
| 4290 | - __FILE__, |
|
| 4291 | - __FUNCTION__, |
|
| 4292 | - __LINE__ |
|
| 4293 | - ); |
|
| 4294 | - } |
|
| 4295 | - |
|
| 4296 | - $this->_template_args['success'] = $success; |
|
| 4297 | - $this->_return_json(); |
|
| 4298 | - } |
|
| 4276 | + $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings); |
|
| 4277 | + } |
|
| 4278 | + |
|
| 4279 | + //okay we should have the data all setup. Now we just update! |
|
| 4280 | + $success = $this->_message_resource_manager->update_active_messengers_option(); |
|
| 4281 | + |
|
| 4282 | + if ($success) { |
|
| 4283 | + EE_Error::add_success(__('Settings updated', 'event_espresso')); |
|
| 4284 | + } else { |
|
| 4285 | + EE_Error::add_error( |
|
| 4286 | + esc_html__( |
|
| 4287 | + 'Settings did not get updated', |
|
| 4288 | + 'event_espresso' |
|
| 4289 | + ), |
|
| 4290 | + __FILE__, |
|
| 4291 | + __FUNCTION__, |
|
| 4292 | + __LINE__ |
|
| 4293 | + ); |
|
| 4294 | + } |
|
| 4295 | + |
|
| 4296 | + $this->_template_args['success'] = $success; |
|
| 4297 | + $this->_return_json(); |
|
| 4298 | + } |
|
| 4299 | 4299 | |
| 4300 | 4300 | |
| 4301 | 4301 | |
| 4302 | 4302 | |
| 4303 | - /** EE MESSAGE PROCESSING ACTIONS **/ |
|
| 4303 | + /** EE MESSAGE PROCESSING ACTIONS **/ |
|
| 4304 | 4304 | |
| 4305 | 4305 | |
| 4306 | - /** |
|
| 4307 | - * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete |
|
| 4308 | - * However, this does not send immediately, it just queues for sending. |
|
| 4309 | - * |
|
| 4310 | - * @since 4.9.0 |
|
| 4311 | - * @throws EE_Error |
|
| 4312 | - * @throws InvalidDataTypeException |
|
| 4313 | - * @throws InvalidInterfaceException |
|
| 4314 | - * @throws InvalidArgumentException |
|
| 4315 | - * @throws ReflectionException |
|
| 4316 | - */ |
|
| 4317 | - protected function _generate_now() |
|
| 4318 | - { |
|
| 4319 | - EED_Messages::generate_now($this->_get_msg_ids_from_request()); |
|
| 4320 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4321 | - } |
|
| 4306 | + /** |
|
| 4307 | + * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete |
|
| 4308 | + * However, this does not send immediately, it just queues for sending. |
|
| 4309 | + * |
|
| 4310 | + * @since 4.9.0 |
|
| 4311 | + * @throws EE_Error |
|
| 4312 | + * @throws InvalidDataTypeException |
|
| 4313 | + * @throws InvalidInterfaceException |
|
| 4314 | + * @throws InvalidArgumentException |
|
| 4315 | + * @throws ReflectionException |
|
| 4316 | + */ |
|
| 4317 | + protected function _generate_now() |
|
| 4318 | + { |
|
| 4319 | + EED_Messages::generate_now($this->_get_msg_ids_from_request()); |
|
| 4320 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4321 | + } |
|
| 4322 | 4322 | |
| 4323 | 4323 | |
| 4324 | - /** |
|
| 4325 | - * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that |
|
| 4326 | - * are EEM_Message::status_resend or EEM_Message::status_idle |
|
| 4327 | - * |
|
| 4328 | - * @since 4.9.0 |
|
| 4329 | - * @throws EE_Error |
|
| 4330 | - * @throws InvalidDataTypeException |
|
| 4331 | - * @throws InvalidInterfaceException |
|
| 4332 | - * @throws InvalidArgumentException |
|
| 4333 | - * @throws ReflectionException |
|
| 4334 | - */ |
|
| 4335 | - protected function _generate_and_send_now() |
|
| 4336 | - { |
|
| 4337 | - EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request()); |
|
| 4338 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4339 | - } |
|
| 4324 | + /** |
|
| 4325 | + * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that |
|
| 4326 | + * are EEM_Message::status_resend or EEM_Message::status_idle |
|
| 4327 | + * |
|
| 4328 | + * @since 4.9.0 |
|
| 4329 | + * @throws EE_Error |
|
| 4330 | + * @throws InvalidDataTypeException |
|
| 4331 | + * @throws InvalidInterfaceException |
|
| 4332 | + * @throws InvalidArgumentException |
|
| 4333 | + * @throws ReflectionException |
|
| 4334 | + */ |
|
| 4335 | + protected function _generate_and_send_now() |
|
| 4336 | + { |
|
| 4337 | + EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request()); |
|
| 4338 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4339 | + } |
|
| 4340 | 4340 | |
| 4341 | 4341 | |
| 4342 | - /** |
|
| 4343 | - * This queues any EEM_Message::status_sent EE_Message ids in the request for resending. |
|
| 4344 | - * |
|
| 4345 | - * @since 4.9.0 |
|
| 4346 | - * @throws EE_Error |
|
| 4347 | - * @throws InvalidDataTypeException |
|
| 4348 | - * @throws InvalidInterfaceException |
|
| 4349 | - * @throws InvalidArgumentException |
|
| 4350 | - * @throws ReflectionException |
|
| 4351 | - */ |
|
| 4352 | - protected function _queue_for_resending() |
|
| 4353 | - { |
|
| 4354 | - EED_Messages::queue_for_resending($this->_get_msg_ids_from_request()); |
|
| 4355 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4356 | - } |
|
| 4342 | + /** |
|
| 4343 | + * This queues any EEM_Message::status_sent EE_Message ids in the request for resending. |
|
| 4344 | + * |
|
| 4345 | + * @since 4.9.0 |
|
| 4346 | + * @throws EE_Error |
|
| 4347 | + * @throws InvalidDataTypeException |
|
| 4348 | + * @throws InvalidInterfaceException |
|
| 4349 | + * @throws InvalidArgumentException |
|
| 4350 | + * @throws ReflectionException |
|
| 4351 | + */ |
|
| 4352 | + protected function _queue_for_resending() |
|
| 4353 | + { |
|
| 4354 | + EED_Messages::queue_for_resending($this->_get_msg_ids_from_request()); |
|
| 4355 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4356 | + } |
|
| 4357 | 4357 | |
| 4358 | 4358 | |
| 4359 | - /** |
|
| 4360 | - * This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue |
|
| 4361 | - * |
|
| 4362 | - * @since 4.9.0 |
|
| 4363 | - * @throws EE_Error |
|
| 4364 | - * @throws InvalidDataTypeException |
|
| 4365 | - * @throws InvalidInterfaceException |
|
| 4366 | - * @throws InvalidArgumentException |
|
| 4367 | - * @throws ReflectionException |
|
| 4368 | - */ |
|
| 4369 | - protected function _send_now() |
|
| 4370 | - { |
|
| 4371 | - EED_Messages::send_now($this->_get_msg_ids_from_request()); |
|
| 4372 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4373 | - } |
|
| 4359 | + /** |
|
| 4360 | + * This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue |
|
| 4361 | + * |
|
| 4362 | + * @since 4.9.0 |
|
| 4363 | + * @throws EE_Error |
|
| 4364 | + * @throws InvalidDataTypeException |
|
| 4365 | + * @throws InvalidInterfaceException |
|
| 4366 | + * @throws InvalidArgumentException |
|
| 4367 | + * @throws ReflectionException |
|
| 4368 | + */ |
|
| 4369 | + protected function _send_now() |
|
| 4370 | + { |
|
| 4371 | + EED_Messages::send_now($this->_get_msg_ids_from_request()); |
|
| 4372 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4373 | + } |
|
| 4374 | 4374 | |
| 4375 | 4375 | |
| 4376 | - /** |
|
| 4377 | - * Deletes EE_messages for IDs in the request. |
|
| 4378 | - * |
|
| 4379 | - * @since 4.9.0 |
|
| 4380 | - * @throws EE_Error |
|
| 4381 | - * @throws InvalidDataTypeException |
|
| 4382 | - * @throws InvalidInterfaceException |
|
| 4383 | - * @throws InvalidArgumentException |
|
| 4384 | - */ |
|
| 4385 | - protected function _delete_ee_messages() |
|
| 4386 | - { |
|
| 4387 | - $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 4388 | - $deleted_count = 0; |
|
| 4389 | - foreach ($msg_ids as $msg_id) { |
|
| 4390 | - if (EEM_Message::instance()->delete_by_ID($msg_id)) { |
|
| 4391 | - $deleted_count++; |
|
| 4392 | - } |
|
| 4393 | - } |
|
| 4394 | - if ($deleted_count) { |
|
| 4395 | - $this->_redirect_after_action( |
|
| 4396 | - true, |
|
| 4397 | - _n('message', 'messages', $deleted_count, 'event_espresso'), |
|
| 4398 | - esc_html__('deleted', 'event_espresso') |
|
| 4399 | - ); |
|
| 4400 | - } else { |
|
| 4401 | - EE_Error::add_error( |
|
| 4402 | - _n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'), |
|
| 4403 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 4404 | - ); |
|
| 4405 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4406 | - } |
|
| 4407 | - } |
|
| 4376 | + /** |
|
| 4377 | + * Deletes EE_messages for IDs in the request. |
|
| 4378 | + * |
|
| 4379 | + * @since 4.9.0 |
|
| 4380 | + * @throws EE_Error |
|
| 4381 | + * @throws InvalidDataTypeException |
|
| 4382 | + * @throws InvalidInterfaceException |
|
| 4383 | + * @throws InvalidArgumentException |
|
| 4384 | + */ |
|
| 4385 | + protected function _delete_ee_messages() |
|
| 4386 | + { |
|
| 4387 | + $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 4388 | + $deleted_count = 0; |
|
| 4389 | + foreach ($msg_ids as $msg_id) { |
|
| 4390 | + if (EEM_Message::instance()->delete_by_ID($msg_id)) { |
|
| 4391 | + $deleted_count++; |
|
| 4392 | + } |
|
| 4393 | + } |
|
| 4394 | + if ($deleted_count) { |
|
| 4395 | + $this->_redirect_after_action( |
|
| 4396 | + true, |
|
| 4397 | + _n('message', 'messages', $deleted_count, 'event_espresso'), |
|
| 4398 | + esc_html__('deleted', 'event_espresso') |
|
| 4399 | + ); |
|
| 4400 | + } else { |
|
| 4401 | + EE_Error::add_error( |
|
| 4402 | + _n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'), |
|
| 4403 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 4404 | + ); |
|
| 4405 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4406 | + } |
|
| 4407 | + } |
|
| 4408 | 4408 | |
| 4409 | 4409 | |
| 4410 | - /** |
|
| 4411 | - * This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present. |
|
| 4412 | - * @since 4.9.0 |
|
| 4413 | - * @return array |
|
| 4414 | - */ |
|
| 4415 | - protected function _get_msg_ids_from_request() |
|
| 4416 | - { |
|
| 4417 | - if ( ! isset($this->_req_data['MSG_ID'])) { |
|
| 4418 | - return array(); |
|
| 4419 | - } |
|
| 4420 | - |
|
| 4421 | - return is_array($this->_req_data['MSG_ID']) |
|
| 4422 | - ? array_keys($this->_req_data['MSG_ID']) |
|
| 4423 | - : array($this->_req_data['MSG_ID']); |
|
| 4424 | - } |
|
| 4410 | + /** |
|
| 4411 | + * This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present. |
|
| 4412 | + * @since 4.9.0 |
|
| 4413 | + * @return array |
|
| 4414 | + */ |
|
| 4415 | + protected function _get_msg_ids_from_request() |
|
| 4416 | + { |
|
| 4417 | + if ( ! isset($this->_req_data['MSG_ID'])) { |
|
| 4418 | + return array(); |
|
| 4419 | + } |
|
| 4420 | + |
|
| 4421 | + return is_array($this->_req_data['MSG_ID']) |
|
| 4422 | + ? array_keys($this->_req_data['MSG_ID']) |
|
| 4423 | + : array($this->_req_data['MSG_ID']); |
|
| 4424 | + } |
|
| 4425 | 4425 | } |
@@ -18,27 +18,27 @@ |
||
| 18 | 18 | * @author Darren Ethier |
| 19 | 19 | */ |
| 20 | 20 | class EE_Messages_Email_Newsletter_Validator extends EE_Messages_Validator { |
| 21 | - public function __construct( $fields, $context ) { |
|
| 22 | - $this->_m_name = 'email'; |
|
| 23 | - $this->_mt_name = 'newsletter'; |
|
| 21 | + public function __construct( $fields, $context ) { |
|
| 22 | + $this->_m_name = 'email'; |
|
| 23 | + $this->_mt_name = 'newsletter'; |
|
| 24 | 24 | |
| 25 | - parent::__construct( $fields, $context ); |
|
| 26 | - } |
|
| 25 | + parent::__construct( $fields, $context ); |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * custom validator (restricting what was originally set by the messenger) |
|
| 30 | - */ |
|
| 31 | - protected function _modify_validator() { |
|
| 32 | - if ( $this->_context == 'attendee' ) |
|
| 33 | - $this->_valid_shortcodes_modifier[$this->_context]['from'] = array('recipient_details', 'email', 'organization'); |
|
| 28 | + /** |
|
| 29 | + * custom validator (restricting what was originally set by the messenger) |
|
| 30 | + */ |
|
| 31 | + protected function _modify_validator() { |
|
| 32 | + if ( $this->_context == 'attendee' ) |
|
| 33 | + $this->_valid_shortcodes_modifier[$this->_context]['from'] = array('recipient_details', 'email', 'organization'); |
|
| 34 | 34 | |
| 35 | - //excluded shortcodes |
|
| 36 | - $fields = array('to','from','subject','content','newsletter_content'); |
|
| 37 | - foreach ( $fields as $field ) { |
|
| 38 | - $this->_specific_shortcode_excludes[$field] = array('[RECIPIENT_REGISTRATION_CODE]', '[EVENT_AUTHOR_FORMATTED_EMAIL]', '[EVENT_AUTHOR_EMAIL]'); |
|
| 39 | - } |
|
| 40 | - $add_excludes = array( '[RECIPIENT_FNAME]', '[RECIPIENT_LNAME]', '[RECIPIENT_EMAIL]', '[COMPANY]', '[CO_ADD1]','[CO_ADD2]', '[CO_CITY]', '[CO_STATE]','[CO_ZIP]','[CO_LOGO]','[CO_PHONE]','[CO_LOGO_URL]','[CO_FACEBOOK_URL]','[CO_TWITTER_URL]','[CO_PINTEREST_URL]','[CO_GOOGLE_URL]','[CO_LINKEDIN_URL]','[CO_INSTAGRAM_URL]'); |
|
| 41 | - $this->_specific_shortcode_excludes['from'] = array_merge($this->_specific_shortcode_excludes['from'], $add_excludes); |
|
| 42 | - $this->_specific_shortcode_excludes['content'] = array_merge( $this->_specific_shortcode_excludes['content'], array('[DISPLAY_PDF_URL]', '[DISPLAY_PDF_BUTTON]') ); |
|
| 43 | - } |
|
| 35 | + //excluded shortcodes |
|
| 36 | + $fields = array('to','from','subject','content','newsletter_content'); |
|
| 37 | + foreach ( $fields as $field ) { |
|
| 38 | + $this->_specific_shortcode_excludes[$field] = array('[RECIPIENT_REGISTRATION_CODE]', '[EVENT_AUTHOR_FORMATTED_EMAIL]', '[EVENT_AUTHOR_EMAIL]'); |
|
| 39 | + } |
|
| 40 | + $add_excludes = array( '[RECIPIENT_FNAME]', '[RECIPIENT_LNAME]', '[RECIPIENT_EMAIL]', '[COMPANY]', '[CO_ADD1]','[CO_ADD2]', '[CO_CITY]', '[CO_STATE]','[CO_ZIP]','[CO_LOGO]','[CO_PHONE]','[CO_LOGO_URL]','[CO_FACEBOOK_URL]','[CO_TWITTER_URL]','[CO_PINTEREST_URL]','[CO_GOOGLE_URL]','[CO_LINKEDIN_URL]','[CO_INSTAGRAM_URL]'); |
|
| 41 | + $this->_specific_shortcode_excludes['from'] = array_merge($this->_specific_shortcode_excludes['from'], $add_excludes); |
|
| 42 | + $this->_specific_shortcode_excludes['content'] = array_merge( $this->_specific_shortcode_excludes['content'], array('[DISPLAY_PDF_URL]', '[DISPLAY_PDF_BUTTON]') ); |
|
| 43 | + } |
|
| 44 | 44 | } |
@@ -18,27 +18,27 @@ |
||
| 18 | 18 | * @author Darren Ethier |
| 19 | 19 | */ |
| 20 | 20 | class EE_Messages_Email_Newsletter_Validator extends EE_Messages_Validator { |
| 21 | - public function __construct( $fields, $context ) { |
|
| 21 | + public function __construct($fields, $context) { |
|
| 22 | 22 | $this->_m_name = 'email'; |
| 23 | 23 | $this->_mt_name = 'newsletter'; |
| 24 | 24 | |
| 25 | - parent::__construct( $fields, $context ); |
|
| 25 | + parent::__construct($fields, $context); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | 29 | * custom validator (restricting what was originally set by the messenger) |
| 30 | 30 | */ |
| 31 | 31 | protected function _modify_validator() { |
| 32 | - if ( $this->_context == 'attendee' ) |
|
| 32 | + if ($this->_context == 'attendee') |
|
| 33 | 33 | $this->_valid_shortcodes_modifier[$this->_context]['from'] = array('recipient_details', 'email', 'organization'); |
| 34 | 34 | |
| 35 | 35 | //excluded shortcodes |
| 36 | - $fields = array('to','from','subject','content','newsletter_content'); |
|
| 37 | - foreach ( $fields as $field ) { |
|
| 36 | + $fields = array('to', 'from', 'subject', 'content', 'newsletter_content'); |
|
| 37 | + foreach ($fields as $field) { |
|
| 38 | 38 | $this->_specific_shortcode_excludes[$field] = array('[RECIPIENT_REGISTRATION_CODE]', '[EVENT_AUTHOR_FORMATTED_EMAIL]', '[EVENT_AUTHOR_EMAIL]'); |
| 39 | 39 | } |
| 40 | - $add_excludes = array( '[RECIPIENT_FNAME]', '[RECIPIENT_LNAME]', '[RECIPIENT_EMAIL]', '[COMPANY]', '[CO_ADD1]','[CO_ADD2]', '[CO_CITY]', '[CO_STATE]','[CO_ZIP]','[CO_LOGO]','[CO_PHONE]','[CO_LOGO_URL]','[CO_FACEBOOK_URL]','[CO_TWITTER_URL]','[CO_PINTEREST_URL]','[CO_GOOGLE_URL]','[CO_LINKEDIN_URL]','[CO_INSTAGRAM_URL]'); |
|
| 40 | + $add_excludes = array('[RECIPIENT_FNAME]', '[RECIPIENT_LNAME]', '[RECIPIENT_EMAIL]', '[COMPANY]', '[CO_ADD1]', '[CO_ADD2]', '[CO_CITY]', '[CO_STATE]', '[CO_ZIP]', '[CO_LOGO]', '[CO_PHONE]', '[CO_LOGO_URL]', '[CO_FACEBOOK_URL]', '[CO_TWITTER_URL]', '[CO_PINTEREST_URL]', '[CO_GOOGLE_URL]', '[CO_LINKEDIN_URL]', '[CO_INSTAGRAM_URL]'); |
|
| 41 | 41 | $this->_specific_shortcode_excludes['from'] = array_merge($this->_specific_shortcode_excludes['from'], $add_excludes); |
| 42 | - $this->_specific_shortcode_excludes['content'] = array_merge( $this->_specific_shortcode_excludes['content'], array('[DISPLAY_PDF_URL]', '[DISPLAY_PDF_BUTTON]') ); |
|
| 42 | + $this->_specific_shortcode_excludes['content'] = array_merge($this->_specific_shortcode_excludes['content'], array('[DISPLAY_PDF_URL]', '[DISPLAY_PDF_BUTTON]')); |
|
| 43 | 43 | } |
| 44 | 44 | } |
@@ -274,7 +274,7 @@ discard block |
||
| 274 | 274 | && isset($this->_extra_data['data']) |
| 275 | 275 | && $this->_extra_data['data'] instanceof EE_Messages_Addressee ? $this->_extra_data['data']->payment |
| 276 | 276 | : $payment; |
| 277 | - if (! $transaction instanceof EE_Transaction) { |
|
| 277 | + if ( ! $transaction instanceof EE_Transaction) { |
|
| 278 | 278 | return ''; |
| 279 | 279 | } |
| 280 | 280 | switch ($shortcode) { |
@@ -289,16 +289,16 @@ discard block |
||
| 289 | 289 | break; |
| 290 | 290 | case '[INVOICE_LINK]': |
| 291 | 291 | $invoice_url = $transaction->invoice_url(); |
| 292 | - $invoice_url = empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com': $invoice_url; |
|
| 292 | + $invoice_url = empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com' : $invoice_url; |
|
| 293 | 293 | return sprintf( |
| 294 | 294 | esc_html__('%sClick here for Invoice%s', 'event_espresso'), |
| 295 | - '<a href="' . $invoice_url . '">', |
|
| 295 | + '<a href="'.$invoice_url.'">', |
|
| 296 | 296 | '</a>' |
| 297 | 297 | ); |
| 298 | 298 | break; |
| 299 | 299 | case '[INVOICE_URL]': |
| 300 | 300 | $invoice_url = $transaction->invoice_url(); |
| 301 | - return empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com': $invoice_url; |
|
| 301 | + return empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com' : $invoice_url; |
|
| 302 | 302 | break; |
| 303 | 303 | case '[INVOICE_LOGO_URL]': |
| 304 | 304 | return $this->_get_invoice_logo(); |
@@ -320,7 +320,7 @@ discard block |
||
| 320 | 320 | break; |
| 321 | 321 | case '[TOTAL_COST]': |
| 322 | 322 | $total = $transaction->total(); |
| 323 | - return ! empty($total) ? EEH_Template::format_currency($total): ''; |
|
| 323 | + return ! empty($total) ? EEH_Template::format_currency($total) : ''; |
|
| 324 | 324 | break; |
| 325 | 325 | case '[PAYMENT_STATUS]': |
| 326 | 326 | $status = $transaction->pretty_status(); |
@@ -366,7 +366,7 @@ discard block |
||
| 366 | 366 | return $this->_data->total_ticket_count; |
| 367 | 367 | break; |
| 368 | 368 | case '[TRANSACTION_ADMIN_URL]': |
| 369 | - require_once EE_CORE . 'admin/EE_Admin_Page.core.php'; |
|
| 369 | + require_once EE_CORE.'admin/EE_Admin_Page.core.php'; |
|
| 370 | 370 | $query_args = array( |
| 371 | 371 | 'page' => 'espresso_transactions', |
| 372 | 372 | 'action' => 'view_transaction', |
@@ -378,7 +378,7 @@ discard block |
||
| 378 | 378 | case '[RECEIPT_URL]': |
| 379 | 379 | //get primary_registration |
| 380 | 380 | $reg = $this->_data->primary_reg_obj; |
| 381 | - if (! $reg instanceof EE_Registration) { |
|
| 381 | + if ( ! $reg instanceof EE_Registration) { |
|
| 382 | 382 | return ''; |
| 383 | 383 | } |
| 384 | 384 | return $reg->receipt_url(); |
@@ -462,7 +462,7 @@ discard block |
||
| 462 | 462 | */ |
| 463 | 463 | private function _get_payment_gateway($transaction) |
| 464 | 464 | { |
| 465 | - if ($transaction instanceof EE_Transaction){ |
|
| 465 | + if ($transaction instanceof EE_Transaction) { |
|
| 466 | 466 | $pm = $transaction->payment_method(); |
| 467 | 467 | } else { |
| 468 | 468 | $pm = null; |
@@ -497,7 +497,7 @@ discard block |
||
| 497 | 497 | if (empty($invoice_logo_url)) { |
| 498 | 498 | return ''; |
| 499 | 499 | } |
| 500 | - if (! $img_tags) { |
|
| 500 | + if ( ! $img_tags) { |
|
| 501 | 501 | return $invoice_logo_url; |
| 502 | 502 | } |
| 503 | 503 | //image tags have been requested. |
@@ -508,7 +508,7 @@ discard block |
||
| 508 | 508 | } else { |
| 509 | 509 | $image_width = $image_size[0]; |
| 510 | 510 | } |
| 511 | - return '<img class="logo screen" src="' . $invoice_logo_url . '" width="' . $image_width . '" alt="logo" />'; |
|
| 511 | + return '<img class="logo screen" src="'.$invoice_logo_url.'" width="'.$image_width.'" alt="logo" />'; |
|
| 512 | 512 | } |
| 513 | 513 | |
| 514 | 514 | |
@@ -545,7 +545,7 @@ discard block |
||
| 545 | 545 | */ |
| 546 | 546 | private function _get_invoice_payment_method() |
| 547 | 547 | { |
| 548 | - if (! $this->_invoice_pm instanceof EE_Payment_Method) { |
|
| 548 | + if ( ! $this->_invoice_pm instanceof EE_Payment_Method) { |
|
| 549 | 549 | $transaction = $this->_data->txn instanceof EE_Transaction ? $this->_data->txn : null; |
| 550 | 550 | $transaction = ! $transaction instanceof EE_Transaction |
| 551 | 551 | && is_array($this->_extra_data) |
@@ -613,7 +613,7 @@ discard block |
||
| 613 | 613 | $attrs = $this->_get_shortcode_attrs($shortcode); |
| 614 | 614 | //prefix? |
| 615 | 615 | $prefix = isset($attrs['prefix']) ? $attrs['prefix'] : esc_html__('VAT/Tax Number: ', 'event_espresso'); |
| 616 | - return $prefix . $payee_tax_number; |
|
| 616 | + return $prefix.$payee_tax_number; |
|
| 617 | 617 | } |
| 618 | 618 | |
| 619 | 619 | |
@@ -637,16 +637,16 @@ discard block |
||
| 637 | 637 | } |
| 638 | 638 | if (empty($payee_address)) { |
| 639 | 639 | $organization = EE_Registry::instance()->CFG->organization; |
| 640 | - $payee_address = $organization->get_pretty('address_1') . '<br>'; |
|
| 640 | + $payee_address = $organization->get_pretty('address_1').'<br>'; |
|
| 641 | 641 | $payee_address .= ! empty($organization->address_2) |
| 642 | - ? $organization->get_pretty('address_2') . '<br>' |
|
| 642 | + ? $organization->get_pretty('address_2').'<br>' |
|
| 643 | 643 | : ''; |
| 644 | - $payee_address .= $organization->get_pretty('city') . '<br>'; |
|
| 644 | + $payee_address .= $organization->get_pretty('city').'<br>'; |
|
| 645 | 645 | //state |
| 646 | 646 | $state = EE_Registry::instance()->load_model('State')->get_one_by_ID($organization->STA_ID); |
| 647 | 647 | $payee_address .= $state instanceof EE_State ? $state->name() : ''; |
| 648 | 648 | //Country |
| 649 | - $payee_address .= ! empty($organization->CNT_ISO) ? ', ' . $organization->CNT_ISO . '<br>' : ''; |
|
| 649 | + $payee_address .= ! empty($organization->CNT_ISO) ? ', '.$organization->CNT_ISO.'<br>' : ''; |
|
| 650 | 650 | $payee_address .= ! empty($organization->zip) ? $organization->zip : ''; |
| 651 | 651 | } |
| 652 | 652 | return $payee_address; |
@@ -682,7 +682,7 @@ discard block |
||
| 682 | 682 | { |
| 683 | 683 | $reg = $this->_data->primary_reg_obj; |
| 684 | 684 | $message_type = isset($this->_extra_data['message_type']) ? $this->_extra_data['message_type'] : ''; |
| 685 | - if (! $reg instanceof EE_Registration || empty($message_type)) { |
|
| 685 | + if ( ! $reg instanceof EE_Registration || empty($message_type)) { |
|
| 686 | 686 | return ''; |
| 687 | 687 | } |
| 688 | 688 | $switch_to_invoice = ! $message_type instanceof EE_Invoice_message_type ? true : false; |
@@ -690,13 +690,13 @@ discard block |
||
| 690 | 690 | ? esc_html__('View Invoice', 'event_espresso') : esc_html__('Switch to Invoice', 'event_espresso'); |
| 691 | 691 | $switch_to_label = ! $switch_to_invoice ? esc_html__('Switch to Receipt', 'event_espresso') : $switch_to_label; |
| 692 | 692 | $switch_to_url = $switch_to_invoice ? $reg->invoice_url() : $reg->receipt_url(); |
| 693 | - if (! $button) { |
|
| 693 | + if ( ! $button) { |
|
| 694 | 694 | return $switch_to_url; |
| 695 | 695 | } |
| 696 | - if (! empty($switch_to_url)) { |
|
| 696 | + if ( ! empty($switch_to_url)) { |
|
| 697 | 697 | return ' |
| 698 | - <form method="post" action="' . $switch_to_url . '" > |
|
| 699 | - <input class="print_button" type="submit" value="' . $switch_to_label . '" /> |
|
| 698 | + <form method="post" action="' . $switch_to_url.'" > |
|
| 699 | + <input class="print_button" type="submit" value="' . $switch_to_label.'" /> |
|
| 700 | 700 | </form> |
| 701 | 701 | '; |
| 702 | 702 | } |
@@ -714,7 +714,7 @@ discard block |
||
| 714 | 714 | private function _get_subtotal($tax = false) |
| 715 | 715 | { |
| 716 | 716 | $grand_total = isset($this->_data->grand_total_line_item) ? $this->_data->grand_total_line_item : null; |
| 717 | - if (! $grand_total instanceof EE_Line_Item) { |
|
| 717 | + if ( ! $grand_total instanceof EE_Line_Item) { |
|
| 718 | 718 | return 0; |
| 719 | 719 | } |
| 720 | 720 | return $tax ? $grand_total->get_total_tax() : $grand_total->get_items_total(); |
@@ -741,11 +741,11 @@ discard block |
||
| 741 | 741 | $class = isset($attrs['class']) ? $attrs['class'] : 'callout'; |
| 742 | 742 | $custom_text = isset($attrs['custom_text']) ? $attrs['custom_text'] : 'You can %smake a payment here »%s.'; |
| 743 | 743 | $container_tag = isset($attrs['container_tag']) ? $attrs['container_tag'] : 'p'; |
| 744 | - $opening_tag = ! empty($container_tag) ? '<' . $container_tag : ''; |
|
| 745 | - $opening_tag .= ! empty($opening_tag) && ! empty($class) ? ' class="' . $class . '"' : $opening_tag; |
|
| 744 | + $opening_tag = ! empty($container_tag) ? '<'.$container_tag : ''; |
|
| 745 | + $opening_tag .= ! empty($opening_tag) && ! empty($class) ? ' class="'.$class.'"' : $opening_tag; |
|
| 746 | 746 | $opening_tag .= ! empty($opening_tag) ? '>' : $opening_tag; |
| 747 | - $closing_tag = ! empty($container_tag) ? '</' . $container_tag . '>' : ''; |
|
| 748 | - $content = $opening_tag . sprintf($custom_text, '<a href="[PAYMENT_URL]">', '</a>') . $closing_tag; |
|
| 747 | + $closing_tag = ! empty($container_tag) ? '</'.$container_tag.'>' : ''; |
|
| 748 | + $content = $opening_tag.sprintf($custom_text, '<a href="[PAYMENT_URL]">', '</a>').$closing_tag; |
|
| 749 | 749 | //we need to re run this string through the parser to catch any shortcodes that are in it. |
| 750 | 750 | $owing_content = $this->_shortcode_helper->parse_message_template( |
| 751 | 751 | $content, |
@@ -779,7 +779,7 @@ discard block |
||
| 779 | 779 | } |
| 780 | 780 | $attrs = $this->_get_shortcode_attrs($shortcode); |
| 781 | 781 | $format = isset($attrs['format']) ? $attrs['format'] : get_option('date_format'); |
| 782 | - $days_until_due = isset($attrs['days_until_due']) ? (int)$attrs['days_until_due'] : 30; |
|
| 782 | + $days_until_due = isset($attrs['days_until_due']) ? (int) $attrs['days_until_due'] : 30; |
|
| 783 | 783 | $prefix_text = isset($attrs['prefix_text']) ? $attrs['prefix_text'] |
| 784 | 784 | : esc_html__('Payment in full due by: ', 'event_espresso'); |
| 785 | 785 | $transaction_created = $transaction->get_DateTime_object('TXN_timestamp'); |
@@ -787,7 +787,7 @@ discard block |
||
| 787 | 787 | try { |
| 788 | 788 | if ($transaction_created instanceof DateTime) { |
| 789 | 789 | $date_due = $transaction_created->add( |
| 790 | - new DateInterval('P' . $days_until_due . 'D') |
|
| 790 | + new DateInterval('P'.$days_until_due.'D') |
|
| 791 | 791 | )->format($format); |
| 792 | 792 | } else { |
| 793 | 793 | throw new Exception(); |
@@ -799,7 +799,7 @@ discard block |
||
| 799 | 799 | 'event_espresso' |
| 800 | 800 | ); |
| 801 | 801 | } |
| 802 | - return $prefix_text . $date_due; |
|
| 802 | + return $prefix_text.$date_due; |
|
| 803 | 803 | } |
| 804 | 804 | |
| 805 | 805 | } |
@@ -21,785 +21,785 @@ |
||
| 21 | 21 | class EE_Transaction_Shortcodes extends EE_Shortcodes |
| 22 | 22 | { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @var EE_Payment_Method $_invoice_pm the invoice payment method for use in invoices etc |
|
| 26 | - */ |
|
| 27 | - protected $_invoice_pm; |
|
| 28 | - |
|
| 29 | - |
|
| 30 | - |
|
| 31 | - protected function _init_props() |
|
| 32 | - { |
|
| 33 | - $this->label = esc_html__('Transaction Shortcodes', 'event_espresso'); |
|
| 34 | - $this->description = esc_html__('All shortcodes specific to transaction related data', 'event_espresso'); |
|
| 35 | - $this->_shortcodes = array( |
|
| 36 | - '[TXN_ID]' => esc_html__('The transaction id for the purchase.', 'event_espresso'), |
|
| 37 | - '[PAYMENT_URL]' => esc_html__( |
|
| 38 | - 'This is a link to make a payment for the event', |
|
| 39 | - 'event_espresso' |
|
| 40 | - ), |
|
| 41 | - '[PAYMENT_LINK_IF_NEEDED_*]' => esc_html__( |
|
| 42 | - 'This is a special dynamic shortcode that allows one to insert a payment link conditional on there being amount owing on the transaction. Three params are available on this shortcode:', |
|
| 43 | - 'event_espresso' |
|
| 44 | - ) |
|
| 45 | - . '<ul>' |
|
| 46 | - . '<li>' |
|
| 47 | - . sprintf( |
|
| 48 | - esc_html__( |
|
| 49 | - '%sclass:%s This can be used to indicate css class is given to the containing css element (default is "callout").', |
|
| 50 | - 'event_espresso' |
|
| 51 | - ), |
|
| 52 | - '<strong>', |
|
| 53 | - '</strong>' |
|
| 54 | - ) |
|
| 55 | - . '</li>' |
|
| 56 | - . '<li>' |
|
| 57 | - . sprintf( |
|
| 58 | - esc_html__( |
|
| 59 | - '%scustom_text:%s This should be a sprintf format text string (with %%s for where the hyperlink tags go) that is used for the generated link text (The default is "You can %%smake a payment here »%%s.)', |
|
| 60 | - 'event_espresso' |
|
| 61 | - ), |
|
| 62 | - '<strong>', |
|
| 63 | - '</strong>' |
|
| 64 | - ) |
|
| 65 | - . '</li>' |
|
| 66 | - . '<li>' |
|
| 67 | - . sprintf( |
|
| 68 | - esc_html__( |
|
| 69 | - '%scontainer_tag:%s Use this to indicate what container tag you want surrounding the payment link (default is "p").', |
|
| 70 | - 'event_espresso' |
|
| 71 | - ), |
|
| 72 | - '<strong>', |
|
| 73 | - '</strong>' |
|
| 74 | - ) |
|
| 75 | - . '</li>' |
|
| 76 | - . '</ul>', |
|
| 77 | - '[PAYMENT_DUE_DATE_*]' => esc_html__( |
|
| 78 | - 'This is a special dynamic shortcode that allows one to output a payment due date. It will only result in a date shown if there is money owing. Three parameters are available on this shortcode:', |
|
| 79 | - 'event_espresso' |
|
| 80 | - ) |
|
| 81 | - . '<ul>' |
|
| 82 | - . '<li>' |
|
| 83 | - . sprintf( |
|
| 84 | - esc_html__( |
|
| 85 | - '%sformat:%s This is used to indicate what format the date is in. Default is whatever is set as date formats for your website.', |
|
| 86 | - 'event_espresso' |
|
| 87 | - ), |
|
| 88 | - '<strong>', |
|
| 89 | - '</strong>' |
|
| 90 | - ) |
|
| 91 | - . '</li>' |
|
| 92 | - . '<li>' |
|
| 93 | - . sprintf( |
|
| 94 | - esc_html__( |
|
| 95 | - '%sdays_until_due:%s This is the number of days form the transaction creation date that the payment is due. Defaults to 30.', |
|
| 96 | - 'event_espresso' |
|
| 97 | - ), |
|
| 98 | - '<strong>', |
|
| 99 | - '</strong>' |
|
| 100 | - ) |
|
| 101 | - . '</li>' |
|
| 102 | - . '<li>' |
|
| 103 | - . sprintf( |
|
| 104 | - esc_html__( |
|
| 105 | - '%sprefix_text:%s You can use this to indicate what text will prefix the date string. Defaults to "Payment in full due by:"', |
|
| 106 | - 'event_espresso' |
|
| 107 | - ), |
|
| 108 | - '<strong>', |
|
| 109 | - '</strong>' |
|
| 110 | - ) |
|
| 111 | - . '</li>', |
|
| 112 | - '[INVOICE_LINK]' => esc_html__( |
|
| 113 | - 'This is a full html link to the invoice', |
|
| 114 | - 'event_espresso' |
|
| 115 | - ), |
|
| 116 | - '[INVOICE_URL]' => esc_html__( |
|
| 117 | - 'This is just the url for the invoice', |
|
| 118 | - 'event_espresso' |
|
| 119 | - ), |
|
| 120 | - '[INVOICE_LOGO_URL]' => esc_html__( |
|
| 121 | - 'This returns the url for the logo uploaded via the invoice settings page.', |
|
| 122 | - 'event_espresso' |
|
| 123 | - ), |
|
| 124 | - '[INVOICE_LOGO]' => esc_html__( |
|
| 125 | - 'This returns the logo uploaded via the invoice settings page wrapped in img_tags and with a "logo screen" classes. The image size is also set in the img tags automatically to match the uploaded logo.', |
|
| 126 | - 'event_espresso' |
|
| 127 | - ), |
|
| 128 | - '[INVOICE_PAYEE_NAME]' => esc_html__( |
|
| 129 | - 'This will parse to either: the value of the "Company Name" field in the invoice payment method settings; if that is blank, then the value of the Company Name in the "Your Organization Settings", if that is blank then an empty string.', |
|
| 130 | - 'event_espresso' |
|
| 131 | - ), |
|
| 132 | - '[INVOICE_PAYEE_ADDRESS]' => esc_html__( |
|
| 133 | - 'This will parse to either: the value of the "Company Address" field in the invoice payment method settings; if that is blank, then the value of the Company Address in the "Your Organization Settings", if that is blank then an empty string.', |
|
| 134 | - 'event_espresso' |
|
| 135 | - ), |
|
| 136 | - '[INVOICE_PAYMENT_INSTRUCTIONS]' => esc_html__( |
|
| 137 | - 'This will parse to the value of the "Payment Instructions" field found on the Invoice payment methods settings page', |
|
| 138 | - 'event_espresso' |
|
| 139 | - ), |
|
| 140 | - '[INVOICE_PAYEE_EMAIL]' => esc_html__( |
|
| 141 | - 'This will parse to either: the value of the "Company Email" field in the invoice payment method settings; if that is blank, then the value of the Company Email in the "Your Organization Settings", if that is blank then an empty string.', |
|
| 142 | - 'event_espresso' |
|
| 143 | - ), |
|
| 144 | - '[INVOICE_PAYEE_TAX_NUMBER_*]' => sprintf( |
|
| 145 | - esc_html__( |
|
| 146 | - 'This will parse to either: the value of the "Company Tax Number" field in the invoice payment method settings; if that is blank, then the value of the Company Tax Number in the "Your Organization Settings", if that is blank then an empty string. Note this is also a special dynamic shortcode. You can use the "prefix" parameter to indicate what text you want to use as a prefix before this tax number. It defaults to "VAT/Tax Number:". To change this prefix you do the following format for this shortcode: %1$s[INVOICE_PAYEE_TAX_NUMBER_* prefix="GST:"]%2$s and that will output: GST: 12345t56. If you have no tax number in your settings, then no prefix will be output either.', |
|
| 147 | - 'event_espresso' |
|
| 148 | - ), |
|
| 149 | - '<code>', |
|
| 150 | - '</code>' |
|
| 151 | - ), |
|
| 152 | - '[TOTAL_COST]' => esc_html__('The total cost for the transaction', 'event_espresso'), |
|
| 153 | - '[TXN_STATUS]' => esc_html__( |
|
| 154 | - 'The transaction status for the transaction.', |
|
| 155 | - 'event_espresso' |
|
| 156 | - ), |
|
| 157 | - '[TXN_STATUS_ID]' => esc_html__( |
|
| 158 | - 'The ID representing the transaction status as saved in the db. This tends to be useful for including with css classes for styling certain statuses differently from others.', |
|
| 159 | - 'event_espresso' |
|
| 160 | - ), |
|
| 161 | - '[PAYMENT_STATUS]' => esc_html__( |
|
| 162 | - 'The transaction status for the transaction. This parses to the same value as the [TXN_STATUS] shortcode and still remains here for legacy support.', |
|
| 163 | - 'event_espresso' |
|
| 164 | - ), |
|
| 165 | - '[PAYMENT_GATEWAY]' => esc_html__( |
|
| 166 | - 'The payment gateway used for the transaction', |
|
| 167 | - 'event_espresso' |
|
| 168 | - ), |
|
| 169 | - '[AMOUNT_PAID]' => esc_html__( |
|
| 170 | - 'The amount paid or refunded. This will only have a value if there was a payment or refund at the time of generating the message.', |
|
| 171 | - 'event_espresso' |
|
| 172 | - ), |
|
| 173 | - '[LAST_AMOUNT_PAID]' => esc_html__( |
|
| 174 | - 'This is the last payment or refund made on the transaction related to the message being generated.', |
|
| 175 | - 'event_espresso' |
|
| 176 | - ), |
|
| 177 | - '[TOTAL_AMOUNT_PAID]' => esc_html__( |
|
| 178 | - 'This parses to the total amount paid over all payments', |
|
| 179 | - 'event_espresso' |
|
| 180 | - ), |
|
| 181 | - '[TOTAL_OWING]' => esc_html__( |
|
| 182 | - 'The total owing on a transaction with no attributes.', |
|
| 183 | - 'event_espresso' |
|
| 184 | - ), |
|
| 185 | - '[TXN_SUBTOTAL]' => esc_html__('The subtotal for all txn line items.', 'event_espresso'), |
|
| 186 | - '[TXN_TAX_SUBTOTAL]' => esc_html__('The subtotal for all tax line items.', 'event_espresso'), |
|
| 187 | - '[OWING_STATUS_MESSAGE_*]' => esc_html__( |
|
| 188 | - 'A dynamic shortcode for adjusting how total owing gets shown. The acceptable attributes on the shortcode are:', |
|
| 189 | - 'event_espresso' |
|
| 190 | - ) |
|
| 191 | - . '<p></ul>' |
|
| 192 | - . '<li><strong>still_owing</strong>:' |
|
| 193 | - . esc_html__( |
|
| 194 | - 'If the transaction is not paid in full, then whatever is set for this attribute is shown (otherwise its just the amount owing). The default is:', |
|
| 195 | - 'event_espresso' |
|
| 196 | - ) |
|
| 197 | - . sprintf( |
|
| 198 | - esc_html__('%sPlease make a payment.%s', 'event_espresso'), |
|
| 199 | - '<a href="[PAYMENT_URL]" class="noPrint">', |
|
| 200 | - '</a>' |
|
| 201 | - ) |
|
| 202 | - . '</li>' |
|
| 203 | - . |
|
| 204 | - '<li><strong>none_owing</strong>:' |
|
| 205 | - . esc_html__( |
|
| 206 | - 'If the transaction is paid in full, then you can indicate how this gets displayed. Note, that it defaults to just be the total owing.', |
|
| 207 | - 'event_espresso' |
|
| 208 | - ) |
|
| 209 | - . '</li></ul></p>', |
|
| 210 | - '[TXN_TOTAL_TICKETS]' => esc_html__( |
|
| 211 | - 'The total number of all tickets purchased in a transaction', |
|
| 212 | - 'event_espresso' |
|
| 213 | - ), |
|
| 214 | - '[TKT_QTY_PURCHASED]' => sprintf( |
|
| 215 | - esc_html__( |
|
| 216 | - 'The total number of all tickets purchased in a transaction. %1$sNOTE: This shortcode is good to use in the "[TICKET_LIST]" field but has been deprecated from all other contexts in favor of the more explicit [TXN_TOTAL_TICKETS] shortcode.%2$s', |
|
| 217 | - 'event_espresso' |
|
| 218 | - ), |
|
| 219 | - '<strong>', |
|
| 220 | - '</strong>' |
|
| 221 | - ), |
|
| 222 | - '[TRANSACTION_ADMIN_URL]' => esc_html__( |
|
| 223 | - 'The url to the admin page for this transaction', |
|
| 224 | - 'event_espresso' |
|
| 225 | - ), |
|
| 226 | - '[RECEIPT_URL]' => esc_html__( |
|
| 227 | - 'This parses to the generated url for retrieving the receipt for the transaction', |
|
| 228 | - 'event_espresso' |
|
| 229 | - ), |
|
| 230 | - '[INVOICE_RECEIPT_SWITCHER_URL]' => esc_html__( |
|
| 231 | - 'This parses to the url that will switch to the receipt if an invoice is displayed, and switch to the invoice if receipt is displayed. If a message type OTHER than invoice or receipt is displayed then this will just return the url for the invoice. If the related message type is not active then will parse to an empty string.', |
|
| 232 | - 'event_espresso' |
|
| 233 | - ), |
|
| 234 | - '[INVOICE_RECEIPT_SWITCHER_BUTTON]' => sprintf( |
|
| 235 | - esc_html__( |
|
| 236 | - 'The same as %1$s%2$s except this returns the html for a button linked to the invoice or receipt.', |
|
| 237 | - 'event_espresso' |
|
| 238 | - ), |
|
| 239 | - '<code>[INVOICE_RECEIPT_SWITCHER_URL]', |
|
| 240 | - '</code>' |
|
| 241 | - ), |
|
| 242 | - '[LAST_PAYMENT_TRANSACTION_ID]' => esc_html__( |
|
| 243 | - 'This will output the value of the payment transaction id for the last payment made on the transaction. Note, if a specific payment was included for message generation, that will be used when parsing the shortcode.', |
|
| 244 | - 'event_espresso' |
|
| 245 | - ), |
|
| 246 | - ); |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - |
|
| 250 | - /** |
|
| 251 | - * @param string $shortcode the shortcode to be parsed. |
|
| 252 | - * @return string parsed shortcode |
|
| 253 | - * @throws EE_Error |
|
| 254 | - * @throws InvalidArgumentException |
|
| 255 | - * @throws ReflectionException |
|
| 256 | - * @throws InvalidDataTypeException |
|
| 257 | - * @throws InvalidInterfaceException |
|
| 258 | - */ |
|
| 259 | - protected function _parser($shortcode) |
|
| 260 | - { |
|
| 261 | - //attempt to get the transaction. Since this is potentially used in more fields, we may have to look in the |
|
| 262 | - // _extra_data for the transaction. |
|
| 263 | - $transaction = $this->_data->txn instanceof EE_Transaction ? $this->_data->txn : null; |
|
| 264 | - $transaction = ! $transaction instanceof EE_Transaction |
|
| 265 | - && is_array($this->_extra_data) |
|
| 266 | - && isset($this->_extra_data['data']) |
|
| 267 | - && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
| 268 | - ? $this->_extra_data['data']->txn |
|
| 269 | - : $transaction; |
|
| 270 | - //payment |
|
| 271 | - $payment = $this->_data->payment instanceof EE_Payment ? $this->_data->payment : null; |
|
| 272 | - $payment = ! $payment instanceof EE_Payment |
|
| 273 | - && is_array($this->_extra_data) |
|
| 274 | - && isset($this->_extra_data['data']) |
|
| 275 | - && $this->_extra_data['data'] instanceof EE_Messages_Addressee ? $this->_extra_data['data']->payment |
|
| 276 | - : $payment; |
|
| 277 | - if (! $transaction instanceof EE_Transaction) { |
|
| 278 | - return ''; |
|
| 279 | - } |
|
| 280 | - switch ($shortcode) { |
|
| 281 | - case '[TXN_ID]': |
|
| 282 | - return $transaction->ID(); |
|
| 283 | - break; |
|
| 284 | - case '[PAYMENT_URL]': |
|
| 285 | - $payment_url = $transaction->payment_overview_url(); |
|
| 286 | - return empty($payment_url) |
|
| 287 | - ? esc_html__('http://dummypaymenturlforpreview.com', 'event_espresso') |
|
| 288 | - : $payment_url; |
|
| 289 | - break; |
|
| 290 | - case '[INVOICE_LINK]': |
|
| 291 | - $invoice_url = $transaction->invoice_url(); |
|
| 292 | - $invoice_url = empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com': $invoice_url; |
|
| 293 | - return sprintf( |
|
| 294 | - esc_html__('%sClick here for Invoice%s', 'event_espresso'), |
|
| 295 | - '<a href="' . $invoice_url . '">', |
|
| 296 | - '</a>' |
|
| 297 | - ); |
|
| 298 | - break; |
|
| 299 | - case '[INVOICE_URL]': |
|
| 300 | - $invoice_url = $transaction->invoice_url(); |
|
| 301 | - return empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com': $invoice_url; |
|
| 302 | - break; |
|
| 303 | - case '[INVOICE_LOGO_URL]': |
|
| 304 | - return $this->_get_invoice_logo(); |
|
| 305 | - break; |
|
| 306 | - case '[INVOICE_LOGO]': |
|
| 307 | - return $this->_get_invoice_logo(true); |
|
| 308 | - break; |
|
| 309 | - case '[INVOICE_PAYEE_NAME]': |
|
| 310 | - return $this->_get_invoice_payee_name(); |
|
| 311 | - break; |
|
| 312 | - case '[INVOICE_PAYEE_ADDRESS]': |
|
| 313 | - return $this->_get_invoice_payee_address(); |
|
| 314 | - break; |
|
| 315 | - case '[INVOICE_PAYMENT_INSTRUCTIONS]': |
|
| 316 | - return $this->_get_invoice_payment_instructions(); |
|
| 317 | - break; |
|
| 318 | - case '[INVOICE_PAYEE_EMAIL]': |
|
| 319 | - return $this->_get_invoice_payee_email(); |
|
| 320 | - break; |
|
| 321 | - case '[TOTAL_COST]': |
|
| 322 | - $total = $transaction->total(); |
|
| 323 | - return ! empty($total) ? EEH_Template::format_currency($total): ''; |
|
| 324 | - break; |
|
| 325 | - case '[PAYMENT_STATUS]': |
|
| 326 | - $status = $transaction->pretty_status(); |
|
| 327 | - return ! empty($status) ? $status : esc_html__('Unknown', 'event_espresso'); |
|
| 328 | - break; /**/ |
|
| 329 | - // note the [payment_status] shortcode is kind of misleading because payment status might be different |
|
| 330 | - // from txn status so I'm adding this here for clarity. |
|
| 331 | - case '[TXN_STATUS]': |
|
| 332 | - $status = $transaction->pretty_status(); |
|
| 333 | - return ! empty($status) ? $status : esc_html__('Unknown', 'event_espresso'); |
|
| 334 | - break; |
|
| 335 | - case '[TXN_STATUS_ID]': |
|
| 336 | - return $transaction->status_ID(); |
|
| 337 | - break; |
|
| 338 | - case '[PAYMENT_GATEWAY]': |
|
| 339 | - return $this->_get_payment_gateway($transaction); |
|
| 340 | - break; |
|
| 341 | - case '[AMOUNT_PAID]': |
|
| 342 | - return $payment instanceof EE_Payment |
|
| 343 | - ? EEH_Template::format_currency($payment->amount()) |
|
| 344 | - : EEH_Template::format_currency(0); |
|
| 345 | - break; |
|
| 346 | - case '[LAST_AMOUNT_PAID]': |
|
| 347 | - $last_payment = $transaction->last_payment(); |
|
| 348 | - return $last_payment instanceof EE_Payment |
|
| 349 | - ? EEH_Template::format_currency($last_payment->amount()) |
|
| 350 | - : EEH_Template::format_currency(0); |
|
| 351 | - case '[TOTAL_AMOUNT_PAID]': |
|
| 352 | - return EEH_Template::format_currency($transaction->paid()); |
|
| 353 | - break; |
|
| 354 | - case '[TOTAL_OWING]': |
|
| 355 | - $total_owing = $transaction->remaining(); |
|
| 356 | - return EEH_Template::format_currency($total_owing); |
|
| 357 | - break; |
|
| 358 | - case '[TXN_SUBTOTAL]': |
|
| 359 | - return EEH_Template::format_currency($this->_get_subtotal()); |
|
| 360 | - break; |
|
| 361 | - case '[TXN_TAX_SUBTOTAL]': |
|
| 362 | - return EEH_Template::format_currency($this->_get_subtotal(true)); |
|
| 363 | - break; |
|
| 364 | - case '[TKT_QTY_PURCHASED]': |
|
| 365 | - case '[TXN_TOTAL_TICKETS]': |
|
| 366 | - return $this->_data->total_ticket_count; |
|
| 367 | - break; |
|
| 368 | - case '[TRANSACTION_ADMIN_URL]': |
|
| 369 | - require_once EE_CORE . 'admin/EE_Admin_Page.core.php'; |
|
| 370 | - $query_args = array( |
|
| 371 | - 'page' => 'espresso_transactions', |
|
| 372 | - 'action' => 'view_transaction', |
|
| 373 | - 'TXN_ID' => $transaction->ID(), |
|
| 374 | - ); |
|
| 375 | - $url = EE_Admin_Page::add_query_args_and_nonce($query_args, admin_url('admin.php')); |
|
| 376 | - return $url; |
|
| 377 | - break; |
|
| 378 | - case '[RECEIPT_URL]': |
|
| 379 | - //get primary_registration |
|
| 380 | - $reg = $this->_data->primary_reg_obj; |
|
| 381 | - if (! $reg instanceof EE_Registration) { |
|
| 382 | - return ''; |
|
| 383 | - } |
|
| 384 | - return $reg->receipt_url(); |
|
| 385 | - break; |
|
| 386 | - case '[INVOICE_RECEIPT_SWITCHER_URL]': |
|
| 387 | - return $this->_get_invoice_receipt_switcher(false); |
|
| 388 | - break; |
|
| 389 | - case '[INVOICE_RECEIPT_SWITCHER_BUTTON]': |
|
| 390 | - return $this->_get_invoice_receipt_switcher(); |
|
| 391 | - break; |
|
| 392 | - case '[LAST_PAYMENT_TRANSACTION_ID]': |
|
| 393 | - $id = ''; |
|
| 394 | - $payment = $payment instanceof EE_Payment && $payment->ID() !== 0 |
|
| 395 | - ? $payment |
|
| 396 | - : $transaction->last_payment(); |
|
| 397 | - if ($payment instanceof EE_Payment) { |
|
| 398 | - $id = $payment->txn_id_chq_nmbr(); |
|
| 399 | - } |
|
| 400 | - return $id; |
|
| 401 | - break; |
|
| 402 | - } |
|
| 403 | - if (strpos($shortcode, '[OWING_STATUS_MESSAGE_*') !== false) { |
|
| 404 | - return $this->_get_custom_total_owing($shortcode); |
|
| 405 | - } |
|
| 406 | - if (strpos($shortcode, '[INVOICE_PAYEE_TAX_NUMBER_*') !== false) { |
|
| 407 | - return $this->_get_invoice_payee_tax_number($shortcode); |
|
| 408 | - } |
|
| 409 | - if (strpos($shortcode, '[PAYMENT_LINK_IF_NEEDED_*') !== false) { |
|
| 410 | - return $this->_get_payment_link_if_needed($shortcode); |
|
| 411 | - } |
|
| 412 | - if (strpos($shortcode, '[PAYMENT_DUE_DATE_*') !== false) { |
|
| 413 | - return $this->_get_payment_due_date($shortcode, $transaction); |
|
| 414 | - } |
|
| 415 | - return ''; |
|
| 416 | - } |
|
| 417 | - |
|
| 418 | - |
|
| 419 | - /** |
|
| 420 | - * parser for the [OWING_STATUS_MESSAGE_*] attribute type shortcode |
|
| 421 | - * |
|
| 422 | - * @since 4.5.0 |
|
| 423 | - * @param string $shortcode the incoming shortcode |
|
| 424 | - * @return string parsed. |
|
| 425 | - * @throws EE_Error |
|
| 426 | - */ |
|
| 427 | - private function _get_custom_total_owing($shortcode) |
|
| 428 | - { |
|
| 429 | - $valid_shortcodes = array('transaction'); |
|
| 430 | - $attrs = $this->_get_shortcode_attrs($shortcode); |
|
| 431 | - //ensure default is set. |
|
| 432 | - $addressee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
|
| 433 | - $total_owing = $addressee instanceof EE_Messages_Addressee && $addressee->txn instanceof EE_Transaction |
|
| 434 | - ? $addressee->txn->remaining() : 0; |
|
| 435 | - if ($total_owing > 0) { |
|
| 436 | - $owing_content = ! empty($attrs['still_owing']) |
|
| 437 | - ? $attrs['still_owing'] |
|
| 438 | - : sprintf( |
|
| 439 | - esc_html__('%sPlease make a payment.%s', 'event_espresso'), |
|
| 440 | - '<a href="[PAYMENT_URL]" class="noPrint">', |
|
| 441 | - '</a>' |
|
| 442 | - ); |
|
| 443 | - $owing_content = $this->_shortcode_helper->parse_message_template( |
|
| 444 | - $owing_content, |
|
| 445 | - $addressee, |
|
| 446 | - $valid_shortcodes, |
|
| 447 | - $this->_message_type, |
|
| 448 | - $this->_messenger, |
|
| 449 | - $this->_message |
|
| 450 | - ); |
|
| 451 | - } else { |
|
| 452 | - $owing_content = ! empty($attrs['none_owing']) ? $attrs['none_owing'] : ''; |
|
| 453 | - } |
|
| 454 | - return $owing_content; |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - |
|
| 458 | - /** |
|
| 459 | - * @param EE_Transaction $transaction |
|
| 460 | - * @return string |
|
| 461 | - * @throws EE_Error |
|
| 462 | - */ |
|
| 463 | - private function _get_payment_gateway($transaction) |
|
| 464 | - { |
|
| 465 | - if ($transaction instanceof EE_Transaction){ |
|
| 466 | - $pm = $transaction->payment_method(); |
|
| 467 | - } else { |
|
| 468 | - $pm = null; |
|
| 469 | - } |
|
| 470 | - return $pm instanceof EE_Payment_Method ? $pm->name() : ''; |
|
| 471 | - } |
|
| 472 | - |
|
| 473 | - |
|
| 474 | - /** |
|
| 475 | - * This retrieves a logo to be used for the invoice from whatever is set on the invoice logo settings page. If its |
|
| 476 | - * not present then the organization logo is used if its found (set on the organization settings page). |
|
| 477 | - * |
|
| 478 | - * @since 4.5.0 |
|
| 479 | - * @param bool $img_tags TRUE means to return with the img tag wrappers. False just returns the url to the image. |
|
| 480 | - * @return string url or html |
|
| 481 | - * @throws EE_Error |
|
| 482 | - * @throws InvalidArgumentException |
|
| 483 | - * @throws InvalidDataTypeException |
|
| 484 | - * @throws InvalidInterfaceException |
|
| 485 | - */ |
|
| 486 | - private function _get_invoice_logo($img_tags = false) |
|
| 487 | - { |
|
| 488 | - $invoice_logo_url = ''; |
|
| 489 | - //try to get the invoice payment method's logo for this transaction image first |
|
| 490 | - $pm = $this->_get_invoice_payment_method(); |
|
| 491 | - if ($pm instanceof EE_Payment_Method) { |
|
| 492 | - $invoice_logo_url = $pm->get_extra_meta('pdf_logo_image', true); |
|
| 493 | - } |
|
| 494 | - if (empty($invoice_logo_url)) { |
|
| 495 | - $invoice_logo_url = EE_Registry::instance()->CFG->organization->logo_url; |
|
| 496 | - } |
|
| 497 | - if (empty($invoice_logo_url)) { |
|
| 498 | - return ''; |
|
| 499 | - } |
|
| 500 | - if (! $img_tags) { |
|
| 501 | - return $invoice_logo_url; |
|
| 502 | - } |
|
| 503 | - //image tags have been requested. |
|
| 504 | - $image_size = getimagesize($invoice_logo_url); |
|
| 505 | - //if image is wider than 300px, set the width to 300 |
|
| 506 | - if ($image_size[0] > 300) { |
|
| 507 | - $image_width = 300; |
|
| 508 | - } else { |
|
| 509 | - $image_width = $image_size[0]; |
|
| 510 | - } |
|
| 511 | - return '<img class="logo screen" src="' . $invoice_logo_url . '" width="' . $image_width . '" alt="logo" />'; |
|
| 512 | - } |
|
| 513 | - |
|
| 514 | - |
|
| 515 | - /** |
|
| 516 | - * Used to retrieve the appropriate content for the invoice payee name shortcode |
|
| 517 | - * |
|
| 518 | - * @since 4.5.0 |
|
| 519 | - * @return string |
|
| 520 | - * @throws EE_Error |
|
| 521 | - * @throws InvalidArgumentException |
|
| 522 | - * @throws InvalidDataTypeException |
|
| 523 | - * @throws InvalidInterfaceException |
|
| 524 | - */ |
|
| 525 | - private function _get_invoice_payee_name() |
|
| 526 | - { |
|
| 527 | - $payee_name = null; |
|
| 528 | - $pm = $this->_get_invoice_payment_method(); |
|
| 529 | - if ($pm instanceof EE_Payment_Method) { |
|
| 530 | - $payee_name = $pm->get_extra_meta('pdf_payee_name', true); |
|
| 531 | - } |
|
| 532 | - $payee_name = empty($payee_name) ? EE_Registry::instance()->CFG->organization->get_pretty('name') : $payee_name; |
|
| 533 | - return $payee_name; |
|
| 534 | - } |
|
| 535 | - |
|
| 536 | - |
|
| 537 | - /** |
|
| 538 | - * gets the default invoice payment method, but has a filter so it can be overridden |
|
| 539 | - * |
|
| 540 | - * @return EE_Payment_Method|null |
|
| 541 | - * @throws EE_Error |
|
| 542 | - * @throws InvalidArgumentException |
|
| 543 | - * @throws InvalidDataTypeException |
|
| 544 | - * @throws InvalidInterfaceException |
|
| 545 | - */ |
|
| 546 | - private function _get_invoice_payment_method() |
|
| 547 | - { |
|
| 548 | - if (! $this->_invoice_pm instanceof EE_Payment_Method) { |
|
| 549 | - $transaction = $this->_data->txn instanceof EE_Transaction ? $this->_data->txn : null; |
|
| 550 | - $transaction = ! $transaction instanceof EE_Transaction |
|
| 551 | - && is_array($this->_extra_data) |
|
| 552 | - && isset($this->_extra_data['data']) |
|
| 553 | - && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
| 554 | - ? $this->_extra_data['data']->txn : $transaction; |
|
| 555 | - //get the invoice payment method, and remember it for the next call too |
|
| 556 | - $this->_invoice_pm = apply_filters( |
|
| 557 | - 'FHEE__EE_Transaction_Shortcodes__get_payment_method__default', |
|
| 558 | - EEM_Payment_Method::instance()->get_one_of_type('Invoice'), |
|
| 559 | - $transaction |
|
| 560 | - ); |
|
| 561 | - } |
|
| 562 | - return $this->_invoice_pm; |
|
| 563 | - } |
|
| 564 | - |
|
| 565 | - |
|
| 566 | - /** |
|
| 567 | - * Used to retrieve the appropriate content for the invoice payee email shortcode |
|
| 568 | - * |
|
| 569 | - * @since 4.5.0 |
|
| 570 | - * @return string |
|
| 571 | - * @throws EE_Error |
|
| 572 | - * @throws InvalidArgumentException |
|
| 573 | - * @throws InvalidDataTypeException |
|
| 574 | - * @throws InvalidInterfaceException |
|
| 575 | - */ |
|
| 576 | - private function _get_invoice_payee_email() |
|
| 577 | - { |
|
| 578 | - $payee_email = null; |
|
| 579 | - $pm = $this->_get_invoice_payment_method(); |
|
| 580 | - if ($pm instanceof EE_Payment_Method) { |
|
| 581 | - $payee_email = $pm->get_extra_meta('pdf_payee_email', true); |
|
| 582 | - } |
|
| 583 | - $payee_email = empty($payee_email) ? EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 584 | - : $payee_email; |
|
| 585 | - return $payee_email; |
|
| 586 | - } |
|
| 587 | - |
|
| 588 | - |
|
| 589 | - /** |
|
| 590 | - * Used to retrieve the appropriate content for the invoice payee tax number shortcode |
|
| 591 | - * |
|
| 592 | - * @since 4.5.0 |
|
| 593 | - * @param string $shortcode |
|
| 594 | - * @return string |
|
| 595 | - * @throws EE_Error |
|
| 596 | - * @throws InvalidArgumentException |
|
| 597 | - * @throws InvalidDataTypeException |
|
| 598 | - * @throws InvalidInterfaceException |
|
| 599 | - */ |
|
| 600 | - private function _get_invoice_payee_tax_number($shortcode) |
|
| 601 | - { |
|
| 602 | - $payee_tax_number = null; |
|
| 603 | - $pm = $this->_get_invoice_payment_method(); |
|
| 604 | - if ($pm instanceof EE_Payment_Method) { |
|
| 605 | - $payee_tax_number = $pm->get_extra_meta('pdf_payee_tax_number', true); |
|
| 606 | - } |
|
| 607 | - $payee_tax_number = empty($payee_tax_number) ? EE_Registry::instance()->CFG->organization->vat |
|
| 608 | - : $payee_tax_number; |
|
| 609 | - if (empty($payee_tax_number)) { |
|
| 610 | - return ''; |
|
| 611 | - } |
|
| 612 | - //any attributes? |
|
| 613 | - $attrs = $this->_get_shortcode_attrs($shortcode); |
|
| 614 | - //prefix? |
|
| 615 | - $prefix = isset($attrs['prefix']) ? $attrs['prefix'] : esc_html__('VAT/Tax Number: ', 'event_espresso'); |
|
| 616 | - return $prefix . $payee_tax_number; |
|
| 617 | - } |
|
| 618 | - |
|
| 619 | - |
|
| 620 | - /** |
|
| 621 | - * Used to retrieve the appropriate content for the invoice payee address shortcode. |
|
| 622 | - * |
|
| 623 | - * @since 4.5.0 |
|
| 624 | - * @return string |
|
| 625 | - * @throws EE_Error |
|
| 626 | - * @throws InvalidArgumentException |
|
| 627 | - * @throws ReflectionException |
|
| 628 | - * @throws InvalidDataTypeException |
|
| 629 | - * @throws InvalidInterfaceException |
|
| 630 | - */ |
|
| 631 | - private function _get_invoice_payee_address() |
|
| 632 | - { |
|
| 633 | - $payee_address = null; |
|
| 634 | - $pm = $this->_get_invoice_payment_method(); |
|
| 635 | - if ($pm instanceof EE_Payment_Method) { |
|
| 636 | - $payee_address = $pm->get_extra_meta('pdf_payee_address', true); |
|
| 637 | - } |
|
| 638 | - if (empty($payee_address)) { |
|
| 639 | - $organization = EE_Registry::instance()->CFG->organization; |
|
| 640 | - $payee_address = $organization->get_pretty('address_1') . '<br>'; |
|
| 641 | - $payee_address .= ! empty($organization->address_2) |
|
| 642 | - ? $organization->get_pretty('address_2') . '<br>' |
|
| 643 | - : ''; |
|
| 644 | - $payee_address .= $organization->get_pretty('city') . '<br>'; |
|
| 645 | - //state |
|
| 646 | - $state = EE_Registry::instance()->load_model('State')->get_one_by_ID($organization->STA_ID); |
|
| 647 | - $payee_address .= $state instanceof EE_State ? $state->name() : ''; |
|
| 648 | - //Country |
|
| 649 | - $payee_address .= ! empty($organization->CNT_ISO) ? ', ' . $organization->CNT_ISO . '<br>' : ''; |
|
| 650 | - $payee_address .= ! empty($organization->zip) ? $organization->zip : ''; |
|
| 651 | - } |
|
| 652 | - return $payee_address; |
|
| 653 | - } |
|
| 654 | - |
|
| 655 | - |
|
| 656 | - /** |
|
| 657 | - * Used to retrieve the appropriate content for the invoice payment instructions shortcode. |
|
| 658 | - * |
|
| 659 | - * @since 4.5.0 |
|
| 660 | - * @return string |
|
| 661 | - * @throws EE_Error |
|
| 662 | - * @throws InvalidArgumentException |
|
| 663 | - * @throws InvalidDataTypeException |
|
| 664 | - * @throws InvalidInterfaceException |
|
| 665 | - */ |
|
| 666 | - private function _get_invoice_payment_instructions() |
|
| 667 | - { |
|
| 668 | - $instructions = null; |
|
| 669 | - $pm = $this->_get_invoice_payment_method(); |
|
| 670 | - return ($pm instanceof EE_Payment_Method) ? $pm->get_extra_meta('pdf_instructions', true) : ''; |
|
| 671 | - } |
|
| 672 | - |
|
| 673 | - |
|
| 674 | - /** |
|
| 675 | - * get invoice/receipt switch button or url. |
|
| 676 | - * |
|
| 677 | - * @param bool $button true (default) returns the html for a button, false just returns the url. |
|
| 678 | - * @return string |
|
| 679 | - * @throws EE_Error |
|
| 680 | - */ |
|
| 681 | - protected function _get_invoice_receipt_switcher($button = true) |
|
| 682 | - { |
|
| 683 | - $reg = $this->_data->primary_reg_obj; |
|
| 684 | - $message_type = isset($this->_extra_data['message_type']) ? $this->_extra_data['message_type'] : ''; |
|
| 685 | - if (! $reg instanceof EE_Registration || empty($message_type)) { |
|
| 686 | - return ''; |
|
| 687 | - } |
|
| 688 | - $switch_to_invoice = ! $message_type instanceof EE_Invoice_message_type ? true : false; |
|
| 689 | - $switch_to_label = $switch_to_invoice && ! $message_type instanceof EE_Receipt_message_type |
|
| 690 | - ? esc_html__('View Invoice', 'event_espresso') : esc_html__('Switch to Invoice', 'event_espresso'); |
|
| 691 | - $switch_to_label = ! $switch_to_invoice ? esc_html__('Switch to Receipt', 'event_espresso') : $switch_to_label; |
|
| 692 | - $switch_to_url = $switch_to_invoice ? $reg->invoice_url() : $reg->receipt_url(); |
|
| 693 | - if (! $button) { |
|
| 694 | - return $switch_to_url; |
|
| 695 | - } |
|
| 696 | - if (! empty($switch_to_url)) { |
|
| 697 | - return ' |
|
| 24 | + /** |
|
| 25 | + * @var EE_Payment_Method $_invoice_pm the invoice payment method for use in invoices etc |
|
| 26 | + */ |
|
| 27 | + protected $_invoice_pm; |
|
| 28 | + |
|
| 29 | + |
|
| 30 | + |
|
| 31 | + protected function _init_props() |
|
| 32 | + { |
|
| 33 | + $this->label = esc_html__('Transaction Shortcodes', 'event_espresso'); |
|
| 34 | + $this->description = esc_html__('All shortcodes specific to transaction related data', 'event_espresso'); |
|
| 35 | + $this->_shortcodes = array( |
|
| 36 | + '[TXN_ID]' => esc_html__('The transaction id for the purchase.', 'event_espresso'), |
|
| 37 | + '[PAYMENT_URL]' => esc_html__( |
|
| 38 | + 'This is a link to make a payment for the event', |
|
| 39 | + 'event_espresso' |
|
| 40 | + ), |
|
| 41 | + '[PAYMENT_LINK_IF_NEEDED_*]' => esc_html__( |
|
| 42 | + 'This is a special dynamic shortcode that allows one to insert a payment link conditional on there being amount owing on the transaction. Three params are available on this shortcode:', |
|
| 43 | + 'event_espresso' |
|
| 44 | + ) |
|
| 45 | + . '<ul>' |
|
| 46 | + . '<li>' |
|
| 47 | + . sprintf( |
|
| 48 | + esc_html__( |
|
| 49 | + '%sclass:%s This can be used to indicate css class is given to the containing css element (default is "callout").', |
|
| 50 | + 'event_espresso' |
|
| 51 | + ), |
|
| 52 | + '<strong>', |
|
| 53 | + '</strong>' |
|
| 54 | + ) |
|
| 55 | + . '</li>' |
|
| 56 | + . '<li>' |
|
| 57 | + . sprintf( |
|
| 58 | + esc_html__( |
|
| 59 | + '%scustom_text:%s This should be a sprintf format text string (with %%s for where the hyperlink tags go) that is used for the generated link text (The default is "You can %%smake a payment here »%%s.)', |
|
| 60 | + 'event_espresso' |
|
| 61 | + ), |
|
| 62 | + '<strong>', |
|
| 63 | + '</strong>' |
|
| 64 | + ) |
|
| 65 | + . '</li>' |
|
| 66 | + . '<li>' |
|
| 67 | + . sprintf( |
|
| 68 | + esc_html__( |
|
| 69 | + '%scontainer_tag:%s Use this to indicate what container tag you want surrounding the payment link (default is "p").', |
|
| 70 | + 'event_espresso' |
|
| 71 | + ), |
|
| 72 | + '<strong>', |
|
| 73 | + '</strong>' |
|
| 74 | + ) |
|
| 75 | + . '</li>' |
|
| 76 | + . '</ul>', |
|
| 77 | + '[PAYMENT_DUE_DATE_*]' => esc_html__( |
|
| 78 | + 'This is a special dynamic shortcode that allows one to output a payment due date. It will only result in a date shown if there is money owing. Three parameters are available on this shortcode:', |
|
| 79 | + 'event_espresso' |
|
| 80 | + ) |
|
| 81 | + . '<ul>' |
|
| 82 | + . '<li>' |
|
| 83 | + . sprintf( |
|
| 84 | + esc_html__( |
|
| 85 | + '%sformat:%s This is used to indicate what format the date is in. Default is whatever is set as date formats for your website.', |
|
| 86 | + 'event_espresso' |
|
| 87 | + ), |
|
| 88 | + '<strong>', |
|
| 89 | + '</strong>' |
|
| 90 | + ) |
|
| 91 | + . '</li>' |
|
| 92 | + . '<li>' |
|
| 93 | + . sprintf( |
|
| 94 | + esc_html__( |
|
| 95 | + '%sdays_until_due:%s This is the number of days form the transaction creation date that the payment is due. Defaults to 30.', |
|
| 96 | + 'event_espresso' |
|
| 97 | + ), |
|
| 98 | + '<strong>', |
|
| 99 | + '</strong>' |
|
| 100 | + ) |
|
| 101 | + . '</li>' |
|
| 102 | + . '<li>' |
|
| 103 | + . sprintf( |
|
| 104 | + esc_html__( |
|
| 105 | + '%sprefix_text:%s You can use this to indicate what text will prefix the date string. Defaults to "Payment in full due by:"', |
|
| 106 | + 'event_espresso' |
|
| 107 | + ), |
|
| 108 | + '<strong>', |
|
| 109 | + '</strong>' |
|
| 110 | + ) |
|
| 111 | + . '</li>', |
|
| 112 | + '[INVOICE_LINK]' => esc_html__( |
|
| 113 | + 'This is a full html link to the invoice', |
|
| 114 | + 'event_espresso' |
|
| 115 | + ), |
|
| 116 | + '[INVOICE_URL]' => esc_html__( |
|
| 117 | + 'This is just the url for the invoice', |
|
| 118 | + 'event_espresso' |
|
| 119 | + ), |
|
| 120 | + '[INVOICE_LOGO_URL]' => esc_html__( |
|
| 121 | + 'This returns the url for the logo uploaded via the invoice settings page.', |
|
| 122 | + 'event_espresso' |
|
| 123 | + ), |
|
| 124 | + '[INVOICE_LOGO]' => esc_html__( |
|
| 125 | + 'This returns the logo uploaded via the invoice settings page wrapped in img_tags and with a "logo screen" classes. The image size is also set in the img tags automatically to match the uploaded logo.', |
|
| 126 | + 'event_espresso' |
|
| 127 | + ), |
|
| 128 | + '[INVOICE_PAYEE_NAME]' => esc_html__( |
|
| 129 | + 'This will parse to either: the value of the "Company Name" field in the invoice payment method settings; if that is blank, then the value of the Company Name in the "Your Organization Settings", if that is blank then an empty string.', |
|
| 130 | + 'event_espresso' |
|
| 131 | + ), |
|
| 132 | + '[INVOICE_PAYEE_ADDRESS]' => esc_html__( |
|
| 133 | + 'This will parse to either: the value of the "Company Address" field in the invoice payment method settings; if that is blank, then the value of the Company Address in the "Your Organization Settings", if that is blank then an empty string.', |
|
| 134 | + 'event_espresso' |
|
| 135 | + ), |
|
| 136 | + '[INVOICE_PAYMENT_INSTRUCTIONS]' => esc_html__( |
|
| 137 | + 'This will parse to the value of the "Payment Instructions" field found on the Invoice payment methods settings page', |
|
| 138 | + 'event_espresso' |
|
| 139 | + ), |
|
| 140 | + '[INVOICE_PAYEE_EMAIL]' => esc_html__( |
|
| 141 | + 'This will parse to either: the value of the "Company Email" field in the invoice payment method settings; if that is blank, then the value of the Company Email in the "Your Organization Settings", if that is blank then an empty string.', |
|
| 142 | + 'event_espresso' |
|
| 143 | + ), |
|
| 144 | + '[INVOICE_PAYEE_TAX_NUMBER_*]' => sprintf( |
|
| 145 | + esc_html__( |
|
| 146 | + 'This will parse to either: the value of the "Company Tax Number" field in the invoice payment method settings; if that is blank, then the value of the Company Tax Number in the "Your Organization Settings", if that is blank then an empty string. Note this is also a special dynamic shortcode. You can use the "prefix" parameter to indicate what text you want to use as a prefix before this tax number. It defaults to "VAT/Tax Number:". To change this prefix you do the following format for this shortcode: %1$s[INVOICE_PAYEE_TAX_NUMBER_* prefix="GST:"]%2$s and that will output: GST: 12345t56. If you have no tax number in your settings, then no prefix will be output either.', |
|
| 147 | + 'event_espresso' |
|
| 148 | + ), |
|
| 149 | + '<code>', |
|
| 150 | + '</code>' |
|
| 151 | + ), |
|
| 152 | + '[TOTAL_COST]' => esc_html__('The total cost for the transaction', 'event_espresso'), |
|
| 153 | + '[TXN_STATUS]' => esc_html__( |
|
| 154 | + 'The transaction status for the transaction.', |
|
| 155 | + 'event_espresso' |
|
| 156 | + ), |
|
| 157 | + '[TXN_STATUS_ID]' => esc_html__( |
|
| 158 | + 'The ID representing the transaction status as saved in the db. This tends to be useful for including with css classes for styling certain statuses differently from others.', |
|
| 159 | + 'event_espresso' |
|
| 160 | + ), |
|
| 161 | + '[PAYMENT_STATUS]' => esc_html__( |
|
| 162 | + 'The transaction status for the transaction. This parses to the same value as the [TXN_STATUS] shortcode and still remains here for legacy support.', |
|
| 163 | + 'event_espresso' |
|
| 164 | + ), |
|
| 165 | + '[PAYMENT_GATEWAY]' => esc_html__( |
|
| 166 | + 'The payment gateway used for the transaction', |
|
| 167 | + 'event_espresso' |
|
| 168 | + ), |
|
| 169 | + '[AMOUNT_PAID]' => esc_html__( |
|
| 170 | + 'The amount paid or refunded. This will only have a value if there was a payment or refund at the time of generating the message.', |
|
| 171 | + 'event_espresso' |
|
| 172 | + ), |
|
| 173 | + '[LAST_AMOUNT_PAID]' => esc_html__( |
|
| 174 | + 'This is the last payment or refund made on the transaction related to the message being generated.', |
|
| 175 | + 'event_espresso' |
|
| 176 | + ), |
|
| 177 | + '[TOTAL_AMOUNT_PAID]' => esc_html__( |
|
| 178 | + 'This parses to the total amount paid over all payments', |
|
| 179 | + 'event_espresso' |
|
| 180 | + ), |
|
| 181 | + '[TOTAL_OWING]' => esc_html__( |
|
| 182 | + 'The total owing on a transaction with no attributes.', |
|
| 183 | + 'event_espresso' |
|
| 184 | + ), |
|
| 185 | + '[TXN_SUBTOTAL]' => esc_html__('The subtotal for all txn line items.', 'event_espresso'), |
|
| 186 | + '[TXN_TAX_SUBTOTAL]' => esc_html__('The subtotal for all tax line items.', 'event_espresso'), |
|
| 187 | + '[OWING_STATUS_MESSAGE_*]' => esc_html__( |
|
| 188 | + 'A dynamic shortcode for adjusting how total owing gets shown. The acceptable attributes on the shortcode are:', |
|
| 189 | + 'event_espresso' |
|
| 190 | + ) |
|
| 191 | + . '<p></ul>' |
|
| 192 | + . '<li><strong>still_owing</strong>:' |
|
| 193 | + . esc_html__( |
|
| 194 | + 'If the transaction is not paid in full, then whatever is set for this attribute is shown (otherwise its just the amount owing). The default is:', |
|
| 195 | + 'event_espresso' |
|
| 196 | + ) |
|
| 197 | + . sprintf( |
|
| 198 | + esc_html__('%sPlease make a payment.%s', 'event_espresso'), |
|
| 199 | + '<a href="[PAYMENT_URL]" class="noPrint">', |
|
| 200 | + '</a>' |
|
| 201 | + ) |
|
| 202 | + . '</li>' |
|
| 203 | + . |
|
| 204 | + '<li><strong>none_owing</strong>:' |
|
| 205 | + . esc_html__( |
|
| 206 | + 'If the transaction is paid in full, then you can indicate how this gets displayed. Note, that it defaults to just be the total owing.', |
|
| 207 | + 'event_espresso' |
|
| 208 | + ) |
|
| 209 | + . '</li></ul></p>', |
|
| 210 | + '[TXN_TOTAL_TICKETS]' => esc_html__( |
|
| 211 | + 'The total number of all tickets purchased in a transaction', |
|
| 212 | + 'event_espresso' |
|
| 213 | + ), |
|
| 214 | + '[TKT_QTY_PURCHASED]' => sprintf( |
|
| 215 | + esc_html__( |
|
| 216 | + 'The total number of all tickets purchased in a transaction. %1$sNOTE: This shortcode is good to use in the "[TICKET_LIST]" field but has been deprecated from all other contexts in favor of the more explicit [TXN_TOTAL_TICKETS] shortcode.%2$s', |
|
| 217 | + 'event_espresso' |
|
| 218 | + ), |
|
| 219 | + '<strong>', |
|
| 220 | + '</strong>' |
|
| 221 | + ), |
|
| 222 | + '[TRANSACTION_ADMIN_URL]' => esc_html__( |
|
| 223 | + 'The url to the admin page for this transaction', |
|
| 224 | + 'event_espresso' |
|
| 225 | + ), |
|
| 226 | + '[RECEIPT_URL]' => esc_html__( |
|
| 227 | + 'This parses to the generated url for retrieving the receipt for the transaction', |
|
| 228 | + 'event_espresso' |
|
| 229 | + ), |
|
| 230 | + '[INVOICE_RECEIPT_SWITCHER_URL]' => esc_html__( |
|
| 231 | + 'This parses to the url that will switch to the receipt if an invoice is displayed, and switch to the invoice if receipt is displayed. If a message type OTHER than invoice or receipt is displayed then this will just return the url for the invoice. If the related message type is not active then will parse to an empty string.', |
|
| 232 | + 'event_espresso' |
|
| 233 | + ), |
|
| 234 | + '[INVOICE_RECEIPT_SWITCHER_BUTTON]' => sprintf( |
|
| 235 | + esc_html__( |
|
| 236 | + 'The same as %1$s%2$s except this returns the html for a button linked to the invoice or receipt.', |
|
| 237 | + 'event_espresso' |
|
| 238 | + ), |
|
| 239 | + '<code>[INVOICE_RECEIPT_SWITCHER_URL]', |
|
| 240 | + '</code>' |
|
| 241 | + ), |
|
| 242 | + '[LAST_PAYMENT_TRANSACTION_ID]' => esc_html__( |
|
| 243 | + 'This will output the value of the payment transaction id for the last payment made on the transaction. Note, if a specific payment was included for message generation, that will be used when parsing the shortcode.', |
|
| 244 | + 'event_espresso' |
|
| 245 | + ), |
|
| 246 | + ); |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + |
|
| 250 | + /** |
|
| 251 | + * @param string $shortcode the shortcode to be parsed. |
|
| 252 | + * @return string parsed shortcode |
|
| 253 | + * @throws EE_Error |
|
| 254 | + * @throws InvalidArgumentException |
|
| 255 | + * @throws ReflectionException |
|
| 256 | + * @throws InvalidDataTypeException |
|
| 257 | + * @throws InvalidInterfaceException |
|
| 258 | + */ |
|
| 259 | + protected function _parser($shortcode) |
|
| 260 | + { |
|
| 261 | + //attempt to get the transaction. Since this is potentially used in more fields, we may have to look in the |
|
| 262 | + // _extra_data for the transaction. |
|
| 263 | + $transaction = $this->_data->txn instanceof EE_Transaction ? $this->_data->txn : null; |
|
| 264 | + $transaction = ! $transaction instanceof EE_Transaction |
|
| 265 | + && is_array($this->_extra_data) |
|
| 266 | + && isset($this->_extra_data['data']) |
|
| 267 | + && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
| 268 | + ? $this->_extra_data['data']->txn |
|
| 269 | + : $transaction; |
|
| 270 | + //payment |
|
| 271 | + $payment = $this->_data->payment instanceof EE_Payment ? $this->_data->payment : null; |
|
| 272 | + $payment = ! $payment instanceof EE_Payment |
|
| 273 | + && is_array($this->_extra_data) |
|
| 274 | + && isset($this->_extra_data['data']) |
|
| 275 | + && $this->_extra_data['data'] instanceof EE_Messages_Addressee ? $this->_extra_data['data']->payment |
|
| 276 | + : $payment; |
|
| 277 | + if (! $transaction instanceof EE_Transaction) { |
|
| 278 | + return ''; |
|
| 279 | + } |
|
| 280 | + switch ($shortcode) { |
|
| 281 | + case '[TXN_ID]': |
|
| 282 | + return $transaction->ID(); |
|
| 283 | + break; |
|
| 284 | + case '[PAYMENT_URL]': |
|
| 285 | + $payment_url = $transaction->payment_overview_url(); |
|
| 286 | + return empty($payment_url) |
|
| 287 | + ? esc_html__('http://dummypaymenturlforpreview.com', 'event_espresso') |
|
| 288 | + : $payment_url; |
|
| 289 | + break; |
|
| 290 | + case '[INVOICE_LINK]': |
|
| 291 | + $invoice_url = $transaction->invoice_url(); |
|
| 292 | + $invoice_url = empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com': $invoice_url; |
|
| 293 | + return sprintf( |
|
| 294 | + esc_html__('%sClick here for Invoice%s', 'event_espresso'), |
|
| 295 | + '<a href="' . $invoice_url . '">', |
|
| 296 | + '</a>' |
|
| 297 | + ); |
|
| 298 | + break; |
|
| 299 | + case '[INVOICE_URL]': |
|
| 300 | + $invoice_url = $transaction->invoice_url(); |
|
| 301 | + return empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com': $invoice_url; |
|
| 302 | + break; |
|
| 303 | + case '[INVOICE_LOGO_URL]': |
|
| 304 | + return $this->_get_invoice_logo(); |
|
| 305 | + break; |
|
| 306 | + case '[INVOICE_LOGO]': |
|
| 307 | + return $this->_get_invoice_logo(true); |
|
| 308 | + break; |
|
| 309 | + case '[INVOICE_PAYEE_NAME]': |
|
| 310 | + return $this->_get_invoice_payee_name(); |
|
| 311 | + break; |
|
| 312 | + case '[INVOICE_PAYEE_ADDRESS]': |
|
| 313 | + return $this->_get_invoice_payee_address(); |
|
| 314 | + break; |
|
| 315 | + case '[INVOICE_PAYMENT_INSTRUCTIONS]': |
|
| 316 | + return $this->_get_invoice_payment_instructions(); |
|
| 317 | + break; |
|
| 318 | + case '[INVOICE_PAYEE_EMAIL]': |
|
| 319 | + return $this->_get_invoice_payee_email(); |
|
| 320 | + break; |
|
| 321 | + case '[TOTAL_COST]': |
|
| 322 | + $total = $transaction->total(); |
|
| 323 | + return ! empty($total) ? EEH_Template::format_currency($total): ''; |
|
| 324 | + break; |
|
| 325 | + case '[PAYMENT_STATUS]': |
|
| 326 | + $status = $transaction->pretty_status(); |
|
| 327 | + return ! empty($status) ? $status : esc_html__('Unknown', 'event_espresso'); |
|
| 328 | + break; /**/ |
|
| 329 | + // note the [payment_status] shortcode is kind of misleading because payment status might be different |
|
| 330 | + // from txn status so I'm adding this here for clarity. |
|
| 331 | + case '[TXN_STATUS]': |
|
| 332 | + $status = $transaction->pretty_status(); |
|
| 333 | + return ! empty($status) ? $status : esc_html__('Unknown', 'event_espresso'); |
|
| 334 | + break; |
|
| 335 | + case '[TXN_STATUS_ID]': |
|
| 336 | + return $transaction->status_ID(); |
|
| 337 | + break; |
|
| 338 | + case '[PAYMENT_GATEWAY]': |
|
| 339 | + return $this->_get_payment_gateway($transaction); |
|
| 340 | + break; |
|
| 341 | + case '[AMOUNT_PAID]': |
|
| 342 | + return $payment instanceof EE_Payment |
|
| 343 | + ? EEH_Template::format_currency($payment->amount()) |
|
| 344 | + : EEH_Template::format_currency(0); |
|
| 345 | + break; |
|
| 346 | + case '[LAST_AMOUNT_PAID]': |
|
| 347 | + $last_payment = $transaction->last_payment(); |
|
| 348 | + return $last_payment instanceof EE_Payment |
|
| 349 | + ? EEH_Template::format_currency($last_payment->amount()) |
|
| 350 | + : EEH_Template::format_currency(0); |
|
| 351 | + case '[TOTAL_AMOUNT_PAID]': |
|
| 352 | + return EEH_Template::format_currency($transaction->paid()); |
|
| 353 | + break; |
|
| 354 | + case '[TOTAL_OWING]': |
|
| 355 | + $total_owing = $transaction->remaining(); |
|
| 356 | + return EEH_Template::format_currency($total_owing); |
|
| 357 | + break; |
|
| 358 | + case '[TXN_SUBTOTAL]': |
|
| 359 | + return EEH_Template::format_currency($this->_get_subtotal()); |
|
| 360 | + break; |
|
| 361 | + case '[TXN_TAX_SUBTOTAL]': |
|
| 362 | + return EEH_Template::format_currency($this->_get_subtotal(true)); |
|
| 363 | + break; |
|
| 364 | + case '[TKT_QTY_PURCHASED]': |
|
| 365 | + case '[TXN_TOTAL_TICKETS]': |
|
| 366 | + return $this->_data->total_ticket_count; |
|
| 367 | + break; |
|
| 368 | + case '[TRANSACTION_ADMIN_URL]': |
|
| 369 | + require_once EE_CORE . 'admin/EE_Admin_Page.core.php'; |
|
| 370 | + $query_args = array( |
|
| 371 | + 'page' => 'espresso_transactions', |
|
| 372 | + 'action' => 'view_transaction', |
|
| 373 | + 'TXN_ID' => $transaction->ID(), |
|
| 374 | + ); |
|
| 375 | + $url = EE_Admin_Page::add_query_args_and_nonce($query_args, admin_url('admin.php')); |
|
| 376 | + return $url; |
|
| 377 | + break; |
|
| 378 | + case '[RECEIPT_URL]': |
|
| 379 | + //get primary_registration |
|
| 380 | + $reg = $this->_data->primary_reg_obj; |
|
| 381 | + if (! $reg instanceof EE_Registration) { |
|
| 382 | + return ''; |
|
| 383 | + } |
|
| 384 | + return $reg->receipt_url(); |
|
| 385 | + break; |
|
| 386 | + case '[INVOICE_RECEIPT_SWITCHER_URL]': |
|
| 387 | + return $this->_get_invoice_receipt_switcher(false); |
|
| 388 | + break; |
|
| 389 | + case '[INVOICE_RECEIPT_SWITCHER_BUTTON]': |
|
| 390 | + return $this->_get_invoice_receipt_switcher(); |
|
| 391 | + break; |
|
| 392 | + case '[LAST_PAYMENT_TRANSACTION_ID]': |
|
| 393 | + $id = ''; |
|
| 394 | + $payment = $payment instanceof EE_Payment && $payment->ID() !== 0 |
|
| 395 | + ? $payment |
|
| 396 | + : $transaction->last_payment(); |
|
| 397 | + if ($payment instanceof EE_Payment) { |
|
| 398 | + $id = $payment->txn_id_chq_nmbr(); |
|
| 399 | + } |
|
| 400 | + return $id; |
|
| 401 | + break; |
|
| 402 | + } |
|
| 403 | + if (strpos($shortcode, '[OWING_STATUS_MESSAGE_*') !== false) { |
|
| 404 | + return $this->_get_custom_total_owing($shortcode); |
|
| 405 | + } |
|
| 406 | + if (strpos($shortcode, '[INVOICE_PAYEE_TAX_NUMBER_*') !== false) { |
|
| 407 | + return $this->_get_invoice_payee_tax_number($shortcode); |
|
| 408 | + } |
|
| 409 | + if (strpos($shortcode, '[PAYMENT_LINK_IF_NEEDED_*') !== false) { |
|
| 410 | + return $this->_get_payment_link_if_needed($shortcode); |
|
| 411 | + } |
|
| 412 | + if (strpos($shortcode, '[PAYMENT_DUE_DATE_*') !== false) { |
|
| 413 | + return $this->_get_payment_due_date($shortcode, $transaction); |
|
| 414 | + } |
|
| 415 | + return ''; |
|
| 416 | + } |
|
| 417 | + |
|
| 418 | + |
|
| 419 | + /** |
|
| 420 | + * parser for the [OWING_STATUS_MESSAGE_*] attribute type shortcode |
|
| 421 | + * |
|
| 422 | + * @since 4.5.0 |
|
| 423 | + * @param string $shortcode the incoming shortcode |
|
| 424 | + * @return string parsed. |
|
| 425 | + * @throws EE_Error |
|
| 426 | + */ |
|
| 427 | + private function _get_custom_total_owing($shortcode) |
|
| 428 | + { |
|
| 429 | + $valid_shortcodes = array('transaction'); |
|
| 430 | + $attrs = $this->_get_shortcode_attrs($shortcode); |
|
| 431 | + //ensure default is set. |
|
| 432 | + $addressee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
|
| 433 | + $total_owing = $addressee instanceof EE_Messages_Addressee && $addressee->txn instanceof EE_Transaction |
|
| 434 | + ? $addressee->txn->remaining() : 0; |
|
| 435 | + if ($total_owing > 0) { |
|
| 436 | + $owing_content = ! empty($attrs['still_owing']) |
|
| 437 | + ? $attrs['still_owing'] |
|
| 438 | + : sprintf( |
|
| 439 | + esc_html__('%sPlease make a payment.%s', 'event_espresso'), |
|
| 440 | + '<a href="[PAYMENT_URL]" class="noPrint">', |
|
| 441 | + '</a>' |
|
| 442 | + ); |
|
| 443 | + $owing_content = $this->_shortcode_helper->parse_message_template( |
|
| 444 | + $owing_content, |
|
| 445 | + $addressee, |
|
| 446 | + $valid_shortcodes, |
|
| 447 | + $this->_message_type, |
|
| 448 | + $this->_messenger, |
|
| 449 | + $this->_message |
|
| 450 | + ); |
|
| 451 | + } else { |
|
| 452 | + $owing_content = ! empty($attrs['none_owing']) ? $attrs['none_owing'] : ''; |
|
| 453 | + } |
|
| 454 | + return $owing_content; |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + |
|
| 458 | + /** |
|
| 459 | + * @param EE_Transaction $transaction |
|
| 460 | + * @return string |
|
| 461 | + * @throws EE_Error |
|
| 462 | + */ |
|
| 463 | + private function _get_payment_gateway($transaction) |
|
| 464 | + { |
|
| 465 | + if ($transaction instanceof EE_Transaction){ |
|
| 466 | + $pm = $transaction->payment_method(); |
|
| 467 | + } else { |
|
| 468 | + $pm = null; |
|
| 469 | + } |
|
| 470 | + return $pm instanceof EE_Payment_Method ? $pm->name() : ''; |
|
| 471 | + } |
|
| 472 | + |
|
| 473 | + |
|
| 474 | + /** |
|
| 475 | + * This retrieves a logo to be used for the invoice from whatever is set on the invoice logo settings page. If its |
|
| 476 | + * not present then the organization logo is used if its found (set on the organization settings page). |
|
| 477 | + * |
|
| 478 | + * @since 4.5.0 |
|
| 479 | + * @param bool $img_tags TRUE means to return with the img tag wrappers. False just returns the url to the image. |
|
| 480 | + * @return string url or html |
|
| 481 | + * @throws EE_Error |
|
| 482 | + * @throws InvalidArgumentException |
|
| 483 | + * @throws InvalidDataTypeException |
|
| 484 | + * @throws InvalidInterfaceException |
|
| 485 | + */ |
|
| 486 | + private function _get_invoice_logo($img_tags = false) |
|
| 487 | + { |
|
| 488 | + $invoice_logo_url = ''; |
|
| 489 | + //try to get the invoice payment method's logo for this transaction image first |
|
| 490 | + $pm = $this->_get_invoice_payment_method(); |
|
| 491 | + if ($pm instanceof EE_Payment_Method) { |
|
| 492 | + $invoice_logo_url = $pm->get_extra_meta('pdf_logo_image', true); |
|
| 493 | + } |
|
| 494 | + if (empty($invoice_logo_url)) { |
|
| 495 | + $invoice_logo_url = EE_Registry::instance()->CFG->organization->logo_url; |
|
| 496 | + } |
|
| 497 | + if (empty($invoice_logo_url)) { |
|
| 498 | + return ''; |
|
| 499 | + } |
|
| 500 | + if (! $img_tags) { |
|
| 501 | + return $invoice_logo_url; |
|
| 502 | + } |
|
| 503 | + //image tags have been requested. |
|
| 504 | + $image_size = getimagesize($invoice_logo_url); |
|
| 505 | + //if image is wider than 300px, set the width to 300 |
|
| 506 | + if ($image_size[0] > 300) { |
|
| 507 | + $image_width = 300; |
|
| 508 | + } else { |
|
| 509 | + $image_width = $image_size[0]; |
|
| 510 | + } |
|
| 511 | + return '<img class="logo screen" src="' . $invoice_logo_url . '" width="' . $image_width . '" alt="logo" />'; |
|
| 512 | + } |
|
| 513 | + |
|
| 514 | + |
|
| 515 | + /** |
|
| 516 | + * Used to retrieve the appropriate content for the invoice payee name shortcode |
|
| 517 | + * |
|
| 518 | + * @since 4.5.0 |
|
| 519 | + * @return string |
|
| 520 | + * @throws EE_Error |
|
| 521 | + * @throws InvalidArgumentException |
|
| 522 | + * @throws InvalidDataTypeException |
|
| 523 | + * @throws InvalidInterfaceException |
|
| 524 | + */ |
|
| 525 | + private function _get_invoice_payee_name() |
|
| 526 | + { |
|
| 527 | + $payee_name = null; |
|
| 528 | + $pm = $this->_get_invoice_payment_method(); |
|
| 529 | + if ($pm instanceof EE_Payment_Method) { |
|
| 530 | + $payee_name = $pm->get_extra_meta('pdf_payee_name', true); |
|
| 531 | + } |
|
| 532 | + $payee_name = empty($payee_name) ? EE_Registry::instance()->CFG->organization->get_pretty('name') : $payee_name; |
|
| 533 | + return $payee_name; |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + |
|
| 537 | + /** |
|
| 538 | + * gets the default invoice payment method, but has a filter so it can be overridden |
|
| 539 | + * |
|
| 540 | + * @return EE_Payment_Method|null |
|
| 541 | + * @throws EE_Error |
|
| 542 | + * @throws InvalidArgumentException |
|
| 543 | + * @throws InvalidDataTypeException |
|
| 544 | + * @throws InvalidInterfaceException |
|
| 545 | + */ |
|
| 546 | + private function _get_invoice_payment_method() |
|
| 547 | + { |
|
| 548 | + if (! $this->_invoice_pm instanceof EE_Payment_Method) { |
|
| 549 | + $transaction = $this->_data->txn instanceof EE_Transaction ? $this->_data->txn : null; |
|
| 550 | + $transaction = ! $transaction instanceof EE_Transaction |
|
| 551 | + && is_array($this->_extra_data) |
|
| 552 | + && isset($this->_extra_data['data']) |
|
| 553 | + && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
| 554 | + ? $this->_extra_data['data']->txn : $transaction; |
|
| 555 | + //get the invoice payment method, and remember it for the next call too |
|
| 556 | + $this->_invoice_pm = apply_filters( |
|
| 557 | + 'FHEE__EE_Transaction_Shortcodes__get_payment_method__default', |
|
| 558 | + EEM_Payment_Method::instance()->get_one_of_type('Invoice'), |
|
| 559 | + $transaction |
|
| 560 | + ); |
|
| 561 | + } |
|
| 562 | + return $this->_invoice_pm; |
|
| 563 | + } |
|
| 564 | + |
|
| 565 | + |
|
| 566 | + /** |
|
| 567 | + * Used to retrieve the appropriate content for the invoice payee email shortcode |
|
| 568 | + * |
|
| 569 | + * @since 4.5.0 |
|
| 570 | + * @return string |
|
| 571 | + * @throws EE_Error |
|
| 572 | + * @throws InvalidArgumentException |
|
| 573 | + * @throws InvalidDataTypeException |
|
| 574 | + * @throws InvalidInterfaceException |
|
| 575 | + */ |
|
| 576 | + private function _get_invoice_payee_email() |
|
| 577 | + { |
|
| 578 | + $payee_email = null; |
|
| 579 | + $pm = $this->_get_invoice_payment_method(); |
|
| 580 | + if ($pm instanceof EE_Payment_Method) { |
|
| 581 | + $payee_email = $pm->get_extra_meta('pdf_payee_email', true); |
|
| 582 | + } |
|
| 583 | + $payee_email = empty($payee_email) ? EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 584 | + : $payee_email; |
|
| 585 | + return $payee_email; |
|
| 586 | + } |
|
| 587 | + |
|
| 588 | + |
|
| 589 | + /** |
|
| 590 | + * Used to retrieve the appropriate content for the invoice payee tax number shortcode |
|
| 591 | + * |
|
| 592 | + * @since 4.5.0 |
|
| 593 | + * @param string $shortcode |
|
| 594 | + * @return string |
|
| 595 | + * @throws EE_Error |
|
| 596 | + * @throws InvalidArgumentException |
|
| 597 | + * @throws InvalidDataTypeException |
|
| 598 | + * @throws InvalidInterfaceException |
|
| 599 | + */ |
|
| 600 | + private function _get_invoice_payee_tax_number($shortcode) |
|
| 601 | + { |
|
| 602 | + $payee_tax_number = null; |
|
| 603 | + $pm = $this->_get_invoice_payment_method(); |
|
| 604 | + if ($pm instanceof EE_Payment_Method) { |
|
| 605 | + $payee_tax_number = $pm->get_extra_meta('pdf_payee_tax_number', true); |
|
| 606 | + } |
|
| 607 | + $payee_tax_number = empty($payee_tax_number) ? EE_Registry::instance()->CFG->organization->vat |
|
| 608 | + : $payee_tax_number; |
|
| 609 | + if (empty($payee_tax_number)) { |
|
| 610 | + return ''; |
|
| 611 | + } |
|
| 612 | + //any attributes? |
|
| 613 | + $attrs = $this->_get_shortcode_attrs($shortcode); |
|
| 614 | + //prefix? |
|
| 615 | + $prefix = isset($attrs['prefix']) ? $attrs['prefix'] : esc_html__('VAT/Tax Number: ', 'event_espresso'); |
|
| 616 | + return $prefix . $payee_tax_number; |
|
| 617 | + } |
|
| 618 | + |
|
| 619 | + |
|
| 620 | + /** |
|
| 621 | + * Used to retrieve the appropriate content for the invoice payee address shortcode. |
|
| 622 | + * |
|
| 623 | + * @since 4.5.0 |
|
| 624 | + * @return string |
|
| 625 | + * @throws EE_Error |
|
| 626 | + * @throws InvalidArgumentException |
|
| 627 | + * @throws ReflectionException |
|
| 628 | + * @throws InvalidDataTypeException |
|
| 629 | + * @throws InvalidInterfaceException |
|
| 630 | + */ |
|
| 631 | + private function _get_invoice_payee_address() |
|
| 632 | + { |
|
| 633 | + $payee_address = null; |
|
| 634 | + $pm = $this->_get_invoice_payment_method(); |
|
| 635 | + if ($pm instanceof EE_Payment_Method) { |
|
| 636 | + $payee_address = $pm->get_extra_meta('pdf_payee_address', true); |
|
| 637 | + } |
|
| 638 | + if (empty($payee_address)) { |
|
| 639 | + $organization = EE_Registry::instance()->CFG->organization; |
|
| 640 | + $payee_address = $organization->get_pretty('address_1') . '<br>'; |
|
| 641 | + $payee_address .= ! empty($organization->address_2) |
|
| 642 | + ? $organization->get_pretty('address_2') . '<br>' |
|
| 643 | + : ''; |
|
| 644 | + $payee_address .= $organization->get_pretty('city') . '<br>'; |
|
| 645 | + //state |
|
| 646 | + $state = EE_Registry::instance()->load_model('State')->get_one_by_ID($organization->STA_ID); |
|
| 647 | + $payee_address .= $state instanceof EE_State ? $state->name() : ''; |
|
| 648 | + //Country |
|
| 649 | + $payee_address .= ! empty($organization->CNT_ISO) ? ', ' . $organization->CNT_ISO . '<br>' : ''; |
|
| 650 | + $payee_address .= ! empty($organization->zip) ? $organization->zip : ''; |
|
| 651 | + } |
|
| 652 | + return $payee_address; |
|
| 653 | + } |
|
| 654 | + |
|
| 655 | + |
|
| 656 | + /** |
|
| 657 | + * Used to retrieve the appropriate content for the invoice payment instructions shortcode. |
|
| 658 | + * |
|
| 659 | + * @since 4.5.0 |
|
| 660 | + * @return string |
|
| 661 | + * @throws EE_Error |
|
| 662 | + * @throws InvalidArgumentException |
|
| 663 | + * @throws InvalidDataTypeException |
|
| 664 | + * @throws InvalidInterfaceException |
|
| 665 | + */ |
|
| 666 | + private function _get_invoice_payment_instructions() |
|
| 667 | + { |
|
| 668 | + $instructions = null; |
|
| 669 | + $pm = $this->_get_invoice_payment_method(); |
|
| 670 | + return ($pm instanceof EE_Payment_Method) ? $pm->get_extra_meta('pdf_instructions', true) : ''; |
|
| 671 | + } |
|
| 672 | + |
|
| 673 | + |
|
| 674 | + /** |
|
| 675 | + * get invoice/receipt switch button or url. |
|
| 676 | + * |
|
| 677 | + * @param bool $button true (default) returns the html for a button, false just returns the url. |
|
| 678 | + * @return string |
|
| 679 | + * @throws EE_Error |
|
| 680 | + */ |
|
| 681 | + protected function _get_invoice_receipt_switcher($button = true) |
|
| 682 | + { |
|
| 683 | + $reg = $this->_data->primary_reg_obj; |
|
| 684 | + $message_type = isset($this->_extra_data['message_type']) ? $this->_extra_data['message_type'] : ''; |
|
| 685 | + if (! $reg instanceof EE_Registration || empty($message_type)) { |
|
| 686 | + return ''; |
|
| 687 | + } |
|
| 688 | + $switch_to_invoice = ! $message_type instanceof EE_Invoice_message_type ? true : false; |
|
| 689 | + $switch_to_label = $switch_to_invoice && ! $message_type instanceof EE_Receipt_message_type |
|
| 690 | + ? esc_html__('View Invoice', 'event_espresso') : esc_html__('Switch to Invoice', 'event_espresso'); |
|
| 691 | + $switch_to_label = ! $switch_to_invoice ? esc_html__('Switch to Receipt', 'event_espresso') : $switch_to_label; |
|
| 692 | + $switch_to_url = $switch_to_invoice ? $reg->invoice_url() : $reg->receipt_url(); |
|
| 693 | + if (! $button) { |
|
| 694 | + return $switch_to_url; |
|
| 695 | + } |
|
| 696 | + if (! empty($switch_to_url)) { |
|
| 697 | + return ' |
|
| 698 | 698 | <form method="post" action="' . $switch_to_url . '" > |
| 699 | 699 | <input class="print_button" type="submit" value="' . $switch_to_label . '" /> |
| 700 | 700 | </form> |
| 701 | 701 | '; |
| 702 | - } |
|
| 703 | - return ''; |
|
| 704 | - } |
|
| 705 | - |
|
| 706 | - |
|
| 707 | - /** |
|
| 708 | - * This returns a subtotal. |
|
| 709 | - * |
|
| 710 | - * @param bool $tax if true then return the subtotal for tax otherwise return subtotal. |
|
| 711 | - * @return int |
|
| 712 | - * @throws EE_Error |
|
| 713 | - */ |
|
| 714 | - private function _get_subtotal($tax = false) |
|
| 715 | - { |
|
| 716 | - $grand_total = isset($this->_data->grand_total_line_item) ? $this->_data->grand_total_line_item : null; |
|
| 717 | - if (! $grand_total instanceof EE_Line_Item) { |
|
| 718 | - return 0; |
|
| 719 | - } |
|
| 720 | - return $tax ? $grand_total->get_total_tax() : $grand_total->get_items_total(); |
|
| 721 | - } |
|
| 722 | - |
|
| 723 | - |
|
| 724 | - /** |
|
| 725 | - * parser for the [PAYMENT_LINK_IF_NEEDED_*] attribute type shortcode |
|
| 726 | - * |
|
| 727 | - * @since 4.7.0 |
|
| 728 | - * @param string $shortcode the incoming shortcode |
|
| 729 | - * @return string parsed. |
|
| 730 | - * @throws EE_Error |
|
| 731 | - */ |
|
| 732 | - private function _get_payment_link_if_needed($shortcode) |
|
| 733 | - { |
|
| 734 | - $valid_shortcodes = array('transaction'); |
|
| 735 | - $attrs = $this->_get_shortcode_attrs($shortcode); |
|
| 736 | - //ensure default is set. |
|
| 737 | - $addressee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
|
| 738 | - $total_owing = $addressee instanceof EE_Messages_Addressee && $addressee->txn instanceof EE_Transaction |
|
| 739 | - ? $addressee->txn->remaining() : 0; |
|
| 740 | - if ($total_owing > 0) { |
|
| 741 | - $class = isset($attrs['class']) ? $attrs['class'] : 'callout'; |
|
| 742 | - $custom_text = isset($attrs['custom_text']) ? $attrs['custom_text'] : 'You can %smake a payment here »%s.'; |
|
| 743 | - $container_tag = isset($attrs['container_tag']) ? $attrs['container_tag'] : 'p'; |
|
| 744 | - $opening_tag = ! empty($container_tag) ? '<' . $container_tag : ''; |
|
| 745 | - $opening_tag .= ! empty($opening_tag) && ! empty($class) ? ' class="' . $class . '"' : $opening_tag; |
|
| 746 | - $opening_tag .= ! empty($opening_tag) ? '>' : $opening_tag; |
|
| 747 | - $closing_tag = ! empty($container_tag) ? '</' . $container_tag . '>' : ''; |
|
| 748 | - $content = $opening_tag . sprintf($custom_text, '<a href="[PAYMENT_URL]">', '</a>') . $closing_tag; |
|
| 749 | - //we need to re run this string through the parser to catch any shortcodes that are in it. |
|
| 750 | - $owing_content = $this->_shortcode_helper->parse_message_template( |
|
| 751 | - $content, |
|
| 752 | - $addressee, |
|
| 753 | - $valid_shortcodes, |
|
| 754 | - $this->_message_type, |
|
| 755 | - $this->_messenger, |
|
| 756 | - $this->_message |
|
| 757 | - ); |
|
| 758 | - } else { |
|
| 759 | - return ''; |
|
| 760 | - } |
|
| 761 | - return $owing_content; |
|
| 762 | - } |
|
| 763 | - |
|
| 764 | - |
|
| 765 | - /** |
|
| 766 | - * Parser for the [PAYMENT_DUE_DATE_*] attribute type shortcode |
|
| 767 | - * |
|
| 768 | - * @since 4.8.28.rc.011 |
|
| 769 | - * @param string $shortcode The shortcode being parsed. |
|
| 770 | - * @param EE_Transaction $transaction |
|
| 771 | - * @return string |
|
| 772 | - * @throws EE_Error |
|
| 773 | - */ |
|
| 774 | - protected function _get_payment_due_date($shortcode, EE_Transaction $transaction) |
|
| 775 | - { |
|
| 776 | - //if transaction is paid in full then we can just return an empty string |
|
| 777 | - if ($transaction->remaining() === 0) { |
|
| 778 | - return ''; |
|
| 779 | - } |
|
| 780 | - $attrs = $this->_get_shortcode_attrs($shortcode); |
|
| 781 | - $format = isset($attrs['format']) ? $attrs['format'] : get_option('date_format'); |
|
| 782 | - $days_until_due = isset($attrs['days_until_due']) ? (int)$attrs['days_until_due'] : 30; |
|
| 783 | - $prefix_text = isset($attrs['prefix_text']) ? $attrs['prefix_text'] |
|
| 784 | - : esc_html__('Payment in full due by: ', 'event_espresso'); |
|
| 785 | - $transaction_created = $transaction->get_DateTime_object('TXN_timestamp'); |
|
| 786 | - //setup date due: |
|
| 787 | - try { |
|
| 788 | - if ($transaction_created instanceof DateTime) { |
|
| 789 | - $date_due = $transaction_created->add( |
|
| 790 | - new DateInterval('P' . $days_until_due . 'D') |
|
| 791 | - )->format($format); |
|
| 792 | - } else { |
|
| 793 | - throw new Exception(); |
|
| 794 | - } |
|
| 795 | - } catch (Exception $e) { |
|
| 796 | - //format was likely invalid. |
|
| 797 | - $date_due = esc_html__( |
|
| 798 | - 'Unable to calculate date due, likely the format string is invalid.', |
|
| 799 | - 'event_espresso' |
|
| 800 | - ); |
|
| 801 | - } |
|
| 802 | - return $prefix_text . $date_due; |
|
| 803 | - } |
|
| 702 | + } |
|
| 703 | + return ''; |
|
| 704 | + } |
|
| 705 | + |
|
| 706 | + |
|
| 707 | + /** |
|
| 708 | + * This returns a subtotal. |
|
| 709 | + * |
|
| 710 | + * @param bool $tax if true then return the subtotal for tax otherwise return subtotal. |
|
| 711 | + * @return int |
|
| 712 | + * @throws EE_Error |
|
| 713 | + */ |
|
| 714 | + private function _get_subtotal($tax = false) |
|
| 715 | + { |
|
| 716 | + $grand_total = isset($this->_data->grand_total_line_item) ? $this->_data->grand_total_line_item : null; |
|
| 717 | + if (! $grand_total instanceof EE_Line_Item) { |
|
| 718 | + return 0; |
|
| 719 | + } |
|
| 720 | + return $tax ? $grand_total->get_total_tax() : $grand_total->get_items_total(); |
|
| 721 | + } |
|
| 722 | + |
|
| 723 | + |
|
| 724 | + /** |
|
| 725 | + * parser for the [PAYMENT_LINK_IF_NEEDED_*] attribute type shortcode |
|
| 726 | + * |
|
| 727 | + * @since 4.7.0 |
|
| 728 | + * @param string $shortcode the incoming shortcode |
|
| 729 | + * @return string parsed. |
|
| 730 | + * @throws EE_Error |
|
| 731 | + */ |
|
| 732 | + private function _get_payment_link_if_needed($shortcode) |
|
| 733 | + { |
|
| 734 | + $valid_shortcodes = array('transaction'); |
|
| 735 | + $attrs = $this->_get_shortcode_attrs($shortcode); |
|
| 736 | + //ensure default is set. |
|
| 737 | + $addressee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
|
| 738 | + $total_owing = $addressee instanceof EE_Messages_Addressee && $addressee->txn instanceof EE_Transaction |
|
| 739 | + ? $addressee->txn->remaining() : 0; |
|
| 740 | + if ($total_owing > 0) { |
|
| 741 | + $class = isset($attrs['class']) ? $attrs['class'] : 'callout'; |
|
| 742 | + $custom_text = isset($attrs['custom_text']) ? $attrs['custom_text'] : 'You can %smake a payment here »%s.'; |
|
| 743 | + $container_tag = isset($attrs['container_tag']) ? $attrs['container_tag'] : 'p'; |
|
| 744 | + $opening_tag = ! empty($container_tag) ? '<' . $container_tag : ''; |
|
| 745 | + $opening_tag .= ! empty($opening_tag) && ! empty($class) ? ' class="' . $class . '"' : $opening_tag; |
|
| 746 | + $opening_tag .= ! empty($opening_tag) ? '>' : $opening_tag; |
|
| 747 | + $closing_tag = ! empty($container_tag) ? '</' . $container_tag . '>' : ''; |
|
| 748 | + $content = $opening_tag . sprintf($custom_text, '<a href="[PAYMENT_URL]">', '</a>') . $closing_tag; |
|
| 749 | + //we need to re run this string through the parser to catch any shortcodes that are in it. |
|
| 750 | + $owing_content = $this->_shortcode_helper->parse_message_template( |
|
| 751 | + $content, |
|
| 752 | + $addressee, |
|
| 753 | + $valid_shortcodes, |
|
| 754 | + $this->_message_type, |
|
| 755 | + $this->_messenger, |
|
| 756 | + $this->_message |
|
| 757 | + ); |
|
| 758 | + } else { |
|
| 759 | + return ''; |
|
| 760 | + } |
|
| 761 | + return $owing_content; |
|
| 762 | + } |
|
| 763 | + |
|
| 764 | + |
|
| 765 | + /** |
|
| 766 | + * Parser for the [PAYMENT_DUE_DATE_*] attribute type shortcode |
|
| 767 | + * |
|
| 768 | + * @since 4.8.28.rc.011 |
|
| 769 | + * @param string $shortcode The shortcode being parsed. |
|
| 770 | + * @param EE_Transaction $transaction |
|
| 771 | + * @return string |
|
| 772 | + * @throws EE_Error |
|
| 773 | + */ |
|
| 774 | + protected function _get_payment_due_date($shortcode, EE_Transaction $transaction) |
|
| 775 | + { |
|
| 776 | + //if transaction is paid in full then we can just return an empty string |
|
| 777 | + if ($transaction->remaining() === 0) { |
|
| 778 | + return ''; |
|
| 779 | + } |
|
| 780 | + $attrs = $this->_get_shortcode_attrs($shortcode); |
|
| 781 | + $format = isset($attrs['format']) ? $attrs['format'] : get_option('date_format'); |
|
| 782 | + $days_until_due = isset($attrs['days_until_due']) ? (int)$attrs['days_until_due'] : 30; |
|
| 783 | + $prefix_text = isset($attrs['prefix_text']) ? $attrs['prefix_text'] |
|
| 784 | + : esc_html__('Payment in full due by: ', 'event_espresso'); |
|
| 785 | + $transaction_created = $transaction->get_DateTime_object('TXN_timestamp'); |
|
| 786 | + //setup date due: |
|
| 787 | + try { |
|
| 788 | + if ($transaction_created instanceof DateTime) { |
|
| 789 | + $date_due = $transaction_created->add( |
|
| 790 | + new DateInterval('P' . $days_until_due . 'D') |
|
| 791 | + )->format($format); |
|
| 792 | + } else { |
|
| 793 | + throw new Exception(); |
|
| 794 | + } |
|
| 795 | + } catch (Exception $e) { |
|
| 796 | + //format was likely invalid. |
|
| 797 | + $date_due = esc_html__( |
|
| 798 | + 'Unable to calculate date due, likely the format string is invalid.', |
|
| 799 | + 'event_espresso' |
|
| 800 | + ); |
|
| 801 | + } |
|
| 802 | + return $prefix_text . $date_due; |
|
| 803 | + } |
|
| 804 | 804 | |
| 805 | 805 | } |
@@ -16,616 +16,616 @@ |
||
| 16 | 16 | class EE_SPCO_Line_Item_Display_Strategy implements EEI_Line_Item_Display |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * array of events |
|
| 21 | - * |
|
| 22 | - * @type EE_Line_Item[] $_events |
|
| 23 | - */ |
|
| 24 | - private $_events = array(); |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * whether to display the taxes row or not |
|
| 28 | - * |
|
| 29 | - * @type bool $_show_taxes |
|
| 30 | - */ |
|
| 31 | - private $_show_taxes = false; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * html for any tax rows |
|
| 35 | - * |
|
| 36 | - * @type string $_show_taxes |
|
| 37 | - */ |
|
| 38 | - private $_taxes_html = ''; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * total amount including tax we can bill for at this time |
|
| 42 | - * |
|
| 43 | - * @type float $_grand_total |
|
| 44 | - */ |
|
| 45 | - private $_grand_total = 0.00; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * total number of items being billed for |
|
| 49 | - * |
|
| 50 | - * @type int $_total_items |
|
| 51 | - */ |
|
| 52 | - private $_total_items = 0; |
|
| 53 | - |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @return float |
|
| 58 | - */ |
|
| 59 | - public function grand_total() |
|
| 60 | - { |
|
| 61 | - return $this->_grand_total; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * @return int |
|
| 68 | - */ |
|
| 69 | - public function total_items() |
|
| 70 | - { |
|
| 71 | - return $this->_total_items; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * @param EE_Line_Item $line_item |
|
| 78 | - * @param array $options |
|
| 79 | - * @param EE_Line_Item $parent_line_item |
|
| 80 | - * @return mixed |
|
| 81 | - * @throws EE_Error |
|
| 82 | - */ |
|
| 83 | - public function display_line_item( |
|
| 84 | - EE_Line_Item $line_item, |
|
| 85 | - $options = array(), |
|
| 86 | - EE_Line_Item $parent_line_item = null |
|
| 87 | - ) { |
|
| 88 | - $html = ''; |
|
| 89 | - // set some default options and merge with incoming |
|
| 90 | - $default_options = array( |
|
| 91 | - 'show_desc' => true, // true false |
|
| 92 | - 'odd' => false, |
|
| 93 | - ); |
|
| 94 | - $options = array_merge($default_options, (array)$options); |
|
| 95 | - switch ($line_item->type()) { |
|
| 96 | - case EEM_Line_Item::type_line_item: |
|
| 97 | - $this->_show_taxes = $line_item->is_taxable() ? true : $this->_show_taxes; |
|
| 98 | - if ($line_item->OBJ_type() === 'Ticket') { |
|
| 99 | - // item row |
|
| 100 | - $html .= $this->_ticket_row($line_item, $options); |
|
| 101 | - } else { |
|
| 102 | - // item row |
|
| 103 | - $html .= $this->_item_row($line_item, $options); |
|
| 104 | - } |
|
| 105 | - if ( |
|
| 106 | - apply_filters( |
|
| 107 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy__display_line_item__display_sub_line_items', |
|
| 108 | - true |
|
| 109 | - ) |
|
| 110 | - ) { |
|
| 111 | - // got any kids? |
|
| 112 | - foreach ($line_item->children() as $child_line_item) { |
|
| 113 | - $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - break; |
|
| 117 | - case EEM_Line_Item::type_sub_line_item: |
|
| 118 | - $html .= $this->_sub_item_row($line_item, $options, $parent_line_item); |
|
| 119 | - break; |
|
| 120 | - case EEM_Line_Item::type_sub_total: |
|
| 121 | - static $sub_total = 0; |
|
| 122 | - $event_sub_total = 0; |
|
| 123 | - $text = esc_html__('Sub-Total', 'event_espresso'); |
|
| 124 | - if ($line_item->OBJ_type() === 'Event') { |
|
| 125 | - $options['event_id'] = $event_id = $line_item->OBJ_ID(); |
|
| 126 | - if (! isset($this->_events[$options['event_id']])) { |
|
| 127 | - $event = EEM_Event::instance()->get_one_by_ID($options['event_id']); |
|
| 128 | - // if event has default reg status of Not Approved, then don't display info on it |
|
| 129 | - if ( |
|
| 130 | - $event instanceof EE_Event |
|
| 131 | - && $event->default_registration_status() === EEM_Registration::status_id_not_approved |
|
| 132 | - ) { |
|
| 133 | - $display_event = false; |
|
| 134 | - // unless there are registrations for it that are returning to pay |
|
| 135 | - if (isset($options['registrations']) && is_array($options['registrations'])) { |
|
| 136 | - foreach ($options['registrations'] as $registration) { |
|
| 137 | - if (! $registration instanceof EE_Registration) { |
|
| 138 | - continue; |
|
| 139 | - } |
|
| 140 | - $display_event = $registration->event_ID() === $options['event_id'] |
|
| 141 | - && $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
| 142 | - ? true |
|
| 143 | - : $display_event; |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - if (! $display_event) { |
|
| 147 | - return ''; |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - $this->_events[$options['event_id']] = 0; |
|
| 151 | - $html .= $this->_event_row($line_item); |
|
| 152 | - $text = esc_html__('Event Sub-Total', 'event_espresso'); |
|
| 153 | - } |
|
| 154 | - } |
|
| 155 | - $child_line_items = $line_item->children(); |
|
| 156 | - // loop thru children |
|
| 157 | - foreach ($child_line_items as $child_line_item) { |
|
| 158 | - // recursively feed children back into this method |
|
| 159 | - $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
| 160 | - } |
|
| 161 | - $event_sub_total += isset($options['event_id']) ? $this->_events[$options['event_id']] : 0; |
|
| 162 | - $sub_total += $event_sub_total; |
|
| 163 | - if ( |
|
| 164 | - ( |
|
| 165 | - // event subtotals |
|
| 166 | - $line_item->code() !== 'pre-tax-subtotal' && count($child_line_items) > 1 |
|
| 167 | - ) |
|
| 168 | - || ( |
|
| 169 | - // pre-tax subtotals |
|
| 170 | - $line_item->code() === 'pre-tax-subtotal' && count($this->_events) > 1 |
|
| 171 | - ) |
|
| 172 | - ) { |
|
| 173 | - $options['sub_total'] = $line_item->OBJ_type() === 'Event' ? $event_sub_total : $sub_total; |
|
| 174 | - $html .= $this->_sub_total_row($line_item, $text, $options); |
|
| 175 | - } |
|
| 176 | - break; |
|
| 177 | - case EEM_Line_Item::type_tax: |
|
| 178 | - if ($this->_show_taxes) { |
|
| 179 | - $this->_taxes_html .= $this->_tax_row($line_item, $options); |
|
| 180 | - } |
|
| 181 | - break; |
|
| 182 | - case EEM_Line_Item::type_tax_sub_total: |
|
| 183 | - if ($this->_show_taxes) { |
|
| 184 | - $child_line_items = $line_item->children(); |
|
| 185 | - // loop thru children |
|
| 186 | - foreach ($child_line_items as $child_line_item) { |
|
| 187 | - // recursively feed children back into this method |
|
| 188 | - $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
| 189 | - } |
|
| 190 | - if (count($child_line_items) > 1) { |
|
| 191 | - $this->_taxes_html .= $this->_total_tax_row($line_item, esc_html__('Tax Total', 'event_espresso')); |
|
| 192 | - } |
|
| 193 | - } |
|
| 194 | - break; |
|
| 195 | - case EEM_Line_Item::type_total: |
|
| 196 | - // get all child line items |
|
| 197 | - $children = $line_item->children(); |
|
| 198 | - // loop thru all non-tax child line items |
|
| 199 | - foreach ($children as $child_line_item) { |
|
| 200 | - if ($child_line_item->type() !== EEM_Line_Item::type_tax_sub_total) { |
|
| 201 | - // recursively feed children back into this method |
|
| 202 | - $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
| 203 | - } |
|
| 204 | - } |
|
| 205 | - // now loop thru tax child line items |
|
| 206 | - foreach ($children as $child_line_item) { |
|
| 207 | - if ($child_line_item->type() === EEM_Line_Item::type_tax_sub_total) { |
|
| 208 | - // recursively feed children back into this method |
|
| 209 | - $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
| 210 | - } |
|
| 211 | - } |
|
| 212 | - $html .= $this->_taxes_html; |
|
| 213 | - $html .= $this->_total_row($line_item, esc_html__('Total', 'event_espresso')); |
|
| 214 | - $html .= $this->_payments_and_amount_owing_rows($line_item, $options); |
|
| 215 | - break; |
|
| 216 | - } |
|
| 217 | - return $html; |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - |
|
| 221 | - |
|
| 222 | - /** |
|
| 223 | - * _event_row - basically a Heading row displayed once above each event's ticket rows |
|
| 224 | - * |
|
| 225 | - * @param EE_Line_Item $line_item |
|
| 226 | - * @return mixed |
|
| 227 | - */ |
|
| 228 | - private function _event_row(EE_Line_Item $line_item) |
|
| 229 | - { |
|
| 230 | - // start of row |
|
| 231 | - $html = EEH_HTML::tr('', 'event-cart-total-row', 'total_tr odd'); |
|
| 232 | - // event name td |
|
| 233 | - $html .= EEH_HTML::td( |
|
| 234 | - EEH_HTML::strong($line_item->name()), |
|
| 235 | - '', |
|
| 236 | - 'event-header', |
|
| 237 | - '', |
|
| 238 | - ' colspan="4"' |
|
| 239 | - ); |
|
| 240 | - // end of row |
|
| 241 | - $html .= EEH_HTML::trx(); |
|
| 242 | - return $html; |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - |
|
| 246 | - |
|
| 247 | - /** |
|
| 248 | - * _ticket_row |
|
| 249 | - * |
|
| 250 | - * @param EE_Line_Item $line_item |
|
| 251 | - * @param array $options |
|
| 252 | - * @return mixed |
|
| 253 | - * @throws EE_Error |
|
| 254 | - */ |
|
| 255 | - private function _ticket_row(EE_Line_Item $line_item, $options = array()) |
|
| 256 | - { |
|
| 257 | - // start of row |
|
| 258 | - $row_class = $options['odd'] ? 'item odd' : 'item'; |
|
| 259 | - $html = EEH_HTML::tr('', '', $row_class); |
|
| 260 | - // name && desc |
|
| 261 | - $name_and_desc = apply_filters( |
|
| 262 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name', |
|
| 263 | - $line_item->name(), |
|
| 264 | - $line_item |
|
| 265 | - ); |
|
| 266 | - $name_and_desc .= apply_filters( |
|
| 267 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc', |
|
| 268 | - ( |
|
| 269 | - $options['show_desc'] |
|
| 270 | - ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' |
|
| 271 | - : '' |
|
| 272 | - ), |
|
| 273 | - $line_item, |
|
| 274 | - $options |
|
| 275 | - ); |
|
| 276 | - $name_and_desc .= $line_item->is_taxable() ? ' * ' : ''; |
|
| 277 | - // name td |
|
| 278 | - $html .= EEH_HTML::td( /*__FUNCTION__ .*/ |
|
| 279 | - $name_and_desc, '', 'item_l'); |
|
| 280 | - // price td |
|
| 281 | - $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght'); |
|
| 282 | - // quantity td |
|
| 283 | - $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght'); |
|
| 284 | - $this->_total_items += $line_item->quantity(); |
|
| 285 | - // determine total for line item |
|
| 286 | - $total = $line_item->total(); |
|
| 287 | - $this->_events[$options['event_id']] += $total; |
|
| 288 | - // total td |
|
| 289 | - $html .= EEH_HTML::td( |
|
| 290 | - EEH_Template::format_currency($total, false, false), |
|
| 291 | - '', |
|
| 292 | - 'item_r jst-rght' |
|
| 293 | - ); |
|
| 294 | - // end of row |
|
| 295 | - $html .= EEH_HTML::trx(); |
|
| 296 | - return $html; |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - |
|
| 300 | - |
|
| 301 | - /** |
|
| 302 | - * _item_row |
|
| 303 | - * |
|
| 304 | - * @param EE_Line_Item $line_item |
|
| 305 | - * @param array $options |
|
| 306 | - * @return mixed |
|
| 307 | - * @throws EE_Error |
|
| 308 | - */ |
|
| 309 | - private function _item_row(EE_Line_Item $line_item, $options = array()) |
|
| 310 | - { |
|
| 311 | - // start of row |
|
| 312 | - $row_class = $options['odd'] ? 'item odd' : 'item'; |
|
| 313 | - $html = EEH_HTML::tr('', '', $row_class); |
|
| 314 | - $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() . ': ' : ''; |
|
| 315 | - // name && desc |
|
| 316 | - $name_and_desc = apply_filters( |
|
| 317 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name', |
|
| 318 | - $obj_name . $line_item->name(), |
|
| 319 | - $line_item |
|
| 320 | - ); |
|
| 321 | - $name_and_desc .= apply_filters( |
|
| 322 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc', |
|
| 323 | - ( |
|
| 324 | - $options['show_desc'] |
|
| 325 | - ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' |
|
| 326 | - : '' |
|
| 327 | - ), |
|
| 328 | - $line_item, |
|
| 329 | - $options |
|
| 330 | - ); |
|
| 331 | - $name_and_desc .= $line_item->is_taxable() ? ' * ' : ''; |
|
| 332 | - // name td |
|
| 333 | - $html .= EEH_HTML::td($name_and_desc, '', 'item_l'); |
|
| 334 | - // price td |
|
| 335 | - if ($line_item->is_percent()) { |
|
| 336 | - $html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c jst-rght'); |
|
| 337 | - } else { |
|
| 338 | - $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght'); |
|
| 339 | - } |
|
| 340 | - // quantity td |
|
| 341 | - $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght'); |
|
| 342 | - //$total = $line_item->total() * $line_item->quantity(); |
|
| 343 | - $total = $line_item->total(); |
|
| 344 | - if (isset($options['event_id'], $this->_events[$options['event_id']])) { |
|
| 345 | - $this->_events[$options['event_id']] += $total; |
|
| 346 | - } |
|
| 347 | - // total td |
|
| 348 | - $html .= EEH_HTML::td( |
|
| 349 | - EEH_Template::format_currency($total, false, false), |
|
| 350 | - '', |
|
| 351 | - 'item_r jst-rght' |
|
| 352 | - ); |
|
| 353 | - // end of row |
|
| 354 | - $html .= EEH_HTML::trx(); |
|
| 355 | - return $html; |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - |
|
| 359 | - |
|
| 360 | - /** |
|
| 361 | - * _sub_item_row |
|
| 362 | - * |
|
| 363 | - * @param EE_Line_Item $line_item |
|
| 364 | - * @param array $options |
|
| 365 | - * @param EE_Line_Item $parent_line_item |
|
| 366 | - * @return mixed |
|
| 367 | - * @throws EE_Error |
|
| 368 | - */ |
|
| 369 | - private function _sub_item_row(EE_Line_Item $line_item, $options = array(), EE_Line_Item $parent_line_item = null) |
|
| 370 | - { |
|
| 371 | - if( |
|
| 372 | - $parent_line_item instanceof EE_Line_Item |
|
| 373 | - && $line_item->children() === array() |
|
| 374 | - && $line_item->name() === $parent_line_item->name() |
|
| 375 | - ) { |
|
| 376 | - return ''; |
|
| 377 | - } |
|
| 378 | - // start of row |
|
| 379 | - $html = EEH_HTML::tr('', '', 'item sub-item-row'); |
|
| 380 | - // name && desc |
|
| 381 | - $name_and_desc = EEH_HTML::span('', '', 'sub-item-row-bullet dashicons dashicons-arrow-right') |
|
| 382 | - . $line_item->name(); |
|
| 383 | - $name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: ' |
|
| 384 | - . $line_item->desc() |
|
| 385 | - . '</span>' : ''; |
|
| 386 | - // name td |
|
| 387 | - $html .= EEH_HTML::td( $name_and_desc, '', 'item_l sub-item'); |
|
| 388 | - $qty = $parent_line_item instanceof EE_Line_Item ? $parent_line_item->quantity() : 1; |
|
| 389 | - // discount/surcharge td |
|
| 390 | - if ($line_item->is_percent()) { |
|
| 391 | - $html .= EEH_HTML::td( |
|
| 392 | - EEH_Template::format_currency( |
|
| 393 | - $line_item->total() / $qty, |
|
| 394 | - false, false |
|
| 395 | - ), |
|
| 396 | - '', 'item_c jst-rght' |
|
| 397 | - ); |
|
| 398 | - } else { |
|
| 399 | - $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght'); |
|
| 400 | - } |
|
| 401 | - // no quantity td |
|
| 402 | - $html .= EEH_HTML::td(); |
|
| 403 | - // no total td |
|
| 404 | - $html .= EEH_HTML::td(); |
|
| 405 | - // end of row |
|
| 406 | - $html .= EEH_HTML::trx(); |
|
| 407 | - return $html; |
|
| 408 | - } |
|
| 409 | - |
|
| 410 | - |
|
| 411 | - |
|
| 412 | - /** |
|
| 413 | - * _tax_row |
|
| 414 | - * |
|
| 415 | - * @param EE_Line_Item $line_item |
|
| 416 | - * @param array $options |
|
| 417 | - * @return mixed |
|
| 418 | - * @throws EE_Error |
|
| 419 | - */ |
|
| 420 | - private function _tax_row(EE_Line_Item $line_item, $options = array()) |
|
| 421 | - { |
|
| 422 | - // start of row |
|
| 423 | - $html = EEH_HTML::tr('', 'item sub-item tax-total'); |
|
| 424 | - // name && desc |
|
| 425 | - $name_and_desc = $line_item->name(); |
|
| 426 | - $name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">' |
|
| 427 | - . esc_html__(' * taxable items', 'event_espresso') . '</span>'; |
|
| 428 | - $name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : ''; |
|
| 429 | - // name td |
|
| 430 | - $html .= EEH_HTML::td( /*__FUNCTION__ .*/ |
|
| 431 | - $name_and_desc, '', 'item_l sub-item'); |
|
| 432 | - // percent td |
|
| 433 | - $html .= EEH_HTML::td($line_item->percent() . '%', '', ' jst-rght', ''); |
|
| 434 | - // empty td (price) |
|
| 435 | - $html .= EEH_HTML::td(EEH_HTML::nbsp()); |
|
| 436 | - // total td |
|
| 437 | - $html .= EEH_HTML::td(EEH_Template::format_currency( |
|
| 438 | - $line_item->total(), false, false), |
|
| 439 | - '', |
|
| 440 | - 'item_r jst-rght' |
|
| 441 | - ); |
|
| 442 | - // end of row |
|
| 443 | - $html .= EEH_HTML::trx(); |
|
| 444 | - return $html; |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - |
|
| 448 | - |
|
| 449 | - /** |
|
| 450 | - * _total_row |
|
| 451 | - * |
|
| 452 | - * @param EE_Line_Item $line_item |
|
| 453 | - * @param string $text |
|
| 454 | - * @return mixed |
|
| 455 | - * @throws EE_Error |
|
| 456 | - */ |
|
| 457 | - private function _total_tax_row(EE_Line_Item $line_item, $text = '') |
|
| 458 | - { |
|
| 459 | - $html = ''; |
|
| 460 | - if ($line_item->total()) { |
|
| 461 | - // start of row |
|
| 462 | - $html = EEH_HTML::tr('', '', 'total_tr odd'); |
|
| 463 | - // total td |
|
| 464 | - $html .= EEH_HTML::td( |
|
| 465 | - $text, |
|
| 466 | - '', |
|
| 467 | - 'total_currency total jst-rght', |
|
| 468 | - '', |
|
| 469 | - ' colspan="2"' |
|
| 470 | - ); |
|
| 471 | - // empty td (price) |
|
| 472 | - $html .= EEH_HTML::td(EEH_HTML::nbsp()); |
|
| 473 | - // total td |
|
| 474 | - $html .= EEH_HTML::td( |
|
| 475 | - EEH_Template::format_currency($line_item->total(), false, false), |
|
| 476 | - '', |
|
| 477 | - 'total jst-rght' |
|
| 478 | - ); |
|
| 479 | - // end of row |
|
| 480 | - $html .= EEH_HTML::trx(); |
|
| 481 | - } |
|
| 482 | - return $html; |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - |
|
| 486 | - |
|
| 487 | - /** |
|
| 488 | - * _total_row |
|
| 489 | - * |
|
| 490 | - * @param EE_Line_Item $line_item |
|
| 491 | - * @param string $text |
|
| 492 | - * @param array $options |
|
| 493 | - * @return mixed |
|
| 494 | - * @throws EE_Error |
|
| 495 | - */ |
|
| 496 | - private function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array()) |
|
| 497 | - { |
|
| 498 | - $html = ''; |
|
| 499 | - if ($line_item->total()) { |
|
| 500 | - // start of row |
|
| 501 | - $html = EEH_HTML::tr('', '', 'total_tr odd'); |
|
| 502 | - // total td |
|
| 503 | - $html .= EEH_HTML::td( |
|
| 504 | - $text, |
|
| 505 | - '', |
|
| 506 | - 'total_currency total jst-rght', |
|
| 507 | - '', |
|
| 508 | - ' colspan="3"' |
|
| 509 | - ); |
|
| 510 | - // total td |
|
| 511 | - $html .= EEH_HTML::td( |
|
| 512 | - EEH_Template::format_currency($options['sub_total'], false, false), |
|
| 513 | - '', |
|
| 514 | - 'total jst-rght' |
|
| 515 | - ); |
|
| 516 | - // end of row |
|
| 517 | - $html .= EEH_HTML::trx(); |
|
| 518 | - } |
|
| 519 | - return $html; |
|
| 520 | - } |
|
| 521 | - |
|
| 522 | - |
|
| 523 | - |
|
| 524 | - /** |
|
| 525 | - * _total_row |
|
| 526 | - * |
|
| 527 | - * @param EE_Line_Item $line_item |
|
| 528 | - * @param string $text |
|
| 529 | - * @return mixed |
|
| 530 | - * @throws EE_Error |
|
| 531 | - */ |
|
| 532 | - private function _total_row(EE_Line_Item $line_item, $text = '') |
|
| 533 | - { |
|
| 534 | - // start of row |
|
| 535 | - $html = EEH_HTML::tr('', '', 'spco-grand-total total_tr odd'); |
|
| 536 | - // total td |
|
| 537 | - $html .= EEH_HTML::td($text, '', 'total_currency total jst-rght', '', ' colspan="3"'); |
|
| 538 | - // total td |
|
| 539 | - $html .= EEH_HTML::td( |
|
| 540 | - EEH_Template::format_currency($line_item->total(), false, false), |
|
| 541 | - '', |
|
| 542 | - 'total jst-rght' |
|
| 543 | - ); |
|
| 544 | - // end of row |
|
| 545 | - $html .= EEH_HTML::trx(); |
|
| 546 | - return $html; |
|
| 547 | - } |
|
| 548 | - |
|
| 549 | - |
|
| 550 | - |
|
| 551 | - /** |
|
| 552 | - * _payments_and_amount_owing_rows |
|
| 553 | - * |
|
| 554 | - * @param EE_Line_Item $line_item |
|
| 555 | - * @param array $options |
|
| 556 | - * @return mixed |
|
| 557 | - * @throws EE_Error |
|
| 558 | - */ |
|
| 559 | - private function _payments_and_amount_owing_rows(EE_Line_Item $line_item, $options = array()) |
|
| 560 | - { |
|
| 561 | - $html = ''; |
|
| 562 | - $owing = $line_item->total(); |
|
| 563 | - $transaction = EEM_Transaction::instance()->get_one_by_ID($line_item->TXN_ID()); |
|
| 564 | - if ($transaction instanceof EE_Transaction) { |
|
| 565 | - $registration_payments = array(); |
|
| 566 | - $registrations = ! empty($options['registrations']) |
|
| 567 | - ? $options['registrations'] |
|
| 568 | - : $transaction->registrations(); |
|
| 569 | - foreach ($registrations as $registration) { |
|
| 570 | - if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) { |
|
| 571 | - $registration_payments += $registration->registration_payments(); |
|
| 572 | - } |
|
| 573 | - } |
|
| 574 | - if (! empty($registration_payments)) { |
|
| 575 | - foreach ($registration_payments as $registration_payment) { |
|
| 576 | - if ($registration_payment instanceof EE_Registration_Payment) { |
|
| 577 | - $owing -= $registration_payment->amount(); |
|
| 578 | - $payment = $registration_payment->payment(); |
|
| 579 | - $payment_desc = ''; |
|
| 580 | - if ($payment instanceof EE_Payment) { |
|
| 581 | - $payment_desc = sprintf( |
|
| 582 | - esc_html__('Payment%1$s Received: %2$s', 'event_espresso'), |
|
| 583 | - $payment->txn_id_chq_nmbr() !== '' |
|
| 584 | - ? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> ' |
|
| 585 | - : '', |
|
| 586 | - $payment->timestamp() |
|
| 587 | - ); |
|
| 588 | - } |
|
| 589 | - // start of row |
|
| 590 | - $html .= EEH_HTML::tr('', '', 'total_tr odd'); |
|
| 591 | - // payment desc |
|
| 592 | - $html .= EEH_HTML::td($payment_desc, '', '', '', ' colspan="3"'); |
|
| 593 | - // total td |
|
| 594 | - $html .= EEH_HTML::td( |
|
| 595 | - EEH_Template::format_currency( |
|
| 596 | - $registration_payment->amount(), |
|
| 597 | - false, |
|
| 598 | - false |
|
| 599 | - ), |
|
| 600 | - '', |
|
| 601 | - 'total jst-rght' |
|
| 602 | - ); |
|
| 603 | - // end of row |
|
| 604 | - $html .= EEH_HTML::trx(); |
|
| 605 | - } |
|
| 606 | - } |
|
| 607 | - if ($line_item->total()) { |
|
| 608 | - // start of row |
|
| 609 | - $html .= EEH_HTML::tr('', '', 'total_tr odd'); |
|
| 610 | - // total td |
|
| 611 | - $html .= EEH_HTML::td( |
|
| 612 | - esc_html__('Amount Owing', 'event_espresso'), |
|
| 613 | - '', 'total_currency total jst-rght', '', ' colspan="3"' |
|
| 614 | - ); |
|
| 615 | - // total td |
|
| 616 | - $html .= EEH_HTML::td( |
|
| 617 | - EEH_Template::format_currency($owing, false, false), |
|
| 618 | - '', |
|
| 619 | - 'total jst-rght' |
|
| 620 | - ); |
|
| 621 | - // end of row |
|
| 622 | - $html .= EEH_HTML::trx(); |
|
| 623 | - } |
|
| 624 | - } |
|
| 625 | - } |
|
| 626 | - $this->_grand_total = $owing; |
|
| 627 | - return $html; |
|
| 628 | - } |
|
| 19 | + /** |
|
| 20 | + * array of events |
|
| 21 | + * |
|
| 22 | + * @type EE_Line_Item[] $_events |
|
| 23 | + */ |
|
| 24 | + private $_events = array(); |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * whether to display the taxes row or not |
|
| 28 | + * |
|
| 29 | + * @type bool $_show_taxes |
|
| 30 | + */ |
|
| 31 | + private $_show_taxes = false; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * html for any tax rows |
|
| 35 | + * |
|
| 36 | + * @type string $_show_taxes |
|
| 37 | + */ |
|
| 38 | + private $_taxes_html = ''; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * total amount including tax we can bill for at this time |
|
| 42 | + * |
|
| 43 | + * @type float $_grand_total |
|
| 44 | + */ |
|
| 45 | + private $_grand_total = 0.00; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * total number of items being billed for |
|
| 49 | + * |
|
| 50 | + * @type int $_total_items |
|
| 51 | + */ |
|
| 52 | + private $_total_items = 0; |
|
| 53 | + |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @return float |
|
| 58 | + */ |
|
| 59 | + public function grand_total() |
|
| 60 | + { |
|
| 61 | + return $this->_grand_total; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @return int |
|
| 68 | + */ |
|
| 69 | + public function total_items() |
|
| 70 | + { |
|
| 71 | + return $this->_total_items; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * @param EE_Line_Item $line_item |
|
| 78 | + * @param array $options |
|
| 79 | + * @param EE_Line_Item $parent_line_item |
|
| 80 | + * @return mixed |
|
| 81 | + * @throws EE_Error |
|
| 82 | + */ |
|
| 83 | + public function display_line_item( |
|
| 84 | + EE_Line_Item $line_item, |
|
| 85 | + $options = array(), |
|
| 86 | + EE_Line_Item $parent_line_item = null |
|
| 87 | + ) { |
|
| 88 | + $html = ''; |
|
| 89 | + // set some default options and merge with incoming |
|
| 90 | + $default_options = array( |
|
| 91 | + 'show_desc' => true, // true false |
|
| 92 | + 'odd' => false, |
|
| 93 | + ); |
|
| 94 | + $options = array_merge($default_options, (array)$options); |
|
| 95 | + switch ($line_item->type()) { |
|
| 96 | + case EEM_Line_Item::type_line_item: |
|
| 97 | + $this->_show_taxes = $line_item->is_taxable() ? true : $this->_show_taxes; |
|
| 98 | + if ($line_item->OBJ_type() === 'Ticket') { |
|
| 99 | + // item row |
|
| 100 | + $html .= $this->_ticket_row($line_item, $options); |
|
| 101 | + } else { |
|
| 102 | + // item row |
|
| 103 | + $html .= $this->_item_row($line_item, $options); |
|
| 104 | + } |
|
| 105 | + if ( |
|
| 106 | + apply_filters( |
|
| 107 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy__display_line_item__display_sub_line_items', |
|
| 108 | + true |
|
| 109 | + ) |
|
| 110 | + ) { |
|
| 111 | + // got any kids? |
|
| 112 | + foreach ($line_item->children() as $child_line_item) { |
|
| 113 | + $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + break; |
|
| 117 | + case EEM_Line_Item::type_sub_line_item: |
|
| 118 | + $html .= $this->_sub_item_row($line_item, $options, $parent_line_item); |
|
| 119 | + break; |
|
| 120 | + case EEM_Line_Item::type_sub_total: |
|
| 121 | + static $sub_total = 0; |
|
| 122 | + $event_sub_total = 0; |
|
| 123 | + $text = esc_html__('Sub-Total', 'event_espresso'); |
|
| 124 | + if ($line_item->OBJ_type() === 'Event') { |
|
| 125 | + $options['event_id'] = $event_id = $line_item->OBJ_ID(); |
|
| 126 | + if (! isset($this->_events[$options['event_id']])) { |
|
| 127 | + $event = EEM_Event::instance()->get_one_by_ID($options['event_id']); |
|
| 128 | + // if event has default reg status of Not Approved, then don't display info on it |
|
| 129 | + if ( |
|
| 130 | + $event instanceof EE_Event |
|
| 131 | + && $event->default_registration_status() === EEM_Registration::status_id_not_approved |
|
| 132 | + ) { |
|
| 133 | + $display_event = false; |
|
| 134 | + // unless there are registrations for it that are returning to pay |
|
| 135 | + if (isset($options['registrations']) && is_array($options['registrations'])) { |
|
| 136 | + foreach ($options['registrations'] as $registration) { |
|
| 137 | + if (! $registration instanceof EE_Registration) { |
|
| 138 | + continue; |
|
| 139 | + } |
|
| 140 | + $display_event = $registration->event_ID() === $options['event_id'] |
|
| 141 | + && $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
| 142 | + ? true |
|
| 143 | + : $display_event; |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + if (! $display_event) { |
|
| 147 | + return ''; |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + $this->_events[$options['event_id']] = 0; |
|
| 151 | + $html .= $this->_event_row($line_item); |
|
| 152 | + $text = esc_html__('Event Sub-Total', 'event_espresso'); |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + $child_line_items = $line_item->children(); |
|
| 156 | + // loop thru children |
|
| 157 | + foreach ($child_line_items as $child_line_item) { |
|
| 158 | + // recursively feed children back into this method |
|
| 159 | + $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
| 160 | + } |
|
| 161 | + $event_sub_total += isset($options['event_id']) ? $this->_events[$options['event_id']] : 0; |
|
| 162 | + $sub_total += $event_sub_total; |
|
| 163 | + if ( |
|
| 164 | + ( |
|
| 165 | + // event subtotals |
|
| 166 | + $line_item->code() !== 'pre-tax-subtotal' && count($child_line_items) > 1 |
|
| 167 | + ) |
|
| 168 | + || ( |
|
| 169 | + // pre-tax subtotals |
|
| 170 | + $line_item->code() === 'pre-tax-subtotal' && count($this->_events) > 1 |
|
| 171 | + ) |
|
| 172 | + ) { |
|
| 173 | + $options['sub_total'] = $line_item->OBJ_type() === 'Event' ? $event_sub_total : $sub_total; |
|
| 174 | + $html .= $this->_sub_total_row($line_item, $text, $options); |
|
| 175 | + } |
|
| 176 | + break; |
|
| 177 | + case EEM_Line_Item::type_tax: |
|
| 178 | + if ($this->_show_taxes) { |
|
| 179 | + $this->_taxes_html .= $this->_tax_row($line_item, $options); |
|
| 180 | + } |
|
| 181 | + break; |
|
| 182 | + case EEM_Line_Item::type_tax_sub_total: |
|
| 183 | + if ($this->_show_taxes) { |
|
| 184 | + $child_line_items = $line_item->children(); |
|
| 185 | + // loop thru children |
|
| 186 | + foreach ($child_line_items as $child_line_item) { |
|
| 187 | + // recursively feed children back into this method |
|
| 188 | + $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
| 189 | + } |
|
| 190 | + if (count($child_line_items) > 1) { |
|
| 191 | + $this->_taxes_html .= $this->_total_tax_row($line_item, esc_html__('Tax Total', 'event_espresso')); |
|
| 192 | + } |
|
| 193 | + } |
|
| 194 | + break; |
|
| 195 | + case EEM_Line_Item::type_total: |
|
| 196 | + // get all child line items |
|
| 197 | + $children = $line_item->children(); |
|
| 198 | + // loop thru all non-tax child line items |
|
| 199 | + foreach ($children as $child_line_item) { |
|
| 200 | + if ($child_line_item->type() !== EEM_Line_Item::type_tax_sub_total) { |
|
| 201 | + // recursively feed children back into this method |
|
| 202 | + $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | + // now loop thru tax child line items |
|
| 206 | + foreach ($children as $child_line_item) { |
|
| 207 | + if ($child_line_item->type() === EEM_Line_Item::type_tax_sub_total) { |
|
| 208 | + // recursively feed children back into this method |
|
| 209 | + $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
| 210 | + } |
|
| 211 | + } |
|
| 212 | + $html .= $this->_taxes_html; |
|
| 213 | + $html .= $this->_total_row($line_item, esc_html__('Total', 'event_espresso')); |
|
| 214 | + $html .= $this->_payments_and_amount_owing_rows($line_item, $options); |
|
| 215 | + break; |
|
| 216 | + } |
|
| 217 | + return $html; |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + |
|
| 221 | + |
|
| 222 | + /** |
|
| 223 | + * _event_row - basically a Heading row displayed once above each event's ticket rows |
|
| 224 | + * |
|
| 225 | + * @param EE_Line_Item $line_item |
|
| 226 | + * @return mixed |
|
| 227 | + */ |
|
| 228 | + private function _event_row(EE_Line_Item $line_item) |
|
| 229 | + { |
|
| 230 | + // start of row |
|
| 231 | + $html = EEH_HTML::tr('', 'event-cart-total-row', 'total_tr odd'); |
|
| 232 | + // event name td |
|
| 233 | + $html .= EEH_HTML::td( |
|
| 234 | + EEH_HTML::strong($line_item->name()), |
|
| 235 | + '', |
|
| 236 | + 'event-header', |
|
| 237 | + '', |
|
| 238 | + ' colspan="4"' |
|
| 239 | + ); |
|
| 240 | + // end of row |
|
| 241 | + $html .= EEH_HTML::trx(); |
|
| 242 | + return $html; |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + |
|
| 246 | + |
|
| 247 | + /** |
|
| 248 | + * _ticket_row |
|
| 249 | + * |
|
| 250 | + * @param EE_Line_Item $line_item |
|
| 251 | + * @param array $options |
|
| 252 | + * @return mixed |
|
| 253 | + * @throws EE_Error |
|
| 254 | + */ |
|
| 255 | + private function _ticket_row(EE_Line_Item $line_item, $options = array()) |
|
| 256 | + { |
|
| 257 | + // start of row |
|
| 258 | + $row_class = $options['odd'] ? 'item odd' : 'item'; |
|
| 259 | + $html = EEH_HTML::tr('', '', $row_class); |
|
| 260 | + // name && desc |
|
| 261 | + $name_and_desc = apply_filters( |
|
| 262 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name', |
|
| 263 | + $line_item->name(), |
|
| 264 | + $line_item |
|
| 265 | + ); |
|
| 266 | + $name_and_desc .= apply_filters( |
|
| 267 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc', |
|
| 268 | + ( |
|
| 269 | + $options['show_desc'] |
|
| 270 | + ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' |
|
| 271 | + : '' |
|
| 272 | + ), |
|
| 273 | + $line_item, |
|
| 274 | + $options |
|
| 275 | + ); |
|
| 276 | + $name_and_desc .= $line_item->is_taxable() ? ' * ' : ''; |
|
| 277 | + // name td |
|
| 278 | + $html .= EEH_HTML::td( /*__FUNCTION__ .*/ |
|
| 279 | + $name_and_desc, '', 'item_l'); |
|
| 280 | + // price td |
|
| 281 | + $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght'); |
|
| 282 | + // quantity td |
|
| 283 | + $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght'); |
|
| 284 | + $this->_total_items += $line_item->quantity(); |
|
| 285 | + // determine total for line item |
|
| 286 | + $total = $line_item->total(); |
|
| 287 | + $this->_events[$options['event_id']] += $total; |
|
| 288 | + // total td |
|
| 289 | + $html .= EEH_HTML::td( |
|
| 290 | + EEH_Template::format_currency($total, false, false), |
|
| 291 | + '', |
|
| 292 | + 'item_r jst-rght' |
|
| 293 | + ); |
|
| 294 | + // end of row |
|
| 295 | + $html .= EEH_HTML::trx(); |
|
| 296 | + return $html; |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + |
|
| 300 | + |
|
| 301 | + /** |
|
| 302 | + * _item_row |
|
| 303 | + * |
|
| 304 | + * @param EE_Line_Item $line_item |
|
| 305 | + * @param array $options |
|
| 306 | + * @return mixed |
|
| 307 | + * @throws EE_Error |
|
| 308 | + */ |
|
| 309 | + private function _item_row(EE_Line_Item $line_item, $options = array()) |
|
| 310 | + { |
|
| 311 | + // start of row |
|
| 312 | + $row_class = $options['odd'] ? 'item odd' : 'item'; |
|
| 313 | + $html = EEH_HTML::tr('', '', $row_class); |
|
| 314 | + $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() . ': ' : ''; |
|
| 315 | + // name && desc |
|
| 316 | + $name_and_desc = apply_filters( |
|
| 317 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name', |
|
| 318 | + $obj_name . $line_item->name(), |
|
| 319 | + $line_item |
|
| 320 | + ); |
|
| 321 | + $name_and_desc .= apply_filters( |
|
| 322 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc', |
|
| 323 | + ( |
|
| 324 | + $options['show_desc'] |
|
| 325 | + ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' |
|
| 326 | + : '' |
|
| 327 | + ), |
|
| 328 | + $line_item, |
|
| 329 | + $options |
|
| 330 | + ); |
|
| 331 | + $name_and_desc .= $line_item->is_taxable() ? ' * ' : ''; |
|
| 332 | + // name td |
|
| 333 | + $html .= EEH_HTML::td($name_and_desc, '', 'item_l'); |
|
| 334 | + // price td |
|
| 335 | + if ($line_item->is_percent()) { |
|
| 336 | + $html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c jst-rght'); |
|
| 337 | + } else { |
|
| 338 | + $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght'); |
|
| 339 | + } |
|
| 340 | + // quantity td |
|
| 341 | + $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght'); |
|
| 342 | + //$total = $line_item->total() * $line_item->quantity(); |
|
| 343 | + $total = $line_item->total(); |
|
| 344 | + if (isset($options['event_id'], $this->_events[$options['event_id']])) { |
|
| 345 | + $this->_events[$options['event_id']] += $total; |
|
| 346 | + } |
|
| 347 | + // total td |
|
| 348 | + $html .= EEH_HTML::td( |
|
| 349 | + EEH_Template::format_currency($total, false, false), |
|
| 350 | + '', |
|
| 351 | + 'item_r jst-rght' |
|
| 352 | + ); |
|
| 353 | + // end of row |
|
| 354 | + $html .= EEH_HTML::trx(); |
|
| 355 | + return $html; |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + |
|
| 359 | + |
|
| 360 | + /** |
|
| 361 | + * _sub_item_row |
|
| 362 | + * |
|
| 363 | + * @param EE_Line_Item $line_item |
|
| 364 | + * @param array $options |
|
| 365 | + * @param EE_Line_Item $parent_line_item |
|
| 366 | + * @return mixed |
|
| 367 | + * @throws EE_Error |
|
| 368 | + */ |
|
| 369 | + private function _sub_item_row(EE_Line_Item $line_item, $options = array(), EE_Line_Item $parent_line_item = null) |
|
| 370 | + { |
|
| 371 | + if( |
|
| 372 | + $parent_line_item instanceof EE_Line_Item |
|
| 373 | + && $line_item->children() === array() |
|
| 374 | + && $line_item->name() === $parent_line_item->name() |
|
| 375 | + ) { |
|
| 376 | + return ''; |
|
| 377 | + } |
|
| 378 | + // start of row |
|
| 379 | + $html = EEH_HTML::tr('', '', 'item sub-item-row'); |
|
| 380 | + // name && desc |
|
| 381 | + $name_and_desc = EEH_HTML::span('', '', 'sub-item-row-bullet dashicons dashicons-arrow-right') |
|
| 382 | + . $line_item->name(); |
|
| 383 | + $name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: ' |
|
| 384 | + . $line_item->desc() |
|
| 385 | + . '</span>' : ''; |
|
| 386 | + // name td |
|
| 387 | + $html .= EEH_HTML::td( $name_and_desc, '', 'item_l sub-item'); |
|
| 388 | + $qty = $parent_line_item instanceof EE_Line_Item ? $parent_line_item->quantity() : 1; |
|
| 389 | + // discount/surcharge td |
|
| 390 | + if ($line_item->is_percent()) { |
|
| 391 | + $html .= EEH_HTML::td( |
|
| 392 | + EEH_Template::format_currency( |
|
| 393 | + $line_item->total() / $qty, |
|
| 394 | + false, false |
|
| 395 | + ), |
|
| 396 | + '', 'item_c jst-rght' |
|
| 397 | + ); |
|
| 398 | + } else { |
|
| 399 | + $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght'); |
|
| 400 | + } |
|
| 401 | + // no quantity td |
|
| 402 | + $html .= EEH_HTML::td(); |
|
| 403 | + // no total td |
|
| 404 | + $html .= EEH_HTML::td(); |
|
| 405 | + // end of row |
|
| 406 | + $html .= EEH_HTML::trx(); |
|
| 407 | + return $html; |
|
| 408 | + } |
|
| 409 | + |
|
| 410 | + |
|
| 411 | + |
|
| 412 | + /** |
|
| 413 | + * _tax_row |
|
| 414 | + * |
|
| 415 | + * @param EE_Line_Item $line_item |
|
| 416 | + * @param array $options |
|
| 417 | + * @return mixed |
|
| 418 | + * @throws EE_Error |
|
| 419 | + */ |
|
| 420 | + private function _tax_row(EE_Line_Item $line_item, $options = array()) |
|
| 421 | + { |
|
| 422 | + // start of row |
|
| 423 | + $html = EEH_HTML::tr('', 'item sub-item tax-total'); |
|
| 424 | + // name && desc |
|
| 425 | + $name_and_desc = $line_item->name(); |
|
| 426 | + $name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">' |
|
| 427 | + . esc_html__(' * taxable items', 'event_espresso') . '</span>'; |
|
| 428 | + $name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : ''; |
|
| 429 | + // name td |
|
| 430 | + $html .= EEH_HTML::td( /*__FUNCTION__ .*/ |
|
| 431 | + $name_and_desc, '', 'item_l sub-item'); |
|
| 432 | + // percent td |
|
| 433 | + $html .= EEH_HTML::td($line_item->percent() . '%', '', ' jst-rght', ''); |
|
| 434 | + // empty td (price) |
|
| 435 | + $html .= EEH_HTML::td(EEH_HTML::nbsp()); |
|
| 436 | + // total td |
|
| 437 | + $html .= EEH_HTML::td(EEH_Template::format_currency( |
|
| 438 | + $line_item->total(), false, false), |
|
| 439 | + '', |
|
| 440 | + 'item_r jst-rght' |
|
| 441 | + ); |
|
| 442 | + // end of row |
|
| 443 | + $html .= EEH_HTML::trx(); |
|
| 444 | + return $html; |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + |
|
| 448 | + |
|
| 449 | + /** |
|
| 450 | + * _total_row |
|
| 451 | + * |
|
| 452 | + * @param EE_Line_Item $line_item |
|
| 453 | + * @param string $text |
|
| 454 | + * @return mixed |
|
| 455 | + * @throws EE_Error |
|
| 456 | + */ |
|
| 457 | + private function _total_tax_row(EE_Line_Item $line_item, $text = '') |
|
| 458 | + { |
|
| 459 | + $html = ''; |
|
| 460 | + if ($line_item->total()) { |
|
| 461 | + // start of row |
|
| 462 | + $html = EEH_HTML::tr('', '', 'total_tr odd'); |
|
| 463 | + // total td |
|
| 464 | + $html .= EEH_HTML::td( |
|
| 465 | + $text, |
|
| 466 | + '', |
|
| 467 | + 'total_currency total jst-rght', |
|
| 468 | + '', |
|
| 469 | + ' colspan="2"' |
|
| 470 | + ); |
|
| 471 | + // empty td (price) |
|
| 472 | + $html .= EEH_HTML::td(EEH_HTML::nbsp()); |
|
| 473 | + // total td |
|
| 474 | + $html .= EEH_HTML::td( |
|
| 475 | + EEH_Template::format_currency($line_item->total(), false, false), |
|
| 476 | + '', |
|
| 477 | + 'total jst-rght' |
|
| 478 | + ); |
|
| 479 | + // end of row |
|
| 480 | + $html .= EEH_HTML::trx(); |
|
| 481 | + } |
|
| 482 | + return $html; |
|
| 483 | + } |
|
| 484 | + |
|
| 485 | + |
|
| 486 | + |
|
| 487 | + /** |
|
| 488 | + * _total_row |
|
| 489 | + * |
|
| 490 | + * @param EE_Line_Item $line_item |
|
| 491 | + * @param string $text |
|
| 492 | + * @param array $options |
|
| 493 | + * @return mixed |
|
| 494 | + * @throws EE_Error |
|
| 495 | + */ |
|
| 496 | + private function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array()) |
|
| 497 | + { |
|
| 498 | + $html = ''; |
|
| 499 | + if ($line_item->total()) { |
|
| 500 | + // start of row |
|
| 501 | + $html = EEH_HTML::tr('', '', 'total_tr odd'); |
|
| 502 | + // total td |
|
| 503 | + $html .= EEH_HTML::td( |
|
| 504 | + $text, |
|
| 505 | + '', |
|
| 506 | + 'total_currency total jst-rght', |
|
| 507 | + '', |
|
| 508 | + ' colspan="3"' |
|
| 509 | + ); |
|
| 510 | + // total td |
|
| 511 | + $html .= EEH_HTML::td( |
|
| 512 | + EEH_Template::format_currency($options['sub_total'], false, false), |
|
| 513 | + '', |
|
| 514 | + 'total jst-rght' |
|
| 515 | + ); |
|
| 516 | + // end of row |
|
| 517 | + $html .= EEH_HTML::trx(); |
|
| 518 | + } |
|
| 519 | + return $html; |
|
| 520 | + } |
|
| 521 | + |
|
| 522 | + |
|
| 523 | + |
|
| 524 | + /** |
|
| 525 | + * _total_row |
|
| 526 | + * |
|
| 527 | + * @param EE_Line_Item $line_item |
|
| 528 | + * @param string $text |
|
| 529 | + * @return mixed |
|
| 530 | + * @throws EE_Error |
|
| 531 | + */ |
|
| 532 | + private function _total_row(EE_Line_Item $line_item, $text = '') |
|
| 533 | + { |
|
| 534 | + // start of row |
|
| 535 | + $html = EEH_HTML::tr('', '', 'spco-grand-total total_tr odd'); |
|
| 536 | + // total td |
|
| 537 | + $html .= EEH_HTML::td($text, '', 'total_currency total jst-rght', '', ' colspan="3"'); |
|
| 538 | + // total td |
|
| 539 | + $html .= EEH_HTML::td( |
|
| 540 | + EEH_Template::format_currency($line_item->total(), false, false), |
|
| 541 | + '', |
|
| 542 | + 'total jst-rght' |
|
| 543 | + ); |
|
| 544 | + // end of row |
|
| 545 | + $html .= EEH_HTML::trx(); |
|
| 546 | + return $html; |
|
| 547 | + } |
|
| 548 | + |
|
| 549 | + |
|
| 550 | + |
|
| 551 | + /** |
|
| 552 | + * _payments_and_amount_owing_rows |
|
| 553 | + * |
|
| 554 | + * @param EE_Line_Item $line_item |
|
| 555 | + * @param array $options |
|
| 556 | + * @return mixed |
|
| 557 | + * @throws EE_Error |
|
| 558 | + */ |
|
| 559 | + private function _payments_and_amount_owing_rows(EE_Line_Item $line_item, $options = array()) |
|
| 560 | + { |
|
| 561 | + $html = ''; |
|
| 562 | + $owing = $line_item->total(); |
|
| 563 | + $transaction = EEM_Transaction::instance()->get_one_by_ID($line_item->TXN_ID()); |
|
| 564 | + if ($transaction instanceof EE_Transaction) { |
|
| 565 | + $registration_payments = array(); |
|
| 566 | + $registrations = ! empty($options['registrations']) |
|
| 567 | + ? $options['registrations'] |
|
| 568 | + : $transaction->registrations(); |
|
| 569 | + foreach ($registrations as $registration) { |
|
| 570 | + if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) { |
|
| 571 | + $registration_payments += $registration->registration_payments(); |
|
| 572 | + } |
|
| 573 | + } |
|
| 574 | + if (! empty($registration_payments)) { |
|
| 575 | + foreach ($registration_payments as $registration_payment) { |
|
| 576 | + if ($registration_payment instanceof EE_Registration_Payment) { |
|
| 577 | + $owing -= $registration_payment->amount(); |
|
| 578 | + $payment = $registration_payment->payment(); |
|
| 579 | + $payment_desc = ''; |
|
| 580 | + if ($payment instanceof EE_Payment) { |
|
| 581 | + $payment_desc = sprintf( |
|
| 582 | + esc_html__('Payment%1$s Received: %2$s', 'event_espresso'), |
|
| 583 | + $payment->txn_id_chq_nmbr() !== '' |
|
| 584 | + ? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> ' |
|
| 585 | + : '', |
|
| 586 | + $payment->timestamp() |
|
| 587 | + ); |
|
| 588 | + } |
|
| 589 | + // start of row |
|
| 590 | + $html .= EEH_HTML::tr('', '', 'total_tr odd'); |
|
| 591 | + // payment desc |
|
| 592 | + $html .= EEH_HTML::td($payment_desc, '', '', '', ' colspan="3"'); |
|
| 593 | + // total td |
|
| 594 | + $html .= EEH_HTML::td( |
|
| 595 | + EEH_Template::format_currency( |
|
| 596 | + $registration_payment->amount(), |
|
| 597 | + false, |
|
| 598 | + false |
|
| 599 | + ), |
|
| 600 | + '', |
|
| 601 | + 'total jst-rght' |
|
| 602 | + ); |
|
| 603 | + // end of row |
|
| 604 | + $html .= EEH_HTML::trx(); |
|
| 605 | + } |
|
| 606 | + } |
|
| 607 | + if ($line_item->total()) { |
|
| 608 | + // start of row |
|
| 609 | + $html .= EEH_HTML::tr('', '', 'total_tr odd'); |
|
| 610 | + // total td |
|
| 611 | + $html .= EEH_HTML::td( |
|
| 612 | + esc_html__('Amount Owing', 'event_espresso'), |
|
| 613 | + '', 'total_currency total jst-rght', '', ' colspan="3"' |
|
| 614 | + ); |
|
| 615 | + // total td |
|
| 616 | + $html .= EEH_HTML::td( |
|
| 617 | + EEH_Template::format_currency($owing, false, false), |
|
| 618 | + '', |
|
| 619 | + 'total jst-rght' |
|
| 620 | + ); |
|
| 621 | + // end of row |
|
| 622 | + $html .= EEH_HTML::trx(); |
|
| 623 | + } |
|
| 624 | + } |
|
| 625 | + } |
|
| 626 | + $this->_grand_total = $owing; |
|
| 627 | + return $html; |
|
| 628 | + } |
|
| 629 | 629 | |
| 630 | 630 | |
| 631 | 631 | } |
@@ -88,10 +88,10 @@ discard block |
||
| 88 | 88 | $html = ''; |
| 89 | 89 | // set some default options and merge with incoming |
| 90 | 90 | $default_options = array( |
| 91 | - 'show_desc' => true, // true false |
|
| 91 | + 'show_desc' => true, // true false |
|
| 92 | 92 | 'odd' => false, |
| 93 | 93 | ); |
| 94 | - $options = array_merge($default_options, (array)$options); |
|
| 94 | + $options = array_merge($default_options, (array) $options); |
|
| 95 | 95 | switch ($line_item->type()) { |
| 96 | 96 | case EEM_Line_Item::type_line_item: |
| 97 | 97 | $this->_show_taxes = $line_item->is_taxable() ? true : $this->_show_taxes; |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | $text = esc_html__('Sub-Total', 'event_espresso'); |
| 124 | 124 | if ($line_item->OBJ_type() === 'Event') { |
| 125 | 125 | $options['event_id'] = $event_id = $line_item->OBJ_ID(); |
| 126 | - if (! isset($this->_events[$options['event_id']])) { |
|
| 126 | + if ( ! isset($this->_events[$options['event_id']])) { |
|
| 127 | 127 | $event = EEM_Event::instance()->get_one_by_ID($options['event_id']); |
| 128 | 128 | // if event has default reg status of Not Approved, then don't display info on it |
| 129 | 129 | if ( |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | // unless there are registrations for it that are returning to pay |
| 135 | 135 | if (isset($options['registrations']) && is_array($options['registrations'])) { |
| 136 | 136 | foreach ($options['registrations'] as $registration) { |
| 137 | - if (! $registration instanceof EE_Registration) { |
|
| 137 | + if ( ! $registration instanceof EE_Registration) { |
|
| 138 | 138 | continue; |
| 139 | 139 | } |
| 140 | 140 | $display_event = $registration->event_ID() === $options['event_id'] |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | : $display_event; |
| 144 | 144 | } |
| 145 | 145 | } |
| 146 | - if (! $display_event) { |
|
| 146 | + if ( ! $display_event) { |
|
| 147 | 147 | return ''; |
| 148 | 148 | } |
| 149 | 149 | } |
@@ -267,7 +267,7 @@ discard block |
||
| 267 | 267 | 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc', |
| 268 | 268 | ( |
| 269 | 269 | $options['show_desc'] |
| 270 | - ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' |
|
| 270 | + ? '<span class="line-item-desc-spn smaller-text">: '.$line_item->desc().'</span>' |
|
| 271 | 271 | : '' |
| 272 | 272 | ), |
| 273 | 273 | $line_item, |
@@ -311,18 +311,18 @@ discard block |
||
| 311 | 311 | // start of row |
| 312 | 312 | $row_class = $options['odd'] ? 'item odd' : 'item'; |
| 313 | 313 | $html = EEH_HTML::tr('', '', $row_class); |
| 314 | - $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() . ': ' : ''; |
|
| 314 | + $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n().': ' : ''; |
|
| 315 | 315 | // name && desc |
| 316 | 316 | $name_and_desc = apply_filters( |
| 317 | 317 | 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name', |
| 318 | - $obj_name . $line_item->name(), |
|
| 318 | + $obj_name.$line_item->name(), |
|
| 319 | 319 | $line_item |
| 320 | 320 | ); |
| 321 | 321 | $name_and_desc .= apply_filters( |
| 322 | 322 | 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc', |
| 323 | 323 | ( |
| 324 | 324 | $options['show_desc'] |
| 325 | - ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' |
|
| 325 | + ? '<span class="line-item-desc-spn smaller-text">: '.$line_item->desc().'</span>' |
|
| 326 | 326 | : '' |
| 327 | 327 | ), |
| 328 | 328 | $line_item, |
@@ -333,7 +333,7 @@ discard block |
||
| 333 | 333 | $html .= EEH_HTML::td($name_and_desc, '', 'item_l'); |
| 334 | 334 | // price td |
| 335 | 335 | if ($line_item->is_percent()) { |
| 336 | - $html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c jst-rght'); |
|
| 336 | + $html .= EEH_HTML::td($line_item->percent().'%', '', 'item_c jst-rght'); |
|
| 337 | 337 | } else { |
| 338 | 338 | $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght'); |
| 339 | 339 | } |
@@ -368,7 +368,7 @@ discard block |
||
| 368 | 368 | */ |
| 369 | 369 | private function _sub_item_row(EE_Line_Item $line_item, $options = array(), EE_Line_Item $parent_line_item = null) |
| 370 | 370 | { |
| 371 | - if( |
|
| 371 | + if ( |
|
| 372 | 372 | $parent_line_item instanceof EE_Line_Item |
| 373 | 373 | && $line_item->children() === array() |
| 374 | 374 | && $line_item->name() === $parent_line_item->name() |
@@ -384,7 +384,7 @@ discard block |
||
| 384 | 384 | . $line_item->desc() |
| 385 | 385 | . '</span>' : ''; |
| 386 | 386 | // name td |
| 387 | - $html .= EEH_HTML::td( $name_and_desc, '', 'item_l sub-item'); |
|
| 387 | + $html .= EEH_HTML::td($name_and_desc, '', 'item_l sub-item'); |
|
| 388 | 388 | $qty = $parent_line_item instanceof EE_Line_Item ? $parent_line_item->quantity() : 1; |
| 389 | 389 | // discount/surcharge td |
| 390 | 390 | if ($line_item->is_percent()) { |
@@ -424,13 +424,13 @@ discard block |
||
| 424 | 424 | // name && desc |
| 425 | 425 | $name_and_desc = $line_item->name(); |
| 426 | 426 | $name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">' |
| 427 | - . esc_html__(' * taxable items', 'event_espresso') . '</span>'; |
|
| 428 | - $name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : ''; |
|
| 427 | + . esc_html__(' * taxable items', 'event_espresso').'</span>'; |
|
| 428 | + $name_and_desc .= $options['show_desc'] ? '<br/>'.$line_item->desc() : ''; |
|
| 429 | 429 | // name td |
| 430 | 430 | $html .= EEH_HTML::td( /*__FUNCTION__ .*/ |
| 431 | 431 | $name_and_desc, '', 'item_l sub-item'); |
| 432 | 432 | // percent td |
| 433 | - $html .= EEH_HTML::td($line_item->percent() . '%', '', ' jst-rght', ''); |
|
| 433 | + $html .= EEH_HTML::td($line_item->percent().'%', '', ' jst-rght', ''); |
|
| 434 | 434 | // empty td (price) |
| 435 | 435 | $html .= EEH_HTML::td(EEH_HTML::nbsp()); |
| 436 | 436 | // total td |
@@ -571,7 +571,7 @@ discard block |
||
| 571 | 571 | $registration_payments += $registration->registration_payments(); |
| 572 | 572 | } |
| 573 | 573 | } |
| 574 | - if (! empty($registration_payments)) { |
|
| 574 | + if ( ! empty($registration_payments)) { |
|
| 575 | 575 | foreach ($registration_payments as $registration_payment) { |
| 576 | 576 | if ($registration_payment instanceof EE_Registration_Payment) { |
| 577 | 577 | $owing -= $registration_payment->amount(); |
@@ -581,7 +581,7 @@ discard block |
||
| 581 | 581 | $payment_desc = sprintf( |
| 582 | 582 | esc_html__('Payment%1$s Received: %2$s', 'event_espresso'), |
| 583 | 583 | $payment->txn_id_chq_nmbr() !== '' |
| 584 | - ? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> ' |
|
| 584 | + ? ' <span class="small-text">(#'.$payment->txn_id_chq_nmbr().')</span> ' |
|
| 585 | 585 | : '', |
| 586 | 586 | $payment->timestamp() |
| 587 | 587 | ); |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | */ |
| 129 | 129 | protected static function _set_hooks_for_changes() |
| 130 | 130 | { |
| 131 | - $folder_contents = EEH_File::get_contents_of_folders(array(EE_LIBRARIES . 'rest_api' . DS . 'changes'), false); |
|
| 131 | + $folder_contents = EEH_File::get_contents_of_folders(array(EE_LIBRARIES.'rest_api'.DS.'changes'), false); |
|
| 132 | 132 | foreach ($folder_contents as $classname_in_namespace => $filepath) { |
| 133 | 133 | //ignore the base parent class |
| 134 | 134 | //and legacy named classes |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | ) { |
| 138 | 138 | continue; |
| 139 | 139 | } |
| 140 | - $full_classname = 'EventEspresso\core\libraries\rest_api\changes\\' . $classname_in_namespace; |
|
| 140 | + $full_classname = 'EventEspresso\core\libraries\rest_api\changes\\'.$classname_in_namespace; |
|
| 141 | 141 | if (class_exists($full_classname)) { |
| 142 | 142 | $instance_of_class = new $full_classname; |
| 143 | 143 | if ($instance_of_class instanceof ChangesInBase) { |
@@ -183,10 +183,10 @@ discard block |
||
| 183 | 183 | * } |
| 184 | 184 | */ |
| 185 | 185 | //skip route options |
| 186 | - if (! is_numeric($endpoint_key)) { |
|
| 186 | + if ( ! is_numeric($endpoint_key)) { |
|
| 187 | 187 | continue; |
| 188 | 188 | } |
| 189 | - if (! isset($data_for_single_endpoint['callback'], $data_for_single_endpoint['methods'])) { |
|
| 189 | + if ( ! isset($data_for_single_endpoint['callback'], $data_for_single_endpoint['methods'])) { |
|
| 190 | 190 | throw new EE_Error( |
| 191 | 191 | esc_html__( |
| 192 | 192 | // @codingStandardsIgnoreStart |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | } |
| 207 | 207 | if (isset($data_for_single_endpoint['callback_args'])) { |
| 208 | 208 | $callback_args = $data_for_single_endpoint['callback_args']; |
| 209 | - $single_endpoint_args['callback'] = function (\WP_REST_Request $request) use ( |
|
| 209 | + $single_endpoint_args['callback'] = function(\WP_REST_Request $request) use ( |
|
| 210 | 210 | $callback, |
| 211 | 211 | $callback_args |
| 212 | 212 | ) { |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | $schema_route_data = $data_for_multiple_endpoints['schema']; |
| 226 | 226 | $schema_callback = $schema_route_data['schema_callback']; |
| 227 | 227 | $callback_args = $schema_route_data['callback_args']; |
| 228 | - $multiple_endpoint_args['schema'] = function () use ($schema_callback, $callback_args) { |
|
| 228 | + $multiple_endpoint_args['schema'] = function() use ($schema_callback, $callback_args) { |
|
| 229 | 229 | return call_user_func_array( |
| 230 | 230 | $schema_callback, |
| 231 | 231 | $callback_args |
@@ -269,7 +269,7 @@ discard block |
||
| 269 | 269 | { |
| 270 | 270 | //delete the saved EE REST API routes |
| 271 | 271 | foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden) { |
| 272 | - delete_option(EED_Core_Rest_Api::saved_routes_option_names . $version); |
|
| 272 | + delete_option(EED_Core_Rest_Api::saved_routes_option_names.$version); |
|
| 273 | 273 | } |
| 274 | 274 | } |
| 275 | 275 | |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | { |
| 290 | 290 | $ee_routes = array(); |
| 291 | 291 | foreach (self::versions_served() as $version => $hidden_endpoints) { |
| 292 | - $ee_routes[self::ee_api_namespace . $version] = self::_get_ee_route_data_for_version( |
|
| 292 | + $ee_routes[self::ee_api_namespace.$version] = self::_get_ee_route_data_for_version( |
|
| 293 | 293 | $version, |
| 294 | 294 | $hidden_endpoints |
| 295 | 295 | ); |
@@ -310,8 +310,8 @@ discard block |
||
| 310 | 310 | */ |
| 311 | 311 | protected static function _get_ee_route_data_for_version($version, $hidden_endpoints = false) |
| 312 | 312 | { |
| 313 | - $ee_routes = get_option(self::saved_routes_option_names . $version, null); |
|
| 314 | - if (! $ee_routes || (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE)) { |
|
| 313 | + $ee_routes = get_option(self::saved_routes_option_names.$version, null); |
|
| 314 | + if ( ! $ee_routes || (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE)) { |
|
| 315 | 315 | $ee_routes = self::_save_ee_route_data_for_version($version, $hidden_endpoints); |
| 316 | 316 | } |
| 317 | 317 | return $ee_routes; |
@@ -339,7 +339,7 @@ discard block |
||
| 339 | 339 | $instance->_get_rpc_route_data_for_version($version, $hidden_endpoints) |
| 340 | 340 | ) |
| 341 | 341 | ); |
| 342 | - $option_name = self::saved_routes_option_names . $version; |
|
| 342 | + $option_name = self::saved_routes_option_names.$version; |
|
| 343 | 343 | if (get_option($option_name)) { |
| 344 | 344 | update_option($option_name, $routes, true); |
| 345 | 345 | } else { |
@@ -405,11 +405,11 @@ discard block |
||
| 405 | 405 | */ |
| 406 | 406 | public static function should_have_write_endpoints(EEM_Base $model) |
| 407 | 407 | { |
| 408 | - if ($model->is_wp_core_model()){ |
|
| 408 | + if ($model->is_wp_core_model()) { |
|
| 409 | 409 | return false; |
| 410 | 410 | } |
| 411 | - foreach($model->get_tables() as $table){ |
|
| 412 | - if( $table->is_global()){ |
|
| 411 | + foreach ($model->get_tables() as $table) { |
|
| 412 | + if ($table->is_global()) { |
|
| 413 | 413 | return false; |
| 414 | 414 | } |
| 415 | 415 | } |
@@ -424,7 +424,7 @@ discard block |
||
| 424 | 424 | * @param $version |
| 425 | 425 | * @return array keys are model names (eg 'Event') and values ar either classnames (eg 'EEM_Event') |
| 426 | 426 | */ |
| 427 | - public static function model_names_with_plural_routes($version){ |
|
| 427 | + public static function model_names_with_plural_routes($version) { |
|
| 428 | 428 | $model_version_info = new ModelVersionInfo($version); |
| 429 | 429 | $models_to_register = $model_version_info->modelsForRequestedVersion(); |
| 430 | 430 | //let's not bother having endpoints for extra metas |
@@ -456,7 +456,7 @@ discard block |
||
| 456 | 456 | foreach (EED_Core_Rest_Api::model_names_with_plural_routes($version) as $model_name => $model_classname) { |
| 457 | 457 | $model = \EE_Registry::instance()->load_model($model_name); |
| 458 | 458 | //if this isn't a valid model then let's skip iterate to the next item in the loop. |
| 459 | - if (! $model instanceof EEM_Base) { |
|
| 459 | + if ( ! $model instanceof EEM_Base) { |
|
| 460 | 460 | continue; |
| 461 | 461 | } |
| 462 | 462 | //yes we could just register one route for ALL models, but then they wouldn't show up in the index |
@@ -473,7 +473,7 @@ discard block |
||
| 473 | 473 | 'hidden_endpoint' => $hidden_endpoint, |
| 474 | 474 | 'args' => $this->_get_read_query_params($model, $version), |
| 475 | 475 | '_links' => array( |
| 476 | - 'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace . $version . $singular_model_route), |
|
| 476 | + 'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace.$version.$singular_model_route), |
|
| 477 | 477 | ), |
| 478 | 478 | ), |
| 479 | 479 | 'schema' => array( |
@@ -496,11 +496,11 @@ discard block |
||
| 496 | 496 | 'args' => $this->_get_response_selection_query_params($model, $version), |
| 497 | 497 | ), |
| 498 | 498 | ); |
| 499 | - if( apply_filters( |
|
| 499 | + if (apply_filters( |
|
| 500 | 500 | 'FHEE__EED_Core_Rest_Api___get_model_route_data_for_version__add_write_endpoints', |
| 501 | 501 | EED_Core_Rest_Api::should_have_write_endpoints($model), |
| 502 | 502 | $model |
| 503 | - )){ |
|
| 503 | + )) { |
|
| 504 | 504 | $model_routes[$plural_model_route][] = array( |
| 505 | 505 | 'callback' => array( |
| 506 | 506 | 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
@@ -590,7 +590,7 @@ discard block |
||
| 590 | 590 | */ |
| 591 | 591 | public static function get_entity_route($model, $id) |
| 592 | 592 | { |
| 593 | - return EED_Core_Rest_Api::get_collection_route($model). '/' . $id; |
|
| 593 | + return EED_Core_Rest_Api::get_collection_route($model).'/'.$id; |
|
| 594 | 594 | } |
| 595 | 595 | |
| 596 | 596 | |
@@ -610,7 +610,7 @@ discard block |
||
| 610 | 610 | $relation_obj->get_other_model()->get_this_model_name(), |
| 611 | 611 | $relation_obj |
| 612 | 612 | ); |
| 613 | - return EED_Core_Rest_Api::get_entity_route($model, $id) . '/' . $related_model_name_endpoint_part; |
|
| 613 | + return EED_Core_Rest_Api::get_entity_route($model, $id).'/'.$related_model_name_endpoint_part; |
|
| 614 | 614 | } |
| 615 | 615 | |
| 616 | 616 | |
@@ -622,8 +622,8 @@ discard block |
||
| 622 | 622 | * @param string $version |
| 623 | 623 | * @return string |
| 624 | 624 | */ |
| 625 | - public static function get_versioned_route_to($relative_route, $version = '4.8.36'){ |
|
| 626 | - return '/' . EED_Core_Rest_Api::ee_api_namespace . $version . '/' . $relative_route; |
|
| 625 | + public static function get_versioned_route_to($relative_route, $version = '4.8.36') { |
|
| 626 | + return '/'.EED_Core_Rest_Api::ee_api_namespace.$version.'/'.$relative_route; |
|
| 627 | 627 | } |
| 628 | 628 | |
| 629 | 629 | |
@@ -638,7 +638,7 @@ discard block |
||
| 638 | 638 | { |
| 639 | 639 | $routes = array(); |
| 640 | 640 | foreach (self::versions_served() as $version => $hidden_endpoint) { |
| 641 | - $routes[self::ee_api_namespace . $version] = $this->_get_rpc_route_data_for_version( |
|
| 641 | + $routes[self::ee_api_namespace.$version] = $this->_get_rpc_route_data_for_version( |
|
| 642 | 642 | $version, |
| 643 | 643 | $hidden_endpoint |
| 644 | 644 | ); |
@@ -802,7 +802,7 @@ discard block |
||
| 802 | 802 | 'type' => array( |
| 803 | 803 | 'object', |
| 804 | 804 | 'string', |
| 805 | - ),//because we accept a variety of types, WP core validation and sanitization |
|
| 805 | + ), //because we accept a variety of types, WP core validation and sanitization |
|
| 806 | 806 | //freaks out. We'll just validate this argument while handling the request |
| 807 | 807 | 'validate_callback' => null, |
| 808 | 808 | 'sanitize_callback' => null, |
@@ -907,7 +907,7 @@ discard block |
||
| 907 | 907 | $field_obj->get_nicename(), |
| 908 | 908 | $field_name |
| 909 | 909 | ); |
| 910 | - $args_info[$field_name . '_gmt'] = $gmt_arg_info; |
|
| 910 | + $args_info[$field_name.'_gmt'] = $gmt_arg_info; |
|
| 911 | 911 | } |
| 912 | 912 | } |
| 913 | 913 | return $args_info; |
@@ -928,10 +928,10 @@ discard block |
||
| 928 | 928 | * @throws InvalidInterfaceException |
| 929 | 929 | * @throws InvalidDataTypeException |
| 930 | 930 | */ |
| 931 | - public static function default_sanitize_callback( $value, WP_REST_Request $request, $param) |
|
| 931 | + public static function default_sanitize_callback($value, WP_REST_Request $request, $param) |
|
| 932 | 932 | { |
| 933 | 933 | $attributes = $request->get_attributes(); |
| 934 | - if (! isset($attributes['args'][$param]) |
|
| 934 | + if ( ! isset($attributes['args'][$param]) |
|
| 935 | 935 | || ! is_array($attributes['args'][$param])) { |
| 936 | 936 | $validation_result = true; |
| 937 | 937 | } else { |
@@ -940,7 +940,7 @@ discard block |
||
| 940 | 940 | $value === '' |
| 941 | 941 | || $value === null |
| 942 | 942 | ) |
| 943 | - && (! isset($args['required']) |
|
| 943 | + && ( ! isset($args['required']) |
|
| 944 | 944 | || $args['required'] === false |
| 945 | 945 | ) |
| 946 | 946 | ) { |
@@ -950,7 +950,7 @@ discard block |
||
| 950 | 950 | && $args['format'] === 'email' |
| 951 | 951 | ) { |
| 952 | 952 | $validation_result = true; |
| 953 | - if (! self::_validate_email($value)) { |
|
| 953 | + if ( ! self::_validate_email($value)) { |
|
| 954 | 954 | $validation_result = new WP_Error( |
| 955 | 955 | 'rest_invalid_param', |
| 956 | 956 | esc_html__( |
@@ -980,7 +980,7 @@ discard block |
||
| 980 | 980 | * @throws InvalidInterfaceException |
| 981 | 981 | * @throws InvalidDataTypeException |
| 982 | 982 | */ |
| 983 | - protected static function _validate_email($email){ |
|
| 983 | + protected static function _validate_email($email) { |
|
| 984 | 984 | try { |
| 985 | 985 | EmailAddressFactory::create($email); |
| 986 | 986 | return true; |
@@ -1001,7 +1001,7 @@ discard block |
||
| 1001 | 1001 | { |
| 1002 | 1002 | $config_routes = array(); |
| 1003 | 1003 | foreach (self::versions_served() as $version => $hidden_endpoint) { |
| 1004 | - $config_routes[self::ee_api_namespace . $version] = $this->_get_config_route_data_for_version( |
|
| 1004 | + $config_routes[self::ee_api_namespace.$version] = $this->_get_config_route_data_for_version( |
|
| 1005 | 1005 | $version, |
| 1006 | 1006 | $hidden_endpoint |
| 1007 | 1007 | ); |
@@ -1058,7 +1058,7 @@ discard block |
||
| 1058 | 1058 | { |
| 1059 | 1059 | $meta_routes = array(); |
| 1060 | 1060 | foreach (self::versions_served() as $version => $hidden_endpoint) { |
| 1061 | - $meta_routes[self::ee_api_namespace . $version] = $this->_get_meta_route_data_for_version( |
|
| 1061 | + $meta_routes[self::ee_api_namespace.$version] = $this->_get_meta_route_data_for_version( |
|
| 1062 | 1062 | $version, |
| 1063 | 1063 | $hidden_endpoint |
| 1064 | 1064 | ); |
@@ -1112,7 +1112,7 @@ discard block |
||
| 1112 | 1112 | foreach ($relative_urls as $resource_name => $endpoints) { |
| 1113 | 1113 | foreach ($endpoints as $key => $endpoint) { |
| 1114 | 1114 | //skip schema and other route options |
| 1115 | - if (! is_numeric($key)) { |
|
| 1115 | + if ( ! is_numeric($key)) { |
|
| 1116 | 1116 | continue; |
| 1117 | 1117 | } |
| 1118 | 1118 | //by default, hide "hidden_endpoint"s, unless the request indicates |
@@ -1122,8 +1122,8 @@ discard block |
||
| 1122 | 1122 | ($force_show_ee_namespace !== '' && $force_show_ee_namespace !== $namespace) |
| 1123 | 1123 | || ($endpoint['hidden_endpoint'] && $force_show_ee_namespace === '') |
| 1124 | 1124 | ) { |
| 1125 | - $full_route = '/' . ltrim($namespace, '/'); |
|
| 1126 | - $full_route .= '/' . ltrim($resource_name, '/'); |
|
| 1125 | + $full_route = '/'.ltrim($namespace, '/'); |
|
| 1126 | + $full_route .= '/'.ltrim($resource_name, '/'); |
|
| 1127 | 1127 | unset($route_data[$full_route]); |
| 1128 | 1128 | } |
| 1129 | 1129 | } |
@@ -24,1302 +24,1302 @@ |
||
| 24 | 24 | class EED_Core_Rest_Api extends \EED_Module |
| 25 | 25 | { |
| 26 | 26 | |
| 27 | - const ee_api_namespace = 'ee/v'; |
|
| 27 | + const ee_api_namespace = 'ee/v'; |
|
| 28 | 28 | |
| 29 | - const ee_api_namespace_for_regex = 'ee\/v([^/]*)\/'; |
|
| 30 | - |
|
| 31 | - const saved_routes_option_names = 'ee_core_routes'; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * string used in _links response bodies to make them globally unique. |
|
| 35 | - * |
|
| 36 | - * @see http://v2.wp-api.org/extending/linking/ |
|
| 37 | - */ |
|
| 38 | - const ee_api_link_namespace = 'https://api.eventespresso.com/'; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @var CalculatedModelFields |
|
| 42 | - */ |
|
| 43 | - protected static $_field_calculator; |
|
| 44 | - |
|
| 45 | - |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * @return EED_Core_Rest_Api|EED_Module |
|
| 49 | - */ |
|
| 50 | - public static function instance() |
|
| 51 | - { |
|
| 52 | - self::$_field_calculator = new CalculatedModelFields(); |
|
| 53 | - return parent::get_instance(__CLASS__); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
| 60 | - * |
|
| 61 | - * @access public |
|
| 62 | - * @return void |
|
| 63 | - */ |
|
| 64 | - public static function set_hooks() |
|
| 65 | - { |
|
| 66 | - self::set_hooks_both(); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 73 | - * |
|
| 74 | - * @access public |
|
| 75 | - * @return void |
|
| 76 | - */ |
|
| 77 | - public static function set_hooks_admin() |
|
| 78 | - { |
|
| 79 | - self::set_hooks_both(); |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - |
|
| 83 | - |
|
| 84 | - public static function set_hooks_both() |
|
| 85 | - { |
|
| 86 | - add_action('rest_api_init', array('EED_Core_Rest_Api', 'register_routes'), 10); |
|
| 87 | - add_action('rest_api_init', array('EED_Core_Rest_Api', 'set_hooks_rest_api'), 5); |
|
| 88 | - add_filter('rest_route_data', array('EED_Core_Rest_Api', 'hide_old_endpoints'), 10, 2); |
|
| 89 | - add_filter('rest_index', |
|
| 90 | - array('EventEspresso\core\libraries\rest_api\controllers\model\Meta', 'filterEeMetadataIntoIndex')); |
|
| 91 | - EED_Core_Rest_Api::invalidate_cached_route_data_on_version_change(); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * sets up hooks which only need to be included as part of REST API requests; |
|
| 98 | - * other requests like to the frontend or admin etc don't need them |
|
| 99 | - * |
|
| 100 | - * @throws \EE_Error |
|
| 101 | - */ |
|
| 102 | - public static function set_hooks_rest_api() |
|
| 103 | - { |
|
| 104 | - //set hooks which account for changes made to the API |
|
| 105 | - EED_Core_Rest_Api::_set_hooks_for_changes(); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * public wrapper of _set_hooks_for_changes. |
|
| 112 | - * Loads all the hooks which make requests to old versions of the API |
|
| 113 | - * appear the same as they always did |
|
| 114 | - * |
|
| 115 | - * @throws EE_Error |
|
| 116 | - */ |
|
| 117 | - public static function set_hooks_for_changes() |
|
| 118 | - { |
|
| 119 | - self::_set_hooks_for_changes(); |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * If the user appears to be using WP API basic auth, tell them (via a persistent |
|
| 126 | - * admin notice and an email) that we're going to remove it soon, so they should |
|
| 127 | - * replace it with application passwords. |
|
| 128 | - * |
|
| 129 | - * @throws InvalidDataTypeException |
|
| 130 | - */ |
|
| 131 | - public static function maybe_notify_of_basic_auth_removal() |
|
| 132 | - { |
|
| 133 | - if ( |
|
| 134 | - apply_filters( |
|
| 135 | - 'FHEE__EED_Core_Rest_Api__maybe_notify_of_basic_auth_removal__override', |
|
| 136 | - ! isset($_SERVER['PHP_AUTH_USER']) |
|
| 137 | - && ! isset($_SERVER['HTTP_AUTHORIZATION']) |
|
| 138 | - ) |
|
| 139 | - ) { |
|
| 140 | - //sure it's a WP API request, but they aren't using basic auth, so don't bother them |
|
| 141 | - return; |
|
| 142 | - } |
|
| 143 | - //ok they're using the WP API with Basic Auth |
|
| 144 | - new PersistentAdminNotice( |
|
| 145 | - 'using_basic_auth', |
|
| 146 | - sprintf( |
|
| 147 | - __( |
|
| 148 | - 'We noticed you\'re using the WP API, which is used by the Event Espresso 4 mobile apps. Because of security and compatibility concerns, we will soon be removing our default authentication mechanism, WP API Basic Auth, from Event Espresso. It is recommended you instead install the %1$sWP Application Passwords plugin%2$s and use it with the EE4 Mobile apps. See %3$sour mobile app documentation%2$s for more information. %4$sIf you have installed the WP API Basic Auth plugin separately, or are not using the Event Espresso 4 mobile apps, you can disregard this message.%4$sThe Event Espresso Team', |
|
| 149 | - 'event_espresso' |
|
| 150 | - ), |
|
| 151 | - '<a href="https://wordpress.org/plugins/application-passwords/">', |
|
| 152 | - '</a>', |
|
| 153 | - '<a href="https://eventespresso.com/wiki/ee4-event-apps/#authentication">', |
|
| 154 | - '<br/>' |
|
| 155 | - ) |
|
| 156 | - ); |
|
| 157 | - if ( ! get_option('ee_notified_admin_on_basic_auth_removal', false)) { |
|
| 158 | - add_option('ee_notified_admin_on_basic_auth_removal', true); |
|
| 159 | - //piggy back off EE_Error::set_content_type, which sets the content type to HTML |
|
| 160 | - add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type')); |
|
| 161 | - //and send the message to the site admin too |
|
| 162 | - wp_mail(get_option('admin_email'), |
|
| 163 | - __('Notice of Removal of WP API Basic Auth From Event Espresso 4', 'event_espresso'), $message); |
|
| 164 | - remove_filter('wp_mail_content_type', array('EE_Error', 'set_content_type')); |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * Loads all the hooks which make requests to old versions of the API |
|
| 172 | - * appear the same as they always did |
|
| 173 | - * |
|
| 174 | - * @throws EE_Error |
|
| 175 | - */ |
|
| 176 | - protected static function _set_hooks_for_changes() |
|
| 177 | - { |
|
| 178 | - $folder_contents = EEH_File::get_contents_of_folders(array(EE_LIBRARIES . 'rest_api' . DS . 'changes'), false); |
|
| 179 | - foreach ($folder_contents as $classname_in_namespace => $filepath) { |
|
| 180 | - //ignore the base parent class |
|
| 181 | - //and legacy named classes |
|
| 182 | - if ($classname_in_namespace === 'ChangesInBase' |
|
| 183 | - || strpos($classname_in_namespace, 'Changes_In_') === 0 |
|
| 184 | - ) { |
|
| 185 | - continue; |
|
| 186 | - } |
|
| 187 | - $full_classname = 'EventEspresso\core\libraries\rest_api\changes\\' . $classname_in_namespace; |
|
| 188 | - if (class_exists($full_classname)) { |
|
| 189 | - $instance_of_class = new $full_classname; |
|
| 190 | - if ($instance_of_class instanceof ChangesInBase) { |
|
| 191 | - $instance_of_class->setHooks(); |
|
| 192 | - } |
|
| 193 | - } |
|
| 194 | - } |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * Filters the WP routes to add our EE-related ones. This takes a bit of time |
|
| 201 | - * so we actually prefer to only do it when an EE plugin is activated or upgraded |
|
| 202 | - * |
|
| 203 | - * @throws \EE_Error |
|
| 204 | - */ |
|
| 205 | - public static function register_routes() |
|
| 206 | - { |
|
| 207 | - foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_routes) { |
|
| 208 | - foreach ($relative_routes as $relative_route => $data_for_multiple_endpoints) { |
|
| 209 | - /** |
|
| 210 | - * @var array $data_for_multiple_endpoints numerically indexed array |
|
| 211 | - * but can also contain route options like { |
|
| 212 | - * @type array $schema { |
|
| 213 | - * @type callable $schema_callback |
|
| 214 | - * @type array $callback_args arguments that will be passed to the callback, after the |
|
| 215 | - * WP_REST_Request of course |
|
| 216 | - * } |
|
| 217 | - * } |
|
| 218 | - */ |
|
| 219 | - //when registering routes, register all the endpoints' data at the same time |
|
| 220 | - $multiple_endpoint_args = array(); |
|
| 221 | - foreach ($data_for_multiple_endpoints as $endpoint_key => $data_for_single_endpoint) { |
|
| 222 | - /** |
|
| 223 | - * @var array $data_for_single_endpoint { |
|
| 224 | - * @type callable $callback |
|
| 225 | - * @type string methods |
|
| 226 | - * @type array args |
|
| 227 | - * @type array _links |
|
| 228 | - * @type array $callback_args arguments that will be passed to the callback, after the |
|
| 229 | - * WP_REST_Request of course |
|
| 230 | - * } |
|
| 231 | - */ |
|
| 232 | - //skip route options |
|
| 233 | - if (! is_numeric($endpoint_key)) { |
|
| 234 | - continue; |
|
| 235 | - } |
|
| 236 | - if (! isset($data_for_single_endpoint['callback'], $data_for_single_endpoint['methods'])) { |
|
| 237 | - throw new EE_Error( |
|
| 238 | - esc_html__( |
|
| 239 | - // @codingStandardsIgnoreStart |
|
| 240 | - 'Endpoint configuration data needs to have entries "callback" (callable) and "methods" (comma-separated list of accepts HTTP methods).', |
|
| 241 | - // @codingStandardsIgnoreEnd |
|
| 242 | - 'event_espresso') |
|
| 243 | - ); |
|
| 244 | - } |
|
| 245 | - $callback = $data_for_single_endpoint['callback']; |
|
| 246 | - $single_endpoint_args = array( |
|
| 247 | - 'methods' => $data_for_single_endpoint['methods'], |
|
| 248 | - 'args' => isset($data_for_single_endpoint['args']) ? $data_for_single_endpoint['args'] |
|
| 249 | - : array(), |
|
| 250 | - ); |
|
| 251 | - if (isset($data_for_single_endpoint['_links'])) { |
|
| 252 | - $single_endpoint_args['_links'] = $data_for_single_endpoint['_links']; |
|
| 253 | - } |
|
| 254 | - if (isset($data_for_single_endpoint['callback_args'])) { |
|
| 255 | - $callback_args = $data_for_single_endpoint['callback_args']; |
|
| 256 | - $single_endpoint_args['callback'] = function (\WP_REST_Request $request) use ( |
|
| 257 | - $callback, |
|
| 258 | - $callback_args |
|
| 259 | - ) { |
|
| 260 | - array_unshift($callback_args, $request); |
|
| 261 | - return call_user_func_array( |
|
| 262 | - $callback, |
|
| 263 | - $callback_args |
|
| 264 | - ); |
|
| 265 | - }; |
|
| 266 | - } else { |
|
| 267 | - $single_endpoint_args['callback'] = $data_for_single_endpoint['callback']; |
|
| 268 | - } |
|
| 269 | - $multiple_endpoint_args[] = $single_endpoint_args; |
|
| 270 | - } |
|
| 271 | - if (isset($data_for_multiple_endpoints['schema'])) { |
|
| 272 | - $schema_route_data = $data_for_multiple_endpoints['schema']; |
|
| 273 | - $schema_callback = $schema_route_data['schema_callback']; |
|
| 274 | - $callback_args = $schema_route_data['callback_args']; |
|
| 275 | - $multiple_endpoint_args['schema'] = function () use ($schema_callback, $callback_args) { |
|
| 276 | - return call_user_func_array( |
|
| 277 | - $schema_callback, |
|
| 278 | - $callback_args |
|
| 279 | - ); |
|
| 280 | - }; |
|
| 281 | - } |
|
| 282 | - register_rest_route( |
|
| 283 | - $namespace, |
|
| 284 | - $relative_route, |
|
| 285 | - $multiple_endpoint_args |
|
| 286 | - ); |
|
| 287 | - } |
|
| 288 | - } |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - |
|
| 292 | - |
|
| 293 | - /** |
|
| 294 | - * Checks if there was a version change or something that merits invalidating the cached |
|
| 295 | - * route data. If so, invalidates the cached route data so that it gets refreshed |
|
| 296 | - * next time the WP API is used |
|
| 297 | - */ |
|
| 298 | - public static function invalidate_cached_route_data_on_version_change() |
|
| 299 | - { |
|
| 300 | - if (EE_System::instance()->detect_req_type() !== EE_System::req_type_normal) { |
|
| 301 | - EED_Core_Rest_Api::invalidate_cached_route_data(); |
|
| 302 | - } |
|
| 303 | - foreach (EE_Registry::instance()->addons as $addon) { |
|
| 304 | - if ($addon instanceof EE_Addon && $addon->detect_req_type() !== EE_System::req_type_normal) { |
|
| 305 | - EED_Core_Rest_Api::invalidate_cached_route_data(); |
|
| 306 | - } |
|
| 307 | - } |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - |
|
| 311 | - |
|
| 312 | - /** |
|
| 313 | - * Removes the cached route data so it will get refreshed next time the WP API is used |
|
| 314 | - */ |
|
| 315 | - public static function invalidate_cached_route_data() |
|
| 316 | - { |
|
| 317 | - //delete the saved EE REST API routes |
|
| 318 | - foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden) { |
|
| 319 | - delete_option(EED_Core_Rest_Api::saved_routes_option_names . $version); |
|
| 320 | - } |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - |
|
| 324 | - |
|
| 325 | - /** |
|
| 326 | - * Gets the EE route data |
|
| 327 | - * |
|
| 328 | - * @return array top-level key is the namespace, next-level key is the route and its value is array{ |
|
| 329 | - * @throws \EE_Error |
|
| 330 | - * @type string|array $callback |
|
| 331 | - * @type string $methods |
|
| 332 | - * @type boolean $hidden_endpoint |
|
| 333 | - * } |
|
| 334 | - */ |
|
| 335 | - public static function get_ee_route_data() |
|
| 336 | - { |
|
| 337 | - $ee_routes = array(); |
|
| 338 | - foreach (self::versions_served() as $version => $hidden_endpoints) { |
|
| 339 | - $ee_routes[self::ee_api_namespace . $version] = self::_get_ee_route_data_for_version( |
|
| 340 | - $version, |
|
| 341 | - $hidden_endpoints |
|
| 342 | - ); |
|
| 343 | - } |
|
| 344 | - return $ee_routes; |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - |
|
| 348 | - |
|
| 349 | - /** |
|
| 350 | - * Gets the EE route data from the wp options if it exists already, |
|
| 351 | - * otherwise re-generates it and saves it to the option |
|
| 352 | - * |
|
| 353 | - * @param string $version |
|
| 354 | - * @param boolean $hidden_endpoints |
|
| 355 | - * @return array |
|
| 356 | - * @throws \EE_Error |
|
| 357 | - */ |
|
| 358 | - protected static function _get_ee_route_data_for_version($version, $hidden_endpoints = false) |
|
| 359 | - { |
|
| 360 | - $ee_routes = get_option(self::saved_routes_option_names . $version, null); |
|
| 361 | - if (! $ee_routes || (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE)) { |
|
| 362 | - $ee_routes = self::_save_ee_route_data_for_version($version, $hidden_endpoints); |
|
| 363 | - } |
|
| 364 | - return $ee_routes; |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - |
|
| 368 | - |
|
| 369 | - /** |
|
| 370 | - * Saves the EE REST API route data to a wp option and returns it |
|
| 371 | - * |
|
| 372 | - * @param string $version |
|
| 373 | - * @param boolean $hidden_endpoints |
|
| 374 | - * @return mixed|null |
|
| 375 | - * @throws \EE_Error |
|
| 376 | - */ |
|
| 377 | - protected static function _save_ee_route_data_for_version($version, $hidden_endpoints = false) |
|
| 378 | - { |
|
| 379 | - $instance = self::instance(); |
|
| 380 | - $routes = apply_filters( |
|
| 381 | - 'EED_Core_Rest_Api__save_ee_route_data_for_version__routes', |
|
| 382 | - array_replace_recursive( |
|
| 383 | - $instance->_get_config_route_data_for_version($version, $hidden_endpoints), |
|
| 384 | - $instance->_get_meta_route_data_for_version($version, $hidden_endpoints), |
|
| 385 | - $instance->_get_model_route_data_for_version($version, $hidden_endpoints), |
|
| 386 | - $instance->_get_rpc_route_data_for_version($version, $hidden_endpoints) |
|
| 387 | - ) |
|
| 388 | - ); |
|
| 389 | - $option_name = self::saved_routes_option_names . $version; |
|
| 390 | - if (get_option($option_name)) { |
|
| 391 | - update_option($option_name, $routes, true); |
|
| 392 | - } else { |
|
| 393 | - add_option($option_name, $routes, null, 'no'); |
|
| 394 | - } |
|
| 395 | - return $routes; |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - |
|
| 399 | - |
|
| 400 | - /** |
|
| 401 | - * Calculates all the EE routes and saves it to a WordPress option so we don't |
|
| 402 | - * need to calculate it on every request |
|
| 403 | - * |
|
| 404 | - * @deprecated since version 4.9.1 |
|
| 405 | - * @return void |
|
| 406 | - */ |
|
| 407 | - public static function save_ee_routes() |
|
| 408 | - { |
|
| 409 | - if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 410 | - $instance = self::instance(); |
|
| 411 | - $routes = apply_filters( |
|
| 412 | - 'EED_Core_Rest_Api__save_ee_routes__routes', |
|
| 413 | - array_replace_recursive( |
|
| 414 | - $instance->_register_config_routes(), |
|
| 415 | - $instance->_register_meta_routes(), |
|
| 416 | - $instance->_register_model_routes(), |
|
| 417 | - $instance->_register_rpc_routes() |
|
| 418 | - ) |
|
| 419 | - ); |
|
| 420 | - update_option(self::saved_routes_option_names, $routes, true); |
|
| 421 | - } |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - |
|
| 425 | - |
|
| 426 | - /** |
|
| 427 | - * Gets all the route information relating to EE models |
|
| 428 | - * |
|
| 429 | - * @return array @see get_ee_route_data |
|
| 430 | - * @deprecated since version 4.9.1 |
|
| 431 | - */ |
|
| 432 | - protected function _register_model_routes() |
|
| 433 | - { |
|
| 434 | - $model_routes = array(); |
|
| 435 | - foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
| 436 | - $model_routes[EED_Core_Rest_Api::ee_api_namespace |
|
| 437 | - . $version] = $this->_get_config_route_data_for_version($version, $hidden_endpoint); |
|
| 438 | - } |
|
| 439 | - return $model_routes; |
|
| 440 | - } |
|
| 441 | - |
|
| 442 | - |
|
| 443 | - |
|
| 444 | - /** |
|
| 445 | - * Decides whether or not to add write endpoints for this model. |
|
| 446 | - * |
|
| 447 | - * Currently, this defaults to exclude all global tables and models |
|
| 448 | - * which would allow inserting WP core data (we don't want to duplicate |
|
| 449 | - * what WP API does, as it's unnecessary, extra work, and potentially extra bugs) |
|
| 450 | - * @param EEM_Base $model |
|
| 451 | - * @return bool |
|
| 452 | - */ |
|
| 453 | - public static function should_have_write_endpoints(EEM_Base $model) |
|
| 454 | - { |
|
| 455 | - if ($model->is_wp_core_model()){ |
|
| 456 | - return false; |
|
| 457 | - } |
|
| 458 | - foreach($model->get_tables() as $table){ |
|
| 459 | - if( $table->is_global()){ |
|
| 460 | - return false; |
|
| 461 | - } |
|
| 462 | - } |
|
| 463 | - return true; |
|
| 464 | - } |
|
| 465 | - |
|
| 466 | - |
|
| 467 | - |
|
| 468 | - /** |
|
| 469 | - * Gets the names of all models which should have plural routes (eg `ee/v4.8.36/events`) |
|
| 470 | - * in this versioned namespace of EE4 |
|
| 471 | - * @param $version |
|
| 472 | - * @return array keys are model names (eg 'Event') and values ar either classnames (eg 'EEM_Event') |
|
| 473 | - */ |
|
| 474 | - public static function model_names_with_plural_routes($version){ |
|
| 475 | - $model_version_info = new ModelVersionInfo($version); |
|
| 476 | - $models_to_register = $model_version_info->modelsForRequestedVersion(); |
|
| 477 | - //let's not bother having endpoints for extra metas |
|
| 478 | - unset( |
|
| 479 | - $models_to_register['Extra_Meta'], |
|
| 480 | - $models_to_register['Extra_Join'], |
|
| 481 | - $models_to_register['Post_Meta'] |
|
| 482 | - ); |
|
| 483 | - return apply_filters( |
|
| 484 | - 'FHEE__EED_Core_REST_API___register_model_routes', |
|
| 485 | - $models_to_register |
|
| 486 | - ); |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - |
|
| 490 | - |
|
| 491 | - /** |
|
| 492 | - * Gets the route data for EE models in the specified version |
|
| 493 | - * |
|
| 494 | - * @param string $version |
|
| 495 | - * @param boolean $hidden_endpoint |
|
| 496 | - * @return array |
|
| 497 | - * @throws EE_Error |
|
| 498 | - */ |
|
| 499 | - protected function _get_model_route_data_for_version($version, $hidden_endpoint = false) |
|
| 500 | - { |
|
| 501 | - $model_routes = array(); |
|
| 502 | - $model_version_info = new ModelVersionInfo($version); |
|
| 503 | - foreach (EED_Core_Rest_Api::model_names_with_plural_routes($version) as $model_name => $model_classname) { |
|
| 504 | - $model = \EE_Registry::instance()->load_model($model_name); |
|
| 505 | - //if this isn't a valid model then let's skip iterate to the next item in the loop. |
|
| 506 | - if (! $model instanceof EEM_Base) { |
|
| 507 | - continue; |
|
| 508 | - } |
|
| 509 | - //yes we could just register one route for ALL models, but then they wouldn't show up in the index |
|
| 510 | - $plural_model_route = EED_Core_Rest_Api::get_collection_route($model); |
|
| 511 | - $singular_model_route = EED_Core_Rest_Api::get_entity_route($model, '(?P<id>[^\/]+)'); |
|
| 512 | - $model_routes[$plural_model_route] = array( |
|
| 513 | - array( |
|
| 514 | - 'callback' => array( |
|
| 515 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
| 516 | - 'handleRequestGetAll', |
|
| 517 | - ), |
|
| 518 | - 'callback_args' => array($version, $model_name), |
|
| 519 | - 'methods' => WP_REST_Server::READABLE, |
|
| 520 | - 'hidden_endpoint' => $hidden_endpoint, |
|
| 521 | - 'args' => $this->_get_read_query_params($model, $version), |
|
| 522 | - '_links' => array( |
|
| 523 | - 'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace . $version . $singular_model_route), |
|
| 524 | - ), |
|
| 525 | - ), |
|
| 526 | - 'schema' => array( |
|
| 527 | - 'schema_callback' => array( |
|
| 528 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
| 529 | - 'handleSchemaRequest', |
|
| 530 | - ), |
|
| 531 | - 'callback_args' => array($version, $model_name), |
|
| 532 | - ), |
|
| 533 | - ); |
|
| 534 | - $model_routes[$singular_model_route] = array( |
|
| 535 | - array( |
|
| 536 | - 'callback' => array( |
|
| 537 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
| 538 | - 'handleRequestGetOne', |
|
| 539 | - ), |
|
| 540 | - 'callback_args' => array($version, $model_name), |
|
| 541 | - 'methods' => WP_REST_Server::READABLE, |
|
| 542 | - 'hidden_endpoint' => $hidden_endpoint, |
|
| 543 | - 'args' => $this->_get_response_selection_query_params($model, $version), |
|
| 544 | - ), |
|
| 545 | - ); |
|
| 546 | - if( apply_filters( |
|
| 547 | - 'FHEE__EED_Core_Rest_Api___get_model_route_data_for_version__add_write_endpoints', |
|
| 548 | - EED_Core_Rest_Api::should_have_write_endpoints($model), |
|
| 549 | - $model |
|
| 550 | - )){ |
|
| 551 | - $model_routes[$plural_model_route][] = array( |
|
| 552 | - 'callback' => array( |
|
| 553 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
| 554 | - 'handleRequestInsert', |
|
| 555 | - ), |
|
| 556 | - 'callback_args' => array($version, $model_name), |
|
| 557 | - 'methods' => WP_REST_Server::CREATABLE, |
|
| 558 | - 'hidden_endpoint' => $hidden_endpoint, |
|
| 559 | - 'args' => $this->_get_write_params($model_name, $model_version_info, true), |
|
| 560 | - ); |
|
| 561 | - $model_routes[$singular_model_route] = array_merge( |
|
| 562 | - $model_routes[$singular_model_route], |
|
| 563 | - array( |
|
| 564 | - array( |
|
| 565 | - 'callback' => array( |
|
| 566 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
| 567 | - 'handleRequestUpdate', |
|
| 568 | - ), |
|
| 569 | - 'callback_args' => array($version, $model_name), |
|
| 570 | - 'methods' => WP_REST_Server::EDITABLE, |
|
| 571 | - 'hidden_endpoint' => $hidden_endpoint, |
|
| 572 | - 'args' => $this->_get_write_params($model_name, $model_version_info), |
|
| 573 | - ), |
|
| 574 | - array( |
|
| 575 | - 'callback' => array( |
|
| 576 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
| 577 | - 'handleRequestDelete', |
|
| 578 | - ), |
|
| 579 | - 'callback_args' => array($version, $model_name), |
|
| 580 | - 'methods' => WP_REST_Server::DELETABLE, |
|
| 581 | - 'hidden_endpoint' => $hidden_endpoint, |
|
| 582 | - 'args' => $this->_get_delete_query_params($model, $version), |
|
| 583 | - ) |
|
| 584 | - ) |
|
| 585 | - ); |
|
| 586 | - } |
|
| 587 | - foreach ($model->relation_settings() as $relation_name => $relation_obj) { |
|
| 588 | - |
|
| 589 | - $related_route = EED_Core_Rest_Api::get_relation_route_via( |
|
| 590 | - $model, |
|
| 591 | - '(?P<id>[^\/]+)', |
|
| 592 | - $relation_obj |
|
| 593 | - ); |
|
| 594 | - $endpoints = array( |
|
| 595 | - array( |
|
| 596 | - 'callback' => array( |
|
| 597 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
| 598 | - 'handleRequestGetRelated', |
|
| 599 | - ), |
|
| 600 | - 'callback_args' => array($version, $model_name, $relation_name), |
|
| 601 | - 'methods' => WP_REST_Server::READABLE, |
|
| 602 | - 'hidden_endpoint' => $hidden_endpoint, |
|
| 603 | - 'args' => $this->_get_read_query_params($relation_obj->get_other_model(), $version), |
|
| 604 | - ), |
|
| 605 | - ); |
|
| 606 | - $model_routes[$related_route] = $endpoints; |
|
| 607 | - } |
|
| 608 | - } |
|
| 609 | - return $model_routes; |
|
| 610 | - } |
|
| 611 | - |
|
| 612 | - |
|
| 613 | - |
|
| 614 | - /** |
|
| 615 | - * Gets the relative URI to a model's REST API plural route, after the EE4 versioned namespace, |
|
| 616 | - * excluding the preceding slash. |
|
| 617 | - * Eg you pass get_plural_route_to('Event') = 'events' |
|
| 618 | - * |
|
| 619 | - * @param EEM_Base $model |
|
| 620 | - * @return string |
|
| 621 | - */ |
|
| 622 | - public static function get_collection_route(EEM_Base $model) |
|
| 623 | - { |
|
| 624 | - return EEH_Inflector::pluralize_and_lower($model->get_this_model_name()); |
|
| 625 | - } |
|
| 626 | - |
|
| 627 | - |
|
| 628 | - |
|
| 629 | - /** |
|
| 630 | - * Gets the relative URI to a model's REST API singular route, after the EE4 versioned namespace, |
|
| 631 | - * excluding the preceding slash. |
|
| 632 | - * Eg you pass get_plural_route_to('Event', 12) = 'events/12' |
|
| 633 | - * |
|
| 634 | - * @param EEM_Base $model eg Event or Venue |
|
| 635 | - * @param string $id |
|
| 636 | - * @return string |
|
| 637 | - */ |
|
| 638 | - public static function get_entity_route($model, $id) |
|
| 639 | - { |
|
| 640 | - return EED_Core_Rest_Api::get_collection_route($model). '/' . $id; |
|
| 641 | - } |
|
| 642 | - |
|
| 643 | - |
|
| 644 | - /** |
|
| 645 | - * Gets the relative URI to a model's REST API singular route, after the EE4 versioned namespace, |
|
| 646 | - * excluding the preceding slash. |
|
| 647 | - * Eg you pass get_plural_route_to('Event', 12) = 'events/12' |
|
| 648 | - * |
|
| 649 | - * @param EEM_Base $model eg Event or Venue |
|
| 650 | - * @param string $id |
|
| 651 | - * @param EE_Model_Relation_Base $relation_obj |
|
| 652 | - * @return string |
|
| 653 | - */ |
|
| 654 | - public static function get_relation_route_via(EEM_Base $model, $id, EE_Model_Relation_Base $relation_obj) |
|
| 655 | - { |
|
| 656 | - $related_model_name_endpoint_part = ModelRead::getRelatedEntityName( |
|
| 657 | - $relation_obj->get_other_model()->get_this_model_name(), |
|
| 658 | - $relation_obj |
|
| 659 | - ); |
|
| 660 | - return EED_Core_Rest_Api::get_entity_route($model, $id) . '/' . $related_model_name_endpoint_part; |
|
| 661 | - } |
|
| 662 | - |
|
| 663 | - |
|
| 664 | - |
|
| 665 | - /** |
|
| 666 | - * Adds onto the $relative_route the EE4 REST API versioned namespace. |
|
| 667 | - * Eg if given '4.8.36' and 'events', will return 'ee/v4.8.36/events' |
|
| 668 | - * @param string $relative_route |
|
| 669 | - * @param string $version |
|
| 670 | - * @return string |
|
| 671 | - */ |
|
| 672 | - public static function get_versioned_route_to($relative_route, $version = '4.8.36'){ |
|
| 673 | - return '/' . EED_Core_Rest_Api::ee_api_namespace . $version . '/' . $relative_route; |
|
| 674 | - } |
|
| 675 | - |
|
| 676 | - |
|
| 677 | - |
|
| 678 | - /** |
|
| 679 | - * Adds all the RPC-style routes (remote procedure call-like routes, ie |
|
| 680 | - * routes that don't conform to the traditional REST CRUD-style). |
|
| 681 | - * |
|
| 682 | - * @deprecated since 4.9.1 |
|
| 683 | - */ |
|
| 684 | - protected function _register_rpc_routes() |
|
| 685 | - { |
|
| 686 | - $routes = array(); |
|
| 687 | - foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
| 688 | - $routes[self::ee_api_namespace . $version] = $this->_get_rpc_route_data_for_version( |
|
| 689 | - $version, |
|
| 690 | - $hidden_endpoint |
|
| 691 | - ); |
|
| 692 | - } |
|
| 693 | - return $routes; |
|
| 694 | - } |
|
| 695 | - |
|
| 696 | - |
|
| 697 | - |
|
| 698 | - /** |
|
| 699 | - * @param string $version |
|
| 700 | - * @param boolean $hidden_endpoint |
|
| 701 | - * @return array |
|
| 702 | - */ |
|
| 703 | - protected function _get_rpc_route_data_for_version($version, $hidden_endpoint = false) |
|
| 704 | - { |
|
| 705 | - $this_versions_routes = array(); |
|
| 706 | - //checkin endpoint |
|
| 707 | - $this_versions_routes['registrations/(?P<REG_ID>\d+)/toggle_checkin_for_datetime/(?P<DTT_ID>\d+)'] = array( |
|
| 708 | - array( |
|
| 709 | - 'callback' => array( |
|
| 710 | - 'EventEspresso\core\libraries\rest_api\controllers\rpc\Checkin', |
|
| 711 | - 'handleRequestToggleCheckin', |
|
| 712 | - ), |
|
| 713 | - 'methods' => WP_REST_Server::CREATABLE, |
|
| 714 | - 'hidden_endpoint' => $hidden_endpoint, |
|
| 715 | - 'args' => array( |
|
| 716 | - 'force' => array( |
|
| 717 | - 'required' => false, |
|
| 718 | - 'default' => false, |
|
| 719 | - 'description' => __( |
|
| 720 | - // @codingStandardsIgnoreStart |
|
| 721 | - 'Whether to force toggle checkin, or to verify the registration status and allowed ticket uses', |
|
| 722 | - // @codingStandardsIgnoreEnd |
|
| 723 | - 'event_espresso' |
|
| 724 | - ), |
|
| 725 | - ), |
|
| 726 | - ), |
|
| 727 | - 'callback_args' => array($version), |
|
| 728 | - ), |
|
| 729 | - ); |
|
| 730 | - return apply_filters( |
|
| 731 | - 'FHEE__EED_Core_Rest_Api___register_rpc_routes__this_versions_routes', |
|
| 732 | - $this_versions_routes, |
|
| 733 | - $version, |
|
| 734 | - $hidden_endpoint |
|
| 735 | - ); |
|
| 736 | - } |
|
| 737 | - |
|
| 738 | - |
|
| 739 | - |
|
| 740 | - /** |
|
| 741 | - * Gets the query params that can be used when request one or many |
|
| 742 | - * |
|
| 743 | - * @param EEM_Base $model |
|
| 744 | - * @param string $version |
|
| 745 | - * @return array |
|
| 746 | - */ |
|
| 747 | - protected function _get_response_selection_query_params(\EEM_Base $model, $version) |
|
| 748 | - { |
|
| 749 | - return apply_filters( |
|
| 750 | - 'FHEE__EED_Core_Rest_Api___get_response_selection_query_params', |
|
| 751 | - array( |
|
| 752 | - 'include' => array( |
|
| 753 | - 'required' => false, |
|
| 754 | - 'default' => '*', |
|
| 755 | - 'type' => 'string', |
|
| 756 | - ), |
|
| 757 | - 'calculate' => array( |
|
| 758 | - 'required' => false, |
|
| 759 | - 'default' => '', |
|
| 760 | - 'enum' => self::$_field_calculator->retrieveCalculatedFieldsForModel($model), |
|
| 761 | - 'type' => 'string', |
|
| 762 | - //because we accept a CSV'd list of the enumerated strings, WP core validation and sanitization |
|
| 763 | - //freaks out. We'll just validate this argument while handling the request |
|
| 764 | - 'validate_callback' => null, |
|
| 765 | - 'sanitize_callback' => null, |
|
| 766 | - ), |
|
| 767 | - ), |
|
| 768 | - $model, |
|
| 769 | - $version |
|
| 770 | - ); |
|
| 771 | - } |
|
| 772 | - |
|
| 773 | - |
|
| 774 | - |
|
| 775 | - /** |
|
| 776 | - * Gets the parameters acceptable for delete requests |
|
| 777 | - * |
|
| 778 | - * @param \EEM_Base $model |
|
| 779 | - * @param string $version |
|
| 780 | - * @return array |
|
| 781 | - */ |
|
| 782 | - protected function _get_delete_query_params(\EEM_Base $model, $version) |
|
| 783 | - { |
|
| 784 | - $params_for_delete = array( |
|
| 785 | - 'allow_blocking' => array( |
|
| 786 | - 'required' => false, |
|
| 787 | - 'default' => true, |
|
| 788 | - 'type' => 'boolean', |
|
| 789 | - ), |
|
| 790 | - ); |
|
| 791 | - $params_for_delete['force'] = array( |
|
| 792 | - 'required' => false, |
|
| 793 | - 'default' => false, |
|
| 794 | - 'type' => 'boolean', |
|
| 795 | - ); |
|
| 796 | - return apply_filters( |
|
| 797 | - 'FHEE__EED_Core_Rest_Api___get_delete_query_params', |
|
| 798 | - $params_for_delete, |
|
| 799 | - $model, |
|
| 800 | - $version |
|
| 801 | - ); |
|
| 802 | - } |
|
| 803 | - |
|
| 804 | - |
|
| 805 | - |
|
| 806 | - /** |
|
| 807 | - * Gets info about reading query params that are acceptable |
|
| 808 | - * |
|
| 809 | - * @param \EEM_Base $model eg 'Event' or 'Venue' |
|
| 810 | - * @param string $version |
|
| 811 | - * @return array describing the args acceptable when querying this model |
|
| 812 | - * @throws EE_Error |
|
| 813 | - */ |
|
| 814 | - protected function _get_read_query_params(\EEM_Base $model, $version) |
|
| 815 | - { |
|
| 816 | - $default_orderby = array(); |
|
| 817 | - foreach ($model->get_combined_primary_key_fields() as $key_field) { |
|
| 818 | - $default_orderby[$key_field->get_name()] = 'ASC'; |
|
| 819 | - } |
|
| 820 | - return array_merge( |
|
| 821 | - $this->_get_response_selection_query_params($model, $version), |
|
| 822 | - array( |
|
| 823 | - 'where' => array( |
|
| 824 | - 'required' => false, |
|
| 825 | - 'default' => array(), |
|
| 826 | - 'type' => 'object', |
|
| 827 | - //because we accept an almost infinite list of possible where conditions, WP |
|
| 828 | - // core validation and sanitization freaks out. We'll just validate this argument |
|
| 829 | - // while handling the request |
|
| 830 | - 'validate_callback' => null, |
|
| 831 | - 'sanitize_callback' => null, |
|
| 832 | - ), |
|
| 833 | - 'limit' => array( |
|
| 834 | - 'required' => false, |
|
| 835 | - 'default' => EED_Core_Rest_Api::get_default_query_limit(), |
|
| 836 | - 'type' => array( |
|
| 837 | - 'array', |
|
| 838 | - 'string', |
|
| 839 | - 'integer', |
|
| 840 | - ), |
|
| 841 | - //because we accept a variety of types, WP core validation and sanitization |
|
| 842 | - //freaks out. We'll just validate this argument while handling the request |
|
| 843 | - 'validate_callback' => null, |
|
| 844 | - 'sanitize_callback' => null, |
|
| 845 | - ), |
|
| 846 | - 'order_by' => array( |
|
| 847 | - 'required' => false, |
|
| 848 | - 'default' => $default_orderby, |
|
| 849 | - 'type' => array( |
|
| 850 | - 'object', |
|
| 851 | - 'string', |
|
| 852 | - ),//because we accept a variety of types, WP core validation and sanitization |
|
| 853 | - //freaks out. We'll just validate this argument while handling the request |
|
| 854 | - 'validate_callback' => null, |
|
| 855 | - 'sanitize_callback' => null, |
|
| 856 | - ), |
|
| 857 | - 'group_by' => array( |
|
| 858 | - 'required' => false, |
|
| 859 | - 'default' => null, |
|
| 860 | - 'type' => array( |
|
| 861 | - 'object', |
|
| 862 | - 'string', |
|
| 863 | - ), |
|
| 864 | - //because we accept an almost infinite list of possible groupings, |
|
| 865 | - // WP core validation and sanitization |
|
| 866 | - //freaks out. We'll just validate this argument while handling the request |
|
| 867 | - 'validate_callback' => null, |
|
| 868 | - 'sanitize_callback' => null, |
|
| 869 | - ), |
|
| 870 | - 'having' => array( |
|
| 871 | - 'required' => false, |
|
| 872 | - 'default' => null, |
|
| 873 | - 'type' => 'object', |
|
| 874 | - //because we accept an almost infinite list of possible where conditions, WP |
|
| 875 | - // core validation and sanitization freaks out. We'll just validate this argument |
|
| 876 | - // while handling the request |
|
| 877 | - 'validate_callback' => null, |
|
| 878 | - 'sanitize_callback' => null, |
|
| 879 | - ), |
|
| 880 | - 'caps' => array( |
|
| 881 | - 'required' => false, |
|
| 882 | - 'default' => EEM_Base::caps_read, |
|
| 883 | - 'type' => 'string', |
|
| 884 | - 'enum' => array( |
|
| 885 | - EEM_Base::caps_read, |
|
| 886 | - EEM_Base::caps_read_admin, |
|
| 887 | - EEM_Base::caps_edit, |
|
| 888 | - EEM_Base::caps_delete |
|
| 889 | - ) |
|
| 890 | - ), |
|
| 891 | - ) |
|
| 892 | - ); |
|
| 893 | - } |
|
| 894 | - |
|
| 895 | - |
|
| 896 | - |
|
| 897 | - /** |
|
| 898 | - * Gets parameter information for a model regarding writing data |
|
| 899 | - * |
|
| 900 | - * @param string $model_name |
|
| 901 | - * @param ModelVersionInfo $model_version_info |
|
| 902 | - * @param boolean $create whether this is for request to create (in which case we need |
|
| 903 | - * all required params) or just to update (in which case we don't need those on every request) |
|
| 904 | - * @return array |
|
| 905 | - */ |
|
| 906 | - protected function _get_write_params( |
|
| 907 | - $model_name, |
|
| 908 | - ModelVersionInfo $model_version_info, |
|
| 909 | - $create = false |
|
| 910 | - ) { |
|
| 911 | - $model = EE_Registry::instance()->load_model($model_name); |
|
| 912 | - $fields = $model_version_info->fieldsOnModelInThisVersion($model); |
|
| 913 | - $args_info = array(); |
|
| 914 | - foreach ($fields as $field_name => $field_obj) { |
|
| 915 | - if ($field_obj->is_auto_increment()) { |
|
| 916 | - //totally ignore auto increment IDs |
|
| 917 | - continue; |
|
| 918 | - } |
|
| 919 | - $arg_info = $field_obj->getSchema(); |
|
| 920 | - $required = $create && ! $field_obj->is_nullable() && $field_obj->get_default_value() === null; |
|
| 921 | - $arg_info['required'] = $required; |
|
| 922 | - //remove the read-only flag. If it were read-only we wouldn't list it as an argument while writing, right? |
|
| 923 | - unset($arg_info['readonly']); |
|
| 924 | - $schema_properties = $field_obj->getSchemaProperties(); |
|
| 925 | - if ( |
|
| 926 | - isset($schema_properties['raw']) |
|
| 927 | - && $field_obj->getSchemaType() === 'object' |
|
| 928 | - ) { |
|
| 929 | - //if there's a "raw" form of this argument, use those properties instead |
|
| 930 | - $arg_info = array_replace( |
|
| 931 | - $arg_info, |
|
| 932 | - $schema_properties['raw'] |
|
| 933 | - ); |
|
| 934 | - } |
|
| 935 | - $arg_info['default'] = ModelDataTranslator::prepareFieldValueForJson( |
|
| 936 | - $field_obj, |
|
| 937 | - $field_obj->get_default_value(), |
|
| 938 | - $model_version_info->requestedVersion() |
|
| 939 | - ); |
|
| 940 | - //we do our own validation and sanitization within the controller |
|
| 941 | - $arg_info['sanitize_callback'] = |
|
| 942 | - array( |
|
| 943 | - 'EED_Core_Rest_Api', |
|
| 944 | - 'default_sanitize_callback', |
|
| 945 | - ); |
|
| 946 | - $args_info[$field_name] = $arg_info; |
|
| 947 | - if ($field_obj instanceof EE_Datetime_Field) { |
|
| 948 | - $gmt_arg_info = $arg_info; |
|
| 949 | - $gmt_arg_info['description'] = sprintf( |
|
| 950 | - esc_html__( |
|
| 951 | - '%1$s - the value for this field in UTC. Ignored if %2$s is provided.', |
|
| 952 | - 'event_espresso' |
|
| 953 | - ), |
|
| 954 | - $field_obj->get_nicename(), |
|
| 955 | - $field_name |
|
| 956 | - ); |
|
| 957 | - $args_info[$field_name . '_gmt'] = $gmt_arg_info; |
|
| 958 | - } |
|
| 959 | - } |
|
| 960 | - return $args_info; |
|
| 961 | - } |
|
| 962 | - |
|
| 963 | - |
|
| 964 | - |
|
| 965 | - /** |
|
| 966 | - * Replacement for WP API's 'rest_parse_request_arg'. |
|
| 967 | - * If the value is blank but not required, don't bother validating it. |
|
| 968 | - * Also, it uses our email validation instead of WP API's default. |
|
| 969 | - * |
|
| 970 | - * @param $value |
|
| 971 | - * @param WP_REST_Request $request |
|
| 972 | - * @param $param |
|
| 973 | - * @return bool|true|WP_Error |
|
| 974 | - * @throws InvalidArgumentException |
|
| 975 | - * @throws InvalidInterfaceException |
|
| 976 | - * @throws InvalidDataTypeException |
|
| 977 | - */ |
|
| 978 | - public static function default_sanitize_callback( $value, WP_REST_Request $request, $param) |
|
| 979 | - { |
|
| 980 | - $attributes = $request->get_attributes(); |
|
| 981 | - if (! isset($attributes['args'][$param]) |
|
| 982 | - || ! is_array($attributes['args'][$param])) { |
|
| 983 | - $validation_result = true; |
|
| 984 | - } else { |
|
| 985 | - $args = $attributes['args'][$param]; |
|
| 986 | - if (( |
|
| 987 | - $value === '' |
|
| 988 | - || $value === null |
|
| 989 | - ) |
|
| 990 | - && (! isset($args['required']) |
|
| 991 | - || $args['required'] === false |
|
| 992 | - ) |
|
| 993 | - ) { |
|
| 994 | - //not required and not provided? that's cool |
|
| 995 | - $validation_result = true; |
|
| 996 | - } elseif (isset($args['format']) |
|
| 997 | - && $args['format'] === 'email' |
|
| 998 | - ) { |
|
| 999 | - $validation_result = true; |
|
| 1000 | - if (! self::_validate_email($value)) { |
|
| 1001 | - $validation_result = new WP_Error( |
|
| 1002 | - 'rest_invalid_param', |
|
| 1003 | - esc_html__( |
|
| 1004 | - 'The email address is not valid or does not exist.', |
|
| 1005 | - 'event_espresso' |
|
| 1006 | - ) |
|
| 1007 | - ); |
|
| 1008 | - } |
|
| 1009 | - } else { |
|
| 1010 | - $validation_result = rest_validate_value_from_schema($value, $args, $param); |
|
| 1011 | - } |
|
| 1012 | - } |
|
| 1013 | - if (is_wp_error($validation_result)) { |
|
| 1014 | - return $validation_result; |
|
| 1015 | - } |
|
| 1016 | - return rest_sanitize_request_arg($value, $request, $param); |
|
| 1017 | - } |
|
| 1018 | - |
|
| 1019 | - |
|
| 1020 | - |
|
| 1021 | - /** |
|
| 1022 | - * Returns whether or not this email address is valid. Copied from EE_Email_Validation_Strategy::_validate_email() |
|
| 1023 | - * |
|
| 1024 | - * @param $email |
|
| 1025 | - * @return bool |
|
| 1026 | - * @throws InvalidArgumentException |
|
| 1027 | - * @throws InvalidInterfaceException |
|
| 1028 | - * @throws InvalidDataTypeException |
|
| 1029 | - */ |
|
| 1030 | - protected static function _validate_email($email){ |
|
| 1031 | - try { |
|
| 1032 | - EmailAddressFactory::create($email); |
|
| 1033 | - return true; |
|
| 1034 | - } catch (EmailValidationException $e) { |
|
| 1035 | - return false; |
|
| 1036 | - } |
|
| 1037 | - } |
|
| 1038 | - |
|
| 1039 | - |
|
| 1040 | - |
|
| 1041 | - /** |
|
| 1042 | - * Gets routes for the config |
|
| 1043 | - * |
|
| 1044 | - * @return array @see _register_model_routes |
|
| 1045 | - * @deprecated since version 4.9.1 |
|
| 1046 | - */ |
|
| 1047 | - protected function _register_config_routes() |
|
| 1048 | - { |
|
| 1049 | - $config_routes = array(); |
|
| 1050 | - foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
| 1051 | - $config_routes[self::ee_api_namespace . $version] = $this->_get_config_route_data_for_version( |
|
| 1052 | - $version, |
|
| 1053 | - $hidden_endpoint |
|
| 1054 | - ); |
|
| 1055 | - } |
|
| 1056 | - return $config_routes; |
|
| 1057 | - } |
|
| 1058 | - |
|
| 1059 | - |
|
| 1060 | - |
|
| 1061 | - /** |
|
| 1062 | - * Gets routes for the config for the specified version |
|
| 1063 | - * |
|
| 1064 | - * @param string $version |
|
| 1065 | - * @param boolean $hidden_endpoint |
|
| 1066 | - * @return array |
|
| 1067 | - */ |
|
| 1068 | - protected function _get_config_route_data_for_version($version, $hidden_endpoint) |
|
| 1069 | - { |
|
| 1070 | - return array( |
|
| 1071 | - 'config' => array( |
|
| 1072 | - array( |
|
| 1073 | - 'callback' => array( |
|
| 1074 | - 'EventEspresso\core\libraries\rest_api\controllers\config\Read', |
|
| 1075 | - 'handleRequest', |
|
| 1076 | - ), |
|
| 1077 | - 'methods' => WP_REST_Server::READABLE, |
|
| 1078 | - 'hidden_endpoint' => $hidden_endpoint, |
|
| 1079 | - 'callback_args' => array($version), |
|
| 1080 | - ), |
|
| 1081 | - ), |
|
| 1082 | - 'site_info' => array( |
|
| 1083 | - array( |
|
| 1084 | - 'callback' => array( |
|
| 1085 | - 'EventEspresso\core\libraries\rest_api\controllers\config\Read', |
|
| 1086 | - 'handleRequestSiteInfo', |
|
| 1087 | - ), |
|
| 1088 | - 'methods' => WP_REST_Server::READABLE, |
|
| 1089 | - 'hidden_endpoint' => $hidden_endpoint, |
|
| 1090 | - 'callback_args' => array($version), |
|
| 1091 | - ), |
|
| 1092 | - ), |
|
| 1093 | - ); |
|
| 1094 | - } |
|
| 1095 | - |
|
| 1096 | - |
|
| 1097 | - |
|
| 1098 | - /** |
|
| 1099 | - * Gets the meta info routes |
|
| 1100 | - * |
|
| 1101 | - * @return array @see _register_model_routes |
|
| 1102 | - * @deprecated since version 4.9.1 |
|
| 1103 | - */ |
|
| 1104 | - protected function _register_meta_routes() |
|
| 1105 | - { |
|
| 1106 | - $meta_routes = array(); |
|
| 1107 | - foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
| 1108 | - $meta_routes[self::ee_api_namespace . $version] = $this->_get_meta_route_data_for_version( |
|
| 1109 | - $version, |
|
| 1110 | - $hidden_endpoint |
|
| 1111 | - ); |
|
| 1112 | - } |
|
| 1113 | - return $meta_routes; |
|
| 1114 | - } |
|
| 1115 | - |
|
| 1116 | - |
|
| 1117 | - |
|
| 1118 | - /** |
|
| 1119 | - * @param string $version |
|
| 1120 | - * @param boolean $hidden_endpoint |
|
| 1121 | - * @return array |
|
| 1122 | - */ |
|
| 1123 | - protected function _get_meta_route_data_for_version($version, $hidden_endpoint = false) |
|
| 1124 | - { |
|
| 1125 | - return array( |
|
| 1126 | - 'resources' => array( |
|
| 1127 | - array( |
|
| 1128 | - 'callback' => array( |
|
| 1129 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Meta', |
|
| 1130 | - 'handleRequestModelsMeta', |
|
| 1131 | - ), |
|
| 1132 | - 'methods' => WP_REST_Server::READABLE, |
|
| 1133 | - 'hidden_endpoint' => $hidden_endpoint, |
|
| 1134 | - 'callback_args' => array($version), |
|
| 1135 | - ), |
|
| 1136 | - ), |
|
| 1137 | - ); |
|
| 1138 | - } |
|
| 1139 | - |
|
| 1140 | - |
|
| 1141 | - |
|
| 1142 | - /** |
|
| 1143 | - * Tries to hide old 4.6 endpoints from the |
|
| 1144 | - * |
|
| 1145 | - * @param array $route_data |
|
| 1146 | - * @return array |
|
| 1147 | - * @throws \EE_Error |
|
| 1148 | - */ |
|
| 1149 | - public static function hide_old_endpoints($route_data) |
|
| 1150 | - { |
|
| 1151 | - //allow API clients to override which endpoints get hidden, in case |
|
| 1152 | - //they want to discover particular endpoints |
|
| 1153 | - //also, we don't have access to the request so we have to just grab it from the superglobal |
|
| 1154 | - $force_show_ee_namespace = ltrim( |
|
| 1155 | - EEH_Array::is_set($_REQUEST, 'force_show_ee_namespace', ''), |
|
| 1156 | - '/' |
|
| 1157 | - ); |
|
| 1158 | - foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls) { |
|
| 1159 | - foreach ($relative_urls as $resource_name => $endpoints) { |
|
| 1160 | - foreach ($endpoints as $key => $endpoint) { |
|
| 1161 | - //skip schema and other route options |
|
| 1162 | - if (! is_numeric($key)) { |
|
| 1163 | - continue; |
|
| 1164 | - } |
|
| 1165 | - //by default, hide "hidden_endpoint"s, unless the request indicates |
|
| 1166 | - //to $force_show_ee_namespace, in which case only show that one |
|
| 1167 | - //namespace's endpoints (and hide all others) |
|
| 1168 | - if ( |
|
| 1169 | - ($force_show_ee_namespace !== '' && $force_show_ee_namespace !== $namespace) |
|
| 1170 | - || ($endpoint['hidden_endpoint'] && $force_show_ee_namespace === '') |
|
| 1171 | - ) { |
|
| 1172 | - $full_route = '/' . ltrim($namespace, '/'); |
|
| 1173 | - $full_route .= '/' . ltrim($resource_name, '/'); |
|
| 1174 | - unset($route_data[$full_route]); |
|
| 1175 | - } |
|
| 1176 | - } |
|
| 1177 | - } |
|
| 1178 | - } |
|
| 1179 | - return $route_data; |
|
| 1180 | - } |
|
| 1181 | - |
|
| 1182 | - |
|
| 1183 | - |
|
| 1184 | - /** |
|
| 1185 | - * Returns an array describing which versions of core support serving requests for. |
|
| 1186 | - * Keys are core versions' major and minor version, and values are the |
|
| 1187 | - * LOWEST requested version they can serve. Eg, 4.7 can serve requests for 4.6-like |
|
| 1188 | - * data by just removing a few models and fields from the responses. However, 4.15 might remove |
|
| 1189 | - * the answers table entirely, in which case it would be very difficult for |
|
| 1190 | - * it to serve 4.6-style responses. |
|
| 1191 | - * Versions of core that are missing from this array are unknowns. |
|
| 1192 | - * previous ver |
|
| 1193 | - * |
|
| 1194 | - * @return array |
|
| 1195 | - */ |
|
| 1196 | - public static function version_compatibilities() |
|
| 1197 | - { |
|
| 1198 | - return apply_filters( |
|
| 1199 | - 'FHEE__EED_Core_REST_API__version_compatibilities', |
|
| 1200 | - array( |
|
| 1201 | - '4.8.29' => '4.8.29', |
|
| 1202 | - '4.8.33' => '4.8.29', |
|
| 1203 | - '4.8.34' => '4.8.29', |
|
| 1204 | - '4.8.36' => '4.8.29', |
|
| 1205 | - ) |
|
| 1206 | - ); |
|
| 1207 | - } |
|
| 1208 | - |
|
| 1209 | - |
|
| 1210 | - |
|
| 1211 | - /** |
|
| 1212 | - * Gets the latest API version served. Eg if there |
|
| 1213 | - * are two versions served of the API, 4.8.29 and 4.8.32, and |
|
| 1214 | - * we are on core version 4.8.34, it will return the string "4.8.32" |
|
| 1215 | - * |
|
| 1216 | - * @return string |
|
| 1217 | - */ |
|
| 1218 | - public static function latest_rest_api_version() |
|
| 1219 | - { |
|
| 1220 | - $versions_served = \EED_Core_Rest_Api::versions_served(); |
|
| 1221 | - $versions_served_keys = array_keys($versions_served); |
|
| 1222 | - return end($versions_served_keys); |
|
| 1223 | - } |
|
| 1224 | - |
|
| 1225 | - |
|
| 1226 | - |
|
| 1227 | - /** |
|
| 1228 | - * Using EED_Core_Rest_Api::version_compatibilities(), determines what version of |
|
| 1229 | - * EE the API can serve requests for. Eg, if we are on 4.15 of core, and |
|
| 1230 | - * we can serve requests from 4.12 or later, this will return array( '4.12', '4.13', '4.14', '4.15' ). |
|
| 1231 | - * We also indicate whether or not this version should be put in the index or not |
|
| 1232 | - * |
|
| 1233 | - * @return array keys are API version numbers (just major and minor numbers), and values |
|
| 1234 | - * are whether or not they should be hidden |
|
| 1235 | - */ |
|
| 1236 | - public static function versions_served() |
|
| 1237 | - { |
|
| 1238 | - $versions_served = array(); |
|
| 1239 | - $possibly_served_versions = EED_Core_Rest_Api::version_compatibilities(); |
|
| 1240 | - $lowest_compatible_version = end($possibly_served_versions); |
|
| 1241 | - reset($possibly_served_versions); |
|
| 1242 | - $versions_served_historically = array_keys($possibly_served_versions); |
|
| 1243 | - $latest_version = end($versions_served_historically); |
|
| 1244 | - reset($versions_served_historically); |
|
| 1245 | - //for each version of core we have ever served: |
|
| 1246 | - foreach ($versions_served_historically as $key_versioned_endpoint) { |
|
| 1247 | - //if it's not above the current core version, and it's compatible with the current version of core |
|
| 1248 | - if ($key_versioned_endpoint === $latest_version) { |
|
| 1249 | - //don't hide the latest version in the index |
|
| 1250 | - $versions_served[$key_versioned_endpoint] = false; |
|
| 1251 | - } elseif ( |
|
| 1252 | - $key_versioned_endpoint >= $lowest_compatible_version |
|
| 1253 | - && $key_versioned_endpoint < EED_Core_Rest_Api::core_version() |
|
| 1254 | - ) { |
|
| 1255 | - //include, but hide, previous versions which are still supported |
|
| 1256 | - $versions_served[$key_versioned_endpoint] = true; |
|
| 1257 | - } elseif (apply_filters( |
|
| 1258 | - 'FHEE__EED_Core_Rest_Api__versions_served__include_incompatible_versions', |
|
| 1259 | - false, |
|
| 1260 | - $possibly_served_versions |
|
| 1261 | - )) { |
|
| 1262 | - //if a version is no longer supported, don't include it in index or list of versions served |
|
| 1263 | - $versions_served[$key_versioned_endpoint] = true; |
|
| 1264 | - } |
|
| 1265 | - } |
|
| 1266 | - return $versions_served; |
|
| 1267 | - } |
|
| 1268 | - |
|
| 1269 | - |
|
| 1270 | - |
|
| 1271 | - /** |
|
| 1272 | - * Gets the major and minor version of EE core's version string |
|
| 1273 | - * |
|
| 1274 | - * @return string |
|
| 1275 | - */ |
|
| 1276 | - public static function core_version() |
|
| 1277 | - { |
|
| 1278 | - return apply_filters( |
|
| 1279 | - 'FHEE__EED_Core_REST_API__core_version', |
|
| 1280 | - implode( |
|
| 1281 | - '.', |
|
| 1282 | - array_slice( |
|
| 1283 | - explode( |
|
| 1284 | - '.', |
|
| 1285 | - espresso_version() |
|
| 1286 | - ), |
|
| 1287 | - 0, |
|
| 1288 | - 3 |
|
| 1289 | - ) |
|
| 1290 | - ) |
|
| 1291 | - ); |
|
| 1292 | - } |
|
| 1293 | - |
|
| 1294 | - |
|
| 1295 | - |
|
| 1296 | - /** |
|
| 1297 | - * Gets the default limit that should be used when querying for resources |
|
| 1298 | - * |
|
| 1299 | - * @return int |
|
| 1300 | - */ |
|
| 1301 | - public static function get_default_query_limit() |
|
| 1302 | - { |
|
| 1303 | - //we actually don't use a const because we want folks to always use |
|
| 1304 | - //this method, not the const directly |
|
| 1305 | - return apply_filters( |
|
| 1306 | - 'FHEE__EED_Core_Rest_Api__get_default_query_limit', |
|
| 1307 | - 50 |
|
| 1308 | - ); |
|
| 1309 | - } |
|
| 1310 | - |
|
| 1311 | - |
|
| 1312 | - |
|
| 1313 | - /** |
|
| 1314 | - * run - initial module setup |
|
| 1315 | - * |
|
| 1316 | - * @access public |
|
| 1317 | - * @param WP $WP |
|
| 1318 | - * @return void |
|
| 1319 | - */ |
|
| 1320 | - public function run($WP) |
|
| 1321 | - { |
|
| 1322 | - } |
|
| 29 | + const ee_api_namespace_for_regex = 'ee\/v([^/]*)\/'; |
|
| 30 | + |
|
| 31 | + const saved_routes_option_names = 'ee_core_routes'; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * string used in _links response bodies to make them globally unique. |
|
| 35 | + * |
|
| 36 | + * @see http://v2.wp-api.org/extending/linking/ |
|
| 37 | + */ |
|
| 38 | + const ee_api_link_namespace = 'https://api.eventespresso.com/'; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @var CalculatedModelFields |
|
| 42 | + */ |
|
| 43 | + protected static $_field_calculator; |
|
| 44 | + |
|
| 45 | + |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * @return EED_Core_Rest_Api|EED_Module |
|
| 49 | + */ |
|
| 50 | + public static function instance() |
|
| 51 | + { |
|
| 52 | + self::$_field_calculator = new CalculatedModelFields(); |
|
| 53 | + return parent::get_instance(__CLASS__); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
| 60 | + * |
|
| 61 | + * @access public |
|
| 62 | + * @return void |
|
| 63 | + */ |
|
| 64 | + public static function set_hooks() |
|
| 65 | + { |
|
| 66 | + self::set_hooks_both(); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 73 | + * |
|
| 74 | + * @access public |
|
| 75 | + * @return void |
|
| 76 | + */ |
|
| 77 | + public static function set_hooks_admin() |
|
| 78 | + { |
|
| 79 | + self::set_hooks_both(); |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + |
|
| 83 | + |
|
| 84 | + public static function set_hooks_both() |
|
| 85 | + { |
|
| 86 | + add_action('rest_api_init', array('EED_Core_Rest_Api', 'register_routes'), 10); |
|
| 87 | + add_action('rest_api_init', array('EED_Core_Rest_Api', 'set_hooks_rest_api'), 5); |
|
| 88 | + add_filter('rest_route_data', array('EED_Core_Rest_Api', 'hide_old_endpoints'), 10, 2); |
|
| 89 | + add_filter('rest_index', |
|
| 90 | + array('EventEspresso\core\libraries\rest_api\controllers\model\Meta', 'filterEeMetadataIntoIndex')); |
|
| 91 | + EED_Core_Rest_Api::invalidate_cached_route_data_on_version_change(); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * sets up hooks which only need to be included as part of REST API requests; |
|
| 98 | + * other requests like to the frontend or admin etc don't need them |
|
| 99 | + * |
|
| 100 | + * @throws \EE_Error |
|
| 101 | + */ |
|
| 102 | + public static function set_hooks_rest_api() |
|
| 103 | + { |
|
| 104 | + //set hooks which account for changes made to the API |
|
| 105 | + EED_Core_Rest_Api::_set_hooks_for_changes(); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * public wrapper of _set_hooks_for_changes. |
|
| 112 | + * Loads all the hooks which make requests to old versions of the API |
|
| 113 | + * appear the same as they always did |
|
| 114 | + * |
|
| 115 | + * @throws EE_Error |
|
| 116 | + */ |
|
| 117 | + public static function set_hooks_for_changes() |
|
| 118 | + { |
|
| 119 | + self::_set_hooks_for_changes(); |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * If the user appears to be using WP API basic auth, tell them (via a persistent |
|
| 126 | + * admin notice and an email) that we're going to remove it soon, so they should |
|
| 127 | + * replace it with application passwords. |
|
| 128 | + * |
|
| 129 | + * @throws InvalidDataTypeException |
|
| 130 | + */ |
|
| 131 | + public static function maybe_notify_of_basic_auth_removal() |
|
| 132 | + { |
|
| 133 | + if ( |
|
| 134 | + apply_filters( |
|
| 135 | + 'FHEE__EED_Core_Rest_Api__maybe_notify_of_basic_auth_removal__override', |
|
| 136 | + ! isset($_SERVER['PHP_AUTH_USER']) |
|
| 137 | + && ! isset($_SERVER['HTTP_AUTHORIZATION']) |
|
| 138 | + ) |
|
| 139 | + ) { |
|
| 140 | + //sure it's a WP API request, but they aren't using basic auth, so don't bother them |
|
| 141 | + return; |
|
| 142 | + } |
|
| 143 | + //ok they're using the WP API with Basic Auth |
|
| 144 | + new PersistentAdminNotice( |
|
| 145 | + 'using_basic_auth', |
|
| 146 | + sprintf( |
|
| 147 | + __( |
|
| 148 | + 'We noticed you\'re using the WP API, which is used by the Event Espresso 4 mobile apps. Because of security and compatibility concerns, we will soon be removing our default authentication mechanism, WP API Basic Auth, from Event Espresso. It is recommended you instead install the %1$sWP Application Passwords plugin%2$s and use it with the EE4 Mobile apps. See %3$sour mobile app documentation%2$s for more information. %4$sIf you have installed the WP API Basic Auth plugin separately, or are not using the Event Espresso 4 mobile apps, you can disregard this message.%4$sThe Event Espresso Team', |
|
| 149 | + 'event_espresso' |
|
| 150 | + ), |
|
| 151 | + '<a href="https://wordpress.org/plugins/application-passwords/">', |
|
| 152 | + '</a>', |
|
| 153 | + '<a href="https://eventespresso.com/wiki/ee4-event-apps/#authentication">', |
|
| 154 | + '<br/>' |
|
| 155 | + ) |
|
| 156 | + ); |
|
| 157 | + if ( ! get_option('ee_notified_admin_on_basic_auth_removal', false)) { |
|
| 158 | + add_option('ee_notified_admin_on_basic_auth_removal', true); |
|
| 159 | + //piggy back off EE_Error::set_content_type, which sets the content type to HTML |
|
| 160 | + add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type')); |
|
| 161 | + //and send the message to the site admin too |
|
| 162 | + wp_mail(get_option('admin_email'), |
|
| 163 | + __('Notice of Removal of WP API Basic Auth From Event Espresso 4', 'event_espresso'), $message); |
|
| 164 | + remove_filter('wp_mail_content_type', array('EE_Error', 'set_content_type')); |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * Loads all the hooks which make requests to old versions of the API |
|
| 172 | + * appear the same as they always did |
|
| 173 | + * |
|
| 174 | + * @throws EE_Error |
|
| 175 | + */ |
|
| 176 | + protected static function _set_hooks_for_changes() |
|
| 177 | + { |
|
| 178 | + $folder_contents = EEH_File::get_contents_of_folders(array(EE_LIBRARIES . 'rest_api' . DS . 'changes'), false); |
|
| 179 | + foreach ($folder_contents as $classname_in_namespace => $filepath) { |
|
| 180 | + //ignore the base parent class |
|
| 181 | + //and legacy named classes |
|
| 182 | + if ($classname_in_namespace === 'ChangesInBase' |
|
| 183 | + || strpos($classname_in_namespace, 'Changes_In_') === 0 |
|
| 184 | + ) { |
|
| 185 | + continue; |
|
| 186 | + } |
|
| 187 | + $full_classname = 'EventEspresso\core\libraries\rest_api\changes\\' . $classname_in_namespace; |
|
| 188 | + if (class_exists($full_classname)) { |
|
| 189 | + $instance_of_class = new $full_classname; |
|
| 190 | + if ($instance_of_class instanceof ChangesInBase) { |
|
| 191 | + $instance_of_class->setHooks(); |
|
| 192 | + } |
|
| 193 | + } |
|
| 194 | + } |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * Filters the WP routes to add our EE-related ones. This takes a bit of time |
|
| 201 | + * so we actually prefer to only do it when an EE plugin is activated or upgraded |
|
| 202 | + * |
|
| 203 | + * @throws \EE_Error |
|
| 204 | + */ |
|
| 205 | + public static function register_routes() |
|
| 206 | + { |
|
| 207 | + foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_routes) { |
|
| 208 | + foreach ($relative_routes as $relative_route => $data_for_multiple_endpoints) { |
|
| 209 | + /** |
|
| 210 | + * @var array $data_for_multiple_endpoints numerically indexed array |
|
| 211 | + * but can also contain route options like { |
|
| 212 | + * @type array $schema { |
|
| 213 | + * @type callable $schema_callback |
|
| 214 | + * @type array $callback_args arguments that will be passed to the callback, after the |
|
| 215 | + * WP_REST_Request of course |
|
| 216 | + * } |
|
| 217 | + * } |
|
| 218 | + */ |
|
| 219 | + //when registering routes, register all the endpoints' data at the same time |
|
| 220 | + $multiple_endpoint_args = array(); |
|
| 221 | + foreach ($data_for_multiple_endpoints as $endpoint_key => $data_for_single_endpoint) { |
|
| 222 | + /** |
|
| 223 | + * @var array $data_for_single_endpoint { |
|
| 224 | + * @type callable $callback |
|
| 225 | + * @type string methods |
|
| 226 | + * @type array args |
|
| 227 | + * @type array _links |
|
| 228 | + * @type array $callback_args arguments that will be passed to the callback, after the |
|
| 229 | + * WP_REST_Request of course |
|
| 230 | + * } |
|
| 231 | + */ |
|
| 232 | + //skip route options |
|
| 233 | + if (! is_numeric($endpoint_key)) { |
|
| 234 | + continue; |
|
| 235 | + } |
|
| 236 | + if (! isset($data_for_single_endpoint['callback'], $data_for_single_endpoint['methods'])) { |
|
| 237 | + throw new EE_Error( |
|
| 238 | + esc_html__( |
|
| 239 | + // @codingStandardsIgnoreStart |
|
| 240 | + 'Endpoint configuration data needs to have entries "callback" (callable) and "methods" (comma-separated list of accepts HTTP methods).', |
|
| 241 | + // @codingStandardsIgnoreEnd |
|
| 242 | + 'event_espresso') |
|
| 243 | + ); |
|
| 244 | + } |
|
| 245 | + $callback = $data_for_single_endpoint['callback']; |
|
| 246 | + $single_endpoint_args = array( |
|
| 247 | + 'methods' => $data_for_single_endpoint['methods'], |
|
| 248 | + 'args' => isset($data_for_single_endpoint['args']) ? $data_for_single_endpoint['args'] |
|
| 249 | + : array(), |
|
| 250 | + ); |
|
| 251 | + if (isset($data_for_single_endpoint['_links'])) { |
|
| 252 | + $single_endpoint_args['_links'] = $data_for_single_endpoint['_links']; |
|
| 253 | + } |
|
| 254 | + if (isset($data_for_single_endpoint['callback_args'])) { |
|
| 255 | + $callback_args = $data_for_single_endpoint['callback_args']; |
|
| 256 | + $single_endpoint_args['callback'] = function (\WP_REST_Request $request) use ( |
|
| 257 | + $callback, |
|
| 258 | + $callback_args |
|
| 259 | + ) { |
|
| 260 | + array_unshift($callback_args, $request); |
|
| 261 | + return call_user_func_array( |
|
| 262 | + $callback, |
|
| 263 | + $callback_args |
|
| 264 | + ); |
|
| 265 | + }; |
|
| 266 | + } else { |
|
| 267 | + $single_endpoint_args['callback'] = $data_for_single_endpoint['callback']; |
|
| 268 | + } |
|
| 269 | + $multiple_endpoint_args[] = $single_endpoint_args; |
|
| 270 | + } |
|
| 271 | + if (isset($data_for_multiple_endpoints['schema'])) { |
|
| 272 | + $schema_route_data = $data_for_multiple_endpoints['schema']; |
|
| 273 | + $schema_callback = $schema_route_data['schema_callback']; |
|
| 274 | + $callback_args = $schema_route_data['callback_args']; |
|
| 275 | + $multiple_endpoint_args['schema'] = function () use ($schema_callback, $callback_args) { |
|
| 276 | + return call_user_func_array( |
|
| 277 | + $schema_callback, |
|
| 278 | + $callback_args |
|
| 279 | + ); |
|
| 280 | + }; |
|
| 281 | + } |
|
| 282 | + register_rest_route( |
|
| 283 | + $namespace, |
|
| 284 | + $relative_route, |
|
| 285 | + $multiple_endpoint_args |
|
| 286 | + ); |
|
| 287 | + } |
|
| 288 | + } |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + |
|
| 292 | + |
|
| 293 | + /** |
|
| 294 | + * Checks if there was a version change or something that merits invalidating the cached |
|
| 295 | + * route data. If so, invalidates the cached route data so that it gets refreshed |
|
| 296 | + * next time the WP API is used |
|
| 297 | + */ |
|
| 298 | + public static function invalidate_cached_route_data_on_version_change() |
|
| 299 | + { |
|
| 300 | + if (EE_System::instance()->detect_req_type() !== EE_System::req_type_normal) { |
|
| 301 | + EED_Core_Rest_Api::invalidate_cached_route_data(); |
|
| 302 | + } |
|
| 303 | + foreach (EE_Registry::instance()->addons as $addon) { |
|
| 304 | + if ($addon instanceof EE_Addon && $addon->detect_req_type() !== EE_System::req_type_normal) { |
|
| 305 | + EED_Core_Rest_Api::invalidate_cached_route_data(); |
|
| 306 | + } |
|
| 307 | + } |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + |
|
| 311 | + |
|
| 312 | + /** |
|
| 313 | + * Removes the cached route data so it will get refreshed next time the WP API is used |
|
| 314 | + */ |
|
| 315 | + public static function invalidate_cached_route_data() |
|
| 316 | + { |
|
| 317 | + //delete the saved EE REST API routes |
|
| 318 | + foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden) { |
|
| 319 | + delete_option(EED_Core_Rest_Api::saved_routes_option_names . $version); |
|
| 320 | + } |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + |
|
| 324 | + |
|
| 325 | + /** |
|
| 326 | + * Gets the EE route data |
|
| 327 | + * |
|
| 328 | + * @return array top-level key is the namespace, next-level key is the route and its value is array{ |
|
| 329 | + * @throws \EE_Error |
|
| 330 | + * @type string|array $callback |
|
| 331 | + * @type string $methods |
|
| 332 | + * @type boolean $hidden_endpoint |
|
| 333 | + * } |
|
| 334 | + */ |
|
| 335 | + public static function get_ee_route_data() |
|
| 336 | + { |
|
| 337 | + $ee_routes = array(); |
|
| 338 | + foreach (self::versions_served() as $version => $hidden_endpoints) { |
|
| 339 | + $ee_routes[self::ee_api_namespace . $version] = self::_get_ee_route_data_for_version( |
|
| 340 | + $version, |
|
| 341 | + $hidden_endpoints |
|
| 342 | + ); |
|
| 343 | + } |
|
| 344 | + return $ee_routes; |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + |
|
| 348 | + |
|
| 349 | + /** |
|
| 350 | + * Gets the EE route data from the wp options if it exists already, |
|
| 351 | + * otherwise re-generates it and saves it to the option |
|
| 352 | + * |
|
| 353 | + * @param string $version |
|
| 354 | + * @param boolean $hidden_endpoints |
|
| 355 | + * @return array |
|
| 356 | + * @throws \EE_Error |
|
| 357 | + */ |
|
| 358 | + protected static function _get_ee_route_data_for_version($version, $hidden_endpoints = false) |
|
| 359 | + { |
|
| 360 | + $ee_routes = get_option(self::saved_routes_option_names . $version, null); |
|
| 361 | + if (! $ee_routes || (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE)) { |
|
| 362 | + $ee_routes = self::_save_ee_route_data_for_version($version, $hidden_endpoints); |
|
| 363 | + } |
|
| 364 | + return $ee_routes; |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + |
|
| 368 | + |
|
| 369 | + /** |
|
| 370 | + * Saves the EE REST API route data to a wp option and returns it |
|
| 371 | + * |
|
| 372 | + * @param string $version |
|
| 373 | + * @param boolean $hidden_endpoints |
|
| 374 | + * @return mixed|null |
|
| 375 | + * @throws \EE_Error |
|
| 376 | + */ |
|
| 377 | + protected static function _save_ee_route_data_for_version($version, $hidden_endpoints = false) |
|
| 378 | + { |
|
| 379 | + $instance = self::instance(); |
|
| 380 | + $routes = apply_filters( |
|
| 381 | + 'EED_Core_Rest_Api__save_ee_route_data_for_version__routes', |
|
| 382 | + array_replace_recursive( |
|
| 383 | + $instance->_get_config_route_data_for_version($version, $hidden_endpoints), |
|
| 384 | + $instance->_get_meta_route_data_for_version($version, $hidden_endpoints), |
|
| 385 | + $instance->_get_model_route_data_for_version($version, $hidden_endpoints), |
|
| 386 | + $instance->_get_rpc_route_data_for_version($version, $hidden_endpoints) |
|
| 387 | + ) |
|
| 388 | + ); |
|
| 389 | + $option_name = self::saved_routes_option_names . $version; |
|
| 390 | + if (get_option($option_name)) { |
|
| 391 | + update_option($option_name, $routes, true); |
|
| 392 | + } else { |
|
| 393 | + add_option($option_name, $routes, null, 'no'); |
|
| 394 | + } |
|
| 395 | + return $routes; |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + |
|
| 399 | + |
|
| 400 | + /** |
|
| 401 | + * Calculates all the EE routes and saves it to a WordPress option so we don't |
|
| 402 | + * need to calculate it on every request |
|
| 403 | + * |
|
| 404 | + * @deprecated since version 4.9.1 |
|
| 405 | + * @return void |
|
| 406 | + */ |
|
| 407 | + public static function save_ee_routes() |
|
| 408 | + { |
|
| 409 | + if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 410 | + $instance = self::instance(); |
|
| 411 | + $routes = apply_filters( |
|
| 412 | + 'EED_Core_Rest_Api__save_ee_routes__routes', |
|
| 413 | + array_replace_recursive( |
|
| 414 | + $instance->_register_config_routes(), |
|
| 415 | + $instance->_register_meta_routes(), |
|
| 416 | + $instance->_register_model_routes(), |
|
| 417 | + $instance->_register_rpc_routes() |
|
| 418 | + ) |
|
| 419 | + ); |
|
| 420 | + update_option(self::saved_routes_option_names, $routes, true); |
|
| 421 | + } |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + |
|
| 425 | + |
|
| 426 | + /** |
|
| 427 | + * Gets all the route information relating to EE models |
|
| 428 | + * |
|
| 429 | + * @return array @see get_ee_route_data |
|
| 430 | + * @deprecated since version 4.9.1 |
|
| 431 | + */ |
|
| 432 | + protected function _register_model_routes() |
|
| 433 | + { |
|
| 434 | + $model_routes = array(); |
|
| 435 | + foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
| 436 | + $model_routes[EED_Core_Rest_Api::ee_api_namespace |
|
| 437 | + . $version] = $this->_get_config_route_data_for_version($version, $hidden_endpoint); |
|
| 438 | + } |
|
| 439 | + return $model_routes; |
|
| 440 | + } |
|
| 441 | + |
|
| 442 | + |
|
| 443 | + |
|
| 444 | + /** |
|
| 445 | + * Decides whether or not to add write endpoints for this model. |
|
| 446 | + * |
|
| 447 | + * Currently, this defaults to exclude all global tables and models |
|
| 448 | + * which would allow inserting WP core data (we don't want to duplicate |
|
| 449 | + * what WP API does, as it's unnecessary, extra work, and potentially extra bugs) |
|
| 450 | + * @param EEM_Base $model |
|
| 451 | + * @return bool |
|
| 452 | + */ |
|
| 453 | + public static function should_have_write_endpoints(EEM_Base $model) |
|
| 454 | + { |
|
| 455 | + if ($model->is_wp_core_model()){ |
|
| 456 | + return false; |
|
| 457 | + } |
|
| 458 | + foreach($model->get_tables() as $table){ |
|
| 459 | + if( $table->is_global()){ |
|
| 460 | + return false; |
|
| 461 | + } |
|
| 462 | + } |
|
| 463 | + return true; |
|
| 464 | + } |
|
| 465 | + |
|
| 466 | + |
|
| 467 | + |
|
| 468 | + /** |
|
| 469 | + * Gets the names of all models which should have plural routes (eg `ee/v4.8.36/events`) |
|
| 470 | + * in this versioned namespace of EE4 |
|
| 471 | + * @param $version |
|
| 472 | + * @return array keys are model names (eg 'Event') and values ar either classnames (eg 'EEM_Event') |
|
| 473 | + */ |
|
| 474 | + public static function model_names_with_plural_routes($version){ |
|
| 475 | + $model_version_info = new ModelVersionInfo($version); |
|
| 476 | + $models_to_register = $model_version_info->modelsForRequestedVersion(); |
|
| 477 | + //let's not bother having endpoints for extra metas |
|
| 478 | + unset( |
|
| 479 | + $models_to_register['Extra_Meta'], |
|
| 480 | + $models_to_register['Extra_Join'], |
|
| 481 | + $models_to_register['Post_Meta'] |
|
| 482 | + ); |
|
| 483 | + return apply_filters( |
|
| 484 | + 'FHEE__EED_Core_REST_API___register_model_routes', |
|
| 485 | + $models_to_register |
|
| 486 | + ); |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + |
|
| 490 | + |
|
| 491 | + /** |
|
| 492 | + * Gets the route data for EE models in the specified version |
|
| 493 | + * |
|
| 494 | + * @param string $version |
|
| 495 | + * @param boolean $hidden_endpoint |
|
| 496 | + * @return array |
|
| 497 | + * @throws EE_Error |
|
| 498 | + */ |
|
| 499 | + protected function _get_model_route_data_for_version($version, $hidden_endpoint = false) |
|
| 500 | + { |
|
| 501 | + $model_routes = array(); |
|
| 502 | + $model_version_info = new ModelVersionInfo($version); |
|
| 503 | + foreach (EED_Core_Rest_Api::model_names_with_plural_routes($version) as $model_name => $model_classname) { |
|
| 504 | + $model = \EE_Registry::instance()->load_model($model_name); |
|
| 505 | + //if this isn't a valid model then let's skip iterate to the next item in the loop. |
|
| 506 | + if (! $model instanceof EEM_Base) { |
|
| 507 | + continue; |
|
| 508 | + } |
|
| 509 | + //yes we could just register one route for ALL models, but then they wouldn't show up in the index |
|
| 510 | + $plural_model_route = EED_Core_Rest_Api::get_collection_route($model); |
|
| 511 | + $singular_model_route = EED_Core_Rest_Api::get_entity_route($model, '(?P<id>[^\/]+)'); |
|
| 512 | + $model_routes[$plural_model_route] = array( |
|
| 513 | + array( |
|
| 514 | + 'callback' => array( |
|
| 515 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
| 516 | + 'handleRequestGetAll', |
|
| 517 | + ), |
|
| 518 | + 'callback_args' => array($version, $model_name), |
|
| 519 | + 'methods' => WP_REST_Server::READABLE, |
|
| 520 | + 'hidden_endpoint' => $hidden_endpoint, |
|
| 521 | + 'args' => $this->_get_read_query_params($model, $version), |
|
| 522 | + '_links' => array( |
|
| 523 | + 'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace . $version . $singular_model_route), |
|
| 524 | + ), |
|
| 525 | + ), |
|
| 526 | + 'schema' => array( |
|
| 527 | + 'schema_callback' => array( |
|
| 528 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
| 529 | + 'handleSchemaRequest', |
|
| 530 | + ), |
|
| 531 | + 'callback_args' => array($version, $model_name), |
|
| 532 | + ), |
|
| 533 | + ); |
|
| 534 | + $model_routes[$singular_model_route] = array( |
|
| 535 | + array( |
|
| 536 | + 'callback' => array( |
|
| 537 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
| 538 | + 'handleRequestGetOne', |
|
| 539 | + ), |
|
| 540 | + 'callback_args' => array($version, $model_name), |
|
| 541 | + 'methods' => WP_REST_Server::READABLE, |
|
| 542 | + 'hidden_endpoint' => $hidden_endpoint, |
|
| 543 | + 'args' => $this->_get_response_selection_query_params($model, $version), |
|
| 544 | + ), |
|
| 545 | + ); |
|
| 546 | + if( apply_filters( |
|
| 547 | + 'FHEE__EED_Core_Rest_Api___get_model_route_data_for_version__add_write_endpoints', |
|
| 548 | + EED_Core_Rest_Api::should_have_write_endpoints($model), |
|
| 549 | + $model |
|
| 550 | + )){ |
|
| 551 | + $model_routes[$plural_model_route][] = array( |
|
| 552 | + 'callback' => array( |
|
| 553 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
| 554 | + 'handleRequestInsert', |
|
| 555 | + ), |
|
| 556 | + 'callback_args' => array($version, $model_name), |
|
| 557 | + 'methods' => WP_REST_Server::CREATABLE, |
|
| 558 | + 'hidden_endpoint' => $hidden_endpoint, |
|
| 559 | + 'args' => $this->_get_write_params($model_name, $model_version_info, true), |
|
| 560 | + ); |
|
| 561 | + $model_routes[$singular_model_route] = array_merge( |
|
| 562 | + $model_routes[$singular_model_route], |
|
| 563 | + array( |
|
| 564 | + array( |
|
| 565 | + 'callback' => array( |
|
| 566 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
| 567 | + 'handleRequestUpdate', |
|
| 568 | + ), |
|
| 569 | + 'callback_args' => array($version, $model_name), |
|
| 570 | + 'methods' => WP_REST_Server::EDITABLE, |
|
| 571 | + 'hidden_endpoint' => $hidden_endpoint, |
|
| 572 | + 'args' => $this->_get_write_params($model_name, $model_version_info), |
|
| 573 | + ), |
|
| 574 | + array( |
|
| 575 | + 'callback' => array( |
|
| 576 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
| 577 | + 'handleRequestDelete', |
|
| 578 | + ), |
|
| 579 | + 'callback_args' => array($version, $model_name), |
|
| 580 | + 'methods' => WP_REST_Server::DELETABLE, |
|
| 581 | + 'hidden_endpoint' => $hidden_endpoint, |
|
| 582 | + 'args' => $this->_get_delete_query_params($model, $version), |
|
| 583 | + ) |
|
| 584 | + ) |
|
| 585 | + ); |
|
| 586 | + } |
|
| 587 | + foreach ($model->relation_settings() as $relation_name => $relation_obj) { |
|
| 588 | + |
|
| 589 | + $related_route = EED_Core_Rest_Api::get_relation_route_via( |
|
| 590 | + $model, |
|
| 591 | + '(?P<id>[^\/]+)', |
|
| 592 | + $relation_obj |
|
| 593 | + ); |
|
| 594 | + $endpoints = array( |
|
| 595 | + array( |
|
| 596 | + 'callback' => array( |
|
| 597 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
| 598 | + 'handleRequestGetRelated', |
|
| 599 | + ), |
|
| 600 | + 'callback_args' => array($version, $model_name, $relation_name), |
|
| 601 | + 'methods' => WP_REST_Server::READABLE, |
|
| 602 | + 'hidden_endpoint' => $hidden_endpoint, |
|
| 603 | + 'args' => $this->_get_read_query_params($relation_obj->get_other_model(), $version), |
|
| 604 | + ), |
|
| 605 | + ); |
|
| 606 | + $model_routes[$related_route] = $endpoints; |
|
| 607 | + } |
|
| 608 | + } |
|
| 609 | + return $model_routes; |
|
| 610 | + } |
|
| 611 | + |
|
| 612 | + |
|
| 613 | + |
|
| 614 | + /** |
|
| 615 | + * Gets the relative URI to a model's REST API plural route, after the EE4 versioned namespace, |
|
| 616 | + * excluding the preceding slash. |
|
| 617 | + * Eg you pass get_plural_route_to('Event') = 'events' |
|
| 618 | + * |
|
| 619 | + * @param EEM_Base $model |
|
| 620 | + * @return string |
|
| 621 | + */ |
|
| 622 | + public static function get_collection_route(EEM_Base $model) |
|
| 623 | + { |
|
| 624 | + return EEH_Inflector::pluralize_and_lower($model->get_this_model_name()); |
|
| 625 | + } |
|
| 626 | + |
|
| 627 | + |
|
| 628 | + |
|
| 629 | + /** |
|
| 630 | + * Gets the relative URI to a model's REST API singular route, after the EE4 versioned namespace, |
|
| 631 | + * excluding the preceding slash. |
|
| 632 | + * Eg you pass get_plural_route_to('Event', 12) = 'events/12' |
|
| 633 | + * |
|
| 634 | + * @param EEM_Base $model eg Event or Venue |
|
| 635 | + * @param string $id |
|
| 636 | + * @return string |
|
| 637 | + */ |
|
| 638 | + public static function get_entity_route($model, $id) |
|
| 639 | + { |
|
| 640 | + return EED_Core_Rest_Api::get_collection_route($model). '/' . $id; |
|
| 641 | + } |
|
| 642 | + |
|
| 643 | + |
|
| 644 | + /** |
|
| 645 | + * Gets the relative URI to a model's REST API singular route, after the EE4 versioned namespace, |
|
| 646 | + * excluding the preceding slash. |
|
| 647 | + * Eg you pass get_plural_route_to('Event', 12) = 'events/12' |
|
| 648 | + * |
|
| 649 | + * @param EEM_Base $model eg Event or Venue |
|
| 650 | + * @param string $id |
|
| 651 | + * @param EE_Model_Relation_Base $relation_obj |
|
| 652 | + * @return string |
|
| 653 | + */ |
|
| 654 | + public static function get_relation_route_via(EEM_Base $model, $id, EE_Model_Relation_Base $relation_obj) |
|
| 655 | + { |
|
| 656 | + $related_model_name_endpoint_part = ModelRead::getRelatedEntityName( |
|
| 657 | + $relation_obj->get_other_model()->get_this_model_name(), |
|
| 658 | + $relation_obj |
|
| 659 | + ); |
|
| 660 | + return EED_Core_Rest_Api::get_entity_route($model, $id) . '/' . $related_model_name_endpoint_part; |
|
| 661 | + } |
|
| 662 | + |
|
| 663 | + |
|
| 664 | + |
|
| 665 | + /** |
|
| 666 | + * Adds onto the $relative_route the EE4 REST API versioned namespace. |
|
| 667 | + * Eg if given '4.8.36' and 'events', will return 'ee/v4.8.36/events' |
|
| 668 | + * @param string $relative_route |
|
| 669 | + * @param string $version |
|
| 670 | + * @return string |
|
| 671 | + */ |
|
| 672 | + public static function get_versioned_route_to($relative_route, $version = '4.8.36'){ |
|
| 673 | + return '/' . EED_Core_Rest_Api::ee_api_namespace . $version . '/' . $relative_route; |
|
| 674 | + } |
|
| 675 | + |
|
| 676 | + |
|
| 677 | + |
|
| 678 | + /** |
|
| 679 | + * Adds all the RPC-style routes (remote procedure call-like routes, ie |
|
| 680 | + * routes that don't conform to the traditional REST CRUD-style). |
|
| 681 | + * |
|
| 682 | + * @deprecated since 4.9.1 |
|
| 683 | + */ |
|
| 684 | + protected function _register_rpc_routes() |
|
| 685 | + { |
|
| 686 | + $routes = array(); |
|
| 687 | + foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
| 688 | + $routes[self::ee_api_namespace . $version] = $this->_get_rpc_route_data_for_version( |
|
| 689 | + $version, |
|
| 690 | + $hidden_endpoint |
|
| 691 | + ); |
|
| 692 | + } |
|
| 693 | + return $routes; |
|
| 694 | + } |
|
| 695 | + |
|
| 696 | + |
|
| 697 | + |
|
| 698 | + /** |
|
| 699 | + * @param string $version |
|
| 700 | + * @param boolean $hidden_endpoint |
|
| 701 | + * @return array |
|
| 702 | + */ |
|
| 703 | + protected function _get_rpc_route_data_for_version($version, $hidden_endpoint = false) |
|
| 704 | + { |
|
| 705 | + $this_versions_routes = array(); |
|
| 706 | + //checkin endpoint |
|
| 707 | + $this_versions_routes['registrations/(?P<REG_ID>\d+)/toggle_checkin_for_datetime/(?P<DTT_ID>\d+)'] = array( |
|
| 708 | + array( |
|
| 709 | + 'callback' => array( |
|
| 710 | + 'EventEspresso\core\libraries\rest_api\controllers\rpc\Checkin', |
|
| 711 | + 'handleRequestToggleCheckin', |
|
| 712 | + ), |
|
| 713 | + 'methods' => WP_REST_Server::CREATABLE, |
|
| 714 | + 'hidden_endpoint' => $hidden_endpoint, |
|
| 715 | + 'args' => array( |
|
| 716 | + 'force' => array( |
|
| 717 | + 'required' => false, |
|
| 718 | + 'default' => false, |
|
| 719 | + 'description' => __( |
|
| 720 | + // @codingStandardsIgnoreStart |
|
| 721 | + 'Whether to force toggle checkin, or to verify the registration status and allowed ticket uses', |
|
| 722 | + // @codingStandardsIgnoreEnd |
|
| 723 | + 'event_espresso' |
|
| 724 | + ), |
|
| 725 | + ), |
|
| 726 | + ), |
|
| 727 | + 'callback_args' => array($version), |
|
| 728 | + ), |
|
| 729 | + ); |
|
| 730 | + return apply_filters( |
|
| 731 | + 'FHEE__EED_Core_Rest_Api___register_rpc_routes__this_versions_routes', |
|
| 732 | + $this_versions_routes, |
|
| 733 | + $version, |
|
| 734 | + $hidden_endpoint |
|
| 735 | + ); |
|
| 736 | + } |
|
| 737 | + |
|
| 738 | + |
|
| 739 | + |
|
| 740 | + /** |
|
| 741 | + * Gets the query params that can be used when request one or many |
|
| 742 | + * |
|
| 743 | + * @param EEM_Base $model |
|
| 744 | + * @param string $version |
|
| 745 | + * @return array |
|
| 746 | + */ |
|
| 747 | + protected function _get_response_selection_query_params(\EEM_Base $model, $version) |
|
| 748 | + { |
|
| 749 | + return apply_filters( |
|
| 750 | + 'FHEE__EED_Core_Rest_Api___get_response_selection_query_params', |
|
| 751 | + array( |
|
| 752 | + 'include' => array( |
|
| 753 | + 'required' => false, |
|
| 754 | + 'default' => '*', |
|
| 755 | + 'type' => 'string', |
|
| 756 | + ), |
|
| 757 | + 'calculate' => array( |
|
| 758 | + 'required' => false, |
|
| 759 | + 'default' => '', |
|
| 760 | + 'enum' => self::$_field_calculator->retrieveCalculatedFieldsForModel($model), |
|
| 761 | + 'type' => 'string', |
|
| 762 | + //because we accept a CSV'd list of the enumerated strings, WP core validation and sanitization |
|
| 763 | + //freaks out. We'll just validate this argument while handling the request |
|
| 764 | + 'validate_callback' => null, |
|
| 765 | + 'sanitize_callback' => null, |
|
| 766 | + ), |
|
| 767 | + ), |
|
| 768 | + $model, |
|
| 769 | + $version |
|
| 770 | + ); |
|
| 771 | + } |
|
| 772 | + |
|
| 773 | + |
|
| 774 | + |
|
| 775 | + /** |
|
| 776 | + * Gets the parameters acceptable for delete requests |
|
| 777 | + * |
|
| 778 | + * @param \EEM_Base $model |
|
| 779 | + * @param string $version |
|
| 780 | + * @return array |
|
| 781 | + */ |
|
| 782 | + protected function _get_delete_query_params(\EEM_Base $model, $version) |
|
| 783 | + { |
|
| 784 | + $params_for_delete = array( |
|
| 785 | + 'allow_blocking' => array( |
|
| 786 | + 'required' => false, |
|
| 787 | + 'default' => true, |
|
| 788 | + 'type' => 'boolean', |
|
| 789 | + ), |
|
| 790 | + ); |
|
| 791 | + $params_for_delete['force'] = array( |
|
| 792 | + 'required' => false, |
|
| 793 | + 'default' => false, |
|
| 794 | + 'type' => 'boolean', |
|
| 795 | + ); |
|
| 796 | + return apply_filters( |
|
| 797 | + 'FHEE__EED_Core_Rest_Api___get_delete_query_params', |
|
| 798 | + $params_for_delete, |
|
| 799 | + $model, |
|
| 800 | + $version |
|
| 801 | + ); |
|
| 802 | + } |
|
| 803 | + |
|
| 804 | + |
|
| 805 | + |
|
| 806 | + /** |
|
| 807 | + * Gets info about reading query params that are acceptable |
|
| 808 | + * |
|
| 809 | + * @param \EEM_Base $model eg 'Event' or 'Venue' |
|
| 810 | + * @param string $version |
|
| 811 | + * @return array describing the args acceptable when querying this model |
|
| 812 | + * @throws EE_Error |
|
| 813 | + */ |
|
| 814 | + protected function _get_read_query_params(\EEM_Base $model, $version) |
|
| 815 | + { |
|
| 816 | + $default_orderby = array(); |
|
| 817 | + foreach ($model->get_combined_primary_key_fields() as $key_field) { |
|
| 818 | + $default_orderby[$key_field->get_name()] = 'ASC'; |
|
| 819 | + } |
|
| 820 | + return array_merge( |
|
| 821 | + $this->_get_response_selection_query_params($model, $version), |
|
| 822 | + array( |
|
| 823 | + 'where' => array( |
|
| 824 | + 'required' => false, |
|
| 825 | + 'default' => array(), |
|
| 826 | + 'type' => 'object', |
|
| 827 | + //because we accept an almost infinite list of possible where conditions, WP |
|
| 828 | + // core validation and sanitization freaks out. We'll just validate this argument |
|
| 829 | + // while handling the request |
|
| 830 | + 'validate_callback' => null, |
|
| 831 | + 'sanitize_callback' => null, |
|
| 832 | + ), |
|
| 833 | + 'limit' => array( |
|
| 834 | + 'required' => false, |
|
| 835 | + 'default' => EED_Core_Rest_Api::get_default_query_limit(), |
|
| 836 | + 'type' => array( |
|
| 837 | + 'array', |
|
| 838 | + 'string', |
|
| 839 | + 'integer', |
|
| 840 | + ), |
|
| 841 | + //because we accept a variety of types, WP core validation and sanitization |
|
| 842 | + //freaks out. We'll just validate this argument while handling the request |
|
| 843 | + 'validate_callback' => null, |
|
| 844 | + 'sanitize_callback' => null, |
|
| 845 | + ), |
|
| 846 | + 'order_by' => array( |
|
| 847 | + 'required' => false, |
|
| 848 | + 'default' => $default_orderby, |
|
| 849 | + 'type' => array( |
|
| 850 | + 'object', |
|
| 851 | + 'string', |
|
| 852 | + ),//because we accept a variety of types, WP core validation and sanitization |
|
| 853 | + //freaks out. We'll just validate this argument while handling the request |
|
| 854 | + 'validate_callback' => null, |
|
| 855 | + 'sanitize_callback' => null, |
|
| 856 | + ), |
|
| 857 | + 'group_by' => array( |
|
| 858 | + 'required' => false, |
|
| 859 | + 'default' => null, |
|
| 860 | + 'type' => array( |
|
| 861 | + 'object', |
|
| 862 | + 'string', |
|
| 863 | + ), |
|
| 864 | + //because we accept an almost infinite list of possible groupings, |
|
| 865 | + // WP core validation and sanitization |
|
| 866 | + //freaks out. We'll just validate this argument while handling the request |
|
| 867 | + 'validate_callback' => null, |
|
| 868 | + 'sanitize_callback' => null, |
|
| 869 | + ), |
|
| 870 | + 'having' => array( |
|
| 871 | + 'required' => false, |
|
| 872 | + 'default' => null, |
|
| 873 | + 'type' => 'object', |
|
| 874 | + //because we accept an almost infinite list of possible where conditions, WP |
|
| 875 | + // core validation and sanitization freaks out. We'll just validate this argument |
|
| 876 | + // while handling the request |
|
| 877 | + 'validate_callback' => null, |
|
| 878 | + 'sanitize_callback' => null, |
|
| 879 | + ), |
|
| 880 | + 'caps' => array( |
|
| 881 | + 'required' => false, |
|
| 882 | + 'default' => EEM_Base::caps_read, |
|
| 883 | + 'type' => 'string', |
|
| 884 | + 'enum' => array( |
|
| 885 | + EEM_Base::caps_read, |
|
| 886 | + EEM_Base::caps_read_admin, |
|
| 887 | + EEM_Base::caps_edit, |
|
| 888 | + EEM_Base::caps_delete |
|
| 889 | + ) |
|
| 890 | + ), |
|
| 891 | + ) |
|
| 892 | + ); |
|
| 893 | + } |
|
| 894 | + |
|
| 895 | + |
|
| 896 | + |
|
| 897 | + /** |
|
| 898 | + * Gets parameter information for a model regarding writing data |
|
| 899 | + * |
|
| 900 | + * @param string $model_name |
|
| 901 | + * @param ModelVersionInfo $model_version_info |
|
| 902 | + * @param boolean $create whether this is for request to create (in which case we need |
|
| 903 | + * all required params) or just to update (in which case we don't need those on every request) |
|
| 904 | + * @return array |
|
| 905 | + */ |
|
| 906 | + protected function _get_write_params( |
|
| 907 | + $model_name, |
|
| 908 | + ModelVersionInfo $model_version_info, |
|
| 909 | + $create = false |
|
| 910 | + ) { |
|
| 911 | + $model = EE_Registry::instance()->load_model($model_name); |
|
| 912 | + $fields = $model_version_info->fieldsOnModelInThisVersion($model); |
|
| 913 | + $args_info = array(); |
|
| 914 | + foreach ($fields as $field_name => $field_obj) { |
|
| 915 | + if ($field_obj->is_auto_increment()) { |
|
| 916 | + //totally ignore auto increment IDs |
|
| 917 | + continue; |
|
| 918 | + } |
|
| 919 | + $arg_info = $field_obj->getSchema(); |
|
| 920 | + $required = $create && ! $field_obj->is_nullable() && $field_obj->get_default_value() === null; |
|
| 921 | + $arg_info['required'] = $required; |
|
| 922 | + //remove the read-only flag. If it were read-only we wouldn't list it as an argument while writing, right? |
|
| 923 | + unset($arg_info['readonly']); |
|
| 924 | + $schema_properties = $field_obj->getSchemaProperties(); |
|
| 925 | + if ( |
|
| 926 | + isset($schema_properties['raw']) |
|
| 927 | + && $field_obj->getSchemaType() === 'object' |
|
| 928 | + ) { |
|
| 929 | + //if there's a "raw" form of this argument, use those properties instead |
|
| 930 | + $arg_info = array_replace( |
|
| 931 | + $arg_info, |
|
| 932 | + $schema_properties['raw'] |
|
| 933 | + ); |
|
| 934 | + } |
|
| 935 | + $arg_info['default'] = ModelDataTranslator::prepareFieldValueForJson( |
|
| 936 | + $field_obj, |
|
| 937 | + $field_obj->get_default_value(), |
|
| 938 | + $model_version_info->requestedVersion() |
|
| 939 | + ); |
|
| 940 | + //we do our own validation and sanitization within the controller |
|
| 941 | + $arg_info['sanitize_callback'] = |
|
| 942 | + array( |
|
| 943 | + 'EED_Core_Rest_Api', |
|
| 944 | + 'default_sanitize_callback', |
|
| 945 | + ); |
|
| 946 | + $args_info[$field_name] = $arg_info; |
|
| 947 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
| 948 | + $gmt_arg_info = $arg_info; |
|
| 949 | + $gmt_arg_info['description'] = sprintf( |
|
| 950 | + esc_html__( |
|
| 951 | + '%1$s - the value for this field in UTC. Ignored if %2$s is provided.', |
|
| 952 | + 'event_espresso' |
|
| 953 | + ), |
|
| 954 | + $field_obj->get_nicename(), |
|
| 955 | + $field_name |
|
| 956 | + ); |
|
| 957 | + $args_info[$field_name . '_gmt'] = $gmt_arg_info; |
|
| 958 | + } |
|
| 959 | + } |
|
| 960 | + return $args_info; |
|
| 961 | + } |
|
| 962 | + |
|
| 963 | + |
|
| 964 | + |
|
| 965 | + /** |
|
| 966 | + * Replacement for WP API's 'rest_parse_request_arg'. |
|
| 967 | + * If the value is blank but not required, don't bother validating it. |
|
| 968 | + * Also, it uses our email validation instead of WP API's default. |
|
| 969 | + * |
|
| 970 | + * @param $value |
|
| 971 | + * @param WP_REST_Request $request |
|
| 972 | + * @param $param |
|
| 973 | + * @return bool|true|WP_Error |
|
| 974 | + * @throws InvalidArgumentException |
|
| 975 | + * @throws InvalidInterfaceException |
|
| 976 | + * @throws InvalidDataTypeException |
|
| 977 | + */ |
|
| 978 | + public static function default_sanitize_callback( $value, WP_REST_Request $request, $param) |
|
| 979 | + { |
|
| 980 | + $attributes = $request->get_attributes(); |
|
| 981 | + if (! isset($attributes['args'][$param]) |
|
| 982 | + || ! is_array($attributes['args'][$param])) { |
|
| 983 | + $validation_result = true; |
|
| 984 | + } else { |
|
| 985 | + $args = $attributes['args'][$param]; |
|
| 986 | + if (( |
|
| 987 | + $value === '' |
|
| 988 | + || $value === null |
|
| 989 | + ) |
|
| 990 | + && (! isset($args['required']) |
|
| 991 | + || $args['required'] === false |
|
| 992 | + ) |
|
| 993 | + ) { |
|
| 994 | + //not required and not provided? that's cool |
|
| 995 | + $validation_result = true; |
|
| 996 | + } elseif (isset($args['format']) |
|
| 997 | + && $args['format'] === 'email' |
|
| 998 | + ) { |
|
| 999 | + $validation_result = true; |
|
| 1000 | + if (! self::_validate_email($value)) { |
|
| 1001 | + $validation_result = new WP_Error( |
|
| 1002 | + 'rest_invalid_param', |
|
| 1003 | + esc_html__( |
|
| 1004 | + 'The email address is not valid or does not exist.', |
|
| 1005 | + 'event_espresso' |
|
| 1006 | + ) |
|
| 1007 | + ); |
|
| 1008 | + } |
|
| 1009 | + } else { |
|
| 1010 | + $validation_result = rest_validate_value_from_schema($value, $args, $param); |
|
| 1011 | + } |
|
| 1012 | + } |
|
| 1013 | + if (is_wp_error($validation_result)) { |
|
| 1014 | + return $validation_result; |
|
| 1015 | + } |
|
| 1016 | + return rest_sanitize_request_arg($value, $request, $param); |
|
| 1017 | + } |
|
| 1018 | + |
|
| 1019 | + |
|
| 1020 | + |
|
| 1021 | + /** |
|
| 1022 | + * Returns whether or not this email address is valid. Copied from EE_Email_Validation_Strategy::_validate_email() |
|
| 1023 | + * |
|
| 1024 | + * @param $email |
|
| 1025 | + * @return bool |
|
| 1026 | + * @throws InvalidArgumentException |
|
| 1027 | + * @throws InvalidInterfaceException |
|
| 1028 | + * @throws InvalidDataTypeException |
|
| 1029 | + */ |
|
| 1030 | + protected static function _validate_email($email){ |
|
| 1031 | + try { |
|
| 1032 | + EmailAddressFactory::create($email); |
|
| 1033 | + return true; |
|
| 1034 | + } catch (EmailValidationException $e) { |
|
| 1035 | + return false; |
|
| 1036 | + } |
|
| 1037 | + } |
|
| 1038 | + |
|
| 1039 | + |
|
| 1040 | + |
|
| 1041 | + /** |
|
| 1042 | + * Gets routes for the config |
|
| 1043 | + * |
|
| 1044 | + * @return array @see _register_model_routes |
|
| 1045 | + * @deprecated since version 4.9.1 |
|
| 1046 | + */ |
|
| 1047 | + protected function _register_config_routes() |
|
| 1048 | + { |
|
| 1049 | + $config_routes = array(); |
|
| 1050 | + foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
| 1051 | + $config_routes[self::ee_api_namespace . $version] = $this->_get_config_route_data_for_version( |
|
| 1052 | + $version, |
|
| 1053 | + $hidden_endpoint |
|
| 1054 | + ); |
|
| 1055 | + } |
|
| 1056 | + return $config_routes; |
|
| 1057 | + } |
|
| 1058 | + |
|
| 1059 | + |
|
| 1060 | + |
|
| 1061 | + /** |
|
| 1062 | + * Gets routes for the config for the specified version |
|
| 1063 | + * |
|
| 1064 | + * @param string $version |
|
| 1065 | + * @param boolean $hidden_endpoint |
|
| 1066 | + * @return array |
|
| 1067 | + */ |
|
| 1068 | + protected function _get_config_route_data_for_version($version, $hidden_endpoint) |
|
| 1069 | + { |
|
| 1070 | + return array( |
|
| 1071 | + 'config' => array( |
|
| 1072 | + array( |
|
| 1073 | + 'callback' => array( |
|
| 1074 | + 'EventEspresso\core\libraries\rest_api\controllers\config\Read', |
|
| 1075 | + 'handleRequest', |
|
| 1076 | + ), |
|
| 1077 | + 'methods' => WP_REST_Server::READABLE, |
|
| 1078 | + 'hidden_endpoint' => $hidden_endpoint, |
|
| 1079 | + 'callback_args' => array($version), |
|
| 1080 | + ), |
|
| 1081 | + ), |
|
| 1082 | + 'site_info' => array( |
|
| 1083 | + array( |
|
| 1084 | + 'callback' => array( |
|
| 1085 | + 'EventEspresso\core\libraries\rest_api\controllers\config\Read', |
|
| 1086 | + 'handleRequestSiteInfo', |
|
| 1087 | + ), |
|
| 1088 | + 'methods' => WP_REST_Server::READABLE, |
|
| 1089 | + 'hidden_endpoint' => $hidden_endpoint, |
|
| 1090 | + 'callback_args' => array($version), |
|
| 1091 | + ), |
|
| 1092 | + ), |
|
| 1093 | + ); |
|
| 1094 | + } |
|
| 1095 | + |
|
| 1096 | + |
|
| 1097 | + |
|
| 1098 | + /** |
|
| 1099 | + * Gets the meta info routes |
|
| 1100 | + * |
|
| 1101 | + * @return array @see _register_model_routes |
|
| 1102 | + * @deprecated since version 4.9.1 |
|
| 1103 | + */ |
|
| 1104 | + protected function _register_meta_routes() |
|
| 1105 | + { |
|
| 1106 | + $meta_routes = array(); |
|
| 1107 | + foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
| 1108 | + $meta_routes[self::ee_api_namespace . $version] = $this->_get_meta_route_data_for_version( |
|
| 1109 | + $version, |
|
| 1110 | + $hidden_endpoint |
|
| 1111 | + ); |
|
| 1112 | + } |
|
| 1113 | + return $meta_routes; |
|
| 1114 | + } |
|
| 1115 | + |
|
| 1116 | + |
|
| 1117 | + |
|
| 1118 | + /** |
|
| 1119 | + * @param string $version |
|
| 1120 | + * @param boolean $hidden_endpoint |
|
| 1121 | + * @return array |
|
| 1122 | + */ |
|
| 1123 | + protected function _get_meta_route_data_for_version($version, $hidden_endpoint = false) |
|
| 1124 | + { |
|
| 1125 | + return array( |
|
| 1126 | + 'resources' => array( |
|
| 1127 | + array( |
|
| 1128 | + 'callback' => array( |
|
| 1129 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Meta', |
|
| 1130 | + 'handleRequestModelsMeta', |
|
| 1131 | + ), |
|
| 1132 | + 'methods' => WP_REST_Server::READABLE, |
|
| 1133 | + 'hidden_endpoint' => $hidden_endpoint, |
|
| 1134 | + 'callback_args' => array($version), |
|
| 1135 | + ), |
|
| 1136 | + ), |
|
| 1137 | + ); |
|
| 1138 | + } |
|
| 1139 | + |
|
| 1140 | + |
|
| 1141 | + |
|
| 1142 | + /** |
|
| 1143 | + * Tries to hide old 4.6 endpoints from the |
|
| 1144 | + * |
|
| 1145 | + * @param array $route_data |
|
| 1146 | + * @return array |
|
| 1147 | + * @throws \EE_Error |
|
| 1148 | + */ |
|
| 1149 | + public static function hide_old_endpoints($route_data) |
|
| 1150 | + { |
|
| 1151 | + //allow API clients to override which endpoints get hidden, in case |
|
| 1152 | + //they want to discover particular endpoints |
|
| 1153 | + //also, we don't have access to the request so we have to just grab it from the superglobal |
|
| 1154 | + $force_show_ee_namespace = ltrim( |
|
| 1155 | + EEH_Array::is_set($_REQUEST, 'force_show_ee_namespace', ''), |
|
| 1156 | + '/' |
|
| 1157 | + ); |
|
| 1158 | + foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls) { |
|
| 1159 | + foreach ($relative_urls as $resource_name => $endpoints) { |
|
| 1160 | + foreach ($endpoints as $key => $endpoint) { |
|
| 1161 | + //skip schema and other route options |
|
| 1162 | + if (! is_numeric($key)) { |
|
| 1163 | + continue; |
|
| 1164 | + } |
|
| 1165 | + //by default, hide "hidden_endpoint"s, unless the request indicates |
|
| 1166 | + //to $force_show_ee_namespace, in which case only show that one |
|
| 1167 | + //namespace's endpoints (and hide all others) |
|
| 1168 | + if ( |
|
| 1169 | + ($force_show_ee_namespace !== '' && $force_show_ee_namespace !== $namespace) |
|
| 1170 | + || ($endpoint['hidden_endpoint'] && $force_show_ee_namespace === '') |
|
| 1171 | + ) { |
|
| 1172 | + $full_route = '/' . ltrim($namespace, '/'); |
|
| 1173 | + $full_route .= '/' . ltrim($resource_name, '/'); |
|
| 1174 | + unset($route_data[$full_route]); |
|
| 1175 | + } |
|
| 1176 | + } |
|
| 1177 | + } |
|
| 1178 | + } |
|
| 1179 | + return $route_data; |
|
| 1180 | + } |
|
| 1181 | + |
|
| 1182 | + |
|
| 1183 | + |
|
| 1184 | + /** |
|
| 1185 | + * Returns an array describing which versions of core support serving requests for. |
|
| 1186 | + * Keys are core versions' major and minor version, and values are the |
|
| 1187 | + * LOWEST requested version they can serve. Eg, 4.7 can serve requests for 4.6-like |
|
| 1188 | + * data by just removing a few models and fields from the responses. However, 4.15 might remove |
|
| 1189 | + * the answers table entirely, in which case it would be very difficult for |
|
| 1190 | + * it to serve 4.6-style responses. |
|
| 1191 | + * Versions of core that are missing from this array are unknowns. |
|
| 1192 | + * previous ver |
|
| 1193 | + * |
|
| 1194 | + * @return array |
|
| 1195 | + */ |
|
| 1196 | + public static function version_compatibilities() |
|
| 1197 | + { |
|
| 1198 | + return apply_filters( |
|
| 1199 | + 'FHEE__EED_Core_REST_API__version_compatibilities', |
|
| 1200 | + array( |
|
| 1201 | + '4.8.29' => '4.8.29', |
|
| 1202 | + '4.8.33' => '4.8.29', |
|
| 1203 | + '4.8.34' => '4.8.29', |
|
| 1204 | + '4.8.36' => '4.8.29', |
|
| 1205 | + ) |
|
| 1206 | + ); |
|
| 1207 | + } |
|
| 1208 | + |
|
| 1209 | + |
|
| 1210 | + |
|
| 1211 | + /** |
|
| 1212 | + * Gets the latest API version served. Eg if there |
|
| 1213 | + * are two versions served of the API, 4.8.29 and 4.8.32, and |
|
| 1214 | + * we are on core version 4.8.34, it will return the string "4.8.32" |
|
| 1215 | + * |
|
| 1216 | + * @return string |
|
| 1217 | + */ |
|
| 1218 | + public static function latest_rest_api_version() |
|
| 1219 | + { |
|
| 1220 | + $versions_served = \EED_Core_Rest_Api::versions_served(); |
|
| 1221 | + $versions_served_keys = array_keys($versions_served); |
|
| 1222 | + return end($versions_served_keys); |
|
| 1223 | + } |
|
| 1224 | + |
|
| 1225 | + |
|
| 1226 | + |
|
| 1227 | + /** |
|
| 1228 | + * Using EED_Core_Rest_Api::version_compatibilities(), determines what version of |
|
| 1229 | + * EE the API can serve requests for. Eg, if we are on 4.15 of core, and |
|
| 1230 | + * we can serve requests from 4.12 or later, this will return array( '4.12', '4.13', '4.14', '4.15' ). |
|
| 1231 | + * We also indicate whether or not this version should be put in the index or not |
|
| 1232 | + * |
|
| 1233 | + * @return array keys are API version numbers (just major and minor numbers), and values |
|
| 1234 | + * are whether or not they should be hidden |
|
| 1235 | + */ |
|
| 1236 | + public static function versions_served() |
|
| 1237 | + { |
|
| 1238 | + $versions_served = array(); |
|
| 1239 | + $possibly_served_versions = EED_Core_Rest_Api::version_compatibilities(); |
|
| 1240 | + $lowest_compatible_version = end($possibly_served_versions); |
|
| 1241 | + reset($possibly_served_versions); |
|
| 1242 | + $versions_served_historically = array_keys($possibly_served_versions); |
|
| 1243 | + $latest_version = end($versions_served_historically); |
|
| 1244 | + reset($versions_served_historically); |
|
| 1245 | + //for each version of core we have ever served: |
|
| 1246 | + foreach ($versions_served_historically as $key_versioned_endpoint) { |
|
| 1247 | + //if it's not above the current core version, and it's compatible with the current version of core |
|
| 1248 | + if ($key_versioned_endpoint === $latest_version) { |
|
| 1249 | + //don't hide the latest version in the index |
|
| 1250 | + $versions_served[$key_versioned_endpoint] = false; |
|
| 1251 | + } elseif ( |
|
| 1252 | + $key_versioned_endpoint >= $lowest_compatible_version |
|
| 1253 | + && $key_versioned_endpoint < EED_Core_Rest_Api::core_version() |
|
| 1254 | + ) { |
|
| 1255 | + //include, but hide, previous versions which are still supported |
|
| 1256 | + $versions_served[$key_versioned_endpoint] = true; |
|
| 1257 | + } elseif (apply_filters( |
|
| 1258 | + 'FHEE__EED_Core_Rest_Api__versions_served__include_incompatible_versions', |
|
| 1259 | + false, |
|
| 1260 | + $possibly_served_versions |
|
| 1261 | + )) { |
|
| 1262 | + //if a version is no longer supported, don't include it in index or list of versions served |
|
| 1263 | + $versions_served[$key_versioned_endpoint] = true; |
|
| 1264 | + } |
|
| 1265 | + } |
|
| 1266 | + return $versions_served; |
|
| 1267 | + } |
|
| 1268 | + |
|
| 1269 | + |
|
| 1270 | + |
|
| 1271 | + /** |
|
| 1272 | + * Gets the major and minor version of EE core's version string |
|
| 1273 | + * |
|
| 1274 | + * @return string |
|
| 1275 | + */ |
|
| 1276 | + public static function core_version() |
|
| 1277 | + { |
|
| 1278 | + return apply_filters( |
|
| 1279 | + 'FHEE__EED_Core_REST_API__core_version', |
|
| 1280 | + implode( |
|
| 1281 | + '.', |
|
| 1282 | + array_slice( |
|
| 1283 | + explode( |
|
| 1284 | + '.', |
|
| 1285 | + espresso_version() |
|
| 1286 | + ), |
|
| 1287 | + 0, |
|
| 1288 | + 3 |
|
| 1289 | + ) |
|
| 1290 | + ) |
|
| 1291 | + ); |
|
| 1292 | + } |
|
| 1293 | + |
|
| 1294 | + |
|
| 1295 | + |
|
| 1296 | + /** |
|
| 1297 | + * Gets the default limit that should be used when querying for resources |
|
| 1298 | + * |
|
| 1299 | + * @return int |
|
| 1300 | + */ |
|
| 1301 | + public static function get_default_query_limit() |
|
| 1302 | + { |
|
| 1303 | + //we actually don't use a const because we want folks to always use |
|
| 1304 | + //this method, not the const directly |
|
| 1305 | + return apply_filters( |
|
| 1306 | + 'FHEE__EED_Core_Rest_Api__get_default_query_limit', |
|
| 1307 | + 50 |
|
| 1308 | + ); |
|
| 1309 | + } |
|
| 1310 | + |
|
| 1311 | + |
|
| 1312 | + |
|
| 1313 | + /** |
|
| 1314 | + * run - initial module setup |
|
| 1315 | + * |
|
| 1316 | + * @access public |
|
| 1317 | + * @param WP $WP |
|
| 1318 | + * @return void |
|
| 1319 | + */ |
|
| 1320 | + public function run($WP) |
|
| 1321 | + { |
|
| 1322 | + } |
|
| 1323 | 1323 | } |
| 1324 | 1324 | |
| 1325 | 1325 | // End of file EED_Core_Rest_Api.module.php |
@@ -16,328 +16,328 @@ |
||
| 16 | 16 | class EE_Request implements InterminableInterface |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * $_GET parameters |
|
| 21 | - * |
|
| 22 | - * @var array $_get |
|
| 23 | - */ |
|
| 24 | - private $_get; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * $_POST parameters |
|
| 28 | - * |
|
| 29 | - * @var array $_post |
|
| 30 | - */ |
|
| 31 | - private $_post; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * $_COOKIE parameters |
|
| 35 | - * |
|
| 36 | - * @var array $_cookie |
|
| 37 | - */ |
|
| 38 | - private $_cookie; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * $_REQUEST parameters |
|
| 42 | - * |
|
| 43 | - * @var array $_params |
|
| 44 | - */ |
|
| 45 | - private $_params; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * whether current request is for the admin but NOT via AJAX |
|
| 49 | - * |
|
| 50 | - * @var boolean $admin |
|
| 51 | - */ |
|
| 52 | - public $admin = false; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * whether current request is via AJAX |
|
| 56 | - * |
|
| 57 | - * @var boolean $ajax |
|
| 58 | - */ |
|
| 59 | - public $ajax = false; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * whether current request is via AJAX from the frontend of the site |
|
| 63 | - * |
|
| 64 | - * @var boolean $front_ajax |
|
| 65 | - */ |
|
| 66 | - public $front_ajax = false; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * IP address for request |
|
| 70 | - * |
|
| 71 | - * @var string $_ip_address |
|
| 72 | - */ |
|
| 73 | - private $_ip_address; |
|
| 74 | - |
|
| 75 | - |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * class constructor |
|
| 79 | - * |
|
| 80 | - * @access public |
|
| 81 | - * @param array $get |
|
| 82 | - * @param array $post |
|
| 83 | - * @param array $cookie |
|
| 84 | - */ |
|
| 85 | - public function __construct(array $get, array $post, array $cookie) |
|
| 86 | - { |
|
| 87 | - // grab request vars |
|
| 88 | - $this->_get = $get; |
|
| 89 | - $this->_post = $post; |
|
| 90 | - $this->_cookie = $cookie; |
|
| 91 | - $this->_params = array_merge($this->_get, $this->_post); |
|
| 92 | - // AJAX ??? |
|
| 93 | - $this->ajax = defined('DOING_AJAX') && DOING_AJAX; |
|
| 94 | - $this->front_ajax = $this->ajax |
|
| 95 | - && $this->is_set('ee_front_ajax') |
|
| 96 | - && filter_var($this->get('ee_front_ajax'), FILTER_VALIDATE_BOOLEAN); |
|
| 97 | - $this->admin = is_admin() && ! $this->ajax; |
|
| 98 | - // grab user IP |
|
| 99 | - $this->_ip_address = $this->_visitor_ip(); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * @return array |
|
| 106 | - */ |
|
| 107 | - public function get_params() |
|
| 108 | - { |
|
| 109 | - return $this->_get; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * @return array |
|
| 116 | - */ |
|
| 117 | - public function post_params() |
|
| 118 | - { |
|
| 119 | - return $this->_post; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * @return array |
|
| 126 | - */ |
|
| 127 | - public function cookie_params() |
|
| 128 | - { |
|
| 129 | - return $this->_cookie; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * returns contents of $_REQUEST |
|
| 136 | - * |
|
| 137 | - * @return array |
|
| 138 | - */ |
|
| 139 | - public function params() |
|
| 140 | - { |
|
| 141 | - return $this->_params; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * @param $key |
|
| 148 | - * @param $value |
|
| 149 | - * @param bool $override_ee |
|
| 150 | - * @return void |
|
| 151 | - */ |
|
| 152 | - public function set($key, $value, $override_ee = false) |
|
| 153 | - { |
|
| 154 | - // don't allow "ee" to be overwritten unless explicitly instructed to do so |
|
| 155 | - if ( |
|
| 156 | - $key !== 'ee' |
|
| 157 | - || ($key === 'ee' && empty($this->_params['ee'])) |
|
| 158 | - || ($key === 'ee' && ! empty($this->_params['ee']) && $override_ee) |
|
| 159 | - ) { |
|
| 160 | - $this->_params[$key] = $value; |
|
| 161 | - } |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * returns the value for a request param if the given key exists |
|
| 168 | - * |
|
| 169 | - * @param $key |
|
| 170 | - * @param null $default |
|
| 171 | - * @return mixed |
|
| 172 | - */ |
|
| 173 | - public function get($key, $default = null) |
|
| 174 | - { |
|
| 175 | - return $this->request_parameter_drill_down($key, $default, 'get'); |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * check if param exists |
|
| 182 | - * |
|
| 183 | - * @param $key |
|
| 184 | - * @return bool |
|
| 185 | - */ |
|
| 186 | - public function is_set($key) |
|
| 187 | - { |
|
| 188 | - return $this->request_parameter_drill_down($key); |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * the supplied key can be a simple string to represent a "top-level" request parameter |
|
| 195 | - * or represent a key for a request parameter that is nested deeper within the request parameter array, |
|
| 196 | - * by using square brackets to surround keys for deeper array elements. |
|
| 197 | - * For example : |
|
| 198 | - * if the supplied $key was: "first[second][third]" |
|
| 199 | - * then this will attempt to drill down into the request parameter array to find a value. |
|
| 200 | - * Given the following request parameters: |
|
| 201 | - * array( |
|
| 202 | - * 'first' => array( |
|
| 203 | - * 'second' => array( |
|
| 204 | - * 'third' => 'has a value' |
|
| 205 | - * ) |
|
| 206 | - * ) |
|
| 207 | - * ) |
|
| 208 | - * would return true |
|
| 209 | - * |
|
| 210 | - * @param string $is_set_or_get |
|
| 211 | - * @param $key |
|
| 212 | - * @param null $default |
|
| 213 | - * @param array $request_params |
|
| 214 | - * @return bool|mixed|null |
|
| 215 | - */ |
|
| 216 | - private function request_parameter_drill_down( |
|
| 217 | - $key, |
|
| 218 | - $default = null, |
|
| 219 | - $is_set_or_get = 'is_set', |
|
| 220 | - array $request_params = array() |
|
| 221 | - ) { |
|
| 222 | - $request_params = ! empty($request_params) |
|
| 223 | - ? $request_params |
|
| 224 | - : $this->_params; |
|
| 225 | - // does incoming key represent an array like 'first[second][third]' ? |
|
| 226 | - if (strpos($key, '[') !== false) { |
|
| 227 | - // turn it into an actual array |
|
| 228 | - $key = str_replace(']', '', $key); |
|
| 229 | - $keys = explode('[', $key); |
|
| 230 | - $key = array_shift($keys); |
|
| 231 | - // check if top level key exists |
|
| 232 | - if (isset($request_params[$key])) { |
|
| 233 | - // build a new key to pass along like: 'second[third]' |
|
| 234 | - // or just 'second' depending on depth of keys |
|
| 235 | - $key_string = array_shift($keys); |
|
| 236 | - if (! empty($keys)) { |
|
| 237 | - $key_string .= '[' . implode('][', $keys) . ']'; |
|
| 238 | - } |
|
| 239 | - return $this->request_parameter_drill_down( |
|
| 240 | - $key_string, |
|
| 241 | - $default, |
|
| 242 | - $is_set_or_get, |
|
| 243 | - $request_params[$key] |
|
| 244 | - ); |
|
| 245 | - } |
|
| 246 | - } |
|
| 247 | - if ($is_set_or_get === 'is_set') { |
|
| 248 | - return isset($request_params[$key]); |
|
| 249 | - } |
|
| 250 | - return isset($request_params[$key]) |
|
| 251 | - ? $request_params[$key] |
|
| 252 | - : $default; |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - |
|
| 256 | - |
|
| 257 | - /** |
|
| 258 | - * remove param |
|
| 259 | - * |
|
| 260 | - * @param $key |
|
| 261 | - * @param bool $unset_from_global_too |
|
| 262 | - */ |
|
| 263 | - public function un_set($key, $unset_from_global_too = false) |
|
| 264 | - { |
|
| 265 | - unset($this->_params[$key]); |
|
| 266 | - if ($unset_from_global_too) { |
|
| 267 | - unset($_REQUEST[$key]); |
|
| 268 | - } |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - |
|
| 272 | - |
|
| 273 | - /** |
|
| 274 | - * @return string |
|
| 275 | - */ |
|
| 276 | - public function ip_address() |
|
| 277 | - { |
|
| 278 | - return $this->_ip_address; |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - |
|
| 282 | - /** |
|
| 283 | - * @return bool |
|
| 284 | - */ |
|
| 285 | - public function isAdmin() |
|
| 286 | - { |
|
| 287 | - return $this->admin; |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - |
|
| 291 | - /** |
|
| 292 | - * @return mixed |
|
| 293 | - */ |
|
| 294 | - public function isAjax() |
|
| 295 | - { |
|
| 296 | - return $this->ajax; |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - |
|
| 300 | - /** |
|
| 301 | - * @return mixed |
|
| 302 | - */ |
|
| 303 | - public function isFrontAjax() |
|
| 304 | - { |
|
| 305 | - return $this->front_ajax; |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - |
|
| 309 | - |
|
| 310 | - /** |
|
| 311 | - * _visitor_ip |
|
| 312 | - * attempt to get IP address of current visitor from server |
|
| 313 | - * plz see: http://stackoverflow.com/a/2031935/1475279 |
|
| 314 | - * |
|
| 315 | - * @access public |
|
| 316 | - * @return string |
|
| 317 | - */ |
|
| 318 | - private function _visitor_ip() |
|
| 319 | - { |
|
| 320 | - $visitor_ip = '0.0.0.0'; |
|
| 321 | - $server_keys = array( |
|
| 322 | - 'HTTP_CLIENT_IP', |
|
| 323 | - 'HTTP_X_FORWARDED_FOR', |
|
| 324 | - 'HTTP_X_FORWARDED', |
|
| 325 | - 'HTTP_X_CLUSTER_CLIENT_IP', |
|
| 326 | - 'HTTP_FORWARDED_FOR', |
|
| 327 | - 'HTTP_FORWARDED', |
|
| 328 | - 'REMOTE_ADDR', |
|
| 329 | - ); |
|
| 330 | - foreach ($server_keys as $key) { |
|
| 331 | - if (isset($_SERVER[$key])) { |
|
| 332 | - foreach (array_map('trim', explode(',', $_SERVER[$key])) as $ip) { |
|
| 333 | - if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) { |
|
| 334 | - $visitor_ip = $ip; |
|
| 335 | - } |
|
| 336 | - } |
|
| 337 | - } |
|
| 338 | - } |
|
| 339 | - return $visitor_ip; |
|
| 340 | - } |
|
| 19 | + /** |
|
| 20 | + * $_GET parameters |
|
| 21 | + * |
|
| 22 | + * @var array $_get |
|
| 23 | + */ |
|
| 24 | + private $_get; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * $_POST parameters |
|
| 28 | + * |
|
| 29 | + * @var array $_post |
|
| 30 | + */ |
|
| 31 | + private $_post; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * $_COOKIE parameters |
|
| 35 | + * |
|
| 36 | + * @var array $_cookie |
|
| 37 | + */ |
|
| 38 | + private $_cookie; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * $_REQUEST parameters |
|
| 42 | + * |
|
| 43 | + * @var array $_params |
|
| 44 | + */ |
|
| 45 | + private $_params; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * whether current request is for the admin but NOT via AJAX |
|
| 49 | + * |
|
| 50 | + * @var boolean $admin |
|
| 51 | + */ |
|
| 52 | + public $admin = false; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * whether current request is via AJAX |
|
| 56 | + * |
|
| 57 | + * @var boolean $ajax |
|
| 58 | + */ |
|
| 59 | + public $ajax = false; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * whether current request is via AJAX from the frontend of the site |
|
| 63 | + * |
|
| 64 | + * @var boolean $front_ajax |
|
| 65 | + */ |
|
| 66 | + public $front_ajax = false; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * IP address for request |
|
| 70 | + * |
|
| 71 | + * @var string $_ip_address |
|
| 72 | + */ |
|
| 73 | + private $_ip_address; |
|
| 74 | + |
|
| 75 | + |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * class constructor |
|
| 79 | + * |
|
| 80 | + * @access public |
|
| 81 | + * @param array $get |
|
| 82 | + * @param array $post |
|
| 83 | + * @param array $cookie |
|
| 84 | + */ |
|
| 85 | + public function __construct(array $get, array $post, array $cookie) |
|
| 86 | + { |
|
| 87 | + // grab request vars |
|
| 88 | + $this->_get = $get; |
|
| 89 | + $this->_post = $post; |
|
| 90 | + $this->_cookie = $cookie; |
|
| 91 | + $this->_params = array_merge($this->_get, $this->_post); |
|
| 92 | + // AJAX ??? |
|
| 93 | + $this->ajax = defined('DOING_AJAX') && DOING_AJAX; |
|
| 94 | + $this->front_ajax = $this->ajax |
|
| 95 | + && $this->is_set('ee_front_ajax') |
|
| 96 | + && filter_var($this->get('ee_front_ajax'), FILTER_VALIDATE_BOOLEAN); |
|
| 97 | + $this->admin = is_admin() && ! $this->ajax; |
|
| 98 | + // grab user IP |
|
| 99 | + $this->_ip_address = $this->_visitor_ip(); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * @return array |
|
| 106 | + */ |
|
| 107 | + public function get_params() |
|
| 108 | + { |
|
| 109 | + return $this->_get; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * @return array |
|
| 116 | + */ |
|
| 117 | + public function post_params() |
|
| 118 | + { |
|
| 119 | + return $this->_post; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * @return array |
|
| 126 | + */ |
|
| 127 | + public function cookie_params() |
|
| 128 | + { |
|
| 129 | + return $this->_cookie; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * returns contents of $_REQUEST |
|
| 136 | + * |
|
| 137 | + * @return array |
|
| 138 | + */ |
|
| 139 | + public function params() |
|
| 140 | + { |
|
| 141 | + return $this->_params; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * @param $key |
|
| 148 | + * @param $value |
|
| 149 | + * @param bool $override_ee |
|
| 150 | + * @return void |
|
| 151 | + */ |
|
| 152 | + public function set($key, $value, $override_ee = false) |
|
| 153 | + { |
|
| 154 | + // don't allow "ee" to be overwritten unless explicitly instructed to do so |
|
| 155 | + if ( |
|
| 156 | + $key !== 'ee' |
|
| 157 | + || ($key === 'ee' && empty($this->_params['ee'])) |
|
| 158 | + || ($key === 'ee' && ! empty($this->_params['ee']) && $override_ee) |
|
| 159 | + ) { |
|
| 160 | + $this->_params[$key] = $value; |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * returns the value for a request param if the given key exists |
|
| 168 | + * |
|
| 169 | + * @param $key |
|
| 170 | + * @param null $default |
|
| 171 | + * @return mixed |
|
| 172 | + */ |
|
| 173 | + public function get($key, $default = null) |
|
| 174 | + { |
|
| 175 | + return $this->request_parameter_drill_down($key, $default, 'get'); |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * check if param exists |
|
| 182 | + * |
|
| 183 | + * @param $key |
|
| 184 | + * @return bool |
|
| 185 | + */ |
|
| 186 | + public function is_set($key) |
|
| 187 | + { |
|
| 188 | + return $this->request_parameter_drill_down($key); |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * the supplied key can be a simple string to represent a "top-level" request parameter |
|
| 195 | + * or represent a key for a request parameter that is nested deeper within the request parameter array, |
|
| 196 | + * by using square brackets to surround keys for deeper array elements. |
|
| 197 | + * For example : |
|
| 198 | + * if the supplied $key was: "first[second][third]" |
|
| 199 | + * then this will attempt to drill down into the request parameter array to find a value. |
|
| 200 | + * Given the following request parameters: |
|
| 201 | + * array( |
|
| 202 | + * 'first' => array( |
|
| 203 | + * 'second' => array( |
|
| 204 | + * 'third' => 'has a value' |
|
| 205 | + * ) |
|
| 206 | + * ) |
|
| 207 | + * ) |
|
| 208 | + * would return true |
|
| 209 | + * |
|
| 210 | + * @param string $is_set_or_get |
|
| 211 | + * @param $key |
|
| 212 | + * @param null $default |
|
| 213 | + * @param array $request_params |
|
| 214 | + * @return bool|mixed|null |
|
| 215 | + */ |
|
| 216 | + private function request_parameter_drill_down( |
|
| 217 | + $key, |
|
| 218 | + $default = null, |
|
| 219 | + $is_set_or_get = 'is_set', |
|
| 220 | + array $request_params = array() |
|
| 221 | + ) { |
|
| 222 | + $request_params = ! empty($request_params) |
|
| 223 | + ? $request_params |
|
| 224 | + : $this->_params; |
|
| 225 | + // does incoming key represent an array like 'first[second][third]' ? |
|
| 226 | + if (strpos($key, '[') !== false) { |
|
| 227 | + // turn it into an actual array |
|
| 228 | + $key = str_replace(']', '', $key); |
|
| 229 | + $keys = explode('[', $key); |
|
| 230 | + $key = array_shift($keys); |
|
| 231 | + // check if top level key exists |
|
| 232 | + if (isset($request_params[$key])) { |
|
| 233 | + // build a new key to pass along like: 'second[third]' |
|
| 234 | + // or just 'second' depending on depth of keys |
|
| 235 | + $key_string = array_shift($keys); |
|
| 236 | + if (! empty($keys)) { |
|
| 237 | + $key_string .= '[' . implode('][', $keys) . ']'; |
|
| 238 | + } |
|
| 239 | + return $this->request_parameter_drill_down( |
|
| 240 | + $key_string, |
|
| 241 | + $default, |
|
| 242 | + $is_set_or_get, |
|
| 243 | + $request_params[$key] |
|
| 244 | + ); |
|
| 245 | + } |
|
| 246 | + } |
|
| 247 | + if ($is_set_or_get === 'is_set') { |
|
| 248 | + return isset($request_params[$key]); |
|
| 249 | + } |
|
| 250 | + return isset($request_params[$key]) |
|
| 251 | + ? $request_params[$key] |
|
| 252 | + : $default; |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + |
|
| 256 | + |
|
| 257 | + /** |
|
| 258 | + * remove param |
|
| 259 | + * |
|
| 260 | + * @param $key |
|
| 261 | + * @param bool $unset_from_global_too |
|
| 262 | + */ |
|
| 263 | + public function un_set($key, $unset_from_global_too = false) |
|
| 264 | + { |
|
| 265 | + unset($this->_params[$key]); |
|
| 266 | + if ($unset_from_global_too) { |
|
| 267 | + unset($_REQUEST[$key]); |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + |
|
| 272 | + |
|
| 273 | + /** |
|
| 274 | + * @return string |
|
| 275 | + */ |
|
| 276 | + public function ip_address() |
|
| 277 | + { |
|
| 278 | + return $this->_ip_address; |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + |
|
| 282 | + /** |
|
| 283 | + * @return bool |
|
| 284 | + */ |
|
| 285 | + public function isAdmin() |
|
| 286 | + { |
|
| 287 | + return $this->admin; |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + |
|
| 291 | + /** |
|
| 292 | + * @return mixed |
|
| 293 | + */ |
|
| 294 | + public function isAjax() |
|
| 295 | + { |
|
| 296 | + return $this->ajax; |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + |
|
| 300 | + /** |
|
| 301 | + * @return mixed |
|
| 302 | + */ |
|
| 303 | + public function isFrontAjax() |
|
| 304 | + { |
|
| 305 | + return $this->front_ajax; |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + |
|
| 309 | + |
|
| 310 | + /** |
|
| 311 | + * _visitor_ip |
|
| 312 | + * attempt to get IP address of current visitor from server |
|
| 313 | + * plz see: http://stackoverflow.com/a/2031935/1475279 |
|
| 314 | + * |
|
| 315 | + * @access public |
|
| 316 | + * @return string |
|
| 317 | + */ |
|
| 318 | + private function _visitor_ip() |
|
| 319 | + { |
|
| 320 | + $visitor_ip = '0.0.0.0'; |
|
| 321 | + $server_keys = array( |
|
| 322 | + 'HTTP_CLIENT_IP', |
|
| 323 | + 'HTTP_X_FORWARDED_FOR', |
|
| 324 | + 'HTTP_X_FORWARDED', |
|
| 325 | + 'HTTP_X_CLUSTER_CLIENT_IP', |
|
| 326 | + 'HTTP_FORWARDED_FOR', |
|
| 327 | + 'HTTP_FORWARDED', |
|
| 328 | + 'REMOTE_ADDR', |
|
| 329 | + ); |
|
| 330 | + foreach ($server_keys as $key) { |
|
| 331 | + if (isset($_SERVER[$key])) { |
|
| 332 | + foreach (array_map('trim', explode(',', $_SERVER[$key])) as $ip) { |
|
| 333 | + if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) { |
|
| 334 | + $visitor_ip = $ip; |
|
| 335 | + } |
|
| 336 | + } |
|
| 337 | + } |
|
| 338 | + } |
|
| 339 | + return $visitor_ip; |
|
| 340 | + } |
|
| 341 | 341 | |
| 342 | 342 | |
| 343 | 343 | |
@@ -233,8 +233,8 @@ |
||
| 233 | 233 | // build a new key to pass along like: 'second[third]' |
| 234 | 234 | // or just 'second' depending on depth of keys |
| 235 | 235 | $key_string = array_shift($keys); |
| 236 | - if (! empty($keys)) { |
|
| 237 | - $key_string .= '[' . implode('][', $keys) . ']'; |
|
| 236 | + if ( ! empty($keys)) { |
|
| 237 | + $key_string .= '['.implode('][', $keys).']'; |
|
| 238 | 238 | } |
| 239 | 239 | return $this->request_parameter_drill_down( |
| 240 | 240 | $key_string, |
@@ -274,7 +274,7 @@ discard block |
||
| 274 | 274 | |
| 275 | 275 | /** |
| 276 | 276 | * @access public |
| 277 | - * @return string |
|
| 277 | + * @return boolean |
|
| 278 | 278 | */ |
| 279 | 279 | public static function is_iframe() |
| 280 | 280 | { |
@@ -892,7 +892,7 @@ discard block |
||
| 892 | 892 | * display_description |
| 893 | 893 | * |
| 894 | 894 | * @access public |
| 895 | - * @param $value |
|
| 895 | + * @param integer $value |
|
| 896 | 896 | * @return bool |
| 897 | 897 | */ |
| 898 | 898 | public static function display_description($value) |
@@ -17,1110 +17,1110 @@ discard block |
||
| 17 | 17 | class EED_Events_Archive extends EED_Module |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - const EVENT_DETAILS_PRIORITY = 100; |
|
| 21 | - |
|
| 22 | - const EVENT_DATETIMES_PRIORITY = 110; |
|
| 23 | - |
|
| 24 | - const EVENT_TICKETS_PRIORITY = 120; |
|
| 25 | - |
|
| 26 | - const EVENT_VENUES_PRIORITY = 130; |
|
| 27 | - |
|
| 28 | - |
|
| 29 | - public static $espresso_event_list_ID = 0; |
|
| 30 | - |
|
| 31 | - public static $espresso_grid_event_lists = array(); |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @type bool $using_get_the_excerpt |
|
| 35 | - */ |
|
| 36 | - protected static $using_get_the_excerpt = false; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Used to flag when the event list is being called from an external iframe. |
|
| 40 | - * |
|
| 41 | - * @var bool $iframe |
|
| 42 | - */ |
|
| 43 | - protected static $iframe = false; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @var \EventEspresso\core\libraries\iframe_display\EventListIframeEmbedButton $_iframe_embed_button |
|
| 47 | - */ |
|
| 48 | - private static $_iframe_embed_button; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @type EE_Template_Part_Manager $template_parts |
|
| 52 | - */ |
|
| 53 | - protected $template_parts; |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @return EED_Events_Archive |
|
| 59 | - */ |
|
| 60 | - public static function instance() |
|
| 61 | - { |
|
| 62 | - return parent::get_instance(__CLASS__); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
| 69 | - * |
|
| 70 | - * @access public |
|
| 71 | - * @return void |
|
| 72 | - */ |
|
| 73 | - public static function set_hooks() |
|
| 74 | - { |
|
| 75 | - $custom_post_types = EE_Register_CPTs::get_CPTs(); |
|
| 76 | - EE_Config::register_route( |
|
| 77 | - $custom_post_types['espresso_events']['plural_slug'], |
|
| 78 | - 'Events_Archive', |
|
| 79 | - 'run' |
|
| 80 | - ); |
|
| 81 | - EE_Config::register_route( |
|
| 82 | - 'event_list', |
|
| 83 | - 'Events_Archive', |
|
| 84 | - 'event_list' |
|
| 85 | - ); |
|
| 86 | - EE_Config::register_route( |
|
| 87 | - 'iframe', |
|
| 88 | - 'Events_Archive', |
|
| 89 | - 'event_list_iframe', |
|
| 90 | - 'event_list' |
|
| 91 | - ); |
|
| 92 | - add_action('wp_loaded', array('EED_Events_Archive', 'set_definitions'), 2); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 99 | - * |
|
| 100 | - * @access public |
|
| 101 | - * @return void |
|
| 102 | - */ |
|
| 103 | - public static function set_hooks_admin() |
|
| 104 | - { |
|
| 105 | - add_action('wp_loaded', array('EED_Events_Archive', 'set_definitions'), 2); |
|
| 106 | - // hook into the end of the \EE_Admin_Page::_load_page_dependencies() |
|
| 107 | - // to load assets for "espresso_events" page on the "default" route (action) |
|
| 108 | - add_action( |
|
| 109 | - 'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_events__default', |
|
| 110 | - array('EED_Events_Archive', 'event_list_iframe_embed_button'), |
|
| 111 | - 10 |
|
| 112 | - ); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * set_definitions |
|
| 119 | - * |
|
| 120 | - * @access public |
|
| 121 | - * @return void |
|
| 122 | - */ |
|
| 123 | - public static function set_definitions() |
|
| 124 | - { |
|
| 125 | - define('EVENTS_ARCHIVE_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
| 126 | - define('EVENTS_ARCHIVE_TEMPLATES_PATH', str_replace('\\', DS, plugin_dir_path(__FILE__)) . 'templates' . DS); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * set up EE_Events_Archive_Config |
|
| 133 | - */ |
|
| 134 | - protected function set_config() |
|
| 135 | - { |
|
| 136 | - $this->set_config_section('template_settings'); |
|
| 137 | - $this->set_config_class('EE_Events_Archive_Config'); |
|
| 138 | - $this->set_config_name('EED_Events_Archive'); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * @return EventListIframeEmbedButton |
|
| 145 | - */ |
|
| 146 | - public static function get_iframe_embed_button() |
|
| 147 | - { |
|
| 148 | - if (! self::$_iframe_embed_button instanceof EventListIframeEmbedButton) { |
|
| 149 | - self::$_iframe_embed_button = new EventListIframeEmbedButton(); |
|
| 150 | - } |
|
| 151 | - return self::$_iframe_embed_button; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * event_list_iframe_embed_button |
|
| 158 | - * |
|
| 159 | - * @return void |
|
| 160 | - * @throws \EE_Error |
|
| 161 | - */ |
|
| 162 | - public static function event_list_iframe_embed_button() |
|
| 163 | - { |
|
| 164 | - $iframe_embed_button = \EED_Events_Archive::get_iframe_embed_button(); |
|
| 165 | - $iframe_embed_button->addEmbedButton(); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * initialize_template_parts |
|
| 172 | - * |
|
| 173 | - * @access public |
|
| 174 | - * @param \EE_Events_Archive_Config $config |
|
| 175 | - * @return \EE_Template_Part_Manager |
|
| 176 | - */ |
|
| 177 | - public function initialize_template_parts(EE_Events_Archive_Config $config = null) |
|
| 178 | - { |
|
| 179 | - $config = $config instanceof EE_Events_Archive_Config ? $config : $this->config(); |
|
| 180 | - EEH_Autoloader::instance()->register_template_part_autoloaders(); |
|
| 181 | - $template_parts = new EE_Template_Part_Manager(); |
|
| 182 | - $template_parts->add_template_part( |
|
| 183 | - 'tickets', |
|
| 184 | - __('Ticket Selector', 'event_espresso'), |
|
| 185 | - 'content-espresso_events-tickets.php', |
|
| 186 | - $config->display_order_tickets |
|
| 187 | - ); |
|
| 188 | - $template_parts->add_template_part( |
|
| 189 | - 'datetimes', |
|
| 190 | - __('Dates and Times', 'event_espresso'), |
|
| 191 | - 'content-espresso_events-datetimes.php', |
|
| 192 | - $config->display_order_datetimes |
|
| 193 | - ); |
|
| 194 | - $template_parts->add_template_part( |
|
| 195 | - 'event', |
|
| 196 | - __('Event Description', 'event_espresso'), |
|
| 197 | - 'content-espresso_events-details.php', |
|
| 198 | - $config->display_order_event |
|
| 199 | - ); |
|
| 200 | - $template_parts->add_template_part( |
|
| 201 | - 'venue', |
|
| 202 | - __('Venue Information', 'event_espresso'), |
|
| 203 | - 'content-espresso_events-venues.php', |
|
| 204 | - $config->display_order_venue |
|
| 205 | - ); |
|
| 206 | - do_action('AHEE__EED_Event_Archive__initialize_template_parts', $template_parts); |
|
| 207 | - return $template_parts; |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * run - initial module setup - this gets called by the EE_Front_Controller if the module route is found in the incoming request |
|
| 214 | - * |
|
| 215 | - * @access public |
|
| 216 | - * @param WP $WP |
|
| 217 | - * @return void |
|
| 218 | - */ |
|
| 219 | - public function run($WP) |
|
| 220 | - { |
|
| 221 | - do_action('AHEE__EED_Events_Archive__before_run'); |
|
| 222 | - // ensure valid EE_Events_Archive_Config() object exists |
|
| 223 | - $this->set_config(); |
|
| 224 | - /** @type EE_Events_Archive_Config $config */ |
|
| 225 | - $config = $this->config(); |
|
| 226 | - // load other required components |
|
| 227 | - $this->load_event_list_assets(); |
|
| 228 | - // filter the WP posts_join, posts_where, and posts_orderby SQL clauses |
|
| 229 | - //add query filters |
|
| 230 | - EEH_Event_Query::add_query_filters(); |
|
| 231 | - // set params that will get used by the filters |
|
| 232 | - EEH_Event_Query::set_query_params( |
|
| 233 | - '', // month |
|
| 234 | - '', // category |
|
| 235 | - $config->display_expired_events, // show_expired |
|
| 236 | - 'start_date', // orderby |
|
| 237 | - 'ASC' // sort |
|
| 238 | - ); |
|
| 239 | - // check what template is loaded |
|
| 240 | - add_filter('template_include', array($this, 'template_include'), 999, 1); |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - |
|
| 244 | - |
|
| 245 | - /** |
|
| 246 | - * most likely called by the ESPRESSO_EVENTS shortcode which uses this module to do some of it's lifting |
|
| 247 | - * |
|
| 248 | - * @return void |
|
| 249 | - */ |
|
| 250 | - public function event_list() |
|
| 251 | - { |
|
| 252 | - // ensure valid EE_Events_Archive_Config() object exists |
|
| 253 | - $this->set_config(); |
|
| 254 | - // load other required components |
|
| 255 | - $this->load_event_list_assets(); |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - |
|
| 259 | - |
|
| 260 | - /** |
|
| 261 | - * @access public |
|
| 262 | - * @return void |
|
| 263 | - * @throws \EE_Error |
|
| 264 | - * @throws \DomainException |
|
| 265 | - */ |
|
| 266 | - public function event_list_iframe() |
|
| 267 | - { |
|
| 268 | - \EED_Events_Archive::$iframe = true; |
|
| 269 | - $event_list_iframe = new EventsArchiveIframe($this); |
|
| 270 | - $event_list_iframe->display(); |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - |
|
| 274 | - |
|
| 275 | - /** |
|
| 276 | - * @access public |
|
| 277 | - * @return string |
|
| 278 | - */ |
|
| 279 | - public static function is_iframe() |
|
| 280 | - { |
|
| 281 | - return \EED_Events_Archive::$iframe; |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * @access public |
|
| 288 | - * @return string |
|
| 289 | - */ |
|
| 290 | - public static function link_target() |
|
| 291 | - { |
|
| 292 | - return \EED_Events_Archive::$iframe ? ' target="_blank"' : ''; |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - |
|
| 296 | - |
|
| 297 | - /** |
|
| 298 | - * template_include |
|
| 299 | - * |
|
| 300 | - * @access public |
|
| 301 | - * @param string $template |
|
| 302 | - * @return string |
|
| 303 | - */ |
|
| 304 | - public function template_include($template = '') |
|
| 305 | - { |
|
| 306 | - // don't add content filter for dedicated EE child themes or private posts |
|
| 307 | - if (! EEH_Template::is_espresso_theme()) { |
|
| 308 | - /** @type EE_Events_Archive_Config $config */ |
|
| 309 | - $config = $this->config(); |
|
| 310 | - // add status banner ? |
|
| 311 | - if ($config->display_status_banner) { |
|
| 312 | - add_filter('the_title', array('EED_Events_Archive', 'the_title'), 100, 2); |
|
| 313 | - } |
|
| 314 | - // if NOT a custom template |
|
| 315 | - if ( |
|
| 316 | - apply_filters('FHEE__EED_Event_Archive__template_include__allow_custom_selected_template', false) |
|
| 317 | - || EE_Registry::instance() |
|
| 318 | - ->load_core('Front_Controller') |
|
| 319 | - ->get_selected_template() !== 'archive-espresso_events.php' |
|
| 320 | - ) { |
|
| 321 | - // don't display entry meta because the existing theme will take care of that |
|
| 322 | - add_filter('FHEE__EED_Events_Archive__template_include__events_list_active', '__return_true'); |
|
| 323 | - // load functions.php file for the theme (loaded by WP if using child theme) |
|
| 324 | - EEH_Template::load_espresso_theme_functions(); |
|
| 325 | - // because we don't know if the theme is using the_excerpt() |
|
| 326 | - add_filter( |
|
| 327 | - 'the_excerpt', |
|
| 328 | - array('EED_Events_Archive', 'event_details'), |
|
| 329 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 330 | - ); |
|
| 331 | - // or the_content |
|
| 332 | - add_filter( |
|
| 333 | - 'the_content', |
|
| 334 | - array('EED_Events_Archive', 'event_details'), |
|
| 335 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 336 | - ); |
|
| 337 | - // and just in case they are running get_the_excerpt() which DESTROYS things |
|
| 338 | - add_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1, 1); |
|
| 339 | - // don't display entry meta because the existing theme will take care of that |
|
| 340 | - add_filter('FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false'); |
|
| 341 | - } |
|
| 342 | - } |
|
| 343 | - return $template; |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - |
|
| 347 | - |
|
| 348 | - /** |
|
| 349 | - * get_the_excerpt - kinda hacky, but if a theme is using get_the_excerpt(), then we need to remove our filters on the_content() |
|
| 350 | - * |
|
| 351 | - * @access public |
|
| 352 | - * @param string $excerpt |
|
| 353 | - * @return string |
|
| 354 | - */ |
|
| 355 | - public static function get_the_excerpt($excerpt = '') |
|
| 356 | - { |
|
| 357 | - if (post_password_required()) { |
|
| 358 | - return $excerpt; |
|
| 359 | - } |
|
| 360 | - if (apply_filters('FHEE__EED_Events_Archive__get_the_excerpt__theme_uses_get_the_excerpt', false)) { |
|
| 361 | - remove_filter( |
|
| 362 | - 'the_excerpt', |
|
| 363 | - array('EED_Events_Archive', 'event_details'), |
|
| 364 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 365 | - ); |
|
| 366 | - remove_filter( |
|
| 367 | - 'the_content', |
|
| 368 | - array('EED_Events_Archive', 'event_details'), |
|
| 369 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 370 | - ); |
|
| 371 | - $excerpt = EED_Events_Archive::event_details($excerpt); |
|
| 372 | - } else { |
|
| 373 | - EED_Events_Archive::$using_get_the_excerpt = true; |
|
| 374 | - add_filter('wp_trim_excerpt', array('EED_Events_Archive', 'end_get_the_excerpt'), 999, 1); |
|
| 375 | - } |
|
| 376 | - return $excerpt; |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - |
|
| 380 | - |
|
| 381 | - /** |
|
| 382 | - * end_get_the_excerpt |
|
| 383 | - * |
|
| 384 | - * @access public |
|
| 385 | - * @param string $text |
|
| 386 | - * @return string |
|
| 387 | - */ |
|
| 388 | - public static function end_get_the_excerpt($text = '') |
|
| 389 | - { |
|
| 390 | - EED_Events_Archive::$using_get_the_excerpt = false; |
|
| 391 | - return $text; |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - |
|
| 395 | - |
|
| 396 | - /** |
|
| 397 | - * the_title |
|
| 398 | - * |
|
| 399 | - * @access public |
|
| 400 | - * @param string $title |
|
| 401 | - * @param string $id |
|
| 402 | - * @return string |
|
| 403 | - */ |
|
| 404 | - public static function the_title($title = '', $id = '') |
|
| 405 | - { |
|
| 406 | - global $post; |
|
| 407 | - if ($post instanceof WP_Post) { |
|
| 408 | - return in_the_loop() && $post->ID == $id ? espresso_event_status_banner($post->ID) . $title : $title; |
|
| 409 | - } |
|
| 410 | - return $title; |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - |
|
| 414 | - |
|
| 415 | - /** |
|
| 416 | - * event_details |
|
| 417 | - * |
|
| 418 | - * @access public |
|
| 419 | - * @param string $content |
|
| 420 | - * @return string |
|
| 421 | - */ |
|
| 422 | - public static function event_details($content) |
|
| 423 | - { |
|
| 424 | - global $post; |
|
| 425 | - static $current_post_ID = 0; |
|
| 426 | - if ( |
|
| 427 | - $current_post_ID !== $post->ID |
|
| 428 | - && $post->post_type === 'espresso_events' |
|
| 429 | - && ! EED_Events_Archive::$using_get_the_excerpt |
|
| 430 | - && ! post_password_required() |
|
| 431 | - && ( |
|
| 432 | - apply_filters('FHEE__EES_Espresso_Events__process_shortcode__true', false) |
|
| 433 | - || ! apply_filters('FHEE__content_espresso_events__template_loaded', false) |
|
| 434 | - ) |
|
| 435 | - ) { |
|
| 436 | - // Set current post ID to prevent showing content twice, but only if headers have definitely been sent. |
|
| 437 | - // Reason being is that some plugins, like Yoast, need to run through a copy of the loop early |
|
| 438 | - // BEFORE headers are sent in order to examine the post content and generate content for the HTML header. |
|
| 439 | - // We want to allow those plugins to still do their thing and have access to our content, but depending on |
|
| 440 | - // how your event content is being displayed (shortcode, CPT route, etc), this filter can get applied twice, |
|
| 441 | - // so the following allows this filter to be applied multiple times, but only once for real |
|
| 442 | - $current_post_ID = did_action('loop_start') ? $post->ID : 0; |
|
| 443 | - if (EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->use_sortable_display_order) { |
|
| 444 | - $content = \EED_Events_Archive::use_sortable_display_order(); |
|
| 445 | - } else { |
|
| 446 | - $content = \EED_Events_Archive::use_filterable_display_order(); |
|
| 447 | - } |
|
| 448 | - } |
|
| 449 | - return $content; |
|
| 450 | - } |
|
| 451 | - |
|
| 452 | - |
|
| 453 | - |
|
| 454 | - /** |
|
| 455 | - * use_sortable_display_order |
|
| 456 | - * |
|
| 457 | - * @access protected |
|
| 458 | - * @return string |
|
| 459 | - */ |
|
| 460 | - protected static function use_sortable_display_order() |
|
| 461 | - { |
|
| 462 | - // no further password checks required atm |
|
| 463 | - add_filter('FHEE__EED_Events_Archive__event_details__no_post_password_required', '__return_true'); |
|
| 464 | - // we need to first remove this callback from being applied to the_content() or the_excerpt() |
|
| 465 | - // (otherwise it will recurse and blow up the interweb) |
|
| 466 | - remove_filter( |
|
| 467 | - 'the_excerpt', |
|
| 468 | - array('EED_Events_Archive', 'event_details'), |
|
| 469 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 470 | - ); |
|
| 471 | - remove_filter( |
|
| 472 | - 'the_content', |
|
| 473 | - array('EED_Events_Archive', 'event_details'), |
|
| 474 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 475 | - ); |
|
| 476 | - remove_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1); |
|
| 477 | - // now add additional content depending on whether event is using the_excerpt() or the_content() |
|
| 478 | - EED_Events_Archive::instance()->template_parts = EED_Events_Archive::instance()->initialize_template_parts(); |
|
| 479 | - $content = EEH_Template::locate_template('content-espresso_events-details.php'); |
|
| 480 | - $content = EED_Events_Archive::instance()->template_parts->apply_template_part_filters($content); |
|
| 481 | - // re-add our main filters (or else the next event won't have them) |
|
| 482 | - add_filter( |
|
| 483 | - 'the_excerpt', |
|
| 484 | - array('EED_Events_Archive', 'event_details'), |
|
| 485 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 486 | - ); |
|
| 487 | - add_filter( |
|
| 488 | - 'the_content', |
|
| 489 | - array('EED_Events_Archive', 'event_details'), |
|
| 490 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 491 | - ); |
|
| 492 | - add_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1, 1); |
|
| 493 | - remove_filter( |
|
| 494 | - 'FHEE__EED_Events_Archive__event_details__no_post_password_required', |
|
| 495 | - '__return_true' |
|
| 496 | - ); |
|
| 497 | - return $content; |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - |
|
| 501 | - |
|
| 502 | - /** |
|
| 503 | - * use_filterable_display_order |
|
| 504 | - * |
|
| 505 | - * @access protected |
|
| 506 | - * @return string |
|
| 507 | - */ |
|
| 508 | - protected static function use_filterable_display_order() |
|
| 509 | - { |
|
| 510 | - // we need to first remove this callback from being applied to the_content() |
|
| 511 | - // (otherwise it will recurse and blow up the interweb) |
|
| 512 | - remove_filter( |
|
| 513 | - 'the_excerpt', |
|
| 514 | - array('EED_Events_Archive', 'event_details'), |
|
| 515 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 516 | - ); |
|
| 517 | - remove_filter( |
|
| 518 | - 'the_content', |
|
| 519 | - array('EED_Events_Archive', 'event_details'), |
|
| 520 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 521 | - ); |
|
| 522 | - remove_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1); |
|
| 523 | - //now add additional content depending on whether event is using the_excerpt() or the_content() |
|
| 524 | - EED_Events_Archive::_add_additional_excerpt_filters(); |
|
| 525 | - EED_Events_Archive::_add_additional_content_filters(); |
|
| 526 | - do_action('AHEE__EED_Events_Archive__use_filterable_display_order__after_add_filters'); |
|
| 527 | - // now load our template |
|
| 528 | - $content = EEH_Template::locate_template('content-espresso_events-details.php'); |
|
| 529 | - // re-add our main filters (or else the next event won't have them) |
|
| 530 | - add_filter( |
|
| 531 | - 'the_excerpt', |
|
| 532 | - array('EED_Events_Archive', 'event_details'), |
|
| 533 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 534 | - ); |
|
| 535 | - add_filter( |
|
| 536 | - 'the_content', |
|
| 537 | - array('EED_Events_Archive', 'event_details'), |
|
| 538 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 539 | - ); |
|
| 540 | - add_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1, 1); |
|
| 541 | - // but remove the other filters so that they don't get applied to the next post |
|
| 542 | - EED_Events_Archive::_remove_additional_events_archive_filters(); |
|
| 543 | - do_action('AHEE__EED_Events_Archive__use_filterable_display_order__after_remove_filters'); |
|
| 544 | - // we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt) |
|
| 545 | - //return ! empty( $template ) ? $template : $content; |
|
| 546 | - return $content; |
|
| 547 | - } |
|
| 548 | - |
|
| 549 | - |
|
| 550 | - |
|
| 551 | - /** |
|
| 552 | - * event_datetimes - adds datetimes ABOVE content |
|
| 553 | - * |
|
| 554 | - * @access public |
|
| 555 | - * @param string $content |
|
| 556 | - * @return string |
|
| 557 | - */ |
|
| 558 | - public static function event_datetimes($content) |
|
| 559 | - { |
|
| 560 | - if (post_password_required()) { |
|
| 561 | - return $content; |
|
| 562 | - } |
|
| 563 | - return EEH_Template::locate_template('content-espresso_events-datetimes.php') . $content; |
|
| 564 | - } |
|
| 565 | - |
|
| 566 | - |
|
| 567 | - |
|
| 568 | - /** |
|
| 569 | - * event_tickets - adds tickets ABOVE content (which includes datetimes) |
|
| 570 | - * |
|
| 571 | - * @access public |
|
| 572 | - * @param string $content |
|
| 573 | - * @return string |
|
| 574 | - */ |
|
| 575 | - public static function event_tickets($content) |
|
| 576 | - { |
|
| 577 | - if (post_password_required()) { |
|
| 578 | - return $content; |
|
| 579 | - } |
|
| 580 | - return EEH_Template::locate_template('content-espresso_events-tickets.php') . $content; |
|
| 581 | - } |
|
| 582 | - |
|
| 583 | - |
|
| 584 | - |
|
| 585 | - /** |
|
| 586 | - * event_venues - adds venues BELOW content |
|
| 587 | - * |
|
| 588 | - * @access public |
|
| 589 | - * @param string $content |
|
| 590 | - * @return string |
|
| 591 | - */ |
|
| 592 | - public static function event_venue($content) |
|
| 593 | - { |
|
| 594 | - return EED_Events_Archive::event_venues($content); |
|
| 595 | - } |
|
| 596 | - |
|
| 597 | - |
|
| 598 | - |
|
| 599 | - /** |
|
| 600 | - * event_venues - adds venues BELOW content |
|
| 601 | - * |
|
| 602 | - * @access public |
|
| 603 | - * @param string $content |
|
| 604 | - * @return string |
|
| 605 | - */ |
|
| 606 | - public static function event_venues($content) |
|
| 607 | - { |
|
| 608 | - if (post_password_required()) { |
|
| 609 | - return $content; |
|
| 610 | - } |
|
| 611 | - return $content . EEH_Template::locate_template('content-espresso_events-venues.php'); |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - |
|
| 615 | - |
|
| 616 | - /** |
|
| 617 | - * _add_additional_content_filters |
|
| 618 | - * |
|
| 619 | - * @access private |
|
| 620 | - * @return void |
|
| 621 | - */ |
|
| 622 | - private static function _add_additional_excerpt_filters() |
|
| 623 | - { |
|
| 624 | - add_filter( |
|
| 625 | - 'the_excerpt', |
|
| 626 | - array('EED_Events_Archive', 'event_datetimes'), |
|
| 627 | - EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
| 628 | - ); |
|
| 629 | - add_filter( |
|
| 630 | - 'the_excerpt', |
|
| 631 | - array('EED_Events_Archive', 'event_tickets'), |
|
| 632 | - EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
| 633 | - ); |
|
| 634 | - add_filter( |
|
| 635 | - 'the_excerpt', |
|
| 636 | - array('EED_Events_Archive', 'event_venues'), |
|
| 637 | - EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
| 638 | - ); |
|
| 639 | - } |
|
| 640 | - |
|
| 641 | - |
|
| 642 | - |
|
| 643 | - /** |
|
| 644 | - * _add_additional_content_filters |
|
| 645 | - * |
|
| 646 | - * @access private |
|
| 647 | - * @return void |
|
| 648 | - */ |
|
| 649 | - private static function _add_additional_content_filters() |
|
| 650 | - { |
|
| 651 | - add_filter( |
|
| 652 | - 'the_content', |
|
| 653 | - array('EED_Events_Archive', 'event_datetimes'), |
|
| 654 | - EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
| 655 | - ); |
|
| 656 | - add_filter( |
|
| 657 | - 'the_content', |
|
| 658 | - array('EED_Events_Archive', 'event_tickets'), |
|
| 659 | - EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
| 660 | - ); |
|
| 661 | - add_filter( |
|
| 662 | - 'the_content', |
|
| 663 | - array('EED_Events_Archive', 'event_venues'), |
|
| 664 | - EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
| 665 | - ); |
|
| 666 | - } |
|
| 667 | - |
|
| 668 | - |
|
| 669 | - |
|
| 670 | - /** |
|
| 671 | - * _remove_additional_events_archive_filters |
|
| 672 | - * |
|
| 673 | - * @access private |
|
| 674 | - * @return void |
|
| 675 | - */ |
|
| 676 | - private static function _remove_additional_events_archive_filters() |
|
| 677 | - { |
|
| 678 | - remove_filter( |
|
| 679 | - 'the_excerpt', |
|
| 680 | - array('EED_Events_Archive', 'event_datetimes'), |
|
| 681 | - EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
| 682 | - ); |
|
| 683 | - remove_filter( |
|
| 684 | - 'the_excerpt', |
|
| 685 | - array('EED_Events_Archive', 'event_tickets'), |
|
| 686 | - EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
| 687 | - ); |
|
| 688 | - remove_filter( |
|
| 689 | - 'the_excerpt', |
|
| 690 | - array('EED_Events_Archive', 'event_venues'), |
|
| 691 | - EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
| 692 | - ); |
|
| 693 | - remove_filter( |
|
| 694 | - 'the_content', |
|
| 695 | - array('EED_Events_Archive', 'event_datetimes'), |
|
| 696 | - EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
| 697 | - ); |
|
| 698 | - remove_filter( |
|
| 699 | - 'the_content', |
|
| 700 | - array('EED_Events_Archive', 'event_tickets'), |
|
| 701 | - EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
| 702 | - ); |
|
| 703 | - remove_filter( |
|
| 704 | - 'the_content', |
|
| 705 | - array('EED_Events_Archive', 'event_venues'), |
|
| 706 | - EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
| 707 | - ); |
|
| 708 | - } |
|
| 709 | - |
|
| 710 | - |
|
| 711 | - |
|
| 712 | - /** |
|
| 713 | - * remove_all_events_archive_filters |
|
| 714 | - * |
|
| 715 | - * @access public |
|
| 716 | - * @return void |
|
| 717 | - */ |
|
| 718 | - public static function remove_all_events_archive_filters() |
|
| 719 | - { |
|
| 720 | - //remove_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1 ); |
|
| 721 | - remove_filter('the_title', array('EED_Events_Archive', 'the_title'), 1); |
|
| 722 | - remove_filter( |
|
| 723 | - 'the_excerpt', |
|
| 724 | - array('EED_Events_Archive', 'event_details'), |
|
| 725 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 726 | - ); |
|
| 727 | - remove_filter( |
|
| 728 | - 'the_excerpt', |
|
| 729 | - array('EED_Events_Archive', 'event_datetimes'), |
|
| 730 | - EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
| 731 | - ); |
|
| 732 | - remove_filter( |
|
| 733 | - 'the_excerpt', |
|
| 734 | - array('EED_Events_Archive', 'event_tickets'), |
|
| 735 | - EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
| 736 | - ); |
|
| 737 | - remove_filter( |
|
| 738 | - 'the_excerpt', |
|
| 739 | - array('EED_Events_Archive', 'event_venues'), |
|
| 740 | - EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
| 741 | - ); |
|
| 742 | - remove_filter( |
|
| 743 | - 'the_content', |
|
| 744 | - array('EED_Events_Archive', 'event_details'), |
|
| 745 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 746 | - ); |
|
| 747 | - remove_filter( |
|
| 748 | - 'the_content', |
|
| 749 | - array('EED_Events_Archive', 'event_datetimes'), |
|
| 750 | - EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
| 751 | - ); |
|
| 752 | - remove_filter( |
|
| 753 | - 'the_content', |
|
| 754 | - array('EED_Events_Archive', 'event_tickets'), |
|
| 755 | - EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
| 756 | - ); |
|
| 757 | - remove_filter( |
|
| 758 | - 'the_content', |
|
| 759 | - array('EED_Events_Archive', 'event_venues'), |
|
| 760 | - EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
| 761 | - ); |
|
| 762 | - // don't display entry meta because the existing theme will take care of that |
|
| 763 | - remove_filter( |
|
| 764 | - 'FHEE__content_espresso_events_details_template__display_entry_meta', |
|
| 765 | - '__return_false' |
|
| 766 | - ); |
|
| 767 | - } |
|
| 768 | - |
|
| 769 | - |
|
| 770 | - |
|
| 771 | - /** |
|
| 772 | - * load_event_list_assets |
|
| 773 | - * |
|
| 774 | - * @access public |
|
| 775 | - * @return void |
|
| 776 | - */ |
|
| 777 | - public function load_event_list_assets() |
|
| 778 | - { |
|
| 779 | - do_action('AHEE__EED_Events_Archive__before_load_assets'); |
|
| 780 | - add_filter('FHEE_load_EE_Session', '__return_true'); |
|
| 781 | - add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true'); |
|
| 782 | - add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10); |
|
| 783 | - if (EE_Registry::instance()->CFG->map_settings->use_google_maps) { |
|
| 784 | - add_action('wp_enqueue_scripts', array('EEH_Maps', 'espresso_google_map_js'), 11); |
|
| 785 | - } |
|
| 786 | - } |
|
| 787 | - |
|
| 788 | - |
|
| 789 | - |
|
| 790 | - /** |
|
| 791 | - * wp_enqueue_scripts |
|
| 792 | - * |
|
| 793 | - * @access public |
|
| 794 | - * @return void |
|
| 795 | - */ |
|
| 796 | - public function wp_enqueue_scripts() |
|
| 797 | - { |
|
| 798 | - // get some style |
|
| 799 | - if (apply_filters('FHEE_enable_default_espresso_css', false)) { |
|
| 800 | - // first check uploads folder |
|
| 801 | - if (EEH_File::is_readable(get_stylesheet_directory() . $this->theme . DS . 'style.css')) { |
|
| 802 | - wp_register_style($this->theme, get_stylesheet_directory_uri() . $this->theme . DS . 'style.css', array('dashicons', 'espresso_default')); |
|
| 803 | - } else { |
|
| 804 | - } |
|
| 805 | - wp_enqueue_style($this->theme); |
|
| 806 | - } |
|
| 807 | - } |
|
| 808 | - |
|
| 809 | - |
|
| 810 | - |
|
| 811 | - /** |
|
| 812 | - * template_settings_form |
|
| 813 | - * |
|
| 814 | - * @access public |
|
| 815 | - * @static |
|
| 816 | - * @return string |
|
| 817 | - */ |
|
| 818 | - public static function template_settings_form() |
|
| 819 | - { |
|
| 820 | - $template_settings = EE_Registry::instance()->CFG->template_settings; |
|
| 821 | - $template_settings->EED_Events_Archive = isset($template_settings->EED_Events_Archive) ? $template_settings->EED_Events_Archive : new EE_Events_Archive_Config(); |
|
| 822 | - $template_settings->EED_Events_Archive = apply_filters('FHEE__EED_Events_Archive__template_settings_form__event_list_config', $template_settings->EED_Events_Archive); |
|
| 823 | - $events_archive_settings = array( |
|
| 824 | - 'display_status_banner' => 0, |
|
| 825 | - 'display_description' => 1, |
|
| 826 | - 'display_ticket_selector' => 0, |
|
| 827 | - 'display_datetimes' => 1, |
|
| 828 | - 'display_venue' => 0, |
|
| 829 | - 'display_expired_events' => 0, |
|
| 830 | - ); |
|
| 831 | - $events_archive_settings = array_merge($events_archive_settings, (array)$template_settings->EED_Events_Archive); |
|
| 832 | - EEH_Template::display_template(EVENTS_ARCHIVE_TEMPLATES_PATH . 'admin-event-list-settings.template.php', $events_archive_settings); |
|
| 833 | - } |
|
| 834 | - |
|
| 835 | - |
|
| 836 | - |
|
| 837 | - /** |
|
| 838 | - * update_template_settings |
|
| 839 | - * |
|
| 840 | - * @access public |
|
| 841 | - * @param EE_Template_Config $CFG |
|
| 842 | - * @param EE_Request_Handler $REQ |
|
| 843 | - * @return EE_Template_Config |
|
| 844 | - */ |
|
| 845 | - public static function update_template_settings($CFG, $REQ) |
|
| 846 | - { |
|
| 847 | - $CFG->EED_Events_Archive = new EE_Events_Archive_Config(); |
|
| 848 | - // unless we are resetting the config... |
|
| 849 | - if (! isset($REQ['EED_Events_Archive_reset_event_list_settings']) || absint($REQ['EED_Events_Archive_reset_event_list_settings']) !== 1) { |
|
| 850 | - $CFG->EED_Events_Archive->display_status_banner = isset($REQ['EED_Events_Archive_display_status_banner']) ? absint($REQ['EED_Events_Archive_display_status_banner']) : 0; |
|
| 851 | - $CFG->EED_Events_Archive->display_description = isset($REQ['EED_Events_Archive_display_description']) ? absint($REQ['EED_Events_Archive_display_description']) : 1; |
|
| 852 | - $CFG->EED_Events_Archive->display_ticket_selector = isset($REQ['EED_Events_Archive_display_ticket_selector']) ? absint($REQ['EED_Events_Archive_display_ticket_selector']) : 0; |
|
| 853 | - $CFG->EED_Events_Archive->display_datetimes = isset($REQ['EED_Events_Archive_display_datetimes']) ? absint($REQ['EED_Events_Archive_display_datetimes']) : 1; |
|
| 854 | - $CFG->EED_Events_Archive->display_venue = isset($REQ['EED_Events_Archive_display_venue']) ? absint($REQ['EED_Events_Archive_display_venue']) : 0; |
|
| 855 | - $CFG->EED_Events_Archive->display_expired_events = isset($REQ['EED_Events_Archive_display_expired_events']) ? absint($REQ['EED_Events_Archive_display_expired_events']) : 0; |
|
| 856 | - } |
|
| 857 | - return $CFG; |
|
| 858 | - } |
|
| 859 | - |
|
| 860 | - |
|
| 861 | - |
|
| 862 | - /** |
|
| 863 | - * event_list_css |
|
| 864 | - * |
|
| 865 | - * @access public |
|
| 866 | - * @param string $extra_class |
|
| 867 | - * @return string |
|
| 868 | - */ |
|
| 869 | - public static function event_list_css($extra_class = '') |
|
| 870 | - { |
|
| 871 | - $event_list_css = ! empty($extra_class) ? array($extra_class) : array(); |
|
| 872 | - $event_list_css[] = 'espresso-event-list-event'; |
|
| 873 | - return implode(' ', $event_list_css); |
|
| 874 | - } |
|
| 875 | - |
|
| 876 | - |
|
| 877 | - |
|
| 878 | - /** |
|
| 879 | - * event_categories |
|
| 880 | - * |
|
| 881 | - * @access public |
|
| 882 | - * @return array |
|
| 883 | - */ |
|
| 884 | - public static function event_categories() |
|
| 885 | - { |
|
| 886 | - return EE_Registry::instance()->load_model('Term')->get_all_ee_categories(); |
|
| 887 | - } |
|
| 888 | - |
|
| 889 | - |
|
| 890 | - |
|
| 891 | - /** |
|
| 892 | - * display_description |
|
| 893 | - * |
|
| 894 | - * @access public |
|
| 895 | - * @param $value |
|
| 896 | - * @return bool |
|
| 897 | - */ |
|
| 898 | - public static function display_description($value) |
|
| 899 | - { |
|
| 900 | - $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive; |
|
| 901 | - $display_description = isset($config->display_description) ? $config->display_description : 1; |
|
| 902 | - return $display_description === $value ? true : false; |
|
| 903 | - } |
|
| 904 | - |
|
| 905 | - |
|
| 906 | - |
|
| 907 | - /** |
|
| 908 | - * display_ticket_selector |
|
| 909 | - * |
|
| 910 | - * @access public |
|
| 911 | - * @return bool |
|
| 912 | - */ |
|
| 913 | - public static function display_ticket_selector() |
|
| 914 | - { |
|
| 915 | - $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive; |
|
| 916 | - return isset($config->display_ticket_selector) && $config->display_ticket_selector ? true : false; |
|
| 917 | - } |
|
| 918 | - |
|
| 919 | - |
|
| 920 | - |
|
| 921 | - /** |
|
| 922 | - * display_venue |
|
| 923 | - * |
|
| 924 | - * @access public |
|
| 925 | - * @return bool |
|
| 926 | - */ |
|
| 927 | - public static function display_venue() |
|
| 928 | - { |
|
| 929 | - $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive; |
|
| 930 | - return isset($config->display_venue) && $config->display_venue && EEH_Venue_View::venue_name() ? true : false; |
|
| 931 | - } |
|
| 932 | - |
|
| 933 | - |
|
| 934 | - |
|
| 935 | - /** |
|
| 936 | - * display_datetimes |
|
| 937 | - * |
|
| 938 | - * @access public |
|
| 939 | - * @return bool |
|
| 940 | - */ |
|
| 941 | - public static function display_datetimes() |
|
| 942 | - { |
|
| 943 | - $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive; |
|
| 944 | - return isset($config->display_datetimes) && $config->display_datetimes ? true : false; |
|
| 945 | - } |
|
| 946 | - |
|
| 947 | - |
|
| 948 | - |
|
| 949 | - /** |
|
| 950 | - * event_list_title |
|
| 951 | - * |
|
| 952 | - * @access public |
|
| 953 | - * @return string |
|
| 954 | - */ |
|
| 955 | - public static function event_list_title() |
|
| 956 | - { |
|
| 957 | - return apply_filters('FHEE__archive_espresso_events_template__upcoming_events_h1', __('Upcoming Events', 'event_espresso')); |
|
| 958 | - } |
|
| 959 | - |
|
| 960 | - |
|
| 961 | - // GRAVEYARD |
|
| 962 | - |
|
| 963 | - |
|
| 964 | - |
|
| 965 | - /** |
|
| 966 | - * @since 4.4.0 |
|
| 967 | - */ |
|
| 968 | - public static function _doing_it_wrong_notice($function = '') |
|
| 969 | - { |
|
| 970 | - EE_Error::doing_it_wrong( |
|
| 971 | - __FUNCTION__, |
|
| 972 | - sprintf( |
|
| 973 | - __('EED_Events_Archive::%1$s was moved to EEH_Event_Query::%1$s:%2$sPlease update your existing code because the method it calls will be removed in version %3$s', 'event_espresso'), |
|
| 974 | - $function, |
|
| 975 | - '<br />', |
|
| 976 | - '4.6.0' |
|
| 977 | - ), |
|
| 978 | - '4.4.0' |
|
| 979 | - ); |
|
| 980 | - } |
|
| 981 | - |
|
| 982 | - |
|
| 983 | - |
|
| 984 | - /** |
|
| 985 | - * @deprecated |
|
| 986 | - * @since 4.4.0 |
|
| 987 | - */ |
|
| 988 | - public function get_post_data() |
|
| 989 | - { |
|
| 990 | - EEH_Event_Query::set_query_params(); |
|
| 991 | - } |
|
| 992 | - |
|
| 993 | - |
|
| 994 | - |
|
| 995 | - /** |
|
| 996 | - * @deprecated |
|
| 997 | - * @since 4.4.0 |
|
| 998 | - */ |
|
| 999 | - public function posts_fields($SQL, WP_Query $wp_query) |
|
| 1000 | - { |
|
| 1001 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1002 | - return EEH_Event_Query::posts_fields($SQL, $wp_query); |
|
| 1003 | - } |
|
| 20 | + const EVENT_DETAILS_PRIORITY = 100; |
|
| 21 | + |
|
| 22 | + const EVENT_DATETIMES_PRIORITY = 110; |
|
| 23 | + |
|
| 24 | + const EVENT_TICKETS_PRIORITY = 120; |
|
| 25 | + |
|
| 26 | + const EVENT_VENUES_PRIORITY = 130; |
|
| 27 | + |
|
| 28 | + |
|
| 29 | + public static $espresso_event_list_ID = 0; |
|
| 30 | + |
|
| 31 | + public static $espresso_grid_event_lists = array(); |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @type bool $using_get_the_excerpt |
|
| 35 | + */ |
|
| 36 | + protected static $using_get_the_excerpt = false; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Used to flag when the event list is being called from an external iframe. |
|
| 40 | + * |
|
| 41 | + * @var bool $iframe |
|
| 42 | + */ |
|
| 43 | + protected static $iframe = false; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @var \EventEspresso\core\libraries\iframe_display\EventListIframeEmbedButton $_iframe_embed_button |
|
| 47 | + */ |
|
| 48 | + private static $_iframe_embed_button; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @type EE_Template_Part_Manager $template_parts |
|
| 52 | + */ |
|
| 53 | + protected $template_parts; |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @return EED_Events_Archive |
|
| 59 | + */ |
|
| 60 | + public static function instance() |
|
| 61 | + { |
|
| 62 | + return parent::get_instance(__CLASS__); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
| 69 | + * |
|
| 70 | + * @access public |
|
| 71 | + * @return void |
|
| 72 | + */ |
|
| 73 | + public static function set_hooks() |
|
| 74 | + { |
|
| 75 | + $custom_post_types = EE_Register_CPTs::get_CPTs(); |
|
| 76 | + EE_Config::register_route( |
|
| 77 | + $custom_post_types['espresso_events']['plural_slug'], |
|
| 78 | + 'Events_Archive', |
|
| 79 | + 'run' |
|
| 80 | + ); |
|
| 81 | + EE_Config::register_route( |
|
| 82 | + 'event_list', |
|
| 83 | + 'Events_Archive', |
|
| 84 | + 'event_list' |
|
| 85 | + ); |
|
| 86 | + EE_Config::register_route( |
|
| 87 | + 'iframe', |
|
| 88 | + 'Events_Archive', |
|
| 89 | + 'event_list_iframe', |
|
| 90 | + 'event_list' |
|
| 91 | + ); |
|
| 92 | + add_action('wp_loaded', array('EED_Events_Archive', 'set_definitions'), 2); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 99 | + * |
|
| 100 | + * @access public |
|
| 101 | + * @return void |
|
| 102 | + */ |
|
| 103 | + public static function set_hooks_admin() |
|
| 104 | + { |
|
| 105 | + add_action('wp_loaded', array('EED_Events_Archive', 'set_definitions'), 2); |
|
| 106 | + // hook into the end of the \EE_Admin_Page::_load_page_dependencies() |
|
| 107 | + // to load assets for "espresso_events" page on the "default" route (action) |
|
| 108 | + add_action( |
|
| 109 | + 'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_events__default', |
|
| 110 | + array('EED_Events_Archive', 'event_list_iframe_embed_button'), |
|
| 111 | + 10 |
|
| 112 | + ); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * set_definitions |
|
| 119 | + * |
|
| 120 | + * @access public |
|
| 121 | + * @return void |
|
| 122 | + */ |
|
| 123 | + public static function set_definitions() |
|
| 124 | + { |
|
| 125 | + define('EVENTS_ARCHIVE_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
| 126 | + define('EVENTS_ARCHIVE_TEMPLATES_PATH', str_replace('\\', DS, plugin_dir_path(__FILE__)) . 'templates' . DS); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * set up EE_Events_Archive_Config |
|
| 133 | + */ |
|
| 134 | + protected function set_config() |
|
| 135 | + { |
|
| 136 | + $this->set_config_section('template_settings'); |
|
| 137 | + $this->set_config_class('EE_Events_Archive_Config'); |
|
| 138 | + $this->set_config_name('EED_Events_Archive'); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * @return EventListIframeEmbedButton |
|
| 145 | + */ |
|
| 146 | + public static function get_iframe_embed_button() |
|
| 147 | + { |
|
| 148 | + if (! self::$_iframe_embed_button instanceof EventListIframeEmbedButton) { |
|
| 149 | + self::$_iframe_embed_button = new EventListIframeEmbedButton(); |
|
| 150 | + } |
|
| 151 | + return self::$_iframe_embed_button; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * event_list_iframe_embed_button |
|
| 158 | + * |
|
| 159 | + * @return void |
|
| 160 | + * @throws \EE_Error |
|
| 161 | + */ |
|
| 162 | + public static function event_list_iframe_embed_button() |
|
| 163 | + { |
|
| 164 | + $iframe_embed_button = \EED_Events_Archive::get_iframe_embed_button(); |
|
| 165 | + $iframe_embed_button->addEmbedButton(); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * initialize_template_parts |
|
| 172 | + * |
|
| 173 | + * @access public |
|
| 174 | + * @param \EE_Events_Archive_Config $config |
|
| 175 | + * @return \EE_Template_Part_Manager |
|
| 176 | + */ |
|
| 177 | + public function initialize_template_parts(EE_Events_Archive_Config $config = null) |
|
| 178 | + { |
|
| 179 | + $config = $config instanceof EE_Events_Archive_Config ? $config : $this->config(); |
|
| 180 | + EEH_Autoloader::instance()->register_template_part_autoloaders(); |
|
| 181 | + $template_parts = new EE_Template_Part_Manager(); |
|
| 182 | + $template_parts->add_template_part( |
|
| 183 | + 'tickets', |
|
| 184 | + __('Ticket Selector', 'event_espresso'), |
|
| 185 | + 'content-espresso_events-tickets.php', |
|
| 186 | + $config->display_order_tickets |
|
| 187 | + ); |
|
| 188 | + $template_parts->add_template_part( |
|
| 189 | + 'datetimes', |
|
| 190 | + __('Dates and Times', 'event_espresso'), |
|
| 191 | + 'content-espresso_events-datetimes.php', |
|
| 192 | + $config->display_order_datetimes |
|
| 193 | + ); |
|
| 194 | + $template_parts->add_template_part( |
|
| 195 | + 'event', |
|
| 196 | + __('Event Description', 'event_espresso'), |
|
| 197 | + 'content-espresso_events-details.php', |
|
| 198 | + $config->display_order_event |
|
| 199 | + ); |
|
| 200 | + $template_parts->add_template_part( |
|
| 201 | + 'venue', |
|
| 202 | + __('Venue Information', 'event_espresso'), |
|
| 203 | + 'content-espresso_events-venues.php', |
|
| 204 | + $config->display_order_venue |
|
| 205 | + ); |
|
| 206 | + do_action('AHEE__EED_Event_Archive__initialize_template_parts', $template_parts); |
|
| 207 | + return $template_parts; |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * run - initial module setup - this gets called by the EE_Front_Controller if the module route is found in the incoming request |
|
| 214 | + * |
|
| 215 | + * @access public |
|
| 216 | + * @param WP $WP |
|
| 217 | + * @return void |
|
| 218 | + */ |
|
| 219 | + public function run($WP) |
|
| 220 | + { |
|
| 221 | + do_action('AHEE__EED_Events_Archive__before_run'); |
|
| 222 | + // ensure valid EE_Events_Archive_Config() object exists |
|
| 223 | + $this->set_config(); |
|
| 224 | + /** @type EE_Events_Archive_Config $config */ |
|
| 225 | + $config = $this->config(); |
|
| 226 | + // load other required components |
|
| 227 | + $this->load_event_list_assets(); |
|
| 228 | + // filter the WP posts_join, posts_where, and posts_orderby SQL clauses |
|
| 229 | + //add query filters |
|
| 230 | + EEH_Event_Query::add_query_filters(); |
|
| 231 | + // set params that will get used by the filters |
|
| 232 | + EEH_Event_Query::set_query_params( |
|
| 233 | + '', // month |
|
| 234 | + '', // category |
|
| 235 | + $config->display_expired_events, // show_expired |
|
| 236 | + 'start_date', // orderby |
|
| 237 | + 'ASC' // sort |
|
| 238 | + ); |
|
| 239 | + // check what template is loaded |
|
| 240 | + add_filter('template_include', array($this, 'template_include'), 999, 1); |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + |
|
| 244 | + |
|
| 245 | + /** |
|
| 246 | + * most likely called by the ESPRESSO_EVENTS shortcode which uses this module to do some of it's lifting |
|
| 247 | + * |
|
| 248 | + * @return void |
|
| 249 | + */ |
|
| 250 | + public function event_list() |
|
| 251 | + { |
|
| 252 | + // ensure valid EE_Events_Archive_Config() object exists |
|
| 253 | + $this->set_config(); |
|
| 254 | + // load other required components |
|
| 255 | + $this->load_event_list_assets(); |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + |
|
| 259 | + |
|
| 260 | + /** |
|
| 261 | + * @access public |
|
| 262 | + * @return void |
|
| 263 | + * @throws \EE_Error |
|
| 264 | + * @throws \DomainException |
|
| 265 | + */ |
|
| 266 | + public function event_list_iframe() |
|
| 267 | + { |
|
| 268 | + \EED_Events_Archive::$iframe = true; |
|
| 269 | + $event_list_iframe = new EventsArchiveIframe($this); |
|
| 270 | + $event_list_iframe->display(); |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + |
|
| 274 | + |
|
| 275 | + /** |
|
| 276 | + * @access public |
|
| 277 | + * @return string |
|
| 278 | + */ |
|
| 279 | + public static function is_iframe() |
|
| 280 | + { |
|
| 281 | + return \EED_Events_Archive::$iframe; |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * @access public |
|
| 288 | + * @return string |
|
| 289 | + */ |
|
| 290 | + public static function link_target() |
|
| 291 | + { |
|
| 292 | + return \EED_Events_Archive::$iframe ? ' target="_blank"' : ''; |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + |
|
| 296 | + |
|
| 297 | + /** |
|
| 298 | + * template_include |
|
| 299 | + * |
|
| 300 | + * @access public |
|
| 301 | + * @param string $template |
|
| 302 | + * @return string |
|
| 303 | + */ |
|
| 304 | + public function template_include($template = '') |
|
| 305 | + { |
|
| 306 | + // don't add content filter for dedicated EE child themes or private posts |
|
| 307 | + if (! EEH_Template::is_espresso_theme()) { |
|
| 308 | + /** @type EE_Events_Archive_Config $config */ |
|
| 309 | + $config = $this->config(); |
|
| 310 | + // add status banner ? |
|
| 311 | + if ($config->display_status_banner) { |
|
| 312 | + add_filter('the_title', array('EED_Events_Archive', 'the_title'), 100, 2); |
|
| 313 | + } |
|
| 314 | + // if NOT a custom template |
|
| 315 | + if ( |
|
| 316 | + apply_filters('FHEE__EED_Event_Archive__template_include__allow_custom_selected_template', false) |
|
| 317 | + || EE_Registry::instance() |
|
| 318 | + ->load_core('Front_Controller') |
|
| 319 | + ->get_selected_template() !== 'archive-espresso_events.php' |
|
| 320 | + ) { |
|
| 321 | + // don't display entry meta because the existing theme will take care of that |
|
| 322 | + add_filter('FHEE__EED_Events_Archive__template_include__events_list_active', '__return_true'); |
|
| 323 | + // load functions.php file for the theme (loaded by WP if using child theme) |
|
| 324 | + EEH_Template::load_espresso_theme_functions(); |
|
| 325 | + // because we don't know if the theme is using the_excerpt() |
|
| 326 | + add_filter( |
|
| 327 | + 'the_excerpt', |
|
| 328 | + array('EED_Events_Archive', 'event_details'), |
|
| 329 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 330 | + ); |
|
| 331 | + // or the_content |
|
| 332 | + add_filter( |
|
| 333 | + 'the_content', |
|
| 334 | + array('EED_Events_Archive', 'event_details'), |
|
| 335 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 336 | + ); |
|
| 337 | + // and just in case they are running get_the_excerpt() which DESTROYS things |
|
| 338 | + add_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1, 1); |
|
| 339 | + // don't display entry meta because the existing theme will take care of that |
|
| 340 | + add_filter('FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false'); |
|
| 341 | + } |
|
| 342 | + } |
|
| 343 | + return $template; |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + |
|
| 347 | + |
|
| 348 | + /** |
|
| 349 | + * get_the_excerpt - kinda hacky, but if a theme is using get_the_excerpt(), then we need to remove our filters on the_content() |
|
| 350 | + * |
|
| 351 | + * @access public |
|
| 352 | + * @param string $excerpt |
|
| 353 | + * @return string |
|
| 354 | + */ |
|
| 355 | + public static function get_the_excerpt($excerpt = '') |
|
| 356 | + { |
|
| 357 | + if (post_password_required()) { |
|
| 358 | + return $excerpt; |
|
| 359 | + } |
|
| 360 | + if (apply_filters('FHEE__EED_Events_Archive__get_the_excerpt__theme_uses_get_the_excerpt', false)) { |
|
| 361 | + remove_filter( |
|
| 362 | + 'the_excerpt', |
|
| 363 | + array('EED_Events_Archive', 'event_details'), |
|
| 364 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 365 | + ); |
|
| 366 | + remove_filter( |
|
| 367 | + 'the_content', |
|
| 368 | + array('EED_Events_Archive', 'event_details'), |
|
| 369 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 370 | + ); |
|
| 371 | + $excerpt = EED_Events_Archive::event_details($excerpt); |
|
| 372 | + } else { |
|
| 373 | + EED_Events_Archive::$using_get_the_excerpt = true; |
|
| 374 | + add_filter('wp_trim_excerpt', array('EED_Events_Archive', 'end_get_the_excerpt'), 999, 1); |
|
| 375 | + } |
|
| 376 | + return $excerpt; |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + |
|
| 380 | + |
|
| 381 | + /** |
|
| 382 | + * end_get_the_excerpt |
|
| 383 | + * |
|
| 384 | + * @access public |
|
| 385 | + * @param string $text |
|
| 386 | + * @return string |
|
| 387 | + */ |
|
| 388 | + public static function end_get_the_excerpt($text = '') |
|
| 389 | + { |
|
| 390 | + EED_Events_Archive::$using_get_the_excerpt = false; |
|
| 391 | + return $text; |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + |
|
| 395 | + |
|
| 396 | + /** |
|
| 397 | + * the_title |
|
| 398 | + * |
|
| 399 | + * @access public |
|
| 400 | + * @param string $title |
|
| 401 | + * @param string $id |
|
| 402 | + * @return string |
|
| 403 | + */ |
|
| 404 | + public static function the_title($title = '', $id = '') |
|
| 405 | + { |
|
| 406 | + global $post; |
|
| 407 | + if ($post instanceof WP_Post) { |
|
| 408 | + return in_the_loop() && $post->ID == $id ? espresso_event_status_banner($post->ID) . $title : $title; |
|
| 409 | + } |
|
| 410 | + return $title; |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + |
|
| 414 | + |
|
| 415 | + /** |
|
| 416 | + * event_details |
|
| 417 | + * |
|
| 418 | + * @access public |
|
| 419 | + * @param string $content |
|
| 420 | + * @return string |
|
| 421 | + */ |
|
| 422 | + public static function event_details($content) |
|
| 423 | + { |
|
| 424 | + global $post; |
|
| 425 | + static $current_post_ID = 0; |
|
| 426 | + if ( |
|
| 427 | + $current_post_ID !== $post->ID |
|
| 428 | + && $post->post_type === 'espresso_events' |
|
| 429 | + && ! EED_Events_Archive::$using_get_the_excerpt |
|
| 430 | + && ! post_password_required() |
|
| 431 | + && ( |
|
| 432 | + apply_filters('FHEE__EES_Espresso_Events__process_shortcode__true', false) |
|
| 433 | + || ! apply_filters('FHEE__content_espresso_events__template_loaded', false) |
|
| 434 | + ) |
|
| 435 | + ) { |
|
| 436 | + // Set current post ID to prevent showing content twice, but only if headers have definitely been sent. |
|
| 437 | + // Reason being is that some plugins, like Yoast, need to run through a copy of the loop early |
|
| 438 | + // BEFORE headers are sent in order to examine the post content and generate content for the HTML header. |
|
| 439 | + // We want to allow those plugins to still do their thing and have access to our content, but depending on |
|
| 440 | + // how your event content is being displayed (shortcode, CPT route, etc), this filter can get applied twice, |
|
| 441 | + // so the following allows this filter to be applied multiple times, but only once for real |
|
| 442 | + $current_post_ID = did_action('loop_start') ? $post->ID : 0; |
|
| 443 | + if (EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->use_sortable_display_order) { |
|
| 444 | + $content = \EED_Events_Archive::use_sortable_display_order(); |
|
| 445 | + } else { |
|
| 446 | + $content = \EED_Events_Archive::use_filterable_display_order(); |
|
| 447 | + } |
|
| 448 | + } |
|
| 449 | + return $content; |
|
| 450 | + } |
|
| 451 | + |
|
| 452 | + |
|
| 453 | + |
|
| 454 | + /** |
|
| 455 | + * use_sortable_display_order |
|
| 456 | + * |
|
| 457 | + * @access protected |
|
| 458 | + * @return string |
|
| 459 | + */ |
|
| 460 | + protected static function use_sortable_display_order() |
|
| 461 | + { |
|
| 462 | + // no further password checks required atm |
|
| 463 | + add_filter('FHEE__EED_Events_Archive__event_details__no_post_password_required', '__return_true'); |
|
| 464 | + // we need to first remove this callback from being applied to the_content() or the_excerpt() |
|
| 465 | + // (otherwise it will recurse and blow up the interweb) |
|
| 466 | + remove_filter( |
|
| 467 | + 'the_excerpt', |
|
| 468 | + array('EED_Events_Archive', 'event_details'), |
|
| 469 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 470 | + ); |
|
| 471 | + remove_filter( |
|
| 472 | + 'the_content', |
|
| 473 | + array('EED_Events_Archive', 'event_details'), |
|
| 474 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 475 | + ); |
|
| 476 | + remove_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1); |
|
| 477 | + // now add additional content depending on whether event is using the_excerpt() or the_content() |
|
| 478 | + EED_Events_Archive::instance()->template_parts = EED_Events_Archive::instance()->initialize_template_parts(); |
|
| 479 | + $content = EEH_Template::locate_template('content-espresso_events-details.php'); |
|
| 480 | + $content = EED_Events_Archive::instance()->template_parts->apply_template_part_filters($content); |
|
| 481 | + // re-add our main filters (or else the next event won't have them) |
|
| 482 | + add_filter( |
|
| 483 | + 'the_excerpt', |
|
| 484 | + array('EED_Events_Archive', 'event_details'), |
|
| 485 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 486 | + ); |
|
| 487 | + add_filter( |
|
| 488 | + 'the_content', |
|
| 489 | + array('EED_Events_Archive', 'event_details'), |
|
| 490 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 491 | + ); |
|
| 492 | + add_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1, 1); |
|
| 493 | + remove_filter( |
|
| 494 | + 'FHEE__EED_Events_Archive__event_details__no_post_password_required', |
|
| 495 | + '__return_true' |
|
| 496 | + ); |
|
| 497 | + return $content; |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + |
|
| 501 | + |
|
| 502 | + /** |
|
| 503 | + * use_filterable_display_order |
|
| 504 | + * |
|
| 505 | + * @access protected |
|
| 506 | + * @return string |
|
| 507 | + */ |
|
| 508 | + protected static function use_filterable_display_order() |
|
| 509 | + { |
|
| 510 | + // we need to first remove this callback from being applied to the_content() |
|
| 511 | + // (otherwise it will recurse and blow up the interweb) |
|
| 512 | + remove_filter( |
|
| 513 | + 'the_excerpt', |
|
| 514 | + array('EED_Events_Archive', 'event_details'), |
|
| 515 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 516 | + ); |
|
| 517 | + remove_filter( |
|
| 518 | + 'the_content', |
|
| 519 | + array('EED_Events_Archive', 'event_details'), |
|
| 520 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 521 | + ); |
|
| 522 | + remove_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1); |
|
| 523 | + //now add additional content depending on whether event is using the_excerpt() or the_content() |
|
| 524 | + EED_Events_Archive::_add_additional_excerpt_filters(); |
|
| 525 | + EED_Events_Archive::_add_additional_content_filters(); |
|
| 526 | + do_action('AHEE__EED_Events_Archive__use_filterable_display_order__after_add_filters'); |
|
| 527 | + // now load our template |
|
| 528 | + $content = EEH_Template::locate_template('content-espresso_events-details.php'); |
|
| 529 | + // re-add our main filters (or else the next event won't have them) |
|
| 530 | + add_filter( |
|
| 531 | + 'the_excerpt', |
|
| 532 | + array('EED_Events_Archive', 'event_details'), |
|
| 533 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 534 | + ); |
|
| 535 | + add_filter( |
|
| 536 | + 'the_content', |
|
| 537 | + array('EED_Events_Archive', 'event_details'), |
|
| 538 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 539 | + ); |
|
| 540 | + add_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1, 1); |
|
| 541 | + // but remove the other filters so that they don't get applied to the next post |
|
| 542 | + EED_Events_Archive::_remove_additional_events_archive_filters(); |
|
| 543 | + do_action('AHEE__EED_Events_Archive__use_filterable_display_order__after_remove_filters'); |
|
| 544 | + // we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt) |
|
| 545 | + //return ! empty( $template ) ? $template : $content; |
|
| 546 | + return $content; |
|
| 547 | + } |
|
| 548 | + |
|
| 549 | + |
|
| 550 | + |
|
| 551 | + /** |
|
| 552 | + * event_datetimes - adds datetimes ABOVE content |
|
| 553 | + * |
|
| 554 | + * @access public |
|
| 555 | + * @param string $content |
|
| 556 | + * @return string |
|
| 557 | + */ |
|
| 558 | + public static function event_datetimes($content) |
|
| 559 | + { |
|
| 560 | + if (post_password_required()) { |
|
| 561 | + return $content; |
|
| 562 | + } |
|
| 563 | + return EEH_Template::locate_template('content-espresso_events-datetimes.php') . $content; |
|
| 564 | + } |
|
| 565 | + |
|
| 566 | + |
|
| 567 | + |
|
| 568 | + /** |
|
| 569 | + * event_tickets - adds tickets ABOVE content (which includes datetimes) |
|
| 570 | + * |
|
| 571 | + * @access public |
|
| 572 | + * @param string $content |
|
| 573 | + * @return string |
|
| 574 | + */ |
|
| 575 | + public static function event_tickets($content) |
|
| 576 | + { |
|
| 577 | + if (post_password_required()) { |
|
| 578 | + return $content; |
|
| 579 | + } |
|
| 580 | + return EEH_Template::locate_template('content-espresso_events-tickets.php') . $content; |
|
| 581 | + } |
|
| 582 | + |
|
| 583 | + |
|
| 584 | + |
|
| 585 | + /** |
|
| 586 | + * event_venues - adds venues BELOW content |
|
| 587 | + * |
|
| 588 | + * @access public |
|
| 589 | + * @param string $content |
|
| 590 | + * @return string |
|
| 591 | + */ |
|
| 592 | + public static function event_venue($content) |
|
| 593 | + { |
|
| 594 | + return EED_Events_Archive::event_venues($content); |
|
| 595 | + } |
|
| 596 | + |
|
| 597 | + |
|
| 598 | + |
|
| 599 | + /** |
|
| 600 | + * event_venues - adds venues BELOW content |
|
| 601 | + * |
|
| 602 | + * @access public |
|
| 603 | + * @param string $content |
|
| 604 | + * @return string |
|
| 605 | + */ |
|
| 606 | + public static function event_venues($content) |
|
| 607 | + { |
|
| 608 | + if (post_password_required()) { |
|
| 609 | + return $content; |
|
| 610 | + } |
|
| 611 | + return $content . EEH_Template::locate_template('content-espresso_events-venues.php'); |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + |
|
| 615 | + |
|
| 616 | + /** |
|
| 617 | + * _add_additional_content_filters |
|
| 618 | + * |
|
| 619 | + * @access private |
|
| 620 | + * @return void |
|
| 621 | + */ |
|
| 622 | + private static function _add_additional_excerpt_filters() |
|
| 623 | + { |
|
| 624 | + add_filter( |
|
| 625 | + 'the_excerpt', |
|
| 626 | + array('EED_Events_Archive', 'event_datetimes'), |
|
| 627 | + EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
| 628 | + ); |
|
| 629 | + add_filter( |
|
| 630 | + 'the_excerpt', |
|
| 631 | + array('EED_Events_Archive', 'event_tickets'), |
|
| 632 | + EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
| 633 | + ); |
|
| 634 | + add_filter( |
|
| 635 | + 'the_excerpt', |
|
| 636 | + array('EED_Events_Archive', 'event_venues'), |
|
| 637 | + EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
| 638 | + ); |
|
| 639 | + } |
|
| 640 | + |
|
| 641 | + |
|
| 642 | + |
|
| 643 | + /** |
|
| 644 | + * _add_additional_content_filters |
|
| 645 | + * |
|
| 646 | + * @access private |
|
| 647 | + * @return void |
|
| 648 | + */ |
|
| 649 | + private static function _add_additional_content_filters() |
|
| 650 | + { |
|
| 651 | + add_filter( |
|
| 652 | + 'the_content', |
|
| 653 | + array('EED_Events_Archive', 'event_datetimes'), |
|
| 654 | + EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
| 655 | + ); |
|
| 656 | + add_filter( |
|
| 657 | + 'the_content', |
|
| 658 | + array('EED_Events_Archive', 'event_tickets'), |
|
| 659 | + EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
| 660 | + ); |
|
| 661 | + add_filter( |
|
| 662 | + 'the_content', |
|
| 663 | + array('EED_Events_Archive', 'event_venues'), |
|
| 664 | + EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
| 665 | + ); |
|
| 666 | + } |
|
| 667 | + |
|
| 668 | + |
|
| 669 | + |
|
| 670 | + /** |
|
| 671 | + * _remove_additional_events_archive_filters |
|
| 672 | + * |
|
| 673 | + * @access private |
|
| 674 | + * @return void |
|
| 675 | + */ |
|
| 676 | + private static function _remove_additional_events_archive_filters() |
|
| 677 | + { |
|
| 678 | + remove_filter( |
|
| 679 | + 'the_excerpt', |
|
| 680 | + array('EED_Events_Archive', 'event_datetimes'), |
|
| 681 | + EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
| 682 | + ); |
|
| 683 | + remove_filter( |
|
| 684 | + 'the_excerpt', |
|
| 685 | + array('EED_Events_Archive', 'event_tickets'), |
|
| 686 | + EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
| 687 | + ); |
|
| 688 | + remove_filter( |
|
| 689 | + 'the_excerpt', |
|
| 690 | + array('EED_Events_Archive', 'event_venues'), |
|
| 691 | + EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
| 692 | + ); |
|
| 693 | + remove_filter( |
|
| 694 | + 'the_content', |
|
| 695 | + array('EED_Events_Archive', 'event_datetimes'), |
|
| 696 | + EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
| 697 | + ); |
|
| 698 | + remove_filter( |
|
| 699 | + 'the_content', |
|
| 700 | + array('EED_Events_Archive', 'event_tickets'), |
|
| 701 | + EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
| 702 | + ); |
|
| 703 | + remove_filter( |
|
| 704 | + 'the_content', |
|
| 705 | + array('EED_Events_Archive', 'event_venues'), |
|
| 706 | + EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
| 707 | + ); |
|
| 708 | + } |
|
| 709 | + |
|
| 710 | + |
|
| 711 | + |
|
| 712 | + /** |
|
| 713 | + * remove_all_events_archive_filters |
|
| 714 | + * |
|
| 715 | + * @access public |
|
| 716 | + * @return void |
|
| 717 | + */ |
|
| 718 | + public static function remove_all_events_archive_filters() |
|
| 719 | + { |
|
| 720 | + //remove_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1 ); |
|
| 721 | + remove_filter('the_title', array('EED_Events_Archive', 'the_title'), 1); |
|
| 722 | + remove_filter( |
|
| 723 | + 'the_excerpt', |
|
| 724 | + array('EED_Events_Archive', 'event_details'), |
|
| 725 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 726 | + ); |
|
| 727 | + remove_filter( |
|
| 728 | + 'the_excerpt', |
|
| 729 | + array('EED_Events_Archive', 'event_datetimes'), |
|
| 730 | + EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
| 731 | + ); |
|
| 732 | + remove_filter( |
|
| 733 | + 'the_excerpt', |
|
| 734 | + array('EED_Events_Archive', 'event_tickets'), |
|
| 735 | + EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
| 736 | + ); |
|
| 737 | + remove_filter( |
|
| 738 | + 'the_excerpt', |
|
| 739 | + array('EED_Events_Archive', 'event_venues'), |
|
| 740 | + EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
| 741 | + ); |
|
| 742 | + remove_filter( |
|
| 743 | + 'the_content', |
|
| 744 | + array('EED_Events_Archive', 'event_details'), |
|
| 745 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 746 | + ); |
|
| 747 | + remove_filter( |
|
| 748 | + 'the_content', |
|
| 749 | + array('EED_Events_Archive', 'event_datetimes'), |
|
| 750 | + EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
| 751 | + ); |
|
| 752 | + remove_filter( |
|
| 753 | + 'the_content', |
|
| 754 | + array('EED_Events_Archive', 'event_tickets'), |
|
| 755 | + EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
| 756 | + ); |
|
| 757 | + remove_filter( |
|
| 758 | + 'the_content', |
|
| 759 | + array('EED_Events_Archive', 'event_venues'), |
|
| 760 | + EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
| 761 | + ); |
|
| 762 | + // don't display entry meta because the existing theme will take care of that |
|
| 763 | + remove_filter( |
|
| 764 | + 'FHEE__content_espresso_events_details_template__display_entry_meta', |
|
| 765 | + '__return_false' |
|
| 766 | + ); |
|
| 767 | + } |
|
| 768 | + |
|
| 769 | + |
|
| 770 | + |
|
| 771 | + /** |
|
| 772 | + * load_event_list_assets |
|
| 773 | + * |
|
| 774 | + * @access public |
|
| 775 | + * @return void |
|
| 776 | + */ |
|
| 777 | + public function load_event_list_assets() |
|
| 778 | + { |
|
| 779 | + do_action('AHEE__EED_Events_Archive__before_load_assets'); |
|
| 780 | + add_filter('FHEE_load_EE_Session', '__return_true'); |
|
| 781 | + add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true'); |
|
| 782 | + add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10); |
|
| 783 | + if (EE_Registry::instance()->CFG->map_settings->use_google_maps) { |
|
| 784 | + add_action('wp_enqueue_scripts', array('EEH_Maps', 'espresso_google_map_js'), 11); |
|
| 785 | + } |
|
| 786 | + } |
|
| 787 | + |
|
| 788 | + |
|
| 789 | + |
|
| 790 | + /** |
|
| 791 | + * wp_enqueue_scripts |
|
| 792 | + * |
|
| 793 | + * @access public |
|
| 794 | + * @return void |
|
| 795 | + */ |
|
| 796 | + public function wp_enqueue_scripts() |
|
| 797 | + { |
|
| 798 | + // get some style |
|
| 799 | + if (apply_filters('FHEE_enable_default_espresso_css', false)) { |
|
| 800 | + // first check uploads folder |
|
| 801 | + if (EEH_File::is_readable(get_stylesheet_directory() . $this->theme . DS . 'style.css')) { |
|
| 802 | + wp_register_style($this->theme, get_stylesheet_directory_uri() . $this->theme . DS . 'style.css', array('dashicons', 'espresso_default')); |
|
| 803 | + } else { |
|
| 804 | + } |
|
| 805 | + wp_enqueue_style($this->theme); |
|
| 806 | + } |
|
| 807 | + } |
|
| 808 | + |
|
| 809 | + |
|
| 810 | + |
|
| 811 | + /** |
|
| 812 | + * template_settings_form |
|
| 813 | + * |
|
| 814 | + * @access public |
|
| 815 | + * @static |
|
| 816 | + * @return string |
|
| 817 | + */ |
|
| 818 | + public static function template_settings_form() |
|
| 819 | + { |
|
| 820 | + $template_settings = EE_Registry::instance()->CFG->template_settings; |
|
| 821 | + $template_settings->EED_Events_Archive = isset($template_settings->EED_Events_Archive) ? $template_settings->EED_Events_Archive : new EE_Events_Archive_Config(); |
|
| 822 | + $template_settings->EED_Events_Archive = apply_filters('FHEE__EED_Events_Archive__template_settings_form__event_list_config', $template_settings->EED_Events_Archive); |
|
| 823 | + $events_archive_settings = array( |
|
| 824 | + 'display_status_banner' => 0, |
|
| 825 | + 'display_description' => 1, |
|
| 826 | + 'display_ticket_selector' => 0, |
|
| 827 | + 'display_datetimes' => 1, |
|
| 828 | + 'display_venue' => 0, |
|
| 829 | + 'display_expired_events' => 0, |
|
| 830 | + ); |
|
| 831 | + $events_archive_settings = array_merge($events_archive_settings, (array)$template_settings->EED_Events_Archive); |
|
| 832 | + EEH_Template::display_template(EVENTS_ARCHIVE_TEMPLATES_PATH . 'admin-event-list-settings.template.php', $events_archive_settings); |
|
| 833 | + } |
|
| 834 | + |
|
| 835 | + |
|
| 836 | + |
|
| 837 | + /** |
|
| 838 | + * update_template_settings |
|
| 839 | + * |
|
| 840 | + * @access public |
|
| 841 | + * @param EE_Template_Config $CFG |
|
| 842 | + * @param EE_Request_Handler $REQ |
|
| 843 | + * @return EE_Template_Config |
|
| 844 | + */ |
|
| 845 | + public static function update_template_settings($CFG, $REQ) |
|
| 846 | + { |
|
| 847 | + $CFG->EED_Events_Archive = new EE_Events_Archive_Config(); |
|
| 848 | + // unless we are resetting the config... |
|
| 849 | + if (! isset($REQ['EED_Events_Archive_reset_event_list_settings']) || absint($REQ['EED_Events_Archive_reset_event_list_settings']) !== 1) { |
|
| 850 | + $CFG->EED_Events_Archive->display_status_banner = isset($REQ['EED_Events_Archive_display_status_banner']) ? absint($REQ['EED_Events_Archive_display_status_banner']) : 0; |
|
| 851 | + $CFG->EED_Events_Archive->display_description = isset($REQ['EED_Events_Archive_display_description']) ? absint($REQ['EED_Events_Archive_display_description']) : 1; |
|
| 852 | + $CFG->EED_Events_Archive->display_ticket_selector = isset($REQ['EED_Events_Archive_display_ticket_selector']) ? absint($REQ['EED_Events_Archive_display_ticket_selector']) : 0; |
|
| 853 | + $CFG->EED_Events_Archive->display_datetimes = isset($REQ['EED_Events_Archive_display_datetimes']) ? absint($REQ['EED_Events_Archive_display_datetimes']) : 1; |
|
| 854 | + $CFG->EED_Events_Archive->display_venue = isset($REQ['EED_Events_Archive_display_venue']) ? absint($REQ['EED_Events_Archive_display_venue']) : 0; |
|
| 855 | + $CFG->EED_Events_Archive->display_expired_events = isset($REQ['EED_Events_Archive_display_expired_events']) ? absint($REQ['EED_Events_Archive_display_expired_events']) : 0; |
|
| 856 | + } |
|
| 857 | + return $CFG; |
|
| 858 | + } |
|
| 859 | + |
|
| 860 | + |
|
| 861 | + |
|
| 862 | + /** |
|
| 863 | + * event_list_css |
|
| 864 | + * |
|
| 865 | + * @access public |
|
| 866 | + * @param string $extra_class |
|
| 867 | + * @return string |
|
| 868 | + */ |
|
| 869 | + public static function event_list_css($extra_class = '') |
|
| 870 | + { |
|
| 871 | + $event_list_css = ! empty($extra_class) ? array($extra_class) : array(); |
|
| 872 | + $event_list_css[] = 'espresso-event-list-event'; |
|
| 873 | + return implode(' ', $event_list_css); |
|
| 874 | + } |
|
| 875 | + |
|
| 876 | + |
|
| 877 | + |
|
| 878 | + /** |
|
| 879 | + * event_categories |
|
| 880 | + * |
|
| 881 | + * @access public |
|
| 882 | + * @return array |
|
| 883 | + */ |
|
| 884 | + public static function event_categories() |
|
| 885 | + { |
|
| 886 | + return EE_Registry::instance()->load_model('Term')->get_all_ee_categories(); |
|
| 887 | + } |
|
| 888 | + |
|
| 889 | + |
|
| 890 | + |
|
| 891 | + /** |
|
| 892 | + * display_description |
|
| 893 | + * |
|
| 894 | + * @access public |
|
| 895 | + * @param $value |
|
| 896 | + * @return bool |
|
| 897 | + */ |
|
| 898 | + public static function display_description($value) |
|
| 899 | + { |
|
| 900 | + $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive; |
|
| 901 | + $display_description = isset($config->display_description) ? $config->display_description : 1; |
|
| 902 | + return $display_description === $value ? true : false; |
|
| 903 | + } |
|
| 904 | + |
|
| 905 | + |
|
| 906 | + |
|
| 907 | + /** |
|
| 908 | + * display_ticket_selector |
|
| 909 | + * |
|
| 910 | + * @access public |
|
| 911 | + * @return bool |
|
| 912 | + */ |
|
| 913 | + public static function display_ticket_selector() |
|
| 914 | + { |
|
| 915 | + $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive; |
|
| 916 | + return isset($config->display_ticket_selector) && $config->display_ticket_selector ? true : false; |
|
| 917 | + } |
|
| 918 | + |
|
| 919 | + |
|
| 920 | + |
|
| 921 | + /** |
|
| 922 | + * display_venue |
|
| 923 | + * |
|
| 924 | + * @access public |
|
| 925 | + * @return bool |
|
| 926 | + */ |
|
| 927 | + public static function display_venue() |
|
| 928 | + { |
|
| 929 | + $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive; |
|
| 930 | + return isset($config->display_venue) && $config->display_venue && EEH_Venue_View::venue_name() ? true : false; |
|
| 931 | + } |
|
| 932 | + |
|
| 933 | + |
|
| 934 | + |
|
| 935 | + /** |
|
| 936 | + * display_datetimes |
|
| 937 | + * |
|
| 938 | + * @access public |
|
| 939 | + * @return bool |
|
| 940 | + */ |
|
| 941 | + public static function display_datetimes() |
|
| 942 | + { |
|
| 943 | + $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive; |
|
| 944 | + return isset($config->display_datetimes) && $config->display_datetimes ? true : false; |
|
| 945 | + } |
|
| 946 | + |
|
| 947 | + |
|
| 948 | + |
|
| 949 | + /** |
|
| 950 | + * event_list_title |
|
| 951 | + * |
|
| 952 | + * @access public |
|
| 953 | + * @return string |
|
| 954 | + */ |
|
| 955 | + public static function event_list_title() |
|
| 956 | + { |
|
| 957 | + return apply_filters('FHEE__archive_espresso_events_template__upcoming_events_h1', __('Upcoming Events', 'event_espresso')); |
|
| 958 | + } |
|
| 959 | + |
|
| 960 | + |
|
| 961 | + // GRAVEYARD |
|
| 962 | + |
|
| 963 | + |
|
| 964 | + |
|
| 965 | + /** |
|
| 966 | + * @since 4.4.0 |
|
| 967 | + */ |
|
| 968 | + public static function _doing_it_wrong_notice($function = '') |
|
| 969 | + { |
|
| 970 | + EE_Error::doing_it_wrong( |
|
| 971 | + __FUNCTION__, |
|
| 972 | + sprintf( |
|
| 973 | + __('EED_Events_Archive::%1$s was moved to EEH_Event_Query::%1$s:%2$sPlease update your existing code because the method it calls will be removed in version %3$s', 'event_espresso'), |
|
| 974 | + $function, |
|
| 975 | + '<br />', |
|
| 976 | + '4.6.0' |
|
| 977 | + ), |
|
| 978 | + '4.4.0' |
|
| 979 | + ); |
|
| 980 | + } |
|
| 981 | + |
|
| 982 | + |
|
| 983 | + |
|
| 984 | + /** |
|
| 985 | + * @deprecated |
|
| 986 | + * @since 4.4.0 |
|
| 987 | + */ |
|
| 988 | + public function get_post_data() |
|
| 989 | + { |
|
| 990 | + EEH_Event_Query::set_query_params(); |
|
| 991 | + } |
|
| 992 | + |
|
| 993 | + |
|
| 994 | + |
|
| 995 | + /** |
|
| 996 | + * @deprecated |
|
| 997 | + * @since 4.4.0 |
|
| 998 | + */ |
|
| 999 | + public function posts_fields($SQL, WP_Query $wp_query) |
|
| 1000 | + { |
|
| 1001 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1002 | + return EEH_Event_Query::posts_fields($SQL, $wp_query); |
|
| 1003 | + } |
|
| 1004 | 1004 | |
| 1005 | - |
|
| 1006 | - |
|
| 1007 | - /** |
|
| 1008 | - * @deprecated |
|
| 1009 | - * @since 4.4.0 |
|
| 1010 | - */ |
|
| 1011 | - public static function posts_fields_sql_for_orderby($orderby_params = array()) |
|
| 1012 | - { |
|
| 1013 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1014 | - return EEH_Event_Query::posts_fields_sql_for_orderby($orderby_params); |
|
| 1015 | - } |
|
| 1005 | + |
|
| 1006 | + |
|
| 1007 | + /** |
|
| 1008 | + * @deprecated |
|
| 1009 | + * @since 4.4.0 |
|
| 1010 | + */ |
|
| 1011 | + public static function posts_fields_sql_for_orderby($orderby_params = array()) |
|
| 1012 | + { |
|
| 1013 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1014 | + return EEH_Event_Query::posts_fields_sql_for_orderby($orderby_params); |
|
| 1015 | + } |
|
| 1016 | 1016 | |
| 1017 | 1017 | |
| 1018 | 1018 | |
| 1019 | - /** |
|
| 1020 | - * @deprecated |
|
| 1021 | - * @since 4.4.0 |
|
| 1022 | - */ |
|
| 1023 | - public function posts_join($SQL, WP_Query $wp_query) |
|
| 1024 | - { |
|
| 1025 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1026 | - return EEH_Event_Query::posts_join($SQL, $wp_query); |
|
| 1027 | - } |
|
| 1019 | + /** |
|
| 1020 | + * @deprecated |
|
| 1021 | + * @since 4.4.0 |
|
| 1022 | + */ |
|
| 1023 | + public function posts_join($SQL, WP_Query $wp_query) |
|
| 1024 | + { |
|
| 1025 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1026 | + return EEH_Event_Query::posts_join($SQL, $wp_query); |
|
| 1027 | + } |
|
| 1028 | 1028 | |
| 1029 | 1029 | |
| 1030 | 1030 | |
| 1031 | - /** |
|
| 1032 | - * @deprecated |
|
| 1033 | - * @since 4.4.0 |
|
| 1034 | - */ |
|
| 1035 | - public static function posts_join_sql_for_terms($join_terms = null) |
|
| 1036 | - { |
|
| 1037 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1038 | - return EEH_Event_Query::posts_join_sql_for_terms($join_terms); |
|
| 1039 | - } |
|
| 1031 | + /** |
|
| 1032 | + * @deprecated |
|
| 1033 | + * @since 4.4.0 |
|
| 1034 | + */ |
|
| 1035 | + public static function posts_join_sql_for_terms($join_terms = null) |
|
| 1036 | + { |
|
| 1037 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1038 | + return EEH_Event_Query::posts_join_sql_for_terms($join_terms); |
|
| 1039 | + } |
|
| 1040 | 1040 | |
| 1041 | 1041 | |
| 1042 | 1042 | |
| 1043 | - /** |
|
| 1044 | - * @deprecated |
|
| 1045 | - * @since 4.4.0 |
|
| 1046 | - */ |
|
| 1047 | - public static function posts_join_for_orderby($orderby_params = array()) |
|
| 1048 | - { |
|
| 1049 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1050 | - return EEH_Event_Query::posts_join_for_orderby($orderby_params); |
|
| 1051 | - } |
|
| 1043 | + /** |
|
| 1044 | + * @deprecated |
|
| 1045 | + * @since 4.4.0 |
|
| 1046 | + */ |
|
| 1047 | + public static function posts_join_for_orderby($orderby_params = array()) |
|
| 1048 | + { |
|
| 1049 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1050 | + return EEH_Event_Query::posts_join_for_orderby($orderby_params); |
|
| 1051 | + } |
|
| 1052 | 1052 | |
| 1053 | 1053 | |
| 1054 | 1054 | |
| 1055 | - /** |
|
| 1056 | - * @deprecated |
|
| 1057 | - * @since 4.4.0 |
|
| 1058 | - */ |
|
| 1059 | - public function posts_where($SQL, WP_Query $wp_query) |
|
| 1060 | - { |
|
| 1061 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1062 | - return EEH_Event_Query::posts_where($SQL, $wp_query); |
|
| 1063 | - } |
|
| 1055 | + /** |
|
| 1056 | + * @deprecated |
|
| 1057 | + * @since 4.4.0 |
|
| 1058 | + */ |
|
| 1059 | + public function posts_where($SQL, WP_Query $wp_query) |
|
| 1060 | + { |
|
| 1061 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1062 | + return EEH_Event_Query::posts_where($SQL, $wp_query); |
|
| 1063 | + } |
|
| 1064 | 1064 | |
| 1065 | - |
|
| 1066 | - |
|
| 1067 | - /** |
|
| 1068 | - * @deprecated |
|
| 1069 | - * @since 4.4.0 |
|
| 1070 | - */ |
|
| 1071 | - public static function posts_where_sql_for_show_expired($show_expired = false) |
|
| 1072 | - { |
|
| 1073 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1074 | - return EEH_Event_Query::posts_where_sql_for_show_expired($show_expired); |
|
| 1075 | - } |
|
| 1065 | + |
|
| 1066 | + |
|
| 1067 | + /** |
|
| 1068 | + * @deprecated |
|
| 1069 | + * @since 4.4.0 |
|
| 1070 | + */ |
|
| 1071 | + public static function posts_where_sql_for_show_expired($show_expired = false) |
|
| 1072 | + { |
|
| 1073 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1074 | + return EEH_Event_Query::posts_where_sql_for_show_expired($show_expired); |
|
| 1075 | + } |
|
| 1076 | 1076 | |
| 1077 | 1077 | |
| 1078 | 1078 | |
| 1079 | - /** |
|
| 1080 | - * @deprecated |
|
| 1081 | - * @since 4.4.0 |
|
| 1082 | - */ |
|
| 1083 | - public static function posts_where_sql_for_event_category_slug($event_category_slug = null) |
|
| 1084 | - { |
|
| 1085 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1086 | - return EEH_Event_Query::posts_where_sql_for_event_category_slug($event_category_slug); |
|
| 1087 | - } |
|
| 1079 | + /** |
|
| 1080 | + * @deprecated |
|
| 1081 | + * @since 4.4.0 |
|
| 1082 | + */ |
|
| 1083 | + public static function posts_where_sql_for_event_category_slug($event_category_slug = null) |
|
| 1084 | + { |
|
| 1085 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1086 | + return EEH_Event_Query::posts_where_sql_for_event_category_slug($event_category_slug); |
|
| 1087 | + } |
|
| 1088 | 1088 | |
| 1089 | 1089 | |
| 1090 | 1090 | |
| 1091 | - /** |
|
| 1092 | - * @deprecated |
|
| 1093 | - * @since 4.4.0 |
|
| 1094 | - */ |
|
| 1095 | - public static function posts_where_sql_for_event_list_month($month = null) |
|
| 1096 | - { |
|
| 1097 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1098 | - return EEH_Event_Query::posts_where_sql_for_event_list_month($month); |
|
| 1099 | - } |
|
| 1091 | + /** |
|
| 1092 | + * @deprecated |
|
| 1093 | + * @since 4.4.0 |
|
| 1094 | + */ |
|
| 1095 | + public static function posts_where_sql_for_event_list_month($month = null) |
|
| 1096 | + { |
|
| 1097 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1098 | + return EEH_Event_Query::posts_where_sql_for_event_list_month($month); |
|
| 1099 | + } |
|
| 1100 | 1100 | |
| 1101 | 1101 | |
| 1102 | 1102 | |
| 1103 | - /** |
|
| 1104 | - * @deprecated |
|
| 1105 | - * @since 4.4.0 |
|
| 1106 | - */ |
|
| 1107 | - public function posts_orderby($SQL, WP_Query $wp_query) |
|
| 1108 | - { |
|
| 1109 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1110 | - return EEH_Event_Query::posts_orderby($SQL, $wp_query); |
|
| 1111 | - } |
|
| 1103 | + /** |
|
| 1104 | + * @deprecated |
|
| 1105 | + * @since 4.4.0 |
|
| 1106 | + */ |
|
| 1107 | + public function posts_orderby($SQL, WP_Query $wp_query) |
|
| 1108 | + { |
|
| 1109 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1110 | + return EEH_Event_Query::posts_orderby($SQL, $wp_query); |
|
| 1111 | + } |
|
| 1112 | 1112 | |
| 1113 | 1113 | |
| 1114 | 1114 | |
| 1115 | - /** |
|
| 1116 | - * @deprecated |
|
| 1117 | - * @since 4.4.0 |
|
| 1118 | - */ |
|
| 1119 | - public static function posts_orderby_sql($orderby_params = array(), $sort = 'ASC') |
|
| 1120 | - { |
|
| 1121 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1122 | - return EEH_Event_Query::posts_orderby_sql($orderby_params, $sort); |
|
| 1123 | - } |
|
| 1115 | + /** |
|
| 1116 | + * @deprecated |
|
| 1117 | + * @since 4.4.0 |
|
| 1118 | + */ |
|
| 1119 | + public static function posts_orderby_sql($orderby_params = array(), $sort = 'ASC') |
|
| 1120 | + { |
|
| 1121 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1122 | + return EEH_Event_Query::posts_orderby_sql($orderby_params, $sort); |
|
| 1123 | + } |
|
| 1124 | 1124 | |
| 1125 | 1125 | |
| 1126 | 1126 | |
@@ -1133,9 +1133,9 @@ discard block |
||
| 1133 | 1133 | */ |
| 1134 | 1134 | function espresso_get_event_list_ID() |
| 1135 | 1135 | { |
| 1136 | - EED_Events_Archive::$espresso_event_list_ID++; |
|
| 1137 | - EED_Events_Archive::$espresso_grid_event_lists[] = EED_Events_Archive::$espresso_event_list_ID; |
|
| 1138 | - return EED_Events_Archive::$espresso_event_list_ID; |
|
| 1136 | + EED_Events_Archive::$espresso_event_list_ID++; |
|
| 1137 | + EED_Events_Archive::$espresso_grid_event_lists[] = EED_Events_Archive::$espresso_event_list_ID; |
|
| 1138 | + return EED_Events_Archive::$espresso_event_list_ID; |
|
| 1139 | 1139 | } |
| 1140 | 1140 | |
| 1141 | 1141 | /** |
@@ -1143,7 +1143,7 @@ discard block |
||
| 1143 | 1143 | */ |
| 1144 | 1144 | function espresso_event_list_title() |
| 1145 | 1145 | { |
| 1146 | - return EED_Events_Archive::event_list_title(); |
|
| 1146 | + return EED_Events_Archive::event_list_title(); |
|
| 1147 | 1147 | } |
| 1148 | 1148 | |
| 1149 | 1149 | /** |
@@ -1152,7 +1152,7 @@ discard block |
||
| 1152 | 1152 | */ |
| 1153 | 1153 | function espresso_event_list_css($extra_class = '') |
| 1154 | 1154 | { |
| 1155 | - return EED_Events_Archive::event_list_css($extra_class); |
|
| 1155 | + return EED_Events_Archive::event_list_css($extra_class); |
|
| 1156 | 1156 | } |
| 1157 | 1157 | |
| 1158 | 1158 | /** |
@@ -1160,7 +1160,7 @@ discard block |
||
| 1160 | 1160 | */ |
| 1161 | 1161 | function espresso_get_event_categories() |
| 1162 | 1162 | { |
| 1163 | - return EED_Events_Archive::event_categories(); |
|
| 1163 | + return EED_Events_Archive::event_categories(); |
|
| 1164 | 1164 | } |
| 1165 | 1165 | |
| 1166 | 1166 | /** |
@@ -1168,7 +1168,7 @@ discard block |
||
| 1168 | 1168 | */ |
| 1169 | 1169 | function espresso_display_full_description_in_event_list() |
| 1170 | 1170 | { |
| 1171 | - return EED_Events_Archive::display_description(2); |
|
| 1171 | + return EED_Events_Archive::display_description(2); |
|
| 1172 | 1172 | } |
| 1173 | 1173 | |
| 1174 | 1174 | /** |
@@ -1176,7 +1176,7 @@ discard block |
||
| 1176 | 1176 | */ |
| 1177 | 1177 | function espresso_display_excerpt_in_event_list() |
| 1178 | 1178 | { |
| 1179 | - return EED_Events_Archive::display_description(1); |
|
| 1179 | + return EED_Events_Archive::display_description(1); |
|
| 1180 | 1180 | } |
| 1181 | 1181 | |
| 1182 | 1182 | /** |
@@ -1184,7 +1184,7 @@ discard block |
||
| 1184 | 1184 | */ |
| 1185 | 1185 | function espresso_display_ticket_selector_in_event_list() |
| 1186 | 1186 | { |
| 1187 | - return EED_Events_Archive::display_ticket_selector(); |
|
| 1187 | + return EED_Events_Archive::display_ticket_selector(); |
|
| 1188 | 1188 | } |
| 1189 | 1189 | |
| 1190 | 1190 | /** |
@@ -1192,7 +1192,7 @@ discard block |
||
| 1192 | 1192 | */ |
| 1193 | 1193 | function espresso_display_venue_in_event_list() |
| 1194 | 1194 | { |
| 1195 | - return EED_Events_Archive::display_venue(); |
|
| 1195 | + return EED_Events_Archive::display_venue(); |
|
| 1196 | 1196 | } |
| 1197 | 1197 | |
| 1198 | 1198 | /** |
@@ -1200,7 +1200,7 @@ discard block |
||
| 1200 | 1200 | */ |
| 1201 | 1201 | function espresso_display_datetimes_in_event_list() |
| 1202 | 1202 | { |
| 1203 | - return EED_Events_Archive::display_datetimes(); |
|
| 1203 | + return EED_Events_Archive::display_datetimes(); |
|
| 1204 | 1204 | } |
| 1205 | 1205 | |
| 1206 | 1206 | |
@@ -122,8 +122,8 @@ discard block |
||
| 122 | 122 | */ |
| 123 | 123 | public static function set_definitions() |
| 124 | 124 | { |
| 125 | - define('EVENTS_ARCHIVE_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
| 126 | - define('EVENTS_ARCHIVE_TEMPLATES_PATH', str_replace('\\', DS, plugin_dir_path(__FILE__)) . 'templates' . DS); |
|
| 125 | + define('EVENTS_ARCHIVE_ASSETS_URL', plugin_dir_url(__FILE__).'assets'.DS); |
|
| 126 | + define('EVENTS_ARCHIVE_TEMPLATES_PATH', str_replace('\\', DS, plugin_dir_path(__FILE__)).'templates'.DS); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | */ |
| 146 | 146 | public static function get_iframe_embed_button() |
| 147 | 147 | { |
| 148 | - if (! self::$_iframe_embed_button instanceof EventListIframeEmbedButton) { |
|
| 148 | + if ( ! self::$_iframe_embed_button instanceof EventListIframeEmbedButton) { |
|
| 149 | 149 | self::$_iframe_embed_button = new EventListIframeEmbedButton(); |
| 150 | 150 | } |
| 151 | 151 | return self::$_iframe_embed_button; |
@@ -230,10 +230,10 @@ discard block |
||
| 230 | 230 | EEH_Event_Query::add_query_filters(); |
| 231 | 231 | // set params that will get used by the filters |
| 232 | 232 | EEH_Event_Query::set_query_params( |
| 233 | - '', // month |
|
| 234 | - '', // category |
|
| 235 | - $config->display_expired_events, // show_expired |
|
| 236 | - 'start_date', // orderby |
|
| 233 | + '', // month |
|
| 234 | + '', // category |
|
| 235 | + $config->display_expired_events, // show_expired |
|
| 236 | + 'start_date', // orderby |
|
| 237 | 237 | 'ASC' // sort |
| 238 | 238 | ); |
| 239 | 239 | // check what template is loaded |
@@ -304,7 +304,7 @@ discard block |
||
| 304 | 304 | public function template_include($template = '') |
| 305 | 305 | { |
| 306 | 306 | // don't add content filter for dedicated EE child themes or private posts |
| 307 | - if (! EEH_Template::is_espresso_theme()) { |
|
| 307 | + if ( ! EEH_Template::is_espresso_theme()) { |
|
| 308 | 308 | /** @type EE_Events_Archive_Config $config */ |
| 309 | 309 | $config = $this->config(); |
| 310 | 310 | // add status banner ? |
@@ -405,7 +405,7 @@ discard block |
||
| 405 | 405 | { |
| 406 | 406 | global $post; |
| 407 | 407 | if ($post instanceof WP_Post) { |
| 408 | - return in_the_loop() && $post->ID == $id ? espresso_event_status_banner($post->ID) . $title : $title; |
|
| 408 | + return in_the_loop() && $post->ID == $id ? espresso_event_status_banner($post->ID).$title : $title; |
|
| 409 | 409 | } |
| 410 | 410 | return $title; |
| 411 | 411 | } |
@@ -560,7 +560,7 @@ discard block |
||
| 560 | 560 | if (post_password_required()) { |
| 561 | 561 | return $content; |
| 562 | 562 | } |
| 563 | - return EEH_Template::locate_template('content-espresso_events-datetimes.php') . $content; |
|
| 563 | + return EEH_Template::locate_template('content-espresso_events-datetimes.php').$content; |
|
| 564 | 564 | } |
| 565 | 565 | |
| 566 | 566 | |
@@ -577,7 +577,7 @@ discard block |
||
| 577 | 577 | if (post_password_required()) { |
| 578 | 578 | return $content; |
| 579 | 579 | } |
| 580 | - return EEH_Template::locate_template('content-espresso_events-tickets.php') . $content; |
|
| 580 | + return EEH_Template::locate_template('content-espresso_events-tickets.php').$content; |
|
| 581 | 581 | } |
| 582 | 582 | |
| 583 | 583 | |
@@ -608,7 +608,7 @@ discard block |
||
| 608 | 608 | if (post_password_required()) { |
| 609 | 609 | return $content; |
| 610 | 610 | } |
| 611 | - return $content . EEH_Template::locate_template('content-espresso_events-venues.php'); |
|
| 611 | + return $content.EEH_Template::locate_template('content-espresso_events-venues.php'); |
|
| 612 | 612 | } |
| 613 | 613 | |
| 614 | 614 | |
@@ -798,8 +798,8 @@ discard block |
||
| 798 | 798 | // get some style |
| 799 | 799 | if (apply_filters('FHEE_enable_default_espresso_css', false)) { |
| 800 | 800 | // first check uploads folder |
| 801 | - if (EEH_File::is_readable(get_stylesheet_directory() . $this->theme . DS . 'style.css')) { |
|
| 802 | - wp_register_style($this->theme, get_stylesheet_directory_uri() . $this->theme . DS . 'style.css', array('dashicons', 'espresso_default')); |
|
| 801 | + if (EEH_File::is_readable(get_stylesheet_directory().$this->theme.DS.'style.css')) { |
|
| 802 | + wp_register_style($this->theme, get_stylesheet_directory_uri().$this->theme.DS.'style.css', array('dashicons', 'espresso_default')); |
|
| 803 | 803 | } else { |
| 804 | 804 | } |
| 805 | 805 | wp_enqueue_style($this->theme); |
@@ -828,8 +828,8 @@ discard block |
||
| 828 | 828 | 'display_venue' => 0, |
| 829 | 829 | 'display_expired_events' => 0, |
| 830 | 830 | ); |
| 831 | - $events_archive_settings = array_merge($events_archive_settings, (array)$template_settings->EED_Events_Archive); |
|
| 832 | - EEH_Template::display_template(EVENTS_ARCHIVE_TEMPLATES_PATH . 'admin-event-list-settings.template.php', $events_archive_settings); |
|
| 831 | + $events_archive_settings = array_merge($events_archive_settings, (array) $template_settings->EED_Events_Archive); |
|
| 832 | + EEH_Template::display_template(EVENTS_ARCHIVE_TEMPLATES_PATH.'admin-event-list-settings.template.php', $events_archive_settings); |
|
| 833 | 833 | } |
| 834 | 834 | |
| 835 | 835 | |
@@ -846,7 +846,7 @@ discard block |
||
| 846 | 846 | { |
| 847 | 847 | $CFG->EED_Events_Archive = new EE_Events_Archive_Config(); |
| 848 | 848 | // unless we are resetting the config... |
| 849 | - if (! isset($REQ['EED_Events_Archive_reset_event_list_settings']) || absint($REQ['EED_Events_Archive_reset_event_list_settings']) !== 1) { |
|
| 849 | + if ( ! isset($REQ['EED_Events_Archive_reset_event_list_settings']) || absint($REQ['EED_Events_Archive_reset_event_list_settings']) !== 1) { |
|
| 850 | 850 | $CFG->EED_Events_Archive->display_status_banner = isset($REQ['EED_Events_Archive_display_status_banner']) ? absint($REQ['EED_Events_Archive_display_status_banner']) : 0; |
| 851 | 851 | $CFG->EED_Events_Archive->display_description = isset($REQ['EED_Events_Archive_display_description']) ? absint($REQ['EED_Events_Archive_display_description']) : 1; |
| 852 | 852 | $CFG->EED_Events_Archive->display_ticket_selector = isset($REQ['EED_Events_Archive_display_ticket_selector']) ? absint($REQ['EED_Events_Archive_display_ticket_selector']) : 0; |
@@ -18,1001 +18,1001 @@ discard block |
||
| 18 | 18 | final class EE_Capabilities extends EE_Base |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * the name of the wp option used to store caps previously initialized |
|
| 23 | - */ |
|
| 24 | - const option_name = 'ee_caps_initialized'; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * instance of EE_Capabilities object |
|
| 28 | - * |
|
| 29 | - * @var EE_Capabilities |
|
| 30 | - */ |
|
| 31 | - private static $_instance; |
|
| 32 | - |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * This is a map of caps that correspond to a default WP_Role. |
|
| 36 | - * Array is indexed by Role and values are ee capabilities. |
|
| 37 | - * |
|
| 38 | - * @since 4.5.0 |
|
| 39 | - * |
|
| 40 | - * @var array |
|
| 41 | - */ |
|
| 42 | - private $capabilities_map = array(); |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * This used to hold an array of EE_Meta_Capability_Map objects |
|
| 46 | - * that define the granular capabilities mapped to for a user depending on context. |
|
| 47 | - * |
|
| 48 | - * @var EE_Meta_Capability_Map[] |
|
| 49 | - */ |
|
| 50 | - private $_meta_caps = array(); |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * The internal $capabilities_map needs to be initialized before it can be used. |
|
| 54 | - * This flag tracks whether that has happened or not. |
|
| 55 | - * But for this to work, we need three states to indicate: |
|
| 56 | - * initialization has not occurred at all |
|
| 57 | - * initialization has started but is not complete |
|
| 58 | - * initialization is complete |
|
| 59 | - * The reason this is needed is because the addCaps() method |
|
| 60 | - * normally requires the $capabilities_map to be initialized, |
|
| 61 | - * but is also used during the initialization process. |
|
| 62 | - * So: |
|
| 63 | - * If initialized === null, init_caps() will be called before any other methods will run. |
|
| 64 | - * If initialized === false, then init_caps() is in the process of running it's logic. |
|
| 65 | - * If initialized === true, then init_caps() has completed the initialization process. |
|
| 66 | - * |
|
| 67 | - * @var boolean|null $initialized |
|
| 68 | - */ |
|
| 69 | - private $initialized; |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @var boolean $reset |
|
| 73 | - */ |
|
| 74 | - private $reset = false; |
|
| 75 | - |
|
| 76 | - |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * singleton method used to instantiate class object |
|
| 80 | - * |
|
| 81 | - * @since 4.5.0 |
|
| 82 | - * |
|
| 83 | - * @return EE_Capabilities |
|
| 84 | - */ |
|
| 85 | - public static function instance() |
|
| 86 | - { |
|
| 87 | - //check if instantiated, and if not do so. |
|
| 88 | - if (! self::$_instance instanceof EE_Capabilities) { |
|
| 89 | - self::$_instance = new self(); |
|
| 90 | - } |
|
| 91 | - return self::$_instance; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * private constructor |
|
| 98 | - * |
|
| 99 | - * @since 4.5.0 |
|
| 100 | - */ |
|
| 101 | - private function __construct() |
|
| 102 | - { |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * This delays the initialization of the capabilities class until EE_System core is loaded and ready. |
|
| 109 | - * |
|
| 110 | - * @param bool $reset allows for resetting the default capabilities saved on roles. Note that this doesn't |
|
| 111 | - * actually REMOVE any capabilities from existing roles, it just resaves defaults roles and |
|
| 112 | - * ensures that they are up to date. |
|
| 113 | - * |
|
| 114 | - * @since 4.5.0 |
|
| 115 | - * @return bool |
|
| 116 | - * @throws EE_Error |
|
| 117 | - */ |
|
| 118 | - public function init_caps($reset = false) |
|
| 119 | - { |
|
| 120 | - if(! EE_Maintenance_Mode::instance()->models_can_query()){ |
|
| 121 | - return false; |
|
| 122 | - } |
|
| 123 | - $this->reset = filter_var($reset, FILTER_VALIDATE_BOOLEAN); |
|
| 124 | - // if reset, then completely delete the cache option and clear the $capabilities_map property. |
|
| 125 | - if ($this->reset) { |
|
| 126 | - $this->initialized = null; |
|
| 127 | - $this->capabilities_map = array(); |
|
| 128 | - delete_option(self::option_name); |
|
| 129 | - } |
|
| 130 | - if ($this->initialized === null) { |
|
| 131 | - $this->initialized = false; |
|
| 132 | - do_action( |
|
| 133 | - 'AHEE__EE_Capabilities__init_caps__before_initialization', |
|
| 134 | - $this->reset |
|
| 135 | - ); |
|
| 136 | - $this->addCaps($this->_init_caps_map()); |
|
| 137 | - $this->_set_meta_caps(); |
|
| 138 | - do_action( |
|
| 139 | - 'AHEE__EE_Capabilities__init_caps__after_initialization', |
|
| 140 | - $this->capabilities_map |
|
| 141 | - ); |
|
| 142 | - $this->initialized = true; |
|
| 143 | - } |
|
| 144 | - // reset $this->reset so that it's not stuck on true if init_caps() gets called again |
|
| 145 | - $this->reset = false; |
|
| 146 | - return true; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - |
|
| 150 | - |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * This sets the meta caps property. |
|
| 154 | - * |
|
| 155 | - * @since 4.5.0 |
|
| 156 | - * @return void |
|
| 157 | - * @throws EE_Error |
|
| 158 | - */ |
|
| 159 | - private function _set_meta_caps() |
|
| 160 | - { |
|
| 161 | - // get default meta caps and filter the returned array |
|
| 162 | - $this->_meta_caps = apply_filters( |
|
| 163 | - 'FHEE__EE_Capabilities___set_meta_caps__meta_caps', |
|
| 164 | - $this->_get_default_meta_caps_array() |
|
| 165 | - ); |
|
| 166 | - //add filter for map_meta_caps but only if models can query. |
|
| 167 | - if (! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) { |
|
| 168 | - add_filter('map_meta_cap', array($this, 'map_meta_caps'), 10, 4); |
|
| 169 | - } |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * This builds and returns the default meta_caps array only once. |
|
| 176 | - * |
|
| 177 | - * @since 4.8.28.rc.012 |
|
| 178 | - * @return array |
|
| 179 | - * @throws EE_Error |
|
| 180 | - */ |
|
| 181 | - private function _get_default_meta_caps_array() |
|
| 182 | - { |
|
| 183 | - static $default_meta_caps = array(); |
|
| 184 | - // make sure we're only ever initializing the default _meta_caps array once if it's empty. |
|
| 185 | - if (empty($default_meta_caps)) { |
|
| 186 | - $default_meta_caps = array( |
|
| 187 | - //edits |
|
| 188 | - new EE_Meta_Capability_Map_Edit( |
|
| 189 | - 'ee_edit_event', |
|
| 190 | - array('Event', 'ee_edit_published_events', 'ee_edit_others_events', 'ee_edit_private_events') |
|
| 191 | - ), |
|
| 192 | - new EE_Meta_Capability_Map_Edit( |
|
| 193 | - 'ee_edit_venue', |
|
| 194 | - array('Venue', 'ee_edit_published_venues', 'ee_edit_others_venues', 'ee_edit_private_venues') |
|
| 195 | - ), |
|
| 196 | - new EE_Meta_Capability_Map_Edit( |
|
| 197 | - 'ee_edit_registration', |
|
| 198 | - array('Registration', '', 'ee_edit_others_registrations', '') |
|
| 199 | - ), |
|
| 200 | - new EE_Meta_Capability_Map_Edit( |
|
| 201 | - 'ee_edit_checkin', |
|
| 202 | - array('Registration', '', 'ee_edit_others_checkins', '') |
|
| 203 | - ), |
|
| 204 | - new EE_Meta_Capability_Map_Messages_Cap( |
|
| 205 | - 'ee_edit_message', |
|
| 206 | - array('Message_Template_Group', '', 'ee_edit_others_messages', 'ee_edit_global_messages') |
|
| 207 | - ), |
|
| 208 | - new EE_Meta_Capability_Map_Edit( |
|
| 209 | - 'ee_edit_default_ticket', |
|
| 210 | - array('Ticket', '', 'ee_edit_others_default_tickets', '') |
|
| 211 | - ), |
|
| 212 | - new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
| 213 | - 'ee_edit_question', |
|
| 214 | - array('Question', '', '', 'ee_edit_system_questions') |
|
| 215 | - ), |
|
| 216 | - new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
| 217 | - 'ee_edit_question_group', |
|
| 218 | - array('Question_Group', '', '', 'ee_edit_system_question_groups') |
|
| 219 | - ), |
|
| 220 | - new EE_Meta_Capability_Map_Edit( |
|
| 221 | - 'ee_edit_payment_method', |
|
| 222 | - array('Payment_Method', '', 'ee_edit_others_payment_methods', '') |
|
| 223 | - ), |
|
| 224 | - //reads |
|
| 225 | - new EE_Meta_Capability_Map_Read( |
|
| 226 | - 'ee_read_event', |
|
| 227 | - array('Event', '', 'ee_read_others_events', 'ee_read_private_events') |
|
| 228 | - ), |
|
| 229 | - new EE_Meta_Capability_Map_Read( |
|
| 230 | - 'ee_read_venue', |
|
| 231 | - array('Venue', '', 'ee_read_others_venues', 'ee_read_private_venues') |
|
| 232 | - ), |
|
| 233 | - new EE_Meta_Capability_Map_Read( |
|
| 234 | - 'ee_read_registration', |
|
| 235 | - array('Registration', '', 'ee_read_others_registrations', '') |
|
| 236 | - ), |
|
| 237 | - new EE_Meta_Capability_Map_Read( |
|
| 238 | - 'ee_read_checkin', |
|
| 239 | - array('Registration', '', 'ee_read_others_checkins', '') |
|
| 240 | - ), |
|
| 241 | - new EE_Meta_Capability_Map_Messages_Cap( |
|
| 242 | - 'ee_read_message', |
|
| 243 | - array('Message_Template_Group', '', 'ee_read_others_messages', 'ee_read_global_messages') |
|
| 244 | - ), |
|
| 245 | - new EE_Meta_Capability_Map_Read( |
|
| 246 | - 'ee_read_default_ticket', |
|
| 247 | - array('Ticket', '', 'ee_read_others_default_tickets', '') |
|
| 248 | - ), |
|
| 249 | - new EE_Meta_Capability_Map_Read( |
|
| 250 | - 'ee_read_payment_method', |
|
| 251 | - array('Payment_Method', '', 'ee_read_others_payment_methods', '') |
|
| 252 | - ), |
|
| 253 | - //deletes |
|
| 254 | - new EE_Meta_Capability_Map_Delete( |
|
| 255 | - 'ee_delete_event', |
|
| 256 | - array( |
|
| 257 | - 'Event', |
|
| 258 | - 'ee_delete_published_events', |
|
| 259 | - 'ee_delete_others_events', |
|
| 260 | - 'ee_delete_private_events', |
|
| 261 | - ) |
|
| 262 | - ), |
|
| 263 | - new EE_Meta_Capability_Map_Delete( |
|
| 264 | - 'ee_delete_venue', |
|
| 265 | - array( |
|
| 266 | - 'Venue', |
|
| 267 | - 'ee_delete_published_venues', |
|
| 268 | - 'ee_delete_others_venues', |
|
| 269 | - 'ee_delete_private_venues', |
|
| 270 | - ) |
|
| 271 | - ), |
|
| 272 | - new EE_Meta_Capability_Map_Delete( |
|
| 273 | - 'ee_delete_registration', |
|
| 274 | - array('Registration', '', 'ee_delete_others_registrations', '') |
|
| 275 | - ), |
|
| 276 | - new EE_Meta_Capability_Map_Delete( |
|
| 277 | - 'ee_delete_checkin', |
|
| 278 | - array('Registration', '', 'ee_delete_others_checkins', '') |
|
| 279 | - ), |
|
| 280 | - new EE_Meta_Capability_Map_Messages_Cap( |
|
| 281 | - 'ee_delete_message', |
|
| 282 | - array('Message_Template_Group', '', 'ee_delete_others_messages', 'ee_delete_global_messages') |
|
| 283 | - ), |
|
| 284 | - new EE_Meta_Capability_Map_Delete( |
|
| 285 | - 'ee_delete_default_ticket', |
|
| 286 | - array('Ticket', '', 'ee_delete_others_default_tickets', '') |
|
| 287 | - ), |
|
| 288 | - new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
| 289 | - 'ee_delete_question', |
|
| 290 | - array('Question', '', '', 'delete_system_questions') |
|
| 291 | - ), |
|
| 292 | - new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
| 293 | - 'ee_delete_question_group', |
|
| 294 | - array('Question_Group', '', '', 'delete_system_question_groups') |
|
| 295 | - ), |
|
| 296 | - new EE_Meta_Capability_Map_Delete( |
|
| 297 | - 'ee_delete_payment_method', |
|
| 298 | - array('Payment_Method', '', 'ee_delete_others_payment_methods', '') |
|
| 299 | - ), |
|
| 300 | - ); |
|
| 301 | - } |
|
| 302 | - return $default_meta_caps; |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - |
|
| 306 | - |
|
| 307 | - /** |
|
| 308 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 309 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 310 | - * |
|
| 311 | - * The actual logic is carried out by implementer classes in their definition of _map_meta_caps. |
|
| 312 | - * |
|
| 313 | - * @since 4.5.0 |
|
| 314 | - * @see wp-includes/capabilities.php |
|
| 315 | - * |
|
| 316 | - * @param array $caps actual users capabilities |
|
| 317 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 318 | - * @param int $user_id The user id |
|
| 319 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
| 320 | - * @return array actual users capabilities |
|
| 321 | - * @throws EE_Error |
|
| 322 | - */ |
|
| 323 | - public function map_meta_caps($caps, $cap, $user_id, $args) |
|
| 324 | - { |
|
| 325 | - if (did_action('AHEE__EE_System__load_espresso_addons__complete')) { |
|
| 326 | - //loop through our _meta_caps array |
|
| 327 | - foreach ($this->_meta_caps as $meta_map) { |
|
| 328 | - if (! $meta_map instanceof EE_Meta_Capability_Map) { |
|
| 329 | - continue; |
|
| 330 | - } |
|
| 331 | - // don't load models if there is no object ID in the args |
|
| 332 | - if (! empty($args[0])) { |
|
| 333 | - $meta_map->ensure_is_model(); |
|
| 334 | - } |
|
| 335 | - $caps = $meta_map->map_meta_caps($caps, $cap, $user_id, $args); |
|
| 336 | - } |
|
| 337 | - } |
|
| 338 | - return $caps; |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - |
|
| 342 | - |
|
| 343 | - /** |
|
| 344 | - * This sets up and returns the initial capabilities map for Event Espresso |
|
| 345 | - * Note this array is filtered. |
|
| 346 | - * It is assumed that all available EE capabilities are assigned to the administrator role. |
|
| 347 | - * |
|
| 348 | - * @since 4.5.0 |
|
| 349 | - * |
|
| 350 | - * @return array |
|
| 351 | - */ |
|
| 352 | - private function _init_caps_map() |
|
| 353 | - { |
|
| 354 | - return apply_filters( |
|
| 355 | - 'FHEE__EE_Capabilities__init_caps_map__caps', |
|
| 356 | - array( |
|
| 357 | - 'administrator' => array( |
|
| 358 | - //basic access |
|
| 359 | - 'ee_read_ee', |
|
| 360 | - //gateways |
|
| 361 | - /** |
|
| 362 | - * note that with payment method capabilities, although we've implemented |
|
| 363 | - * capability mapping which will be used for accessing payment methods owned by |
|
| 364 | - * other users. This is not fully implemented yet in the payment method ui. |
|
| 365 | - * Currently only the "plural" caps are in active use. |
|
| 366 | - * (Specific payment method caps are in use as well). |
|
| 367 | - **/ |
|
| 368 | - 'ee_manage_gateways', |
|
| 369 | - 'ee_read_payment_methods', |
|
| 370 | - 'ee_read_others_payment_methods', |
|
| 371 | - 'ee_edit_payment_methods', |
|
| 372 | - 'ee_edit_others_payment_methods', |
|
| 373 | - 'ee_delete_payment_methods', |
|
| 374 | - //events |
|
| 375 | - 'ee_publish_events', |
|
| 376 | - 'ee_read_private_events', |
|
| 377 | - 'ee_read_others_events', |
|
| 378 | - 'ee_read_events', |
|
| 379 | - 'ee_edit_events', |
|
| 380 | - 'ee_edit_published_events', |
|
| 381 | - 'ee_edit_others_events', |
|
| 382 | - 'ee_edit_private_events', |
|
| 383 | - 'ee_delete_published_events', |
|
| 384 | - 'ee_delete_private_events', |
|
| 385 | - 'ee_delete_events', |
|
| 386 | - 'ee_delete_others_events', |
|
| 387 | - //event categories |
|
| 388 | - 'ee_manage_event_categories', |
|
| 389 | - 'ee_edit_event_category', |
|
| 390 | - 'ee_delete_event_category', |
|
| 391 | - 'ee_assign_event_category', |
|
| 392 | - //venues |
|
| 393 | - 'ee_publish_venues', |
|
| 394 | - 'ee_read_venues', |
|
| 395 | - 'ee_read_others_venues', |
|
| 396 | - 'ee_read_private_venues', |
|
| 397 | - 'ee_edit_venues', |
|
| 398 | - 'ee_edit_others_venues', |
|
| 399 | - 'ee_edit_published_venues', |
|
| 400 | - 'ee_edit_private_venues', |
|
| 401 | - 'ee_delete_venues', |
|
| 402 | - 'ee_delete_others_venues', |
|
| 403 | - 'ee_delete_private_venues', |
|
| 404 | - 'ee_delete_published_venues', |
|
| 405 | - //venue categories |
|
| 406 | - 'ee_manage_venue_categories', |
|
| 407 | - 'ee_edit_venue_category', |
|
| 408 | - 'ee_delete_venue_category', |
|
| 409 | - 'ee_assign_venue_category', |
|
| 410 | - //contacts |
|
| 411 | - 'ee_read_contacts', |
|
| 412 | - 'ee_edit_contacts', |
|
| 413 | - 'ee_delete_contacts', |
|
| 414 | - //registrations |
|
| 415 | - 'ee_read_registrations', |
|
| 416 | - 'ee_read_others_registrations', |
|
| 417 | - 'ee_edit_registrations', |
|
| 418 | - 'ee_edit_others_registrations', |
|
| 419 | - 'ee_delete_registrations', |
|
| 420 | - //checkins |
|
| 421 | - 'ee_read_others_checkins', |
|
| 422 | - 'ee_read_checkins', |
|
| 423 | - 'ee_edit_checkins', |
|
| 424 | - 'ee_edit_others_checkins', |
|
| 425 | - 'ee_delete_checkins', |
|
| 426 | - 'ee_delete_others_checkins', |
|
| 427 | - //transactions && payments |
|
| 428 | - 'ee_read_transaction', |
|
| 429 | - 'ee_read_transactions', |
|
| 430 | - 'ee_edit_payments', |
|
| 431 | - 'ee_delete_payments', |
|
| 432 | - //messages |
|
| 433 | - 'ee_read_messages', |
|
| 434 | - 'ee_read_others_messages', |
|
| 435 | - 'ee_read_global_messages', |
|
| 436 | - 'ee_edit_global_messages', |
|
| 437 | - 'ee_edit_messages', |
|
| 438 | - 'ee_edit_others_messages', |
|
| 439 | - 'ee_delete_messages', |
|
| 440 | - 'ee_delete_others_messages', |
|
| 441 | - 'ee_delete_global_messages', |
|
| 442 | - 'ee_send_message', |
|
| 443 | - //tickets |
|
| 444 | - 'ee_read_default_tickets', |
|
| 445 | - 'ee_read_others_default_tickets', |
|
| 446 | - 'ee_edit_default_tickets', |
|
| 447 | - 'ee_edit_others_default_tickets', |
|
| 448 | - 'ee_delete_default_tickets', |
|
| 449 | - 'ee_delete_others_default_tickets', |
|
| 450 | - //prices |
|
| 451 | - 'ee_edit_default_price', |
|
| 452 | - 'ee_edit_default_prices', |
|
| 453 | - 'ee_delete_default_price', |
|
| 454 | - 'ee_delete_default_prices', |
|
| 455 | - 'ee_edit_default_price_type', |
|
| 456 | - 'ee_edit_default_price_types', |
|
| 457 | - 'ee_delete_default_price_type', |
|
| 458 | - 'ee_delete_default_price_types', |
|
| 459 | - 'ee_read_default_prices', |
|
| 460 | - 'ee_read_default_price_types', |
|
| 461 | - //registration form |
|
| 462 | - 'ee_edit_questions', |
|
| 463 | - 'ee_edit_system_questions', |
|
| 464 | - 'ee_read_questions', |
|
| 465 | - 'ee_delete_questions', |
|
| 466 | - 'ee_edit_question_groups', |
|
| 467 | - 'ee_read_question_groups', |
|
| 468 | - 'ee_edit_system_question_groups', |
|
| 469 | - 'ee_delete_question_groups', |
|
| 470 | - //event_type taxonomy |
|
| 471 | - 'ee_assign_event_type', |
|
| 472 | - 'ee_manage_event_types', |
|
| 473 | - 'ee_edit_event_type', |
|
| 474 | - 'ee_delete_event_type', |
|
| 475 | - ), |
|
| 476 | - 'ee_events_administrator' => array( |
|
| 477 | - //core wp caps |
|
| 478 | - 'read', |
|
| 479 | - 'read_private_pages', |
|
| 480 | - 'read_private_posts', |
|
| 481 | - 'edit_users', |
|
| 482 | - 'edit_posts', |
|
| 483 | - 'edit_pages', |
|
| 484 | - 'edit_published_posts', |
|
| 485 | - 'edit_published_pages', |
|
| 486 | - 'edit_private_pages', |
|
| 487 | - 'edit_private_posts', |
|
| 488 | - 'edit_others_posts', |
|
| 489 | - 'edit_others_pages', |
|
| 490 | - 'publish_posts', |
|
| 491 | - 'publish_pages', |
|
| 492 | - 'delete_posts', |
|
| 493 | - 'delete_pages', |
|
| 494 | - 'delete_private_pages', |
|
| 495 | - 'delete_private_posts', |
|
| 496 | - 'delete_published_pages', |
|
| 497 | - 'delete_published_posts', |
|
| 498 | - 'delete_others_posts', |
|
| 499 | - 'delete_others_pages', |
|
| 500 | - 'manage_categories', |
|
| 501 | - 'manage_links', |
|
| 502 | - 'moderate_comments', |
|
| 503 | - 'unfiltered_html', |
|
| 504 | - 'upload_files', |
|
| 505 | - 'export', |
|
| 506 | - 'import', |
|
| 507 | - 'list_users', |
|
| 508 | - 'level_1', //required if user with this role shows up in author dropdowns |
|
| 509 | - //basic ee access |
|
| 510 | - 'ee_read_ee', |
|
| 511 | - //events |
|
| 512 | - 'ee_publish_events', |
|
| 513 | - 'ee_read_private_events', |
|
| 514 | - 'ee_read_others_events', |
|
| 515 | - 'ee_read_event', |
|
| 516 | - 'ee_read_events', |
|
| 517 | - 'ee_edit_event', |
|
| 518 | - 'ee_edit_events', |
|
| 519 | - 'ee_edit_published_events', |
|
| 520 | - 'ee_edit_others_events', |
|
| 521 | - 'ee_edit_private_events', |
|
| 522 | - 'ee_delete_published_events', |
|
| 523 | - 'ee_delete_private_events', |
|
| 524 | - 'ee_delete_event', |
|
| 525 | - 'ee_delete_events', |
|
| 526 | - 'ee_delete_others_events', |
|
| 527 | - //event categories |
|
| 528 | - 'ee_manage_event_categories', |
|
| 529 | - 'ee_edit_event_category', |
|
| 530 | - 'ee_delete_event_category', |
|
| 531 | - 'ee_assign_event_category', |
|
| 532 | - //venues |
|
| 533 | - 'ee_publish_venues', |
|
| 534 | - 'ee_read_venue', |
|
| 535 | - 'ee_read_venues', |
|
| 536 | - 'ee_read_others_venues', |
|
| 537 | - 'ee_read_private_venues', |
|
| 538 | - 'ee_edit_venue', |
|
| 539 | - 'ee_edit_venues', |
|
| 540 | - 'ee_edit_others_venues', |
|
| 541 | - 'ee_edit_published_venues', |
|
| 542 | - 'ee_edit_private_venues', |
|
| 543 | - 'ee_delete_venue', |
|
| 544 | - 'ee_delete_venues', |
|
| 545 | - 'ee_delete_others_venues', |
|
| 546 | - 'ee_delete_private_venues', |
|
| 547 | - 'ee_delete_published_venues', |
|
| 548 | - //venue categories |
|
| 549 | - 'ee_manage_venue_categories', |
|
| 550 | - 'ee_edit_venue_category', |
|
| 551 | - 'ee_delete_venue_category', |
|
| 552 | - 'ee_assign_venue_category', |
|
| 553 | - //contacts |
|
| 554 | - 'ee_read_contacts', |
|
| 555 | - 'ee_edit_contacts', |
|
| 556 | - 'ee_delete_contacts', |
|
| 557 | - //registrations |
|
| 558 | - 'ee_read_registrations', |
|
| 559 | - 'ee_read_others_registrations', |
|
| 560 | - 'ee_edit_registration', |
|
| 561 | - 'ee_edit_registrations', |
|
| 562 | - 'ee_edit_others_registrations', |
|
| 563 | - 'ee_delete_registration', |
|
| 564 | - 'ee_delete_registrations', |
|
| 565 | - //checkins |
|
| 566 | - 'ee_read_others_checkins', |
|
| 567 | - 'ee_read_checkins', |
|
| 568 | - 'ee_edit_checkins', |
|
| 569 | - 'ee_edit_others_checkins', |
|
| 570 | - 'ee_delete_checkins', |
|
| 571 | - 'ee_delete_others_checkins', |
|
| 572 | - //transactions && payments |
|
| 573 | - 'ee_read_transaction', |
|
| 574 | - 'ee_read_transactions', |
|
| 575 | - 'ee_edit_payments', |
|
| 576 | - 'ee_delete_payments', |
|
| 577 | - //messages |
|
| 578 | - 'ee_read_messages', |
|
| 579 | - 'ee_read_others_messages', |
|
| 580 | - 'ee_read_global_messages', |
|
| 581 | - 'ee_edit_global_messages', |
|
| 582 | - 'ee_edit_messages', |
|
| 583 | - 'ee_edit_others_messages', |
|
| 584 | - 'ee_delete_messages', |
|
| 585 | - 'ee_delete_others_messages', |
|
| 586 | - 'ee_delete_global_messages', |
|
| 587 | - 'ee_send_message', |
|
| 588 | - //tickets |
|
| 589 | - 'ee_read_default_tickets', |
|
| 590 | - 'ee_read_others_default_tickets', |
|
| 591 | - 'ee_edit_default_tickets', |
|
| 592 | - 'ee_edit_others_default_tickets', |
|
| 593 | - 'ee_delete_default_tickets', |
|
| 594 | - 'ee_delete_others_default_tickets', |
|
| 595 | - //prices |
|
| 596 | - 'ee_edit_default_price', |
|
| 597 | - 'ee_edit_default_prices', |
|
| 598 | - 'ee_delete_default_price', |
|
| 599 | - 'ee_delete_default_prices', |
|
| 600 | - 'ee_edit_default_price_type', |
|
| 601 | - 'ee_edit_default_price_types', |
|
| 602 | - 'ee_delete_default_price_type', |
|
| 603 | - 'ee_delete_default_price_types', |
|
| 604 | - 'ee_read_default_prices', |
|
| 605 | - 'ee_read_default_price_types', |
|
| 606 | - //registration form |
|
| 607 | - 'ee_edit_questions', |
|
| 608 | - 'ee_edit_system_questions', |
|
| 609 | - 'ee_read_questions', |
|
| 610 | - 'ee_delete_questions', |
|
| 611 | - 'ee_edit_question_groups', |
|
| 612 | - 'ee_read_question_groups', |
|
| 613 | - 'ee_edit_system_question_groups', |
|
| 614 | - 'ee_delete_question_groups', |
|
| 615 | - //event_type taxonomy |
|
| 616 | - 'ee_assign_event_type', |
|
| 617 | - 'ee_manage_event_types', |
|
| 618 | - 'ee_edit_event_type', |
|
| 619 | - 'ee_delete_event_type', |
|
| 620 | - ) |
|
| 621 | - ) |
|
| 622 | - ); |
|
| 623 | - } |
|
| 624 | - |
|
| 625 | - |
|
| 626 | - |
|
| 627 | - /** |
|
| 628 | - * @return bool |
|
| 629 | - * @throws EE_Error |
|
| 630 | - */ |
|
| 631 | - private function setupCapabilitiesMap() |
|
| 632 | - { |
|
| 633 | - // if the initialization process hasn't even started, then we need to call init_caps() |
|
| 634 | - if($this->initialized === null) { |
|
| 635 | - return $this->init_caps(); |
|
| 636 | - } |
|
| 637 | - // unless resetting, get caps from db if we haven't already |
|
| 638 | - $this->capabilities_map = $this->reset || ! empty($this->capabilities_map) |
|
| 639 | - ? $this->capabilities_map |
|
| 640 | - : get_option(self::option_name, array()); |
|
| 641 | - return true; |
|
| 642 | - } |
|
| 643 | - |
|
| 644 | - |
|
| 645 | - |
|
| 646 | - /** |
|
| 647 | - * @param bool $update |
|
| 648 | - * @return bool |
|
| 649 | - */ |
|
| 650 | - private function updateCapabilitiesMap($update = true) |
|
| 651 | - { |
|
| 652 | - return $update ? update_option(self::option_name, $this->capabilities_map) : false; |
|
| 653 | - } |
|
| 654 | - |
|
| 655 | - |
|
| 656 | - |
|
| 657 | - /** |
|
| 658 | - * Adds capabilities to roles. |
|
| 659 | - * |
|
| 660 | - * @since 4.9.42 |
|
| 661 | - * @param array $capabilities_to_add array of capabilities to add, indexed by roles. |
|
| 662 | - * Note that this should ONLY be called on activation hook |
|
| 663 | - * otherwise the caps will be added on every request. |
|
| 664 | - * @return bool |
|
| 665 | - * @throws \EE_Error |
|
| 666 | - */ |
|
| 667 | - public function addCaps(array $capabilities_to_add) |
|
| 668 | - { |
|
| 669 | - // don't do anything if the capabilities map can not be initialized |
|
| 670 | - if (! $this->setupCapabilitiesMap()) { |
|
| 671 | - return false; |
|
| 672 | - } |
|
| 673 | - // and filter the array so others can get in on the fun during resets |
|
| 674 | - $capabilities_to_add = apply_filters( |
|
| 675 | - 'FHEE__EE_Capabilities__addCaps__capabilities_to_add', |
|
| 676 | - $capabilities_to_add, |
|
| 677 | - $this->reset, |
|
| 678 | - $this->capabilities_map |
|
| 679 | - ); |
|
| 680 | - $update_capabilities_map = false; |
|
| 681 | - // if not reset, see what caps are new for each role. if they're new, add them. |
|
| 682 | - foreach ($capabilities_to_add as $role => $caps_for_role) { |
|
| 683 | - if (is_array($caps_for_role)) { |
|
| 684 | - foreach ($caps_for_role as $cap) { |
|
| 685 | - if ( |
|
| 686 | - ! $this->capHasBeenAddedToRole($role, $cap) |
|
| 687 | - && $this->add_cap_to_role($role, $cap, true, false) |
|
| 688 | - ) { |
|
| 689 | - $update_capabilities_map = true; |
|
| 690 | - } |
|
| 691 | - } |
|
| 692 | - } |
|
| 693 | - } |
|
| 694 | - // now let's just save the cap that has been set but only if there's been a change. |
|
| 695 | - $updated = $this->updateCapabilitiesMap($update_capabilities_map); |
|
| 696 | - $this->flushWpUser($updated); |
|
| 697 | - do_action('AHEE__EE_Capabilities__addCaps__complete', $this->capabilities_map, $updated); |
|
| 698 | - return $updated; |
|
| 699 | - } |
|
| 700 | - |
|
| 701 | - |
|
| 702 | - |
|
| 703 | - /** |
|
| 704 | - * Loops through the capabilities map and removes the role caps specified by the incoming array |
|
| 705 | - * |
|
| 706 | - * @param array $caps_map map of capabilities to be removed (indexed by roles) |
|
| 707 | - * @return bool |
|
| 708 | - * @throws \EE_Error |
|
| 709 | - */ |
|
| 710 | - public function removeCaps($caps_map) |
|
| 711 | - { |
|
| 712 | - // don't do anything if the capabilities map can not be initialized |
|
| 713 | - if (! $this->setupCapabilitiesMap()) { |
|
| 714 | - return false; |
|
| 715 | - } |
|
| 716 | - $update_capabilities_map = false; |
|
| 717 | - foreach ($caps_map as $role => $caps_for_role) { |
|
| 718 | - if (is_array($caps_for_role)) { |
|
| 719 | - foreach ($caps_for_role as $cap) { |
|
| 720 | - if ($this->capHasBeenAddedToRole($role, $cap) |
|
| 721 | - && $this->remove_cap_from_role($role, $cap, false) |
|
| 722 | - ) { |
|
| 723 | - $update_capabilities_map = true; |
|
| 724 | - } |
|
| 725 | - } |
|
| 726 | - } |
|
| 727 | - } |
|
| 728 | - // maybe resave the caps |
|
| 729 | - $updated = $this->updateCapabilitiesMap($update_capabilities_map); |
|
| 730 | - $this->flushWpUser($updated); |
|
| 731 | - return $updated; |
|
| 732 | - } |
|
| 733 | - |
|
| 734 | - |
|
| 735 | - /** |
|
| 736 | - * This ensures that the WP User object cached on the $current_user global in WP has the latest capabilities from |
|
| 737 | - * the roles on that user. |
|
| 738 | - * |
|
| 739 | - * @param bool $flush Default is to flush the WP_User object. If false, then this method effectively does nothing. |
|
| 740 | - */ |
|
| 741 | - private function flushWpUser($flush = true) |
|
| 742 | - { |
|
| 743 | - if ($flush) { |
|
| 744 | - $user = wp_get_current_user(); |
|
| 745 | - if ($user instanceof WP_User) { |
|
| 746 | - $user->get_role_caps(); |
|
| 747 | - } |
|
| 748 | - } |
|
| 749 | - } |
|
| 750 | - |
|
| 751 | - |
|
| 752 | - |
|
| 753 | - /** |
|
| 754 | - * This method sets a capability on a role. Note this should only be done on activation, or if you have something |
|
| 755 | - * specific to prevent the cap from being added on every page load (adding caps are persistent to the db). Note. |
|
| 756 | - * this is a wrapper for $wp_role->add_cap() |
|
| 757 | - * |
|
| 758 | - * @see wp-includes/capabilities.php |
|
| 759 | - * @since 4.5.0 |
|
| 760 | - * @param string|WP_Role $role A WordPress role the capability is being added to |
|
| 761 | - * @param string $cap The capability being added to the role |
|
| 762 | - * @param bool $grant Whether to grant access to this cap on this role. |
|
| 763 | - * @param bool $update_capabilities_map |
|
| 764 | - * @return bool |
|
| 765 | - * @throws \EE_Error |
|
| 766 | - */ |
|
| 767 | - public function add_cap_to_role($role, $cap, $grant = true, $update_capabilities_map = true) |
|
| 768 | - { |
|
| 769 | - // capture incoming value for $role because we may need it to create a new WP_Role |
|
| 770 | - $orig_role = $role; |
|
| 771 | - $role = $role instanceof WP_Role ? $role : get_role($role); |
|
| 772 | - //if the role isn't available then we create it. |
|
| 773 | - if (! $role instanceof WP_Role) { |
|
| 774 | - // if a plugin wants to create a specific role name then they should create the role before |
|
| 775 | - // EE_Capabilities does. Otherwise this function will create the role name from the slug: |
|
| 776 | - // - removes any `ee_` namespacing from the start of the slug. |
|
| 777 | - // - replaces `_` with ` ` (empty space). |
|
| 778 | - // - sentence case on the resulting string. |
|
| 779 | - $role_label = ucwords(str_replace(array('ee_', '_'), array('', ' '), $orig_role)); |
|
| 780 | - $role = add_role($orig_role, $role_label); |
|
| 781 | - } |
|
| 782 | - if ($role instanceof WP_Role) { |
|
| 783 | - // don't do anything if the capabilities map can not be initialized |
|
| 784 | - if (! $this->setupCapabilitiesMap()) { |
|
| 785 | - return false; |
|
| 786 | - } |
|
| 787 | - if (! $this->capHasBeenAddedToRole($role->name, $cap)) { |
|
| 788 | - $role->add_cap($cap, $grant); |
|
| 789 | - $this->capabilities_map[ $role->name ][] = $cap; |
|
| 790 | - $this->updateCapabilitiesMap($update_capabilities_map); |
|
| 791 | - return true; |
|
| 792 | - } |
|
| 793 | - } |
|
| 794 | - return false; |
|
| 795 | - } |
|
| 796 | - |
|
| 797 | - |
|
| 798 | - |
|
| 799 | - /** |
|
| 800 | - * Functions similarly to add_cap_to_role except removes cap from given role. |
|
| 801 | - * Wrapper for $wp_role->remove_cap() |
|
| 802 | - * |
|
| 803 | - * @see wp-includes/capabilities.php |
|
| 804 | - * @since 4.5.0 |
|
| 805 | - * @param string|WP_Role $role A WordPress role the capability is being removed from. |
|
| 806 | - * @param string $cap The capability being removed |
|
| 807 | - * @param bool $update_capabilities_map |
|
| 808 | - * @return bool |
|
| 809 | - * @throws \EE_Error |
|
| 810 | - */ |
|
| 811 | - public function remove_cap_from_role($role, $cap, $update_capabilities_map = true) |
|
| 812 | - { |
|
| 813 | - // don't do anything if the capabilities map can not be initialized |
|
| 814 | - if (! $this->setupCapabilitiesMap()) { |
|
| 815 | - return false; |
|
| 816 | - } |
|
| 817 | - |
|
| 818 | - $role = $role instanceof WP_Role ? $role : get_role($role); |
|
| 819 | - if ($role instanceof WP_Role && $index = $this->capHasBeenAddedToRole($role->name, $cap, true)) { |
|
| 820 | - $role->remove_cap($cap); |
|
| 821 | - unset($this->capabilities_map[ $role->name ][ $index ]); |
|
| 822 | - $this->updateCapabilitiesMap($update_capabilities_map); |
|
| 823 | - return true; |
|
| 824 | - } |
|
| 825 | - return false; |
|
| 826 | - } |
|
| 827 | - |
|
| 828 | - |
|
| 829 | - |
|
| 830 | - /** |
|
| 831 | - * @param string $role_name |
|
| 832 | - * @param string $cap |
|
| 833 | - * @param bool $get_index |
|
| 834 | - * @return bool|mixed |
|
| 835 | - */ |
|
| 836 | - private function capHasBeenAddedToRole($role_name='', $cap='', $get_index = false) |
|
| 837 | - { |
|
| 838 | - if ( |
|
| 839 | - isset($this->capabilities_map[$role_name]) |
|
| 840 | - && ($index = array_search($cap, $this->capabilities_map[$role_name], true)) !== false |
|
| 841 | - ) { |
|
| 842 | - return $get_index ? $index : true; |
|
| 843 | - } |
|
| 844 | - return false; |
|
| 845 | - } |
|
| 846 | - |
|
| 847 | - |
|
| 848 | - |
|
| 849 | - /** |
|
| 850 | - * Wrapper for the native WP current_user_can() method. |
|
| 851 | - * This is provided as a handy method for a couple things: |
|
| 852 | - * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to |
|
| 853 | - * write those filters wherever current_user_can is called). |
|
| 854 | - * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters ) |
|
| 855 | - * |
|
| 856 | - * @since 4.5.0 |
|
| 857 | - * |
|
| 858 | - * @param string $cap The cap being checked. |
|
| 859 | - * @param string $context The context where the current_user_can is being called from. |
|
| 860 | - * @param int $id Optional. Id for item where current_user_can is being called from (used in map_meta_cap() |
|
| 861 | - * filters. |
|
| 862 | - * |
|
| 863 | - * @return bool Whether user can or not. |
|
| 864 | - */ |
|
| 865 | - public function current_user_can($cap, $context, $id = 0) |
|
| 866 | - { |
|
| 867 | - //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
| 868 | - $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__' . $context, $cap, $id); |
|
| 869 | - $filtered_cap = apply_filters( |
|
| 870 | - 'FHEE__EE_Capabilities__current_user_can__cap', |
|
| 871 | - $filtered_cap, |
|
| 872 | - $context, |
|
| 873 | - $cap, |
|
| 874 | - $id |
|
| 875 | - ); |
|
| 876 | - return ! empty($id) |
|
| 877 | - ? current_user_can($filtered_cap, $id) |
|
| 878 | - : current_user_can($filtered_cap); |
|
| 879 | - } |
|
| 880 | - |
|
| 881 | - |
|
| 882 | - |
|
| 883 | - /** |
|
| 884 | - * This is a wrapper for the WP user_can() function and follows the same style as the other wrappers in this class. |
|
| 885 | - * |
|
| 886 | - * @param int|WP_User $user Either the user_id or a WP_User object |
|
| 887 | - * @param string $cap The capability string being checked |
|
| 888 | - * @param string $context The context where the user_can is being called from (used in filters). |
|
| 889 | - * @param int $id Optional. Id for item where user_can is being called from ( used in map_meta_cap() |
|
| 890 | - * filters) |
|
| 891 | - * |
|
| 892 | - * @return bool Whether user can or not. |
|
| 893 | - */ |
|
| 894 | - public function user_can($user, $cap, $context, $id = 0) |
|
| 895 | - { |
|
| 896 | - //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
| 897 | - $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__' . $context, $cap, $user, $id); |
|
| 898 | - $filtered_cap = apply_filters( |
|
| 899 | - 'FHEE__EE_Capabilities__user_can__cap', |
|
| 900 | - $filtered_cap, |
|
| 901 | - $context, |
|
| 902 | - $cap, |
|
| 903 | - $user, |
|
| 904 | - $id |
|
| 905 | - ); |
|
| 906 | - return ! empty($id) |
|
| 907 | - ? user_can($user, $filtered_cap, $id) |
|
| 908 | - : user_can($user, $filtered_cap); |
|
| 909 | - } |
|
| 910 | - |
|
| 911 | - |
|
| 912 | - |
|
| 913 | - /** |
|
| 914 | - * Wrapper for the native WP current_user_can_for_blog() method. |
|
| 915 | - * This is provided as a handy method for a couple things: |
|
| 916 | - * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to |
|
| 917 | - * write those filters wherever current_user_can is called). |
|
| 918 | - * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters ) |
|
| 919 | - * |
|
| 920 | - * @since 4.5.0 |
|
| 921 | - * |
|
| 922 | - * @param int $blog_id The blog id that is being checked for. |
|
| 923 | - * @param string $cap The cap being checked. |
|
| 924 | - * @param string $context The context where the current_user_can is being called from. |
|
| 925 | - * @param int $id Optional. Id for item where current_user_can is being called from (used in map_meta_cap() |
|
| 926 | - * filters. |
|
| 927 | - * |
|
| 928 | - * @return bool Whether user can or not. |
|
| 929 | - */ |
|
| 930 | - public function current_user_can_for_blog($blog_id, $cap, $context, $id = 0) |
|
| 931 | - { |
|
| 932 | - $user_can = ! empty($id) |
|
| 933 | - ? current_user_can_for_blog($blog_id, $cap, $id) |
|
| 934 | - : current_user_can($blog_id, $cap); |
|
| 935 | - //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
| 936 | - $user_can = apply_filters( |
|
| 937 | - 'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__' . $context, |
|
| 938 | - $user_can, |
|
| 939 | - $blog_id, |
|
| 940 | - $cap, |
|
| 941 | - $id |
|
| 942 | - ); |
|
| 943 | - $user_can = apply_filters( |
|
| 944 | - 'FHEE__EE_Capabilities__current_user_can_for_blog__user_can', |
|
| 945 | - $user_can, |
|
| 946 | - $context, |
|
| 947 | - $blog_id, |
|
| 948 | - $cap, |
|
| 949 | - $id |
|
| 950 | - ); |
|
| 951 | - return $user_can; |
|
| 952 | - } |
|
| 953 | - |
|
| 954 | - |
|
| 955 | - |
|
| 956 | - /** |
|
| 957 | - * This helper method just returns an array of registered EE capabilities. |
|
| 958 | - * |
|
| 959 | - * @since 4.5.0 |
|
| 960 | - * @param string $role If empty then the entire role/capability map is returned. |
|
| 961 | - * Otherwise just the capabilities for the given role are returned. |
|
| 962 | - * @return array |
|
| 963 | - * @throws EE_Error |
|
| 964 | - */ |
|
| 965 | - public function get_ee_capabilities($role = 'administrator') |
|
| 966 | - { |
|
| 967 | - if (! $this->initialized) { |
|
| 968 | - $this->init_caps(); |
|
| 969 | - } |
|
| 970 | - if (empty($role)) { |
|
| 971 | - return $this->capabilities_map; |
|
| 972 | - } |
|
| 973 | - return isset($this->capabilities_map[ $role ]) |
|
| 974 | - ? $this->capabilities_map[ $role ] |
|
| 975 | - : array(); |
|
| 976 | - } |
|
| 977 | - |
|
| 978 | - |
|
| 979 | - |
|
| 980 | - /** |
|
| 981 | - * @deprecated 4.9.42 |
|
| 982 | - * @param bool $reset If you need to reset Event Espresso's capabilities, |
|
| 983 | - * then please use the init_caps() method with the "$reset" parameter set to "true" |
|
| 984 | - * @param array $caps_map Optional. |
|
| 985 | - * Can be used to send a custom map of roles and capabilities for setting them up. |
|
| 986 | - * Note that this should ONLY be called on activation hook or some other one-time |
|
| 987 | - * task otherwise the caps will be added on every request. |
|
| 988 | - * @return void |
|
| 989 | - * @throws EE_Error |
|
| 990 | - */ |
|
| 991 | - public function init_role_caps($reset = false, $caps_map = array()) |
|
| 992 | - { |
|
| 993 | - // If this method is called directly and reset is set as 'true', |
|
| 994 | - // then display a doing it wrong notice, because we want resets to go through init_caps() |
|
| 995 | - // to guarantee that everything is set up correctly. |
|
| 996 | - // This prevents the capabilities map getting reset incorrectly by direct calls to this method. |
|
| 997 | - if ($reset) { |
|
| 998 | - EE_Error::doing_it_wrong( |
|
| 999 | - __METHOD__, |
|
| 1000 | - sprintf( |
|
| 1001 | - esc_html__( |
|
| 1002 | - 'The "%1$s" parameter for the "%2$s" method is deprecated. If you need to reset Event Espresso\'s capabilities, then please use the "%3$s" method with the "%1$s" parameter set to "%4$s".', |
|
| 1003 | - 'event_espresso' |
|
| 1004 | - ), |
|
| 1005 | - '$reset', |
|
| 1006 | - __METHOD__ . '()', |
|
| 1007 | - 'EE_Capabilities::init_caps()', |
|
| 1008 | - 'true' |
|
| 1009 | - ), |
|
| 1010 | - '4.9.42', |
|
| 1011 | - '5.0.0' |
|
| 1012 | - ); |
|
| 1013 | - } |
|
| 1014 | - $this->addCaps($caps_map); |
|
| 1015 | - } |
|
| 21 | + /** |
|
| 22 | + * the name of the wp option used to store caps previously initialized |
|
| 23 | + */ |
|
| 24 | + const option_name = 'ee_caps_initialized'; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * instance of EE_Capabilities object |
|
| 28 | + * |
|
| 29 | + * @var EE_Capabilities |
|
| 30 | + */ |
|
| 31 | + private static $_instance; |
|
| 32 | + |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * This is a map of caps that correspond to a default WP_Role. |
|
| 36 | + * Array is indexed by Role and values are ee capabilities. |
|
| 37 | + * |
|
| 38 | + * @since 4.5.0 |
|
| 39 | + * |
|
| 40 | + * @var array |
|
| 41 | + */ |
|
| 42 | + private $capabilities_map = array(); |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * This used to hold an array of EE_Meta_Capability_Map objects |
|
| 46 | + * that define the granular capabilities mapped to for a user depending on context. |
|
| 47 | + * |
|
| 48 | + * @var EE_Meta_Capability_Map[] |
|
| 49 | + */ |
|
| 50 | + private $_meta_caps = array(); |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * The internal $capabilities_map needs to be initialized before it can be used. |
|
| 54 | + * This flag tracks whether that has happened or not. |
|
| 55 | + * But for this to work, we need three states to indicate: |
|
| 56 | + * initialization has not occurred at all |
|
| 57 | + * initialization has started but is not complete |
|
| 58 | + * initialization is complete |
|
| 59 | + * The reason this is needed is because the addCaps() method |
|
| 60 | + * normally requires the $capabilities_map to be initialized, |
|
| 61 | + * but is also used during the initialization process. |
|
| 62 | + * So: |
|
| 63 | + * If initialized === null, init_caps() will be called before any other methods will run. |
|
| 64 | + * If initialized === false, then init_caps() is in the process of running it's logic. |
|
| 65 | + * If initialized === true, then init_caps() has completed the initialization process. |
|
| 66 | + * |
|
| 67 | + * @var boolean|null $initialized |
|
| 68 | + */ |
|
| 69 | + private $initialized; |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @var boolean $reset |
|
| 73 | + */ |
|
| 74 | + private $reset = false; |
|
| 75 | + |
|
| 76 | + |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * singleton method used to instantiate class object |
|
| 80 | + * |
|
| 81 | + * @since 4.5.0 |
|
| 82 | + * |
|
| 83 | + * @return EE_Capabilities |
|
| 84 | + */ |
|
| 85 | + public static function instance() |
|
| 86 | + { |
|
| 87 | + //check if instantiated, and if not do so. |
|
| 88 | + if (! self::$_instance instanceof EE_Capabilities) { |
|
| 89 | + self::$_instance = new self(); |
|
| 90 | + } |
|
| 91 | + return self::$_instance; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * private constructor |
|
| 98 | + * |
|
| 99 | + * @since 4.5.0 |
|
| 100 | + */ |
|
| 101 | + private function __construct() |
|
| 102 | + { |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * This delays the initialization of the capabilities class until EE_System core is loaded and ready. |
|
| 109 | + * |
|
| 110 | + * @param bool $reset allows for resetting the default capabilities saved on roles. Note that this doesn't |
|
| 111 | + * actually REMOVE any capabilities from existing roles, it just resaves defaults roles and |
|
| 112 | + * ensures that they are up to date. |
|
| 113 | + * |
|
| 114 | + * @since 4.5.0 |
|
| 115 | + * @return bool |
|
| 116 | + * @throws EE_Error |
|
| 117 | + */ |
|
| 118 | + public function init_caps($reset = false) |
|
| 119 | + { |
|
| 120 | + if(! EE_Maintenance_Mode::instance()->models_can_query()){ |
|
| 121 | + return false; |
|
| 122 | + } |
|
| 123 | + $this->reset = filter_var($reset, FILTER_VALIDATE_BOOLEAN); |
|
| 124 | + // if reset, then completely delete the cache option and clear the $capabilities_map property. |
|
| 125 | + if ($this->reset) { |
|
| 126 | + $this->initialized = null; |
|
| 127 | + $this->capabilities_map = array(); |
|
| 128 | + delete_option(self::option_name); |
|
| 129 | + } |
|
| 130 | + if ($this->initialized === null) { |
|
| 131 | + $this->initialized = false; |
|
| 132 | + do_action( |
|
| 133 | + 'AHEE__EE_Capabilities__init_caps__before_initialization', |
|
| 134 | + $this->reset |
|
| 135 | + ); |
|
| 136 | + $this->addCaps($this->_init_caps_map()); |
|
| 137 | + $this->_set_meta_caps(); |
|
| 138 | + do_action( |
|
| 139 | + 'AHEE__EE_Capabilities__init_caps__after_initialization', |
|
| 140 | + $this->capabilities_map |
|
| 141 | + ); |
|
| 142 | + $this->initialized = true; |
|
| 143 | + } |
|
| 144 | + // reset $this->reset so that it's not stuck on true if init_caps() gets called again |
|
| 145 | + $this->reset = false; |
|
| 146 | + return true; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + |
|
| 150 | + |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * This sets the meta caps property. |
|
| 154 | + * |
|
| 155 | + * @since 4.5.0 |
|
| 156 | + * @return void |
|
| 157 | + * @throws EE_Error |
|
| 158 | + */ |
|
| 159 | + private function _set_meta_caps() |
|
| 160 | + { |
|
| 161 | + // get default meta caps and filter the returned array |
|
| 162 | + $this->_meta_caps = apply_filters( |
|
| 163 | + 'FHEE__EE_Capabilities___set_meta_caps__meta_caps', |
|
| 164 | + $this->_get_default_meta_caps_array() |
|
| 165 | + ); |
|
| 166 | + //add filter for map_meta_caps but only if models can query. |
|
| 167 | + if (! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) { |
|
| 168 | + add_filter('map_meta_cap', array($this, 'map_meta_caps'), 10, 4); |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * This builds and returns the default meta_caps array only once. |
|
| 176 | + * |
|
| 177 | + * @since 4.8.28.rc.012 |
|
| 178 | + * @return array |
|
| 179 | + * @throws EE_Error |
|
| 180 | + */ |
|
| 181 | + private function _get_default_meta_caps_array() |
|
| 182 | + { |
|
| 183 | + static $default_meta_caps = array(); |
|
| 184 | + // make sure we're only ever initializing the default _meta_caps array once if it's empty. |
|
| 185 | + if (empty($default_meta_caps)) { |
|
| 186 | + $default_meta_caps = array( |
|
| 187 | + //edits |
|
| 188 | + new EE_Meta_Capability_Map_Edit( |
|
| 189 | + 'ee_edit_event', |
|
| 190 | + array('Event', 'ee_edit_published_events', 'ee_edit_others_events', 'ee_edit_private_events') |
|
| 191 | + ), |
|
| 192 | + new EE_Meta_Capability_Map_Edit( |
|
| 193 | + 'ee_edit_venue', |
|
| 194 | + array('Venue', 'ee_edit_published_venues', 'ee_edit_others_venues', 'ee_edit_private_venues') |
|
| 195 | + ), |
|
| 196 | + new EE_Meta_Capability_Map_Edit( |
|
| 197 | + 'ee_edit_registration', |
|
| 198 | + array('Registration', '', 'ee_edit_others_registrations', '') |
|
| 199 | + ), |
|
| 200 | + new EE_Meta_Capability_Map_Edit( |
|
| 201 | + 'ee_edit_checkin', |
|
| 202 | + array('Registration', '', 'ee_edit_others_checkins', '') |
|
| 203 | + ), |
|
| 204 | + new EE_Meta_Capability_Map_Messages_Cap( |
|
| 205 | + 'ee_edit_message', |
|
| 206 | + array('Message_Template_Group', '', 'ee_edit_others_messages', 'ee_edit_global_messages') |
|
| 207 | + ), |
|
| 208 | + new EE_Meta_Capability_Map_Edit( |
|
| 209 | + 'ee_edit_default_ticket', |
|
| 210 | + array('Ticket', '', 'ee_edit_others_default_tickets', '') |
|
| 211 | + ), |
|
| 212 | + new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
| 213 | + 'ee_edit_question', |
|
| 214 | + array('Question', '', '', 'ee_edit_system_questions') |
|
| 215 | + ), |
|
| 216 | + new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
| 217 | + 'ee_edit_question_group', |
|
| 218 | + array('Question_Group', '', '', 'ee_edit_system_question_groups') |
|
| 219 | + ), |
|
| 220 | + new EE_Meta_Capability_Map_Edit( |
|
| 221 | + 'ee_edit_payment_method', |
|
| 222 | + array('Payment_Method', '', 'ee_edit_others_payment_methods', '') |
|
| 223 | + ), |
|
| 224 | + //reads |
|
| 225 | + new EE_Meta_Capability_Map_Read( |
|
| 226 | + 'ee_read_event', |
|
| 227 | + array('Event', '', 'ee_read_others_events', 'ee_read_private_events') |
|
| 228 | + ), |
|
| 229 | + new EE_Meta_Capability_Map_Read( |
|
| 230 | + 'ee_read_venue', |
|
| 231 | + array('Venue', '', 'ee_read_others_venues', 'ee_read_private_venues') |
|
| 232 | + ), |
|
| 233 | + new EE_Meta_Capability_Map_Read( |
|
| 234 | + 'ee_read_registration', |
|
| 235 | + array('Registration', '', 'ee_read_others_registrations', '') |
|
| 236 | + ), |
|
| 237 | + new EE_Meta_Capability_Map_Read( |
|
| 238 | + 'ee_read_checkin', |
|
| 239 | + array('Registration', '', 'ee_read_others_checkins', '') |
|
| 240 | + ), |
|
| 241 | + new EE_Meta_Capability_Map_Messages_Cap( |
|
| 242 | + 'ee_read_message', |
|
| 243 | + array('Message_Template_Group', '', 'ee_read_others_messages', 'ee_read_global_messages') |
|
| 244 | + ), |
|
| 245 | + new EE_Meta_Capability_Map_Read( |
|
| 246 | + 'ee_read_default_ticket', |
|
| 247 | + array('Ticket', '', 'ee_read_others_default_tickets', '') |
|
| 248 | + ), |
|
| 249 | + new EE_Meta_Capability_Map_Read( |
|
| 250 | + 'ee_read_payment_method', |
|
| 251 | + array('Payment_Method', '', 'ee_read_others_payment_methods', '') |
|
| 252 | + ), |
|
| 253 | + //deletes |
|
| 254 | + new EE_Meta_Capability_Map_Delete( |
|
| 255 | + 'ee_delete_event', |
|
| 256 | + array( |
|
| 257 | + 'Event', |
|
| 258 | + 'ee_delete_published_events', |
|
| 259 | + 'ee_delete_others_events', |
|
| 260 | + 'ee_delete_private_events', |
|
| 261 | + ) |
|
| 262 | + ), |
|
| 263 | + new EE_Meta_Capability_Map_Delete( |
|
| 264 | + 'ee_delete_venue', |
|
| 265 | + array( |
|
| 266 | + 'Venue', |
|
| 267 | + 'ee_delete_published_venues', |
|
| 268 | + 'ee_delete_others_venues', |
|
| 269 | + 'ee_delete_private_venues', |
|
| 270 | + ) |
|
| 271 | + ), |
|
| 272 | + new EE_Meta_Capability_Map_Delete( |
|
| 273 | + 'ee_delete_registration', |
|
| 274 | + array('Registration', '', 'ee_delete_others_registrations', '') |
|
| 275 | + ), |
|
| 276 | + new EE_Meta_Capability_Map_Delete( |
|
| 277 | + 'ee_delete_checkin', |
|
| 278 | + array('Registration', '', 'ee_delete_others_checkins', '') |
|
| 279 | + ), |
|
| 280 | + new EE_Meta_Capability_Map_Messages_Cap( |
|
| 281 | + 'ee_delete_message', |
|
| 282 | + array('Message_Template_Group', '', 'ee_delete_others_messages', 'ee_delete_global_messages') |
|
| 283 | + ), |
|
| 284 | + new EE_Meta_Capability_Map_Delete( |
|
| 285 | + 'ee_delete_default_ticket', |
|
| 286 | + array('Ticket', '', 'ee_delete_others_default_tickets', '') |
|
| 287 | + ), |
|
| 288 | + new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
| 289 | + 'ee_delete_question', |
|
| 290 | + array('Question', '', '', 'delete_system_questions') |
|
| 291 | + ), |
|
| 292 | + new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
| 293 | + 'ee_delete_question_group', |
|
| 294 | + array('Question_Group', '', '', 'delete_system_question_groups') |
|
| 295 | + ), |
|
| 296 | + new EE_Meta_Capability_Map_Delete( |
|
| 297 | + 'ee_delete_payment_method', |
|
| 298 | + array('Payment_Method', '', 'ee_delete_others_payment_methods', '') |
|
| 299 | + ), |
|
| 300 | + ); |
|
| 301 | + } |
|
| 302 | + return $default_meta_caps; |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + |
|
| 306 | + |
|
| 307 | + /** |
|
| 308 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 309 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 310 | + * |
|
| 311 | + * The actual logic is carried out by implementer classes in their definition of _map_meta_caps. |
|
| 312 | + * |
|
| 313 | + * @since 4.5.0 |
|
| 314 | + * @see wp-includes/capabilities.php |
|
| 315 | + * |
|
| 316 | + * @param array $caps actual users capabilities |
|
| 317 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 318 | + * @param int $user_id The user id |
|
| 319 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
| 320 | + * @return array actual users capabilities |
|
| 321 | + * @throws EE_Error |
|
| 322 | + */ |
|
| 323 | + public function map_meta_caps($caps, $cap, $user_id, $args) |
|
| 324 | + { |
|
| 325 | + if (did_action('AHEE__EE_System__load_espresso_addons__complete')) { |
|
| 326 | + //loop through our _meta_caps array |
|
| 327 | + foreach ($this->_meta_caps as $meta_map) { |
|
| 328 | + if (! $meta_map instanceof EE_Meta_Capability_Map) { |
|
| 329 | + continue; |
|
| 330 | + } |
|
| 331 | + // don't load models if there is no object ID in the args |
|
| 332 | + if (! empty($args[0])) { |
|
| 333 | + $meta_map->ensure_is_model(); |
|
| 334 | + } |
|
| 335 | + $caps = $meta_map->map_meta_caps($caps, $cap, $user_id, $args); |
|
| 336 | + } |
|
| 337 | + } |
|
| 338 | + return $caps; |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + |
|
| 342 | + |
|
| 343 | + /** |
|
| 344 | + * This sets up and returns the initial capabilities map for Event Espresso |
|
| 345 | + * Note this array is filtered. |
|
| 346 | + * It is assumed that all available EE capabilities are assigned to the administrator role. |
|
| 347 | + * |
|
| 348 | + * @since 4.5.0 |
|
| 349 | + * |
|
| 350 | + * @return array |
|
| 351 | + */ |
|
| 352 | + private function _init_caps_map() |
|
| 353 | + { |
|
| 354 | + return apply_filters( |
|
| 355 | + 'FHEE__EE_Capabilities__init_caps_map__caps', |
|
| 356 | + array( |
|
| 357 | + 'administrator' => array( |
|
| 358 | + //basic access |
|
| 359 | + 'ee_read_ee', |
|
| 360 | + //gateways |
|
| 361 | + /** |
|
| 362 | + * note that with payment method capabilities, although we've implemented |
|
| 363 | + * capability mapping which will be used for accessing payment methods owned by |
|
| 364 | + * other users. This is not fully implemented yet in the payment method ui. |
|
| 365 | + * Currently only the "plural" caps are in active use. |
|
| 366 | + * (Specific payment method caps are in use as well). |
|
| 367 | + **/ |
|
| 368 | + 'ee_manage_gateways', |
|
| 369 | + 'ee_read_payment_methods', |
|
| 370 | + 'ee_read_others_payment_methods', |
|
| 371 | + 'ee_edit_payment_methods', |
|
| 372 | + 'ee_edit_others_payment_methods', |
|
| 373 | + 'ee_delete_payment_methods', |
|
| 374 | + //events |
|
| 375 | + 'ee_publish_events', |
|
| 376 | + 'ee_read_private_events', |
|
| 377 | + 'ee_read_others_events', |
|
| 378 | + 'ee_read_events', |
|
| 379 | + 'ee_edit_events', |
|
| 380 | + 'ee_edit_published_events', |
|
| 381 | + 'ee_edit_others_events', |
|
| 382 | + 'ee_edit_private_events', |
|
| 383 | + 'ee_delete_published_events', |
|
| 384 | + 'ee_delete_private_events', |
|
| 385 | + 'ee_delete_events', |
|
| 386 | + 'ee_delete_others_events', |
|
| 387 | + //event categories |
|
| 388 | + 'ee_manage_event_categories', |
|
| 389 | + 'ee_edit_event_category', |
|
| 390 | + 'ee_delete_event_category', |
|
| 391 | + 'ee_assign_event_category', |
|
| 392 | + //venues |
|
| 393 | + 'ee_publish_venues', |
|
| 394 | + 'ee_read_venues', |
|
| 395 | + 'ee_read_others_venues', |
|
| 396 | + 'ee_read_private_venues', |
|
| 397 | + 'ee_edit_venues', |
|
| 398 | + 'ee_edit_others_venues', |
|
| 399 | + 'ee_edit_published_venues', |
|
| 400 | + 'ee_edit_private_venues', |
|
| 401 | + 'ee_delete_venues', |
|
| 402 | + 'ee_delete_others_venues', |
|
| 403 | + 'ee_delete_private_venues', |
|
| 404 | + 'ee_delete_published_venues', |
|
| 405 | + //venue categories |
|
| 406 | + 'ee_manage_venue_categories', |
|
| 407 | + 'ee_edit_venue_category', |
|
| 408 | + 'ee_delete_venue_category', |
|
| 409 | + 'ee_assign_venue_category', |
|
| 410 | + //contacts |
|
| 411 | + 'ee_read_contacts', |
|
| 412 | + 'ee_edit_contacts', |
|
| 413 | + 'ee_delete_contacts', |
|
| 414 | + //registrations |
|
| 415 | + 'ee_read_registrations', |
|
| 416 | + 'ee_read_others_registrations', |
|
| 417 | + 'ee_edit_registrations', |
|
| 418 | + 'ee_edit_others_registrations', |
|
| 419 | + 'ee_delete_registrations', |
|
| 420 | + //checkins |
|
| 421 | + 'ee_read_others_checkins', |
|
| 422 | + 'ee_read_checkins', |
|
| 423 | + 'ee_edit_checkins', |
|
| 424 | + 'ee_edit_others_checkins', |
|
| 425 | + 'ee_delete_checkins', |
|
| 426 | + 'ee_delete_others_checkins', |
|
| 427 | + //transactions && payments |
|
| 428 | + 'ee_read_transaction', |
|
| 429 | + 'ee_read_transactions', |
|
| 430 | + 'ee_edit_payments', |
|
| 431 | + 'ee_delete_payments', |
|
| 432 | + //messages |
|
| 433 | + 'ee_read_messages', |
|
| 434 | + 'ee_read_others_messages', |
|
| 435 | + 'ee_read_global_messages', |
|
| 436 | + 'ee_edit_global_messages', |
|
| 437 | + 'ee_edit_messages', |
|
| 438 | + 'ee_edit_others_messages', |
|
| 439 | + 'ee_delete_messages', |
|
| 440 | + 'ee_delete_others_messages', |
|
| 441 | + 'ee_delete_global_messages', |
|
| 442 | + 'ee_send_message', |
|
| 443 | + //tickets |
|
| 444 | + 'ee_read_default_tickets', |
|
| 445 | + 'ee_read_others_default_tickets', |
|
| 446 | + 'ee_edit_default_tickets', |
|
| 447 | + 'ee_edit_others_default_tickets', |
|
| 448 | + 'ee_delete_default_tickets', |
|
| 449 | + 'ee_delete_others_default_tickets', |
|
| 450 | + //prices |
|
| 451 | + 'ee_edit_default_price', |
|
| 452 | + 'ee_edit_default_prices', |
|
| 453 | + 'ee_delete_default_price', |
|
| 454 | + 'ee_delete_default_prices', |
|
| 455 | + 'ee_edit_default_price_type', |
|
| 456 | + 'ee_edit_default_price_types', |
|
| 457 | + 'ee_delete_default_price_type', |
|
| 458 | + 'ee_delete_default_price_types', |
|
| 459 | + 'ee_read_default_prices', |
|
| 460 | + 'ee_read_default_price_types', |
|
| 461 | + //registration form |
|
| 462 | + 'ee_edit_questions', |
|
| 463 | + 'ee_edit_system_questions', |
|
| 464 | + 'ee_read_questions', |
|
| 465 | + 'ee_delete_questions', |
|
| 466 | + 'ee_edit_question_groups', |
|
| 467 | + 'ee_read_question_groups', |
|
| 468 | + 'ee_edit_system_question_groups', |
|
| 469 | + 'ee_delete_question_groups', |
|
| 470 | + //event_type taxonomy |
|
| 471 | + 'ee_assign_event_type', |
|
| 472 | + 'ee_manage_event_types', |
|
| 473 | + 'ee_edit_event_type', |
|
| 474 | + 'ee_delete_event_type', |
|
| 475 | + ), |
|
| 476 | + 'ee_events_administrator' => array( |
|
| 477 | + //core wp caps |
|
| 478 | + 'read', |
|
| 479 | + 'read_private_pages', |
|
| 480 | + 'read_private_posts', |
|
| 481 | + 'edit_users', |
|
| 482 | + 'edit_posts', |
|
| 483 | + 'edit_pages', |
|
| 484 | + 'edit_published_posts', |
|
| 485 | + 'edit_published_pages', |
|
| 486 | + 'edit_private_pages', |
|
| 487 | + 'edit_private_posts', |
|
| 488 | + 'edit_others_posts', |
|
| 489 | + 'edit_others_pages', |
|
| 490 | + 'publish_posts', |
|
| 491 | + 'publish_pages', |
|
| 492 | + 'delete_posts', |
|
| 493 | + 'delete_pages', |
|
| 494 | + 'delete_private_pages', |
|
| 495 | + 'delete_private_posts', |
|
| 496 | + 'delete_published_pages', |
|
| 497 | + 'delete_published_posts', |
|
| 498 | + 'delete_others_posts', |
|
| 499 | + 'delete_others_pages', |
|
| 500 | + 'manage_categories', |
|
| 501 | + 'manage_links', |
|
| 502 | + 'moderate_comments', |
|
| 503 | + 'unfiltered_html', |
|
| 504 | + 'upload_files', |
|
| 505 | + 'export', |
|
| 506 | + 'import', |
|
| 507 | + 'list_users', |
|
| 508 | + 'level_1', //required if user with this role shows up in author dropdowns |
|
| 509 | + //basic ee access |
|
| 510 | + 'ee_read_ee', |
|
| 511 | + //events |
|
| 512 | + 'ee_publish_events', |
|
| 513 | + 'ee_read_private_events', |
|
| 514 | + 'ee_read_others_events', |
|
| 515 | + 'ee_read_event', |
|
| 516 | + 'ee_read_events', |
|
| 517 | + 'ee_edit_event', |
|
| 518 | + 'ee_edit_events', |
|
| 519 | + 'ee_edit_published_events', |
|
| 520 | + 'ee_edit_others_events', |
|
| 521 | + 'ee_edit_private_events', |
|
| 522 | + 'ee_delete_published_events', |
|
| 523 | + 'ee_delete_private_events', |
|
| 524 | + 'ee_delete_event', |
|
| 525 | + 'ee_delete_events', |
|
| 526 | + 'ee_delete_others_events', |
|
| 527 | + //event categories |
|
| 528 | + 'ee_manage_event_categories', |
|
| 529 | + 'ee_edit_event_category', |
|
| 530 | + 'ee_delete_event_category', |
|
| 531 | + 'ee_assign_event_category', |
|
| 532 | + //venues |
|
| 533 | + 'ee_publish_venues', |
|
| 534 | + 'ee_read_venue', |
|
| 535 | + 'ee_read_venues', |
|
| 536 | + 'ee_read_others_venues', |
|
| 537 | + 'ee_read_private_venues', |
|
| 538 | + 'ee_edit_venue', |
|
| 539 | + 'ee_edit_venues', |
|
| 540 | + 'ee_edit_others_venues', |
|
| 541 | + 'ee_edit_published_venues', |
|
| 542 | + 'ee_edit_private_venues', |
|
| 543 | + 'ee_delete_venue', |
|
| 544 | + 'ee_delete_venues', |
|
| 545 | + 'ee_delete_others_venues', |
|
| 546 | + 'ee_delete_private_venues', |
|
| 547 | + 'ee_delete_published_venues', |
|
| 548 | + //venue categories |
|
| 549 | + 'ee_manage_venue_categories', |
|
| 550 | + 'ee_edit_venue_category', |
|
| 551 | + 'ee_delete_venue_category', |
|
| 552 | + 'ee_assign_venue_category', |
|
| 553 | + //contacts |
|
| 554 | + 'ee_read_contacts', |
|
| 555 | + 'ee_edit_contacts', |
|
| 556 | + 'ee_delete_contacts', |
|
| 557 | + //registrations |
|
| 558 | + 'ee_read_registrations', |
|
| 559 | + 'ee_read_others_registrations', |
|
| 560 | + 'ee_edit_registration', |
|
| 561 | + 'ee_edit_registrations', |
|
| 562 | + 'ee_edit_others_registrations', |
|
| 563 | + 'ee_delete_registration', |
|
| 564 | + 'ee_delete_registrations', |
|
| 565 | + //checkins |
|
| 566 | + 'ee_read_others_checkins', |
|
| 567 | + 'ee_read_checkins', |
|
| 568 | + 'ee_edit_checkins', |
|
| 569 | + 'ee_edit_others_checkins', |
|
| 570 | + 'ee_delete_checkins', |
|
| 571 | + 'ee_delete_others_checkins', |
|
| 572 | + //transactions && payments |
|
| 573 | + 'ee_read_transaction', |
|
| 574 | + 'ee_read_transactions', |
|
| 575 | + 'ee_edit_payments', |
|
| 576 | + 'ee_delete_payments', |
|
| 577 | + //messages |
|
| 578 | + 'ee_read_messages', |
|
| 579 | + 'ee_read_others_messages', |
|
| 580 | + 'ee_read_global_messages', |
|
| 581 | + 'ee_edit_global_messages', |
|
| 582 | + 'ee_edit_messages', |
|
| 583 | + 'ee_edit_others_messages', |
|
| 584 | + 'ee_delete_messages', |
|
| 585 | + 'ee_delete_others_messages', |
|
| 586 | + 'ee_delete_global_messages', |
|
| 587 | + 'ee_send_message', |
|
| 588 | + //tickets |
|
| 589 | + 'ee_read_default_tickets', |
|
| 590 | + 'ee_read_others_default_tickets', |
|
| 591 | + 'ee_edit_default_tickets', |
|
| 592 | + 'ee_edit_others_default_tickets', |
|
| 593 | + 'ee_delete_default_tickets', |
|
| 594 | + 'ee_delete_others_default_tickets', |
|
| 595 | + //prices |
|
| 596 | + 'ee_edit_default_price', |
|
| 597 | + 'ee_edit_default_prices', |
|
| 598 | + 'ee_delete_default_price', |
|
| 599 | + 'ee_delete_default_prices', |
|
| 600 | + 'ee_edit_default_price_type', |
|
| 601 | + 'ee_edit_default_price_types', |
|
| 602 | + 'ee_delete_default_price_type', |
|
| 603 | + 'ee_delete_default_price_types', |
|
| 604 | + 'ee_read_default_prices', |
|
| 605 | + 'ee_read_default_price_types', |
|
| 606 | + //registration form |
|
| 607 | + 'ee_edit_questions', |
|
| 608 | + 'ee_edit_system_questions', |
|
| 609 | + 'ee_read_questions', |
|
| 610 | + 'ee_delete_questions', |
|
| 611 | + 'ee_edit_question_groups', |
|
| 612 | + 'ee_read_question_groups', |
|
| 613 | + 'ee_edit_system_question_groups', |
|
| 614 | + 'ee_delete_question_groups', |
|
| 615 | + //event_type taxonomy |
|
| 616 | + 'ee_assign_event_type', |
|
| 617 | + 'ee_manage_event_types', |
|
| 618 | + 'ee_edit_event_type', |
|
| 619 | + 'ee_delete_event_type', |
|
| 620 | + ) |
|
| 621 | + ) |
|
| 622 | + ); |
|
| 623 | + } |
|
| 624 | + |
|
| 625 | + |
|
| 626 | + |
|
| 627 | + /** |
|
| 628 | + * @return bool |
|
| 629 | + * @throws EE_Error |
|
| 630 | + */ |
|
| 631 | + private function setupCapabilitiesMap() |
|
| 632 | + { |
|
| 633 | + // if the initialization process hasn't even started, then we need to call init_caps() |
|
| 634 | + if($this->initialized === null) { |
|
| 635 | + return $this->init_caps(); |
|
| 636 | + } |
|
| 637 | + // unless resetting, get caps from db if we haven't already |
|
| 638 | + $this->capabilities_map = $this->reset || ! empty($this->capabilities_map) |
|
| 639 | + ? $this->capabilities_map |
|
| 640 | + : get_option(self::option_name, array()); |
|
| 641 | + return true; |
|
| 642 | + } |
|
| 643 | + |
|
| 644 | + |
|
| 645 | + |
|
| 646 | + /** |
|
| 647 | + * @param bool $update |
|
| 648 | + * @return bool |
|
| 649 | + */ |
|
| 650 | + private function updateCapabilitiesMap($update = true) |
|
| 651 | + { |
|
| 652 | + return $update ? update_option(self::option_name, $this->capabilities_map) : false; |
|
| 653 | + } |
|
| 654 | + |
|
| 655 | + |
|
| 656 | + |
|
| 657 | + /** |
|
| 658 | + * Adds capabilities to roles. |
|
| 659 | + * |
|
| 660 | + * @since 4.9.42 |
|
| 661 | + * @param array $capabilities_to_add array of capabilities to add, indexed by roles. |
|
| 662 | + * Note that this should ONLY be called on activation hook |
|
| 663 | + * otherwise the caps will be added on every request. |
|
| 664 | + * @return bool |
|
| 665 | + * @throws \EE_Error |
|
| 666 | + */ |
|
| 667 | + public function addCaps(array $capabilities_to_add) |
|
| 668 | + { |
|
| 669 | + // don't do anything if the capabilities map can not be initialized |
|
| 670 | + if (! $this->setupCapabilitiesMap()) { |
|
| 671 | + return false; |
|
| 672 | + } |
|
| 673 | + // and filter the array so others can get in on the fun during resets |
|
| 674 | + $capabilities_to_add = apply_filters( |
|
| 675 | + 'FHEE__EE_Capabilities__addCaps__capabilities_to_add', |
|
| 676 | + $capabilities_to_add, |
|
| 677 | + $this->reset, |
|
| 678 | + $this->capabilities_map |
|
| 679 | + ); |
|
| 680 | + $update_capabilities_map = false; |
|
| 681 | + // if not reset, see what caps are new for each role. if they're new, add them. |
|
| 682 | + foreach ($capabilities_to_add as $role => $caps_for_role) { |
|
| 683 | + if (is_array($caps_for_role)) { |
|
| 684 | + foreach ($caps_for_role as $cap) { |
|
| 685 | + if ( |
|
| 686 | + ! $this->capHasBeenAddedToRole($role, $cap) |
|
| 687 | + && $this->add_cap_to_role($role, $cap, true, false) |
|
| 688 | + ) { |
|
| 689 | + $update_capabilities_map = true; |
|
| 690 | + } |
|
| 691 | + } |
|
| 692 | + } |
|
| 693 | + } |
|
| 694 | + // now let's just save the cap that has been set but only if there's been a change. |
|
| 695 | + $updated = $this->updateCapabilitiesMap($update_capabilities_map); |
|
| 696 | + $this->flushWpUser($updated); |
|
| 697 | + do_action('AHEE__EE_Capabilities__addCaps__complete', $this->capabilities_map, $updated); |
|
| 698 | + return $updated; |
|
| 699 | + } |
|
| 700 | + |
|
| 701 | + |
|
| 702 | + |
|
| 703 | + /** |
|
| 704 | + * Loops through the capabilities map and removes the role caps specified by the incoming array |
|
| 705 | + * |
|
| 706 | + * @param array $caps_map map of capabilities to be removed (indexed by roles) |
|
| 707 | + * @return bool |
|
| 708 | + * @throws \EE_Error |
|
| 709 | + */ |
|
| 710 | + public function removeCaps($caps_map) |
|
| 711 | + { |
|
| 712 | + // don't do anything if the capabilities map can not be initialized |
|
| 713 | + if (! $this->setupCapabilitiesMap()) { |
|
| 714 | + return false; |
|
| 715 | + } |
|
| 716 | + $update_capabilities_map = false; |
|
| 717 | + foreach ($caps_map as $role => $caps_for_role) { |
|
| 718 | + if (is_array($caps_for_role)) { |
|
| 719 | + foreach ($caps_for_role as $cap) { |
|
| 720 | + if ($this->capHasBeenAddedToRole($role, $cap) |
|
| 721 | + && $this->remove_cap_from_role($role, $cap, false) |
|
| 722 | + ) { |
|
| 723 | + $update_capabilities_map = true; |
|
| 724 | + } |
|
| 725 | + } |
|
| 726 | + } |
|
| 727 | + } |
|
| 728 | + // maybe resave the caps |
|
| 729 | + $updated = $this->updateCapabilitiesMap($update_capabilities_map); |
|
| 730 | + $this->flushWpUser($updated); |
|
| 731 | + return $updated; |
|
| 732 | + } |
|
| 733 | + |
|
| 734 | + |
|
| 735 | + /** |
|
| 736 | + * This ensures that the WP User object cached on the $current_user global in WP has the latest capabilities from |
|
| 737 | + * the roles on that user. |
|
| 738 | + * |
|
| 739 | + * @param bool $flush Default is to flush the WP_User object. If false, then this method effectively does nothing. |
|
| 740 | + */ |
|
| 741 | + private function flushWpUser($flush = true) |
|
| 742 | + { |
|
| 743 | + if ($flush) { |
|
| 744 | + $user = wp_get_current_user(); |
|
| 745 | + if ($user instanceof WP_User) { |
|
| 746 | + $user->get_role_caps(); |
|
| 747 | + } |
|
| 748 | + } |
|
| 749 | + } |
|
| 750 | + |
|
| 751 | + |
|
| 752 | + |
|
| 753 | + /** |
|
| 754 | + * This method sets a capability on a role. Note this should only be done on activation, or if you have something |
|
| 755 | + * specific to prevent the cap from being added on every page load (adding caps are persistent to the db). Note. |
|
| 756 | + * this is a wrapper for $wp_role->add_cap() |
|
| 757 | + * |
|
| 758 | + * @see wp-includes/capabilities.php |
|
| 759 | + * @since 4.5.0 |
|
| 760 | + * @param string|WP_Role $role A WordPress role the capability is being added to |
|
| 761 | + * @param string $cap The capability being added to the role |
|
| 762 | + * @param bool $grant Whether to grant access to this cap on this role. |
|
| 763 | + * @param bool $update_capabilities_map |
|
| 764 | + * @return bool |
|
| 765 | + * @throws \EE_Error |
|
| 766 | + */ |
|
| 767 | + public function add_cap_to_role($role, $cap, $grant = true, $update_capabilities_map = true) |
|
| 768 | + { |
|
| 769 | + // capture incoming value for $role because we may need it to create a new WP_Role |
|
| 770 | + $orig_role = $role; |
|
| 771 | + $role = $role instanceof WP_Role ? $role : get_role($role); |
|
| 772 | + //if the role isn't available then we create it. |
|
| 773 | + if (! $role instanceof WP_Role) { |
|
| 774 | + // if a plugin wants to create a specific role name then they should create the role before |
|
| 775 | + // EE_Capabilities does. Otherwise this function will create the role name from the slug: |
|
| 776 | + // - removes any `ee_` namespacing from the start of the slug. |
|
| 777 | + // - replaces `_` with ` ` (empty space). |
|
| 778 | + // - sentence case on the resulting string. |
|
| 779 | + $role_label = ucwords(str_replace(array('ee_', '_'), array('', ' '), $orig_role)); |
|
| 780 | + $role = add_role($orig_role, $role_label); |
|
| 781 | + } |
|
| 782 | + if ($role instanceof WP_Role) { |
|
| 783 | + // don't do anything if the capabilities map can not be initialized |
|
| 784 | + if (! $this->setupCapabilitiesMap()) { |
|
| 785 | + return false; |
|
| 786 | + } |
|
| 787 | + if (! $this->capHasBeenAddedToRole($role->name, $cap)) { |
|
| 788 | + $role->add_cap($cap, $grant); |
|
| 789 | + $this->capabilities_map[ $role->name ][] = $cap; |
|
| 790 | + $this->updateCapabilitiesMap($update_capabilities_map); |
|
| 791 | + return true; |
|
| 792 | + } |
|
| 793 | + } |
|
| 794 | + return false; |
|
| 795 | + } |
|
| 796 | + |
|
| 797 | + |
|
| 798 | + |
|
| 799 | + /** |
|
| 800 | + * Functions similarly to add_cap_to_role except removes cap from given role. |
|
| 801 | + * Wrapper for $wp_role->remove_cap() |
|
| 802 | + * |
|
| 803 | + * @see wp-includes/capabilities.php |
|
| 804 | + * @since 4.5.0 |
|
| 805 | + * @param string|WP_Role $role A WordPress role the capability is being removed from. |
|
| 806 | + * @param string $cap The capability being removed |
|
| 807 | + * @param bool $update_capabilities_map |
|
| 808 | + * @return bool |
|
| 809 | + * @throws \EE_Error |
|
| 810 | + */ |
|
| 811 | + public function remove_cap_from_role($role, $cap, $update_capabilities_map = true) |
|
| 812 | + { |
|
| 813 | + // don't do anything if the capabilities map can not be initialized |
|
| 814 | + if (! $this->setupCapabilitiesMap()) { |
|
| 815 | + return false; |
|
| 816 | + } |
|
| 817 | + |
|
| 818 | + $role = $role instanceof WP_Role ? $role : get_role($role); |
|
| 819 | + if ($role instanceof WP_Role && $index = $this->capHasBeenAddedToRole($role->name, $cap, true)) { |
|
| 820 | + $role->remove_cap($cap); |
|
| 821 | + unset($this->capabilities_map[ $role->name ][ $index ]); |
|
| 822 | + $this->updateCapabilitiesMap($update_capabilities_map); |
|
| 823 | + return true; |
|
| 824 | + } |
|
| 825 | + return false; |
|
| 826 | + } |
|
| 827 | + |
|
| 828 | + |
|
| 829 | + |
|
| 830 | + /** |
|
| 831 | + * @param string $role_name |
|
| 832 | + * @param string $cap |
|
| 833 | + * @param bool $get_index |
|
| 834 | + * @return bool|mixed |
|
| 835 | + */ |
|
| 836 | + private function capHasBeenAddedToRole($role_name='', $cap='', $get_index = false) |
|
| 837 | + { |
|
| 838 | + if ( |
|
| 839 | + isset($this->capabilities_map[$role_name]) |
|
| 840 | + && ($index = array_search($cap, $this->capabilities_map[$role_name], true)) !== false |
|
| 841 | + ) { |
|
| 842 | + return $get_index ? $index : true; |
|
| 843 | + } |
|
| 844 | + return false; |
|
| 845 | + } |
|
| 846 | + |
|
| 847 | + |
|
| 848 | + |
|
| 849 | + /** |
|
| 850 | + * Wrapper for the native WP current_user_can() method. |
|
| 851 | + * This is provided as a handy method for a couple things: |
|
| 852 | + * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to |
|
| 853 | + * write those filters wherever current_user_can is called). |
|
| 854 | + * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters ) |
|
| 855 | + * |
|
| 856 | + * @since 4.5.0 |
|
| 857 | + * |
|
| 858 | + * @param string $cap The cap being checked. |
|
| 859 | + * @param string $context The context where the current_user_can is being called from. |
|
| 860 | + * @param int $id Optional. Id for item where current_user_can is being called from (used in map_meta_cap() |
|
| 861 | + * filters. |
|
| 862 | + * |
|
| 863 | + * @return bool Whether user can or not. |
|
| 864 | + */ |
|
| 865 | + public function current_user_can($cap, $context, $id = 0) |
|
| 866 | + { |
|
| 867 | + //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
| 868 | + $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__' . $context, $cap, $id); |
|
| 869 | + $filtered_cap = apply_filters( |
|
| 870 | + 'FHEE__EE_Capabilities__current_user_can__cap', |
|
| 871 | + $filtered_cap, |
|
| 872 | + $context, |
|
| 873 | + $cap, |
|
| 874 | + $id |
|
| 875 | + ); |
|
| 876 | + return ! empty($id) |
|
| 877 | + ? current_user_can($filtered_cap, $id) |
|
| 878 | + : current_user_can($filtered_cap); |
|
| 879 | + } |
|
| 880 | + |
|
| 881 | + |
|
| 882 | + |
|
| 883 | + /** |
|
| 884 | + * This is a wrapper for the WP user_can() function and follows the same style as the other wrappers in this class. |
|
| 885 | + * |
|
| 886 | + * @param int|WP_User $user Either the user_id or a WP_User object |
|
| 887 | + * @param string $cap The capability string being checked |
|
| 888 | + * @param string $context The context where the user_can is being called from (used in filters). |
|
| 889 | + * @param int $id Optional. Id for item where user_can is being called from ( used in map_meta_cap() |
|
| 890 | + * filters) |
|
| 891 | + * |
|
| 892 | + * @return bool Whether user can or not. |
|
| 893 | + */ |
|
| 894 | + public function user_can($user, $cap, $context, $id = 0) |
|
| 895 | + { |
|
| 896 | + //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
| 897 | + $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__' . $context, $cap, $user, $id); |
|
| 898 | + $filtered_cap = apply_filters( |
|
| 899 | + 'FHEE__EE_Capabilities__user_can__cap', |
|
| 900 | + $filtered_cap, |
|
| 901 | + $context, |
|
| 902 | + $cap, |
|
| 903 | + $user, |
|
| 904 | + $id |
|
| 905 | + ); |
|
| 906 | + return ! empty($id) |
|
| 907 | + ? user_can($user, $filtered_cap, $id) |
|
| 908 | + : user_can($user, $filtered_cap); |
|
| 909 | + } |
|
| 910 | + |
|
| 911 | + |
|
| 912 | + |
|
| 913 | + /** |
|
| 914 | + * Wrapper for the native WP current_user_can_for_blog() method. |
|
| 915 | + * This is provided as a handy method for a couple things: |
|
| 916 | + * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to |
|
| 917 | + * write those filters wherever current_user_can is called). |
|
| 918 | + * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters ) |
|
| 919 | + * |
|
| 920 | + * @since 4.5.0 |
|
| 921 | + * |
|
| 922 | + * @param int $blog_id The blog id that is being checked for. |
|
| 923 | + * @param string $cap The cap being checked. |
|
| 924 | + * @param string $context The context where the current_user_can is being called from. |
|
| 925 | + * @param int $id Optional. Id for item where current_user_can is being called from (used in map_meta_cap() |
|
| 926 | + * filters. |
|
| 927 | + * |
|
| 928 | + * @return bool Whether user can or not. |
|
| 929 | + */ |
|
| 930 | + public function current_user_can_for_blog($blog_id, $cap, $context, $id = 0) |
|
| 931 | + { |
|
| 932 | + $user_can = ! empty($id) |
|
| 933 | + ? current_user_can_for_blog($blog_id, $cap, $id) |
|
| 934 | + : current_user_can($blog_id, $cap); |
|
| 935 | + //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
| 936 | + $user_can = apply_filters( |
|
| 937 | + 'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__' . $context, |
|
| 938 | + $user_can, |
|
| 939 | + $blog_id, |
|
| 940 | + $cap, |
|
| 941 | + $id |
|
| 942 | + ); |
|
| 943 | + $user_can = apply_filters( |
|
| 944 | + 'FHEE__EE_Capabilities__current_user_can_for_blog__user_can', |
|
| 945 | + $user_can, |
|
| 946 | + $context, |
|
| 947 | + $blog_id, |
|
| 948 | + $cap, |
|
| 949 | + $id |
|
| 950 | + ); |
|
| 951 | + return $user_can; |
|
| 952 | + } |
|
| 953 | + |
|
| 954 | + |
|
| 955 | + |
|
| 956 | + /** |
|
| 957 | + * This helper method just returns an array of registered EE capabilities. |
|
| 958 | + * |
|
| 959 | + * @since 4.5.0 |
|
| 960 | + * @param string $role If empty then the entire role/capability map is returned. |
|
| 961 | + * Otherwise just the capabilities for the given role are returned. |
|
| 962 | + * @return array |
|
| 963 | + * @throws EE_Error |
|
| 964 | + */ |
|
| 965 | + public function get_ee_capabilities($role = 'administrator') |
|
| 966 | + { |
|
| 967 | + if (! $this->initialized) { |
|
| 968 | + $this->init_caps(); |
|
| 969 | + } |
|
| 970 | + if (empty($role)) { |
|
| 971 | + return $this->capabilities_map; |
|
| 972 | + } |
|
| 973 | + return isset($this->capabilities_map[ $role ]) |
|
| 974 | + ? $this->capabilities_map[ $role ] |
|
| 975 | + : array(); |
|
| 976 | + } |
|
| 977 | + |
|
| 978 | + |
|
| 979 | + |
|
| 980 | + /** |
|
| 981 | + * @deprecated 4.9.42 |
|
| 982 | + * @param bool $reset If you need to reset Event Espresso's capabilities, |
|
| 983 | + * then please use the init_caps() method with the "$reset" parameter set to "true" |
|
| 984 | + * @param array $caps_map Optional. |
|
| 985 | + * Can be used to send a custom map of roles and capabilities for setting them up. |
|
| 986 | + * Note that this should ONLY be called on activation hook or some other one-time |
|
| 987 | + * task otherwise the caps will be added on every request. |
|
| 988 | + * @return void |
|
| 989 | + * @throws EE_Error |
|
| 990 | + */ |
|
| 991 | + public function init_role_caps($reset = false, $caps_map = array()) |
|
| 992 | + { |
|
| 993 | + // If this method is called directly and reset is set as 'true', |
|
| 994 | + // then display a doing it wrong notice, because we want resets to go through init_caps() |
|
| 995 | + // to guarantee that everything is set up correctly. |
|
| 996 | + // This prevents the capabilities map getting reset incorrectly by direct calls to this method. |
|
| 997 | + if ($reset) { |
|
| 998 | + EE_Error::doing_it_wrong( |
|
| 999 | + __METHOD__, |
|
| 1000 | + sprintf( |
|
| 1001 | + esc_html__( |
|
| 1002 | + 'The "%1$s" parameter for the "%2$s" method is deprecated. If you need to reset Event Espresso\'s capabilities, then please use the "%3$s" method with the "%1$s" parameter set to "%4$s".', |
|
| 1003 | + 'event_espresso' |
|
| 1004 | + ), |
|
| 1005 | + '$reset', |
|
| 1006 | + __METHOD__ . '()', |
|
| 1007 | + 'EE_Capabilities::init_caps()', |
|
| 1008 | + 'true' |
|
| 1009 | + ), |
|
| 1010 | + '4.9.42', |
|
| 1011 | + '5.0.0' |
|
| 1012 | + ); |
|
| 1013 | + } |
|
| 1014 | + $this->addCaps($caps_map); |
|
| 1015 | + } |
|
| 1016 | 1016 | |
| 1017 | 1017 | |
| 1018 | 1018 | |
@@ -1033,142 +1033,142 @@ discard block |
||
| 1033 | 1033 | abstract class EE_Meta_Capability_Map |
| 1034 | 1034 | { |
| 1035 | 1035 | |
| 1036 | - public $meta_cap; |
|
| 1037 | - |
|
| 1038 | - /** |
|
| 1039 | - * @var EEM_Base |
|
| 1040 | - */ |
|
| 1041 | - protected $_model; |
|
| 1042 | - |
|
| 1043 | - protected $_model_name; |
|
| 1044 | - |
|
| 1045 | - public $published_cap = ''; |
|
| 1046 | - |
|
| 1047 | - public $others_cap = ''; |
|
| 1048 | - |
|
| 1049 | - public $private_cap = ''; |
|
| 1050 | - |
|
| 1051 | - |
|
| 1052 | - /** |
|
| 1053 | - * constructor. |
|
| 1054 | - * Receives the setup arguments for the map. |
|
| 1055 | - * |
|
| 1056 | - * @since 4.5.0 |
|
| 1057 | - * |
|
| 1058 | - * @param string $meta_cap What meta capability is this mapping. |
|
| 1059 | - * @param array $map_values array { |
|
| 1060 | - * //array of values that MUST match a count of 4. It's okay to send an empty string for |
|
| 1061 | - * capabilities that don't get mapped to. |
|
| 1062 | - * |
|
| 1063 | - * @type $map_values [0] string A string representing the model name. Required. String's |
|
| 1064 | - * should always be used when Menu Maps are registered via the |
|
| 1065 | - * plugin API as models are not allowed to be instantiated when |
|
| 1066 | - * in maintenance mode 2 (migrations). |
|
| 1067 | - * @type $map_values [1] string represents the capability used for published. Optional. |
|
| 1068 | - * @type $map_values [2] string represents the capability used for "others". Optional. |
|
| 1069 | - * @type $map_values [3] string represents the capability used for private. Optional. |
|
| 1070 | - * } |
|
| 1071 | - * @throws EE_Error |
|
| 1072 | - */ |
|
| 1073 | - public function __construct($meta_cap, $map_values) |
|
| 1074 | - { |
|
| 1075 | - $this->meta_cap = $meta_cap; |
|
| 1076 | - //verify there are four args in the $map_values array; |
|
| 1077 | - if (count($map_values) !== 4) { |
|
| 1078 | - throw new EE_Error( |
|
| 1079 | - sprintf( |
|
| 1080 | - __( |
|
| 1081 | - 'Incoming $map_values array should have a count of four values in it. This is what was given: %s', |
|
| 1082 | - 'event_espresso' |
|
| 1083 | - ), |
|
| 1084 | - '<br>' . print_r($map_values, true) |
|
| 1085 | - ) |
|
| 1086 | - ); |
|
| 1087 | - } |
|
| 1088 | - //set properties |
|
| 1089 | - $this->_model = null; |
|
| 1090 | - $this->_model_name = $map_values[0]; |
|
| 1091 | - $this->published_cap = (string)$map_values[1]; |
|
| 1092 | - $this->others_cap = (string)$map_values[2]; |
|
| 1093 | - $this->private_cap = (string)$map_values[3]; |
|
| 1094 | - } |
|
| 1095 | - |
|
| 1096 | - /** |
|
| 1097 | - * Makes it so this object stops filtering caps |
|
| 1098 | - */ |
|
| 1099 | - public function remove_filters() |
|
| 1100 | - { |
|
| 1101 | - remove_filter('map_meta_cap', array($this, 'map_meta_caps'), 10); |
|
| 1102 | - } |
|
| 1103 | - |
|
| 1104 | - |
|
| 1105 | - /** |
|
| 1106 | - * This method ensures that the $model property is converted from the model name string to a proper EEM_Base class |
|
| 1107 | - * |
|
| 1108 | - * @since 4.5.0 |
|
| 1109 | - * @throws EE_Error |
|
| 1110 | - * |
|
| 1111 | - * @return void |
|
| 1112 | - */ |
|
| 1113 | - public function ensure_is_model() |
|
| 1114 | - { |
|
| 1115 | - //is it already instantiated? |
|
| 1116 | - if ($this->_model instanceof EEM_Base) { |
|
| 1117 | - return; |
|
| 1118 | - } |
|
| 1119 | - //ensure model name is string |
|
| 1120 | - $this->_model_name = (string)$this->_model_name; |
|
| 1121 | - //error proof if the name has EEM in it |
|
| 1122 | - $this->_model_name = str_replace('EEM', '', $this->_model_name); |
|
| 1123 | - $this->_model = EE_Registry::instance()->load_model($this->_model_name); |
|
| 1124 | - if (! $this->_model instanceof EEM_Base) { |
|
| 1125 | - throw new EE_Error( |
|
| 1126 | - sprintf( |
|
| 1127 | - __( |
|
| 1128 | - 'This string passed in to %s to represent a EEM_Base model class was not able to be used to instantiate the class. Please ensure that the string is a match for the EEM_Base model name (not including the EEM_ part). This was given: %s', |
|
| 1129 | - 'event_espresso' |
|
| 1130 | - ), |
|
| 1131 | - get_class($this), |
|
| 1132 | - $this->_model |
|
| 1133 | - ) |
|
| 1134 | - ); |
|
| 1135 | - } |
|
| 1136 | - } |
|
| 1137 | - |
|
| 1138 | - |
|
| 1139 | - /** |
|
| 1140 | - * |
|
| 1141 | - * @see EE_Meta_Capability_Map::_map_meta_caps() for docs on params. |
|
| 1142 | - * @since 4.6.x |
|
| 1143 | - * |
|
| 1144 | - * @param $caps |
|
| 1145 | - * @param $cap |
|
| 1146 | - * @param $user_id |
|
| 1147 | - * @param $args |
|
| 1148 | - * |
|
| 1149 | - * @return array |
|
| 1150 | - */ |
|
| 1151 | - public function map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1152 | - { |
|
| 1153 | - return $this->_map_meta_caps($caps, $cap, $user_id, $args); |
|
| 1154 | - } |
|
| 1155 | - |
|
| 1156 | - |
|
| 1157 | - /** |
|
| 1158 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1159 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1160 | - * |
|
| 1161 | - * @since 4.5.0 |
|
| 1162 | - * @see wp-includes/capabilities.php |
|
| 1163 | - * |
|
| 1164 | - * @param array $caps actual users capabilities |
|
| 1165 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1166 | - * @param int $user_id The user id |
|
| 1167 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1168 | - * |
|
| 1169 | - * @return array actual users capabilities |
|
| 1170 | - */ |
|
| 1171 | - abstract protected function _map_meta_caps($caps, $cap, $user_id, $args); |
|
| 1036 | + public $meta_cap; |
|
| 1037 | + |
|
| 1038 | + /** |
|
| 1039 | + * @var EEM_Base |
|
| 1040 | + */ |
|
| 1041 | + protected $_model; |
|
| 1042 | + |
|
| 1043 | + protected $_model_name; |
|
| 1044 | + |
|
| 1045 | + public $published_cap = ''; |
|
| 1046 | + |
|
| 1047 | + public $others_cap = ''; |
|
| 1048 | + |
|
| 1049 | + public $private_cap = ''; |
|
| 1050 | + |
|
| 1051 | + |
|
| 1052 | + /** |
|
| 1053 | + * constructor. |
|
| 1054 | + * Receives the setup arguments for the map. |
|
| 1055 | + * |
|
| 1056 | + * @since 4.5.0 |
|
| 1057 | + * |
|
| 1058 | + * @param string $meta_cap What meta capability is this mapping. |
|
| 1059 | + * @param array $map_values array { |
|
| 1060 | + * //array of values that MUST match a count of 4. It's okay to send an empty string for |
|
| 1061 | + * capabilities that don't get mapped to. |
|
| 1062 | + * |
|
| 1063 | + * @type $map_values [0] string A string representing the model name. Required. String's |
|
| 1064 | + * should always be used when Menu Maps are registered via the |
|
| 1065 | + * plugin API as models are not allowed to be instantiated when |
|
| 1066 | + * in maintenance mode 2 (migrations). |
|
| 1067 | + * @type $map_values [1] string represents the capability used for published. Optional. |
|
| 1068 | + * @type $map_values [2] string represents the capability used for "others". Optional. |
|
| 1069 | + * @type $map_values [3] string represents the capability used for private. Optional. |
|
| 1070 | + * } |
|
| 1071 | + * @throws EE_Error |
|
| 1072 | + */ |
|
| 1073 | + public function __construct($meta_cap, $map_values) |
|
| 1074 | + { |
|
| 1075 | + $this->meta_cap = $meta_cap; |
|
| 1076 | + //verify there are four args in the $map_values array; |
|
| 1077 | + if (count($map_values) !== 4) { |
|
| 1078 | + throw new EE_Error( |
|
| 1079 | + sprintf( |
|
| 1080 | + __( |
|
| 1081 | + 'Incoming $map_values array should have a count of four values in it. This is what was given: %s', |
|
| 1082 | + 'event_espresso' |
|
| 1083 | + ), |
|
| 1084 | + '<br>' . print_r($map_values, true) |
|
| 1085 | + ) |
|
| 1086 | + ); |
|
| 1087 | + } |
|
| 1088 | + //set properties |
|
| 1089 | + $this->_model = null; |
|
| 1090 | + $this->_model_name = $map_values[0]; |
|
| 1091 | + $this->published_cap = (string)$map_values[1]; |
|
| 1092 | + $this->others_cap = (string)$map_values[2]; |
|
| 1093 | + $this->private_cap = (string)$map_values[3]; |
|
| 1094 | + } |
|
| 1095 | + |
|
| 1096 | + /** |
|
| 1097 | + * Makes it so this object stops filtering caps |
|
| 1098 | + */ |
|
| 1099 | + public function remove_filters() |
|
| 1100 | + { |
|
| 1101 | + remove_filter('map_meta_cap', array($this, 'map_meta_caps'), 10); |
|
| 1102 | + } |
|
| 1103 | + |
|
| 1104 | + |
|
| 1105 | + /** |
|
| 1106 | + * This method ensures that the $model property is converted from the model name string to a proper EEM_Base class |
|
| 1107 | + * |
|
| 1108 | + * @since 4.5.0 |
|
| 1109 | + * @throws EE_Error |
|
| 1110 | + * |
|
| 1111 | + * @return void |
|
| 1112 | + */ |
|
| 1113 | + public function ensure_is_model() |
|
| 1114 | + { |
|
| 1115 | + //is it already instantiated? |
|
| 1116 | + if ($this->_model instanceof EEM_Base) { |
|
| 1117 | + return; |
|
| 1118 | + } |
|
| 1119 | + //ensure model name is string |
|
| 1120 | + $this->_model_name = (string)$this->_model_name; |
|
| 1121 | + //error proof if the name has EEM in it |
|
| 1122 | + $this->_model_name = str_replace('EEM', '', $this->_model_name); |
|
| 1123 | + $this->_model = EE_Registry::instance()->load_model($this->_model_name); |
|
| 1124 | + if (! $this->_model instanceof EEM_Base) { |
|
| 1125 | + throw new EE_Error( |
|
| 1126 | + sprintf( |
|
| 1127 | + __( |
|
| 1128 | + 'This string passed in to %s to represent a EEM_Base model class was not able to be used to instantiate the class. Please ensure that the string is a match for the EEM_Base model name (not including the EEM_ part). This was given: %s', |
|
| 1129 | + 'event_espresso' |
|
| 1130 | + ), |
|
| 1131 | + get_class($this), |
|
| 1132 | + $this->_model |
|
| 1133 | + ) |
|
| 1134 | + ); |
|
| 1135 | + } |
|
| 1136 | + } |
|
| 1137 | + |
|
| 1138 | + |
|
| 1139 | + /** |
|
| 1140 | + * |
|
| 1141 | + * @see EE_Meta_Capability_Map::_map_meta_caps() for docs on params. |
|
| 1142 | + * @since 4.6.x |
|
| 1143 | + * |
|
| 1144 | + * @param $caps |
|
| 1145 | + * @param $cap |
|
| 1146 | + * @param $user_id |
|
| 1147 | + * @param $args |
|
| 1148 | + * |
|
| 1149 | + * @return array |
|
| 1150 | + */ |
|
| 1151 | + public function map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1152 | + { |
|
| 1153 | + return $this->_map_meta_caps($caps, $cap, $user_id, $args); |
|
| 1154 | + } |
|
| 1155 | + |
|
| 1156 | + |
|
| 1157 | + /** |
|
| 1158 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1159 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1160 | + * |
|
| 1161 | + * @since 4.5.0 |
|
| 1162 | + * @see wp-includes/capabilities.php |
|
| 1163 | + * |
|
| 1164 | + * @param array $caps actual users capabilities |
|
| 1165 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1166 | + * @param int $user_id The user id |
|
| 1167 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1168 | + * |
|
| 1169 | + * @return array actual users capabilities |
|
| 1170 | + */ |
|
| 1171 | + abstract protected function _map_meta_caps($caps, $cap, $user_id, $args); |
|
| 1172 | 1172 | } |
| 1173 | 1173 | |
| 1174 | 1174 | |
@@ -1184,81 +1184,81 @@ discard block |
||
| 1184 | 1184 | class EE_Meta_Capability_Map_Edit extends EE_Meta_Capability_Map |
| 1185 | 1185 | { |
| 1186 | 1186 | |
| 1187 | - /** |
|
| 1188 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1189 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1190 | - * |
|
| 1191 | - * @since 4.5.0 |
|
| 1192 | - * @see wp-includes/capabilities.php |
|
| 1193 | - * |
|
| 1194 | - * @param array $caps actual users capabilities |
|
| 1195 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1196 | - * @param int $user_id The user id |
|
| 1197 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1198 | - * |
|
| 1199 | - * @return array actual users capabilities |
|
| 1200 | - */ |
|
| 1201 | - protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1202 | - { |
|
| 1203 | - //only process if we're checking our mapped_cap |
|
| 1204 | - if ($cap !== $this->meta_cap) { |
|
| 1205 | - return $caps; |
|
| 1206 | - } |
|
| 1207 | - |
|
| 1208 | - //okay it is a meta cap so let's first remove that cap from the $caps array. |
|
| 1209 | - if (($key = array_search($cap, $caps)) !== false) { |
|
| 1210 | - unset($caps[$key]); |
|
| 1211 | - } |
|
| 1212 | - |
|
| 1213 | - //cast $user_id to int for later explicit comparisons |
|
| 1214 | - $user_id = (int) $user_id; |
|
| 1215 | - |
|
| 1216 | - /** @var EE_Base_Class $obj */ |
|
| 1217 | - $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
| 1218 | - //if no obj then let's just do cap |
|
| 1219 | - if (! $obj instanceof EE_Base_Class) { |
|
| 1220 | - $caps[] = 'do_not_allow'; |
|
| 1221 | - return $caps; |
|
| 1222 | - } |
|
| 1223 | - $caps[] = $cap . 's'; |
|
| 1224 | - if ($obj instanceof EE_CPT_Base) { |
|
| 1225 | - //if the item author is set and the user is the author... |
|
| 1226 | - if ($obj->wp_user() && $user_id === $obj->wp_user()) { |
|
| 1227 | - //if obj is published... |
|
| 1228 | - if ($obj->status() === 'publish') { |
|
| 1229 | - $caps[] = $this->published_cap; |
|
| 1230 | - } |
|
| 1231 | - } else { |
|
| 1232 | - //the user is trying to edit someone else's obj |
|
| 1233 | - if (! empty($this->others_cap)) { |
|
| 1234 | - $caps[] = $this->others_cap; |
|
| 1235 | - } |
|
| 1236 | - if (! empty($this->published_cap) && $obj->status() === 'publish') { |
|
| 1237 | - $caps[] = $this->published_cap; |
|
| 1238 | - } elseif (! empty($this->private_cap) && $obj->status() === 'private') { |
|
| 1239 | - $caps[] = $this->private_cap; |
|
| 1240 | - } |
|
| 1241 | - } |
|
| 1242 | - } else { |
|
| 1243 | - //not a cpt object so handled differently |
|
| 1244 | - $has_cap = false; |
|
| 1245 | - try { |
|
| 1246 | - $has_cap = method_exists($obj, 'wp_user') |
|
| 1247 | - && $obj->wp_user() |
|
| 1248 | - && $obj->wp_user() === $user_id; |
|
| 1249 | - } catch (Exception $e) { |
|
| 1250 | - if (WP_DEBUG) { |
|
| 1251 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1252 | - } |
|
| 1253 | - } |
|
| 1254 | - if (! $has_cap) { |
|
| 1255 | - if (! empty($this->others_cap)) { |
|
| 1256 | - $caps[] = $this->others_cap; |
|
| 1257 | - } |
|
| 1258 | - } |
|
| 1259 | - } |
|
| 1260 | - return $caps; |
|
| 1261 | - } |
|
| 1187 | + /** |
|
| 1188 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1189 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1190 | + * |
|
| 1191 | + * @since 4.5.0 |
|
| 1192 | + * @see wp-includes/capabilities.php |
|
| 1193 | + * |
|
| 1194 | + * @param array $caps actual users capabilities |
|
| 1195 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1196 | + * @param int $user_id The user id |
|
| 1197 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1198 | + * |
|
| 1199 | + * @return array actual users capabilities |
|
| 1200 | + */ |
|
| 1201 | + protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1202 | + { |
|
| 1203 | + //only process if we're checking our mapped_cap |
|
| 1204 | + if ($cap !== $this->meta_cap) { |
|
| 1205 | + return $caps; |
|
| 1206 | + } |
|
| 1207 | + |
|
| 1208 | + //okay it is a meta cap so let's first remove that cap from the $caps array. |
|
| 1209 | + if (($key = array_search($cap, $caps)) !== false) { |
|
| 1210 | + unset($caps[$key]); |
|
| 1211 | + } |
|
| 1212 | + |
|
| 1213 | + //cast $user_id to int for later explicit comparisons |
|
| 1214 | + $user_id = (int) $user_id; |
|
| 1215 | + |
|
| 1216 | + /** @var EE_Base_Class $obj */ |
|
| 1217 | + $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
| 1218 | + //if no obj then let's just do cap |
|
| 1219 | + if (! $obj instanceof EE_Base_Class) { |
|
| 1220 | + $caps[] = 'do_not_allow'; |
|
| 1221 | + return $caps; |
|
| 1222 | + } |
|
| 1223 | + $caps[] = $cap . 's'; |
|
| 1224 | + if ($obj instanceof EE_CPT_Base) { |
|
| 1225 | + //if the item author is set and the user is the author... |
|
| 1226 | + if ($obj->wp_user() && $user_id === $obj->wp_user()) { |
|
| 1227 | + //if obj is published... |
|
| 1228 | + if ($obj->status() === 'publish') { |
|
| 1229 | + $caps[] = $this->published_cap; |
|
| 1230 | + } |
|
| 1231 | + } else { |
|
| 1232 | + //the user is trying to edit someone else's obj |
|
| 1233 | + if (! empty($this->others_cap)) { |
|
| 1234 | + $caps[] = $this->others_cap; |
|
| 1235 | + } |
|
| 1236 | + if (! empty($this->published_cap) && $obj->status() === 'publish') { |
|
| 1237 | + $caps[] = $this->published_cap; |
|
| 1238 | + } elseif (! empty($this->private_cap) && $obj->status() === 'private') { |
|
| 1239 | + $caps[] = $this->private_cap; |
|
| 1240 | + } |
|
| 1241 | + } |
|
| 1242 | + } else { |
|
| 1243 | + //not a cpt object so handled differently |
|
| 1244 | + $has_cap = false; |
|
| 1245 | + try { |
|
| 1246 | + $has_cap = method_exists($obj, 'wp_user') |
|
| 1247 | + && $obj->wp_user() |
|
| 1248 | + && $obj->wp_user() === $user_id; |
|
| 1249 | + } catch (Exception $e) { |
|
| 1250 | + if (WP_DEBUG) { |
|
| 1251 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1252 | + } |
|
| 1253 | + } |
|
| 1254 | + if (! $has_cap) { |
|
| 1255 | + if (! empty($this->others_cap)) { |
|
| 1256 | + $caps[] = $this->others_cap; |
|
| 1257 | + } |
|
| 1258 | + } |
|
| 1259 | + } |
|
| 1260 | + return $caps; |
|
| 1261 | + } |
|
| 1262 | 1262 | } |
| 1263 | 1263 | |
| 1264 | 1264 | |
@@ -1275,24 +1275,24 @@ discard block |
||
| 1275 | 1275 | class EE_Meta_Capability_Map_Delete extends EE_Meta_Capability_Map_Edit |
| 1276 | 1276 | { |
| 1277 | 1277 | |
| 1278 | - /** |
|
| 1279 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1280 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1281 | - * |
|
| 1282 | - * @since 4.5.0 |
|
| 1283 | - * @see wp-includes/capabilities.php |
|
| 1284 | - * |
|
| 1285 | - * @param array $caps actual users capabilities |
|
| 1286 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1287 | - * @param int $user_id The user id |
|
| 1288 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1289 | - * |
|
| 1290 | - * @return array actual users capabilities |
|
| 1291 | - */ |
|
| 1292 | - protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1293 | - { |
|
| 1294 | - return parent::_map_meta_caps($caps, $cap, $user_id, $args); |
|
| 1295 | - } |
|
| 1278 | + /** |
|
| 1279 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1280 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1281 | + * |
|
| 1282 | + * @since 4.5.0 |
|
| 1283 | + * @see wp-includes/capabilities.php |
|
| 1284 | + * |
|
| 1285 | + * @param array $caps actual users capabilities |
|
| 1286 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1287 | + * @param int $user_id The user id |
|
| 1288 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1289 | + * |
|
| 1290 | + * @return array actual users capabilities |
|
| 1291 | + */ |
|
| 1292 | + protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1293 | + { |
|
| 1294 | + return parent::_map_meta_caps($caps, $cap, $user_id, $args); |
|
| 1295 | + } |
|
| 1296 | 1296 | } |
| 1297 | 1297 | |
| 1298 | 1298 | |
@@ -1308,85 +1308,85 @@ discard block |
||
| 1308 | 1308 | class EE_Meta_Capability_Map_Read extends EE_Meta_Capability_Map |
| 1309 | 1309 | { |
| 1310 | 1310 | |
| 1311 | - /** |
|
| 1312 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1313 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1314 | - * |
|
| 1315 | - * @since 4.5.0 |
|
| 1316 | - * @see wp-includes/capabilities.php |
|
| 1317 | - * |
|
| 1318 | - * @param array $caps actual users capabilities |
|
| 1319 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1320 | - * @param int $user_id The user id |
|
| 1321 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1322 | - * |
|
| 1323 | - * @return array actual users capabilities |
|
| 1324 | - */ |
|
| 1325 | - protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1326 | - { |
|
| 1327 | - //only process if we're checking our mapped cap; |
|
| 1328 | - if ($cap !== $this->meta_cap) { |
|
| 1329 | - return $caps; |
|
| 1330 | - } |
|
| 1331 | - |
|
| 1332 | - //okay it is a meta cap so let's first remove that cap from the $caps array. |
|
| 1333 | - if (($key = array_search($cap, $caps)) !== false) { |
|
| 1334 | - unset($caps[$key]); |
|
| 1335 | - } |
|
| 1336 | - |
|
| 1337 | - //cast $user_id to int for later explicit comparisons |
|
| 1338 | - $user_id = (int) $user_id; |
|
| 1339 | - |
|
| 1340 | - $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
| 1341 | - //if no obj then let's just do cap |
|
| 1342 | - if (! $obj instanceof EE_Base_Class) { |
|
| 1343 | - $caps[] = 'do_not_allow'; |
|
| 1344 | - return $caps; |
|
| 1345 | - } |
|
| 1346 | - |
|
| 1347 | - $caps[] = $cap . 's'; |
|
| 1348 | - if ($obj instanceof EE_CPT_Base) { |
|
| 1349 | - $status_obj = get_post_status_object($obj->status()); |
|
| 1350 | - if ($status_obj->public) { |
|
| 1351 | - return $caps; |
|
| 1352 | - } |
|
| 1353 | - //if the item author is set and the user is not the author... |
|
| 1354 | - if ($obj->wp_user() && $obj->wp_user() !== $user_id) { |
|
| 1355 | - if (! empty($this->others_cap)) { |
|
| 1356 | - $caps[] = $this->others_cap; |
|
| 1357 | - } |
|
| 1358 | - } |
|
| 1359 | - //yes this means that if users created the private post, they are able to see it regardless of private cap. |
|
| 1360 | - if ($status_obj->private |
|
| 1361 | - && ! empty($this->private_cap) |
|
| 1362 | - && $obj->wp_user() !== $user_id |
|
| 1363 | - ) { |
|
| 1364 | - //the user is trying to view a private object for an object they don't own. |
|
| 1365 | - $caps[] = $this->private_cap; |
|
| 1366 | - } |
|
| 1367 | - } else { |
|
| 1368 | - //not a cpt object so handled differently |
|
| 1369 | - $has_cap = false; |
|
| 1370 | - try { |
|
| 1371 | - $has_cap = method_exists($obj, 'wp_user') |
|
| 1372 | - && $obj->wp_user() |
|
| 1373 | - && $obj->wp_user() === $user_id; |
|
| 1374 | - } catch (Exception $e) { |
|
| 1375 | - if (WP_DEBUG) { |
|
| 1376 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1377 | - } |
|
| 1378 | - } |
|
| 1379 | - if (! $has_cap) { |
|
| 1380 | - if (! empty($this->private_cap)) { |
|
| 1381 | - $caps[] = $this->private_cap; |
|
| 1382 | - } |
|
| 1383 | - if (! empty($this->others_cap)) { |
|
| 1384 | - $caps[] = $this->others_cap; |
|
| 1385 | - } |
|
| 1386 | - } |
|
| 1387 | - } |
|
| 1388 | - return $caps; |
|
| 1389 | - } |
|
| 1311 | + /** |
|
| 1312 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1313 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1314 | + * |
|
| 1315 | + * @since 4.5.0 |
|
| 1316 | + * @see wp-includes/capabilities.php |
|
| 1317 | + * |
|
| 1318 | + * @param array $caps actual users capabilities |
|
| 1319 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1320 | + * @param int $user_id The user id |
|
| 1321 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1322 | + * |
|
| 1323 | + * @return array actual users capabilities |
|
| 1324 | + */ |
|
| 1325 | + protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1326 | + { |
|
| 1327 | + //only process if we're checking our mapped cap; |
|
| 1328 | + if ($cap !== $this->meta_cap) { |
|
| 1329 | + return $caps; |
|
| 1330 | + } |
|
| 1331 | + |
|
| 1332 | + //okay it is a meta cap so let's first remove that cap from the $caps array. |
|
| 1333 | + if (($key = array_search($cap, $caps)) !== false) { |
|
| 1334 | + unset($caps[$key]); |
|
| 1335 | + } |
|
| 1336 | + |
|
| 1337 | + //cast $user_id to int for later explicit comparisons |
|
| 1338 | + $user_id = (int) $user_id; |
|
| 1339 | + |
|
| 1340 | + $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
| 1341 | + //if no obj then let's just do cap |
|
| 1342 | + if (! $obj instanceof EE_Base_Class) { |
|
| 1343 | + $caps[] = 'do_not_allow'; |
|
| 1344 | + return $caps; |
|
| 1345 | + } |
|
| 1346 | + |
|
| 1347 | + $caps[] = $cap . 's'; |
|
| 1348 | + if ($obj instanceof EE_CPT_Base) { |
|
| 1349 | + $status_obj = get_post_status_object($obj->status()); |
|
| 1350 | + if ($status_obj->public) { |
|
| 1351 | + return $caps; |
|
| 1352 | + } |
|
| 1353 | + //if the item author is set and the user is not the author... |
|
| 1354 | + if ($obj->wp_user() && $obj->wp_user() !== $user_id) { |
|
| 1355 | + if (! empty($this->others_cap)) { |
|
| 1356 | + $caps[] = $this->others_cap; |
|
| 1357 | + } |
|
| 1358 | + } |
|
| 1359 | + //yes this means that if users created the private post, they are able to see it regardless of private cap. |
|
| 1360 | + if ($status_obj->private |
|
| 1361 | + && ! empty($this->private_cap) |
|
| 1362 | + && $obj->wp_user() !== $user_id |
|
| 1363 | + ) { |
|
| 1364 | + //the user is trying to view a private object for an object they don't own. |
|
| 1365 | + $caps[] = $this->private_cap; |
|
| 1366 | + } |
|
| 1367 | + } else { |
|
| 1368 | + //not a cpt object so handled differently |
|
| 1369 | + $has_cap = false; |
|
| 1370 | + try { |
|
| 1371 | + $has_cap = method_exists($obj, 'wp_user') |
|
| 1372 | + && $obj->wp_user() |
|
| 1373 | + && $obj->wp_user() === $user_id; |
|
| 1374 | + } catch (Exception $e) { |
|
| 1375 | + if (WP_DEBUG) { |
|
| 1376 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1377 | + } |
|
| 1378 | + } |
|
| 1379 | + if (! $has_cap) { |
|
| 1380 | + if (! empty($this->private_cap)) { |
|
| 1381 | + $caps[] = $this->private_cap; |
|
| 1382 | + } |
|
| 1383 | + if (! empty($this->others_cap)) { |
|
| 1384 | + $caps[] = $this->others_cap; |
|
| 1385 | + } |
|
| 1386 | + } |
|
| 1387 | + } |
|
| 1388 | + return $caps; |
|
| 1389 | + } |
|
| 1390 | 1390 | } |
| 1391 | 1391 | |
| 1392 | 1392 | |
@@ -1403,56 +1403,56 @@ discard block |
||
| 1403 | 1403 | class EE_Meta_Capability_Map_Messages_Cap extends EE_Meta_Capability_Map |
| 1404 | 1404 | { |
| 1405 | 1405 | |
| 1406 | - /** |
|
| 1407 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1408 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1409 | - * |
|
| 1410 | - * @since 4.5.0 |
|
| 1411 | - * @see wp-includes/capabilities.php |
|
| 1412 | - * |
|
| 1413 | - * @param array $caps actual users capabilities |
|
| 1414 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1415 | - * @param int $user_id The user id |
|
| 1416 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1417 | - * |
|
| 1418 | - * @return array actual users capabilities |
|
| 1419 | - */ |
|
| 1420 | - protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1421 | - { |
|
| 1422 | - //only process if we're checking our mapped_cap |
|
| 1423 | - if ($cap !== $this->meta_cap) { |
|
| 1424 | - return $caps; |
|
| 1425 | - } |
|
| 1426 | - |
|
| 1427 | - //okay it is a meta cap so let's first remove that cap from the $caps array. |
|
| 1428 | - if (($key = array_search($cap, $caps)) !== false) { |
|
| 1429 | - unset($caps[$key]); |
|
| 1430 | - } |
|
| 1431 | - |
|
| 1432 | - //cast $user_id to int for later explicit comparisons |
|
| 1433 | - $user_id = (int) $user_id; |
|
| 1434 | - |
|
| 1435 | - $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
| 1436 | - //if no obj then let's just do cap |
|
| 1437 | - if (! $obj instanceof EE_Message_Template_Group) { |
|
| 1438 | - $caps[] = 'do_not_allow'; |
|
| 1439 | - return $caps; |
|
| 1440 | - } |
|
| 1441 | - $caps[] = $cap . 's'; |
|
| 1442 | - $is_global = $obj->is_global(); |
|
| 1443 | - if ($obj->wp_user() && $obj->wp_user() === $user_id) { |
|
| 1444 | - if ($is_global) { |
|
| 1445 | - $caps[] = $this->private_cap; |
|
| 1446 | - } |
|
| 1447 | - } else { |
|
| 1448 | - if ($is_global) { |
|
| 1449 | - $caps[] = $this->private_cap; |
|
| 1450 | - } else { |
|
| 1451 | - $caps[] = $this->others_cap; |
|
| 1452 | - } |
|
| 1453 | - } |
|
| 1454 | - return $caps; |
|
| 1455 | - } |
|
| 1406 | + /** |
|
| 1407 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1408 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1409 | + * |
|
| 1410 | + * @since 4.5.0 |
|
| 1411 | + * @see wp-includes/capabilities.php |
|
| 1412 | + * |
|
| 1413 | + * @param array $caps actual users capabilities |
|
| 1414 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1415 | + * @param int $user_id The user id |
|
| 1416 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1417 | + * |
|
| 1418 | + * @return array actual users capabilities |
|
| 1419 | + */ |
|
| 1420 | + protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1421 | + { |
|
| 1422 | + //only process if we're checking our mapped_cap |
|
| 1423 | + if ($cap !== $this->meta_cap) { |
|
| 1424 | + return $caps; |
|
| 1425 | + } |
|
| 1426 | + |
|
| 1427 | + //okay it is a meta cap so let's first remove that cap from the $caps array. |
|
| 1428 | + if (($key = array_search($cap, $caps)) !== false) { |
|
| 1429 | + unset($caps[$key]); |
|
| 1430 | + } |
|
| 1431 | + |
|
| 1432 | + //cast $user_id to int for later explicit comparisons |
|
| 1433 | + $user_id = (int) $user_id; |
|
| 1434 | + |
|
| 1435 | + $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
| 1436 | + //if no obj then let's just do cap |
|
| 1437 | + if (! $obj instanceof EE_Message_Template_Group) { |
|
| 1438 | + $caps[] = 'do_not_allow'; |
|
| 1439 | + return $caps; |
|
| 1440 | + } |
|
| 1441 | + $caps[] = $cap . 's'; |
|
| 1442 | + $is_global = $obj->is_global(); |
|
| 1443 | + if ($obj->wp_user() && $obj->wp_user() === $user_id) { |
|
| 1444 | + if ($is_global) { |
|
| 1445 | + $caps[] = $this->private_cap; |
|
| 1446 | + } |
|
| 1447 | + } else { |
|
| 1448 | + if ($is_global) { |
|
| 1449 | + $caps[] = $this->private_cap; |
|
| 1450 | + } else { |
|
| 1451 | + $caps[] = $this->others_cap; |
|
| 1452 | + } |
|
| 1453 | + } |
|
| 1454 | + return $caps; |
|
| 1455 | + } |
|
| 1456 | 1456 | } |
| 1457 | 1457 | |
| 1458 | 1458 | |
@@ -1469,40 +1469,40 @@ discard block |
||
| 1469 | 1469 | class EE_Meta_Capability_Map_Registration_Form_Cap extends EE_Meta_Capability_Map |
| 1470 | 1470 | { |
| 1471 | 1471 | |
| 1472 | - /** |
|
| 1473 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1474 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1475 | - * |
|
| 1476 | - * @since 4.5.0 |
|
| 1477 | - * @see wp-includes/capabilities.php |
|
| 1478 | - * @param array $caps actual users capabilities |
|
| 1479 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1480 | - * @param int $user_id The user id |
|
| 1481 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1482 | - * @return array actual users capabilities |
|
| 1483 | - */ |
|
| 1484 | - protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1485 | - { |
|
| 1486 | - //only process if we're checking our mapped_cap |
|
| 1487 | - if ($cap !== $this->meta_cap) { |
|
| 1488 | - return $caps; |
|
| 1489 | - } |
|
| 1490 | - //okay it is a meta cap so let's first remove that cap from the $caps array. |
|
| 1491 | - if (($key = array_search($cap, $caps)) !== false) { |
|
| 1492 | - unset($caps[$key]); |
|
| 1493 | - } |
|
| 1494 | - $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
| 1495 | - //if no obj then let's just do cap |
|
| 1496 | - if (! $obj instanceof EE_Base_Class) { |
|
| 1497 | - $caps[] = 'do_not_allow'; |
|
| 1498 | - return $caps; |
|
| 1499 | - } |
|
| 1500 | - $caps[] = $cap . 's'; |
|
| 1501 | - $is_system = $obj instanceof EE_Question_Group ? $obj->system_group() : false; |
|
| 1502 | - $is_system = $obj instanceof EE_Question ? $obj->is_system_question() : $is_system; |
|
| 1503 | - if ($is_system) { |
|
| 1504 | - $caps[] = $this->private_cap; |
|
| 1505 | - } |
|
| 1506 | - return $caps; |
|
| 1507 | - } |
|
| 1472 | + /** |
|
| 1473 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1474 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1475 | + * |
|
| 1476 | + * @since 4.5.0 |
|
| 1477 | + * @see wp-includes/capabilities.php |
|
| 1478 | + * @param array $caps actual users capabilities |
|
| 1479 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1480 | + * @param int $user_id The user id |
|
| 1481 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1482 | + * @return array actual users capabilities |
|
| 1483 | + */ |
|
| 1484 | + protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1485 | + { |
|
| 1486 | + //only process if we're checking our mapped_cap |
|
| 1487 | + if ($cap !== $this->meta_cap) { |
|
| 1488 | + return $caps; |
|
| 1489 | + } |
|
| 1490 | + //okay it is a meta cap so let's first remove that cap from the $caps array. |
|
| 1491 | + if (($key = array_search($cap, $caps)) !== false) { |
|
| 1492 | + unset($caps[$key]); |
|
| 1493 | + } |
|
| 1494 | + $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
| 1495 | + //if no obj then let's just do cap |
|
| 1496 | + if (! $obj instanceof EE_Base_Class) { |
|
| 1497 | + $caps[] = 'do_not_allow'; |
|
| 1498 | + return $caps; |
|
| 1499 | + } |
|
| 1500 | + $caps[] = $cap . 's'; |
|
| 1501 | + $is_system = $obj instanceof EE_Question_Group ? $obj->system_group() : false; |
|
| 1502 | + $is_system = $obj instanceof EE_Question ? $obj->is_system_question() : $is_system; |
|
| 1503 | + if ($is_system) { |
|
| 1504 | + $caps[] = $this->private_cap; |
|
| 1505 | + } |
|
| 1506 | + return $caps; |
|
| 1507 | + } |
|
| 1508 | 1508 | } |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | public static function instance() |
| 86 | 86 | { |
| 87 | 87 | //check if instantiated, and if not do so. |
| 88 | - if (! self::$_instance instanceof EE_Capabilities) { |
|
| 88 | + if ( ! self::$_instance instanceof EE_Capabilities) { |
|
| 89 | 89 | self::$_instance = new self(); |
| 90 | 90 | } |
| 91 | 91 | return self::$_instance; |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | */ |
| 118 | 118 | public function init_caps($reset = false) |
| 119 | 119 | { |
| 120 | - if(! EE_Maintenance_Mode::instance()->models_can_query()){ |
|
| 120 | + if ( ! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 121 | 121 | return false; |
| 122 | 122 | } |
| 123 | 123 | $this->reset = filter_var($reset, FILTER_VALIDATE_BOOLEAN); |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | $this->_get_default_meta_caps_array() |
| 165 | 165 | ); |
| 166 | 166 | //add filter for map_meta_caps but only if models can query. |
| 167 | - if (! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) { |
|
| 167 | + if ( ! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) { |
|
| 168 | 168 | add_filter('map_meta_cap', array($this, 'map_meta_caps'), 10, 4); |
| 169 | 169 | } |
| 170 | 170 | } |
@@ -325,11 +325,11 @@ discard block |
||
| 325 | 325 | if (did_action('AHEE__EE_System__load_espresso_addons__complete')) { |
| 326 | 326 | //loop through our _meta_caps array |
| 327 | 327 | foreach ($this->_meta_caps as $meta_map) { |
| 328 | - if (! $meta_map instanceof EE_Meta_Capability_Map) { |
|
| 328 | + if ( ! $meta_map instanceof EE_Meta_Capability_Map) { |
|
| 329 | 329 | continue; |
| 330 | 330 | } |
| 331 | 331 | // don't load models if there is no object ID in the args |
| 332 | - if (! empty($args[0])) { |
|
| 332 | + if ( ! empty($args[0])) { |
|
| 333 | 333 | $meta_map->ensure_is_model(); |
| 334 | 334 | } |
| 335 | 335 | $caps = $meta_map->map_meta_caps($caps, $cap, $user_id, $args); |
@@ -631,7 +631,7 @@ discard block |
||
| 631 | 631 | private function setupCapabilitiesMap() |
| 632 | 632 | { |
| 633 | 633 | // if the initialization process hasn't even started, then we need to call init_caps() |
| 634 | - if($this->initialized === null) { |
|
| 634 | + if ($this->initialized === null) { |
|
| 635 | 635 | return $this->init_caps(); |
| 636 | 636 | } |
| 637 | 637 | // unless resetting, get caps from db if we haven't already |
@@ -667,7 +667,7 @@ discard block |
||
| 667 | 667 | public function addCaps(array $capabilities_to_add) |
| 668 | 668 | { |
| 669 | 669 | // don't do anything if the capabilities map can not be initialized |
| 670 | - if (! $this->setupCapabilitiesMap()) { |
|
| 670 | + if ( ! $this->setupCapabilitiesMap()) { |
|
| 671 | 671 | return false; |
| 672 | 672 | } |
| 673 | 673 | // and filter the array so others can get in on the fun during resets |
@@ -710,7 +710,7 @@ discard block |
||
| 710 | 710 | public function removeCaps($caps_map) |
| 711 | 711 | { |
| 712 | 712 | // don't do anything if the capabilities map can not be initialized |
| 713 | - if (! $this->setupCapabilitiesMap()) { |
|
| 713 | + if ( ! $this->setupCapabilitiesMap()) { |
|
| 714 | 714 | return false; |
| 715 | 715 | } |
| 716 | 716 | $update_capabilities_map = false; |
@@ -770,7 +770,7 @@ discard block |
||
| 770 | 770 | $orig_role = $role; |
| 771 | 771 | $role = $role instanceof WP_Role ? $role : get_role($role); |
| 772 | 772 | //if the role isn't available then we create it. |
| 773 | - if (! $role instanceof WP_Role) { |
|
| 773 | + if ( ! $role instanceof WP_Role) { |
|
| 774 | 774 | // if a plugin wants to create a specific role name then they should create the role before |
| 775 | 775 | // EE_Capabilities does. Otherwise this function will create the role name from the slug: |
| 776 | 776 | // - removes any `ee_` namespacing from the start of the slug. |
@@ -781,12 +781,12 @@ discard block |
||
| 781 | 781 | } |
| 782 | 782 | if ($role instanceof WP_Role) { |
| 783 | 783 | // don't do anything if the capabilities map can not be initialized |
| 784 | - if (! $this->setupCapabilitiesMap()) { |
|
| 784 | + if ( ! $this->setupCapabilitiesMap()) { |
|
| 785 | 785 | return false; |
| 786 | 786 | } |
| 787 | - if (! $this->capHasBeenAddedToRole($role->name, $cap)) { |
|
| 787 | + if ( ! $this->capHasBeenAddedToRole($role->name, $cap)) { |
|
| 788 | 788 | $role->add_cap($cap, $grant); |
| 789 | - $this->capabilities_map[ $role->name ][] = $cap; |
|
| 789 | + $this->capabilities_map[$role->name][] = $cap; |
|
| 790 | 790 | $this->updateCapabilitiesMap($update_capabilities_map); |
| 791 | 791 | return true; |
| 792 | 792 | } |
@@ -811,14 +811,14 @@ discard block |
||
| 811 | 811 | public function remove_cap_from_role($role, $cap, $update_capabilities_map = true) |
| 812 | 812 | { |
| 813 | 813 | // don't do anything if the capabilities map can not be initialized |
| 814 | - if (! $this->setupCapabilitiesMap()) { |
|
| 814 | + if ( ! $this->setupCapabilitiesMap()) { |
|
| 815 | 815 | return false; |
| 816 | 816 | } |
| 817 | 817 | |
| 818 | 818 | $role = $role instanceof WP_Role ? $role : get_role($role); |
| 819 | 819 | if ($role instanceof WP_Role && $index = $this->capHasBeenAddedToRole($role->name, $cap, true)) { |
| 820 | 820 | $role->remove_cap($cap); |
| 821 | - unset($this->capabilities_map[ $role->name ][ $index ]); |
|
| 821 | + unset($this->capabilities_map[$role->name][$index]); |
|
| 822 | 822 | $this->updateCapabilitiesMap($update_capabilities_map); |
| 823 | 823 | return true; |
| 824 | 824 | } |
@@ -833,7 +833,7 @@ discard block |
||
| 833 | 833 | * @param bool $get_index |
| 834 | 834 | * @return bool|mixed |
| 835 | 835 | */ |
| 836 | - private function capHasBeenAddedToRole($role_name='', $cap='', $get_index = false) |
|
| 836 | + private function capHasBeenAddedToRole($role_name = '', $cap = '', $get_index = false) |
|
| 837 | 837 | { |
| 838 | 838 | if ( |
| 839 | 839 | isset($this->capabilities_map[$role_name]) |
@@ -865,7 +865,7 @@ discard block |
||
| 865 | 865 | public function current_user_can($cap, $context, $id = 0) |
| 866 | 866 | { |
| 867 | 867 | //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
| 868 | - $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__' . $context, $cap, $id); |
|
| 868 | + $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__'.$context, $cap, $id); |
|
| 869 | 869 | $filtered_cap = apply_filters( |
| 870 | 870 | 'FHEE__EE_Capabilities__current_user_can__cap', |
| 871 | 871 | $filtered_cap, |
@@ -894,7 +894,7 @@ discard block |
||
| 894 | 894 | public function user_can($user, $cap, $context, $id = 0) |
| 895 | 895 | { |
| 896 | 896 | //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
| 897 | - $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__' . $context, $cap, $user, $id); |
|
| 897 | + $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__'.$context, $cap, $user, $id); |
|
| 898 | 898 | $filtered_cap = apply_filters( |
| 899 | 899 | 'FHEE__EE_Capabilities__user_can__cap', |
| 900 | 900 | $filtered_cap, |
@@ -934,7 +934,7 @@ discard block |
||
| 934 | 934 | : current_user_can($blog_id, $cap); |
| 935 | 935 | //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
| 936 | 936 | $user_can = apply_filters( |
| 937 | - 'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__' . $context, |
|
| 937 | + 'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__'.$context, |
|
| 938 | 938 | $user_can, |
| 939 | 939 | $blog_id, |
| 940 | 940 | $cap, |
@@ -964,14 +964,14 @@ discard block |
||
| 964 | 964 | */ |
| 965 | 965 | public function get_ee_capabilities($role = 'administrator') |
| 966 | 966 | { |
| 967 | - if (! $this->initialized) { |
|
| 967 | + if ( ! $this->initialized) { |
|
| 968 | 968 | $this->init_caps(); |
| 969 | 969 | } |
| 970 | 970 | if (empty($role)) { |
| 971 | 971 | return $this->capabilities_map; |
| 972 | 972 | } |
| 973 | - return isset($this->capabilities_map[ $role ]) |
|
| 974 | - ? $this->capabilities_map[ $role ] |
|
| 973 | + return isset($this->capabilities_map[$role]) |
|
| 974 | + ? $this->capabilities_map[$role] |
|
| 975 | 975 | : array(); |
| 976 | 976 | } |
| 977 | 977 | |
@@ -1003,7 +1003,7 @@ discard block |
||
| 1003 | 1003 | 'event_espresso' |
| 1004 | 1004 | ), |
| 1005 | 1005 | '$reset', |
| 1006 | - __METHOD__ . '()', |
|
| 1006 | + __METHOD__.'()', |
|
| 1007 | 1007 | 'EE_Capabilities::init_caps()', |
| 1008 | 1008 | 'true' |
| 1009 | 1009 | ), |
@@ -1081,16 +1081,16 @@ discard block |
||
| 1081 | 1081 | 'Incoming $map_values array should have a count of four values in it. This is what was given: %s', |
| 1082 | 1082 | 'event_espresso' |
| 1083 | 1083 | ), |
| 1084 | - '<br>' . print_r($map_values, true) |
|
| 1084 | + '<br>'.print_r($map_values, true) |
|
| 1085 | 1085 | ) |
| 1086 | 1086 | ); |
| 1087 | 1087 | } |
| 1088 | 1088 | //set properties |
| 1089 | 1089 | $this->_model = null; |
| 1090 | 1090 | $this->_model_name = $map_values[0]; |
| 1091 | - $this->published_cap = (string)$map_values[1]; |
|
| 1092 | - $this->others_cap = (string)$map_values[2]; |
|
| 1093 | - $this->private_cap = (string)$map_values[3]; |
|
| 1091 | + $this->published_cap = (string) $map_values[1]; |
|
| 1092 | + $this->others_cap = (string) $map_values[2]; |
|
| 1093 | + $this->private_cap = (string) $map_values[3]; |
|
| 1094 | 1094 | } |
| 1095 | 1095 | |
| 1096 | 1096 | /** |
@@ -1117,11 +1117,11 @@ discard block |
||
| 1117 | 1117 | return; |
| 1118 | 1118 | } |
| 1119 | 1119 | //ensure model name is string |
| 1120 | - $this->_model_name = (string)$this->_model_name; |
|
| 1120 | + $this->_model_name = (string) $this->_model_name; |
|
| 1121 | 1121 | //error proof if the name has EEM in it |
| 1122 | 1122 | $this->_model_name = str_replace('EEM', '', $this->_model_name); |
| 1123 | 1123 | $this->_model = EE_Registry::instance()->load_model($this->_model_name); |
| 1124 | - if (! $this->_model instanceof EEM_Base) { |
|
| 1124 | + if ( ! $this->_model instanceof EEM_Base) { |
|
| 1125 | 1125 | throw new EE_Error( |
| 1126 | 1126 | sprintf( |
| 1127 | 1127 | __( |
@@ -1216,11 +1216,11 @@ discard block |
||
| 1216 | 1216 | /** @var EE_Base_Class $obj */ |
| 1217 | 1217 | $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
| 1218 | 1218 | //if no obj then let's just do cap |
| 1219 | - if (! $obj instanceof EE_Base_Class) { |
|
| 1219 | + if ( ! $obj instanceof EE_Base_Class) { |
|
| 1220 | 1220 | $caps[] = 'do_not_allow'; |
| 1221 | 1221 | return $caps; |
| 1222 | 1222 | } |
| 1223 | - $caps[] = $cap . 's'; |
|
| 1223 | + $caps[] = $cap.'s'; |
|
| 1224 | 1224 | if ($obj instanceof EE_CPT_Base) { |
| 1225 | 1225 | //if the item author is set and the user is the author... |
| 1226 | 1226 | if ($obj->wp_user() && $user_id === $obj->wp_user()) { |
@@ -1230,12 +1230,12 @@ discard block |
||
| 1230 | 1230 | } |
| 1231 | 1231 | } else { |
| 1232 | 1232 | //the user is trying to edit someone else's obj |
| 1233 | - if (! empty($this->others_cap)) { |
|
| 1233 | + if ( ! empty($this->others_cap)) { |
|
| 1234 | 1234 | $caps[] = $this->others_cap; |
| 1235 | 1235 | } |
| 1236 | - if (! empty($this->published_cap) && $obj->status() === 'publish') { |
|
| 1236 | + if ( ! empty($this->published_cap) && $obj->status() === 'publish') { |
|
| 1237 | 1237 | $caps[] = $this->published_cap; |
| 1238 | - } elseif (! empty($this->private_cap) && $obj->status() === 'private') { |
|
| 1238 | + } elseif ( ! empty($this->private_cap) && $obj->status() === 'private') { |
|
| 1239 | 1239 | $caps[] = $this->private_cap; |
| 1240 | 1240 | } |
| 1241 | 1241 | } |
@@ -1251,8 +1251,8 @@ discard block |
||
| 1251 | 1251 | EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
| 1252 | 1252 | } |
| 1253 | 1253 | } |
| 1254 | - if (! $has_cap) { |
|
| 1255 | - if (! empty($this->others_cap)) { |
|
| 1254 | + if ( ! $has_cap) { |
|
| 1255 | + if ( ! empty($this->others_cap)) { |
|
| 1256 | 1256 | $caps[] = $this->others_cap; |
| 1257 | 1257 | } |
| 1258 | 1258 | } |
@@ -1339,12 +1339,12 @@ discard block |
||
| 1339 | 1339 | |
| 1340 | 1340 | $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
| 1341 | 1341 | //if no obj then let's just do cap |
| 1342 | - if (! $obj instanceof EE_Base_Class) { |
|
| 1342 | + if ( ! $obj instanceof EE_Base_Class) { |
|
| 1343 | 1343 | $caps[] = 'do_not_allow'; |
| 1344 | 1344 | return $caps; |
| 1345 | 1345 | } |
| 1346 | 1346 | |
| 1347 | - $caps[] = $cap . 's'; |
|
| 1347 | + $caps[] = $cap.'s'; |
|
| 1348 | 1348 | if ($obj instanceof EE_CPT_Base) { |
| 1349 | 1349 | $status_obj = get_post_status_object($obj->status()); |
| 1350 | 1350 | if ($status_obj->public) { |
@@ -1352,7 +1352,7 @@ discard block |
||
| 1352 | 1352 | } |
| 1353 | 1353 | //if the item author is set and the user is not the author... |
| 1354 | 1354 | if ($obj->wp_user() && $obj->wp_user() !== $user_id) { |
| 1355 | - if (! empty($this->others_cap)) { |
|
| 1355 | + if ( ! empty($this->others_cap)) { |
|
| 1356 | 1356 | $caps[] = $this->others_cap; |
| 1357 | 1357 | } |
| 1358 | 1358 | } |
@@ -1376,11 +1376,11 @@ discard block |
||
| 1376 | 1376 | EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
| 1377 | 1377 | } |
| 1378 | 1378 | } |
| 1379 | - if (! $has_cap) { |
|
| 1380 | - if (! empty($this->private_cap)) { |
|
| 1379 | + if ( ! $has_cap) { |
|
| 1380 | + if ( ! empty($this->private_cap)) { |
|
| 1381 | 1381 | $caps[] = $this->private_cap; |
| 1382 | 1382 | } |
| 1383 | - if (! empty($this->others_cap)) { |
|
| 1383 | + if ( ! empty($this->others_cap)) { |
|
| 1384 | 1384 | $caps[] = $this->others_cap; |
| 1385 | 1385 | } |
| 1386 | 1386 | } |
@@ -1434,11 +1434,11 @@ discard block |
||
| 1434 | 1434 | |
| 1435 | 1435 | $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
| 1436 | 1436 | //if no obj then let's just do cap |
| 1437 | - if (! $obj instanceof EE_Message_Template_Group) { |
|
| 1437 | + if ( ! $obj instanceof EE_Message_Template_Group) { |
|
| 1438 | 1438 | $caps[] = 'do_not_allow'; |
| 1439 | 1439 | return $caps; |
| 1440 | 1440 | } |
| 1441 | - $caps[] = $cap . 's'; |
|
| 1441 | + $caps[] = $cap.'s'; |
|
| 1442 | 1442 | $is_global = $obj->is_global(); |
| 1443 | 1443 | if ($obj->wp_user() && $obj->wp_user() === $user_id) { |
| 1444 | 1444 | if ($is_global) { |
@@ -1493,11 +1493,11 @@ discard block |
||
| 1493 | 1493 | } |
| 1494 | 1494 | $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
| 1495 | 1495 | //if no obj then let's just do cap |
| 1496 | - if (! $obj instanceof EE_Base_Class) { |
|
| 1496 | + if ( ! $obj instanceof EE_Base_Class) { |
|
| 1497 | 1497 | $caps[] = 'do_not_allow'; |
| 1498 | 1498 | return $caps; |
| 1499 | 1499 | } |
| 1500 | - $caps[] = $cap . 's'; |
|
| 1500 | + $caps[] = $cap.'s'; |
|
| 1501 | 1501 | $is_system = $obj instanceof EE_Question_Group ? $obj->system_group() : false; |
| 1502 | 1502 | $is_system = $obj instanceof EE_Question ? $obj->is_system_question() : $is_system; |
| 1503 | 1503 | if ($is_system) { |