Completed
Branch FET-10486-add-timestamp-checki... (611b15)
by
unknown
105:07 queued 90:18
created
acceptance_tests/Page/MessagesAdmin.php 2 patches
Indentation   +125 added lines, -125 removed lines patch added patch discarded remove patch
@@ -12,130 +12,130 @@
 block discarded – undo
12 12
 class MessagesAdmin extends CoreAdmin
13 13
 {
14 14
 
15
-    /**
16
-     * Context slug for the admin messages context.
17
-     * @var string
18
-     */
19
-    const ADMIN_CONTEXT_SLUG = 'admin';
20
-
21
-    /**
22
-     * Context slug for the primary attendee messages context
23
-     * @var string
24
-     */
25
-    const PRIMARY_ATTENDEE_CONTEXT_SLUG = 'primary_attendee';
26
-
27
-
28
-    /**
29
-     * Status reference for the EEM_Message::status_sent status.
30
-     * @var string
31
-     */
32
-    const MESSAGE_STATUS_SENT = 'MSN';
33
-
34
-
35
-    /**
36
-     * Message type slug for the Payment Failed message type
37
-     */
38
-    const PAYMENT_FAILED_MESSAGE_TYPE_SLUG = 'payment_failed';
39
-
40
-
41
-    /**
42
-     * Selector for the Global Messages "Send on same request" field in the Messages Settings tab.
43
-     * @var string
44
-     */
45
-    const GLOBAL_MESSAGES_SETTINGS_ON_REQUEST_SELECTION_SELECTOR = '#global_messages_settings-do-messages-on-same-request';
46
-
47
-
48
-    /**
49
-     * Selector for the Global Messages Settings submit button in the Messages Settings tab.
50
-     * @var string
51
-     */
52
-    const GLOBAL_MESSAGES_SETTINGS_SUBMIT_SELECTOR = '#global_messages_settings-update-settings-submit';
53
-
54
-
55
-
56
-    /**
57
-     * @param string $additional_params Any additional request parameters for the generated url should be included as
58
-     *                                  a string.
59
-     * @return string
60
-     */
61
-    public static function messageActivityListTableUrl($additional_params = '')
62
-    {
63
-        return self::adminUrl('espresso_messages', 'default', $additional_params);
64
-    }
65
-
66
-
67
-    /**
68
-     * @param string $additional_params Any additional request parameters for the generated url should be included as
69
-     *                                  a string.
70
-     * @return string
71
-     */
72
-    public static function defaultMessageTemplateListTableUrl($additional_params = '')
73
-    {
74
-        return self::adminUrl('espresso_messages', 'global_mtps', $additional_params);
75
-    }
76
-
77
-
78
-    /**
79
-     * @param string $additional_params Any additional request parameters for the generated url should be included as
80
-     *                                  a string.
81
-     * @return string
82
-     */
83
-    public static function customMessageTemplateListTableUrl($additional_params = '')
84
-    {
85
-        return self::adminUrl('espresso_messages', 'custom_mtps', $additional_params);
86
-    }
87
-
88
-
89
-    /**
90
-     * @return string
91
-     */
92
-    public static function messageSettingsUrl()
93
-    {
94
-        return self::adminUrl('espresso_messages', 'settings');
95
-    }
96
-
97
-
98
-    /**
99
-     * @param string $message_type_slug
100
-     * @param string $context
101
-     * @return string
102
-     */
103
-    public static function editMessageTemplateClassByMessageType($message_type_slug, $context = '')
104
-    {
105
-        return $context
106
-            ? '.' . $message_type_slug . '-' . $context . '-edit-link'
107
-            : '.' . $message_type_slug . '-edit-link';
108
-    }
109
-
110
-
111
-    /**
112
-     * Selector for (a) specific table cell(s) in the Messages Activity list table for the given parameters.
113
-     * @param        $field
114
-     * @param        $message_type_label
115
-     * @param string $message_status
116
-     * @param string $messenger
117
-     * @param string $context
118
-     * @param string $table_cell_content_for_field
119
-     * @return string
120
-     */
121
-    public static function messagesActivityListTableCellSelectorFor(
122
-        $field,
123
-        $message_type_label,
124
-        $message_status = self::MESSAGE_STATUS_SENT,
125
-        $messenger = 'Email',
126
-        $context = 'Event Admin',
127
-        $table_cell_content_for_field = ''
128
-    ) {
129
-        $selector = "//tr[contains(@class, 'msg-status-$message_status')]"
130
-                . "//td[contains(@class, 'message_type') and text()='$message_type_label']";
131
-        if ($messenger) {
132
-            $selector .= "/ancestor::tr/td[contains(@class, 'messenger') and text()='$messenger']";
133
-        }
134
-        $selector .= "/ancestor::tr/td[contains(@class, 'column-context') and text()='$context']";
135
-        $selector .= $table_cell_content_for_field
136
-            ? "/ancestor::tr/td[contains(@class, 'column-$field') and text()='$table_cell_content_for_field']"
137
-            : "/ancestor::tr/td[contains(@class, 'column-$field')]";
138
-        return $selector;
139
-    }
15
+	/**
16
+	 * Context slug for the admin messages context.
17
+	 * @var string
18
+	 */
19
+	const ADMIN_CONTEXT_SLUG = 'admin';
20
+
21
+	/**
22
+	 * Context slug for the primary attendee messages context
23
+	 * @var string
24
+	 */
25
+	const PRIMARY_ATTENDEE_CONTEXT_SLUG = 'primary_attendee';
26
+
27
+
28
+	/**
29
+	 * Status reference for the EEM_Message::status_sent status.
30
+	 * @var string
31
+	 */
32
+	const MESSAGE_STATUS_SENT = 'MSN';
33
+
34
+
35
+	/**
36
+	 * Message type slug for the Payment Failed message type
37
+	 */
38
+	const PAYMENT_FAILED_MESSAGE_TYPE_SLUG = 'payment_failed';
39
+
40
+
41
+	/**
42
+	 * Selector for the Global Messages "Send on same request" field in the Messages Settings tab.
43
+	 * @var string
44
+	 */
45
+	const GLOBAL_MESSAGES_SETTINGS_ON_REQUEST_SELECTION_SELECTOR = '#global_messages_settings-do-messages-on-same-request';
46
+
47
+
48
+	/**
49
+	 * Selector for the Global Messages Settings submit button in the Messages Settings tab.
50
+	 * @var string
51
+	 */
52
+	const GLOBAL_MESSAGES_SETTINGS_SUBMIT_SELECTOR = '#global_messages_settings-update-settings-submit';
53
+
54
+
55
+
56
+	/**
57
+	 * @param string $additional_params Any additional request parameters for the generated url should be included as
58
+	 *                                  a string.
59
+	 * @return string
60
+	 */
61
+	public static function messageActivityListTableUrl($additional_params = '')
62
+	{
63
+		return self::adminUrl('espresso_messages', 'default', $additional_params);
64
+	}
65
+
66
+
67
+	/**
68
+	 * @param string $additional_params Any additional request parameters for the generated url should be included as
69
+	 *                                  a string.
70
+	 * @return string
71
+	 */
72
+	public static function defaultMessageTemplateListTableUrl($additional_params = '')
73
+	{
74
+		return self::adminUrl('espresso_messages', 'global_mtps', $additional_params);
75
+	}
76
+
77
+
78
+	/**
79
+	 * @param string $additional_params Any additional request parameters for the generated url should be included as
80
+	 *                                  a string.
81
+	 * @return string
82
+	 */
83
+	public static function customMessageTemplateListTableUrl($additional_params = '')
84
+	{
85
+		return self::adminUrl('espresso_messages', 'custom_mtps', $additional_params);
86
+	}
87
+
88
+
89
+	/**
90
+	 * @return string
91
+	 */
92
+	public static function messageSettingsUrl()
93
+	{
94
+		return self::adminUrl('espresso_messages', 'settings');
95
+	}
96
+
97
+
98
+	/**
99
+	 * @param string $message_type_slug
100
+	 * @param string $context
101
+	 * @return string
102
+	 */
103
+	public static function editMessageTemplateClassByMessageType($message_type_slug, $context = '')
104
+	{
105
+		return $context
106
+			? '.' . $message_type_slug . '-' . $context . '-edit-link'
107
+			: '.' . $message_type_slug . '-edit-link';
108
+	}
109
+
110
+
111
+	/**
112
+	 * Selector for (a) specific table cell(s) in the Messages Activity list table for the given parameters.
113
+	 * @param        $field
114
+	 * @param        $message_type_label
115
+	 * @param string $message_status
116
+	 * @param string $messenger
117
+	 * @param string $context
118
+	 * @param string $table_cell_content_for_field
119
+	 * @return string
120
+	 */
121
+	public static function messagesActivityListTableCellSelectorFor(
122
+		$field,
123
+		$message_type_label,
124
+		$message_status = self::MESSAGE_STATUS_SENT,
125
+		$messenger = 'Email',
126
+		$context = 'Event Admin',
127
+		$table_cell_content_for_field = ''
128
+	) {
129
+		$selector = "//tr[contains(@class, 'msg-status-$message_status')]"
130
+				. "//td[contains(@class, 'message_type') and text()='$message_type_label']";
131
+		if ($messenger) {
132
+			$selector .= "/ancestor::tr/td[contains(@class, 'messenger') and text()='$messenger']";
133
+		}
134
+		$selector .= "/ancestor::tr/td[contains(@class, 'column-context') and text()='$context']";
135
+		$selector .= $table_cell_content_for_field
136
+			? "/ancestor::tr/td[contains(@class, 'column-$field') and text()='$table_cell_content_for_field']"
137
+			: "/ancestor::tr/td[contains(@class, 'column-$field')]";
138
+		return $selector;
139
+	}
140 140
 
141 141
 }
142 142
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -103,8 +103,8 @@
 block discarded – undo
103 103
     public static function editMessageTemplateClassByMessageType($message_type_slug, $context = '')
104 104
     {
105 105
         return $context
106
-            ? '.' . $message_type_slug . '-' . $context . '-edit-link'
107
-            : '.' . $message_type_slug . '-edit-link';
106
+            ? '.'.$message_type_slug.'-'.$context.'-edit-link'
107
+            : '.'.$message_type_slug.'-edit-link';
108 108
     }
109 109
 
110 110
 
Please login to merge, or discard this patch.
acceptance_tests/Page/TicketSelector.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -12,24 +12,24 @@
 block discarded – undo
12 12
 class TicketSelector
13 13
 {
14 14
 
15
-    /**
16
-     * Return the selector for the ticket option select input for the given event id.
17
-     * @param int|string $event_id
18
-     * @return string
19
-     */
20
-    public static function ticketOptionByEventIdSelector($event_id)
21
-    {
22
-        return "//select[@id='ticket-selector-tbl-qty-slct-$event_id-1']";
23
-    }
15
+	/**
16
+	 * Return the selector for the ticket option select input for the given event id.
17
+	 * @param int|string $event_id
18
+	 * @return string
19
+	 */
20
+	public static function ticketOptionByEventIdSelector($event_id)
21
+	{
22
+		return "//select[@id='ticket-selector-tbl-qty-slct-$event_id-1']";
23
+	}
24 24
 
25 25
 
26
-    /**
27
-     * Return the selector for the submit button for the ticket selector for the given event id.
28
-     * @param int|string $event_id
29
-     * @return string
30
-     */
31
-    public static function ticketSelectionSubmitSelectorByEventId($event_id)
32
-    {
33
-        return "#ticket-selector-submit-$event_id-btn";
34
-    }
26
+	/**
27
+	 * Return the selector for the submit button for the ticket selector for the given event id.
28
+	 * @param int|string $event_id
29
+	 * @return string
30
+	 */
31
+	public static function ticketSelectionSubmitSelectorByEventId($event_id)
32
+	{
33
+		return "#ticket-selector-submit-$event_id-btn";
34
+	}
35 35
 }
36 36
\ No newline at end of file
Please login to merge, or discard this patch.
payment_methods/Invoice/EE_PMT_Invoice.pm.php 1 patch
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if (!defined('EVENT_ESPRESSO_VERSION'))
3
+if ( ! defined('EVENT_ESPRESSO_VERSION'))
4 4
 	exit('No direct script access allowed');
5 5
 
6 6
 /**
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
  *
26 26
  * ------------------------------------------------------------------------
27 27
  */
28
-class EE_PMT_Invoice extends EE_PMT_Base{
28
+class EE_PMT_Invoice extends EE_PMT_Base {
29 29
 
30 30
 
31 31
 
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 	public function __construct($pm_instance = NULL) {
38 38
 		$this->_pretty_name = esc_html__("Invoice", 'event_espresso');
39 39
 		$this->_default_description = sprintf(
40
-			esc_html__( 'After clicking "Finalize Registration", you will be given instructions on how to access your invoice and complete your payment.%sPlease note that event spaces will not be reserved until payment is received in full, and any remaining tickets could be sold to others in the meantime.', 'event_espresso' ),
40
+			esc_html__('After clicking "Finalize Registration", you will be given instructions on how to access your invoice and complete your payment.%sPlease note that event spaces will not be reserved until payment is received in full, and any remaining tickets could be sold to others in the meantime.', 'event_espresso'),
41 41
 			'<br />'
42 42
 		);
43 43
 		parent::__construct($pm_instance);
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 	 * @param \EE_Transaction $transaction
52 52
 	 * @return NULL
53 53
 	 */
54
-	public function generate_new_billing_form( EE_Transaction $transaction = NULL ) {
54
+	public function generate_new_billing_form(EE_Transaction $transaction = NULL) {
55 55
 		return NULL;
56 56
 	}
57 57
 
@@ -64,53 +64,53 @@  discard block
 block discarded – undo
64 64
 	public function generate_new_settings_form() {
65 65
 		$pdf_payee_input_name = 'pdf_payee_name';
66 66
 		$confirmation_text_input_name = 'page_confirmation_text';
67
-		$form =  new EE_Payment_Method_Form(array(
67
+		$form = new EE_Payment_Method_Form(array(
68 68
 //				'payment_method_type' => $this,
69 69
 				'extra_meta_inputs'=>array(
70 70
 					$pdf_payee_input_name => new EE_Text_Input(array(
71
-						'html_label_text' => sprintf( esc_html__( 'Payee Name %s', 'event_espresso' ), $this->get_help_tab_link())
71
+						'html_label_text' => sprintf(esc_html__('Payee Name %s', 'event_espresso'), $this->get_help_tab_link())
72 72
 					)),
73 73
 					'pdf_payee_email' => new EE_Email_Input(array(
74
-						'html_label_text' => sprintf( esc_html__( 'Payee Email %s', 'event_espresso' ), $this->get_help_tab_link()),
74
+						'html_label_text' => sprintf(esc_html__('Payee Email %s', 'event_espresso'), $this->get_help_tab_link()),
75 75
 					)),
76 76
 					'pdf_payee_tax_number' => new EE_Text_Input(array(
77
-						'html_label_text' => sprintf( esc_html__( 'Payee Tax Number %s', 'event_espresso' ), $this->get_help_tab_link()),
77
+						'html_label_text' => sprintf(esc_html__('Payee Tax Number %s', 'event_espresso'), $this->get_help_tab_link()),
78 78
 						)),
79
-					'pdf_payee_address' => new EE_Text_Area_Input( array(
80
-						'html_label_text' => sprintf( esc_html__( 'Payee Address %s', 'event_espresso' ), $this->get_help_tab_link() ),
81
-						'validation_strategies' => array( new EE_Full_HTML_Validation_Strategy() ),
79
+					'pdf_payee_address' => new EE_Text_Area_Input(array(
80
+						'html_label_text' => sprintf(esc_html__('Payee Address %s', 'event_espresso'), $this->get_help_tab_link()),
81
+						'validation_strategies' => array(new EE_Full_HTML_Validation_Strategy()),
82 82
 					)),
83 83
 					'pdf_instructions'=>new EE_Text_Area_Input(array(
84
-						'html_label_text'=>  sprintf(esc_html__("Instructions %s", "event_espresso"),  $this->get_help_tab_link()),
84
+						'html_label_text'=>  sprintf(esc_html__("Instructions %s", "event_espresso"), $this->get_help_tab_link()),
85 85
 						'default'=>  esc_html__("Please send this invoice with payment attached to the address above, or use the payment link below. Payment must be received within 48 hours of event date.", 'event_espresso'),
86
-						'validation_strategies' => array( new EE_Full_HTML_Validation_Strategy() ),
86
+						'validation_strategies' => array(new EE_Full_HTML_Validation_Strategy()),
87 87
 					)),
88 88
 					'pdf_logo_image'=>new EE_Admin_File_Uploader_Input(array(
89
-						'html_label_text'=>  sprintf(esc_html__("Logo Image %s", "event_espresso"),  $this->get_help_tab_link()),
89
+						'html_label_text'=>  sprintf(esc_html__("Logo Image %s", "event_espresso"), $this->get_help_tab_link()),
90 90
 						'default'=>  EE_Config::instance()->organization->logo_url,
91 91
 						'html_help_text'=>  esc_html__("(Logo for the top left of the invoice)", 'event_espresso'),
92 92
 					)),
93 93
 					$confirmation_text_input_name =>new EE_Text_Area_Input(array(
94
-						'html_label_text'=>  sprintf(esc_html__("Confirmation Text %s", "event_espresso"),  $this->get_help_tab_link()),
94
+						'html_label_text'=>  sprintf(esc_html__("Confirmation Text %s", "event_espresso"), $this->get_help_tab_link()),
95 95
 						'default'=>  esc_html__("Payment must be received within 48 hours of event date. Details about where to send the payment are included on the invoice.", 'event_espresso'), 
96
-						'validation_strategies' => array( new EE_Full_HTML_Validation_Strategy() ),
96
+						'validation_strategies' => array(new EE_Full_HTML_Validation_Strategy()),
97 97
 					)),
98 98
 					'page_extra_info'=>new EE_Text_Area_Input(array(
99
-						'html_label_text'=>  sprintf(esc_html__("Extra Info %s", "event_espresso"),  $this->get_help_tab_link()),
100
-						'validation_strategies' => array( new EE_Full_HTML_Validation_Strategy() ),
99
+						'html_label_text'=>  sprintf(esc_html__("Extra Info %s", "event_espresso"), $this->get_help_tab_link()),
100
+						'validation_strategies' => array(new EE_Full_HTML_Validation_Strategy()),
101 101
 					)),
102 102
 				),
103 103
 				'include'=>array(
104
-					'PMD_ID', 'PMD_name','PMD_desc','PMD_admin_name','PMD_admin_desc', 'PMD_type','PMD_slug', 'PMD_open_by_default','PMD_button_url','PMD_scope','Currency','PMD_order',
105
-					$pdf_payee_input_name, 'pdf_payee_email', 'pdf_payee_tax_number', 'pdf_payee_address', 'pdf_instructions','pdf_logo_image',
104
+					'PMD_ID', 'PMD_name', 'PMD_desc', 'PMD_admin_name', 'PMD_admin_desc', 'PMD_type', 'PMD_slug', 'PMD_open_by_default', 'PMD_button_url', 'PMD_scope', 'Currency', 'PMD_order',
105
+					$pdf_payee_input_name, 'pdf_payee_email', 'pdf_payee_tax_number', 'pdf_payee_address', 'pdf_instructions', 'pdf_logo_image',
106 106
 					$confirmation_text_input_name, 'page_extra_info'),
107 107
 			));
108 108
 		$form->add_subsections(
109
-			array( 'header1' => new EE_Form_Section_HTML_From_Template( 'payment_methods/Invoice/templates/invoice_settings_header_display.template.php' )),
109
+			array('header1' => new EE_Form_Section_HTML_From_Template('payment_methods/Invoice/templates/invoice_settings_header_display.template.php')),
110 110
 			$pdf_payee_input_name
111 111
 		);
112 112
 		$form->add_subsections(
113
-			array( 'header2'=>new EE_Form_Section_HTML_From_Template( 'payment_methods/Invoice/templates/invoice_settings_header_gateway.template.php' )),
113
+			array('header2'=>new EE_Form_Section_HTML_From_Template('payment_methods/Invoice/templates/invoice_settings_header_gateway.template.php')),
114 114
 			$confirmation_text_input_name
115 115
 		);
116 116
 		return $form;
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
 	 * @see EE_PMT_Base::help_tabs_config()
124 124
 	 * @return array
125 125
 	 */
126
-	public function help_tabs_config(){
126
+	public function help_tabs_config() {
127 127
 		return array(
128 128
 			$this->get_help_tab_name() => array(
129 129
 				'title' => esc_html__('Invoice Settings', 'event_espresso'),
@@ -141,16 +141,16 @@  discard block
 block discarded – undo
141 141
 	 * @param \EE_Payment $payment
142 142
 	 * @return string
143 143
 	 */
144
-	public function payment_overview_content( EE_Payment $payment ){
144
+	public function payment_overview_content(EE_Payment $payment) {
145 145
 		return EEH_Template::locate_template(
146
-			'payment_methods' . DS . 'Invoice'. DS . 'templates'.DS.'invoice_payment_details_content.template.php',
146
+			'payment_methods'.DS.'Invoice'.DS.'templates'.DS.'invoice_payment_details_content.template.php',
147 147
 			array_merge(
148 148
 				array(
149 149
 					'payment_method'			=> $this->_pm_instance,
150 150
 					'payment'						=> $payment,
151 151
 					'page_confirmation_text'					=> '',
152 152
 					'page_extra_info'	=> '',
153
-					'invoice_url' 					=> $payment->transaction()->primary_registration()->invoice_url( 'html' )
153
+					'invoice_url' 					=> $payment->transaction()->primary_registration()->invoice_url('html')
154 154
 				),
155 155
 				$this->_pm_instance->all_extra_meta_array()
156 156
 			)
Please login to merge, or discard this patch.
acceptance_tests/Helpers/EventsAdmin.php 1 patch
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -14,51 +14,51 @@
 block discarded – undo
14 14
 trait EventsAdmin
15 15
 {
16 16
 
17
-    /**
18
-     * @param string $additional_params
19
-     */
20
-    public function amOnDefaultEventsListTablePage($additional_params = '')
21
-    {
22
-        $this->actor()->amOnAdminPage(EventsPage::defaultEventsListTableUrl($additional_params));
23
-    }
17
+	/**
18
+	 * @param string $additional_params
19
+	 */
20
+	public function amOnDefaultEventsListTablePage($additional_params = '')
21
+	{
22
+		$this->actor()->amOnAdminPage(EventsPage::defaultEventsListTableUrl($additional_params));
23
+	}
24 24
 
25 25
 
26
-    /**
27
-     * Triggers the publishing of the Event.
28
-     */
29
-    public function publishEvent()
30
-    {
31
-        $this->actor()->click(EventsPage::EVENT_EDITOR_PUBLISH_BUTTON_SELECTOR);
32
-    }
26
+	/**
27
+	 * Triggers the publishing of the Event.
28
+	 */
29
+	public function publishEvent()
30
+	{
31
+		$this->actor()->click(EventsPage::EVENT_EDITOR_PUBLISH_BUTTON_SELECTOR);
32
+	}
33 33
 
34 34
 
35
-    /**
36
-     * Navigates the actor to the event list table page and will attempt to edit the event for the given title.
37
-     * First this will search using the given title and then attempt to edit from the results of the search.
38
-     *
39
-     * Assumes actor is already logged in.
40
-     * @param $event_title
41
-     */
42
-    public function amEditingTheEventWithTitle($event_title)
43
-    {
44
-        $this->amOnDefaultEventsListTablePage();
45
-        $this->actor()->fillField(EventsPage::EVENT_LIST_TABLE_SEARCH_INPUT_SELECTOR, $event_title);
46
-        $this->actor()->click(CoreAdmin::LIST_TABLE_SEARCH_SUBMIT_SELECTOR);
47
-        $this->actor()->waitForText('Displaying search results for');
48
-        $this->actor()->click(EventsPage::eventListTableEventTitleEditLink($event_title));
49
-    }
35
+	/**
36
+	 * Navigates the actor to the event list table page and will attempt to edit the event for the given title.
37
+	 * First this will search using the given title and then attempt to edit from the results of the search.
38
+	 *
39
+	 * Assumes actor is already logged in.
40
+	 * @param $event_title
41
+	 */
42
+	public function amEditingTheEventWithTitle($event_title)
43
+	{
44
+		$this->amOnDefaultEventsListTablePage();
45
+		$this->actor()->fillField(EventsPage::EVENT_LIST_TABLE_SEARCH_INPUT_SELECTOR, $event_title);
46
+		$this->actor()->click(CoreAdmin::LIST_TABLE_SEARCH_SUBMIT_SELECTOR);
47
+		$this->actor()->waitForText('Displaying search results for');
48
+		$this->actor()->click(EventsPage::eventListTableEventTitleEditLink($event_title));
49
+	}
50 50
 
51 51
 
52
-    /**
53
-     * Navigates the user to the single event page (frontend view) for the given event title via clicking the "View" link
54
-     * for the event in the event list table.
55
-     *
56
-     * Assumes the actor is already logged in and on the Event list table page.
57
-     * @param string $event_title
58
-     */
59
-    public function amOnEventPageAfterClickingViewLinkInListTableForEvent($event_title)
60
-    {
61
-        $this->actor()->moveMouseOver(EventsPage::eventListTableEventTitleEditLinkSelectorForTitle($event_title));
62
-        $this->actor()->click(EventsPage::eventListTableEventTitleViewLinkSelectorForTitle($event_title));
63
-    }
52
+	/**
53
+	 * Navigates the user to the single event page (frontend view) for the given event title via clicking the "View" link
54
+	 * for the event in the event list table.
55
+	 *
56
+	 * Assumes the actor is already logged in and on the Event list table page.
57
+	 * @param string $event_title
58
+	 */
59
+	public function amOnEventPageAfterClickingViewLinkInListTableForEvent($event_title)
60
+	{
61
+		$this->actor()->moveMouseOver(EventsPage::eventListTableEventTitleEditLinkSelectorForTitle($event_title));
62
+		$this->actor()->click(EventsPage::eventListTableEventTitleViewLinkSelectorForTitle($event_title));
63
+	}
64 64
 }
65 65
\ No newline at end of file
Please login to merge, or discard this patch.
acceptance_tests/Helpers/MessagesAdmin.php 1 patch
Indentation   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -10,96 +10,96 @@
 block discarded – undo
10 10
  */
11 11
 trait MessagesAdmin
12 12
 {
13
-    /**
14
-     * @param string $additional_params Any additional request parameters for the generated url should be included as
15
-     *                                  a string.
16
-     */
17
-    public function amOnMessagesActivityListTablePage($additional_params = '')
18
-    {
19
-        $this->actor()->amOnAdminPage(MessagesPage::messageActivityListTableUrl($additional_params));
20
-    }
13
+	/**
14
+	 * @param string $additional_params Any additional request parameters for the generated url should be included as
15
+	 *                                  a string.
16
+	 */
17
+	public function amOnMessagesActivityListTablePage($additional_params = '')
18
+	{
19
+		$this->actor()->amOnAdminPage(MessagesPage::messageActivityListTableUrl($additional_params));
20
+	}
21 21
 
22
-    /**
23
-     * @param string $additional_params Any additional request parameters for the generated url should be included as
24
-     *                                  a string.
25
-     */
26
-    public function amOnDefaultMessageTemplateListTablePage($additional_params = '')
27
-    {
28
-        $this->actor()->amOnAdminPage(MessagesPage::defaultMessageTemplateListTableUrl($additional_params));
29
-    }
22
+	/**
23
+	 * @param string $additional_params Any additional request parameters for the generated url should be included as
24
+	 *                                  a string.
25
+	 */
26
+	public function amOnDefaultMessageTemplateListTablePage($additional_params = '')
27
+	{
28
+		$this->actor()->amOnAdminPage(MessagesPage::defaultMessageTemplateListTableUrl($additional_params));
29
+	}
30 30
 
31 31
 
32
-    /**
33
-     * @param string $additional_params Any additional request parameters for the generated url should be included as
34
-     *                                  a string.
35
-     */
36
-    public function amOnCustomMessageTemplateListTablePage($additional_params = '')
37
-    {
38
-        $this->actor()->amOnAdminPage(MessagesPage::customMessageTemplateListTableUrl($additional_params));
39
-    }
32
+	/**
33
+	 * @param string $additional_params Any additional request parameters for the generated url should be included as
34
+	 *                                  a string.
35
+	 */
36
+	public function amOnCustomMessageTemplateListTablePage($additional_params = '')
37
+	{
38
+		$this->actor()->amOnAdminPage(MessagesPage::customMessageTemplateListTableUrl($additional_params));
39
+	}
40 40
 
41 41
 
42
-    /**
43
-     * Directs to message settings page
44
-     */
45
-    public function amOnMessageSettingsPage()
46
-    {
47
-        $this->actor()->amOnAdminPage(MessagesPage::messageSettingsUrl());
48
-    }
42
+	/**
43
+	 * Directs to message settings page
44
+	 */
45
+	public function amOnMessageSettingsPage()
46
+	{
47
+		$this->actor()->amOnAdminPage(MessagesPage::messageSettingsUrl());
48
+	}
49 49
 
50 50
 
51
-    /**
52
-     * Assumes you are already on the list table page that has the ui for editing the template.
53
-     * @param string $message_type_slug
54
-     * @param string $context [optional] if you want to click directly to the given context in the editor
55
-     */
56
-    public function clickToEditMessageTemplateByMessageType($message_type_slug, $context = '')
57
-    {
58
-        $this->actor()->click(MessagesPage::editMessageTemplateClassByMessageType($message_type_slug, $context));
59
-    }
51
+	/**
52
+	 * Assumes you are already on the list table page that has the ui for editing the template.
53
+	 * @param string $message_type_slug
54
+	 * @param string $context [optional] if you want to click directly to the given context in the editor
55
+	 */
56
+	public function clickToEditMessageTemplateByMessageType($message_type_slug, $context = '')
57
+	{
58
+		$this->actor()->click(MessagesPage::editMessageTemplateClassByMessageType($message_type_slug, $context));
59
+	}
60 60
 
61 61
 
62
-    /**
63
-     * Use this action to verify that the count for the given text in the specified field is as expected.  For example
64
-     * filling the condition of, "There should only be 1 instance of `[email protected]` in all the 'to' column.
65
-     *
66
-     * @param int    $expected_occurence_count
67
-     * @param string $text_to_check_for
68
-     * @param string $field
69
-     * @param string $message_type_label
70
-     * @param string $message_status
71
-     * @param string $messenger
72
-     * @param string $context
73
-     */
74
-    public function verifyMatchingCountofTextInMessageActivityListTableFor(
75
-        $expected_occurence_count,
76
-        $text_to_check_for,
77
-        $field,
78
-        $message_type_label,
79
-        $message_status = MessagesPage::MESSAGE_STATUS_SENT,
80
-        $messenger = 'Email',
81
-        $context = 'Event Admin'
82
-    ) {
83
-        $elements = $this->actor()->grabMultiple(MessagesPage::messagesActivityListTableCellSelectorFor(
84
-            $field,
85
-            $message_type_label,
86
-            $message_status,
87
-            $messenger,
88
-            $context,
89
-            $text_to_check_for
90
-        ));
91
-        $actual_count = count($elements);
92
-        $this->actor()->assertEquals(
93
-            $expected_occurence_count,
94
-            $actual_count,
95
-            sprintf(
96
-                'Expected %s of the %s text for the %s field but there were actually %s counted.',
97
-                $expected_occurence_count,
98
-                $text_to_check_for,
99
-                $field,
100
-                $actual_count
101
-            )
102
-        );
103
-    }
62
+	/**
63
+	 * Use this action to verify that the count for the given text in the specified field is as expected.  For example
64
+	 * filling the condition of, "There should only be 1 instance of `[email protected]` in all the 'to' column.
65
+	 *
66
+	 * @param int    $expected_occurence_count
67
+	 * @param string $text_to_check_for
68
+	 * @param string $field
69
+	 * @param string $message_type_label
70
+	 * @param string $message_status
71
+	 * @param string $messenger
72
+	 * @param string $context
73
+	 */
74
+	public function verifyMatchingCountofTextInMessageActivityListTableFor(
75
+		$expected_occurence_count,
76
+		$text_to_check_for,
77
+		$field,
78
+		$message_type_label,
79
+		$message_status = MessagesPage::MESSAGE_STATUS_SENT,
80
+		$messenger = 'Email',
81
+		$context = 'Event Admin'
82
+	) {
83
+		$elements = $this->actor()->grabMultiple(MessagesPage::messagesActivityListTableCellSelectorFor(
84
+			$field,
85
+			$message_type_label,
86
+			$message_status,
87
+			$messenger,
88
+			$context,
89
+			$text_to_check_for
90
+		));
91
+		$actual_count = count($elements);
92
+		$this->actor()->assertEquals(
93
+			$expected_occurence_count,
94
+			$actual_count,
95
+			sprintf(
96
+				'Expected %s of the %s text for the %s field but there were actually %s counted.',
97
+				$expected_occurence_count,
98
+				$text_to_check_for,
99
+				$field,
100
+				$actual_count
101
+			)
102
+		);
103
+	}
104 104
 
105 105
 }
106 106
\ No newline at end of file
Please login to merge, or discard this patch.
acceptance_tests/Helpers/BaseCoreAdmin.php 1 patch
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -13,39 +13,39 @@
 block discarded – undo
13 13
 trait BaseCoreAdmin
14 14
 {
15 15
 
16
-    /**
17
-     * Core method for going to an Event Espresso Admin page.
18
-     * @param string $page
19
-     * @param string $action
20
-     * @param string $additional_params
21
-     */
22
-    public function amOnEventEspressoAdminPage($page = '', $action = '', $additional_params = '')
23
-    {
24
-        $this->actor()->amOnAdminPage(CoreAdmin::adminUrl($page, $action, $additional_params));
25
-    }
16
+	/**
17
+	 * Core method for going to an Event Espresso Admin page.
18
+	 * @param string $page
19
+	 * @param string $action
20
+	 * @param string $additional_params
21
+	 */
22
+	public function amOnEventEspressoAdminPage($page = '', $action = '', $additional_params = '')
23
+	{
24
+		$this->actor()->amOnAdminPage(CoreAdmin::adminUrl($page, $action, $additional_params));
25
+	}
26 26
 
27 27
 
28
-    /**
29
-     * Helper method for returning an instance of the Actor.  Intended to help with IDE fill out of methods.
30
-     * @return \EventEspressoAcceptanceTester;
31
-     */
32
-    protected function actor()
33
-    {
34
-        /** @var \EventEspressoAcceptanceTester $this */
35
-        return $this;
36
-    }
28
+	/**
29
+	 * Helper method for returning an instance of the Actor.  Intended to help with IDE fill out of methods.
30
+	 * @return \EventEspressoAcceptanceTester;
31
+	 */
32
+	protected function actor()
33
+	{
34
+		/** @var \EventEspressoAcceptanceTester $this */
35
+		return $this;
36
+	}
37 37
 
38 38
 
39
-    /**
40
-     * Use this to set the per page option for a list table page.
41
-     * Assumes you are on a page that has this field exposed.
42
-     * @param int|string $per_page_value
43
-     */
44
-    public function setPerPageOptionForScreen($per_page_value)
45
-    {
46
-        $this->actor()->click(CoreAdmin::WP_SCREEN_SETTINGS_LINK_SELECTOR);
47
-        $this->actor()->fillField(CoreAdmin::WP_SCREEN_SETTINGS_PER_PAGE_FIELD_SELECTOR, $per_page_value);
48
-        $this->actor()->click(CoreAdmin::WP_SCREEN_OPTIONS_APPLY_SETTINGS_BUTTON_SELECTOR);
49
-        $this->actor()->wait(8);
50
-    }
39
+	/**
40
+	 * Use this to set the per page option for a list table page.
41
+	 * Assumes you are on a page that has this field exposed.
42
+	 * @param int|string $per_page_value
43
+	 */
44
+	public function setPerPageOptionForScreen($per_page_value)
45
+	{
46
+		$this->actor()->click(CoreAdmin::WP_SCREEN_SETTINGS_LINK_SELECTOR);
47
+		$this->actor()->fillField(CoreAdmin::WP_SCREEN_SETTINGS_PER_PAGE_FIELD_SELECTOR, $per_page_value);
48
+		$this->actor()->click(CoreAdmin::WP_SCREEN_OPTIONS_APPLY_SETTINGS_BUTTON_SELECTOR);
49
+		$this->actor()->wait(8);
50
+	}
51 51
 }
52 52
\ No newline at end of file
Please login to merge, or discard this patch.
acceptance_tests/Page/EventsAdmin.php 1 patch
Indentation   +132 added lines, -132 removed lines patch added patch discarded remove patch
@@ -14,136 +14,136 @@
 block discarded – undo
14 14
 class EventsAdmin extends CoreAdmin
15 15
 {
16 16
 
17
-    /**
18
-     * Selector for the Add new Event button in the admin.
19
-     * @var string
20
-     */
21
-    const ADD_NEW_EVENT_BUTTON_SELECTOR = '#add-new-event';
22
-
23
-
24
-    /**
25
-     * Selector for the Event Title field in the event editor
26
-     * @var string
27
-     */
28
-    const EVENT_EDITOR_TITLE_FIELD_SELECTOR = "//input[@id='title']";
29
-
30
-    /**
31
-     * Selector for the publish submit button in the event editor.
32
-     * @var string
33
-     */
34
-    const EVENT_EDITOR_PUBLISH_BUTTON_SELECTOR = "#publish";
35
-
36
-    /**
37
-     * Selector for the view link after publishing an event.
38
-     * @var string
39
-     */
40
-    const EVENT_EDITOR_VIEW_LINK_AFTER_PUBLISH_SELECTOR = "//div[@id='message']/p/a";
41
-
42
-
43
-    /**
44
-     * Selector for the ID of the event in the event editor
45
-     * @var string
46
-     */
47
-    const EVENT_EDITOR_EVT_ID_SELECTOR = "//input[@id='post_ID']";
48
-
49
-
50
-    /**
51
-     * Selector for the search input on the event list table page.
52
-     * @var string
53
-     */
54
-    const EVENT_LIST_TABLE_SEARCH_INPUT_SELECTOR = '#toplevel_page_espresso_events-search-input';
55
-
56
-
57
-
58
-    /**
59
-     * @param string $additional_params
60
-     * @return string
61
-     */
62
-    public static function defaultEventsListTableUrl($additional_params = '')
63
-    {
64
-        return self::adminUrl('espresso_events', 'default', $additional_params);
65
-    }
66
-
67
-
68
-    /**
69
-     * The selector for the DTTname field for the given row in the event editor.
70
-     * @param int $row_number
71
-     * @return string
72
-     */
73
-    public static function eventEditorDatetimeNameFieldSelector($row_number = 1)
74
-    {
75
-        return self::eventEditorDatetimeFieldSelectorForField('DTT_name', $row_number);
76
-    }
77
-
78
-
79
-    /**
80
-     * The selector for the DTT_EVT_start field for the given row in the event editor.d
81
-     * @param int $row_number
82
-     * @return string
83
-     */
84
-    public static function eventEditorDatetimeStartDateFieldSelector($row_number = 1)
85
-    {
86
-        return self::eventEditorDatetimeFieldSelectorForField('DTT_EVT_start', $row_number);
87
-    }
88
-
89
-
90
-    /**
91
-     * Wrapper for getting the selector for a given field and given row of a datetime in the event editor.
92
-     *
93
-     * @param string $field_name
94
-     * @param int    $row_number
95
-     * @return string
96
-     */
97
-    public static function eventEditorDatetimeFieldSelectorForField($field_name, $row_number = 1)
98
-    {
99
-        return "//input[@id='event-datetime-$field_name-$row_number']";
100
-    }
101
-
102
-
103
-    /**
104
-     * The selector for the TKT_name field for the given display row in the event editor.
105
-     * @param int $row_number
106
-     * @return string
107
-     */
108
-    public static function eventEditorTicketNameFieldSelector($row_number = 1)
109
-    {
110
-        return self::eventEditorTicketFieldSelectorForFieldInDisplayRow('TKT_name', $row_number);
111
-    }
112
-
113
-
114
-    /**
115
-     * Wrapper for getting the selector for a given field and given display row of a ticket in the event editor.
116
-     * @param     $field_name
117
-     * @param int $row_number
118
-     * @return string
119
-     */
120
-    public static function eventEditorTicketFieldSelectorForFieldInDisplayRow($field_name, $row_number = 1)
121
-    {
122
-        return "//tr[@id='display-ticketrow-$row_number']/td[2]/input[@class='edit-ticket-$field_name ee-large-text-inp']";
123
-    }
124
-
125
-
126
-    /**
127
-     * Returns the selector for the event title edit link in the events list table for the given Event Title.
128
-     * @param string $event_title
129
-     * @return string
130
-     */
131
-    public static function eventListTableEventTitleEditLinkSelectorForTitle($event_title)
132
-    {
133
-        return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']";
134
-    }
135
-
136
-
137
-    public static function eventListTableEventIdSelectorForTitle($event_title)
138
-    {
139
-        return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']"
140
-            . "//ancestor::tr/th[contains(@class, 'check-column')]/input";
141
-    }
142
-
143
-
144
-    public static function eventListTableEventTitleViewLinkSelectorForTitle($event_title)
145
-    {
146
-        return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']"
147
-            . "//ancestor::td//span[@class='view']/a";
148
-    }
17
+	/**
18
+	 * Selector for the Add new Event button in the admin.
19
+	 * @var string
20
+	 */
21
+	const ADD_NEW_EVENT_BUTTON_SELECTOR = '#add-new-event';
22
+
23
+
24
+	/**
25
+	 * Selector for the Event Title field in the event editor
26
+	 * @var string
27
+	 */
28
+	const EVENT_EDITOR_TITLE_FIELD_SELECTOR = "//input[@id='title']";
29
+
30
+	/**
31
+	 * Selector for the publish submit button in the event editor.
32
+	 * @var string
33
+	 */
34
+	const EVENT_EDITOR_PUBLISH_BUTTON_SELECTOR = "#publish";
35
+
36
+	/**
37
+	 * Selector for the view link after publishing an event.
38
+	 * @var string
39
+	 */
40
+	const EVENT_EDITOR_VIEW_LINK_AFTER_PUBLISH_SELECTOR = "//div[@id='message']/p/a";
41
+
42
+
43
+	/**
44
+	 * Selector for the ID of the event in the event editor
45
+	 * @var string
46
+	 */
47
+	const EVENT_EDITOR_EVT_ID_SELECTOR = "//input[@id='post_ID']";
48
+
49
+
50
+	/**
51
+	 * Selector for the search input on the event list table page.
52
+	 * @var string
53
+	 */
54
+	const EVENT_LIST_TABLE_SEARCH_INPUT_SELECTOR = '#toplevel_page_espresso_events-search-input';
55
+
56
+
57
+
58
+	/**
59
+	 * @param string $additional_params
60
+	 * @return string
61
+	 */
62
+	public static function defaultEventsListTableUrl($additional_params = '')
63
+	{
64
+		return self::adminUrl('espresso_events', 'default', $additional_params);
65
+	}
66
+
67
+
68
+	/**
69
+	 * The selector for the DTTname field for the given row in the event editor.
70
+	 * @param int $row_number
71
+	 * @return string
72
+	 */
73
+	public static function eventEditorDatetimeNameFieldSelector($row_number = 1)
74
+	{
75
+		return self::eventEditorDatetimeFieldSelectorForField('DTT_name', $row_number);
76
+	}
77
+
78
+
79
+	/**
80
+	 * The selector for the DTT_EVT_start field for the given row in the event editor.d
81
+	 * @param int $row_number
82
+	 * @return string
83
+	 */
84
+	public static function eventEditorDatetimeStartDateFieldSelector($row_number = 1)
85
+	{
86
+		return self::eventEditorDatetimeFieldSelectorForField('DTT_EVT_start', $row_number);
87
+	}
88
+
89
+
90
+	/**
91
+	 * Wrapper for getting the selector for a given field and given row of a datetime in the event editor.
92
+	 *
93
+	 * @param string $field_name
94
+	 * @param int    $row_number
95
+	 * @return string
96
+	 */
97
+	public static function eventEditorDatetimeFieldSelectorForField($field_name, $row_number = 1)
98
+	{
99
+		return "//input[@id='event-datetime-$field_name-$row_number']";
100
+	}
101
+
102
+
103
+	/**
104
+	 * The selector for the TKT_name field for the given display row in the event editor.
105
+	 * @param int $row_number
106
+	 * @return string
107
+	 */
108
+	public static function eventEditorTicketNameFieldSelector($row_number = 1)
109
+	{
110
+		return self::eventEditorTicketFieldSelectorForFieldInDisplayRow('TKT_name', $row_number);
111
+	}
112
+
113
+
114
+	/**
115
+	 * Wrapper for getting the selector for a given field and given display row of a ticket in the event editor.
116
+	 * @param     $field_name
117
+	 * @param int $row_number
118
+	 * @return string
119
+	 */
120
+	public static function eventEditorTicketFieldSelectorForFieldInDisplayRow($field_name, $row_number = 1)
121
+	{
122
+		return "//tr[@id='display-ticketrow-$row_number']/td[2]/input[@class='edit-ticket-$field_name ee-large-text-inp']";
123
+	}
124
+
125
+
126
+	/**
127
+	 * Returns the selector for the event title edit link in the events list table for the given Event Title.
128
+	 * @param string $event_title
129
+	 * @return string
130
+	 */
131
+	public static function eventListTableEventTitleEditLinkSelectorForTitle($event_title)
132
+	{
133
+		return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']";
134
+	}
135
+
136
+
137
+	public static function eventListTableEventIdSelectorForTitle($event_title)
138
+	{
139
+		return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']"
140
+			. "//ancestor::tr/th[contains(@class, 'check-column')]/input";
141
+	}
142
+
143
+
144
+	public static function eventListTableEventTitleViewLinkSelectorForTitle($event_title)
145
+	{
146
+		return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']"
147
+			. "//ancestor::td//span[@class='view']/a";
148
+	}
149 149
 }
150 150
\ No newline at end of file
Please login to merge, or discard this patch.
core/libraries/payment_methods/EE_Payment_Method_Manager.lib.php 1 patch
Indentation   +402 added lines, -402 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 
5 5
 
@@ -17,402 +17,402 @@  discard block
 block discarded – undo
17 17
 class EE_Payment_Method_Manager
18 18
 {
19 19
 
20
-    /**
21
-     *    instance of the EE_Payment_Method_Manager object
22
-     *
23
-     * @var    $_instance
24
-     * @access    private
25
-     */
26
-    private static $_instance;
27
-
28
-    /**
29
-     * @var array keys are classnames without 'EE_PMT_', values are their filepaths
30
-     */
31
-    protected $_payment_method_types = array();
32
-
33
-
34
-
35
-    /**
36
-     * @singleton method used to instantiate class object
37
-     * @access    public
38
-     * @return EE_Payment_Method_Manager instance
39
-     */
40
-    public static function instance()
41
-    {
42
-        // check if class object is instantiated, and instantiated properly
43
-        if ( ! self::$_instance instanceof EE_Payment_Method_Manager) {
44
-            self::$_instance = new self();
45
-        }
46
-        EE_Registry::instance()->load_lib('PMT_Base');
47
-        return self::$_instance;
48
-    }
49
-
50
-
51
-
52
-    /**
53
-     * Resets the instance and returns a new one
54
-     *
55
-     * @return EE_Payment_Method_Manager
56
-     */
57
-    public static function reset()
58
-    {
59
-        self::$_instance = null;
60
-        return self::instance();
61
-    }
62
-
63
-
64
-
65
-    /**
66
-     * If necessary, re-register payment methods
67
-     *
68
-     * @param boolean $force_recheck whether to recheck for payment method types,
69
-     *                               or just re-use the PMTs we found last time we checked during this request (if
70
-     *                               we have not yet checked during this request, then we need to check anyways)
71
-     */
72
-    public function maybe_register_payment_methods($force_recheck = false)
73
-    {
74
-        if ( ! $this->_payment_method_types || $force_recheck) {
75
-            $this->_register_payment_methods();
76
-        }
77
-    }
78
-
79
-
80
-
81
-    /**
82
-     *        register_payment_methods
83
-     *
84
-     * @return array
85
-     */
86
-    protected function _register_payment_methods()
87
-    {
88
-        // grab list of installed modules
89
-        $pm_to_register = glob(EE_PAYMENT_METHODS . '*', GLOB_ONLYDIR);
90
-        // filter list of modules to register
91
-        $pm_to_register = apply_filters('FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register',
92
-            $pm_to_register);
93
-        // loop through folders
94
-        foreach ($pm_to_register as $pm_path) {
95
-            $this->register_payment_method($pm_path);
96
-        }
97
-        do_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods');
98
-        // filter list of installed modules
99
-        //keep them organized alphabetically by the payment method type's name
100
-        ksort($this->_payment_method_types);
101
-        return apply_filters('FHEE__EE_Payment_Method_Manager__register_payment_methods__installed_payment_methods',
102
-            $this->_payment_method_types);
103
-    }
104
-
105
-
106
-
107
-    /**
108
-     *    register_payment_method- makes core aware of this payment method
109
-     *
110
-     * @access public
111
-     * @param string $payment_method_path - full path up to and including payment method folder
112
-     * @return boolean
113
-     */
114
-    public function register_payment_method($payment_method_path = '')
115
-    {
116
-        do_action('AHEE__EE_Payment_Method_Manager__register_payment_method__begin', $payment_method_path);
117
-        $module_ext = '.pm.php';
118
-        // make all separators match
119
-        $payment_method_path = rtrim(str_replace('/\\', DS, $payment_method_path), DS);
120
-        // grab and sanitize module name
121
-        $module_dir = basename($payment_method_path);
122
-        // create classname from module directory name
123
-        $module = str_replace(' ', '_', str_replace('_', ' ', $module_dir));
124
-        // add class prefix
125
-        $module_class = 'EE_PMT_' . $module;
126
-        // does the module exist ?
127
-        if ( ! is_readable($payment_method_path . DS . $module_class . $module_ext)) {
128
-            $msg = sprintf(__('The requested %s payment method file could not be found or is not readable due to file permissions.',
129
-                'event_espresso'), $module);
130
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
131
-            return false;
132
-        }
133
-        if (WP_DEBUG === true) {
134
-            EEH_Debug_Tools::instance()->start_timer();
135
-        }
136
-        // load the module class file
137
-        require_once($payment_method_path . DS . $module_class . $module_ext);
138
-        if (WP_DEBUG === true) {
139
-            EEH_Debug_Tools::instance()->stop_timer("Requiring payment method $module_class");
140
-        }
141
-        // verify that class exists
142
-        if ( ! class_exists($module_class)) {
143
-            $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class);
144
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
145
-            return false;
146
-        }
147
-        // add to array of registered modules
148
-        $this->_payment_method_types[$module] = $payment_method_path . DS . $module_class . $module_ext;
149
-        return true;
150
-    }
151
-
152
-
153
-
154
-    /**
155
-     * Checks if a payment method has been registered, and if so includes it
156
-     *
157
-     * @param string  $payment_method_name like 'Paypal_Pro', (ie classname without the prefix 'EEPM_')
158
-     * @param boolean $force_recheck       whether to force re-checking for new payment method types
159
-     * @return boolean
160
-     */
161
-    public function payment_method_type_exists($payment_method_name, $force_recheck = false)
162
-    {
163
-        if (
164
-            $force_recheck
165
-            || ! is_array($this->_payment_method_types)
166
-            || ! isset($this->_payment_method_types[$payment_method_name])
167
-        ) {
168
-            $this->maybe_register_payment_methods($force_recheck);
169
-        }
170
-        if (isset($this->_payment_method_types[$payment_method_name])) {
171
-            require_once($this->_payment_method_types[$payment_method_name]);
172
-            return true;
173
-        } else {
174
-            return false;
175
-        }
176
-    }
177
-
178
-
179
-
180
-    /**
181
-     * Returns all the classnames of the various payment method types
182
-     *
183
-     * @param boolean $with_prefixes TRUE: get payment method type classnames; false just their 'names'
184
-     *                               (what you'd find in wp_esp_payment_method.PMD_type)
185
-     * @param boolean $force_recheck whether to force re-checking for new payment method types
186
-     * @return array
187
-     */
188
-    public function payment_method_type_names($with_prefixes = false, $force_recheck = false)
189
-    {
190
-        $this->maybe_register_payment_methods($force_recheck);
191
-        if ($with_prefixes) {
192
-            $classnames = array_keys($this->_payment_method_types);
193
-            $payment_methods = array();
194
-            foreach ($classnames as $classname) {
195
-                $payment_methods[] = $this->payment_method_class_from_type($classname);
196
-            }
197
-            return $payment_methods;
198
-        } else {
199
-            return array_keys($this->_payment_method_types);
200
-        }
201
-    }
202
-
203
-
204
-
205
-    /**
206
-     * Gets an object of each payment method type, none of which are bound to a
207
-     * payment method instance
208
-     *
209
-     * @param boolean $force_recheck whether to force re-checking for new payment method types
210
-     * @return EE_PMT_Base[]
211
-     */
212
-    public function payment_method_types($force_recheck = false)
213
-    {
214
-        $this->maybe_register_payment_methods($force_recheck);
215
-        $pmt_objs = array();
216
-        foreach ($this->payment_method_type_names(true) as $classname) {
217
-            $pmt_objs[] = new $classname;
218
-        }
219
-        return $pmt_objs;
220
-    }
221
-
222
-
223
-
224
-    /**
225
-     * Changes the payment method's classname into the payment method type's name
226
-     * (as used on the payment method's table's PMD_type field)
227
-     *
228
-     * @param string $classname
229
-     * @return string
230
-     */
231
-    public function payment_method_type_sans_class_prefix($classname)
232
-    {
233
-        return str_replace("EE_PMT_", "", $classname);
234
-    }
235
-
236
-
237
-
238
-    /**
239
-     * Does the opposite of payment-method_type_sans_prefix
240
-     *
241
-     * @param string $type
242
-     * @return string
243
-     */
244
-    public function payment_method_class_from_type($type)
245
-    {
246
-        $this->maybe_register_payment_methods();
247
-        return "EE_PMT_" . $type;
248
-    }
249
-
250
-
251
-
252
-    /**
253
-     * Activates a payment method of the given type.
254
-     *
255
-     * @param string $payment_method_type the PMT_type; for EE_PMT_Invoice this would be 'Invoice'
256
-     * @return \EE_Payment_Method
257
-     * @throws \EE_Error
258
-     */
259
-    public function activate_a_payment_method_of_type($payment_method_type)
260
-    {
261
-        $payment_method = EEM_Payment_Method::instance()->get_one_of_type($payment_method_type);
262
-        if ( ! $payment_method instanceof EE_Payment_Method) {
263
-            $pm_type_class = $this->payment_method_class_from_type($payment_method_type);
264
-            if (class_exists($pm_type_class)) {
265
-                /** @var $pm_type_obj EE_PMT_Base */
266
-                $pm_type_obj = new $pm_type_class;
267
-                $payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_type_obj->system_name());
268
-                if ( ! $payment_method) {
269
-                    $payment_method = $this->create_payment_method_of_type($pm_type_obj);
270
-                }
271
-                $payment_method->set_type($payment_method_type);
272
-                $this->initialize_payment_method($payment_method);
273
-            } else {
274
-                throw new EE_Error(
275
-                    sprintf(
276
-                        __('There is no payment method of type %1$s, so it could not be activated', 'event_espresso'),
277
-                        $pm_type_class)
278
-                );
279
-            }
280
-        }
281
-        $payment_method->set_active();
282
-        $payment_method->save();
283
-        $this->set_usable_currencies_on_payment_method($payment_method);
284
-        if ($payment_method->type() === 'Invoice') {
285
-            /** @type EE_Message_Resource_Manager $message_resource_manager */
286
-            $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
287
-            $message_resource_manager->ensure_message_type_is_active('invoice', 'html');
288
-            $message_resource_manager->ensure_messenger_is_active('pdf');
289
-            EE_Error::add_persistent_admin_notice(
290
-                'invoice_pm_requirements_notice',
291
-                sprintf(
292
-                    __('The Invoice payment method has been activated. It requires the invoice message type, html messenger, and pdf messenger be activated as well for the %1$smessages system%2$s, so it has been automatically verified that they are also active.',
293
-                        'event_espresso'),
294
-                    '<a href="' . admin_url('admin.php?page=espresso_messages') . '">',
295
-                    '</a>'
296
-                ),
297
-                true
298
-            );
299
-        }
300
-        return $payment_method;
301
-    }
302
-
303
-
304
-
305
-    /**
306
-     * Creates a payment method of the specified type. Does not save it.
307
-     *
308
-     * @global WP_User    $current_user
309
-     * @param EE_PMT_Base $pm_type_obj
310
-     * @return EE_Payment_Method
311
-     * @throws \EE_Error
312
-     */
313
-    public function create_payment_method_of_type($pm_type_obj)
314
-    {
315
-        global $current_user;
316
-        $payment_method = EE_Payment_Method::new_instance(
317
-            array(
318
-                'PMD_type'       => $pm_type_obj->system_name(),
319
-                'PMD_name'       => $pm_type_obj->pretty_name(),
320
-                'PMD_admin_name' => $pm_type_obj->pretty_name(),
321
-                'PMD_slug'       => $pm_type_obj->system_name(),//automatically converted to slug
322
-                'PMD_wp_user'    => $current_user->ID,
323
-                'PMD_order'      => EEM_Payment_Method::instance()->count(
324
-                        array(array('PMD_type' => array('!=', 'Admin_Only')))
325
-                    ) * 10,
326
-            )
327
-        );
328
-        return $payment_method;
329
-    }
330
-
331
-
332
-
333
-    /**
334
-     * Sets the initial payment method properties (including extra meta)
335
-     *
336
-     * @param EE_Payment_Method $payment_method
337
-     * @return EE_Payment_Method
338
-     * @throws \EE_Error
339
-     */
340
-    public function initialize_payment_method($payment_method)
341
-    {
342
-        $pm_type_obj = $payment_method->type_obj();
343
-        $payment_method->set_description($pm_type_obj->default_description());
344
-        if ( ! $payment_method->button_url()) {
345
-            $payment_method->set_button_url($pm_type_obj->default_button_url());
346
-        }
347
-        //now add setup its default extra meta properties
348
-        $extra_metas = $pm_type_obj->settings_form()->extra_meta_inputs();
349
-        if ( ! empty($extra_metas)) {
350
-            //verify the payment method has an ID before adding extra meta
351
-            if ( ! $payment_method->ID()) {
352
-                $payment_method->save();
353
-            }
354
-            foreach ($extra_metas as $meta_name => $input) {
355
-                $payment_method->update_extra_meta($meta_name, $input->raw_value());
356
-            }
357
-        }
358
-        return $payment_method;
359
-    }
360
-
361
-
362
-
363
-    /**
364
-     * Makes sure the payment method is related to the specified payment method
365
-     *
366
-     * @param EE_Payment_Method $payment_method
367
-     * @return EE_Payment_Method
368
-     * @throws \EE_Error
369
-     */
370
-    public function set_usable_currencies_on_payment_method($payment_method)
371
-    {
372
-        foreach ($payment_method->get_all_usable_currencies() as $currency_obj) {
373
-            $payment_method->_add_relation_to($currency_obj, 'Currency');
374
-        }
375
-        return $payment_method;
376
-    }
377
-
378
-
379
-
380
-    /**
381
-     * Deactivates a payment method of the given payment method slug.
382
-     *
383
-     * @param string $payment_method_slug The slug for the payment method to deactivate.
384
-     * @return int count of rows updated.
385
-     */
386
-    public function deactivate_payment_method($payment_method_slug)
387
-    {
388
-        EE_Log::instance()->log(
389
-            __FILE__,
390
-            __FUNCTION__,
391
-            sprintf(
392
-                __('Payment method with slug %1$s is being deactivated by site admin', 'event_espresso'),
393
-                $payment_method_slug
394
-            ),
395
-            'payment_method_change'
396
-        );
397
-        $count_updated = EEM_Payment_Method::instance()->update(
398
-            array('PMD_scope' => array()),
399
-            array(array('PMD_slug' => $payment_method_slug))
400
-        );
401
-        return $count_updated;
402
-    }
403
-
404
-
405
-
406
-    /**
407
-     * callback for FHEE__EE_Capabilities__init_caps_map__caps filter to add dynamic payment method
408
-     * access caps.
409
-     *
410
-     * @param array $caps capabilities being filtered
411
-     * @return array
412
-     */
413
-    public function add_payment_method_caps($caps)
414
-    {
415
-        /* add dynamic caps from payment methods
20
+	/**
21
+	 *    instance of the EE_Payment_Method_Manager object
22
+	 *
23
+	 * @var    $_instance
24
+	 * @access    private
25
+	 */
26
+	private static $_instance;
27
+
28
+	/**
29
+	 * @var array keys are classnames without 'EE_PMT_', values are their filepaths
30
+	 */
31
+	protected $_payment_method_types = array();
32
+
33
+
34
+
35
+	/**
36
+	 * @singleton method used to instantiate class object
37
+	 * @access    public
38
+	 * @return EE_Payment_Method_Manager instance
39
+	 */
40
+	public static function instance()
41
+	{
42
+		// check if class object is instantiated, and instantiated properly
43
+		if ( ! self::$_instance instanceof EE_Payment_Method_Manager) {
44
+			self::$_instance = new self();
45
+		}
46
+		EE_Registry::instance()->load_lib('PMT_Base');
47
+		return self::$_instance;
48
+	}
49
+
50
+
51
+
52
+	/**
53
+	 * Resets the instance and returns a new one
54
+	 *
55
+	 * @return EE_Payment_Method_Manager
56
+	 */
57
+	public static function reset()
58
+	{
59
+		self::$_instance = null;
60
+		return self::instance();
61
+	}
62
+
63
+
64
+
65
+	/**
66
+	 * If necessary, re-register payment methods
67
+	 *
68
+	 * @param boolean $force_recheck whether to recheck for payment method types,
69
+	 *                               or just re-use the PMTs we found last time we checked during this request (if
70
+	 *                               we have not yet checked during this request, then we need to check anyways)
71
+	 */
72
+	public function maybe_register_payment_methods($force_recheck = false)
73
+	{
74
+		if ( ! $this->_payment_method_types || $force_recheck) {
75
+			$this->_register_payment_methods();
76
+		}
77
+	}
78
+
79
+
80
+
81
+	/**
82
+	 *        register_payment_methods
83
+	 *
84
+	 * @return array
85
+	 */
86
+	protected function _register_payment_methods()
87
+	{
88
+		// grab list of installed modules
89
+		$pm_to_register = glob(EE_PAYMENT_METHODS . '*', GLOB_ONLYDIR);
90
+		// filter list of modules to register
91
+		$pm_to_register = apply_filters('FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register',
92
+			$pm_to_register);
93
+		// loop through folders
94
+		foreach ($pm_to_register as $pm_path) {
95
+			$this->register_payment_method($pm_path);
96
+		}
97
+		do_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods');
98
+		// filter list of installed modules
99
+		//keep them organized alphabetically by the payment method type's name
100
+		ksort($this->_payment_method_types);
101
+		return apply_filters('FHEE__EE_Payment_Method_Manager__register_payment_methods__installed_payment_methods',
102
+			$this->_payment_method_types);
103
+	}
104
+
105
+
106
+
107
+	/**
108
+	 *    register_payment_method- makes core aware of this payment method
109
+	 *
110
+	 * @access public
111
+	 * @param string $payment_method_path - full path up to and including payment method folder
112
+	 * @return boolean
113
+	 */
114
+	public function register_payment_method($payment_method_path = '')
115
+	{
116
+		do_action('AHEE__EE_Payment_Method_Manager__register_payment_method__begin', $payment_method_path);
117
+		$module_ext = '.pm.php';
118
+		// make all separators match
119
+		$payment_method_path = rtrim(str_replace('/\\', DS, $payment_method_path), DS);
120
+		// grab and sanitize module name
121
+		$module_dir = basename($payment_method_path);
122
+		// create classname from module directory name
123
+		$module = str_replace(' ', '_', str_replace('_', ' ', $module_dir));
124
+		// add class prefix
125
+		$module_class = 'EE_PMT_' . $module;
126
+		// does the module exist ?
127
+		if ( ! is_readable($payment_method_path . DS . $module_class . $module_ext)) {
128
+			$msg = sprintf(__('The requested %s payment method file could not be found or is not readable due to file permissions.',
129
+				'event_espresso'), $module);
130
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
131
+			return false;
132
+		}
133
+		if (WP_DEBUG === true) {
134
+			EEH_Debug_Tools::instance()->start_timer();
135
+		}
136
+		// load the module class file
137
+		require_once($payment_method_path . DS . $module_class . $module_ext);
138
+		if (WP_DEBUG === true) {
139
+			EEH_Debug_Tools::instance()->stop_timer("Requiring payment method $module_class");
140
+		}
141
+		// verify that class exists
142
+		if ( ! class_exists($module_class)) {
143
+			$msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class);
144
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
145
+			return false;
146
+		}
147
+		// add to array of registered modules
148
+		$this->_payment_method_types[$module] = $payment_method_path . DS . $module_class . $module_ext;
149
+		return true;
150
+	}
151
+
152
+
153
+
154
+	/**
155
+	 * Checks if a payment method has been registered, and if so includes it
156
+	 *
157
+	 * @param string  $payment_method_name like 'Paypal_Pro', (ie classname without the prefix 'EEPM_')
158
+	 * @param boolean $force_recheck       whether to force re-checking for new payment method types
159
+	 * @return boolean
160
+	 */
161
+	public function payment_method_type_exists($payment_method_name, $force_recheck = false)
162
+	{
163
+		if (
164
+			$force_recheck
165
+			|| ! is_array($this->_payment_method_types)
166
+			|| ! isset($this->_payment_method_types[$payment_method_name])
167
+		) {
168
+			$this->maybe_register_payment_methods($force_recheck);
169
+		}
170
+		if (isset($this->_payment_method_types[$payment_method_name])) {
171
+			require_once($this->_payment_method_types[$payment_method_name]);
172
+			return true;
173
+		} else {
174
+			return false;
175
+		}
176
+	}
177
+
178
+
179
+
180
+	/**
181
+	 * Returns all the classnames of the various payment method types
182
+	 *
183
+	 * @param boolean $with_prefixes TRUE: get payment method type classnames; false just their 'names'
184
+	 *                               (what you'd find in wp_esp_payment_method.PMD_type)
185
+	 * @param boolean $force_recheck whether to force re-checking for new payment method types
186
+	 * @return array
187
+	 */
188
+	public function payment_method_type_names($with_prefixes = false, $force_recheck = false)
189
+	{
190
+		$this->maybe_register_payment_methods($force_recheck);
191
+		if ($with_prefixes) {
192
+			$classnames = array_keys($this->_payment_method_types);
193
+			$payment_methods = array();
194
+			foreach ($classnames as $classname) {
195
+				$payment_methods[] = $this->payment_method_class_from_type($classname);
196
+			}
197
+			return $payment_methods;
198
+		} else {
199
+			return array_keys($this->_payment_method_types);
200
+		}
201
+	}
202
+
203
+
204
+
205
+	/**
206
+	 * Gets an object of each payment method type, none of which are bound to a
207
+	 * payment method instance
208
+	 *
209
+	 * @param boolean $force_recheck whether to force re-checking for new payment method types
210
+	 * @return EE_PMT_Base[]
211
+	 */
212
+	public function payment_method_types($force_recheck = false)
213
+	{
214
+		$this->maybe_register_payment_methods($force_recheck);
215
+		$pmt_objs = array();
216
+		foreach ($this->payment_method_type_names(true) as $classname) {
217
+			$pmt_objs[] = new $classname;
218
+		}
219
+		return $pmt_objs;
220
+	}
221
+
222
+
223
+
224
+	/**
225
+	 * Changes the payment method's classname into the payment method type's name
226
+	 * (as used on the payment method's table's PMD_type field)
227
+	 *
228
+	 * @param string $classname
229
+	 * @return string
230
+	 */
231
+	public function payment_method_type_sans_class_prefix($classname)
232
+	{
233
+		return str_replace("EE_PMT_", "", $classname);
234
+	}
235
+
236
+
237
+
238
+	/**
239
+	 * Does the opposite of payment-method_type_sans_prefix
240
+	 *
241
+	 * @param string $type
242
+	 * @return string
243
+	 */
244
+	public function payment_method_class_from_type($type)
245
+	{
246
+		$this->maybe_register_payment_methods();
247
+		return "EE_PMT_" . $type;
248
+	}
249
+
250
+
251
+
252
+	/**
253
+	 * Activates a payment method of the given type.
254
+	 *
255
+	 * @param string $payment_method_type the PMT_type; for EE_PMT_Invoice this would be 'Invoice'
256
+	 * @return \EE_Payment_Method
257
+	 * @throws \EE_Error
258
+	 */
259
+	public function activate_a_payment_method_of_type($payment_method_type)
260
+	{
261
+		$payment_method = EEM_Payment_Method::instance()->get_one_of_type($payment_method_type);
262
+		if ( ! $payment_method instanceof EE_Payment_Method) {
263
+			$pm_type_class = $this->payment_method_class_from_type($payment_method_type);
264
+			if (class_exists($pm_type_class)) {
265
+				/** @var $pm_type_obj EE_PMT_Base */
266
+				$pm_type_obj = new $pm_type_class;
267
+				$payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_type_obj->system_name());
268
+				if ( ! $payment_method) {
269
+					$payment_method = $this->create_payment_method_of_type($pm_type_obj);
270
+				}
271
+				$payment_method->set_type($payment_method_type);
272
+				$this->initialize_payment_method($payment_method);
273
+			} else {
274
+				throw new EE_Error(
275
+					sprintf(
276
+						__('There is no payment method of type %1$s, so it could not be activated', 'event_espresso'),
277
+						$pm_type_class)
278
+				);
279
+			}
280
+		}
281
+		$payment_method->set_active();
282
+		$payment_method->save();
283
+		$this->set_usable_currencies_on_payment_method($payment_method);
284
+		if ($payment_method->type() === 'Invoice') {
285
+			/** @type EE_Message_Resource_Manager $message_resource_manager */
286
+			$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
287
+			$message_resource_manager->ensure_message_type_is_active('invoice', 'html');
288
+			$message_resource_manager->ensure_messenger_is_active('pdf');
289
+			EE_Error::add_persistent_admin_notice(
290
+				'invoice_pm_requirements_notice',
291
+				sprintf(
292
+					__('The Invoice payment method has been activated. It requires the invoice message type, html messenger, and pdf messenger be activated as well for the %1$smessages system%2$s, so it has been automatically verified that they are also active.',
293
+						'event_espresso'),
294
+					'<a href="' . admin_url('admin.php?page=espresso_messages') . '">',
295
+					'</a>'
296
+				),
297
+				true
298
+			);
299
+		}
300
+		return $payment_method;
301
+	}
302
+
303
+
304
+
305
+	/**
306
+	 * Creates a payment method of the specified type. Does not save it.
307
+	 *
308
+	 * @global WP_User    $current_user
309
+	 * @param EE_PMT_Base $pm_type_obj
310
+	 * @return EE_Payment_Method
311
+	 * @throws \EE_Error
312
+	 */
313
+	public function create_payment_method_of_type($pm_type_obj)
314
+	{
315
+		global $current_user;
316
+		$payment_method = EE_Payment_Method::new_instance(
317
+			array(
318
+				'PMD_type'       => $pm_type_obj->system_name(),
319
+				'PMD_name'       => $pm_type_obj->pretty_name(),
320
+				'PMD_admin_name' => $pm_type_obj->pretty_name(),
321
+				'PMD_slug'       => $pm_type_obj->system_name(),//automatically converted to slug
322
+				'PMD_wp_user'    => $current_user->ID,
323
+				'PMD_order'      => EEM_Payment_Method::instance()->count(
324
+						array(array('PMD_type' => array('!=', 'Admin_Only')))
325
+					) * 10,
326
+			)
327
+		);
328
+		return $payment_method;
329
+	}
330
+
331
+
332
+
333
+	/**
334
+	 * Sets the initial payment method properties (including extra meta)
335
+	 *
336
+	 * @param EE_Payment_Method $payment_method
337
+	 * @return EE_Payment_Method
338
+	 * @throws \EE_Error
339
+	 */
340
+	public function initialize_payment_method($payment_method)
341
+	{
342
+		$pm_type_obj = $payment_method->type_obj();
343
+		$payment_method->set_description($pm_type_obj->default_description());
344
+		if ( ! $payment_method->button_url()) {
345
+			$payment_method->set_button_url($pm_type_obj->default_button_url());
346
+		}
347
+		//now add setup its default extra meta properties
348
+		$extra_metas = $pm_type_obj->settings_form()->extra_meta_inputs();
349
+		if ( ! empty($extra_metas)) {
350
+			//verify the payment method has an ID before adding extra meta
351
+			if ( ! $payment_method->ID()) {
352
+				$payment_method->save();
353
+			}
354
+			foreach ($extra_metas as $meta_name => $input) {
355
+				$payment_method->update_extra_meta($meta_name, $input->raw_value());
356
+			}
357
+		}
358
+		return $payment_method;
359
+	}
360
+
361
+
362
+
363
+	/**
364
+	 * Makes sure the payment method is related to the specified payment method
365
+	 *
366
+	 * @param EE_Payment_Method $payment_method
367
+	 * @return EE_Payment_Method
368
+	 * @throws \EE_Error
369
+	 */
370
+	public function set_usable_currencies_on_payment_method($payment_method)
371
+	{
372
+		foreach ($payment_method->get_all_usable_currencies() as $currency_obj) {
373
+			$payment_method->_add_relation_to($currency_obj, 'Currency');
374
+		}
375
+		return $payment_method;
376
+	}
377
+
378
+
379
+
380
+	/**
381
+	 * Deactivates a payment method of the given payment method slug.
382
+	 *
383
+	 * @param string $payment_method_slug The slug for the payment method to deactivate.
384
+	 * @return int count of rows updated.
385
+	 */
386
+	public function deactivate_payment_method($payment_method_slug)
387
+	{
388
+		EE_Log::instance()->log(
389
+			__FILE__,
390
+			__FUNCTION__,
391
+			sprintf(
392
+				__('Payment method with slug %1$s is being deactivated by site admin', 'event_espresso'),
393
+				$payment_method_slug
394
+			),
395
+			'payment_method_change'
396
+		);
397
+		$count_updated = EEM_Payment_Method::instance()->update(
398
+			array('PMD_scope' => array()),
399
+			array(array('PMD_slug' => $payment_method_slug))
400
+		);
401
+		return $count_updated;
402
+	}
403
+
404
+
405
+
406
+	/**
407
+	 * callback for FHEE__EE_Capabilities__init_caps_map__caps filter to add dynamic payment method
408
+	 * access caps.
409
+	 *
410
+	 * @param array $caps capabilities being filtered
411
+	 * @return array
412
+	 */
413
+	public function add_payment_method_caps($caps)
414
+	{
415
+		/* add dynamic caps from payment methods
416 416
          * at the time of writing, october 20 2014, these are the caps added:
417 417
          * ee_payment_method_admin_only
418 418
          * ee_payment_method_aim
@@ -426,10 +426,10 @@  discard block
 block discarded – undo
426 426
          * their related capability automatically added too, so long as they are
427 427
          * registered properly using EE_Register_Payment_Method::register()
428 428
          */
429
-        foreach ($this->payment_method_types() as $payment_method_type_obj) {
430
-            $caps['administrator'][] = $payment_method_type_obj->cap_name();
431
-        }
432
-        return $caps;
433
-    }
429
+		foreach ($this->payment_method_types() as $payment_method_type_obj) {
430
+			$caps['administrator'][] = $payment_method_type_obj->cap_name();
431
+		}
432
+		return $caps;
433
+	}
434 434
 
435 435
 }
Please login to merge, or discard this patch.
core/helpers/EEH_Activation.helper.php 1 patch
Indentation   +1652 added lines, -1652 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 
5 5
 
@@ -14,243 +14,243 @@  discard block
 block discarded – undo
14 14
 class EEH_Activation
15 15
 {
16 16
 
17
-    /**
18
-     * constant used to indicate a cron task is no longer in use
19
-     */
20
-    const cron_task_no_longer_in_use = 'no_longer_in_use';
21
-
22
-    /**
23
-     * option name that will indicate whether or not we still
24
-     * need to create EE's folders in the uploads directory
25
-     * (because if EE was installed without file system access,
26
-     * we need to request credentials before we can create them)
27
-     */
28
-    const upload_directories_incomplete_option_name = 'ee_upload_directories_incomplete';
29
-
30
-    /**
31
-     * WP_User->ID
32
-     *
33
-     * @var int
34
-     */
35
-    private static $_default_creator_id;
36
-
37
-    /**
38
-     * indicates whether or not we've already verified core's default data during this request,
39
-     * because after migrations are done, any addons activated while in maintenance mode
40
-     * will want to setup their own default data, and they might hook into core's default data
41
-     * and trigger core to setup its default data. In which case they might all ask for core to init its default data.
42
-     * This prevents doing that for EVERY single addon.
43
-     *
44
-     * @var boolean
45
-     */
46
-    protected static $_initialized_db_content_already_in_this_request = false;
47
-
48
-    /**
49
-     * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
50
-     */
51
-    private static $table_analysis;
52
-
53
-    /**
54
-     * @var \EventEspresso\core\services\database\TableManager $table_manager
55
-     */
56
-    private static $table_manager;
57
-
58
-
59
-    /**
60
-     * @return \EventEspresso\core\services\database\TableAnalysis
61
-     */
62
-    public static function getTableAnalysis()
63
-    {
64
-        if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) {
65
-            self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
66
-        }
67
-        return self::$table_analysis;
68
-    }
69
-
70
-
71
-    /**
72
-     * @return \EventEspresso\core\services\database\TableManager
73
-     */
74
-    public static function getTableManager()
75
-    {
76
-        if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) {
77
-            self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true);
78
-        }
79
-        return self::$table_manager;
80
-    }
81
-
82
-
83
-    /**
84
-     *    _ensure_table_name_has_prefix
85
-     *
86
-     * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix()
87
-     * @access     public
88
-     * @static
89
-     * @param $table_name
90
-     * @return string
91
-     */
92
-    public static function ensure_table_name_has_prefix($table_name)
93
-    {
94
-        return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name);
95
-    }
96
-
97
-
98
-    /**
99
-     *    system_initialization
100
-     *    ensures the EE configuration settings are loaded with at least default options set
101
-     *    and that all critical EE pages have been generated with the appropriate shortcodes in place
102
-     *
103
-     * @access public
104
-     * @static
105
-     * @return void
106
-     */
107
-    public static function system_initialization()
108
-    {
109
-        EEH_Activation::reset_and_update_config();
110
-        //which is fired BEFORE activation of plugin anyways
111
-        EEH_Activation::verify_default_pages_exist();
112
-    }
113
-
114
-
115
-    /**
116
-     * Sets the database schema and creates folders. This should
117
-     * be called on plugin activation and reactivation
118
-     *
119
-     * @return boolean success, whether the database and folders are setup properly
120
-     * @throws \EE_Error
121
-     */
122
-    public static function initialize_db_and_folders()
123
-    {
124
-        $good_filesystem = EEH_Activation::create_upload_directories();
125
-        $good_db         = EEH_Activation::create_database_tables();
126
-        return $good_filesystem && $good_db;
127
-    }
128
-
129
-
130
-    /**
131
-     * assuming we have an up-to-date database schema, this will populate it
132
-     * with default and initial data. This should be called
133
-     * upon activation of a new plugin, reactivation, and at the end
134
-     * of running migration scripts
135
-     *
136
-     * @throws \EE_Error
137
-     */
138
-    public static function initialize_db_content()
139
-    {
140
-        //let's avoid doing all this logic repeatedly, especially when addons are requesting it
141
-        if (EEH_Activation::$_initialized_db_content_already_in_this_request) {
142
-            return;
143
-        }
144
-        EEH_Activation::$_initialized_db_content_already_in_this_request = true;
145
-
146
-        EEH_Activation::initialize_system_questions();
147
-        EEH_Activation::insert_default_status_codes();
148
-        EEH_Activation::generate_default_message_templates();
149
-        EEH_Activation::create_no_ticket_prices_array();
150
-        EEH_Activation::validate_messages_system();
151
-        EEH_Activation::insert_default_payment_methods();
152
-        //in case we've
153
-        EEH_Activation::remove_cron_tasks();
154
-        EEH_Activation::create_cron_tasks();
155
-        // remove all TXN locks since that is being done via extra meta now
156
-        delete_option('ee_locked_transactions');
157
-        //also, check for CAF default db content
158
-        do_action('AHEE__EEH_Activation__initialize_db_content');
159
-        //also: EEM_Gateways::load_all_gateways() outputs a lot of success messages
160
-        //which users really won't care about on initial activation
161
-        EE_Error::overwrite_success();
162
-    }
163
-
164
-
165
-    /**
166
-     * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"),
167
-     * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event
168
-     * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use
169
-     * (null)
170
-     *
171
-     * @param string $which_to_include can be 'current' (ones that are currently in use),
172
-     *                                 'old' (only returns ones that should no longer be used),or 'all',
173
-     * @return array
174
-     * @throws \EE_Error
175
-     */
176
-    public static function get_cron_tasks($which_to_include)
177
-    {
178
-        $cron_tasks = apply_filters(
179
-            'FHEE__EEH_Activation__get_cron_tasks',
180
-            array(
181
-                'AHEE__EE_Cron_Tasks__clean_up_junk_transactions'      => 'hourly',
17
+	/**
18
+	 * constant used to indicate a cron task is no longer in use
19
+	 */
20
+	const cron_task_no_longer_in_use = 'no_longer_in_use';
21
+
22
+	/**
23
+	 * option name that will indicate whether or not we still
24
+	 * need to create EE's folders in the uploads directory
25
+	 * (because if EE was installed without file system access,
26
+	 * we need to request credentials before we can create them)
27
+	 */
28
+	const upload_directories_incomplete_option_name = 'ee_upload_directories_incomplete';
29
+
30
+	/**
31
+	 * WP_User->ID
32
+	 *
33
+	 * @var int
34
+	 */
35
+	private static $_default_creator_id;
36
+
37
+	/**
38
+	 * indicates whether or not we've already verified core's default data during this request,
39
+	 * because after migrations are done, any addons activated while in maintenance mode
40
+	 * will want to setup their own default data, and they might hook into core's default data
41
+	 * and trigger core to setup its default data. In which case they might all ask for core to init its default data.
42
+	 * This prevents doing that for EVERY single addon.
43
+	 *
44
+	 * @var boolean
45
+	 */
46
+	protected static $_initialized_db_content_already_in_this_request = false;
47
+
48
+	/**
49
+	 * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
50
+	 */
51
+	private static $table_analysis;
52
+
53
+	/**
54
+	 * @var \EventEspresso\core\services\database\TableManager $table_manager
55
+	 */
56
+	private static $table_manager;
57
+
58
+
59
+	/**
60
+	 * @return \EventEspresso\core\services\database\TableAnalysis
61
+	 */
62
+	public static function getTableAnalysis()
63
+	{
64
+		if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) {
65
+			self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
66
+		}
67
+		return self::$table_analysis;
68
+	}
69
+
70
+
71
+	/**
72
+	 * @return \EventEspresso\core\services\database\TableManager
73
+	 */
74
+	public static function getTableManager()
75
+	{
76
+		if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) {
77
+			self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true);
78
+		}
79
+		return self::$table_manager;
80
+	}
81
+
82
+
83
+	/**
84
+	 *    _ensure_table_name_has_prefix
85
+	 *
86
+	 * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix()
87
+	 * @access     public
88
+	 * @static
89
+	 * @param $table_name
90
+	 * @return string
91
+	 */
92
+	public static function ensure_table_name_has_prefix($table_name)
93
+	{
94
+		return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name);
95
+	}
96
+
97
+
98
+	/**
99
+	 *    system_initialization
100
+	 *    ensures the EE configuration settings are loaded with at least default options set
101
+	 *    and that all critical EE pages have been generated with the appropriate shortcodes in place
102
+	 *
103
+	 * @access public
104
+	 * @static
105
+	 * @return void
106
+	 */
107
+	public static function system_initialization()
108
+	{
109
+		EEH_Activation::reset_and_update_config();
110
+		//which is fired BEFORE activation of plugin anyways
111
+		EEH_Activation::verify_default_pages_exist();
112
+	}
113
+
114
+
115
+	/**
116
+	 * Sets the database schema and creates folders. This should
117
+	 * be called on plugin activation and reactivation
118
+	 *
119
+	 * @return boolean success, whether the database and folders are setup properly
120
+	 * @throws \EE_Error
121
+	 */
122
+	public static function initialize_db_and_folders()
123
+	{
124
+		$good_filesystem = EEH_Activation::create_upload_directories();
125
+		$good_db         = EEH_Activation::create_database_tables();
126
+		return $good_filesystem && $good_db;
127
+	}
128
+
129
+
130
+	/**
131
+	 * assuming we have an up-to-date database schema, this will populate it
132
+	 * with default and initial data. This should be called
133
+	 * upon activation of a new plugin, reactivation, and at the end
134
+	 * of running migration scripts
135
+	 *
136
+	 * @throws \EE_Error
137
+	 */
138
+	public static function initialize_db_content()
139
+	{
140
+		//let's avoid doing all this logic repeatedly, especially when addons are requesting it
141
+		if (EEH_Activation::$_initialized_db_content_already_in_this_request) {
142
+			return;
143
+		}
144
+		EEH_Activation::$_initialized_db_content_already_in_this_request = true;
145
+
146
+		EEH_Activation::initialize_system_questions();
147
+		EEH_Activation::insert_default_status_codes();
148
+		EEH_Activation::generate_default_message_templates();
149
+		EEH_Activation::create_no_ticket_prices_array();
150
+		EEH_Activation::validate_messages_system();
151
+		EEH_Activation::insert_default_payment_methods();
152
+		//in case we've
153
+		EEH_Activation::remove_cron_tasks();
154
+		EEH_Activation::create_cron_tasks();
155
+		// remove all TXN locks since that is being done via extra meta now
156
+		delete_option('ee_locked_transactions');
157
+		//also, check for CAF default db content
158
+		do_action('AHEE__EEH_Activation__initialize_db_content');
159
+		//also: EEM_Gateways::load_all_gateways() outputs a lot of success messages
160
+		//which users really won't care about on initial activation
161
+		EE_Error::overwrite_success();
162
+	}
163
+
164
+
165
+	/**
166
+	 * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"),
167
+	 * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event
168
+	 * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use
169
+	 * (null)
170
+	 *
171
+	 * @param string $which_to_include can be 'current' (ones that are currently in use),
172
+	 *                                 'old' (only returns ones that should no longer be used),or 'all',
173
+	 * @return array
174
+	 * @throws \EE_Error
175
+	 */
176
+	public static function get_cron_tasks($which_to_include)
177
+	{
178
+		$cron_tasks = apply_filters(
179
+			'FHEE__EEH_Activation__get_cron_tasks',
180
+			array(
181
+				'AHEE__EE_Cron_Tasks__clean_up_junk_transactions'      => 'hourly',
182 182
 //				'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions' => EEH_Activation::cron_task_no_longer_in_use, actually this is still in use
183
-                'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use,
184
-                //there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates
185
-                'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs'       => 'daily',
186
-            )
187
-        );
188
-        if ($which_to_include === 'old') {
189
-            $cron_tasks = array_filter(
190
-                $cron_tasks,
191
-                function ($value) {
192
-                    return $value === EEH_Activation::cron_task_no_longer_in_use;
193
-                }
194
-            );
195
-        } elseif ($which_to_include === 'current') {
196
-            $cron_tasks = array_filter($cron_tasks);
197
-        } elseif (WP_DEBUG && $which_to_include !== 'all') {
198
-            throw new EE_Error(
199
-                sprintf(
200
-                    __(
201
-                        'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".',
202
-                        'event_espresso'
203
-                    ),
204
-                    $which_to_include
205
-                )
206
-            );
207
-        }
208
-        return $cron_tasks;
209
-    }
210
-
211
-
212
-    /**
213
-     * Ensure cron tasks are setup (the removal of crons should be done by remove_crons())
214
-     *
215
-     * @throws \EE_Error
216
-     */
217
-    public static function create_cron_tasks()
218
-    {
219
-
220
-        foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) {
221
-            if (! wp_next_scheduled($hook_name)) {
222
-                /**
223
-                 * This allows client code to define the initial start timestamp for this schedule.
224
-                 */
225
-                if (is_array($frequency)
226
-                    && count($frequency) === 2
227
-                    && isset($frequency[0], $frequency[1])
228
-                ) {
229
-                    $start_timestamp = $frequency[0];
230
-                    $frequency = $frequency[1];
231
-                } else {
232
-                    $start_timestamp = time();
233
-                }
234
-                wp_schedule_event($start_timestamp, $frequency, $hook_name);
235
-            }
236
-        }
237
-
238
-    }
239
-
240
-
241
-
242
-    /**
243
-     * Remove the currently-existing and now-removed cron tasks.
244
-     *
245
-     * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones
246
-     * @throws \EE_Error
247
-     */
248
-    public static function remove_cron_tasks($remove_all = true)
249
-    {
250
-        $cron_tasks_to_remove = $remove_all ? 'all' : 'old';
251
-        $crons                = _get_cron_array();
252
-        $crons                = is_array($crons) ? $crons : array();
253
-        /* reminder of what $crons look like:
183
+				'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use,
184
+				//there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates
185
+				'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs'       => 'daily',
186
+			)
187
+		);
188
+		if ($which_to_include === 'old') {
189
+			$cron_tasks = array_filter(
190
+				$cron_tasks,
191
+				function ($value) {
192
+					return $value === EEH_Activation::cron_task_no_longer_in_use;
193
+				}
194
+			);
195
+		} elseif ($which_to_include === 'current') {
196
+			$cron_tasks = array_filter($cron_tasks);
197
+		} elseif (WP_DEBUG && $which_to_include !== 'all') {
198
+			throw new EE_Error(
199
+				sprintf(
200
+					__(
201
+						'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".',
202
+						'event_espresso'
203
+					),
204
+					$which_to_include
205
+				)
206
+			);
207
+		}
208
+		return $cron_tasks;
209
+	}
210
+
211
+
212
+	/**
213
+	 * Ensure cron tasks are setup (the removal of crons should be done by remove_crons())
214
+	 *
215
+	 * @throws \EE_Error
216
+	 */
217
+	public static function create_cron_tasks()
218
+	{
219
+
220
+		foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) {
221
+			if (! wp_next_scheduled($hook_name)) {
222
+				/**
223
+				 * This allows client code to define the initial start timestamp for this schedule.
224
+				 */
225
+				if (is_array($frequency)
226
+					&& count($frequency) === 2
227
+					&& isset($frequency[0], $frequency[1])
228
+				) {
229
+					$start_timestamp = $frequency[0];
230
+					$frequency = $frequency[1];
231
+				} else {
232
+					$start_timestamp = time();
233
+				}
234
+				wp_schedule_event($start_timestamp, $frequency, $hook_name);
235
+			}
236
+		}
237
+
238
+	}
239
+
240
+
241
+
242
+	/**
243
+	 * Remove the currently-existing and now-removed cron tasks.
244
+	 *
245
+	 * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones
246
+	 * @throws \EE_Error
247
+	 */
248
+	public static function remove_cron_tasks($remove_all = true)
249
+	{
250
+		$cron_tasks_to_remove = $remove_all ? 'all' : 'old';
251
+		$crons                = _get_cron_array();
252
+		$crons                = is_array($crons) ? $crons : array();
253
+		/* reminder of what $crons look like:
254 254
          * Top-level keys are timestamps, and their values are arrays.
255 255
          * The 2nd level arrays have keys with each of the cron task hook names to run at that time
256 256
          * and their values are arrays.
@@ -267,912 +267,912 @@  discard block
 block discarded – undo
267 267
          *					...
268 268
          *      ...
269 269
          */
270
-        $ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove);
271
-        foreach ($crons as $timestamp => $hooks_to_fire_at_time) {
272
-            if (is_array($hooks_to_fire_at_time)) {
273
-                foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) {
274
-                    if (isset($ee_cron_tasks_to_remove[$hook_name])
275
-                        && is_array($ee_cron_tasks_to_remove[$hook_name])
276
-                    ) {
277
-                        unset($crons[$timestamp][$hook_name]);
278
-                    }
279
-                }
280
-                //also take care of any empty cron timestamps.
281
-                if (empty($hooks_to_fire_at_time)) {
282
-                    unset($crons[$timestamp]);
283
-                }
284
-            }
285
-        }
286
-        _set_cron_array($crons);
287
-    }
288
-
289
-
290
-    /**
291
-     *    CPT_initialization
292
-     *    registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist
293
-     *
294
-     * @access public
295
-     * @static
296
-     * @return void
297
-     */
298
-    public static function CPT_initialization()
299
-    {
300
-        // register Custom Post Types
301
-        EE_Registry::instance()->load_core('Register_CPTs');
302
-        flush_rewrite_rules();
303
-    }
304
-
305
-
306
-
307
-    /**
308
-     *    reset_and_update_config
309
-     * The following code was moved over from EE_Config so that it will no longer run on every request.
310
-     * If there is old calendar config data saved, then it will get converted on activation.
311
-     * This was basically a DMS before we had DMS's, and will get removed after a few more versions.
312
-     *
313
-     * @access public
314
-     * @static
315
-     * @return void
316
-     */
317
-    public static function reset_and_update_config()
318
-    {
319
-        do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config'));
320
-        add_filter(
321
-            'FHEE__EE_Config___load_core_config__config_settings',
322
-            array('EEH_Activation', 'migrate_old_config_data'),
323
-            10,
324
-            3
325
-        );
326
-        //EE_Config::reset();
327
-        if (! EE_Config::logging_enabled()) {
328
-            delete_option(EE_Config::LOG_NAME);
329
-        }
330
-    }
331
-
332
-
333
-    /**
334
-     *    load_calendar_config
335
-     *
336
-     * @access    public
337
-     * @return    void
338
-     */
339
-    public static function load_calendar_config()
340
-    {
341
-        // grab array of all plugin folders and loop thru it
342
-        $plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR);
343
-        if (empty($plugins)) {
344
-            return;
345
-        }
346
-        foreach ($plugins as $plugin_path) {
347
-            // grab plugin folder name from path
348
-            $plugin = basename($plugin_path);
349
-            // drill down to Espresso plugins
350
-            // then to calendar related plugins
351
-            if (
352
-                strpos($plugin, 'espresso') !== false
353
-                || strpos($plugin, 'Espresso') !== false
354
-                || strpos($plugin, 'ee4') !== false
355
-                || strpos($plugin, 'EE4') !== false
356
-                || strpos($plugin, 'calendar') !== false
357
-            ) {
358
-                // this is what we are looking for
359
-                $calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php';
360
-                // does it exist in this folder ?
361
-                if (is_readable($calendar_config)) {
362
-                    // YEAH! let's load it
363
-                    require_once($calendar_config);
364
-                }
365
-            }
366
-        }
367
-    }
368
-
369
-
370
-
371
-    /**
372
-     *    _migrate_old_config_data
373
-     *
374
-     * @access    public
375
-     * @param array|stdClass $settings
376
-     * @param string         $config
377
-     * @param \EE_Config     $EE_Config
378
-     * @return \stdClass
379
-     */
380
-    public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config)
381
-    {
382
-        $convert_from_array = array('addons');
383
-        // in case old settings were saved as an array
384
-        if (is_array($settings) && in_array($config, $convert_from_array)) {
385
-            // convert existing settings to an object
386
-            $config_array = $settings;
387
-            $settings = new stdClass();
388
-            foreach ($config_array as $key => $value) {
389
-                if ($key === 'calendar' && class_exists('EE_Calendar_Config')) {
390
-                    $EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value);
391
-                } else {
392
-                    $settings->{$key} = $value;
393
-                }
394
-            }
395
-            add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true');
396
-        }
397
-        return $settings;
398
-    }
399
-
400
-
401
-    /**
402
-     * deactivate_event_espresso
403
-     *
404
-     * @access public
405
-     * @static
406
-     * @return void
407
-     */
408
-    public static function deactivate_event_espresso()
409
-    {
410
-        // check permissions
411
-        if (current_user_can('activate_plugins')) {
412
-            deactivate_plugins(EE_PLUGIN_BASENAME, true);
413
-        }
414
-    }
415
-
416
-
417
-
418
-
419
-    /**
420
-     * verify_default_pages_exist
421
-     *
422
-     * @access public
423
-     * @static
424
-     * @return void
425
-     */
426
-    public static function verify_default_pages_exist()
427
-    {
428
-        $critical_page_problem = false;
429
-        $critical_pages = array(
430
-            array(
431
-                'id'   => 'reg_page_id',
432
-                'name' => __('Registration Checkout', 'event_espresso'),
433
-                'post' => null,
434
-                'code' => 'ESPRESSO_CHECKOUT',
435
-            ),
436
-            array(
437
-                'id'   => 'txn_page_id',
438
-                'name' => __('Transactions', 'event_espresso'),
439
-                'post' => null,
440
-                'code' => 'ESPRESSO_TXN_PAGE',
441
-            ),
442
-            array(
443
-                'id'   => 'thank_you_page_id',
444
-                'name' => __('Thank You', 'event_espresso'),
445
-                'post' => null,
446
-                'code' => 'ESPRESSO_THANK_YOU',
447
-            ),
448
-            array(
449
-                'id'   => 'cancel_page_id',
450
-                'name' => __('Registration Cancelled', 'event_espresso'),
451
-                'post' => null,
452
-                'code' => 'ESPRESSO_CANCELLED',
453
-            ),
454
-        );
455
-        $EE_Core_Config = EE_Registry::instance()->CFG->core;
456
-        foreach ($critical_pages as $critical_page) {
457
-            // is critical page ID set in config ?
458
-            if ($EE_Core_Config->{$critical_page['id']} !== false) {
459
-                // attempt to find post by ID
460
-                $critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']});
461
-            }
462
-            // no dice?
463
-            if ($critical_page['post'] === null) {
464
-                // attempt to find post by title
465
-                $critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']);
466
-                // still nothing?
467
-                if ($critical_page['post'] === null) {
468
-                    $critical_page = EEH_Activation::create_critical_page($critical_page);
469
-                    // REALLY? Still nothing ??!?!?
470
-                    if ($critical_page['post'] === null) {
471
-                        $msg = __(
472
-                            'The Event Espresso critical page configuration settings could not be updated.',
473
-                            'event_espresso'
474
-                        );
475
-                        EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
476
-                        break;
477
-                    }
478
-                }
479
-            }
480
-            // check that Post ID matches critical page ID in config
481
-            if (
482
-                isset($critical_page['post']->ID)
483
-                && $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']}
484
-            ) {
485
-                //update Config with post ID
486
-                $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID;
487
-                if (! EE_Config::instance()->update_espresso_config(false, false)) {
488
-                    $msg = __(
489
-                        'The Event Espresso critical page configuration settings could not be updated.',
490
-                        'event_espresso'
491
-                    );
492
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
493
-                }
494
-            }
495
-            $critical_page_problem =
496
-                ! isset($critical_page['post']->post_status)
497
-                || $critical_page['post']->post_status !== 'publish'
498
-                || strpos($critical_page['post']->post_content, $critical_page['code']) === false
499
-                    ? true
500
-                    : $critical_page_problem;
501
-        }
502
-        if ($critical_page_problem) {
503
-            $msg = sprintf(
504
-                __(
505
-                    'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.',
506
-                    'event_espresso'
507
-                ),
508
-                '<a href="'
509
-                . admin_url('admin.php?page=espresso_general_settings&action=critical_pages')
510
-                . '">'
511
-                . __('Event Espresso Critical Pages Settings', 'event_espresso')
512
-                . '</a>'
513
-            );
514
-            EE_Error::add_persistent_admin_notice('critical_page_problem', $msg);
515
-        }
516
-        if (EE_Error::has_notices()) {
517
-            EE_Error::get_notices(false, true, true);
518
-        }
519
-    }
520
-
521
-
522
-
523
-    /**
524
-     * Returns the first post which uses the specified shortcode
525
-     *
526
-     * @param string $ee_shortcode usually one of the critical pages shortcodes, eg
527
-     *                             ESPRESSO_THANK_YOU. So we will search fora post with the content
528
-     *                             "[ESPRESSO_THANK_YOU"
529
-     *                             (we don't search for the closing shortcode bracket because they might have added
530
-     *                             parameter to the shortcode
531
-     * @return WP_Post or NULl
532
-     */
533
-    public static function get_page_by_ee_shortcode($ee_shortcode)
534
-    {
535
-        global $wpdb;
536
-        $shortcode_and_opening_bracket = '[' . $ee_shortcode;
537
-        $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1");
538
-        if ($post_id) {
539
-            return get_post($post_id);
540
-        } else {
541
-            return null;
542
-        }
543
-    }
544
-
545
-
546
-
547
-    /**
548
-     *    This function generates a post for critical espresso pages
549
-     *
550
-     * @access public
551
-     * @static
552
-     * @param array $critical_page
553
-     * @return array
554
-     */
555
-    public static function create_critical_page($critical_page)
556
-    {
557
-
558
-        $post_args = array(
559
-            'post_title'     => $critical_page['name'],
560
-            'post_status'    => 'publish',
561
-            'post_type'      => 'page',
562
-            'comment_status' => 'closed',
563
-            'post_content'   => '[' . $critical_page['code'] . ']',
564
-        );
565
-
566
-        $post_id = wp_insert_post($post_args);
567
-        if (! $post_id) {
568
-            $msg = sprintf(
569
-                __('The Event Espresso  critical page entitled "%s" could not be created.', 'event_espresso'),
570
-                $critical_page['name']
571
-            );
572
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
573
-            return $critical_page;
574
-        }
575
-        // get newly created post's details
576
-        if (! $critical_page['post'] = get_post($post_id)) {
577
-            $msg = sprintf(
578
-                __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'),
579
-                $critical_page['name']
580
-            );
581
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
582
-        }
583
-
584
-        return $critical_page;
585
-
586
-    }
587
-
588
-
589
-
590
-
591
-    /**
592
-     * Tries to find the oldest admin for this site.  If there are no admins for this site then return NULL.
593
-     * The role being used to check is filterable.
594
-     *
595
-     * @since  4.6.0
596
-     * @global WPDB $wpdb
597
-     * @return mixed null|int WP_user ID or NULL
598
-     */
599
-    public static function get_default_creator_id()
600
-    {
601
-        global $wpdb;
602
-        if ( ! empty(self::$_default_creator_id)) {
603
-            return self::$_default_creator_id;
604
-        }/**/
605
-        $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator');
606
-        //let's allow pre_filtering for early exits by alternative methods for getting id.  We check for truthy result and if so then exit early.
607
-        $pre_filtered_id = apply_filters(
608
-            'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id',
609
-            false,
610
-            $role_to_check
611
-        );
612
-        if ($pre_filtered_id !== false) {
613
-            return (int)$pre_filtered_id;
614
-        }
615
-        $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities');
616
-        $query = $wpdb->prepare(
617
-            "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1",
618
-            '%' . $role_to_check . '%'
619
-        );
620
-        $user_id = $wpdb->get_var($query);
621
-        $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id);
622
-        if ($user_id && (int)$user_id) {
623
-            self::$_default_creator_id = (int)$user_id;
624
-            return self::$_default_creator_id;
625
-        } else {
626
-            return null;
627
-        }
628
-    }
629
-
630
-
631
-
632
-    /**
633
-     * used by EE and EE addons during plugin activation to create tables.
634
-     * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable,
635
-     * but includes extra logic regarding activations.
636
-     *
637
-     * @access public
638
-     * @static
639
-     * @param string  $table_name              without the $wpdb->prefix
640
-     * @param string  $sql                     SQL for creating the table (contents between brackets in an SQL create
641
-     *                                         table query)
642
-     * @param string  $engine                  like 'ENGINE=MyISAM' or 'ENGINE=InnoDB'
643
-     * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty
644
-     *                                         and new once this function is done (ie, you really do want to CREATE a
645
-     *                                         table, and expect it to be empty once you're done) leave as FALSE when
646
-     *                                         you just want to verify the table exists and matches this definition
647
-     *                                         (and if it HAS data in it you want to leave it be)
648
-     * @return void
649
-     * @throws EE_Error if there are database errors
650
-     */
651
-    public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false)
652
-    {
653
-        if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) {
654
-            return;
655
-        }
656
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
657
-        if ( ! function_exists('dbDelta')) {
658
-            require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
659
-        }
660
-        $tableAnalysis = \EEH_Activation::getTableAnalysis();
661
-        $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name);
662
-        // do we need to first delete an existing version of this table ?
663
-        if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) {
664
-            // ok, delete the table... but ONLY if it's empty
665
-            $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name);
666
-            // table is NOT empty, are you SURE you want to delete this table ???
667
-            if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) {
668
-                \EEH_Activation::getTableManager()->dropTable($wp_table_name);
669
-            } else if ( ! $deleted_safely) {
670
-                // so we should be more cautious rather than just dropping tables so easily
671
-                error_log(
672
-                    sprintf(
673
-                        __(
674
-                            'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.',
675
-                            'event_espresso'
676
-                        ),
677
-                        $wp_table_name,
678
-                        '<br/>',
679
-                        'espresso_db_update'
680
-                    )
681
-                );
682
-            }
683
-        }
684
-        $engine = str_replace('ENGINE=', '', $engine);
685
-        \EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine);
686
-    }
687
-
688
-
689
-
690
-    /**
691
-     *    add_column_if_it_doesn't_exist
692
-     *    Checks if this column already exists on the specified table. Handy for addons which want to add a column
693
-     *
694
-     * @access     public
695
-     * @static
696
-     * @deprecated instead use TableManager::addColumn()
697
-     * @param string $table_name  (without "wp_", eg "esp_attendee"
698
-     * @param string $column_name
699
-     * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be
700
-     *                            'VARCHAR(10)'
701
-     * @return bool|int
702
-     */
703
-    public static function add_column_if_it_doesnt_exist(
704
-        $table_name,
705
-        $column_name,
706
-        $column_info = 'INT UNSIGNED NOT NULL'
707
-    ) {
708
-        return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info);
709
-    }
710
-
711
-
712
-    /**
713
-     * get_fields_on_table
714
-     * Gets all the fields on the database table.
715
-     *
716
-     * @access     public
717
-     * @deprecated instead use TableManager::getTableColumns()
718
-     * @static
719
-     * @param string $table_name , without prefixed $wpdb->prefix
720
-     * @return array of database column names
721
-     */
722
-    public static function get_fields_on_table($table_name = null)
723
-    {
724
-        return \EEH_Activation::getTableManager()->getTableColumns($table_name);
725
-    }
726
-
727
-
728
-    /**
729
-     * db_table_is_empty
730
-     *
731
-     * @access     public\
732
-     * @deprecated instead use TableAnalysis::tableIsEmpty()
733
-     * @static
734
-     * @param string $table_name
735
-     * @return bool
736
-     */
737
-    public static function db_table_is_empty($table_name)
738
-    {
739
-        return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name);
740
-    }
741
-
742
-
743
-    /**
744
-     * delete_db_table_if_empty
745
-     *
746
-     * @access public
747
-     * @static
748
-     * @param string $table_name
749
-     * @return bool | int
750
-     */
751
-    public static function delete_db_table_if_empty($table_name)
752
-    {
753
-        if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) {
754
-            return \EEH_Activation::getTableManager()->dropTable($table_name);
755
-        }
756
-        return false;
757
-    }
758
-
759
-
760
-    /**
761
-     * delete_unused_db_table
762
-     *
763
-     * @access     public
764
-     * @static
765
-     * @deprecated instead use TableManager::dropTable()
766
-     * @param string $table_name
767
-     * @return bool | int
768
-     */
769
-    public static function delete_unused_db_table($table_name)
770
-    {
771
-        return \EEH_Activation::getTableManager()->dropTable($table_name);
772
-    }
773
-
774
-
775
-    /**
776
-     * drop_index
777
-     *
778
-     * @access     public
779
-     * @static
780
-     * @deprecated instead use TableManager::dropIndex()
781
-     * @param string $table_name
782
-     * @param string $index_name
783
-     * @return bool | int
784
-     */
785
-    public static function drop_index($table_name, $index_name)
786
-    {
787
-        return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name);
788
-    }
789
-
790
-
791
-
792
-    /**
793
-     * create_database_tables
794
-     *
795
-     * @access public
796
-     * @static
797
-     * @throws EE_Error
798
-     * @return boolean success (whether database is setup properly or not)
799
-     */
800
-    public static function create_database_tables()
801
-    {
802
-        EE_Registry::instance()->load_core('Data_Migration_Manager');
803
-        //find the migration script that sets the database to be compatible with the code
804
-        $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms();
805
-        if ($dms_name) {
806
-            $current_data_migration_script = EE_Registry::instance()->load_dms($dms_name);
807
-            $current_data_migration_script->set_migrating(false);
808
-            $current_data_migration_script->schema_changes_before_migration();
809
-            $current_data_migration_script->schema_changes_after_migration();
810
-            if ($current_data_migration_script->get_errors()) {
811
-                if (WP_DEBUG) {
812
-                    foreach ($current_data_migration_script->get_errors() as $error) {
813
-                        EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
814
-                    }
815
-                } else {
816
-                    EE_Error::add_error(
817
-                        __(
818
-                            'There were errors creating the Event Espresso database tables and Event Espresso has been 
270
+		$ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove);
271
+		foreach ($crons as $timestamp => $hooks_to_fire_at_time) {
272
+			if (is_array($hooks_to_fire_at_time)) {
273
+				foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) {
274
+					if (isset($ee_cron_tasks_to_remove[$hook_name])
275
+						&& is_array($ee_cron_tasks_to_remove[$hook_name])
276
+					) {
277
+						unset($crons[$timestamp][$hook_name]);
278
+					}
279
+				}
280
+				//also take care of any empty cron timestamps.
281
+				if (empty($hooks_to_fire_at_time)) {
282
+					unset($crons[$timestamp]);
283
+				}
284
+			}
285
+		}
286
+		_set_cron_array($crons);
287
+	}
288
+
289
+
290
+	/**
291
+	 *    CPT_initialization
292
+	 *    registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist
293
+	 *
294
+	 * @access public
295
+	 * @static
296
+	 * @return void
297
+	 */
298
+	public static function CPT_initialization()
299
+	{
300
+		// register Custom Post Types
301
+		EE_Registry::instance()->load_core('Register_CPTs');
302
+		flush_rewrite_rules();
303
+	}
304
+
305
+
306
+
307
+	/**
308
+	 *    reset_and_update_config
309
+	 * The following code was moved over from EE_Config so that it will no longer run on every request.
310
+	 * If there is old calendar config data saved, then it will get converted on activation.
311
+	 * This was basically a DMS before we had DMS's, and will get removed after a few more versions.
312
+	 *
313
+	 * @access public
314
+	 * @static
315
+	 * @return void
316
+	 */
317
+	public static function reset_and_update_config()
318
+	{
319
+		do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config'));
320
+		add_filter(
321
+			'FHEE__EE_Config___load_core_config__config_settings',
322
+			array('EEH_Activation', 'migrate_old_config_data'),
323
+			10,
324
+			3
325
+		);
326
+		//EE_Config::reset();
327
+		if (! EE_Config::logging_enabled()) {
328
+			delete_option(EE_Config::LOG_NAME);
329
+		}
330
+	}
331
+
332
+
333
+	/**
334
+	 *    load_calendar_config
335
+	 *
336
+	 * @access    public
337
+	 * @return    void
338
+	 */
339
+	public static function load_calendar_config()
340
+	{
341
+		// grab array of all plugin folders and loop thru it
342
+		$plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR);
343
+		if (empty($plugins)) {
344
+			return;
345
+		}
346
+		foreach ($plugins as $plugin_path) {
347
+			// grab plugin folder name from path
348
+			$plugin = basename($plugin_path);
349
+			// drill down to Espresso plugins
350
+			// then to calendar related plugins
351
+			if (
352
+				strpos($plugin, 'espresso') !== false
353
+				|| strpos($plugin, 'Espresso') !== false
354
+				|| strpos($plugin, 'ee4') !== false
355
+				|| strpos($plugin, 'EE4') !== false
356
+				|| strpos($plugin, 'calendar') !== false
357
+			) {
358
+				// this is what we are looking for
359
+				$calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php';
360
+				// does it exist in this folder ?
361
+				if (is_readable($calendar_config)) {
362
+					// YEAH! let's load it
363
+					require_once($calendar_config);
364
+				}
365
+			}
366
+		}
367
+	}
368
+
369
+
370
+
371
+	/**
372
+	 *    _migrate_old_config_data
373
+	 *
374
+	 * @access    public
375
+	 * @param array|stdClass $settings
376
+	 * @param string         $config
377
+	 * @param \EE_Config     $EE_Config
378
+	 * @return \stdClass
379
+	 */
380
+	public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config)
381
+	{
382
+		$convert_from_array = array('addons');
383
+		// in case old settings were saved as an array
384
+		if (is_array($settings) && in_array($config, $convert_from_array)) {
385
+			// convert existing settings to an object
386
+			$config_array = $settings;
387
+			$settings = new stdClass();
388
+			foreach ($config_array as $key => $value) {
389
+				if ($key === 'calendar' && class_exists('EE_Calendar_Config')) {
390
+					$EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value);
391
+				} else {
392
+					$settings->{$key} = $value;
393
+				}
394
+			}
395
+			add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true');
396
+		}
397
+		return $settings;
398
+	}
399
+
400
+
401
+	/**
402
+	 * deactivate_event_espresso
403
+	 *
404
+	 * @access public
405
+	 * @static
406
+	 * @return void
407
+	 */
408
+	public static function deactivate_event_espresso()
409
+	{
410
+		// check permissions
411
+		if (current_user_can('activate_plugins')) {
412
+			deactivate_plugins(EE_PLUGIN_BASENAME, true);
413
+		}
414
+	}
415
+
416
+
417
+
418
+
419
+	/**
420
+	 * verify_default_pages_exist
421
+	 *
422
+	 * @access public
423
+	 * @static
424
+	 * @return void
425
+	 */
426
+	public static function verify_default_pages_exist()
427
+	{
428
+		$critical_page_problem = false;
429
+		$critical_pages = array(
430
+			array(
431
+				'id'   => 'reg_page_id',
432
+				'name' => __('Registration Checkout', 'event_espresso'),
433
+				'post' => null,
434
+				'code' => 'ESPRESSO_CHECKOUT',
435
+			),
436
+			array(
437
+				'id'   => 'txn_page_id',
438
+				'name' => __('Transactions', 'event_espresso'),
439
+				'post' => null,
440
+				'code' => 'ESPRESSO_TXN_PAGE',
441
+			),
442
+			array(
443
+				'id'   => 'thank_you_page_id',
444
+				'name' => __('Thank You', 'event_espresso'),
445
+				'post' => null,
446
+				'code' => 'ESPRESSO_THANK_YOU',
447
+			),
448
+			array(
449
+				'id'   => 'cancel_page_id',
450
+				'name' => __('Registration Cancelled', 'event_espresso'),
451
+				'post' => null,
452
+				'code' => 'ESPRESSO_CANCELLED',
453
+			),
454
+		);
455
+		$EE_Core_Config = EE_Registry::instance()->CFG->core;
456
+		foreach ($critical_pages as $critical_page) {
457
+			// is critical page ID set in config ?
458
+			if ($EE_Core_Config->{$critical_page['id']} !== false) {
459
+				// attempt to find post by ID
460
+				$critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']});
461
+			}
462
+			// no dice?
463
+			if ($critical_page['post'] === null) {
464
+				// attempt to find post by title
465
+				$critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']);
466
+				// still nothing?
467
+				if ($critical_page['post'] === null) {
468
+					$critical_page = EEH_Activation::create_critical_page($critical_page);
469
+					// REALLY? Still nothing ??!?!?
470
+					if ($critical_page['post'] === null) {
471
+						$msg = __(
472
+							'The Event Espresso critical page configuration settings could not be updated.',
473
+							'event_espresso'
474
+						);
475
+						EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
476
+						break;
477
+					}
478
+				}
479
+			}
480
+			// check that Post ID matches critical page ID in config
481
+			if (
482
+				isset($critical_page['post']->ID)
483
+				&& $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']}
484
+			) {
485
+				//update Config with post ID
486
+				$EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID;
487
+				if (! EE_Config::instance()->update_espresso_config(false, false)) {
488
+					$msg = __(
489
+						'The Event Espresso critical page configuration settings could not be updated.',
490
+						'event_espresso'
491
+					);
492
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
493
+				}
494
+			}
495
+			$critical_page_problem =
496
+				! isset($critical_page['post']->post_status)
497
+				|| $critical_page['post']->post_status !== 'publish'
498
+				|| strpos($critical_page['post']->post_content, $critical_page['code']) === false
499
+					? true
500
+					: $critical_page_problem;
501
+		}
502
+		if ($critical_page_problem) {
503
+			$msg = sprintf(
504
+				__(
505
+					'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.',
506
+					'event_espresso'
507
+				),
508
+				'<a href="'
509
+				. admin_url('admin.php?page=espresso_general_settings&action=critical_pages')
510
+				. '">'
511
+				. __('Event Espresso Critical Pages Settings', 'event_espresso')
512
+				. '</a>'
513
+			);
514
+			EE_Error::add_persistent_admin_notice('critical_page_problem', $msg);
515
+		}
516
+		if (EE_Error::has_notices()) {
517
+			EE_Error::get_notices(false, true, true);
518
+		}
519
+	}
520
+
521
+
522
+
523
+	/**
524
+	 * Returns the first post which uses the specified shortcode
525
+	 *
526
+	 * @param string $ee_shortcode usually one of the critical pages shortcodes, eg
527
+	 *                             ESPRESSO_THANK_YOU. So we will search fora post with the content
528
+	 *                             "[ESPRESSO_THANK_YOU"
529
+	 *                             (we don't search for the closing shortcode bracket because they might have added
530
+	 *                             parameter to the shortcode
531
+	 * @return WP_Post or NULl
532
+	 */
533
+	public static function get_page_by_ee_shortcode($ee_shortcode)
534
+	{
535
+		global $wpdb;
536
+		$shortcode_and_opening_bracket = '[' . $ee_shortcode;
537
+		$post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1");
538
+		if ($post_id) {
539
+			return get_post($post_id);
540
+		} else {
541
+			return null;
542
+		}
543
+	}
544
+
545
+
546
+
547
+	/**
548
+	 *    This function generates a post for critical espresso pages
549
+	 *
550
+	 * @access public
551
+	 * @static
552
+	 * @param array $critical_page
553
+	 * @return array
554
+	 */
555
+	public static function create_critical_page($critical_page)
556
+	{
557
+
558
+		$post_args = array(
559
+			'post_title'     => $critical_page['name'],
560
+			'post_status'    => 'publish',
561
+			'post_type'      => 'page',
562
+			'comment_status' => 'closed',
563
+			'post_content'   => '[' . $critical_page['code'] . ']',
564
+		);
565
+
566
+		$post_id = wp_insert_post($post_args);
567
+		if (! $post_id) {
568
+			$msg = sprintf(
569
+				__('The Event Espresso  critical page entitled "%s" could not be created.', 'event_espresso'),
570
+				$critical_page['name']
571
+			);
572
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
573
+			return $critical_page;
574
+		}
575
+		// get newly created post's details
576
+		if (! $critical_page['post'] = get_post($post_id)) {
577
+			$msg = sprintf(
578
+				__('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'),
579
+				$critical_page['name']
580
+			);
581
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
582
+		}
583
+
584
+		return $critical_page;
585
+
586
+	}
587
+
588
+
589
+
590
+
591
+	/**
592
+	 * Tries to find the oldest admin for this site.  If there are no admins for this site then return NULL.
593
+	 * The role being used to check is filterable.
594
+	 *
595
+	 * @since  4.6.0
596
+	 * @global WPDB $wpdb
597
+	 * @return mixed null|int WP_user ID or NULL
598
+	 */
599
+	public static function get_default_creator_id()
600
+	{
601
+		global $wpdb;
602
+		if ( ! empty(self::$_default_creator_id)) {
603
+			return self::$_default_creator_id;
604
+		}/**/
605
+		$role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator');
606
+		//let's allow pre_filtering for early exits by alternative methods for getting id.  We check for truthy result and if so then exit early.
607
+		$pre_filtered_id = apply_filters(
608
+			'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id',
609
+			false,
610
+			$role_to_check
611
+		);
612
+		if ($pre_filtered_id !== false) {
613
+			return (int)$pre_filtered_id;
614
+		}
615
+		$capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities');
616
+		$query = $wpdb->prepare(
617
+			"SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1",
618
+			'%' . $role_to_check . '%'
619
+		);
620
+		$user_id = $wpdb->get_var($query);
621
+		$user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id);
622
+		if ($user_id && (int)$user_id) {
623
+			self::$_default_creator_id = (int)$user_id;
624
+			return self::$_default_creator_id;
625
+		} else {
626
+			return null;
627
+		}
628
+	}
629
+
630
+
631
+
632
+	/**
633
+	 * used by EE and EE addons during plugin activation to create tables.
634
+	 * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable,
635
+	 * but includes extra logic regarding activations.
636
+	 *
637
+	 * @access public
638
+	 * @static
639
+	 * @param string  $table_name              without the $wpdb->prefix
640
+	 * @param string  $sql                     SQL for creating the table (contents between brackets in an SQL create
641
+	 *                                         table query)
642
+	 * @param string  $engine                  like 'ENGINE=MyISAM' or 'ENGINE=InnoDB'
643
+	 * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty
644
+	 *                                         and new once this function is done (ie, you really do want to CREATE a
645
+	 *                                         table, and expect it to be empty once you're done) leave as FALSE when
646
+	 *                                         you just want to verify the table exists and matches this definition
647
+	 *                                         (and if it HAS data in it you want to leave it be)
648
+	 * @return void
649
+	 * @throws EE_Error if there are database errors
650
+	 */
651
+	public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false)
652
+	{
653
+		if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) {
654
+			return;
655
+		}
656
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
657
+		if ( ! function_exists('dbDelta')) {
658
+			require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
659
+		}
660
+		$tableAnalysis = \EEH_Activation::getTableAnalysis();
661
+		$wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name);
662
+		// do we need to first delete an existing version of this table ?
663
+		if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) {
664
+			// ok, delete the table... but ONLY if it's empty
665
+			$deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name);
666
+			// table is NOT empty, are you SURE you want to delete this table ???
667
+			if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) {
668
+				\EEH_Activation::getTableManager()->dropTable($wp_table_name);
669
+			} else if ( ! $deleted_safely) {
670
+				// so we should be more cautious rather than just dropping tables so easily
671
+				error_log(
672
+					sprintf(
673
+						__(
674
+							'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.',
675
+							'event_espresso'
676
+						),
677
+						$wp_table_name,
678
+						'<br/>',
679
+						'espresso_db_update'
680
+					)
681
+				);
682
+			}
683
+		}
684
+		$engine = str_replace('ENGINE=', '', $engine);
685
+		\EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine);
686
+	}
687
+
688
+
689
+
690
+	/**
691
+	 *    add_column_if_it_doesn't_exist
692
+	 *    Checks if this column already exists on the specified table. Handy for addons which want to add a column
693
+	 *
694
+	 * @access     public
695
+	 * @static
696
+	 * @deprecated instead use TableManager::addColumn()
697
+	 * @param string $table_name  (without "wp_", eg "esp_attendee"
698
+	 * @param string $column_name
699
+	 * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be
700
+	 *                            'VARCHAR(10)'
701
+	 * @return bool|int
702
+	 */
703
+	public static function add_column_if_it_doesnt_exist(
704
+		$table_name,
705
+		$column_name,
706
+		$column_info = 'INT UNSIGNED NOT NULL'
707
+	) {
708
+		return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info);
709
+	}
710
+
711
+
712
+	/**
713
+	 * get_fields_on_table
714
+	 * Gets all the fields on the database table.
715
+	 *
716
+	 * @access     public
717
+	 * @deprecated instead use TableManager::getTableColumns()
718
+	 * @static
719
+	 * @param string $table_name , without prefixed $wpdb->prefix
720
+	 * @return array of database column names
721
+	 */
722
+	public static function get_fields_on_table($table_name = null)
723
+	{
724
+		return \EEH_Activation::getTableManager()->getTableColumns($table_name);
725
+	}
726
+
727
+
728
+	/**
729
+	 * db_table_is_empty
730
+	 *
731
+	 * @access     public\
732
+	 * @deprecated instead use TableAnalysis::tableIsEmpty()
733
+	 * @static
734
+	 * @param string $table_name
735
+	 * @return bool
736
+	 */
737
+	public static function db_table_is_empty($table_name)
738
+	{
739
+		return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name);
740
+	}
741
+
742
+
743
+	/**
744
+	 * delete_db_table_if_empty
745
+	 *
746
+	 * @access public
747
+	 * @static
748
+	 * @param string $table_name
749
+	 * @return bool | int
750
+	 */
751
+	public static function delete_db_table_if_empty($table_name)
752
+	{
753
+		if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) {
754
+			return \EEH_Activation::getTableManager()->dropTable($table_name);
755
+		}
756
+		return false;
757
+	}
758
+
759
+
760
+	/**
761
+	 * delete_unused_db_table
762
+	 *
763
+	 * @access     public
764
+	 * @static
765
+	 * @deprecated instead use TableManager::dropTable()
766
+	 * @param string $table_name
767
+	 * @return bool | int
768
+	 */
769
+	public static function delete_unused_db_table($table_name)
770
+	{
771
+		return \EEH_Activation::getTableManager()->dropTable($table_name);
772
+	}
773
+
774
+
775
+	/**
776
+	 * drop_index
777
+	 *
778
+	 * @access     public
779
+	 * @static
780
+	 * @deprecated instead use TableManager::dropIndex()
781
+	 * @param string $table_name
782
+	 * @param string $index_name
783
+	 * @return bool | int
784
+	 */
785
+	public static function drop_index($table_name, $index_name)
786
+	{
787
+		return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name);
788
+	}
789
+
790
+
791
+
792
+	/**
793
+	 * create_database_tables
794
+	 *
795
+	 * @access public
796
+	 * @static
797
+	 * @throws EE_Error
798
+	 * @return boolean success (whether database is setup properly or not)
799
+	 */
800
+	public static function create_database_tables()
801
+	{
802
+		EE_Registry::instance()->load_core('Data_Migration_Manager');
803
+		//find the migration script that sets the database to be compatible with the code
804
+		$dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms();
805
+		if ($dms_name) {
806
+			$current_data_migration_script = EE_Registry::instance()->load_dms($dms_name);
807
+			$current_data_migration_script->set_migrating(false);
808
+			$current_data_migration_script->schema_changes_before_migration();
809
+			$current_data_migration_script->schema_changes_after_migration();
810
+			if ($current_data_migration_script->get_errors()) {
811
+				if (WP_DEBUG) {
812
+					foreach ($current_data_migration_script->get_errors() as $error) {
813
+						EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
814
+					}
815
+				} else {
816
+					EE_Error::add_error(
817
+						__(
818
+							'There were errors creating the Event Espresso database tables and Event Espresso has been 
819 819
                             deactivated. To view the errors, please enable WP_DEBUG in your wp-config.php file.',
820
-                            'event_espresso'
821
-                        )
822
-                    );
823
-                }
824
-                return false;
825
-            }
826
-            EE_Data_Migration_Manager::instance()->update_current_database_state_to();
827
-        } else {
828
-            EE_Error::add_error(
829
-                __(
830
-                    'Could not determine most up-to-date data migration script from which to pull database schema
820
+							'event_espresso'
821
+						)
822
+					);
823
+				}
824
+				return false;
825
+			}
826
+			EE_Data_Migration_Manager::instance()->update_current_database_state_to();
827
+		} else {
828
+			EE_Error::add_error(
829
+				__(
830
+					'Could not determine most up-to-date data migration script from which to pull database schema
831 831
                      structure. So database is probably not setup properly',
832
-                    'event_espresso'
833
-                ),
834
-                __FILE__,
835
-                __FUNCTION__,
836
-                __LINE__
837
-            );
838
-            return false;
839
-        }
840
-        return true;
841
-    }
842
-
843
-
844
-
845
-    /**
846
-     * initialize_system_questions
847
-     *
848
-     * @access public
849
-     * @static
850
-     * @return void
851
-     */
852
-    public static function initialize_system_questions()
853
-    {
854
-        // QUESTION GROUPS
855
-        global $wpdb;
856
-        $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group');
857
-        $SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0";
858
-        // what we have
859
-        $question_groups = $wpdb->get_col($SQL);
860
-        // check the response
861
-        $question_groups = is_array($question_groups) ? $question_groups : array();
862
-        // what we should have
863
-        $QSG_systems = array(1, 2);
864
-        // loop thru what we should have and compare to what we have
865
-        foreach ($QSG_systems as $QSG_system) {
866
-            // reset values array
867
-            $QSG_values = array();
868
-            // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db)
869
-            if (! in_array("$QSG_system", $question_groups)) {
870
-                // add it
871
-                switch ($QSG_system) {
872
-                    case 1:
873
-                        $QSG_values = array(
874
-                            'QSG_name'            => __('Personal Information', 'event_espresso'),
875
-                            'QSG_identifier'      => 'personal-information-' . time(),
876
-                            'QSG_desc'            => '',
877
-                            'QSG_order'           => 1,
878
-                            'QSG_show_group_name' => 1,
879
-                            'QSG_show_group_desc' => 1,
880
-                            'QSG_system'          => EEM_Question_Group::system_personal,
881
-                            'QSG_deleted'         => 0,
882
-                        );
883
-                        break;
884
-                    case 2:
885
-                        $QSG_values = array(
886
-                            'QSG_name'            => __('Address Information', 'event_espresso'),
887
-                            'QSG_identifier'      => 'address-information-' . time(),
888
-                            'QSG_desc'            => '',
889
-                            'QSG_order'           => 2,
890
-                            'QSG_show_group_name' => 1,
891
-                            'QSG_show_group_desc' => 1,
892
-                            'QSG_system'          => EEM_Question_Group::system_address,
893
-                            'QSG_deleted'         => 0,
894
-                        );
895
-                        break;
896
-                }
897
-                // make sure we have some values before inserting them
898
-                if (! empty($QSG_values)) {
899
-                    // insert system question
900
-                    $wpdb->insert(
901
-                        $table_name,
902
-                        $QSG_values,
903
-                        array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d')
904
-                    );
905
-                    $QSG_IDs[$QSG_system] = $wpdb->insert_id;
906
-                }
907
-            }
908
-        }
909
-        // QUESTIONS
910
-        global $wpdb;
911
-        $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question');
912
-        $SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''";
913
-        // what we have
914
-        $questions = $wpdb->get_col($SQL);
915
-        // what we should have
916
-        $QST_systems = array(
917
-            'fname',
918
-            'lname',
919
-            'email',
920
-            'address',
921
-            'address2',
922
-            'city',
923
-            'country',
924
-            'state',
925
-            'zip',
926
-            'phone',
927
-        );
928
-        $order_for_group_1 = 1;
929
-        $order_for_group_2 = 1;
930
-        // loop thru what we should have and compare to what we have
931
-        foreach ($QST_systems as $QST_system) {
932
-            // reset values array
933
-            $QST_values = array();
934
-            // if we don't have what we should have
935
-            if (! in_array($QST_system, $questions)) {
936
-                // add it
937
-                switch ($QST_system) {
938
-                    case 'fname':
939
-                        $QST_values = array(
940
-                            'QST_display_text'  => __('First Name', 'event_espresso'),
941
-                            'QST_admin_label'   => __('First Name - System Question', 'event_espresso'),
942
-                            'QST_system'        => 'fname',
943
-                            'QST_type'          => 'TEXT',
944
-                            'QST_required'      => 1,
945
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
946
-                            'QST_order'         => 1,
947
-                            'QST_admin_only'    => 0,
948
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
949
-                            'QST_wp_user'       => self::get_default_creator_id(),
950
-                            'QST_deleted'       => 0,
951
-                        );
952
-                        break;
953
-                    case 'lname':
954
-                        $QST_values = array(
955
-                            'QST_display_text'  => __('Last Name', 'event_espresso'),
956
-                            'QST_admin_label'   => __('Last Name - System Question', 'event_espresso'),
957
-                            'QST_system'        => 'lname',
958
-                            'QST_type'          => 'TEXT',
959
-                            'QST_required'      => 1,
960
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
961
-                            'QST_order'         => 2,
962
-                            'QST_admin_only'    => 0,
963
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
964
-                            'QST_wp_user'       => self::get_default_creator_id(),
965
-                            'QST_deleted'       => 0,
966
-                        );
967
-                        break;
968
-                    case 'email':
969
-                        $QST_values = array(
970
-                            'QST_display_text'  => __('Email Address', 'event_espresso'),
971
-                            'QST_admin_label'   => __('Email Address - System Question', 'event_espresso'),
972
-                            'QST_system'        => 'email',
973
-                            'QST_type'          => 'EMAIL',
974
-                            'QST_required'      => 1,
975
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
976
-                            'QST_order'         => 3,
977
-                            'QST_admin_only'    => 0,
978
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
979
-                            'QST_wp_user'       => self::get_default_creator_id(),
980
-                            'QST_deleted'       => 0,
981
-                        );
982
-                        break;
983
-                    case 'address':
984
-                        $QST_values = array(
985
-                            'QST_display_text'  => __('Address', 'event_espresso'),
986
-                            'QST_admin_label'   => __('Address - System Question', 'event_espresso'),
987
-                            'QST_system'        => 'address',
988
-                            'QST_type'          => 'TEXT',
989
-                            'QST_required'      => 0,
990
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
991
-                            'QST_order'         => 4,
992
-                            'QST_admin_only'    => 0,
993
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
994
-                            'QST_wp_user'       => self::get_default_creator_id(),
995
-                            'QST_deleted'       => 0,
996
-                        );
997
-                        break;
998
-                    case 'address2':
999
-                        $QST_values = array(
1000
-                            'QST_display_text'  => __('Address2', 'event_espresso'),
1001
-                            'QST_admin_label'   => __('Address2 - System Question', 'event_espresso'),
1002
-                            'QST_system'        => 'address2',
1003
-                            'QST_type'          => 'TEXT',
1004
-                            'QST_required'      => 0,
1005
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1006
-                            'QST_order'         => 5,
1007
-                            'QST_admin_only'    => 0,
1008
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1009
-                            'QST_wp_user'       => self::get_default_creator_id(),
1010
-                            'QST_deleted'       => 0,
1011
-                        );
1012
-                        break;
1013
-                    case 'city':
1014
-                        $QST_values = array(
1015
-                            'QST_display_text'  => __('City', 'event_espresso'),
1016
-                            'QST_admin_label'   => __('City - System Question', 'event_espresso'),
1017
-                            'QST_system'        => 'city',
1018
-                            'QST_type'          => 'TEXT',
1019
-                            'QST_required'      => 0,
1020
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1021
-                            'QST_order'         => 6,
1022
-                            'QST_admin_only'    => 0,
1023
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1024
-                            'QST_wp_user'       => self::get_default_creator_id(),
1025
-                            'QST_deleted'       => 0,
1026
-                        );
1027
-                        break;
1028
-                    case 'country':
1029
-                        $QST_values = array(
1030
-                            'QST_display_text'  => __('Country', 'event_espresso'),
1031
-                            'QST_admin_label'   => __('Country - System Question', 'event_espresso'),
1032
-                            'QST_system'        => 'country',
1033
-                            'QST_type'          => 'COUNTRY',
1034
-                            'QST_required'      => 0,
1035
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1036
-                            'QST_order'         => 7,
1037
-                            'QST_admin_only'    => 0,
1038
-                            'QST_wp_user'       => self::get_default_creator_id(),
1039
-                            'QST_deleted'       => 0,
1040
-                        );
1041
-                        break;
1042
-                    case 'state':
1043
-                        $QST_values = array(
1044
-                            'QST_display_text'  => __('State/Province', 'event_espresso'),
1045
-                            'QST_admin_label'   => __('State/Province - System Question', 'event_espresso'),
1046
-                            'QST_system'        => 'state',
1047
-                            'QST_type'          => 'STATE',
1048
-                            'QST_required'      => 0,
1049
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1050
-                            'QST_order'         => 8,
1051
-                            'QST_admin_only'    => 0,
1052
-                            'QST_wp_user'       => self::get_default_creator_id(),
1053
-                            'QST_deleted'       => 0,
1054
-                        );
1055
-                        break;
1056
-                    case 'zip':
1057
-                        $QST_values = array(
1058
-                            'QST_display_text'  => __('Zip/Postal Code', 'event_espresso'),
1059
-                            'QST_admin_label'   => __('Zip/Postal Code - System Question', 'event_espresso'),
1060
-                            'QST_system'        => 'zip',
1061
-                            'QST_type'          => 'TEXT',
1062
-                            'QST_required'      => 0,
1063
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1064
-                            'QST_order'         => 9,
1065
-                            'QST_admin_only'    => 0,
1066
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1067
-                            'QST_wp_user'       => self::get_default_creator_id(),
1068
-                            'QST_deleted'       => 0,
1069
-                        );
1070
-                        break;
1071
-                    case 'phone':
1072
-                        $QST_values = array(
1073
-                            'QST_display_text'  => __('Phone Number', 'event_espresso'),
1074
-                            'QST_admin_label'   => __('Phone Number - System Question', 'event_espresso'),
1075
-                            'QST_system'        => 'phone',
1076
-                            'QST_type'          => 'TEXT',
1077
-                            'QST_required'      => 0,
1078
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1079
-                            'QST_order'         => 10,
1080
-                            'QST_admin_only'    => 0,
1081
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1082
-                            'QST_wp_user'       => self::get_default_creator_id(),
1083
-                            'QST_deleted'       => 0,
1084
-                        );
1085
-                        break;
1086
-                }
1087
-                if (! empty($QST_values)) {
1088
-                    // insert system question
1089
-                    $wpdb->insert(
1090
-                        $table_name,
1091
-                        $QST_values,
1092
-                        array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d')
1093
-                    );
1094
-                    $QST_ID = $wpdb->insert_id;
1095
-                    // QUESTION GROUP QUESTIONS
1096
-                    if (in_array($QST_system, array('fname', 'lname', 'email'))) {
1097
-                        $system_question_we_want = EEM_Question_Group::system_personal;
1098
-                    } else {
1099
-                        $system_question_we_want = EEM_Question_Group::system_address;
1100
-                    }
1101
-                    if (isset($QSG_IDs[$system_question_we_want])) {
1102
-                        $QSG_ID = $QSG_IDs[$system_question_we_want];
1103
-                    } else {
1104
-                        $id_col = EEM_Question_Group::instance()
1105
-                                                    ->get_col(array(array('QSG_system' => $system_question_we_want)));
1106
-                        if (is_array($id_col)) {
1107
-                            $QSG_ID = reset($id_col);
1108
-                        } else {
1109
-                            //ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method
1110
-                            EE_Log::instance()->log(
1111
-                                __FILE__,
1112
-                                __FUNCTION__,
1113
-                                sprintf(
1114
-                                    __(
1115
-                                        'Could not associate question %1$s to a question group because no system question
832
+					'event_espresso'
833
+				),
834
+				__FILE__,
835
+				__FUNCTION__,
836
+				__LINE__
837
+			);
838
+			return false;
839
+		}
840
+		return true;
841
+	}
842
+
843
+
844
+
845
+	/**
846
+	 * initialize_system_questions
847
+	 *
848
+	 * @access public
849
+	 * @static
850
+	 * @return void
851
+	 */
852
+	public static function initialize_system_questions()
853
+	{
854
+		// QUESTION GROUPS
855
+		global $wpdb;
856
+		$table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group');
857
+		$SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0";
858
+		// what we have
859
+		$question_groups = $wpdb->get_col($SQL);
860
+		// check the response
861
+		$question_groups = is_array($question_groups) ? $question_groups : array();
862
+		// what we should have
863
+		$QSG_systems = array(1, 2);
864
+		// loop thru what we should have and compare to what we have
865
+		foreach ($QSG_systems as $QSG_system) {
866
+			// reset values array
867
+			$QSG_values = array();
868
+			// if we don't have what we should have (but use $QST_system as as string because that's what we got from the db)
869
+			if (! in_array("$QSG_system", $question_groups)) {
870
+				// add it
871
+				switch ($QSG_system) {
872
+					case 1:
873
+						$QSG_values = array(
874
+							'QSG_name'            => __('Personal Information', 'event_espresso'),
875
+							'QSG_identifier'      => 'personal-information-' . time(),
876
+							'QSG_desc'            => '',
877
+							'QSG_order'           => 1,
878
+							'QSG_show_group_name' => 1,
879
+							'QSG_show_group_desc' => 1,
880
+							'QSG_system'          => EEM_Question_Group::system_personal,
881
+							'QSG_deleted'         => 0,
882
+						);
883
+						break;
884
+					case 2:
885
+						$QSG_values = array(
886
+							'QSG_name'            => __('Address Information', 'event_espresso'),
887
+							'QSG_identifier'      => 'address-information-' . time(),
888
+							'QSG_desc'            => '',
889
+							'QSG_order'           => 2,
890
+							'QSG_show_group_name' => 1,
891
+							'QSG_show_group_desc' => 1,
892
+							'QSG_system'          => EEM_Question_Group::system_address,
893
+							'QSG_deleted'         => 0,
894
+						);
895
+						break;
896
+				}
897
+				// make sure we have some values before inserting them
898
+				if (! empty($QSG_values)) {
899
+					// insert system question
900
+					$wpdb->insert(
901
+						$table_name,
902
+						$QSG_values,
903
+						array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d')
904
+					);
905
+					$QSG_IDs[$QSG_system] = $wpdb->insert_id;
906
+				}
907
+			}
908
+		}
909
+		// QUESTIONS
910
+		global $wpdb;
911
+		$table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question');
912
+		$SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''";
913
+		// what we have
914
+		$questions = $wpdb->get_col($SQL);
915
+		// what we should have
916
+		$QST_systems = array(
917
+			'fname',
918
+			'lname',
919
+			'email',
920
+			'address',
921
+			'address2',
922
+			'city',
923
+			'country',
924
+			'state',
925
+			'zip',
926
+			'phone',
927
+		);
928
+		$order_for_group_1 = 1;
929
+		$order_for_group_2 = 1;
930
+		// loop thru what we should have and compare to what we have
931
+		foreach ($QST_systems as $QST_system) {
932
+			// reset values array
933
+			$QST_values = array();
934
+			// if we don't have what we should have
935
+			if (! in_array($QST_system, $questions)) {
936
+				// add it
937
+				switch ($QST_system) {
938
+					case 'fname':
939
+						$QST_values = array(
940
+							'QST_display_text'  => __('First Name', 'event_espresso'),
941
+							'QST_admin_label'   => __('First Name - System Question', 'event_espresso'),
942
+							'QST_system'        => 'fname',
943
+							'QST_type'          => 'TEXT',
944
+							'QST_required'      => 1,
945
+							'QST_required_text' => __('This field is required', 'event_espresso'),
946
+							'QST_order'         => 1,
947
+							'QST_admin_only'    => 0,
948
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
949
+							'QST_wp_user'       => self::get_default_creator_id(),
950
+							'QST_deleted'       => 0,
951
+						);
952
+						break;
953
+					case 'lname':
954
+						$QST_values = array(
955
+							'QST_display_text'  => __('Last Name', 'event_espresso'),
956
+							'QST_admin_label'   => __('Last Name - System Question', 'event_espresso'),
957
+							'QST_system'        => 'lname',
958
+							'QST_type'          => 'TEXT',
959
+							'QST_required'      => 1,
960
+							'QST_required_text' => __('This field is required', 'event_espresso'),
961
+							'QST_order'         => 2,
962
+							'QST_admin_only'    => 0,
963
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
964
+							'QST_wp_user'       => self::get_default_creator_id(),
965
+							'QST_deleted'       => 0,
966
+						);
967
+						break;
968
+					case 'email':
969
+						$QST_values = array(
970
+							'QST_display_text'  => __('Email Address', 'event_espresso'),
971
+							'QST_admin_label'   => __('Email Address - System Question', 'event_espresso'),
972
+							'QST_system'        => 'email',
973
+							'QST_type'          => 'EMAIL',
974
+							'QST_required'      => 1,
975
+							'QST_required_text' => __('This field is required', 'event_espresso'),
976
+							'QST_order'         => 3,
977
+							'QST_admin_only'    => 0,
978
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
979
+							'QST_wp_user'       => self::get_default_creator_id(),
980
+							'QST_deleted'       => 0,
981
+						);
982
+						break;
983
+					case 'address':
984
+						$QST_values = array(
985
+							'QST_display_text'  => __('Address', 'event_espresso'),
986
+							'QST_admin_label'   => __('Address - System Question', 'event_espresso'),
987
+							'QST_system'        => 'address',
988
+							'QST_type'          => 'TEXT',
989
+							'QST_required'      => 0,
990
+							'QST_required_text' => __('This field is required', 'event_espresso'),
991
+							'QST_order'         => 4,
992
+							'QST_admin_only'    => 0,
993
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
994
+							'QST_wp_user'       => self::get_default_creator_id(),
995
+							'QST_deleted'       => 0,
996
+						);
997
+						break;
998
+					case 'address2':
999
+						$QST_values = array(
1000
+							'QST_display_text'  => __('Address2', 'event_espresso'),
1001
+							'QST_admin_label'   => __('Address2 - System Question', 'event_espresso'),
1002
+							'QST_system'        => 'address2',
1003
+							'QST_type'          => 'TEXT',
1004
+							'QST_required'      => 0,
1005
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1006
+							'QST_order'         => 5,
1007
+							'QST_admin_only'    => 0,
1008
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1009
+							'QST_wp_user'       => self::get_default_creator_id(),
1010
+							'QST_deleted'       => 0,
1011
+						);
1012
+						break;
1013
+					case 'city':
1014
+						$QST_values = array(
1015
+							'QST_display_text'  => __('City', 'event_espresso'),
1016
+							'QST_admin_label'   => __('City - System Question', 'event_espresso'),
1017
+							'QST_system'        => 'city',
1018
+							'QST_type'          => 'TEXT',
1019
+							'QST_required'      => 0,
1020
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1021
+							'QST_order'         => 6,
1022
+							'QST_admin_only'    => 0,
1023
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1024
+							'QST_wp_user'       => self::get_default_creator_id(),
1025
+							'QST_deleted'       => 0,
1026
+						);
1027
+						break;
1028
+					case 'country':
1029
+						$QST_values = array(
1030
+							'QST_display_text'  => __('Country', 'event_espresso'),
1031
+							'QST_admin_label'   => __('Country - System Question', 'event_espresso'),
1032
+							'QST_system'        => 'country',
1033
+							'QST_type'          => 'COUNTRY',
1034
+							'QST_required'      => 0,
1035
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1036
+							'QST_order'         => 7,
1037
+							'QST_admin_only'    => 0,
1038
+							'QST_wp_user'       => self::get_default_creator_id(),
1039
+							'QST_deleted'       => 0,
1040
+						);
1041
+						break;
1042
+					case 'state':
1043
+						$QST_values = array(
1044
+							'QST_display_text'  => __('State/Province', 'event_espresso'),
1045
+							'QST_admin_label'   => __('State/Province - System Question', 'event_espresso'),
1046
+							'QST_system'        => 'state',
1047
+							'QST_type'          => 'STATE',
1048
+							'QST_required'      => 0,
1049
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1050
+							'QST_order'         => 8,
1051
+							'QST_admin_only'    => 0,
1052
+							'QST_wp_user'       => self::get_default_creator_id(),
1053
+							'QST_deleted'       => 0,
1054
+						);
1055
+						break;
1056
+					case 'zip':
1057
+						$QST_values = array(
1058
+							'QST_display_text'  => __('Zip/Postal Code', 'event_espresso'),
1059
+							'QST_admin_label'   => __('Zip/Postal Code - System Question', 'event_espresso'),
1060
+							'QST_system'        => 'zip',
1061
+							'QST_type'          => 'TEXT',
1062
+							'QST_required'      => 0,
1063
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1064
+							'QST_order'         => 9,
1065
+							'QST_admin_only'    => 0,
1066
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1067
+							'QST_wp_user'       => self::get_default_creator_id(),
1068
+							'QST_deleted'       => 0,
1069
+						);
1070
+						break;
1071
+					case 'phone':
1072
+						$QST_values = array(
1073
+							'QST_display_text'  => __('Phone Number', 'event_espresso'),
1074
+							'QST_admin_label'   => __('Phone Number - System Question', 'event_espresso'),
1075
+							'QST_system'        => 'phone',
1076
+							'QST_type'          => 'TEXT',
1077
+							'QST_required'      => 0,
1078
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1079
+							'QST_order'         => 10,
1080
+							'QST_admin_only'    => 0,
1081
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1082
+							'QST_wp_user'       => self::get_default_creator_id(),
1083
+							'QST_deleted'       => 0,
1084
+						);
1085
+						break;
1086
+				}
1087
+				if (! empty($QST_values)) {
1088
+					// insert system question
1089
+					$wpdb->insert(
1090
+						$table_name,
1091
+						$QST_values,
1092
+						array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d')
1093
+					);
1094
+					$QST_ID = $wpdb->insert_id;
1095
+					// QUESTION GROUP QUESTIONS
1096
+					if (in_array($QST_system, array('fname', 'lname', 'email'))) {
1097
+						$system_question_we_want = EEM_Question_Group::system_personal;
1098
+					} else {
1099
+						$system_question_we_want = EEM_Question_Group::system_address;
1100
+					}
1101
+					if (isset($QSG_IDs[$system_question_we_want])) {
1102
+						$QSG_ID = $QSG_IDs[$system_question_we_want];
1103
+					} else {
1104
+						$id_col = EEM_Question_Group::instance()
1105
+													->get_col(array(array('QSG_system' => $system_question_we_want)));
1106
+						if (is_array($id_col)) {
1107
+							$QSG_ID = reset($id_col);
1108
+						} else {
1109
+							//ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method
1110
+							EE_Log::instance()->log(
1111
+								__FILE__,
1112
+								__FUNCTION__,
1113
+								sprintf(
1114
+									__(
1115
+										'Could not associate question %1$s to a question group because no system question
1116 1116
                                          group existed',
1117
-                                        'event_espresso'
1118
-                                    ),
1119
-                                    $QST_ID),
1120
-                                'error');
1121
-                            continue;
1122
-                        }
1123
-                    }
1124
-                    // add system questions to groups
1125
-                    $wpdb->insert(
1126
-                        \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'),
1127
-                        array(
1128
-                            'QSG_ID'    => $QSG_ID,
1129
-                            'QST_ID'    => $QST_ID,
1130
-                            'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++,
1131
-                        ),
1132
-                        array('%d', '%d', '%d')
1133
-                    );
1134
-                }
1135
-            }
1136
-        }
1137
-    }
1138
-
1139
-
1140
-    /**
1141
-     * Makes sure the default payment method (Invoice) is active.
1142
-     * This used to be done automatically as part of constructing the old gateways config
1143
-     *
1144
-     * @throws \EE_Error
1145
-     */
1146
-    public static function insert_default_payment_methods()
1147
-    {
1148
-        if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1149
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
1150
-            EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
1151
-        } else {
1152
-            EEM_Payment_Method::instance()->verify_button_urls();
1153
-        }
1154
-    }
1155
-
1156
-    /**
1157
-     * insert_default_status_codes
1158
-     *
1159
-     * @access public
1160
-     * @static
1161
-     * @return void
1162
-     */
1163
-    public static function insert_default_status_codes()
1164
-    {
1165
-
1166
-        global $wpdb;
1167
-
1168
-        if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) {
1169
-
1170
-            $table_name = EEM_Status::instance()->table();
1171
-
1172
-            $SQL = "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );";
1173
-            $wpdb->query($SQL);
1174
-
1175
-            $SQL = "INSERT INTO $table_name
1117
+										'event_espresso'
1118
+									),
1119
+									$QST_ID),
1120
+								'error');
1121
+							continue;
1122
+						}
1123
+					}
1124
+					// add system questions to groups
1125
+					$wpdb->insert(
1126
+						\EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'),
1127
+						array(
1128
+							'QSG_ID'    => $QSG_ID,
1129
+							'QST_ID'    => $QST_ID,
1130
+							'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++,
1131
+						),
1132
+						array('%d', '%d', '%d')
1133
+					);
1134
+				}
1135
+			}
1136
+		}
1137
+	}
1138
+
1139
+
1140
+	/**
1141
+	 * Makes sure the default payment method (Invoice) is active.
1142
+	 * This used to be done automatically as part of constructing the old gateways config
1143
+	 *
1144
+	 * @throws \EE_Error
1145
+	 */
1146
+	public static function insert_default_payment_methods()
1147
+	{
1148
+		if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1149
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
1150
+			EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
1151
+		} else {
1152
+			EEM_Payment_Method::instance()->verify_button_urls();
1153
+		}
1154
+	}
1155
+
1156
+	/**
1157
+	 * insert_default_status_codes
1158
+	 *
1159
+	 * @access public
1160
+	 * @static
1161
+	 * @return void
1162
+	 */
1163
+	public static function insert_default_status_codes()
1164
+	{
1165
+
1166
+		global $wpdb;
1167
+
1168
+		if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) {
1169
+
1170
+			$table_name = EEM_Status::instance()->table();
1171
+
1172
+			$SQL = "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );";
1173
+			$wpdb->query($SQL);
1174
+
1175
+			$SQL = "INSERT INTO $table_name
1176 1176
 					(STS_ID, STS_code, STS_type, STS_can_edit, STS_desc, STS_open) VALUES
1177 1177
 					('ACT', 'ACTIVE', 'event', 0, NULL, 1),
1178 1178
 					('NAC', 'NOT_ACTIVE', 'event', 0, NULL, 0),
@@ -1212,521 +1212,521 @@  discard block
 block discarded – undo
1212 1212
 					('MID', 'IDLE', 'message', 0, NULL, 1),
1213 1213
 					('MRS', 'RESEND', 'message', 0, NULL, 1),
1214 1214
 					('MIC', 'INCOMPLETE', 'message', 0, NULL, 0);";
1215
-            $wpdb->query($SQL);
1216
-
1217
-        }
1218
-
1219
-    }
1220
-
1221
-
1222
-    /**
1223
-     * create_upload_directories
1224
-     * Creates folders in the uploads directory to facilitate addons and templates
1225
-     *
1226
-     * @access public
1227
-     * @static
1228
-     * @return boolean success of verifying upload directories exist
1229
-     */
1230
-    public static function create_upload_directories()
1231
-    {
1232
-        // Create the required folders
1233
-        $folders = array(
1234
-            EVENT_ESPRESSO_TEMPLATE_DIR,
1235
-            EVENT_ESPRESSO_GATEWAY_DIR,
1236
-            EVENT_ESPRESSO_UPLOAD_DIR . 'logs/',
1237
-            EVENT_ESPRESSO_UPLOAD_DIR . 'css/',
1238
-            EVENT_ESPRESSO_UPLOAD_DIR . 'tickets/',
1239
-        );
1240
-        foreach ($folders as $folder) {
1241
-            try {
1242
-                EEH_File::ensure_folder_exists_and_is_writable($folder);
1243
-                @ chmod($folder, 0755);
1244
-            } catch (EE_Error $e) {
1245
-                EE_Error::add_error(
1246
-                    sprintf(
1247
-                        __('Could not create the folder at "%1$s" because: %2$s', 'event_espresso'),
1248
-                        $folder,
1249
-                        '<br />' . $e->getMessage()
1250
-                    ),
1251
-                    __FILE__, __FUNCTION__, __LINE__
1252
-                );
1253
-                //indicate we'll need to fix this later
1254
-                update_option(EEH_Activation::upload_directories_incomplete_option_name, true);
1255
-                return false;
1256
-            }
1257
-        }
1258
-        //just add the .htaccess file to the logs directory to begin with. Even if logging
1259
-        //is disabled, there might be activation errors recorded in there
1260
-        EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs/');
1261
-        //remember EE's folders are all good
1262
-        delete_option(EEH_Activation::upload_directories_incomplete_option_name);
1263
-        return true;
1264
-    }
1265
-
1266
-    /**
1267
-     * Whether the upload directories need to be fixed or not.
1268
-     * If EE is installed but filesystem access isn't initially available,
1269
-     * we need to get the user's filesystem credentials and THEN create them,
1270
-     * so there might be period of time when EE is installed but its
1271
-     * upload directories aren't available. This indicates such a state
1272
-     *
1273
-     * @return boolean
1274
-     */
1275
-    public static function upload_directories_incomplete()
1276
-    {
1277
-        return get_option(EEH_Activation::upload_directories_incomplete_option_name, false);
1278
-    }
1279
-
1280
-
1281
-    /**
1282
-     * generate_default_message_templates
1283
-     *
1284
-     * @static
1285
-     * @throws EE_Error
1286
-     * @return bool     true means new templates were created.
1287
-     *                  false means no templates were created.
1288
-     *                  This is NOT an error flag. To check for errors you will want
1289
-     *                  to use either EE_Error or a try catch for an EE_Error exception.
1290
-     */
1291
-    public static function generate_default_message_templates()
1292
-    {
1293
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
1294
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1295
-        /*
1215
+			$wpdb->query($SQL);
1216
+
1217
+		}
1218
+
1219
+	}
1220
+
1221
+
1222
+	/**
1223
+	 * create_upload_directories
1224
+	 * Creates folders in the uploads directory to facilitate addons and templates
1225
+	 *
1226
+	 * @access public
1227
+	 * @static
1228
+	 * @return boolean success of verifying upload directories exist
1229
+	 */
1230
+	public static function create_upload_directories()
1231
+	{
1232
+		// Create the required folders
1233
+		$folders = array(
1234
+			EVENT_ESPRESSO_TEMPLATE_DIR,
1235
+			EVENT_ESPRESSO_GATEWAY_DIR,
1236
+			EVENT_ESPRESSO_UPLOAD_DIR . 'logs/',
1237
+			EVENT_ESPRESSO_UPLOAD_DIR . 'css/',
1238
+			EVENT_ESPRESSO_UPLOAD_DIR . 'tickets/',
1239
+		);
1240
+		foreach ($folders as $folder) {
1241
+			try {
1242
+				EEH_File::ensure_folder_exists_and_is_writable($folder);
1243
+				@ chmod($folder, 0755);
1244
+			} catch (EE_Error $e) {
1245
+				EE_Error::add_error(
1246
+					sprintf(
1247
+						__('Could not create the folder at "%1$s" because: %2$s', 'event_espresso'),
1248
+						$folder,
1249
+						'<br />' . $e->getMessage()
1250
+					),
1251
+					__FILE__, __FUNCTION__, __LINE__
1252
+				);
1253
+				//indicate we'll need to fix this later
1254
+				update_option(EEH_Activation::upload_directories_incomplete_option_name, true);
1255
+				return false;
1256
+			}
1257
+		}
1258
+		//just add the .htaccess file to the logs directory to begin with. Even if logging
1259
+		//is disabled, there might be activation errors recorded in there
1260
+		EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs/');
1261
+		//remember EE's folders are all good
1262
+		delete_option(EEH_Activation::upload_directories_incomplete_option_name);
1263
+		return true;
1264
+	}
1265
+
1266
+	/**
1267
+	 * Whether the upload directories need to be fixed or not.
1268
+	 * If EE is installed but filesystem access isn't initially available,
1269
+	 * we need to get the user's filesystem credentials and THEN create them,
1270
+	 * so there might be period of time when EE is installed but its
1271
+	 * upload directories aren't available. This indicates such a state
1272
+	 *
1273
+	 * @return boolean
1274
+	 */
1275
+	public static function upload_directories_incomplete()
1276
+	{
1277
+		return get_option(EEH_Activation::upload_directories_incomplete_option_name, false);
1278
+	}
1279
+
1280
+
1281
+	/**
1282
+	 * generate_default_message_templates
1283
+	 *
1284
+	 * @static
1285
+	 * @throws EE_Error
1286
+	 * @return bool     true means new templates were created.
1287
+	 *                  false means no templates were created.
1288
+	 *                  This is NOT an error flag. To check for errors you will want
1289
+	 *                  to use either EE_Error or a try catch for an EE_Error exception.
1290
+	 */
1291
+	public static function generate_default_message_templates()
1292
+	{
1293
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
1294
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1295
+		/*
1296 1296
          * This first method is taking care of ensuring any default messengers
1297 1297
          * that should be made active and have templates generated are done.
1298 1298
          */
1299
-        $new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates(
1300
-            $message_resource_manager
1301
-        );
1302
-        /**
1303
-         * This method is verifying there are no NEW default message types
1304
-         * for ACTIVE messengers that need activated (and corresponding templates setup).
1305
-         */
1306
-        $new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates(
1307
-            $message_resource_manager
1308
-        );
1309
-        //after all is done, let's persist these changes to the db.
1310
-        $message_resource_manager->update_has_activated_messengers_option();
1311
-        $message_resource_manager->update_active_messengers_option();
1312
-        // will return true if either of these are true.  Otherwise will return false.
1313
-        return $new_templates_created_for_message_type || $new_templates_created_for_messenger;
1314
-    }
1315
-
1316
-
1317
-
1318
-    /**
1319
-     * @param \EE_Message_Resource_Manager $message_resource_manager
1320
-     * @return array|bool
1321
-     * @throws \EE_Error
1322
-     */
1323
-    protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates(
1324
-        EE_Message_Resource_Manager $message_resource_manager
1325
-    ) {
1326
-        /** @type EE_messenger[] $active_messengers */
1327
-        $active_messengers = $message_resource_manager->active_messengers();
1328
-        $installed_message_types = $message_resource_manager->installed_message_types();
1329
-        $templates_created = false;
1330
-        foreach ($active_messengers as $active_messenger) {
1331
-            $default_message_type_names_for_messenger = $active_messenger->get_default_message_types();
1332
-            $default_message_type_names_to_activate = array();
1333
-            // looping through each default message type reported by the messenger
1334
-            // and setup the actual message types to activate.
1335
-            foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) {
1336
-                // if already active or has already been activated before we skip
1337
-                // (otherwise we might reactivate something user's intentionally deactivated.)
1338
-                // we also skip if the message type is not installed.
1339
-                if (
1340
-                    $message_resource_manager->has_message_type_been_activated_for_messenger(
1341
-                        $default_message_type_name_for_messenger,
1342
-                        $active_messenger->name
1343
-                    )
1344
-                    || $message_resource_manager->is_message_type_active_for_messenger(
1345
-                        $active_messenger->name,
1346
-                        $default_message_type_name_for_messenger
1347
-                    )
1348
-                    || ! isset($installed_message_types[$default_message_type_name_for_messenger])
1349
-                ) {
1350
-                    continue;
1351
-                }
1352
-                $default_message_type_names_to_activate[] = $default_message_type_name_for_messenger;
1353
-            }
1354
-            //let's activate!
1355
-            $message_resource_manager->ensure_message_types_are_active(
1356
-                $default_message_type_names_to_activate,
1357
-                $active_messenger->name,
1358
-                false
1359
-            );
1360
-            //activate the templates for these message types
1361
-            if ( ! empty($default_message_type_names_to_activate)) {
1362
-                $templates_created = EEH_MSG_Template::generate_new_templates(
1363
-                    $active_messenger->name,
1364
-                    $default_message_type_names_for_messenger,
1365
-                    '',
1366
-                    true
1367
-                );
1368
-            }
1369
-        }
1370
-        return $templates_created;
1371
-    }
1372
-
1373
-
1374
-
1375
-    /**
1376
-     * This will activate and generate default messengers and default message types for those messengers.
1377
-     *
1378
-     * @param EE_message_Resource_Manager $message_resource_manager
1379
-     * @return array|bool  True means there were default messengers and message type templates generated.
1380
-     *                     False means that there were no templates generated
1381
-     *                     (which could simply mean there are no default message types for a messenger).
1382
-     * @throws EE_Error
1383
-     */
1384
-    protected static function _activate_and_generate_default_messengers_and_message_templates(
1385
-        EE_Message_Resource_Manager $message_resource_manager
1386
-    ) {
1387
-        /** @type EE_messenger[] $messengers_to_generate */
1388
-        $messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager);
1389
-        $installed_message_types = $message_resource_manager->installed_message_types();
1390
-        $templates_generated = false;
1391
-        foreach ($messengers_to_generate as $messenger_to_generate) {
1392
-            $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types();
1393
-            //verify the default message types match an installed message type.
1394
-            foreach ($default_message_type_names_for_messenger as $key => $name) {
1395
-                if (
1396
-                    ! isset($installed_message_types[$name])
1397
-                    || $message_resource_manager->has_message_type_been_activated_for_messenger(
1398
-                        $name,
1399
-                        $messenger_to_generate->name
1400
-                    )
1401
-                ) {
1402
-                    unset($default_message_type_names_for_messenger[$key]);
1403
-                }
1404
-            }
1405
-            // in previous iterations, the active_messengers option in the db
1406
-            // needed updated before calling create templates. however with the changes this may not be necessary.
1407
-            // This comment is left here just in case we discover that we _do_ need to update before
1408
-            // passing off to create templates (after the refactor is done).
1409
-            // @todo remove this comment when determined not necessary.
1410
-            $message_resource_manager->activate_messenger(
1411
-                $messenger_to_generate->name,
1412
-                $default_message_type_names_for_messenger,
1413
-                false
1414
-            );
1415
-            //create any templates needing created (or will reactivate templates already generated as necessary).
1416
-            if ( ! empty($default_message_type_names_for_messenger)) {
1417
-                $templates_generated = EEH_MSG_Template::generate_new_templates(
1418
-                    $messenger_to_generate->name,
1419
-                    $default_message_type_names_for_messenger,
1420
-                    '',
1421
-                    true
1422
-                );
1423
-            }
1424
-        }
1425
-        return $templates_generated;
1426
-    }
1427
-
1428
-
1429
-    /**
1430
-     * This returns the default messengers to generate templates for on activation of EE.
1431
-     * It considers:
1432
-     * - whether a messenger is already active in the db.
1433
-     * - whether a messenger has been made active at any time in the past.
1434
-     *
1435
-     * @static
1436
-     * @param  EE_Message_Resource_Manager $message_resource_manager
1437
-     * @return EE_messenger[]
1438
-     */
1439
-    protected static function _get_default_messengers_to_generate_on_activation(
1440
-        EE_Message_Resource_Manager $message_resource_manager
1441
-    ) {
1442
-        $active_messengers    = $message_resource_manager->active_messengers();
1443
-        $installed_messengers = $message_resource_manager->installed_messengers();
1444
-        $has_activated        = $message_resource_manager->get_has_activated_messengers_option();
1445
-
1446
-        $messengers_to_generate = array();
1447
-        foreach ($installed_messengers as $installed_messenger) {
1448
-            //if installed messenger is a messenger that should be activated on install
1449
-            //and is not already active
1450
-            //and has never been activated
1451
-            if (
1452
-                ! $installed_messenger->activate_on_install
1453
-                || isset($active_messengers[$installed_messenger->name])
1454
-                || isset($has_activated[$installed_messenger->name])
1455
-            ) {
1456
-                continue;
1457
-            }
1458
-            $messengers_to_generate[$installed_messenger->name] = $installed_messenger;
1459
-        }
1460
-        return $messengers_to_generate;
1461
-    }
1462
-
1463
-
1464
-    /**
1465
-     * This simply validates active message types to ensure they actually match installed
1466
-     * message types.  If there's a mismatch then we deactivate the message type and ensure all related db
1467
-     * rows are set inactive.
1468
-     * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever
1469
-     * EE_Messenger_Resource_Manager is constructed.  Message Types are a bit more resource heavy for validation so they
1470
-     * are still handled in here.
1471
-     *
1472
-     * @since 4.3.1
1473
-     * @return void
1474
-     */
1475
-    public static function validate_messages_system()
1476
-    {
1477
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
1478
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1479
-        $message_resource_manager->validate_active_message_types_are_installed();
1480
-        do_action('AHEE__EEH_Activation__validate_messages_system');
1481
-    }
1482
-
1483
-
1484
-    /**
1485
-     * create_no_ticket_prices_array
1486
-     *
1487
-     * @access public
1488
-     * @static
1489
-     * @return void
1490
-     */
1491
-    public static function create_no_ticket_prices_array()
1492
-    {
1493
-        // this creates an array for tracking events that have no active ticket prices created
1494
-        // this allows us to warn admins of the situation so that it can be corrected
1495
-        $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false);
1496
-        if (! $espresso_no_ticket_prices) {
1497
-            add_option('ee_no_ticket_prices', array(), '', false);
1498
-        }
1499
-    }
1500
-
1501
-
1502
-    /**
1503
-     * plugin_deactivation
1504
-     *
1505
-     * @access public
1506
-     * @static
1507
-     * @return void
1508
-     */
1509
-    public static function plugin_deactivation()
1510
-    {
1511
-    }
1512
-
1513
-
1514
-    /**
1515
-     * Finds all our EE4 custom post types, and deletes them and their associated data
1516
-     * (like post meta or term relations)
1517
-     *
1518
-     * @global wpdb $wpdb
1519
-     * @throws \EE_Error
1520
-     */
1521
-    public static function delete_all_espresso_cpt_data()
1522
-    {
1523
-        global $wpdb;
1524
-        //get all the CPT post_types
1525
-        $ee_post_types = array();
1526
-        foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1527
-            if (method_exists($model_name, 'instance')) {
1528
-                $model_obj = call_user_func(array($model_name, 'instance'));
1529
-                if ($model_obj instanceof EEM_CPT_Base) {
1530
-                    $ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type());
1531
-                }
1532
-            }
1533
-        }
1534
-        //get all our CPTs
1535
-        $query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")";
1536
-        $cpt_ids = $wpdb->get_col($query);
1537
-        //delete each post meta and term relations too
1538
-        foreach ($cpt_ids as $post_id) {
1539
-            wp_delete_post($post_id, true);
1540
-        }
1541
-    }
1542
-
1543
-    /**
1544
-     * Deletes all EE custom tables
1545
-     *
1546
-     * @return array
1547
-     */
1548
-    public static function drop_espresso_tables()
1549
-    {
1550
-        $tables = array();
1551
-        // load registry
1552
-        foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1553
-            if (method_exists($model_name, 'instance')) {
1554
-                $model_obj = call_user_func(array($model_name, 'instance'));
1555
-                if ($model_obj instanceof EEM_Base) {
1556
-                    foreach ($model_obj->get_tables() as $table) {
1557
-                        if (strpos($table->get_table_name(), 'esp_')
1558
-                            &&
1559
-                            (
1560
-                                is_main_site()//main site? nuke them all
1561
-                                || ! $table->is_global()//not main site,but not global either. nuke it
1562
-                            )
1563
-                        ) {
1564
-                            $tables[] = $table->get_table_name();
1565
-                        }
1566
-                    }
1567
-                }
1568
-            }
1569
-        }
1570
-
1571
-        //there are some tables whose models were removed.
1572
-        //they should be removed when removing all EE core's data
1573
-        $tables_without_models = array(
1574
-            'esp_promotion',
1575
-            'esp_promotion_applied',
1576
-            'esp_promotion_object',
1577
-            'esp_promotion_rule',
1578
-            'esp_rule',
1579
-        );
1580
-        foreach ($tables_without_models as $table) {
1581
-            $tables[] = $table;
1582
-        }
1583
-        return \EEH_Activation::getTableManager()->dropTables($tables);
1584
-    }
1585
-
1586
-
1587
-
1588
-    /**
1589
-     * Drops all the tables mentioned in a single MYSQL query. Double-checks
1590
-     * each table name provided has a wpdb prefix attached, and that it exists.
1591
-     * Returns the list actually deleted
1592
-     *
1593
-     * @deprecated in 4.9.13. Instead use TableManager::dropTables()
1594
-     * @global WPDB $wpdb
1595
-     * @param array $table_names
1596
-     * @return array of table names which we deleted
1597
-     */
1598
-    public static function drop_tables($table_names)
1599
-    {
1600
-        return \EEH_Activation::getTableManager()->dropTables($table_names);
1601
-    }
1602
-
1603
-
1604
-
1605
-    /**
1606
-     * plugin_uninstall
1607
-     *
1608
-     * @access public
1609
-     * @static
1610
-     * @param bool $remove_all
1611
-     * @return void
1612
-     */
1613
-    public static function delete_all_espresso_tables_and_data($remove_all = true)
1614
-    {
1615
-        global $wpdb;
1616
-        self::drop_espresso_tables();
1617
-        $wp_options_to_delete = array(
1618
-            'ee_no_ticket_prices'                => true,
1619
-            'ee_active_messengers'               => true,
1620
-            'ee_has_activated_messenger'         => true,
1621
-            'ee_flush_rewrite_rules'             => true,
1622
-            'ee_config'                          => false,
1623
-            'ee_data_migration_current_db_state' => true,
1624
-            'ee_data_migration_mapping_'         => false,
1625
-            'ee_data_migration_script_'          => false,
1626
-            'ee_data_migrations'                 => true,
1627
-            'ee_dms_map'                         => false,
1628
-            'ee_notices'                         => true,
1629
-            'lang_file_check_'                   => false,
1630
-            'ee_maintenance_mode'                => true,
1631
-            'ee_ueip_optin'                      => true,
1632
-            'ee_ueip_has_notified'               => true,
1633
-            'ee_plugin_activation_errors'        => true,
1634
-            'ee_id_mapping_from'                 => false,
1635
-            'espresso_persistent_admin_notices'  => true,
1636
-            'ee_encryption_key'                  => true,
1637
-            'pue_force_upgrade_'                 => false,
1638
-            'pue_json_error_'                    => false,
1639
-            'pue_install_key_'                   => false,
1640
-            'pue_verification_error_'            => false,
1641
-            'pu_dismissed_upgrade_'              => false,
1642
-            'external_updates-'                  => false,
1643
-            'ee_extra_data'                      => true,
1644
-            'ee_ssn_'                            => false,
1645
-            'ee_rss_'                            => false,
1646
-            'ee_rte_n_tx_'                       => false,
1647
-            'ee_pers_admin_notices'              => true,
1648
-            'ee_job_parameters_'                 => false,
1649
-            'ee_upload_directories_incomplete'   => true,
1650
-            'ee_verified_db_collations'          => true,
1651
-        );
1652
-        if (is_main_site()) {
1653
-            $wp_options_to_delete['ee_network_config'] = true;
1654
-        }
1655
-        $undeleted_options = array();
1656
-        foreach ($wp_options_to_delete as $option_name => $no_wildcard) {
1657
-            if ($no_wildcard) {
1658
-                if ( ! delete_option($option_name)) {
1659
-                    $undeleted_options[] = $option_name;
1660
-                }
1661
-            } else {
1662
-                $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'");
1663
-                foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) {
1664
-                    if ( ! delete_option($option_name_from_wildcard)) {
1665
-                        $undeleted_options[] = $option_name_from_wildcard;
1666
-                    }
1667
-                }
1668
-            }
1669
-        }
1670
-        //also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it
1671
-        remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10);
1672
-        if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) {
1673
-            $db_update_sans_ee4 = array();
1674
-            foreach ($espresso_db_update as $version => $times_activated) {
1675
-                if ((string)$version[0] === '3') {//if its NON EE4
1676
-                    $db_update_sans_ee4[$version] = $times_activated;
1677
-                }
1678
-            }
1679
-            update_option('espresso_db_update', $db_update_sans_ee4);
1680
-        }
1681
-        $errors = '';
1682
-        if ( ! empty($undeleted_options)) {
1683
-            $errors .= sprintf(
1684
-                __('The following wp-options could not be deleted: %s%s', 'event_espresso'),
1685
-                '<br/>',
1686
-                implode(',<br/>', $undeleted_options)
1687
-            );
1688
-        }
1689
-        if ( ! empty($errors)) {
1690
-            EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__);
1691
-        }
1692
-    }
1693
-
1694
-    /**
1695
-     * Gets the mysql error code from the last used query by wpdb
1696
-     *
1697
-     * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html
1698
-     */
1699
-    public static function last_wpdb_error_code()
1700
-    {
1701
-        global $wpdb;
1702
-        if ($wpdb->use_mysqli) {
1703
-            return mysqli_errno($wpdb->dbh);
1704
-        } else {
1705
-            return mysql_errno($wpdb->dbh);
1706
-        }
1707
-    }
1708
-
1709
-    /**
1710
-     * Checks that the database table exists. Also works on temporary tables (for unit tests mostly).
1711
-     *
1712
-     * @global wpdb  $wpdb
1713
-     * @deprecated instead use TableAnalysis::tableExists()
1714
-     * @param string $table_name with or without $wpdb->prefix
1715
-     * @return boolean
1716
-     */
1717
-    public static function table_exists($table_name)
1718
-    {
1719
-        return \EEH_Activation::getTableAnalysis()->tableExists($table_name);
1720
-    }
1721
-
1722
-    /**
1723
-     * Resets the cache on EEH_Activation
1724
-     */
1725
-    public static function reset()
1726
-    {
1727
-        self::$_default_creator_id                             = null;
1728
-        self::$_initialized_db_content_already_in_this_request = false;
1729
-    }
1299
+		$new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates(
1300
+			$message_resource_manager
1301
+		);
1302
+		/**
1303
+		 * This method is verifying there are no NEW default message types
1304
+		 * for ACTIVE messengers that need activated (and corresponding templates setup).
1305
+		 */
1306
+		$new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates(
1307
+			$message_resource_manager
1308
+		);
1309
+		//after all is done, let's persist these changes to the db.
1310
+		$message_resource_manager->update_has_activated_messengers_option();
1311
+		$message_resource_manager->update_active_messengers_option();
1312
+		// will return true if either of these are true.  Otherwise will return false.
1313
+		return $new_templates_created_for_message_type || $new_templates_created_for_messenger;
1314
+	}
1315
+
1316
+
1317
+
1318
+	/**
1319
+	 * @param \EE_Message_Resource_Manager $message_resource_manager
1320
+	 * @return array|bool
1321
+	 * @throws \EE_Error
1322
+	 */
1323
+	protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates(
1324
+		EE_Message_Resource_Manager $message_resource_manager
1325
+	) {
1326
+		/** @type EE_messenger[] $active_messengers */
1327
+		$active_messengers = $message_resource_manager->active_messengers();
1328
+		$installed_message_types = $message_resource_manager->installed_message_types();
1329
+		$templates_created = false;
1330
+		foreach ($active_messengers as $active_messenger) {
1331
+			$default_message_type_names_for_messenger = $active_messenger->get_default_message_types();
1332
+			$default_message_type_names_to_activate = array();
1333
+			// looping through each default message type reported by the messenger
1334
+			// and setup the actual message types to activate.
1335
+			foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) {
1336
+				// if already active or has already been activated before we skip
1337
+				// (otherwise we might reactivate something user's intentionally deactivated.)
1338
+				// we also skip if the message type is not installed.
1339
+				if (
1340
+					$message_resource_manager->has_message_type_been_activated_for_messenger(
1341
+						$default_message_type_name_for_messenger,
1342
+						$active_messenger->name
1343
+					)
1344
+					|| $message_resource_manager->is_message_type_active_for_messenger(
1345
+						$active_messenger->name,
1346
+						$default_message_type_name_for_messenger
1347
+					)
1348
+					|| ! isset($installed_message_types[$default_message_type_name_for_messenger])
1349
+				) {
1350
+					continue;
1351
+				}
1352
+				$default_message_type_names_to_activate[] = $default_message_type_name_for_messenger;
1353
+			}
1354
+			//let's activate!
1355
+			$message_resource_manager->ensure_message_types_are_active(
1356
+				$default_message_type_names_to_activate,
1357
+				$active_messenger->name,
1358
+				false
1359
+			);
1360
+			//activate the templates for these message types
1361
+			if ( ! empty($default_message_type_names_to_activate)) {
1362
+				$templates_created = EEH_MSG_Template::generate_new_templates(
1363
+					$active_messenger->name,
1364
+					$default_message_type_names_for_messenger,
1365
+					'',
1366
+					true
1367
+				);
1368
+			}
1369
+		}
1370
+		return $templates_created;
1371
+	}
1372
+
1373
+
1374
+
1375
+	/**
1376
+	 * This will activate and generate default messengers and default message types for those messengers.
1377
+	 *
1378
+	 * @param EE_message_Resource_Manager $message_resource_manager
1379
+	 * @return array|bool  True means there were default messengers and message type templates generated.
1380
+	 *                     False means that there were no templates generated
1381
+	 *                     (which could simply mean there are no default message types for a messenger).
1382
+	 * @throws EE_Error
1383
+	 */
1384
+	protected static function _activate_and_generate_default_messengers_and_message_templates(
1385
+		EE_Message_Resource_Manager $message_resource_manager
1386
+	) {
1387
+		/** @type EE_messenger[] $messengers_to_generate */
1388
+		$messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager);
1389
+		$installed_message_types = $message_resource_manager->installed_message_types();
1390
+		$templates_generated = false;
1391
+		foreach ($messengers_to_generate as $messenger_to_generate) {
1392
+			$default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types();
1393
+			//verify the default message types match an installed message type.
1394
+			foreach ($default_message_type_names_for_messenger as $key => $name) {
1395
+				if (
1396
+					! isset($installed_message_types[$name])
1397
+					|| $message_resource_manager->has_message_type_been_activated_for_messenger(
1398
+						$name,
1399
+						$messenger_to_generate->name
1400
+					)
1401
+				) {
1402
+					unset($default_message_type_names_for_messenger[$key]);
1403
+				}
1404
+			}
1405
+			// in previous iterations, the active_messengers option in the db
1406
+			// needed updated before calling create templates. however with the changes this may not be necessary.
1407
+			// This comment is left here just in case we discover that we _do_ need to update before
1408
+			// passing off to create templates (after the refactor is done).
1409
+			// @todo remove this comment when determined not necessary.
1410
+			$message_resource_manager->activate_messenger(
1411
+				$messenger_to_generate->name,
1412
+				$default_message_type_names_for_messenger,
1413
+				false
1414
+			);
1415
+			//create any templates needing created (or will reactivate templates already generated as necessary).
1416
+			if ( ! empty($default_message_type_names_for_messenger)) {
1417
+				$templates_generated = EEH_MSG_Template::generate_new_templates(
1418
+					$messenger_to_generate->name,
1419
+					$default_message_type_names_for_messenger,
1420
+					'',
1421
+					true
1422
+				);
1423
+			}
1424
+		}
1425
+		return $templates_generated;
1426
+	}
1427
+
1428
+
1429
+	/**
1430
+	 * This returns the default messengers to generate templates for on activation of EE.
1431
+	 * It considers:
1432
+	 * - whether a messenger is already active in the db.
1433
+	 * - whether a messenger has been made active at any time in the past.
1434
+	 *
1435
+	 * @static
1436
+	 * @param  EE_Message_Resource_Manager $message_resource_manager
1437
+	 * @return EE_messenger[]
1438
+	 */
1439
+	protected static function _get_default_messengers_to_generate_on_activation(
1440
+		EE_Message_Resource_Manager $message_resource_manager
1441
+	) {
1442
+		$active_messengers    = $message_resource_manager->active_messengers();
1443
+		$installed_messengers = $message_resource_manager->installed_messengers();
1444
+		$has_activated        = $message_resource_manager->get_has_activated_messengers_option();
1445
+
1446
+		$messengers_to_generate = array();
1447
+		foreach ($installed_messengers as $installed_messenger) {
1448
+			//if installed messenger is a messenger that should be activated on install
1449
+			//and is not already active
1450
+			//and has never been activated
1451
+			if (
1452
+				! $installed_messenger->activate_on_install
1453
+				|| isset($active_messengers[$installed_messenger->name])
1454
+				|| isset($has_activated[$installed_messenger->name])
1455
+			) {
1456
+				continue;
1457
+			}
1458
+			$messengers_to_generate[$installed_messenger->name] = $installed_messenger;
1459
+		}
1460
+		return $messengers_to_generate;
1461
+	}
1462
+
1463
+
1464
+	/**
1465
+	 * This simply validates active message types to ensure they actually match installed
1466
+	 * message types.  If there's a mismatch then we deactivate the message type and ensure all related db
1467
+	 * rows are set inactive.
1468
+	 * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever
1469
+	 * EE_Messenger_Resource_Manager is constructed.  Message Types are a bit more resource heavy for validation so they
1470
+	 * are still handled in here.
1471
+	 *
1472
+	 * @since 4.3.1
1473
+	 * @return void
1474
+	 */
1475
+	public static function validate_messages_system()
1476
+	{
1477
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
1478
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1479
+		$message_resource_manager->validate_active_message_types_are_installed();
1480
+		do_action('AHEE__EEH_Activation__validate_messages_system');
1481
+	}
1482
+
1483
+
1484
+	/**
1485
+	 * create_no_ticket_prices_array
1486
+	 *
1487
+	 * @access public
1488
+	 * @static
1489
+	 * @return void
1490
+	 */
1491
+	public static function create_no_ticket_prices_array()
1492
+	{
1493
+		// this creates an array for tracking events that have no active ticket prices created
1494
+		// this allows us to warn admins of the situation so that it can be corrected
1495
+		$espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false);
1496
+		if (! $espresso_no_ticket_prices) {
1497
+			add_option('ee_no_ticket_prices', array(), '', false);
1498
+		}
1499
+	}
1500
+
1501
+
1502
+	/**
1503
+	 * plugin_deactivation
1504
+	 *
1505
+	 * @access public
1506
+	 * @static
1507
+	 * @return void
1508
+	 */
1509
+	public static function plugin_deactivation()
1510
+	{
1511
+	}
1512
+
1513
+
1514
+	/**
1515
+	 * Finds all our EE4 custom post types, and deletes them and their associated data
1516
+	 * (like post meta or term relations)
1517
+	 *
1518
+	 * @global wpdb $wpdb
1519
+	 * @throws \EE_Error
1520
+	 */
1521
+	public static function delete_all_espresso_cpt_data()
1522
+	{
1523
+		global $wpdb;
1524
+		//get all the CPT post_types
1525
+		$ee_post_types = array();
1526
+		foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1527
+			if (method_exists($model_name, 'instance')) {
1528
+				$model_obj = call_user_func(array($model_name, 'instance'));
1529
+				if ($model_obj instanceof EEM_CPT_Base) {
1530
+					$ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type());
1531
+				}
1532
+			}
1533
+		}
1534
+		//get all our CPTs
1535
+		$query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")";
1536
+		$cpt_ids = $wpdb->get_col($query);
1537
+		//delete each post meta and term relations too
1538
+		foreach ($cpt_ids as $post_id) {
1539
+			wp_delete_post($post_id, true);
1540
+		}
1541
+	}
1542
+
1543
+	/**
1544
+	 * Deletes all EE custom tables
1545
+	 *
1546
+	 * @return array
1547
+	 */
1548
+	public static function drop_espresso_tables()
1549
+	{
1550
+		$tables = array();
1551
+		// load registry
1552
+		foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1553
+			if (method_exists($model_name, 'instance')) {
1554
+				$model_obj = call_user_func(array($model_name, 'instance'));
1555
+				if ($model_obj instanceof EEM_Base) {
1556
+					foreach ($model_obj->get_tables() as $table) {
1557
+						if (strpos($table->get_table_name(), 'esp_')
1558
+							&&
1559
+							(
1560
+								is_main_site()//main site? nuke them all
1561
+								|| ! $table->is_global()//not main site,but not global either. nuke it
1562
+							)
1563
+						) {
1564
+							$tables[] = $table->get_table_name();
1565
+						}
1566
+					}
1567
+				}
1568
+			}
1569
+		}
1570
+
1571
+		//there are some tables whose models were removed.
1572
+		//they should be removed when removing all EE core's data
1573
+		$tables_without_models = array(
1574
+			'esp_promotion',
1575
+			'esp_promotion_applied',
1576
+			'esp_promotion_object',
1577
+			'esp_promotion_rule',
1578
+			'esp_rule',
1579
+		);
1580
+		foreach ($tables_without_models as $table) {
1581
+			$tables[] = $table;
1582
+		}
1583
+		return \EEH_Activation::getTableManager()->dropTables($tables);
1584
+	}
1585
+
1586
+
1587
+
1588
+	/**
1589
+	 * Drops all the tables mentioned in a single MYSQL query. Double-checks
1590
+	 * each table name provided has a wpdb prefix attached, and that it exists.
1591
+	 * Returns the list actually deleted
1592
+	 *
1593
+	 * @deprecated in 4.9.13. Instead use TableManager::dropTables()
1594
+	 * @global WPDB $wpdb
1595
+	 * @param array $table_names
1596
+	 * @return array of table names which we deleted
1597
+	 */
1598
+	public static function drop_tables($table_names)
1599
+	{
1600
+		return \EEH_Activation::getTableManager()->dropTables($table_names);
1601
+	}
1602
+
1603
+
1604
+
1605
+	/**
1606
+	 * plugin_uninstall
1607
+	 *
1608
+	 * @access public
1609
+	 * @static
1610
+	 * @param bool $remove_all
1611
+	 * @return void
1612
+	 */
1613
+	public static function delete_all_espresso_tables_and_data($remove_all = true)
1614
+	{
1615
+		global $wpdb;
1616
+		self::drop_espresso_tables();
1617
+		$wp_options_to_delete = array(
1618
+			'ee_no_ticket_prices'                => true,
1619
+			'ee_active_messengers'               => true,
1620
+			'ee_has_activated_messenger'         => true,
1621
+			'ee_flush_rewrite_rules'             => true,
1622
+			'ee_config'                          => false,
1623
+			'ee_data_migration_current_db_state' => true,
1624
+			'ee_data_migration_mapping_'         => false,
1625
+			'ee_data_migration_script_'          => false,
1626
+			'ee_data_migrations'                 => true,
1627
+			'ee_dms_map'                         => false,
1628
+			'ee_notices'                         => true,
1629
+			'lang_file_check_'                   => false,
1630
+			'ee_maintenance_mode'                => true,
1631
+			'ee_ueip_optin'                      => true,
1632
+			'ee_ueip_has_notified'               => true,
1633
+			'ee_plugin_activation_errors'        => true,
1634
+			'ee_id_mapping_from'                 => false,
1635
+			'espresso_persistent_admin_notices'  => true,
1636
+			'ee_encryption_key'                  => true,
1637
+			'pue_force_upgrade_'                 => false,
1638
+			'pue_json_error_'                    => false,
1639
+			'pue_install_key_'                   => false,
1640
+			'pue_verification_error_'            => false,
1641
+			'pu_dismissed_upgrade_'              => false,
1642
+			'external_updates-'                  => false,
1643
+			'ee_extra_data'                      => true,
1644
+			'ee_ssn_'                            => false,
1645
+			'ee_rss_'                            => false,
1646
+			'ee_rte_n_tx_'                       => false,
1647
+			'ee_pers_admin_notices'              => true,
1648
+			'ee_job_parameters_'                 => false,
1649
+			'ee_upload_directories_incomplete'   => true,
1650
+			'ee_verified_db_collations'          => true,
1651
+		);
1652
+		if (is_main_site()) {
1653
+			$wp_options_to_delete['ee_network_config'] = true;
1654
+		}
1655
+		$undeleted_options = array();
1656
+		foreach ($wp_options_to_delete as $option_name => $no_wildcard) {
1657
+			if ($no_wildcard) {
1658
+				if ( ! delete_option($option_name)) {
1659
+					$undeleted_options[] = $option_name;
1660
+				}
1661
+			} else {
1662
+				$option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'");
1663
+				foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) {
1664
+					if ( ! delete_option($option_name_from_wildcard)) {
1665
+						$undeleted_options[] = $option_name_from_wildcard;
1666
+					}
1667
+				}
1668
+			}
1669
+		}
1670
+		//also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it
1671
+		remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10);
1672
+		if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) {
1673
+			$db_update_sans_ee4 = array();
1674
+			foreach ($espresso_db_update as $version => $times_activated) {
1675
+				if ((string)$version[0] === '3') {//if its NON EE4
1676
+					$db_update_sans_ee4[$version] = $times_activated;
1677
+				}
1678
+			}
1679
+			update_option('espresso_db_update', $db_update_sans_ee4);
1680
+		}
1681
+		$errors = '';
1682
+		if ( ! empty($undeleted_options)) {
1683
+			$errors .= sprintf(
1684
+				__('The following wp-options could not be deleted: %s%s', 'event_espresso'),
1685
+				'<br/>',
1686
+				implode(',<br/>', $undeleted_options)
1687
+			);
1688
+		}
1689
+		if ( ! empty($errors)) {
1690
+			EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__);
1691
+		}
1692
+	}
1693
+
1694
+	/**
1695
+	 * Gets the mysql error code from the last used query by wpdb
1696
+	 *
1697
+	 * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html
1698
+	 */
1699
+	public static function last_wpdb_error_code()
1700
+	{
1701
+		global $wpdb;
1702
+		if ($wpdb->use_mysqli) {
1703
+			return mysqli_errno($wpdb->dbh);
1704
+		} else {
1705
+			return mysql_errno($wpdb->dbh);
1706
+		}
1707
+	}
1708
+
1709
+	/**
1710
+	 * Checks that the database table exists. Also works on temporary tables (for unit tests mostly).
1711
+	 *
1712
+	 * @global wpdb  $wpdb
1713
+	 * @deprecated instead use TableAnalysis::tableExists()
1714
+	 * @param string $table_name with or without $wpdb->prefix
1715
+	 * @return boolean
1716
+	 */
1717
+	public static function table_exists($table_name)
1718
+	{
1719
+		return \EEH_Activation::getTableAnalysis()->tableExists($table_name);
1720
+	}
1721
+
1722
+	/**
1723
+	 * Resets the cache on EEH_Activation
1724
+	 */
1725
+	public static function reset()
1726
+	{
1727
+		self::$_default_creator_id                             = null;
1728
+		self::$_initialized_db_content_already_in_this_request = false;
1729
+	}
1730 1730
 }
1731 1731
 // End of file EEH_Activation.helper.php
1732 1732
 // Location: /helpers/EEH_Activation.core.php
Please login to merge, or discard this patch.