Completed
Branch FET-10486-add-timestamp-checki... (611b15)
by
unknown
105:07 queued 90:18
created
line_item_filters/EE_Specific_Registrations_Line_Item_Filter.class.php 2 patches
Indentation   +187 added lines, -187 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if (! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('No direct script access allowed');
3
+	exit('No direct script access allowed');
4 4
 }
5 5
 
6 6
 
@@ -18,192 +18,192 @@  discard block
 block discarded – undo
18 18
 class EE_Specific_Registrations_Line_Item_Filter extends EE_Line_Item_Filter_Base
19 19
 {
20 20
 
21
-    /**
22
-     * array of line item codes and their corresponding quantities for registrations
23
-     *
24
-     * @type array $_line_item_registrations
25
-     */
26
-    protected $_line_item_registrations = array();
27
-
28
-    /**
29
-     * Just kept in case we want it someday. Currently unused
30
-     *
31
-     * @var EE_Registration[]
32
-     */
33
-    protected $_registrations = array();
34
-
35
-    /**
36
-     * @var EE_Registration
37
-     */
38
-    protected $_current_registration;
39
-
40
-    /**
41
-     * these reg statuses should NOT increment the line item quantity
42
-     *
43
-     * @var array
44
-     */
45
-    protected $_closed_reg_statuses = array();
46
-
47
-
48
-
49
-    /**
50
-     * EE_Billable_Line_Item_Filter constructor.
51
-     *
52
-     * @param EE_Registration[] $registrations
53
-     * @throws EE_Error
54
-     */
55
-    public function __construct($registrations)
56
-    {
57
-        $this->_registrations = $registrations;
58
-        $this->_calculate_registrations_per_line_item_code($registrations);
59
-        // these reg statuses should NOT increment the line item quantity
60
-        $this->_closed_reg_statuses = EEM_Registration::closed_reg_statuses();
61
-    }
62
-
63
-
64
-
65
-    /**
66
-     * sets the _line_item_registrations from the provided registrations
67
-     *
68
-     * @param EE_Registration[] $registrations
69
-     * @return void
70
-     * @throws EE_Error
71
-     */
72
-    protected function _calculate_registrations_per_line_item_code($registrations)
73
-    {
74
-        foreach ($registrations as $registration) {
75
-            $line_item_code = EEM_Line_Item::instance()->get_var(
76
-                EEM_Line_Item::instance()->line_item_for_registration_query_params(
77
-                    $registration,
78
-                    array('limit' => 1)
79
-                ),
80
-                'LIN_code'
81
-            );
82
-            if ($line_item_code) {
83
-                if (! isset($this->_line_item_registrations[$line_item_code])) {
84
-                    $this->_line_item_registrations[$line_item_code] = array();
85
-                }
86
-                $this->_line_item_registrations[$line_item_code][$registration->ID()] = $registration;
87
-            }
88
-        }
89
-    }
90
-
91
-
92
-
93
-    /**
94
-     * Creates a duplicate of the line item tree, except only includes billable items
95
-     * and the portion of line items attributed to billable things
96
-     *
97
-     * @param EEI_Line_Item $line_item
98
-     * @return EEI_Line_Item
99
-     * @throws EE_Error
100
-     */
101
-    public function process(EEI_Line_Item $line_item)
102
-    {
103
-        $this->_adjust_line_item_quantity($line_item);
104
-        if (! $line_item->children()) {
105
-            return $line_item;
106
-        }
107
-        //the original running total (taking ALL tickets into account)
108
-        $running_total_of_children = 0;
109
-        //the new running total (only taking the specified ticket quantities into account)
110
-        $running_total_of_children_under_consideration = 0;
111
-        // let's also track the quantity of tickets that pertain to the registrations
112
-        $total_child_ticket_quantity = 0;
113
-        foreach ($line_item->children() as $child_line_item) {
114
-            $original_li_total = $child_line_item->is_percent()
115
-                ? $running_total_of_children * $child_line_item->percent() / 100
116
-                : $child_line_item->unit_price() * $child_line_item->quantity();
117
-            $this->process($child_line_item);
118
-            // If this line item is a normal line item that isn't for a ticket,
119
-            // we want to modify its total (and unit price if not a percentage line item)
120
-            // so it reflects only that portion of the surcharge/discount shared by these registrations
121
-            if (
122
-                $child_line_item->type() === EEM_Line_Item::type_line_item
123
-                && $child_line_item->OBJ_type() !== 'Ticket'
124
-            ) {
125
-                $percent_of_running_total = $running_total_of_children
126
-                    ? $original_li_total / $running_total_of_children
127
-                    : 0;
128
-                $child_line_item->set_total(
129
-                    $running_total_of_children_under_consideration * $percent_of_running_total
130
-                );
131
-                if (! $child_line_item->is_percent()) {
132
-                    $child_line_item->set_unit_price($child_line_item->total() / $child_line_item->quantity());
133
-                }
134
-            } else if (
135
-                //make sure this item's quantity and total matches its parent
136
-                $line_item->type() === EEM_Line_Item::type_line_item
137
-                && $line_item->OBJ_type() === 'Ticket'
138
-                // but not if it's a percentage modifier
139
-                && ! $child_line_item->is_percent()
140
-                && ! (
141
-                    // or a cancellation
142
-                    $child_line_item->is_cancelled()
143
-                    && ! (
144
-                        // unless it IS a cancellation and the current registration is cancelled
145
-                        $child_line_item->is_cancelled()
146
-                        && $this->_current_registration instanceof EE_Registration
147
-                        && in_array($this->_current_registration->status_ID(), $this->_closed_reg_statuses, true)
148
-                    )
149
-                )
150
-            ) {
151
-                $child_line_item->set_quantity($line_item->quantity());
152
-                $child_line_item->set_total($child_line_item->unit_price() * $child_line_item->quantity());
153
-            }
154
-            $running_total_of_children += $original_li_total;
155
-            $running_total_of_children_under_consideration += $child_line_item->total();
156
-            if ($child_line_item->OBJ_type() === 'Ticket') {
157
-                $total_child_ticket_quantity += $child_line_item->quantity();
158
-            }
159
-        }
160
-        $line_item->set_total($running_total_of_children_under_consideration);
161
-        if ($line_item->quantity()) {
162
-            $line_item->set_unit_price($running_total_of_children_under_consideration / $line_item->quantity());
163
-        } else {
164
-            $line_item->set_unit_price(0);
165
-        }
166
-        if ($line_item->OBJ_type() === 'Event') {
167
-            $line_item->set_quantity($total_child_ticket_quantity);
168
-        }
169
-        return $line_item;
170
-    }
171
-
172
-
173
-
174
-    /**
175
-     * Adjusts quantities for line items for tickets according to the registrations provided
176
-     * in the constructor
177
-     *
178
-     * @param EEI_Line_Item $line_item
179
-     * @return EEI_Line_Item
180
-     */
181
-    protected function _adjust_line_item_quantity(EEI_Line_Item $line_item)
182
-    {
183
-        // is this a ticket ?
184
-        if ($line_item->type() === EEM_Line_Item::type_line_item && $line_item->OBJ_type() === 'Ticket') {
185
-            $this->_current_registration = null;
186
-            $quantity = 0;
187
-            // if this ticket is billable at this moment, then we should have a positive quantity
188
-            if (
189
-                isset($this->_line_item_registrations[$line_item->code()])
190
-                && is_array($this->_line_item_registrations[$line_item->code()])
191
-            ) {
192
-                // set quantity based on number of open registrations for this ticket
193
-                foreach ($this->_line_item_registrations[$line_item->code()] as $registration) {
194
-                    if (
195
-                        $registration instanceof EE_Registration
196
-                    ) {
197
-                        $quantity++;
198
-                        $this->_current_registration = $registration;
199
-                    }
200
-                }
201
-            }
202
-            $line_item->set_quantity($quantity);
203
-            $line_item->set_total($line_item->unit_price() * $line_item->quantity());
204
-        }
205
-        return $line_item;
206
-    }
21
+	/**
22
+	 * array of line item codes and their corresponding quantities for registrations
23
+	 *
24
+	 * @type array $_line_item_registrations
25
+	 */
26
+	protected $_line_item_registrations = array();
27
+
28
+	/**
29
+	 * Just kept in case we want it someday. Currently unused
30
+	 *
31
+	 * @var EE_Registration[]
32
+	 */
33
+	protected $_registrations = array();
34
+
35
+	/**
36
+	 * @var EE_Registration
37
+	 */
38
+	protected $_current_registration;
39
+
40
+	/**
41
+	 * these reg statuses should NOT increment the line item quantity
42
+	 *
43
+	 * @var array
44
+	 */
45
+	protected $_closed_reg_statuses = array();
46
+
47
+
48
+
49
+	/**
50
+	 * EE_Billable_Line_Item_Filter constructor.
51
+	 *
52
+	 * @param EE_Registration[] $registrations
53
+	 * @throws EE_Error
54
+	 */
55
+	public function __construct($registrations)
56
+	{
57
+		$this->_registrations = $registrations;
58
+		$this->_calculate_registrations_per_line_item_code($registrations);
59
+		// these reg statuses should NOT increment the line item quantity
60
+		$this->_closed_reg_statuses = EEM_Registration::closed_reg_statuses();
61
+	}
62
+
63
+
64
+
65
+	/**
66
+	 * sets the _line_item_registrations from the provided registrations
67
+	 *
68
+	 * @param EE_Registration[] $registrations
69
+	 * @return void
70
+	 * @throws EE_Error
71
+	 */
72
+	protected function _calculate_registrations_per_line_item_code($registrations)
73
+	{
74
+		foreach ($registrations as $registration) {
75
+			$line_item_code = EEM_Line_Item::instance()->get_var(
76
+				EEM_Line_Item::instance()->line_item_for_registration_query_params(
77
+					$registration,
78
+					array('limit' => 1)
79
+				),
80
+				'LIN_code'
81
+			);
82
+			if ($line_item_code) {
83
+				if (! isset($this->_line_item_registrations[$line_item_code])) {
84
+					$this->_line_item_registrations[$line_item_code] = array();
85
+				}
86
+				$this->_line_item_registrations[$line_item_code][$registration->ID()] = $registration;
87
+			}
88
+		}
89
+	}
90
+
91
+
92
+
93
+	/**
94
+	 * Creates a duplicate of the line item tree, except only includes billable items
95
+	 * and the portion of line items attributed to billable things
96
+	 *
97
+	 * @param EEI_Line_Item $line_item
98
+	 * @return EEI_Line_Item
99
+	 * @throws EE_Error
100
+	 */
101
+	public function process(EEI_Line_Item $line_item)
102
+	{
103
+		$this->_adjust_line_item_quantity($line_item);
104
+		if (! $line_item->children()) {
105
+			return $line_item;
106
+		}
107
+		//the original running total (taking ALL tickets into account)
108
+		$running_total_of_children = 0;
109
+		//the new running total (only taking the specified ticket quantities into account)
110
+		$running_total_of_children_under_consideration = 0;
111
+		// let's also track the quantity of tickets that pertain to the registrations
112
+		$total_child_ticket_quantity = 0;
113
+		foreach ($line_item->children() as $child_line_item) {
114
+			$original_li_total = $child_line_item->is_percent()
115
+				? $running_total_of_children * $child_line_item->percent() / 100
116
+				: $child_line_item->unit_price() * $child_line_item->quantity();
117
+			$this->process($child_line_item);
118
+			// If this line item is a normal line item that isn't for a ticket,
119
+			// we want to modify its total (and unit price if not a percentage line item)
120
+			// so it reflects only that portion of the surcharge/discount shared by these registrations
121
+			if (
122
+				$child_line_item->type() === EEM_Line_Item::type_line_item
123
+				&& $child_line_item->OBJ_type() !== 'Ticket'
124
+			) {
125
+				$percent_of_running_total = $running_total_of_children
126
+					? $original_li_total / $running_total_of_children
127
+					: 0;
128
+				$child_line_item->set_total(
129
+					$running_total_of_children_under_consideration * $percent_of_running_total
130
+				);
131
+				if (! $child_line_item->is_percent()) {
132
+					$child_line_item->set_unit_price($child_line_item->total() / $child_line_item->quantity());
133
+				}
134
+			} else if (
135
+				//make sure this item's quantity and total matches its parent
136
+				$line_item->type() === EEM_Line_Item::type_line_item
137
+				&& $line_item->OBJ_type() === 'Ticket'
138
+				// but not if it's a percentage modifier
139
+				&& ! $child_line_item->is_percent()
140
+				&& ! (
141
+					// or a cancellation
142
+					$child_line_item->is_cancelled()
143
+					&& ! (
144
+						// unless it IS a cancellation and the current registration is cancelled
145
+						$child_line_item->is_cancelled()
146
+						&& $this->_current_registration instanceof EE_Registration
147
+						&& in_array($this->_current_registration->status_ID(), $this->_closed_reg_statuses, true)
148
+					)
149
+				)
150
+			) {
151
+				$child_line_item->set_quantity($line_item->quantity());
152
+				$child_line_item->set_total($child_line_item->unit_price() * $child_line_item->quantity());
153
+			}
154
+			$running_total_of_children += $original_li_total;
155
+			$running_total_of_children_under_consideration += $child_line_item->total();
156
+			if ($child_line_item->OBJ_type() === 'Ticket') {
157
+				$total_child_ticket_quantity += $child_line_item->quantity();
158
+			}
159
+		}
160
+		$line_item->set_total($running_total_of_children_under_consideration);
161
+		if ($line_item->quantity()) {
162
+			$line_item->set_unit_price($running_total_of_children_under_consideration / $line_item->quantity());
163
+		} else {
164
+			$line_item->set_unit_price(0);
165
+		}
166
+		if ($line_item->OBJ_type() === 'Event') {
167
+			$line_item->set_quantity($total_child_ticket_quantity);
168
+		}
169
+		return $line_item;
170
+	}
171
+
172
+
173
+
174
+	/**
175
+	 * Adjusts quantities for line items for tickets according to the registrations provided
176
+	 * in the constructor
177
+	 *
178
+	 * @param EEI_Line_Item $line_item
179
+	 * @return EEI_Line_Item
180
+	 */
181
+	protected function _adjust_line_item_quantity(EEI_Line_Item $line_item)
182
+	{
183
+		// is this a ticket ?
184
+		if ($line_item->type() === EEM_Line_Item::type_line_item && $line_item->OBJ_type() === 'Ticket') {
185
+			$this->_current_registration = null;
186
+			$quantity = 0;
187
+			// if this ticket is billable at this moment, then we should have a positive quantity
188
+			if (
189
+				isset($this->_line_item_registrations[$line_item->code()])
190
+				&& is_array($this->_line_item_registrations[$line_item->code()])
191
+			) {
192
+				// set quantity based on number of open registrations for this ticket
193
+				foreach ($this->_line_item_registrations[$line_item->code()] as $registration) {
194
+					if (
195
+						$registration instanceof EE_Registration
196
+					) {
197
+						$quantity++;
198
+						$this->_current_registration = $registration;
199
+					}
200
+				}
201
+			}
202
+			$line_item->set_quantity($quantity);
203
+			$line_item->set_total($line_item->unit_price() * $line_item->quantity());
204
+		}
205
+		return $line_item;
206
+	}
207 207
 
208 208
 
209 209
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if (! defined('EVENT_ESPRESSO_VERSION')) {
2
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3 3
     exit('No direct script access allowed');
4 4
 }
5 5
 
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
                 'LIN_code'
81 81
             );
82 82
             if ($line_item_code) {
83
-                if (! isset($this->_line_item_registrations[$line_item_code])) {
83
+                if ( ! isset($this->_line_item_registrations[$line_item_code])) {
84 84
                     $this->_line_item_registrations[$line_item_code] = array();
85 85
                 }
86 86
                 $this->_line_item_registrations[$line_item_code][$registration->ID()] = $registration;
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
     public function process(EEI_Line_Item $line_item)
102 102
     {
103 103
         $this->_adjust_line_item_quantity($line_item);
104
-        if (! $line_item->children()) {
104
+        if ( ! $line_item->children()) {
105 105
             return $line_item;
106 106
         }
107 107
         //the original running total (taking ALL tickets into account)
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
                 $child_line_item->set_total(
129 129
                     $running_total_of_children_under_consideration * $percent_of_running_total
130 130
                 );
131
-                if (! $child_line_item->is_percent()) {
131
+                if ( ! $child_line_item->is_percent()) {
132 132
                     $child_line_item->set_unit_price($child_line_item->total() / $child_line_item->quantity());
133 133
                 }
134 134
             } else if (
Please login to merge, or discard this patch.
core/libraries/form_sections/form_handlers/SequentialStepForm.php 2 patches
Indentation   +223 added lines, -223 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 use InvalidArgumentException;
9 9
 
10 10
 if (! defined('EVENT_ESPRESSO_VERSION')) {
11
-    exit('No direct script access allowed');
11
+	exit('No direct script access allowed');
12 12
 }
13 13
 
14 14
 
@@ -25,228 +25,228 @@  discard block
 block discarded – undo
25 25
 abstract class SequentialStepForm extends FormHandler implements SequentialStepFormInterface
26 26
 {
27 27
 
28
-    const REDIRECT_TO_NEXT_STEP    = 'redirect_to_next_step';
29
-
30
-    const REDIRECT_TO_CURRENT_STEP = 'redirect_to_current_step';
31
-
32
-    const REDIRECT_TO_PREV_STEP    = 'redirect_to_prev_step';
33
-
34
-    const REDIRECT_TO_OTHER        = 'redirect_to_other';
35
-
36
-    /**
37
-     * numerical value used for sorting form steps
38
-     *
39
-     * @var int $order
40
-     */
41
-    private $order = 1;
42
-
43
-    /**
44
-     * a final URL with all form related parameters added
45
-     * that will be used to advance to the next step
46
-     *
47
-     * @var string $redirect_url
48
-     */
49
-    private $redirect_url = '';
50
-
51
-    /**
52
-     * URL params in key value pairs
53
-     *
54
-     * @var array $redirect_args
55
-     */
56
-    private $redirect_args = array();
57
-
58
-    /**
59
-     * Which step should be redirected to after form processing.
60
-     * Usually after successfully processing this value would be REDIRECT_TO_NEXT_STEP
61
-     * If a form is invalid and requires errors to be corrected,
62
-     * then this value would be REDIRECT_TO_CURRENT_STEP so that form can be resubmitted
63
-     * Some form handlers do not have a form that is displayable,
64
-     * and only perform data processing, but if an error occurs,
65
-     * then this value needs to be set to REDIRECT_TO_PREV_STEP
66
-     * since the current step has no displayable content.
67
-     * if the form is completely finished, and needs to redirect to somewhere
68
-     * completely different, then this value will be REDIRECT_TO_OTHER
69
-     *
70
-     * @var string $redirect_to
71
-     */
72
-    private $redirect_to = SequentialStepForm::REDIRECT_TO_CURRENT_STEP;
73
-
74
-
75
-
76
-    /**
77
-     * SequentialStepForm constructor
78
-     *
79
-     * @param int         $order
80
-     * @param string      $form_name
81
-     * @param string      $admin_name
82
-     * @param string      $slug
83
-     * @param string      $form_action
84
-     * @param string      $form_config
85
-     * @param EE_Registry $registry
86
-     * @throws InvalidArgumentException
87
-     * @throws InvalidDataTypeException
88
-     * @throws DomainException
89
-     */
90
-    public function __construct(
91
-        $order,
92
-        $form_name,
93
-        $admin_name,
94
-        $slug,
95
-        $form_action = '',
96
-        $form_config = 'add_form_tags_and_submit',
97
-        EE_Registry $registry
98
-    ) {
99
-        $this->setOrder($order);
100
-        parent::__construct($form_name, $admin_name, $slug, $form_action, $form_config, $registry);
101
-    }
102
-
103
-
104
-
105
-    /**
106
-     * @return int
107
-     */
108
-    public function order()
109
-    {
110
-        return $this->order;
111
-    }
112
-
113
-
114
-
115
-    /**
116
-     * @param int $order
117
-     * @throws InvalidArgumentException
118
-     */
119
-    public function setOrder($order)
120
-    {
121
-        $order = absint($order);
122
-        if (! $order > 0) {
123
-            throw new InvalidArgumentException(
124
-                esc_html__('The form order property must be a positive integer.', 'event_espresso')
125
-            );
126
-        }
127
-        $this->order = $order;
128
-    }
129
-
130
-
131
-
132
-    /**
133
-     * @return string
134
-     */
135
-    public function redirectUrl()
136
-    {
137
-        return ! empty($this->redirect_args)
138
-            ? add_query_arg($this->redirect_args, $this->redirect_url)
139
-            : $this->redirect_url;
140
-    }
141
-
142
-
143
-
144
-    /**
145
-     * @param string $redirect_url
146
-     * @throws InvalidDataTypeException
147
-     * @throws InvalidArgumentException
148
-     */
149
-    public function setRedirectUrl($redirect_url)
150
-    {
151
-        if (! is_string($redirect_url)) {
152
-            throw new InvalidDataTypeException('$redirect_url', $redirect_url, 'string');
153
-        }
154
-        if (empty($redirect_url)) {
155
-            throw new InvalidArgumentException(
156
-                esc_html__('The redirect URL can not be an empty string.', 'event_espresso')
157
-            );
158
-        }
159
-        $this->redirect_url = $redirect_url;
160
-    }
161
-
162
-
163
-
164
-    /**
165
-     * @param array $redirect_args
166
-     * @throws InvalidDataTypeException
167
-     * @throws InvalidArgumentException
168
-     */
169
-    public function addRedirectArgs($redirect_args = array())
170
-    {
171
-        if (is_object($redirect_args)) {
172
-            throw new InvalidDataTypeException(
173
-                '$redirect_args',
174
-                $redirect_args,
175
-                'anything other than an object was expected.'
176
-            );
177
-        }
178
-        if (empty($redirect_args)) {
179
-            throw new InvalidArgumentException(
180
-                esc_html__('The redirect argument can not be an empty array.', 'event_espresso')
181
-            );
182
-        }
183
-        $this->redirect_args = array_merge($this->redirect_args, (array)$redirect_args);
184
-    }
185
-
186
-
187
-
188
-    /**
189
-     * @param array $redirect_arg_keys_to_remove
190
-     * @throws InvalidDataTypeException
191
-     * @throws InvalidArgumentException
192
-     */
193
-    public function removeRedirectArgs($redirect_arg_keys_to_remove = array())
194
-    {
195
-        if (is_object($redirect_arg_keys_to_remove)) {
196
-            throw new InvalidDataTypeException(
197
-                '$redirect_arg_keys_to_remove',
198
-                $redirect_arg_keys_to_remove,
199
-                'anything other than an object was expected.'
200
-            );
201
-        }
202
-        if (empty($redirect_arg_keys_to_remove)) {
203
-            throw new InvalidArgumentException(
204
-                esc_html__('The $redirect_arg_keys_to_remove argument can not be an empty array.', 'event_espresso')
205
-            );
206
-        }
207
-        foreach ($redirect_arg_keys_to_remove as $redirect_arg_key) {
208
-            unset($this->redirect_args[$redirect_arg_key]);
209
-        }
210
-    }
211
-
212
-
213
-
214
-    /**
215
-     * @return string
216
-     */
217
-    public function redirectTo()
218
-    {
219
-        return $this->redirect_to;
220
-    }
221
-
222
-
223
-
224
-    /**
225
-     * @param string $redirect_to
226
-     * @throws InvalidDataTypeException
227
-     */
228
-    public function setRedirectTo($redirect_to)
229
-    {
230
-        if (
231
-            ! in_array(
232
-                $redirect_to,
233
-                array(
234
-                    SequentialStepForm::REDIRECT_TO_NEXT_STEP,
235
-                    SequentialStepForm::REDIRECT_TO_CURRENT_STEP,
236
-                    SequentialStepForm::REDIRECT_TO_PREV_STEP,
237
-                    SequentialStepForm::REDIRECT_TO_OTHER,
238
-                ),
239
-                true
240
-            )
241
-        ) {
242
-            throw new InvalidDataTypeException(
243
-                'setRedirectTo()',
244
-                $redirect_to,
245
-                'one of the SequentialStepForm class constants was expected.'
246
-            );
247
-        }
248
-        $this->redirect_to = $redirect_to;
249
-    }
28
+	const REDIRECT_TO_NEXT_STEP    = 'redirect_to_next_step';
29
+
30
+	const REDIRECT_TO_CURRENT_STEP = 'redirect_to_current_step';
31
+
32
+	const REDIRECT_TO_PREV_STEP    = 'redirect_to_prev_step';
33
+
34
+	const REDIRECT_TO_OTHER        = 'redirect_to_other';
35
+
36
+	/**
37
+	 * numerical value used for sorting form steps
38
+	 *
39
+	 * @var int $order
40
+	 */
41
+	private $order = 1;
42
+
43
+	/**
44
+	 * a final URL with all form related parameters added
45
+	 * that will be used to advance to the next step
46
+	 *
47
+	 * @var string $redirect_url
48
+	 */
49
+	private $redirect_url = '';
50
+
51
+	/**
52
+	 * URL params in key value pairs
53
+	 *
54
+	 * @var array $redirect_args
55
+	 */
56
+	private $redirect_args = array();
57
+
58
+	/**
59
+	 * Which step should be redirected to after form processing.
60
+	 * Usually after successfully processing this value would be REDIRECT_TO_NEXT_STEP
61
+	 * If a form is invalid and requires errors to be corrected,
62
+	 * then this value would be REDIRECT_TO_CURRENT_STEP so that form can be resubmitted
63
+	 * Some form handlers do not have a form that is displayable,
64
+	 * and only perform data processing, but if an error occurs,
65
+	 * then this value needs to be set to REDIRECT_TO_PREV_STEP
66
+	 * since the current step has no displayable content.
67
+	 * if the form is completely finished, and needs to redirect to somewhere
68
+	 * completely different, then this value will be REDIRECT_TO_OTHER
69
+	 *
70
+	 * @var string $redirect_to
71
+	 */
72
+	private $redirect_to = SequentialStepForm::REDIRECT_TO_CURRENT_STEP;
73
+
74
+
75
+
76
+	/**
77
+	 * SequentialStepForm constructor
78
+	 *
79
+	 * @param int         $order
80
+	 * @param string      $form_name
81
+	 * @param string      $admin_name
82
+	 * @param string      $slug
83
+	 * @param string      $form_action
84
+	 * @param string      $form_config
85
+	 * @param EE_Registry $registry
86
+	 * @throws InvalidArgumentException
87
+	 * @throws InvalidDataTypeException
88
+	 * @throws DomainException
89
+	 */
90
+	public function __construct(
91
+		$order,
92
+		$form_name,
93
+		$admin_name,
94
+		$slug,
95
+		$form_action = '',
96
+		$form_config = 'add_form_tags_and_submit',
97
+		EE_Registry $registry
98
+	) {
99
+		$this->setOrder($order);
100
+		parent::__construct($form_name, $admin_name, $slug, $form_action, $form_config, $registry);
101
+	}
102
+
103
+
104
+
105
+	/**
106
+	 * @return int
107
+	 */
108
+	public function order()
109
+	{
110
+		return $this->order;
111
+	}
112
+
113
+
114
+
115
+	/**
116
+	 * @param int $order
117
+	 * @throws InvalidArgumentException
118
+	 */
119
+	public function setOrder($order)
120
+	{
121
+		$order = absint($order);
122
+		if (! $order > 0) {
123
+			throw new InvalidArgumentException(
124
+				esc_html__('The form order property must be a positive integer.', 'event_espresso')
125
+			);
126
+		}
127
+		$this->order = $order;
128
+	}
129
+
130
+
131
+
132
+	/**
133
+	 * @return string
134
+	 */
135
+	public function redirectUrl()
136
+	{
137
+		return ! empty($this->redirect_args)
138
+			? add_query_arg($this->redirect_args, $this->redirect_url)
139
+			: $this->redirect_url;
140
+	}
141
+
142
+
143
+
144
+	/**
145
+	 * @param string $redirect_url
146
+	 * @throws InvalidDataTypeException
147
+	 * @throws InvalidArgumentException
148
+	 */
149
+	public function setRedirectUrl($redirect_url)
150
+	{
151
+		if (! is_string($redirect_url)) {
152
+			throw new InvalidDataTypeException('$redirect_url', $redirect_url, 'string');
153
+		}
154
+		if (empty($redirect_url)) {
155
+			throw new InvalidArgumentException(
156
+				esc_html__('The redirect URL can not be an empty string.', 'event_espresso')
157
+			);
158
+		}
159
+		$this->redirect_url = $redirect_url;
160
+	}
161
+
162
+
163
+
164
+	/**
165
+	 * @param array $redirect_args
166
+	 * @throws InvalidDataTypeException
167
+	 * @throws InvalidArgumentException
168
+	 */
169
+	public function addRedirectArgs($redirect_args = array())
170
+	{
171
+		if (is_object($redirect_args)) {
172
+			throw new InvalidDataTypeException(
173
+				'$redirect_args',
174
+				$redirect_args,
175
+				'anything other than an object was expected.'
176
+			);
177
+		}
178
+		if (empty($redirect_args)) {
179
+			throw new InvalidArgumentException(
180
+				esc_html__('The redirect argument can not be an empty array.', 'event_espresso')
181
+			);
182
+		}
183
+		$this->redirect_args = array_merge($this->redirect_args, (array)$redirect_args);
184
+	}
185
+
186
+
187
+
188
+	/**
189
+	 * @param array $redirect_arg_keys_to_remove
190
+	 * @throws InvalidDataTypeException
191
+	 * @throws InvalidArgumentException
192
+	 */
193
+	public function removeRedirectArgs($redirect_arg_keys_to_remove = array())
194
+	{
195
+		if (is_object($redirect_arg_keys_to_remove)) {
196
+			throw new InvalidDataTypeException(
197
+				'$redirect_arg_keys_to_remove',
198
+				$redirect_arg_keys_to_remove,
199
+				'anything other than an object was expected.'
200
+			);
201
+		}
202
+		if (empty($redirect_arg_keys_to_remove)) {
203
+			throw new InvalidArgumentException(
204
+				esc_html__('The $redirect_arg_keys_to_remove argument can not be an empty array.', 'event_espresso')
205
+			);
206
+		}
207
+		foreach ($redirect_arg_keys_to_remove as $redirect_arg_key) {
208
+			unset($this->redirect_args[$redirect_arg_key]);
209
+		}
210
+	}
211
+
212
+
213
+
214
+	/**
215
+	 * @return string
216
+	 */
217
+	public function redirectTo()
218
+	{
219
+		return $this->redirect_to;
220
+	}
221
+
222
+
223
+
224
+	/**
225
+	 * @param string $redirect_to
226
+	 * @throws InvalidDataTypeException
227
+	 */
228
+	public function setRedirectTo($redirect_to)
229
+	{
230
+		if (
231
+			! in_array(
232
+				$redirect_to,
233
+				array(
234
+					SequentialStepForm::REDIRECT_TO_NEXT_STEP,
235
+					SequentialStepForm::REDIRECT_TO_CURRENT_STEP,
236
+					SequentialStepForm::REDIRECT_TO_PREV_STEP,
237
+					SequentialStepForm::REDIRECT_TO_OTHER,
238
+				),
239
+				true
240
+			)
241
+		) {
242
+			throw new InvalidDataTypeException(
243
+				'setRedirectTo()',
244
+				$redirect_to,
245
+				'one of the SequentialStepForm class constants was expected.'
246
+			);
247
+		}
248
+		$this->redirect_to = $redirect_to;
249
+	}
250 250
 
251 251
 
252 252
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
 use EventEspresso\core\exceptions\InvalidDataTypeException;
8 8
 use InvalidArgumentException;
9 9
 
10
-if (! defined('EVENT_ESPRESSO_VERSION')) {
10
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
11 11
     exit('No direct script access allowed');
12 12
 }
13 13
 
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
     public function setOrder($order)
120 120
     {
121 121
         $order = absint($order);
122
-        if (! $order > 0) {
122
+        if ( ! $order > 0) {
123 123
             throw new InvalidArgumentException(
124 124
                 esc_html__('The form order property must be a positive integer.', 'event_espresso')
125 125
             );
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
      */
149 149
     public function setRedirectUrl($redirect_url)
150 150
     {
151
-        if (! is_string($redirect_url)) {
151
+        if ( ! is_string($redirect_url)) {
152 152
             throw new InvalidDataTypeException('$redirect_url', $redirect_url, 'string');
153 153
         }
154 154
         if (empty($redirect_url)) {
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
                 esc_html__('The redirect argument can not be an empty array.', 'event_espresso')
181 181
             );
182 182
         }
183
-        $this->redirect_args = array_merge($this->redirect_args, (array)$redirect_args);
183
+        $this->redirect_args = array_merge($this->redirect_args, (array) $redirect_args);
184 184
     }
185 185
 
186 186
 
Please login to merge, or discard this patch.
core/libraries/form_sections/form_handlers/SequentialStepFormManager.php 3 patches
Indentation   +614 added lines, -614 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
 use InvalidArgumentException;
19 19
 
20 20
 if (! defined('EVENT_ESPRESSO_VERSION')) {
21
-    exit('No direct script access allowed');
21
+	exit('No direct script access allowed');
22 22
 }
23 23
 
24 24
 
@@ -35,619 +35,619 @@  discard block
 block discarded – undo
35 35
 abstract class SequentialStepFormManager
36 36
 {
37 37
 
38
-    /**
39
-     * a simplified URL with no form related parameters
40
-     * that will be used to build the form's redirect URLs
41
-     *
42
-     * @var string $base_url
43
-     */
44
-    private $base_url = '';
45
-
46
-    /**
47
-     * the key used for the URL param that denotes the current form step
48
-     * defaults to 'ee-form-step'
49
-     *
50
-     * @var string $form_step_url_key
51
-     */
52
-    private $form_step_url_key = '';
53
-
54
-    /**
55
-     * @var string $default_form_step
56
-     */
57
-    private $default_form_step = '';
58
-
59
-    /**
60
-     * @var string $form_action
61
-     */
62
-    private $form_action;
63
-
64
-    /**
65
-     * value of one of the string constant above
66
-     *
67
-     * @var string $form_config
68
-     */
69
-    private $form_config;
70
-
71
-    /**
72
-     * @var string $progress_step_style
73
-     */
74
-    private $progress_step_style = '';
75
-
76
-    /**
77
-     * @var EE_Request $request
78
-     */
79
-    private $request;
80
-
81
-    /**
82
-     * @var Collection $form_steps
83
-     */
84
-    protected $form_steps;
85
-
86
-    /**
87
-     * @var ProgressStepManager $progress_step_manager
88
-     */
89
-    protected $progress_step_manager;
90
-
91
-
92
-
93
-    /**
94
-     * @return Collection|null
95
-     */
96
-    abstract protected function getFormStepsCollection();
97
-
98
-
99
-
100
-    /**
101
-     * StepsManager constructor
102
-     *
103
-     * @param string     $base_url
104
-     * @param string     $default_form_step
105
-     * @param string     $form_action
106
-     * @param string     $form_config
107
-     * @param EE_Request $request
108
-     * @param string     $progress_step_style
109
-     * @throws InvalidDataTypeException
110
-     * @throws InvalidArgumentException
111
-     */
112
-    public function __construct(
113
-        $base_url,
114
-        $default_form_step,
115
-        $form_action = '',
116
-        $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
117
-        $progress_step_style = 'number_bubbles',
118
-        EE_Request $request
119
-    ) {
120
-        $this->setBaseUrl($base_url);
121
-        $this->setDefaultFormStep($default_form_step);
122
-        $this->setFormAction($form_action);
123
-        $this->setFormConfig($form_config);
124
-        $this->setProgressStepStyle($progress_step_style);
125
-        $this->request = $request;
126
-    }
127
-
128
-
129
-
130
-    /**
131
-     * @return string
132
-     * @throws InvalidFormHandlerException
133
-     */
134
-    public function baseUrl()
135
-    {
136
-        if (strpos($this->base_url, $this->getCurrentStep()->slug()) === false) {
137
-            add_query_arg(
138
-                array($this->form_step_url_key => $this->getCurrentStep()->slug()),
139
-                $this->base_url
140
-            );
141
-        }
142
-        return $this->base_url;
143
-    }
144
-
145
-
146
-
147
-    /**
148
-     * @param string $base_url
149
-     * @throws InvalidDataTypeException
150
-     * @throws InvalidArgumentException
151
-     */
152
-    protected function setBaseUrl($base_url)
153
-    {
154
-        if (! is_string($base_url)) {
155
-            throw new InvalidDataTypeException('$base_url', $base_url, 'string');
156
-        }
157
-        if (empty($base_url)) {
158
-            throw new InvalidArgumentException(
159
-                esc_html__('The base URL can not be an empty string.', 'event_espresso')
160
-            );
161
-        }
162
-        $this->base_url = $base_url;
163
-    }
164
-
165
-
166
-
167
-    /**
168
-     * @return string
169
-     * @throws InvalidDataTypeException
170
-     */
171
-    public function formStepUrlKey()
172
-    {
173
-        if (empty($this->form_step_url_key)) {
174
-            $this->setFormStepUrlKey();
175
-        }
176
-        return $this->form_step_url_key;
177
-    }
178
-
179
-
180
-
181
-    /**
182
-     * @param string $form_step_url_key
183
-     * @throws InvalidDataTypeException
184
-     */
185
-    public function setFormStepUrlKey($form_step_url_key = 'ee-form-step')
186
-    {
187
-        if (! is_string($form_step_url_key)) {
188
-            throw new InvalidDataTypeException('$form_step_key', $form_step_url_key, 'string');
189
-        }
190
-        $this->form_step_url_key = ! empty($form_step_url_key) ? $form_step_url_key : 'ee-form-step';
191
-    }
192
-
193
-
194
-
195
-    /**
196
-     * @return string
197
-     */
198
-    public function defaultFormStep()
199
-    {
200
-        return $this->default_form_step;
201
-    }
202
-
203
-
204
-
205
-    /**
206
-     * @param $default_form_step
207
-     * @throws InvalidDataTypeException
208
-     */
209
-    protected function setDefaultFormStep($default_form_step)
210
-    {
211
-        if (! is_string($default_form_step)) {
212
-            throw new InvalidDataTypeException('$default_form_step', $default_form_step, 'string');
213
-        }
214
-        $this->default_form_step = $default_form_step;
215
-    }
216
-
217
-
218
-
219
-    /**
220
-     * @return void
221
-     * @throws \EventEspresso\core\exceptions\InvalidIdentifierException
222
-     * @throws InvalidDataTypeException
223
-     */
224
-    protected function setCurrentStepFromRequest()
225
-    {
226
-        $current_step_slug = $this->request()->get($this->formStepUrlKey(), $this->defaultFormStep());
227
-        if (! $this->form_steps->setCurrent($current_step_slug)) {
228
-            throw new InvalidIdentifierException(
229
-                $current_step_slug,
230
-                $this->defaultFormStep(),
231
-                $message = sprintf(
232
-                    esc_html__(
233
-                        'The "%1$s" form step could not be set.',
234
-                        'event_espresso'
235
-                    ),
236
-                    $current_step_slug
237
-                )
238
-            );
239
-        }
240
-    }
241
-
242
-
243
-
244
-    /**
245
-     * @return object|SequentialStepFormInterface
246
-     * @throws InvalidFormHandlerException
247
-     */
248
-    public function getCurrentStep()
249
-    {
250
-        if (! $this->form_steps->current() instanceof SequentialStepForm) {
251
-            throw new InvalidFormHandlerException($this->form_steps->current());
252
-        }
253
-        return $this->form_steps->current();
254
-    }
255
-
256
-
257
-
258
-    /**
259
-     * @return string
260
-     * @throws InvalidFormHandlerException
261
-     */
262
-    public function formAction()
263
-    {
264
-        if (! is_string($this->form_action) || empty($this->form_action)) {
265
-            $this->form_action = $this->baseUrl();
266
-        }
267
-        return $this->form_action;
268
-    }
269
-
270
-
271
-
272
-    /**
273
-     * @param string $form_action
274
-     * @throws InvalidDataTypeException
275
-     */
276
-    public function setFormAction($form_action)
277
-    {
278
-        if (! is_string($form_action)) {
279
-            throw new InvalidDataTypeException('$form_action', $form_action, 'string');
280
-        }
281
-        $this->form_action = $form_action;
282
-    }
283
-
284
-
285
-
286
-    /**
287
-     * @param array $form_action_args
288
-     * @throws InvalidDataTypeException
289
-     * @throws InvalidFormHandlerException
290
-     */
291
-    public function addFormActionArgs($form_action_args = array())
292
-    {
293
-        if (! is_array($form_action_args)) {
294
-            throw new InvalidDataTypeException('$form_action_args', $form_action_args, 'array');
295
-        }
296
-        $form_action_args = ! empty($form_action_args)
297
-            ? $form_action_args
298
-            : array($this->formStepUrlKey() => $this->form_steps->current()->slug());
299
-        $this->getCurrentStep()->setFormAction(
300
-            add_query_arg($form_action_args, $this->formAction())
301
-        );
302
-        $this->form_action = $this->getCurrentStep()->formAction();
303
-    }
304
-
305
-
306
-
307
-    /**
308
-     * @return string
309
-     */
310
-    public function formConfig()
311
-    {
312
-        return $this->form_config;
313
-    }
314
-
315
-
316
-
317
-    /**
318
-     * @param string $form_config
319
-     */
320
-    public function setFormConfig($form_config)
321
-    {
322
-        $this->form_config = $form_config;
323
-    }
324
-
325
-
326
-
327
-    /**
328
-     * @return string
329
-     */
330
-    public function progressStepStyle()
331
-    {
332
-        return $this->progress_step_style;
333
-    }
334
-
335
-
336
-
337
-    /**
338
-     * @param string $progress_step_style
339
-     */
340
-    public function setProgressStepStyle($progress_step_style)
341
-    {
342
-        $this->progress_step_style = $progress_step_style;
343
-    }
344
-
345
-
346
-
347
-    /**
348
-     * @return EE_Request
349
-     */
350
-    public function request()
351
-    {
352
-        return $this->request;
353
-    }
354
-
355
-
356
-
357
-    /**
358
-     * @return Collection|null
359
-     * @throws InvalidInterfaceException
360
-     */
361
-    protected function getProgressStepsCollection()
362
-    {
363
-        static $collection = null;
364
-        if (! $collection instanceof ProgressStepCollection) {
365
-            $collection = new ProgressStepCollection();
366
-        }
367
-        return $collection;
368
-    }
369
-
370
-
371
-
372
-    /**
373
-     * @param Collection $progress_steps_collection
374
-     * @return ProgressStepManager
375
-     * @throws InvalidInterfaceException
376
-     * @throws InvalidClassException
377
-     * @throws InvalidDataTypeException
378
-     * @throws InvalidEntityException
379
-     * @throws InvalidFormHandlerException
380
-     */
381
-    protected function generateProgressSteps(Collection $progress_steps_collection)
382
-    {
383
-        $current_step = $this->getCurrentStep();
384
-        /** @var SequentialStepForm $form_step */
385
-        foreach ($this->form_steps as $form_step) {
386
-            // is this step active ?
387
-            if (! $form_step->initialize()) {
388
-                continue;
389
-            }
390
-            $progress_steps_collection->add(
391
-                new ProgressStep(
392
-                    $form_step->order(),
393
-                    $form_step->slug(),
394
-                    $form_step->slug(),
395
-                    $form_step->formName()
396
-                ),
397
-                $form_step->slug()
398
-            );
399
-        }
400
-        // set collection pointer back to current step
401
-        $this->form_steps->setCurrentUsingObject($current_step);
402
-        return new ProgressStepManager(
403
-            $this->progressStepStyle(),
404
-            $this->defaultFormStep(),
405
-            $this->formStepUrlKey(),
406
-            $progress_steps_collection
407
-        );
408
-    }
409
-
410
-
411
-
412
-    /**
413
-     * @throws InvalidClassException
414
-     * @throws InvalidDataTypeException
415
-     * @throws InvalidEntityException
416
-     * @throws InvalidIdentifierException
417
-     * @throws InvalidInterfaceException
418
-     * @throws InvalidArgumentException
419
-     * @throws InvalidFormHandlerException
420
-     */
421
-    public function buildForm()
422
-    {
423
-        $this->buildCurrentStepFormForDisplay();
424
-    }
425
-
426
-
427
-
428
-    /**
429
-     * @param array $form_data
430
-     * @throws InvalidArgumentException
431
-     * @throws InvalidClassException
432
-     * @throws InvalidDataTypeException
433
-     * @throws InvalidEntityException
434
-     * @throws InvalidFormHandlerException
435
-     * @throws InvalidIdentifierException
436
-     * @throws InvalidInterfaceException
437
-     */
438
-    public function processForm($form_data = array())
439
-    {
440
-        $this->buildCurrentStepFormForProcessing();
441
-        $this->processCurrentStepForm($form_data);
442
-    }
443
-
444
-
445
-
446
-    /**
447
-     * @throws InvalidClassException
448
-     * @throws InvalidDataTypeException
449
-     * @throws InvalidEntityException
450
-     * @throws InvalidInterfaceException
451
-     * @throws InvalidIdentifierException
452
-     * @throws InvalidArgumentException
453
-     * @throws InvalidFormHandlerException
454
-     */
455
-    public function buildCurrentStepFormForDisplay()
456
-    {
457
-        $form_step = $this->buildCurrentStepForm();
458
-        // no displayable content ? then skip straight to processing
459
-        if (! $form_step->displayable()) {
460
-            $this->addFormActionArgs();
461
-            $form_step->setFormAction($this->formAction());
462
-            wp_safe_redirect($form_step->formAction());
463
-        }
464
-    }
465
-
466
-
467
-
468
-    /**
469
-     * @throws InvalidClassException
470
-     * @throws InvalidDataTypeException
471
-     * @throws InvalidEntityException
472
-     * @throws InvalidInterfaceException
473
-     * @throws InvalidIdentifierException
474
-     * @throws InvalidArgumentException
475
-     * @throws InvalidFormHandlerException
476
-     */
477
-    public function buildCurrentStepFormForProcessing()
478
-    {
479
-        $this->buildCurrentStepForm(false);
480
-    }
481
-
482
-
483
-
484
-    /**
485
-     * @param bool $for_display
486
-     * @return SequentialStepFormInterface
487
-     * @throws InvalidArgumentException
488
-     * @throws InvalidClassException
489
-     * @throws InvalidDataTypeException
490
-     * @throws InvalidEntityException
491
-     * @throws InvalidFormHandlerException
492
-     * @throws InvalidIdentifierException
493
-     * @throws InvalidInterfaceException
494
-     */
495
-    private function buildCurrentStepForm($for_display = true)
496
-    {
497
-        $this->form_steps = $this->getFormStepsCollection();
498
-        $this->setCurrentStepFromRequest();
499
-        $form_step = $this->getCurrentStep();
500
-        if ($form_step->submitBtnText() === esc_html__('Submit', 'event_espresso')) {
501
-            $form_step->setSubmitBtnText(esc_html__('Next Step', 'event_espresso'));
502
-        }
503
-        if ($for_display && $form_step->displayable()) {
504
-            $this->progress_step_manager = $this->generateProgressSteps(
505
-                $this->getProgressStepsCollection()
506
-            );
507
-            $this->progress_step_manager->setCurrentStep(
508
-                $form_step->slug()
509
-            );
510
-            // mark all previous progress steps as completed
511
-            $this->progress_step_manager->setPreviousStepsCompleted();
512
-            $this->progress_step_manager->enqueueStylesAndScripts();
513
-            $this->addFormActionArgs();
514
-            $form_step->setFormAction($this->formAction());
515
-        } else {
516
-            $form_step->setRedirectUrl($this->baseUrl());
517
-            $form_step->addRedirectArgs(
518
-                array($this->formStepUrlKey() => $this->form_steps->current()->slug())
519
-            );
520
-        }
521
-        $form_step->generate();
522
-        if ($for_display) {
523
-            $form_step->enqueueStylesAndScripts();
524
-        }
525
-        return $form_step;
526
-    }
527
-
528
-
529
-
530
-    /**
531
-     * @param bool $return_as_string
532
-     * @return string
533
-     * @throws InvalidFormHandlerException
534
-     */
535
-    public function displayProgressSteps($return_as_string = true)
536
-    {
537
-        $form_step = $this->getCurrentStep();
538
-        if (! $form_step->displayable()) {
539
-            return '';
540
-        }
541
-        $progress_steps = apply_filters(
542
-            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_SequentialStepFormManager__displayProgressSteps__before_steps',
543
-            ''
544
-        );
545
-        $progress_steps .= $this->progress_step_manager->displaySteps();
546
-        $progress_steps .= apply_filters(
547
-            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_SequentialStepFormManager__displayProgressSteps__after_steps',
548
-            ''
549
-        );
550
-        if ($return_as_string) {
551
-            return $progress_steps;
552
-        }
553
-        echo $progress_steps;
554
-        return '';
555
-    }
556
-
557
-
558
-
559
-    /**
560
-     * @param bool $return_as_string
561
-     * @return string
562
-     * @throws InvalidFormHandlerException
563
-     */
564
-    public function displayCurrentStepForm($return_as_string = true)
565
-    {
566
-        if ($return_as_string) {
567
-            return $this->getCurrentStep()->display();
568
-        }
569
-        echo $this->getCurrentStep()->display();
570
-        return '';
571
-    }
572
-
573
-
574
-
575
-    /**
576
-     * @param array $form_data
577
-     * @return void
578
-     * @throws InvalidArgumentException
579
-     * @throws InvalidDataTypeException
580
-     * @throws InvalidFormHandlerException
581
-     */
582
-    public function processCurrentStepForm($form_data = array())
583
-    {
584
-        // grab instance of current step because after calling next() below,
585
-        // any calls to getCurrentStep() will return the "next" step because we advanced
586
-        $current_step = $this->getCurrentStep();
587
-        try {
588
-            // form processing should either throw exceptions or return true
589
-            $current_step->process($form_data);
590
-        } catch (Exception $e) {
591
-            // something went wrong, so...
592
-            // if WP_DEBUG === true, display the Exception and stack trace right now
593
-            new ExceptionStackTraceDisplay($e);
594
-            // else convert the Exception to an EE_Error
595
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
596
-            // prevent redirect to next step or other if exception was thrown
597
-            if (
598
-                $current_step->redirectTo() === SequentialStepForm::REDIRECT_TO_NEXT_STEP
599
-                || $current_step->redirectTo() === SequentialStepForm::REDIRECT_TO_OTHER
600
-            ) {
601
-                $current_step->setRedirectTo(SequentialStepForm::REDIRECT_TO_CURRENT_STEP);
602
-            }
603
-        }
604
-        // save notices to a transient so that when we redirect back
605
-        // to the display portion for this step
606
-        // those notices can be displayed
607
-        EE_Error::get_notices(false, true);
608
-        $this->redirectForm($current_step);
609
-    }
610
-
611
-
612
-
613
-    /**
614
-     * handles where to go to next
615
-     *
616
-     * @param SequentialStepFormInterface $current_step
617
-     * @throws InvalidArgumentException
618
-     * @throws InvalidDataTypeException
619
-     * @throws InvalidFormHandlerException
620
-     */
621
-    public function redirectForm(SequentialStepFormInterface $current_step)
622
-    {
623
-        $redirect_step = $current_step;
624
-        switch ($current_step->redirectTo()) {
625
-            case SequentialStepForm::REDIRECT_TO_OTHER:
626
-                // going somewhere else, so just check out now
627
-                wp_safe_redirect($redirect_step->redirectUrl());
628
-                exit();
629
-                break;
630
-            case SequentialStepForm::REDIRECT_TO_PREV_STEP:
631
-                $redirect_step = $this->form_steps->previous();
632
-                break;
633
-            case SequentialStepForm::REDIRECT_TO_NEXT_STEP:
634
-                $this->form_steps->next();
635
-                if ($this->form_steps->valid()) {
636
-                    $redirect_step = $this->form_steps->current();
637
-                }
638
-                break;
639
-            case SequentialStepForm::REDIRECT_TO_CURRENT_STEP:
640
-            default :
641
-                // $redirect_step is already set
642
-        }
643
-        $current_step->setRedirectUrl($this->baseUrl());
644
-        $current_step->addRedirectArgs(
645
-        // use the slug for whatever step we are redirecting too
646
-            array($this->formStepUrlKey() => $redirect_step->slug())
647
-        );
648
-        wp_safe_redirect($current_step->redirectUrl());
649
-        exit();
650
-    }
38
+	/**
39
+	 * a simplified URL with no form related parameters
40
+	 * that will be used to build the form's redirect URLs
41
+	 *
42
+	 * @var string $base_url
43
+	 */
44
+	private $base_url = '';
45
+
46
+	/**
47
+	 * the key used for the URL param that denotes the current form step
48
+	 * defaults to 'ee-form-step'
49
+	 *
50
+	 * @var string $form_step_url_key
51
+	 */
52
+	private $form_step_url_key = '';
53
+
54
+	/**
55
+	 * @var string $default_form_step
56
+	 */
57
+	private $default_form_step = '';
58
+
59
+	/**
60
+	 * @var string $form_action
61
+	 */
62
+	private $form_action;
63
+
64
+	/**
65
+	 * value of one of the string constant above
66
+	 *
67
+	 * @var string $form_config
68
+	 */
69
+	private $form_config;
70
+
71
+	/**
72
+	 * @var string $progress_step_style
73
+	 */
74
+	private $progress_step_style = '';
75
+
76
+	/**
77
+	 * @var EE_Request $request
78
+	 */
79
+	private $request;
80
+
81
+	/**
82
+	 * @var Collection $form_steps
83
+	 */
84
+	protected $form_steps;
85
+
86
+	/**
87
+	 * @var ProgressStepManager $progress_step_manager
88
+	 */
89
+	protected $progress_step_manager;
90
+
91
+
92
+
93
+	/**
94
+	 * @return Collection|null
95
+	 */
96
+	abstract protected function getFormStepsCollection();
97
+
98
+
99
+
100
+	/**
101
+	 * StepsManager constructor
102
+	 *
103
+	 * @param string     $base_url
104
+	 * @param string     $default_form_step
105
+	 * @param string     $form_action
106
+	 * @param string     $form_config
107
+	 * @param EE_Request $request
108
+	 * @param string     $progress_step_style
109
+	 * @throws InvalidDataTypeException
110
+	 * @throws InvalidArgumentException
111
+	 */
112
+	public function __construct(
113
+		$base_url,
114
+		$default_form_step,
115
+		$form_action = '',
116
+		$form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
117
+		$progress_step_style = 'number_bubbles',
118
+		EE_Request $request
119
+	) {
120
+		$this->setBaseUrl($base_url);
121
+		$this->setDefaultFormStep($default_form_step);
122
+		$this->setFormAction($form_action);
123
+		$this->setFormConfig($form_config);
124
+		$this->setProgressStepStyle($progress_step_style);
125
+		$this->request = $request;
126
+	}
127
+
128
+
129
+
130
+	/**
131
+	 * @return string
132
+	 * @throws InvalidFormHandlerException
133
+	 */
134
+	public function baseUrl()
135
+	{
136
+		if (strpos($this->base_url, $this->getCurrentStep()->slug()) === false) {
137
+			add_query_arg(
138
+				array($this->form_step_url_key => $this->getCurrentStep()->slug()),
139
+				$this->base_url
140
+			);
141
+		}
142
+		return $this->base_url;
143
+	}
144
+
145
+
146
+
147
+	/**
148
+	 * @param string $base_url
149
+	 * @throws InvalidDataTypeException
150
+	 * @throws InvalidArgumentException
151
+	 */
152
+	protected function setBaseUrl($base_url)
153
+	{
154
+		if (! is_string($base_url)) {
155
+			throw new InvalidDataTypeException('$base_url', $base_url, 'string');
156
+		}
157
+		if (empty($base_url)) {
158
+			throw new InvalidArgumentException(
159
+				esc_html__('The base URL can not be an empty string.', 'event_espresso')
160
+			);
161
+		}
162
+		$this->base_url = $base_url;
163
+	}
164
+
165
+
166
+
167
+	/**
168
+	 * @return string
169
+	 * @throws InvalidDataTypeException
170
+	 */
171
+	public function formStepUrlKey()
172
+	{
173
+		if (empty($this->form_step_url_key)) {
174
+			$this->setFormStepUrlKey();
175
+		}
176
+		return $this->form_step_url_key;
177
+	}
178
+
179
+
180
+
181
+	/**
182
+	 * @param string $form_step_url_key
183
+	 * @throws InvalidDataTypeException
184
+	 */
185
+	public function setFormStepUrlKey($form_step_url_key = 'ee-form-step')
186
+	{
187
+		if (! is_string($form_step_url_key)) {
188
+			throw new InvalidDataTypeException('$form_step_key', $form_step_url_key, 'string');
189
+		}
190
+		$this->form_step_url_key = ! empty($form_step_url_key) ? $form_step_url_key : 'ee-form-step';
191
+	}
192
+
193
+
194
+
195
+	/**
196
+	 * @return string
197
+	 */
198
+	public function defaultFormStep()
199
+	{
200
+		return $this->default_form_step;
201
+	}
202
+
203
+
204
+
205
+	/**
206
+	 * @param $default_form_step
207
+	 * @throws InvalidDataTypeException
208
+	 */
209
+	protected function setDefaultFormStep($default_form_step)
210
+	{
211
+		if (! is_string($default_form_step)) {
212
+			throw new InvalidDataTypeException('$default_form_step', $default_form_step, 'string');
213
+		}
214
+		$this->default_form_step = $default_form_step;
215
+	}
216
+
217
+
218
+
219
+	/**
220
+	 * @return void
221
+	 * @throws \EventEspresso\core\exceptions\InvalidIdentifierException
222
+	 * @throws InvalidDataTypeException
223
+	 */
224
+	protected function setCurrentStepFromRequest()
225
+	{
226
+		$current_step_slug = $this->request()->get($this->formStepUrlKey(), $this->defaultFormStep());
227
+		if (! $this->form_steps->setCurrent($current_step_slug)) {
228
+			throw new InvalidIdentifierException(
229
+				$current_step_slug,
230
+				$this->defaultFormStep(),
231
+				$message = sprintf(
232
+					esc_html__(
233
+						'The "%1$s" form step could not be set.',
234
+						'event_espresso'
235
+					),
236
+					$current_step_slug
237
+				)
238
+			);
239
+		}
240
+	}
241
+
242
+
243
+
244
+	/**
245
+	 * @return object|SequentialStepFormInterface
246
+	 * @throws InvalidFormHandlerException
247
+	 */
248
+	public function getCurrentStep()
249
+	{
250
+		if (! $this->form_steps->current() instanceof SequentialStepForm) {
251
+			throw new InvalidFormHandlerException($this->form_steps->current());
252
+		}
253
+		return $this->form_steps->current();
254
+	}
255
+
256
+
257
+
258
+	/**
259
+	 * @return string
260
+	 * @throws InvalidFormHandlerException
261
+	 */
262
+	public function formAction()
263
+	{
264
+		if (! is_string($this->form_action) || empty($this->form_action)) {
265
+			$this->form_action = $this->baseUrl();
266
+		}
267
+		return $this->form_action;
268
+	}
269
+
270
+
271
+
272
+	/**
273
+	 * @param string $form_action
274
+	 * @throws InvalidDataTypeException
275
+	 */
276
+	public function setFormAction($form_action)
277
+	{
278
+		if (! is_string($form_action)) {
279
+			throw new InvalidDataTypeException('$form_action', $form_action, 'string');
280
+		}
281
+		$this->form_action = $form_action;
282
+	}
283
+
284
+
285
+
286
+	/**
287
+	 * @param array $form_action_args
288
+	 * @throws InvalidDataTypeException
289
+	 * @throws InvalidFormHandlerException
290
+	 */
291
+	public function addFormActionArgs($form_action_args = array())
292
+	{
293
+		if (! is_array($form_action_args)) {
294
+			throw new InvalidDataTypeException('$form_action_args', $form_action_args, 'array');
295
+		}
296
+		$form_action_args = ! empty($form_action_args)
297
+			? $form_action_args
298
+			: array($this->formStepUrlKey() => $this->form_steps->current()->slug());
299
+		$this->getCurrentStep()->setFormAction(
300
+			add_query_arg($form_action_args, $this->formAction())
301
+		);
302
+		$this->form_action = $this->getCurrentStep()->formAction();
303
+	}
304
+
305
+
306
+
307
+	/**
308
+	 * @return string
309
+	 */
310
+	public function formConfig()
311
+	{
312
+		return $this->form_config;
313
+	}
314
+
315
+
316
+
317
+	/**
318
+	 * @param string $form_config
319
+	 */
320
+	public function setFormConfig($form_config)
321
+	{
322
+		$this->form_config = $form_config;
323
+	}
324
+
325
+
326
+
327
+	/**
328
+	 * @return string
329
+	 */
330
+	public function progressStepStyle()
331
+	{
332
+		return $this->progress_step_style;
333
+	}
334
+
335
+
336
+
337
+	/**
338
+	 * @param string $progress_step_style
339
+	 */
340
+	public function setProgressStepStyle($progress_step_style)
341
+	{
342
+		$this->progress_step_style = $progress_step_style;
343
+	}
344
+
345
+
346
+
347
+	/**
348
+	 * @return EE_Request
349
+	 */
350
+	public function request()
351
+	{
352
+		return $this->request;
353
+	}
354
+
355
+
356
+
357
+	/**
358
+	 * @return Collection|null
359
+	 * @throws InvalidInterfaceException
360
+	 */
361
+	protected function getProgressStepsCollection()
362
+	{
363
+		static $collection = null;
364
+		if (! $collection instanceof ProgressStepCollection) {
365
+			$collection = new ProgressStepCollection();
366
+		}
367
+		return $collection;
368
+	}
369
+
370
+
371
+
372
+	/**
373
+	 * @param Collection $progress_steps_collection
374
+	 * @return ProgressStepManager
375
+	 * @throws InvalidInterfaceException
376
+	 * @throws InvalidClassException
377
+	 * @throws InvalidDataTypeException
378
+	 * @throws InvalidEntityException
379
+	 * @throws InvalidFormHandlerException
380
+	 */
381
+	protected function generateProgressSteps(Collection $progress_steps_collection)
382
+	{
383
+		$current_step = $this->getCurrentStep();
384
+		/** @var SequentialStepForm $form_step */
385
+		foreach ($this->form_steps as $form_step) {
386
+			// is this step active ?
387
+			if (! $form_step->initialize()) {
388
+				continue;
389
+			}
390
+			$progress_steps_collection->add(
391
+				new ProgressStep(
392
+					$form_step->order(),
393
+					$form_step->slug(),
394
+					$form_step->slug(),
395
+					$form_step->formName()
396
+				),
397
+				$form_step->slug()
398
+			);
399
+		}
400
+		// set collection pointer back to current step
401
+		$this->form_steps->setCurrentUsingObject($current_step);
402
+		return new ProgressStepManager(
403
+			$this->progressStepStyle(),
404
+			$this->defaultFormStep(),
405
+			$this->formStepUrlKey(),
406
+			$progress_steps_collection
407
+		);
408
+	}
409
+
410
+
411
+
412
+	/**
413
+	 * @throws InvalidClassException
414
+	 * @throws InvalidDataTypeException
415
+	 * @throws InvalidEntityException
416
+	 * @throws InvalidIdentifierException
417
+	 * @throws InvalidInterfaceException
418
+	 * @throws InvalidArgumentException
419
+	 * @throws InvalidFormHandlerException
420
+	 */
421
+	public function buildForm()
422
+	{
423
+		$this->buildCurrentStepFormForDisplay();
424
+	}
425
+
426
+
427
+
428
+	/**
429
+	 * @param array $form_data
430
+	 * @throws InvalidArgumentException
431
+	 * @throws InvalidClassException
432
+	 * @throws InvalidDataTypeException
433
+	 * @throws InvalidEntityException
434
+	 * @throws InvalidFormHandlerException
435
+	 * @throws InvalidIdentifierException
436
+	 * @throws InvalidInterfaceException
437
+	 */
438
+	public function processForm($form_data = array())
439
+	{
440
+		$this->buildCurrentStepFormForProcessing();
441
+		$this->processCurrentStepForm($form_data);
442
+	}
443
+
444
+
445
+
446
+	/**
447
+	 * @throws InvalidClassException
448
+	 * @throws InvalidDataTypeException
449
+	 * @throws InvalidEntityException
450
+	 * @throws InvalidInterfaceException
451
+	 * @throws InvalidIdentifierException
452
+	 * @throws InvalidArgumentException
453
+	 * @throws InvalidFormHandlerException
454
+	 */
455
+	public function buildCurrentStepFormForDisplay()
456
+	{
457
+		$form_step = $this->buildCurrentStepForm();
458
+		// no displayable content ? then skip straight to processing
459
+		if (! $form_step->displayable()) {
460
+			$this->addFormActionArgs();
461
+			$form_step->setFormAction($this->formAction());
462
+			wp_safe_redirect($form_step->formAction());
463
+		}
464
+	}
465
+
466
+
467
+
468
+	/**
469
+	 * @throws InvalidClassException
470
+	 * @throws InvalidDataTypeException
471
+	 * @throws InvalidEntityException
472
+	 * @throws InvalidInterfaceException
473
+	 * @throws InvalidIdentifierException
474
+	 * @throws InvalidArgumentException
475
+	 * @throws InvalidFormHandlerException
476
+	 */
477
+	public function buildCurrentStepFormForProcessing()
478
+	{
479
+		$this->buildCurrentStepForm(false);
480
+	}
481
+
482
+
483
+
484
+	/**
485
+	 * @param bool $for_display
486
+	 * @return SequentialStepFormInterface
487
+	 * @throws InvalidArgumentException
488
+	 * @throws InvalidClassException
489
+	 * @throws InvalidDataTypeException
490
+	 * @throws InvalidEntityException
491
+	 * @throws InvalidFormHandlerException
492
+	 * @throws InvalidIdentifierException
493
+	 * @throws InvalidInterfaceException
494
+	 */
495
+	private function buildCurrentStepForm($for_display = true)
496
+	{
497
+		$this->form_steps = $this->getFormStepsCollection();
498
+		$this->setCurrentStepFromRequest();
499
+		$form_step = $this->getCurrentStep();
500
+		if ($form_step->submitBtnText() === esc_html__('Submit', 'event_espresso')) {
501
+			$form_step->setSubmitBtnText(esc_html__('Next Step', 'event_espresso'));
502
+		}
503
+		if ($for_display && $form_step->displayable()) {
504
+			$this->progress_step_manager = $this->generateProgressSteps(
505
+				$this->getProgressStepsCollection()
506
+			);
507
+			$this->progress_step_manager->setCurrentStep(
508
+				$form_step->slug()
509
+			);
510
+			// mark all previous progress steps as completed
511
+			$this->progress_step_manager->setPreviousStepsCompleted();
512
+			$this->progress_step_manager->enqueueStylesAndScripts();
513
+			$this->addFormActionArgs();
514
+			$form_step->setFormAction($this->formAction());
515
+		} else {
516
+			$form_step->setRedirectUrl($this->baseUrl());
517
+			$form_step->addRedirectArgs(
518
+				array($this->formStepUrlKey() => $this->form_steps->current()->slug())
519
+			);
520
+		}
521
+		$form_step->generate();
522
+		if ($for_display) {
523
+			$form_step->enqueueStylesAndScripts();
524
+		}
525
+		return $form_step;
526
+	}
527
+
528
+
529
+
530
+	/**
531
+	 * @param bool $return_as_string
532
+	 * @return string
533
+	 * @throws InvalidFormHandlerException
534
+	 */
535
+	public function displayProgressSteps($return_as_string = true)
536
+	{
537
+		$form_step = $this->getCurrentStep();
538
+		if (! $form_step->displayable()) {
539
+			return '';
540
+		}
541
+		$progress_steps = apply_filters(
542
+			'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_SequentialStepFormManager__displayProgressSteps__before_steps',
543
+			''
544
+		);
545
+		$progress_steps .= $this->progress_step_manager->displaySteps();
546
+		$progress_steps .= apply_filters(
547
+			'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_SequentialStepFormManager__displayProgressSteps__after_steps',
548
+			''
549
+		);
550
+		if ($return_as_string) {
551
+			return $progress_steps;
552
+		}
553
+		echo $progress_steps;
554
+		return '';
555
+	}
556
+
557
+
558
+
559
+	/**
560
+	 * @param bool $return_as_string
561
+	 * @return string
562
+	 * @throws InvalidFormHandlerException
563
+	 */
564
+	public function displayCurrentStepForm($return_as_string = true)
565
+	{
566
+		if ($return_as_string) {
567
+			return $this->getCurrentStep()->display();
568
+		}
569
+		echo $this->getCurrentStep()->display();
570
+		return '';
571
+	}
572
+
573
+
574
+
575
+	/**
576
+	 * @param array $form_data
577
+	 * @return void
578
+	 * @throws InvalidArgumentException
579
+	 * @throws InvalidDataTypeException
580
+	 * @throws InvalidFormHandlerException
581
+	 */
582
+	public function processCurrentStepForm($form_data = array())
583
+	{
584
+		// grab instance of current step because after calling next() below,
585
+		// any calls to getCurrentStep() will return the "next" step because we advanced
586
+		$current_step = $this->getCurrentStep();
587
+		try {
588
+			// form processing should either throw exceptions or return true
589
+			$current_step->process($form_data);
590
+		} catch (Exception $e) {
591
+			// something went wrong, so...
592
+			// if WP_DEBUG === true, display the Exception and stack trace right now
593
+			new ExceptionStackTraceDisplay($e);
594
+			// else convert the Exception to an EE_Error
595
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
596
+			// prevent redirect to next step or other if exception was thrown
597
+			if (
598
+				$current_step->redirectTo() === SequentialStepForm::REDIRECT_TO_NEXT_STEP
599
+				|| $current_step->redirectTo() === SequentialStepForm::REDIRECT_TO_OTHER
600
+			) {
601
+				$current_step->setRedirectTo(SequentialStepForm::REDIRECT_TO_CURRENT_STEP);
602
+			}
603
+		}
604
+		// save notices to a transient so that when we redirect back
605
+		// to the display portion for this step
606
+		// those notices can be displayed
607
+		EE_Error::get_notices(false, true);
608
+		$this->redirectForm($current_step);
609
+	}
610
+
611
+
612
+
613
+	/**
614
+	 * handles where to go to next
615
+	 *
616
+	 * @param SequentialStepFormInterface $current_step
617
+	 * @throws InvalidArgumentException
618
+	 * @throws InvalidDataTypeException
619
+	 * @throws InvalidFormHandlerException
620
+	 */
621
+	public function redirectForm(SequentialStepFormInterface $current_step)
622
+	{
623
+		$redirect_step = $current_step;
624
+		switch ($current_step->redirectTo()) {
625
+			case SequentialStepForm::REDIRECT_TO_OTHER:
626
+				// going somewhere else, so just check out now
627
+				wp_safe_redirect($redirect_step->redirectUrl());
628
+				exit();
629
+				break;
630
+			case SequentialStepForm::REDIRECT_TO_PREV_STEP:
631
+				$redirect_step = $this->form_steps->previous();
632
+				break;
633
+			case SequentialStepForm::REDIRECT_TO_NEXT_STEP:
634
+				$this->form_steps->next();
635
+				if ($this->form_steps->valid()) {
636
+					$redirect_step = $this->form_steps->current();
637
+				}
638
+				break;
639
+			case SequentialStepForm::REDIRECT_TO_CURRENT_STEP:
640
+			default :
641
+				// $redirect_step is already set
642
+		}
643
+		$current_step->setRedirectUrl($this->baseUrl());
644
+		$current_step->addRedirectArgs(
645
+		// use the slug for whatever step we are redirecting too
646
+			array($this->formStepUrlKey() => $redirect_step->slug())
647
+		);
648
+		wp_safe_redirect($current_step->redirectUrl());
649
+		exit();
650
+	}
651 651
 
652 652
 
653 653
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
 use Exception;
18 18
 use InvalidArgumentException;
19 19
 
20
-if (! defined('EVENT_ESPRESSO_VERSION')) {
20
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
21 21
     exit('No direct script access allowed');
22 22
 }
23 23
 
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
      */
152 152
     protected function setBaseUrl($base_url)
153 153
     {
154
-        if (! is_string($base_url)) {
154
+        if ( ! is_string($base_url)) {
155 155
             throw new InvalidDataTypeException('$base_url', $base_url, 'string');
156 156
         }
157 157
         if (empty($base_url)) {
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
      */
185 185
     public function setFormStepUrlKey($form_step_url_key = 'ee-form-step')
186 186
     {
187
-        if (! is_string($form_step_url_key)) {
187
+        if ( ! is_string($form_step_url_key)) {
188 188
             throw new InvalidDataTypeException('$form_step_key', $form_step_url_key, 'string');
189 189
         }
190 190
         $this->form_step_url_key = ! empty($form_step_url_key) ? $form_step_url_key : 'ee-form-step';
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
      */
209 209
     protected function setDefaultFormStep($default_form_step)
210 210
     {
211
-        if (! is_string($default_form_step)) {
211
+        if ( ! is_string($default_form_step)) {
212 212
             throw new InvalidDataTypeException('$default_form_step', $default_form_step, 'string');
213 213
         }
214 214
         $this->default_form_step = $default_form_step;
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
     protected function setCurrentStepFromRequest()
225 225
     {
226 226
         $current_step_slug = $this->request()->get($this->formStepUrlKey(), $this->defaultFormStep());
227
-        if (! $this->form_steps->setCurrent($current_step_slug)) {
227
+        if ( ! $this->form_steps->setCurrent($current_step_slug)) {
228 228
             throw new InvalidIdentifierException(
229 229
                 $current_step_slug,
230 230
                 $this->defaultFormStep(),
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
      */
248 248
     public function getCurrentStep()
249 249
     {
250
-        if (! $this->form_steps->current() instanceof SequentialStepForm) {
250
+        if ( ! $this->form_steps->current() instanceof SequentialStepForm) {
251 251
             throw new InvalidFormHandlerException($this->form_steps->current());
252 252
         }
253 253
         return $this->form_steps->current();
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
      */
262 262
     public function formAction()
263 263
     {
264
-        if (! is_string($this->form_action) || empty($this->form_action)) {
264
+        if ( ! is_string($this->form_action) || empty($this->form_action)) {
265 265
             $this->form_action = $this->baseUrl();
266 266
         }
267 267
         return $this->form_action;
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
      */
276 276
     public function setFormAction($form_action)
277 277
     {
278
-        if (! is_string($form_action)) {
278
+        if ( ! is_string($form_action)) {
279 279
             throw new InvalidDataTypeException('$form_action', $form_action, 'string');
280 280
         }
281 281
         $this->form_action = $form_action;
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
      */
291 291
     public function addFormActionArgs($form_action_args = array())
292 292
     {
293
-        if (! is_array($form_action_args)) {
293
+        if ( ! is_array($form_action_args)) {
294 294
             throw new InvalidDataTypeException('$form_action_args', $form_action_args, 'array');
295 295
         }
296 296
         $form_action_args = ! empty($form_action_args)
@@ -361,7 +361,7 @@  discard block
 block discarded – undo
361 361
     protected function getProgressStepsCollection()
362 362
     {
363 363
         static $collection = null;
364
-        if (! $collection instanceof ProgressStepCollection) {
364
+        if ( ! $collection instanceof ProgressStepCollection) {
365 365
             $collection = new ProgressStepCollection();
366 366
         }
367 367
         return $collection;
@@ -384,7 +384,7 @@  discard block
 block discarded – undo
384 384
         /** @var SequentialStepForm $form_step */
385 385
         foreach ($this->form_steps as $form_step) {
386 386
             // is this step active ?
387
-            if (! $form_step->initialize()) {
387
+            if ( ! $form_step->initialize()) {
388 388
                 continue;
389 389
             }
390 390
             $progress_steps_collection->add(
@@ -456,7 +456,7 @@  discard block
 block discarded – undo
456 456
     {
457 457
         $form_step = $this->buildCurrentStepForm();
458 458
         // no displayable content ? then skip straight to processing
459
-        if (! $form_step->displayable()) {
459
+        if ( ! $form_step->displayable()) {
460 460
             $this->addFormActionArgs();
461 461
             $form_step->setFormAction($this->formAction());
462 462
             wp_safe_redirect($form_step->formAction());
@@ -535,7 +535,7 @@  discard block
 block discarded – undo
535 535
     public function displayProgressSteps($return_as_string = true)
536 536
     {
537 537
         $form_step = $this->getCurrentStep();
538
-        if (! $form_step->displayable()) {
538
+        if ( ! $form_step->displayable()) {
539 539
             return '';
540 540
         }
541 541
         $progress_steps = apply_filters(
Please login to merge, or discard this patch.
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
 
204 204
 
205 205
     /**
206
-     * @param $default_form_step
206
+     * @param string $default_form_step
207 207
      * @throws InvalidDataTypeException
208 208
      */
209 209
     protected function setDefaultFormStep($default_form_step)
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
 
243 243
 
244 244
     /**
245
-     * @return object|SequentialStepFormInterface
245
+     * @return SequentialStepForm
246 246
      * @throws InvalidFormHandlerException
247 247
      */
248 248
     public function getCurrentStep()
Please login to merge, or discard this patch.
core/libraries/form_sections/form_handlers/FormHandler.php 2 patches
Indentation   +633 added lines, -633 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
 use EventEspresso\core\exceptions\InvalidFormSubmissionException;
13 13
 
14 14
 if (! defined('EVENT_ESPRESSO_VERSION')) {
15
-    exit('No direct script access allowed');
15
+	exit('No direct script access allowed');
16 16
 }
17 17
 
18 18
 
@@ -31,638 +31,638 @@  discard block
 block discarded – undo
31 31
 abstract class FormHandler implements FormHandlerInterface
32 32
 {
33 33
 
34
-    /**
35
-     * will add opening and closing HTML form tags as well as a submit button
36
-     */
37
-    const ADD_FORM_TAGS_AND_SUBMIT = 'add_form_tags_and_submit';
38
-
39
-    /**
40
-     * will add opening and closing HTML form tags but NOT a submit button
41
-     */
42
-    const ADD_FORM_TAGS_ONLY = 'add_form_tags_only';
43
-
44
-    /**
45
-     * will NOT add opening and closing HTML form tags but will add a submit button
46
-     */
47
-    const ADD_FORM_SUBMIT_ONLY = 'add_form_submit_only';
48
-
49
-    /**
50
-     * will NOT add opening and closing HTML form tags NOR a submit button
51
-     */
52
-    const DO_NOT_SETUP_FORM = 'do_not_setup_form';
53
-
54
-    /**
55
-     * if set to false, then this form has no displayable content,
56
-     * and will only be used for processing data sent passed via GET or POST
57
-     * defaults to true ( ie: form has displayable content )
58
-     *
59
-     * @var boolean $displayable
60
-     */
61
-    private $displayable = true;
62
-
63
-    /**
64
-     * @var string $form_name
65
-     */
66
-    private $form_name;
67
-
68
-    /**
69
-     * @var string $admin_name
70
-     */
71
-    private $admin_name;
72
-
73
-    /**
74
-     * @var string $slug
75
-     */
76
-    private $slug;
77
-
78
-    /**
79
-     * @var string $submit_btn_text
80
-     */
81
-    private $submit_btn_text;
82
-
83
-    /**
84
-     * @var string $form_action
85
-     */
86
-    private $form_action;
87
-
88
-    /**
89
-     * form params in key value pairs
90
-     * can be added to form action URL or as hidden inputs
91
-     *
92
-     * @var array $form_args
93
-     */
94
-    private $form_args = array();
95
-
96
-    /**
97
-     * value of one of the string constant above
98
-     *
99
-     * @var string $form_config
100
-     */
101
-    private $form_config;
102
-
103
-    /**
104
-     * whether or not the form was determined to be invalid
105
-     *
106
-     * @var boolean $form_has_errors
107
-     */
108
-    private $form_has_errors;
109
-
110
-    /**
111
-     * the absolute top level form section being used on the page
112
-     *
113
-     * @var \EE_Form_Section_Proper $form
114
-     */
115
-    private $form;
116
-
117
-    /**
118
-     * @var \EE_Registry $registry
119
-     */
120
-    protected $registry;
121
-
122
-
123
-
124
-    /**
125
-     * Form constructor.
126
-     *
127
-     * @param string       $form_name
128
-     * @param string       $admin_name
129
-     * @param string       $slug
130
-     * @param string       $form_action
131
-     * @param string       $form_config
132
-     * @param \EE_Registry $registry
133
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
134
-     * @throws \DomainException
135
-     * @throws \InvalidArgumentException
136
-     */
137
-    public function __construct(
138
-        $form_name,
139
-        $admin_name,
140
-        $slug,
141
-        $form_action = '',
142
-        $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
143
-        \EE_Registry $registry
144
-    ) {
145
-        $this->setFormName($form_name);
146
-        $this->setAdminName($admin_name);
147
-        $this->setSlug($slug);
148
-        $this->setFormAction($form_action);
149
-        $this->setFormConfig($form_config);
150
-        $this->setSubmitBtnText(esc_html__('Submit', 'event_espresso'));
151
-        $this->registry = $registry;
152
-    }
153
-
154
-
155
-
156
-    /**
157
-     * @return array
158
-     */
159
-    public static function getFormConfigConstants()
160
-    {
161
-        return array(
162
-            FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
163
-            FormHandler::ADD_FORM_TAGS_ONLY,
164
-            FormHandler::ADD_FORM_SUBMIT_ONLY,
165
-            FormHandler::DO_NOT_SETUP_FORM,
166
-        );
167
-    }
168
-
169
-
170
-
171
-    /**
172
-     * @param bool $for_display
173
-     * @return \EE_Form_Section_Proper
174
-     * @throws \EE_Error
175
-     * @throws \LogicException
176
-     */
177
-    public function form($for_display = false)
178
-    {
179
-        if (! $this->formIsValid()) {
180
-            return null;
181
-        }
182
-        if ($for_display) {
183
-            $form_config = $this->formConfig();
184
-            if (
185
-                $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
186
-                || $form_config === FormHandler::ADD_FORM_SUBMIT_ONLY
187
-            ) {
188
-                $this->appendSubmitButton();
189
-                $this->clearFormButtonFloats();
190
-            }
191
-        }
192
-        return $this->form;
193
-    }
194
-
195
-
196
-
197
-    /**
198
-     * @return boolean
199
-     * @throws LogicException
200
-     */
201
-    public function formIsValid()
202
-    {
203
-        if (! $this->form instanceof \EE_Form_Section_Proper) {
204
-            static $generated = false;
205
-            if (! $generated) {
206
-                $generated = true;
207
-                $form = $this->generate();
208
-                if ($form instanceof \EE_Form_Section_Proper) {
209
-                    $this->setForm($form);
210
-                }
211
-            }
212
-            return $this->verifyForm();
213
-        }
214
-        return true;
215
-    }
216
-
217
-
218
-
219
-    /**
220
-     * @return boolean
221
-     * @throws LogicException
222
-     */
223
-    public function verifyForm()
224
-    {
225
-        if ($this->form instanceof \EE_Form_Section_Proper) {
226
-            return true;
227
-        }
228
-        throw new LogicException(
229
-            sprintf(
230
-                esc_html__('The "%1$s" form is invalid or missing', 'event_espresso'),
231
-                $this->form_name
232
-            )
233
-        );
234
-    }
235
-
236
-
237
-
238
-    /**
239
-     * @param \EE_Form_Section_Proper $form
240
-     */
241
-    public function setForm(\EE_Form_Section_Proper $form)
242
-    {
243
-        $this->form = $form;
244
-    }
245
-
246
-
247
-
248
-    /**
249
-     * @return boolean
250
-     */
251
-    public function displayable()
252
-    {
253
-        return $this->displayable;
254
-    }
255
-
256
-
257
-
258
-    /**
259
-     * @param boolean $displayable
260
-     */
261
-    public function setDisplayable($displayable = false)
262
-    {
263
-        $this->displayable = filter_var($displayable, FILTER_VALIDATE_BOOLEAN);
264
-    }
265
-
266
-
267
-
268
-    /**
269
-     * a public name for the form that can be displayed on the frontend of a site
270
-     *
271
-     * @return string
272
-     */
273
-    public function formName()
274
-    {
275
-        return $this->form_name;
276
-    }
277
-
278
-
279
-
280
-    /**
281
-     * @param string $form_name
282
-     * @throws InvalidDataTypeException
283
-     */
284
-    public function setFormName($form_name)
285
-    {
286
-        if (! is_string($form_name)) {
287
-            throw new InvalidDataTypeException('$form_name', $form_name, 'string');
288
-        }
289
-        $this->form_name = $form_name;
290
-    }
291
-
292
-
293
-
294
-    /**
295
-     * a public name for the form that can be displayed, but only in the admin
296
-     *
297
-     * @return string
298
-     */
299
-    public function adminName()
300
-    {
301
-        return $this->admin_name;
302
-    }
303
-
304
-
305
-
306
-    /**
307
-     * @param string $admin_name
308
-     * @throws InvalidDataTypeException
309
-     */
310
-    public function setAdminName($admin_name)
311
-    {
312
-        if (! is_string($admin_name)) {
313
-            throw new InvalidDataTypeException('$admin_name', $admin_name, 'string');
314
-        }
315
-        $this->admin_name = $admin_name;
316
-    }
317
-
318
-
319
-
320
-    /**
321
-     * a URL friendly string that can be used for identifying the form
322
-     *
323
-     * @return string
324
-     */
325
-    public function slug()
326
-    {
327
-        return $this->slug;
328
-    }
329
-
330
-
331
-
332
-    /**
333
-     * @param string $slug
334
-     * @throws InvalidDataTypeException
335
-     */
336
-    public function setSlug($slug)
337
-    {
338
-        if (! is_string($slug)) {
339
-            throw new InvalidDataTypeException('$slug', $slug, 'string');
340
-        }
341
-        $this->slug = $slug;
342
-    }
343
-
344
-
345
-
346
-    /**
347
-     * @return string
348
-     */
349
-    public function submitBtnText()
350
-    {
351
-        return $this->submit_btn_text;
352
-    }
353
-
354
-
355
-
356
-    /**
357
-     * @param string $submit_btn_text
358
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
359
-     * @throws \InvalidArgumentException
360
-     */
361
-    public function setSubmitBtnText($submit_btn_text)
362
-    {
363
-        if (! is_string($submit_btn_text)) {
364
-            throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string');
365
-        }
366
-        if (empty($submit_btn_text)) {
367
-            throw new InvalidArgumentException(
368
-                esc_html__('Can not set Submit button text because an empty string was provided.', 'event_espresso')
369
-            );
370
-        }
371
-        $this->submit_btn_text = $submit_btn_text;
372
-    }
373
-
374
-
375
-
376
-    /**
377
-     * @return string
378
-     */
379
-    public function formAction()
380
-    {
381
-        return ! empty($this->form_args)
382
-            ? add_query_arg($this->form_args, $this->form_action)
383
-            : $this->form_action;
384
-    }
385
-
386
-
387
-
388
-    /**
389
-     * @param string $form_action
390
-     * @throws InvalidDataTypeException
391
-     */
392
-    public function setFormAction($form_action)
393
-    {
394
-        if (! is_string($form_action)) {
395
-            throw new InvalidDataTypeException('$form_action', $form_action, 'string');
396
-        }
397
-        $this->form_action = $form_action;
398
-    }
399
-
400
-
401
-
402
-    /**
403
-     * @param array $form_args
404
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
405
-     * @throws \InvalidArgumentException
406
-     */
407
-    public function addFormActionArgs($form_args = array())
408
-    {
409
-        if (is_object($form_args)) {
410
-            throw new InvalidDataTypeException(
411
-                '$form_args',
412
-                $form_args,
413
-                'anything other than an object was expected.'
414
-            );
415
-        }
416
-        if (empty($form_args)) {
417
-            throw new InvalidArgumentException(
418
-                esc_html__('The redirect arguments can not be an empty array.', 'event_espresso')
419
-            );
420
-        }
421
-        $this->form_args = array_merge($this->form_args, $form_args);
422
-    }
423
-
424
-
425
-
426
-    /**
427
-     * @return string
428
-     */
429
-    public function formConfig()
430
-    {
431
-        return $this->form_config;
432
-    }
433
-
434
-
435
-
436
-    /**
437
-     * @param string $form_config
438
-     * @throws DomainException
439
-     */
440
-    public function setFormConfig($form_config)
441
-    {
442
-        if (
443
-        ! in_array(
444
-            $form_config,
445
-            array(
446
-                FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
447
-                FormHandler::ADD_FORM_TAGS_ONLY,
448
-                FormHandler::ADD_FORM_SUBMIT_ONLY,
449
-                FormHandler::DO_NOT_SETUP_FORM,
450
-            ),
451
-            true
452
-        )
453
-        ) {
454
-            throw new DomainException(
455
-                sprintf(
456
-                    esc_html__('"%1$s" is not a valid value for the form config. Please use one of the class constants on \EventEspresso\core\libraries\form_sections\form_handlers\Form',
457
-                        'event_espresso'),
458
-                    $form_config
459
-                )
460
-            );
461
-        }
462
-        $this->form_config = $form_config;
463
-    }
464
-
465
-
466
-
467
-    /**
468
-     * called after the form is instantiated
469
-     * and used for performing any logic that needs to occur early
470
-     * before any of the other methods are called.
471
-     * returns true if everything is ok to proceed,
472
-     * and false if no further form logic should be implemented
473
-     *
474
-     * @return boolean
475
-     */
476
-    public function initialize()
477
-    {
478
-        $this->form_has_errors = \EE_Error::has_error(true);
479
-        return true;
480
-    }
481
-
482
-
483
-
484
-    /**
485
-     * used for setting up css and js
486
-     *
487
-     * @return void
488
-     * @throws LogicException
489
-     * @throws \EE_Error
490
-     */
491
-    public function enqueueStylesAndScripts()
492
-    {
493
-        $this->form(false)->enqueue_js();
494
-    }
495
-
496
-
497
-
498
-    /**
499
-     * creates and returns the actual form
500
-     *
501
-     * @return EE_Form_Section_Proper
502
-     */
503
-    abstract public function generate();
504
-
505
-
506
-
507
-    /**
508
-     * creates and returns an EE_Submit_Input labeled "Submit"
509
-     *
510
-     * @param string $text
511
-     * @return \EE_Submit_Input
512
-     */
513
-    public function generateSubmitButton($text = '')
514
-    {
515
-        $text = ! empty($text) ? $text : $this->submitBtnText();
516
-        return new EE_Submit_Input(
517
-            array(
518
-                'html_name'             => 'ee-form-submit-' . $this->slug(),
519
-                'html_id'               => 'ee-form-submit-' . $this->slug(),
520
-                'html_class'            => 'ee-form-submit',
521
-                'html_label'            => '&nbsp;',
522
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
523
-                'default'               => $text,
524
-            )
525
-        );
526
-    }
527
-
528
-
529
-
530
-    /**
531
-     * calls generateSubmitButton() and appends it onto the form along with a float clearing div
532
-     *
533
-     * @param string $text
534
-     * @return void
535
-     * @throws \LogicException
536
-     * @throws \EE_Error
537
-     */
538
-    public function appendSubmitButton($text = '')
539
-    {
540
-        if ($this->form->subsection_exists($this->slug() . '-submit-btn')) {
541
-            return;
542
-        }
543
-        $this->form->add_subsections(
544
-            array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)),
545
-            null,
546
-            false
547
-        );
548
-    }
549
-
550
-
551
-
552
-    /**
553
-     * creates and returns an EE_Submit_Input labeled "Cancel"
554
-     *
555
-     * @param string $text
556
-     * @return \EE_Submit_Input
557
-     */
558
-    public function generateCancelButton($text = '')
559
-    {
560
-        $cancel_button = new EE_Submit_Input(
561
-            array(
562
-                'html_name'             => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!!
563
-                'html_id'               => 'ee-cancel-form-' . $this->slug(),
564
-                'html_class'            => 'ee-cancel-form',
565
-                'html_label'            => '&nbsp;',
566
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
567
-                'default'               => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'),
568
-            )
569
-        );
570
-        $cancel_button->set_button_css_attributes(false);
571
-        return $cancel_button;
572
-    }
573
-
574
-
575
-
576
-    /**
577
-     * appends a float clearing div onto end of form
578
-     *
579
-     * @return void
580
-     * @throws \EE_Error
581
-     */
582
-    public function clearFormButtonFloats()
583
-    {
584
-        $this->form->add_subsections(
585
-            array(
586
-                'clear-submit-btn-float' => new \EE_Form_Section_HTML(
587
-                    EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx()
588
-                ),
589
-            ),
590
-            null,
591
-            false
592
-        );
593
-    }
594
-
595
-
596
-
597
-    /**
598
-     * takes the generated form and displays it along with ony other non-form HTML that may be required
599
-     * returns a string of HTML that can be directly echoed in a template
600
-     *
601
-     * @return string
602
-     * @throws LogicException
603
-     * @throws \EE_Error
604
-     */
605
-    public function display()
606
-    {
607
-        $form_html = apply_filters(
608
-            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form',
609
-            ''
610
-        );
611
-        $form_config = $this->formConfig();
612
-        if (
613
-            $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
614
-            || $form_config === FormHandler::ADD_FORM_TAGS_ONLY
615
-        ) {
616
-            $form_html .= $this->form()->form_open($this->formAction());
617
-        }
618
-        $form_html .= $this->form(true)->get_html($this->form_has_errors);
619
-        if (
620
-            $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
621
-            || $form_config === FormHandler::ADD_FORM_TAGS_ONLY
622
-        ) {
623
-            $form_html .= $this->form()->form_close();
624
-        }
625
-        $form_html .= apply_filters(
626
-            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__after_form',
627
-            ''
628
-        );
629
-        return $form_html;
630
-    }
631
-
632
-
633
-
634
-    /**
635
-     * handles processing the form submission
636
-     * returns true or false depending on whether the form was processed successfully or not
637
-     *
638
-     * @param array $submitted_form_data
639
-     * @return array
640
-     * @throws \EE_Error
641
-     * @throws \LogicException
642
-     * @throws InvalidFormSubmissionException
643
-     */
644
-    public function process($submitted_form_data = array())
645
-    {
646
-        if (! $this->form()->was_submitted($submitted_form_data)) {
647
-            throw new InvalidFormSubmissionException($this->form_name);
648
-        }
649
-        $this->form(true)->receive_form_submission($submitted_form_data);
650
-        if (! $this->form()->is_valid()) {
651
-            throw new InvalidFormSubmissionException(
652
-                $this->form_name,
653
-                sprintf(
654
-                    esc_html__(
655
-                        'The "%1$s" form is invalid. Please correct the following errors and resubmit: %2$s %3$s',
656
-                        'event_espresso'
657
-                    ),
658
-                    $this->form_name,
659
-                    '<br />',
660
-                    $this->form()->submission_error_message()
661
-                )
662
-            );
663
-        }
664
-        return $this->form()->valid_data();
665
-    }
34
+	/**
35
+	 * will add opening and closing HTML form tags as well as a submit button
36
+	 */
37
+	const ADD_FORM_TAGS_AND_SUBMIT = 'add_form_tags_and_submit';
38
+
39
+	/**
40
+	 * will add opening and closing HTML form tags but NOT a submit button
41
+	 */
42
+	const ADD_FORM_TAGS_ONLY = 'add_form_tags_only';
43
+
44
+	/**
45
+	 * will NOT add opening and closing HTML form tags but will add a submit button
46
+	 */
47
+	const ADD_FORM_SUBMIT_ONLY = 'add_form_submit_only';
48
+
49
+	/**
50
+	 * will NOT add opening and closing HTML form tags NOR a submit button
51
+	 */
52
+	const DO_NOT_SETUP_FORM = 'do_not_setup_form';
53
+
54
+	/**
55
+	 * if set to false, then this form has no displayable content,
56
+	 * and will only be used for processing data sent passed via GET or POST
57
+	 * defaults to true ( ie: form has displayable content )
58
+	 *
59
+	 * @var boolean $displayable
60
+	 */
61
+	private $displayable = true;
62
+
63
+	/**
64
+	 * @var string $form_name
65
+	 */
66
+	private $form_name;
67
+
68
+	/**
69
+	 * @var string $admin_name
70
+	 */
71
+	private $admin_name;
72
+
73
+	/**
74
+	 * @var string $slug
75
+	 */
76
+	private $slug;
77
+
78
+	/**
79
+	 * @var string $submit_btn_text
80
+	 */
81
+	private $submit_btn_text;
82
+
83
+	/**
84
+	 * @var string $form_action
85
+	 */
86
+	private $form_action;
87
+
88
+	/**
89
+	 * form params in key value pairs
90
+	 * can be added to form action URL or as hidden inputs
91
+	 *
92
+	 * @var array $form_args
93
+	 */
94
+	private $form_args = array();
95
+
96
+	/**
97
+	 * value of one of the string constant above
98
+	 *
99
+	 * @var string $form_config
100
+	 */
101
+	private $form_config;
102
+
103
+	/**
104
+	 * whether or not the form was determined to be invalid
105
+	 *
106
+	 * @var boolean $form_has_errors
107
+	 */
108
+	private $form_has_errors;
109
+
110
+	/**
111
+	 * the absolute top level form section being used on the page
112
+	 *
113
+	 * @var \EE_Form_Section_Proper $form
114
+	 */
115
+	private $form;
116
+
117
+	/**
118
+	 * @var \EE_Registry $registry
119
+	 */
120
+	protected $registry;
121
+
122
+
123
+
124
+	/**
125
+	 * Form constructor.
126
+	 *
127
+	 * @param string       $form_name
128
+	 * @param string       $admin_name
129
+	 * @param string       $slug
130
+	 * @param string       $form_action
131
+	 * @param string       $form_config
132
+	 * @param \EE_Registry $registry
133
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
134
+	 * @throws \DomainException
135
+	 * @throws \InvalidArgumentException
136
+	 */
137
+	public function __construct(
138
+		$form_name,
139
+		$admin_name,
140
+		$slug,
141
+		$form_action = '',
142
+		$form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
143
+		\EE_Registry $registry
144
+	) {
145
+		$this->setFormName($form_name);
146
+		$this->setAdminName($admin_name);
147
+		$this->setSlug($slug);
148
+		$this->setFormAction($form_action);
149
+		$this->setFormConfig($form_config);
150
+		$this->setSubmitBtnText(esc_html__('Submit', 'event_espresso'));
151
+		$this->registry = $registry;
152
+	}
153
+
154
+
155
+
156
+	/**
157
+	 * @return array
158
+	 */
159
+	public static function getFormConfigConstants()
160
+	{
161
+		return array(
162
+			FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
163
+			FormHandler::ADD_FORM_TAGS_ONLY,
164
+			FormHandler::ADD_FORM_SUBMIT_ONLY,
165
+			FormHandler::DO_NOT_SETUP_FORM,
166
+		);
167
+	}
168
+
169
+
170
+
171
+	/**
172
+	 * @param bool $for_display
173
+	 * @return \EE_Form_Section_Proper
174
+	 * @throws \EE_Error
175
+	 * @throws \LogicException
176
+	 */
177
+	public function form($for_display = false)
178
+	{
179
+		if (! $this->formIsValid()) {
180
+			return null;
181
+		}
182
+		if ($for_display) {
183
+			$form_config = $this->formConfig();
184
+			if (
185
+				$form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
186
+				|| $form_config === FormHandler::ADD_FORM_SUBMIT_ONLY
187
+			) {
188
+				$this->appendSubmitButton();
189
+				$this->clearFormButtonFloats();
190
+			}
191
+		}
192
+		return $this->form;
193
+	}
194
+
195
+
196
+
197
+	/**
198
+	 * @return boolean
199
+	 * @throws LogicException
200
+	 */
201
+	public function formIsValid()
202
+	{
203
+		if (! $this->form instanceof \EE_Form_Section_Proper) {
204
+			static $generated = false;
205
+			if (! $generated) {
206
+				$generated = true;
207
+				$form = $this->generate();
208
+				if ($form instanceof \EE_Form_Section_Proper) {
209
+					$this->setForm($form);
210
+				}
211
+			}
212
+			return $this->verifyForm();
213
+		}
214
+		return true;
215
+	}
216
+
217
+
218
+
219
+	/**
220
+	 * @return boolean
221
+	 * @throws LogicException
222
+	 */
223
+	public function verifyForm()
224
+	{
225
+		if ($this->form instanceof \EE_Form_Section_Proper) {
226
+			return true;
227
+		}
228
+		throw new LogicException(
229
+			sprintf(
230
+				esc_html__('The "%1$s" form is invalid or missing', 'event_espresso'),
231
+				$this->form_name
232
+			)
233
+		);
234
+	}
235
+
236
+
237
+
238
+	/**
239
+	 * @param \EE_Form_Section_Proper $form
240
+	 */
241
+	public function setForm(\EE_Form_Section_Proper $form)
242
+	{
243
+		$this->form = $form;
244
+	}
245
+
246
+
247
+
248
+	/**
249
+	 * @return boolean
250
+	 */
251
+	public function displayable()
252
+	{
253
+		return $this->displayable;
254
+	}
255
+
256
+
257
+
258
+	/**
259
+	 * @param boolean $displayable
260
+	 */
261
+	public function setDisplayable($displayable = false)
262
+	{
263
+		$this->displayable = filter_var($displayable, FILTER_VALIDATE_BOOLEAN);
264
+	}
265
+
266
+
267
+
268
+	/**
269
+	 * a public name for the form that can be displayed on the frontend of a site
270
+	 *
271
+	 * @return string
272
+	 */
273
+	public function formName()
274
+	{
275
+		return $this->form_name;
276
+	}
277
+
278
+
279
+
280
+	/**
281
+	 * @param string $form_name
282
+	 * @throws InvalidDataTypeException
283
+	 */
284
+	public function setFormName($form_name)
285
+	{
286
+		if (! is_string($form_name)) {
287
+			throw new InvalidDataTypeException('$form_name', $form_name, 'string');
288
+		}
289
+		$this->form_name = $form_name;
290
+	}
291
+
292
+
293
+
294
+	/**
295
+	 * a public name for the form that can be displayed, but only in the admin
296
+	 *
297
+	 * @return string
298
+	 */
299
+	public function adminName()
300
+	{
301
+		return $this->admin_name;
302
+	}
303
+
304
+
305
+
306
+	/**
307
+	 * @param string $admin_name
308
+	 * @throws InvalidDataTypeException
309
+	 */
310
+	public function setAdminName($admin_name)
311
+	{
312
+		if (! is_string($admin_name)) {
313
+			throw new InvalidDataTypeException('$admin_name', $admin_name, 'string');
314
+		}
315
+		$this->admin_name = $admin_name;
316
+	}
317
+
318
+
319
+
320
+	/**
321
+	 * a URL friendly string that can be used for identifying the form
322
+	 *
323
+	 * @return string
324
+	 */
325
+	public function slug()
326
+	{
327
+		return $this->slug;
328
+	}
329
+
330
+
331
+
332
+	/**
333
+	 * @param string $slug
334
+	 * @throws InvalidDataTypeException
335
+	 */
336
+	public function setSlug($slug)
337
+	{
338
+		if (! is_string($slug)) {
339
+			throw new InvalidDataTypeException('$slug', $slug, 'string');
340
+		}
341
+		$this->slug = $slug;
342
+	}
343
+
344
+
345
+
346
+	/**
347
+	 * @return string
348
+	 */
349
+	public function submitBtnText()
350
+	{
351
+		return $this->submit_btn_text;
352
+	}
353
+
354
+
355
+
356
+	/**
357
+	 * @param string $submit_btn_text
358
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
359
+	 * @throws \InvalidArgumentException
360
+	 */
361
+	public function setSubmitBtnText($submit_btn_text)
362
+	{
363
+		if (! is_string($submit_btn_text)) {
364
+			throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string');
365
+		}
366
+		if (empty($submit_btn_text)) {
367
+			throw new InvalidArgumentException(
368
+				esc_html__('Can not set Submit button text because an empty string was provided.', 'event_espresso')
369
+			);
370
+		}
371
+		$this->submit_btn_text = $submit_btn_text;
372
+	}
373
+
374
+
375
+
376
+	/**
377
+	 * @return string
378
+	 */
379
+	public function formAction()
380
+	{
381
+		return ! empty($this->form_args)
382
+			? add_query_arg($this->form_args, $this->form_action)
383
+			: $this->form_action;
384
+	}
385
+
386
+
387
+
388
+	/**
389
+	 * @param string $form_action
390
+	 * @throws InvalidDataTypeException
391
+	 */
392
+	public function setFormAction($form_action)
393
+	{
394
+		if (! is_string($form_action)) {
395
+			throw new InvalidDataTypeException('$form_action', $form_action, 'string');
396
+		}
397
+		$this->form_action = $form_action;
398
+	}
399
+
400
+
401
+
402
+	/**
403
+	 * @param array $form_args
404
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
405
+	 * @throws \InvalidArgumentException
406
+	 */
407
+	public function addFormActionArgs($form_args = array())
408
+	{
409
+		if (is_object($form_args)) {
410
+			throw new InvalidDataTypeException(
411
+				'$form_args',
412
+				$form_args,
413
+				'anything other than an object was expected.'
414
+			);
415
+		}
416
+		if (empty($form_args)) {
417
+			throw new InvalidArgumentException(
418
+				esc_html__('The redirect arguments can not be an empty array.', 'event_espresso')
419
+			);
420
+		}
421
+		$this->form_args = array_merge($this->form_args, $form_args);
422
+	}
423
+
424
+
425
+
426
+	/**
427
+	 * @return string
428
+	 */
429
+	public function formConfig()
430
+	{
431
+		return $this->form_config;
432
+	}
433
+
434
+
435
+
436
+	/**
437
+	 * @param string $form_config
438
+	 * @throws DomainException
439
+	 */
440
+	public function setFormConfig($form_config)
441
+	{
442
+		if (
443
+		! in_array(
444
+			$form_config,
445
+			array(
446
+				FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
447
+				FormHandler::ADD_FORM_TAGS_ONLY,
448
+				FormHandler::ADD_FORM_SUBMIT_ONLY,
449
+				FormHandler::DO_NOT_SETUP_FORM,
450
+			),
451
+			true
452
+		)
453
+		) {
454
+			throw new DomainException(
455
+				sprintf(
456
+					esc_html__('"%1$s" is not a valid value for the form config. Please use one of the class constants on \EventEspresso\core\libraries\form_sections\form_handlers\Form',
457
+						'event_espresso'),
458
+					$form_config
459
+				)
460
+			);
461
+		}
462
+		$this->form_config = $form_config;
463
+	}
464
+
465
+
466
+
467
+	/**
468
+	 * called after the form is instantiated
469
+	 * and used for performing any logic that needs to occur early
470
+	 * before any of the other methods are called.
471
+	 * returns true if everything is ok to proceed,
472
+	 * and false if no further form logic should be implemented
473
+	 *
474
+	 * @return boolean
475
+	 */
476
+	public function initialize()
477
+	{
478
+		$this->form_has_errors = \EE_Error::has_error(true);
479
+		return true;
480
+	}
481
+
482
+
483
+
484
+	/**
485
+	 * used for setting up css and js
486
+	 *
487
+	 * @return void
488
+	 * @throws LogicException
489
+	 * @throws \EE_Error
490
+	 */
491
+	public function enqueueStylesAndScripts()
492
+	{
493
+		$this->form(false)->enqueue_js();
494
+	}
495
+
496
+
497
+
498
+	/**
499
+	 * creates and returns the actual form
500
+	 *
501
+	 * @return EE_Form_Section_Proper
502
+	 */
503
+	abstract public function generate();
504
+
505
+
506
+
507
+	/**
508
+	 * creates and returns an EE_Submit_Input labeled "Submit"
509
+	 *
510
+	 * @param string $text
511
+	 * @return \EE_Submit_Input
512
+	 */
513
+	public function generateSubmitButton($text = '')
514
+	{
515
+		$text = ! empty($text) ? $text : $this->submitBtnText();
516
+		return new EE_Submit_Input(
517
+			array(
518
+				'html_name'             => 'ee-form-submit-' . $this->slug(),
519
+				'html_id'               => 'ee-form-submit-' . $this->slug(),
520
+				'html_class'            => 'ee-form-submit',
521
+				'html_label'            => '&nbsp;',
522
+				'other_html_attributes' => ' rel="' . $this->slug() . '"',
523
+				'default'               => $text,
524
+			)
525
+		);
526
+	}
527
+
528
+
529
+
530
+	/**
531
+	 * calls generateSubmitButton() and appends it onto the form along with a float clearing div
532
+	 *
533
+	 * @param string $text
534
+	 * @return void
535
+	 * @throws \LogicException
536
+	 * @throws \EE_Error
537
+	 */
538
+	public function appendSubmitButton($text = '')
539
+	{
540
+		if ($this->form->subsection_exists($this->slug() . '-submit-btn')) {
541
+			return;
542
+		}
543
+		$this->form->add_subsections(
544
+			array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)),
545
+			null,
546
+			false
547
+		);
548
+	}
549
+
550
+
551
+
552
+	/**
553
+	 * creates and returns an EE_Submit_Input labeled "Cancel"
554
+	 *
555
+	 * @param string $text
556
+	 * @return \EE_Submit_Input
557
+	 */
558
+	public function generateCancelButton($text = '')
559
+	{
560
+		$cancel_button = new EE_Submit_Input(
561
+			array(
562
+				'html_name'             => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!!
563
+				'html_id'               => 'ee-cancel-form-' . $this->slug(),
564
+				'html_class'            => 'ee-cancel-form',
565
+				'html_label'            => '&nbsp;',
566
+				'other_html_attributes' => ' rel="' . $this->slug() . '"',
567
+				'default'               => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'),
568
+			)
569
+		);
570
+		$cancel_button->set_button_css_attributes(false);
571
+		return $cancel_button;
572
+	}
573
+
574
+
575
+
576
+	/**
577
+	 * appends a float clearing div onto end of form
578
+	 *
579
+	 * @return void
580
+	 * @throws \EE_Error
581
+	 */
582
+	public function clearFormButtonFloats()
583
+	{
584
+		$this->form->add_subsections(
585
+			array(
586
+				'clear-submit-btn-float' => new \EE_Form_Section_HTML(
587
+					EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx()
588
+				),
589
+			),
590
+			null,
591
+			false
592
+		);
593
+	}
594
+
595
+
596
+
597
+	/**
598
+	 * takes the generated form and displays it along with ony other non-form HTML that may be required
599
+	 * returns a string of HTML that can be directly echoed in a template
600
+	 *
601
+	 * @return string
602
+	 * @throws LogicException
603
+	 * @throws \EE_Error
604
+	 */
605
+	public function display()
606
+	{
607
+		$form_html = apply_filters(
608
+			'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form',
609
+			''
610
+		);
611
+		$form_config = $this->formConfig();
612
+		if (
613
+			$form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
614
+			|| $form_config === FormHandler::ADD_FORM_TAGS_ONLY
615
+		) {
616
+			$form_html .= $this->form()->form_open($this->formAction());
617
+		}
618
+		$form_html .= $this->form(true)->get_html($this->form_has_errors);
619
+		if (
620
+			$form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
621
+			|| $form_config === FormHandler::ADD_FORM_TAGS_ONLY
622
+		) {
623
+			$form_html .= $this->form()->form_close();
624
+		}
625
+		$form_html .= apply_filters(
626
+			'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__after_form',
627
+			''
628
+		);
629
+		return $form_html;
630
+	}
631
+
632
+
633
+
634
+	/**
635
+	 * handles processing the form submission
636
+	 * returns true or false depending on whether the form was processed successfully or not
637
+	 *
638
+	 * @param array $submitted_form_data
639
+	 * @return array
640
+	 * @throws \EE_Error
641
+	 * @throws \LogicException
642
+	 * @throws InvalidFormSubmissionException
643
+	 */
644
+	public function process($submitted_form_data = array())
645
+	{
646
+		if (! $this->form()->was_submitted($submitted_form_data)) {
647
+			throw new InvalidFormSubmissionException($this->form_name);
648
+		}
649
+		$this->form(true)->receive_form_submission($submitted_form_data);
650
+		if (! $this->form()->is_valid()) {
651
+			throw new InvalidFormSubmissionException(
652
+				$this->form_name,
653
+				sprintf(
654
+					esc_html__(
655
+						'The "%1$s" form is invalid. Please correct the following errors and resubmit: %2$s %3$s',
656
+						'event_espresso'
657
+					),
658
+					$this->form_name,
659
+					'<br />',
660
+					$this->form()->submission_error_message()
661
+				)
662
+			);
663
+		}
664
+		return $this->form()->valid_data();
665
+	}
666 666
 
667 667
 
668 668
 
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 use EventEspresso\core\exceptions\InvalidDataTypeException;
12 12
 use EventEspresso\core\exceptions\InvalidFormSubmissionException;
13 13
 
14
-if (! defined('EVENT_ESPRESSO_VERSION')) {
14
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
15 15
     exit('No direct script access allowed');
16 16
 }
17 17
 
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
      */
177 177
     public function form($for_display = false)
178 178
     {
179
-        if (! $this->formIsValid()) {
179
+        if ( ! $this->formIsValid()) {
180 180
             return null;
181 181
         }
182 182
         if ($for_display) {
@@ -200,9 +200,9 @@  discard block
 block discarded – undo
200 200
      */
201 201
     public function formIsValid()
202 202
     {
203
-        if (! $this->form instanceof \EE_Form_Section_Proper) {
203
+        if ( ! $this->form instanceof \EE_Form_Section_Proper) {
204 204
             static $generated = false;
205
-            if (! $generated) {
205
+            if ( ! $generated) {
206 206
                 $generated = true;
207 207
                 $form = $this->generate();
208 208
                 if ($form instanceof \EE_Form_Section_Proper) {
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
      */
284 284
     public function setFormName($form_name)
285 285
     {
286
-        if (! is_string($form_name)) {
286
+        if ( ! is_string($form_name)) {
287 287
             throw new InvalidDataTypeException('$form_name', $form_name, 'string');
288 288
         }
289 289
         $this->form_name = $form_name;
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
      */
310 310
     public function setAdminName($admin_name)
311 311
     {
312
-        if (! is_string($admin_name)) {
312
+        if ( ! is_string($admin_name)) {
313 313
             throw new InvalidDataTypeException('$admin_name', $admin_name, 'string');
314 314
         }
315 315
         $this->admin_name = $admin_name;
@@ -335,7 +335,7 @@  discard block
 block discarded – undo
335 335
      */
336 336
     public function setSlug($slug)
337 337
     {
338
-        if (! is_string($slug)) {
338
+        if ( ! is_string($slug)) {
339 339
             throw new InvalidDataTypeException('$slug', $slug, 'string');
340 340
         }
341 341
         $this->slug = $slug;
@@ -360,7 +360,7 @@  discard block
 block discarded – undo
360 360
      */
361 361
     public function setSubmitBtnText($submit_btn_text)
362 362
     {
363
-        if (! is_string($submit_btn_text)) {
363
+        if ( ! is_string($submit_btn_text)) {
364 364
             throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string');
365 365
         }
366 366
         if (empty($submit_btn_text)) {
@@ -391,7 +391,7 @@  discard block
 block discarded – undo
391 391
      */
392 392
     public function setFormAction($form_action)
393 393
     {
394
-        if (! is_string($form_action)) {
394
+        if ( ! is_string($form_action)) {
395 395
             throw new InvalidDataTypeException('$form_action', $form_action, 'string');
396 396
         }
397 397
         $this->form_action = $form_action;
@@ -515,11 +515,11 @@  discard block
 block discarded – undo
515 515
         $text = ! empty($text) ? $text : $this->submitBtnText();
516 516
         return new EE_Submit_Input(
517 517
             array(
518
-                'html_name'             => 'ee-form-submit-' . $this->slug(),
519
-                'html_id'               => 'ee-form-submit-' . $this->slug(),
518
+                'html_name'             => 'ee-form-submit-'.$this->slug(),
519
+                'html_id'               => 'ee-form-submit-'.$this->slug(),
520 520
                 'html_class'            => 'ee-form-submit',
521 521
                 'html_label'            => '&nbsp;',
522
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
522
+                'other_html_attributes' => ' rel="'.$this->slug().'"',
523 523
                 'default'               => $text,
524 524
             )
525 525
         );
@@ -537,11 +537,11 @@  discard block
 block discarded – undo
537 537
      */
538 538
     public function appendSubmitButton($text = '')
539 539
     {
540
-        if ($this->form->subsection_exists($this->slug() . '-submit-btn')) {
540
+        if ($this->form->subsection_exists($this->slug().'-submit-btn')) {
541 541
             return;
542 542
         }
543 543
         $this->form->add_subsections(
544
-            array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)),
544
+            array($this->slug().'-submit-btn' => $this->generateSubmitButton($text)),
545 545
             null,
546 546
             false
547 547
         );
@@ -559,11 +559,11 @@  discard block
 block discarded – undo
559 559
     {
560 560
         $cancel_button = new EE_Submit_Input(
561 561
             array(
562
-                'html_name'             => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!!
563
-                'html_id'               => 'ee-cancel-form-' . $this->slug(),
562
+                'html_name'             => 'ee-form-submit-'.$this->slug(), // YES! Same name as submit !!!
563
+                'html_id'               => 'ee-cancel-form-'.$this->slug(),
564 564
                 'html_class'            => 'ee-cancel-form',
565 565
                 'html_label'            => '&nbsp;',
566
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
566
+                'other_html_attributes' => ' rel="'.$this->slug().'"',
567 567
                 'default'               => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'),
568 568
             )
569 569
         );
@@ -584,7 +584,7 @@  discard block
 block discarded – undo
584 584
         $this->form->add_subsections(
585 585
             array(
586 586
                 'clear-submit-btn-float' => new \EE_Form_Section_HTML(
587
-                    EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx()
587
+                    EEH_HTML::div('', '', 'clear-float').EEH_HTML::divx()
588 588
                 ),
589 589
             ),
590 590
             null,
@@ -643,11 +643,11 @@  discard block
 block discarded – undo
643 643
      */
644 644
     public function process($submitted_form_data = array())
645 645
     {
646
-        if (! $this->form()->was_submitted($submitted_form_data)) {
646
+        if ( ! $this->form()->was_submitted($submitted_form_data)) {
647 647
             throw new InvalidFormSubmissionException($this->form_name);
648 648
         }
649 649
         $this->form(true)->receive_form_submission($submitted_form_data);
650
-        if (! $this->form()->is_valid()) {
650
+        if ( ! $this->form()->is_valid()) {
651 651
             throw new InvalidFormSubmissionException(
652 652
                 $this->form_name,
653 653
                 sprintf(
Please login to merge, or discard this patch.
core/EE_Error.core.php 3 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
     /**
74 74
      *    error_handler
75 75
      *
76
-     * @param $code
76
+     * @param integer $code
77 77
      * @param $message
78 78
      * @param $file
79 79
      * @param $line
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
     /**
178 178
      * _format_error
179 179
      *
180
-     * @param $code
180
+     * @param string $code
181 181
      * @param $message
182 182
      * @param $file
183 183
      * @param $line
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
 
211 211
 
212 212
     /**
213
-     * @return void
213
+     * @return string|null
214 214
      * @throws EE_Error
215 215
      * @throws ReflectionException
216 216
      */
Please login to merge, or discard this patch.
Indentation   +1086 added lines, -1086 removed lines patch added patch discarded remove patch
@@ -5,8 +5,8 @@  discard block
 block discarded – undo
5 5
 // if you're a dev and want to receive all errors via email
6 6
 // add this to your wp-config.php: define( 'EE_ERROR_EMAILS', TRUE );
7 7
 if (defined('WP_DEBUG') && WP_DEBUG === true && defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS === true) {
8
-    set_error_handler(array('EE_Error', 'error_handler'));
9
-    register_shutdown_function(array('EE_Error', 'fatal_error_handler'));
8
+	set_error_handler(array('EE_Error', 'error_handler'));
9
+	register_shutdown_function(array('EE_Error', 'fatal_error_handler'));
10 10
 }
11 11
 
12 12
 
@@ -23,259 +23,259 @@  discard block
 block discarded – undo
23 23
 {
24 24
 
25 25
 
26
-    /**
27
-     *    name of the file to log exceptions to
28
-     *
29
-     * @var string
30
-     */
31
-    private static $_exception_log_file = 'espresso_error_log.txt';
32
-
33
-    /**
34
-     *    stores details for all exception
35
-     *
36
-     * @var array
37
-     */
38
-    private static $_all_exceptions = array();
39
-
40
-    /**
41
-     *    tracks number of errors
42
-     *
43
-     * @var int
44
-     */
45
-    private static $_error_count = 0;
46
-
47
-    /**
48
-     *    has shutdown action been added ?
49
-     *
50
-     * @var array $_espresso_notices
51
-     */
52
-    private static $_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false);
53
-
54
-
55
-
56
-    /**
57
-     * @override default exception handling
58
-     * @param string         $message
59
-     * @param int            $code
60
-     * @param Exception|null $previous
61
-     */
62
-    public function __construct($message, $code = 0, Exception $previous = null)
63
-    {
64
-        if (version_compare(PHP_VERSION, '5.3.0', '<')) {
65
-            parent::__construct($message, $code);
66
-        } else {
67
-            parent::__construct($message, $code, $previous);
68
-        }
69
-    }
70
-
71
-
72
-
73
-    /**
74
-     *    error_handler
75
-     *
76
-     * @param $code
77
-     * @param $message
78
-     * @param $file
79
-     * @param $line
80
-     * @return void
81
-     */
82
-    public static function error_handler($code, $message, $file, $line)
83
-    {
84
-        $type = EE_Error::error_type($code);
85
-        $site = site_url();
86
-        switch ($site) {
87
-            case 'http://ee4.eventespresso.com/' :
88
-            case 'http://ee4decaf.eventespresso.com/' :
89
-            case 'http://ee4hf.eventespresso.com/' :
90
-            case 'http://ee4a.eventespresso.com/' :
91
-            case 'http://ee4ad.eventespresso.com/' :
92
-            case 'http://ee4b.eventespresso.com/' :
93
-            case 'http://ee4bd.eventespresso.com/' :
94
-            case 'http://ee4d.eventespresso.com/' :
95
-            case 'http://ee4dd.eventespresso.com/' :
96
-                $to = '[email protected]';
97
-                break;
98
-            default :
99
-                $to = get_option('admin_email');
100
-        }
101
-        $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url();
102
-        $msg = EE_Error::_format_error($type, $message, $file, $line);
103
-        if (function_exists('wp_mail')) {
104
-            add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type'));
105
-            wp_mail($to, $subject, $msg);
106
-        }
107
-        echo '<div id="message" class="espresso-notices error"><p>';
108
-        echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line;
109
-        echo '<br /></p></div>';
110
-    }
111
-
112
-
113
-
114
-    /**
115
-     * error_type
116
-     * http://www.php.net/manual/en/errorfunc.constants.php#109430
117
-     *
118
-     * @param $code
119
-     * @return string
120
-     */
121
-    public static function error_type($code)
122
-    {
123
-        switch ($code) {
124
-            case E_ERROR: // 1 //
125
-                return 'E_ERROR';
126
-            case E_WARNING: // 2 //
127
-                return 'E_WARNING';
128
-            case E_PARSE: // 4 //
129
-                return 'E_PARSE';
130
-            case E_NOTICE: // 8 //
131
-                return 'E_NOTICE';
132
-            case E_CORE_ERROR: // 16 //
133
-                return 'E_CORE_ERROR';
134
-            case E_CORE_WARNING: // 32 //
135
-                return 'E_CORE_WARNING';
136
-            case E_COMPILE_ERROR: // 64 //
137
-                return 'E_COMPILE_ERROR';
138
-            case E_COMPILE_WARNING: // 128 //
139
-                return 'E_COMPILE_WARNING';
140
-            case E_USER_ERROR: // 256 //
141
-                return 'E_USER_ERROR';
142
-            case E_USER_WARNING: // 512 //
143
-                return 'E_USER_WARNING';
144
-            case E_USER_NOTICE: // 1024 //
145
-                return 'E_USER_NOTICE';
146
-            case E_STRICT: // 2048 //
147
-                return 'E_STRICT';
148
-            case E_RECOVERABLE_ERROR: // 4096 //
149
-                return 'E_RECOVERABLE_ERROR';
150
-            case E_DEPRECATED: // 8192 //
151
-                return 'E_DEPRECATED';
152
-            case E_USER_DEPRECATED: // 16384 //
153
-                return 'E_USER_DEPRECATED';
154
-            case E_ALL: // 16384 //
155
-                return 'E_ALL';
156
-        }
157
-        return '';
158
-    }
159
-
160
-
161
-
162
-    /**
163
-     *    fatal_error_handler
164
-     *
165
-     * @return void
166
-     */
167
-    public static function fatal_error_handler()
168
-    {
169
-        $last_error = error_get_last();
170
-        if ($last_error['type'] === E_ERROR) {
171
-            EE_Error::error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']);
172
-        }
173
-    }
174
-
175
-
176
-
177
-    /**
178
-     * _format_error
179
-     *
180
-     * @param $code
181
-     * @param $message
182
-     * @param $file
183
-     * @param $line
184
-     * @return string
185
-     */
186
-    private static function _format_error($code, $message, $file, $line)
187
-    {
188
-        $html = "<table cellpadding='5'><thead bgcolor='#f8f8f8'><th>Item</th><th align='left'>Details</th></thead><tbody>";
189
-        $html .= "<tr valign='top'><td><b>Code</b></td><td>$code</td></tr>";
190
-        $html .= "<tr valign='top'><td><b>Error</b></td><td>$message</td></tr>";
191
-        $html .= "<tr valign='top'><td><b>File</b></td><td>$file</td></tr>";
192
-        $html .= "<tr valign='top'><td><b>Line</b></td><td>$line</td></tr>";
193
-        $html .= '</tbody></table>';
194
-        return $html;
195
-    }
196
-
197
-
198
-
199
-    /**
200
-     * set_content_type
201
-     *
202
-     * @param $content_type
203
-     * @return string
204
-     */
205
-    public static function set_content_type($content_type)
206
-    {
207
-        return 'text/html';
208
-    }
209
-
210
-
211
-
212
-    /**
213
-     * @return void
214
-     * @throws EE_Error
215
-     * @throws ReflectionException
216
-     */
217
-    public function get_error()
218
-    {
219
-        if (apply_filters('FHEE__EE_Error__get_error__show_normal_exceptions', false)) {
220
-            throw $this;
221
-        }
222
-        // get separate user and developer messages if they exist
223
-        $msg = explode('||', $this->getMessage());
224
-        $user_msg = $msg[0];
225
-        $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0];
226
-        $msg = WP_DEBUG ? $dev_msg : $user_msg;
227
-        // add details to _all_exceptions array
228
-        $x_time = time();
229
-        self::$_all_exceptions[$x_time]['name'] = get_class($this);
230
-        self::$_all_exceptions[$x_time]['file'] = $this->getFile();
231
-        self::$_all_exceptions[$x_time]['line'] = $this->getLine();
232
-        self::$_all_exceptions[$x_time]['msg'] = $msg;
233
-        self::$_all_exceptions[$x_time]['code'] = $this->getCode();
234
-        self::$_all_exceptions[$x_time]['trace'] = $this->getTrace();
235
-        self::$_all_exceptions[$x_time]['string'] = $this->getTraceAsString();
236
-        self::$_error_count++;
237
-        //add_action( 'shutdown', array( $this, 'display_errors' ));
238
-        $this->display_errors();
239
-    }
240
-
241
-
242
-
243
-    /**
244
-     *    has_error
245
-     *
246
-     * @param bool   $check_stored
247
-     * @param string $type_to_check
248
-     * @return bool
249
-     */
250
-    public static function has_error($check_stored = false, $type_to_check = 'errors')
251
-    {
252
-        $has_error = isset(self::$_espresso_notices[$type_to_check])
253
-                     && ! empty(self::$_espresso_notices[$type_to_check])
254
-            ? true
255
-            : false;
256
-        if ($check_stored && ! $has_error) {
257
-            $notices = (array)get_option('ee_notices', array());
258
-            foreach ($notices as $type => $notice) {
259
-                if ($type === $type_to_check && $notice) {
260
-                    return true;
261
-                }
262
-            }
263
-        }
264
-        return $has_error;
265
-    }
266
-
267
-
268
-
269
-    /**
270
-     *    display_errors
271
-     *
272
-     * @echo   string
273
-     * @throws \ReflectionException
274
-     */
275
-    public function display_errors()
276
-    {
277
-        $trace_details = '';
278
-        $output = '
26
+	/**
27
+	 *    name of the file to log exceptions to
28
+	 *
29
+	 * @var string
30
+	 */
31
+	private static $_exception_log_file = 'espresso_error_log.txt';
32
+
33
+	/**
34
+	 *    stores details for all exception
35
+	 *
36
+	 * @var array
37
+	 */
38
+	private static $_all_exceptions = array();
39
+
40
+	/**
41
+	 *    tracks number of errors
42
+	 *
43
+	 * @var int
44
+	 */
45
+	private static $_error_count = 0;
46
+
47
+	/**
48
+	 *    has shutdown action been added ?
49
+	 *
50
+	 * @var array $_espresso_notices
51
+	 */
52
+	private static $_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false);
53
+
54
+
55
+
56
+	/**
57
+	 * @override default exception handling
58
+	 * @param string         $message
59
+	 * @param int            $code
60
+	 * @param Exception|null $previous
61
+	 */
62
+	public function __construct($message, $code = 0, Exception $previous = null)
63
+	{
64
+		if (version_compare(PHP_VERSION, '5.3.0', '<')) {
65
+			parent::__construct($message, $code);
66
+		} else {
67
+			parent::__construct($message, $code, $previous);
68
+		}
69
+	}
70
+
71
+
72
+
73
+	/**
74
+	 *    error_handler
75
+	 *
76
+	 * @param $code
77
+	 * @param $message
78
+	 * @param $file
79
+	 * @param $line
80
+	 * @return void
81
+	 */
82
+	public static function error_handler($code, $message, $file, $line)
83
+	{
84
+		$type = EE_Error::error_type($code);
85
+		$site = site_url();
86
+		switch ($site) {
87
+			case 'http://ee4.eventespresso.com/' :
88
+			case 'http://ee4decaf.eventespresso.com/' :
89
+			case 'http://ee4hf.eventespresso.com/' :
90
+			case 'http://ee4a.eventespresso.com/' :
91
+			case 'http://ee4ad.eventespresso.com/' :
92
+			case 'http://ee4b.eventespresso.com/' :
93
+			case 'http://ee4bd.eventespresso.com/' :
94
+			case 'http://ee4d.eventespresso.com/' :
95
+			case 'http://ee4dd.eventespresso.com/' :
96
+				$to = '[email protected]';
97
+				break;
98
+			default :
99
+				$to = get_option('admin_email');
100
+		}
101
+		$subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url();
102
+		$msg = EE_Error::_format_error($type, $message, $file, $line);
103
+		if (function_exists('wp_mail')) {
104
+			add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type'));
105
+			wp_mail($to, $subject, $msg);
106
+		}
107
+		echo '<div id="message" class="espresso-notices error"><p>';
108
+		echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line;
109
+		echo '<br /></p></div>';
110
+	}
111
+
112
+
113
+
114
+	/**
115
+	 * error_type
116
+	 * http://www.php.net/manual/en/errorfunc.constants.php#109430
117
+	 *
118
+	 * @param $code
119
+	 * @return string
120
+	 */
121
+	public static function error_type($code)
122
+	{
123
+		switch ($code) {
124
+			case E_ERROR: // 1 //
125
+				return 'E_ERROR';
126
+			case E_WARNING: // 2 //
127
+				return 'E_WARNING';
128
+			case E_PARSE: // 4 //
129
+				return 'E_PARSE';
130
+			case E_NOTICE: // 8 //
131
+				return 'E_NOTICE';
132
+			case E_CORE_ERROR: // 16 //
133
+				return 'E_CORE_ERROR';
134
+			case E_CORE_WARNING: // 32 //
135
+				return 'E_CORE_WARNING';
136
+			case E_COMPILE_ERROR: // 64 //
137
+				return 'E_COMPILE_ERROR';
138
+			case E_COMPILE_WARNING: // 128 //
139
+				return 'E_COMPILE_WARNING';
140
+			case E_USER_ERROR: // 256 //
141
+				return 'E_USER_ERROR';
142
+			case E_USER_WARNING: // 512 //
143
+				return 'E_USER_WARNING';
144
+			case E_USER_NOTICE: // 1024 //
145
+				return 'E_USER_NOTICE';
146
+			case E_STRICT: // 2048 //
147
+				return 'E_STRICT';
148
+			case E_RECOVERABLE_ERROR: // 4096 //
149
+				return 'E_RECOVERABLE_ERROR';
150
+			case E_DEPRECATED: // 8192 //
151
+				return 'E_DEPRECATED';
152
+			case E_USER_DEPRECATED: // 16384 //
153
+				return 'E_USER_DEPRECATED';
154
+			case E_ALL: // 16384 //
155
+				return 'E_ALL';
156
+		}
157
+		return '';
158
+	}
159
+
160
+
161
+
162
+	/**
163
+	 *    fatal_error_handler
164
+	 *
165
+	 * @return void
166
+	 */
167
+	public static function fatal_error_handler()
168
+	{
169
+		$last_error = error_get_last();
170
+		if ($last_error['type'] === E_ERROR) {
171
+			EE_Error::error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']);
172
+		}
173
+	}
174
+
175
+
176
+
177
+	/**
178
+	 * _format_error
179
+	 *
180
+	 * @param $code
181
+	 * @param $message
182
+	 * @param $file
183
+	 * @param $line
184
+	 * @return string
185
+	 */
186
+	private static function _format_error($code, $message, $file, $line)
187
+	{
188
+		$html = "<table cellpadding='5'><thead bgcolor='#f8f8f8'><th>Item</th><th align='left'>Details</th></thead><tbody>";
189
+		$html .= "<tr valign='top'><td><b>Code</b></td><td>$code</td></tr>";
190
+		$html .= "<tr valign='top'><td><b>Error</b></td><td>$message</td></tr>";
191
+		$html .= "<tr valign='top'><td><b>File</b></td><td>$file</td></tr>";
192
+		$html .= "<tr valign='top'><td><b>Line</b></td><td>$line</td></tr>";
193
+		$html .= '</tbody></table>';
194
+		return $html;
195
+	}
196
+
197
+
198
+
199
+	/**
200
+	 * set_content_type
201
+	 *
202
+	 * @param $content_type
203
+	 * @return string
204
+	 */
205
+	public static function set_content_type($content_type)
206
+	{
207
+		return 'text/html';
208
+	}
209
+
210
+
211
+
212
+	/**
213
+	 * @return void
214
+	 * @throws EE_Error
215
+	 * @throws ReflectionException
216
+	 */
217
+	public function get_error()
218
+	{
219
+		if (apply_filters('FHEE__EE_Error__get_error__show_normal_exceptions', false)) {
220
+			throw $this;
221
+		}
222
+		// get separate user and developer messages if they exist
223
+		$msg = explode('||', $this->getMessage());
224
+		$user_msg = $msg[0];
225
+		$dev_msg = isset($msg[1]) ? $msg[1] : $msg[0];
226
+		$msg = WP_DEBUG ? $dev_msg : $user_msg;
227
+		// add details to _all_exceptions array
228
+		$x_time = time();
229
+		self::$_all_exceptions[$x_time]['name'] = get_class($this);
230
+		self::$_all_exceptions[$x_time]['file'] = $this->getFile();
231
+		self::$_all_exceptions[$x_time]['line'] = $this->getLine();
232
+		self::$_all_exceptions[$x_time]['msg'] = $msg;
233
+		self::$_all_exceptions[$x_time]['code'] = $this->getCode();
234
+		self::$_all_exceptions[$x_time]['trace'] = $this->getTrace();
235
+		self::$_all_exceptions[$x_time]['string'] = $this->getTraceAsString();
236
+		self::$_error_count++;
237
+		//add_action( 'shutdown', array( $this, 'display_errors' ));
238
+		$this->display_errors();
239
+	}
240
+
241
+
242
+
243
+	/**
244
+	 *    has_error
245
+	 *
246
+	 * @param bool   $check_stored
247
+	 * @param string $type_to_check
248
+	 * @return bool
249
+	 */
250
+	public static function has_error($check_stored = false, $type_to_check = 'errors')
251
+	{
252
+		$has_error = isset(self::$_espresso_notices[$type_to_check])
253
+					 && ! empty(self::$_espresso_notices[$type_to_check])
254
+			? true
255
+			: false;
256
+		if ($check_stored && ! $has_error) {
257
+			$notices = (array)get_option('ee_notices', array());
258
+			foreach ($notices as $type => $notice) {
259
+				if ($type === $type_to_check && $notice) {
260
+					return true;
261
+				}
262
+			}
263
+		}
264
+		return $has_error;
265
+	}
266
+
267
+
268
+
269
+	/**
270
+	 *    display_errors
271
+	 *
272
+	 * @echo   string
273
+	 * @throws \ReflectionException
274
+	 */
275
+	public function display_errors()
276
+	{
277
+		$trace_details = '';
278
+		$output = '
279 279
 <style type="text/css">
280 280
 	#ee-error-message {
281 281
 		max-width:90% !important;
@@ -331,19 +331,19 @@  discard block
 block discarded – undo
331 331
 	}
332 332
 </style>
333 333
 <div id="ee-error-message" class="error">';
334
-        if (! WP_DEBUG) {
335
-            $output .= '
334
+		if (! WP_DEBUG) {
335
+			$output .= '
336 336
 	<p>';
337
-        }
338
-        // cycle thru errors
339
-        foreach (self::$_all_exceptions as $time => $ex) {
340
-            $error_code = '';
341
-            // process trace info
342
-            if (empty($ex['trace'])) {
343
-                $trace_details .= __('Sorry, but no trace information was available for this exception.',
344
-                    'event_espresso');
345
-            } else {
346
-                $trace_details .= '
337
+		}
338
+		// cycle thru errors
339
+		foreach (self::$_all_exceptions as $time => $ex) {
340
+			$error_code = '';
341
+			// process trace info
342
+			if (empty($ex['trace'])) {
343
+				$trace_details .= __('Sorry, but no trace information was available for this exception.',
344
+					'event_espresso');
345
+			} else {
346
+				$trace_details .= '
347 347
 			<div id="ee-trace-details">
348 348
 			<table width="100%" border="0" cellpadding="5" cellspacing="0">
349 349
 				<tr>
@@ -353,38 +353,38 @@  discard block
 block discarded – undo
353 353
 					<th scope="col" align="left">Class</th>
354 354
 					<th scope="col" align="left">Method( arguments )</th>
355 355
 				</tr>';
356
-                $last_on_stack = count($ex['trace']) - 1;
357
-                // reverse array so that stack is in proper chronological order
358
-                $sorted_trace = array_reverse($ex['trace']);
359
-                foreach ($sorted_trace as $nmbr => $trace) {
360
-                    $file = isset($trace['file']) ? $trace['file'] : '';
361
-                    $class = isset($trace['class']) ? $trace['class'] : '';
362
-                    $type = isset($trace['type']) ? $trace['type'] : '';
363
-                    $function = isset($trace['function']) ? $trace['function'] : '';
364
-                    $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : '';
365
-                    $line = isset($trace['line']) ? $trace['line'] : '';
366
-                    $zebra = ($nmbr % 2) ? ' odd' : '';
367
-                    if (empty($file) && ! empty($class)) {
368
-                        $a = new ReflectionClass($class);
369
-                        $file = $a->getFileName();
370
-                        if (empty($line) && ! empty($function)) {
371
-                            $b = new ReflectionMethod($class, $function);
372
-                            $line = $b->getStartLine();
373
-                        }
374
-                    }
375
-                    if ($nmbr === $last_on_stack) {
376
-                        $file = $ex['file'] !== '' ? $ex['file'] : $file;
377
-                        $line = $ex['line'] !== '' ? $ex['line'] : $line;
378
-                        $error_code = self::generate_error_code($file, $trace['function'], $line);
379
-                    }
380
-                    $nmbr_dsply = ! empty($nmbr) ? $nmbr : '&nbsp;';
381
-                    $line_dsply = ! empty($line) ? $line : '&nbsp;';
382
-                    $file_dsply = ! empty($file) ? $file : '&nbsp;';
383
-                    $class_dsply = ! empty($class) ? $class : '&nbsp;';
384
-                    $type_dsply = ! empty($type) ? $type : '&nbsp;';
385
-                    $function_dsply = ! empty($function) ? $function : '&nbsp;';
386
-                    $args_dsply = ! empty($args) ? '( ' . $args . ' )' : '';
387
-                    $trace_details .= '
356
+				$last_on_stack = count($ex['trace']) - 1;
357
+				// reverse array so that stack is in proper chronological order
358
+				$sorted_trace = array_reverse($ex['trace']);
359
+				foreach ($sorted_trace as $nmbr => $trace) {
360
+					$file = isset($trace['file']) ? $trace['file'] : '';
361
+					$class = isset($trace['class']) ? $trace['class'] : '';
362
+					$type = isset($trace['type']) ? $trace['type'] : '';
363
+					$function = isset($trace['function']) ? $trace['function'] : '';
364
+					$args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : '';
365
+					$line = isset($trace['line']) ? $trace['line'] : '';
366
+					$zebra = ($nmbr % 2) ? ' odd' : '';
367
+					if (empty($file) && ! empty($class)) {
368
+						$a = new ReflectionClass($class);
369
+						$file = $a->getFileName();
370
+						if (empty($line) && ! empty($function)) {
371
+							$b = new ReflectionMethod($class, $function);
372
+							$line = $b->getStartLine();
373
+						}
374
+					}
375
+					if ($nmbr === $last_on_stack) {
376
+						$file = $ex['file'] !== '' ? $ex['file'] : $file;
377
+						$line = $ex['line'] !== '' ? $ex['line'] : $line;
378
+						$error_code = self::generate_error_code($file, $trace['function'], $line);
379
+					}
380
+					$nmbr_dsply = ! empty($nmbr) ? $nmbr : '&nbsp;';
381
+					$line_dsply = ! empty($line) ? $line : '&nbsp;';
382
+					$file_dsply = ! empty($file) ? $file : '&nbsp;';
383
+					$class_dsply = ! empty($class) ? $class : '&nbsp;';
384
+					$type_dsply = ! empty($type) ? $type : '&nbsp;';
385
+					$function_dsply = ! empty($function) ? $function : '&nbsp;';
386
+					$args_dsply = ! empty($args) ? '( ' . $args . ' )' : '';
387
+					$trace_details .= '
388 388
 					<tr>
389 389
 						<td align="right" class="' . $zebra . '">' . $nmbr_dsply . '</td>
390 390
 						<td align="right" class="' . $zebra . '">' . $line_dsply . '</td>
@@ -392,670 +392,670 @@  discard block
 block discarded – undo
392 392
 						<td align="left" class="' . $zebra . '">' . $class_dsply . '</td>
393 393
 						<td align="left" class="' . $zebra . '">' . $type_dsply . $function_dsply . $args_dsply . '</td>
394 394
 					</tr>';
395
-                }
396
-                $trace_details .= '
395
+				}
396
+				$trace_details .= '
397 397
 			 </table>
398 398
 			</div>';
399
-            }
400
-            $ex['code'] = $ex['code'] ? $ex['code'] : $error_code;
401
-            // add generic non-identifying messages for non-privileged users
402
-            if (! WP_DEBUG) {
403
-                $output .= '<span class="ee-error-user-msg-spn">'
404
-                           . trim($ex['msg'])
405
-                           . '</span> &nbsp; <sup>'
406
-                           . $ex['code']
407
-                           . '</sup><br />';
408
-            } else {
409
-                // or helpful developer messages if debugging is on
410
-                $output .= '
399
+			}
400
+			$ex['code'] = $ex['code'] ? $ex['code'] : $error_code;
401
+			// add generic non-identifying messages for non-privileged users
402
+			if (! WP_DEBUG) {
403
+				$output .= '<span class="ee-error-user-msg-spn">'
404
+						   . trim($ex['msg'])
405
+						   . '</span> &nbsp; <sup>'
406
+						   . $ex['code']
407
+						   . '</sup><br />';
408
+			} else {
409
+				// or helpful developer messages if debugging is on
410
+				$output .= '
411 411
 		<div class="ee-error-dev-msg-dv">
412 412
 			<p class="ee-error-dev-msg-pg">
413 413
 				<strong class="ee-error-dev-msg-str">An '
414
-                           . $ex['name']
415
-                           . ' exception was thrown!</strong>  &nbsp; <span>code: '
416
-                           . $ex['code']
417
-                           . '</span><br />
414
+						   . $ex['name']
415
+						   . ' exception was thrown!</strong>  &nbsp; <span>code: '
416
+						   . $ex['code']
417
+						   . '</span><br />
418 418
 				<span class="big-text">"'
419
-                           . trim($ex['msg'])
420
-                           . '"</span><br/>
419
+						   . trim($ex['msg'])
420
+						   . '"</span><br/>
421 421
 				<a id="display-ee-error-trace-'
422
-                           . self::$_error_count
423
-                           . $time
424
-                           . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-'
425
-                           . self::$_error_count
426
-                           . $time
427
-                           . '">
422
+						   . self::$_error_count
423
+						   . $time
424
+						   . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-'
425
+						   . self::$_error_count
426
+						   . $time
427
+						   . '">
428 428
 					'
429
-                           . __('click to view backtrace and class/method details', 'event_espresso')
430
-                           . '
429
+						   . __('click to view backtrace and class/method details', 'event_espresso')
430
+						   . '
431 431
 				</a><br />
432 432
 				<span class="small-text lt-grey-text">'
433
-                           . $ex['file']
434
-                           . ' &nbsp; ( line no: '
435
-                           . $ex['line']
436
-                           . ' )</span>
433
+						   . $ex['file']
434
+						   . ' &nbsp; ( line no: '
435
+						   . $ex['line']
436
+						   . ' )</span>
437 437
 			</p>
438 438
 			<div id="ee-error-trace-'
439
-                           . self::$_error_count
440
-                           . $time
441
-                           . '-dv" class="ee-error-trace-dv" style="display: none;">
439
+						   . self::$_error_count
440
+						   . $time
441
+						   . '-dv" class="ee-error-trace-dv" style="display: none;">
442 442
 				'
443
-                           . $trace_details;
444
-                if (! empty($class)) {
445
-                    $output .= '
443
+						   . $trace_details;
444
+				if (! empty($class)) {
445
+					$output .= '
446 446
 				<div style="padding:3px; margin:0 0 1em; border:1px solid #666; background:#fff; border-radius:3px;">
447 447
 					<div style="padding:1em 2em; border:1px solid #666; background:#f9f9f9;">
448 448
 						<h3>Class Details</h3>';
449
-                    $a = new ReflectionClass($class);
450
-                    $output .= '
449
+					$a = new ReflectionClass($class);
450
+					$output .= '
451 451
 						<pre>' . $a . '</pre>
452 452
 					</div>
453 453
 				</div>';
454
-                }
455
-                $output .= '
454
+				}
455
+				$output .= '
456 456
 			</div>
457 457
 		</div>
458 458
 		<br />';
459
-            }
460
-            $this->write_to_error_log($time, $ex);
461
-        }
462
-        // remove last linebreak
463
-        $output = substr($output, 0, -6);
464
-        if (! WP_DEBUG) {
465
-            $output .= '
459
+			}
460
+			$this->write_to_error_log($time, $ex);
461
+		}
462
+		// remove last linebreak
463
+		$output = substr($output, 0, -6);
464
+		if (! WP_DEBUG) {
465
+			$output .= '
466 466
 	</p>';
467
-        }
468
-        $output .= '
467
+		}
468
+		$output .= '
469 469
 </div>';
470
-        $output .= self::_print_scripts(true);
471
-        if (defined('DOING_AJAX')) {
472
-            echo wp_json_encode(array('error' => $output));
473
-            exit();
474
-        }
475
-        echo $output;
476
-        die();
477
-    }
478
-
479
-
480
-
481
-    /**
482
-     *    generate string from exception trace args
483
-     *
484
-     * @param array $arguments
485
-     * @param bool  $array
486
-     * @return string
487
-     */
488
-    private function _convert_args_to_string($arguments = array(), $array = false)
489
-    {
490
-        $arg_string = '';
491
-        if (! empty($arguments)) {
492
-            $args = array();
493
-            foreach ($arguments as $arg) {
494
-                if (! empty($arg)) {
495
-                    if (is_string($arg)) {
496
-                        $args[] = " '" . $arg . "'";
497
-                    } elseif (is_array($arg)) {
498
-                        $args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true);
499
-                    } elseif ($arg === null) {
500
-                        $args[] = ' NULL';
501
-                    } elseif (is_bool($arg)) {
502
-                        $args[] = ($arg) ? ' TRUE' : ' FALSE';
503
-                    } elseif (is_object($arg)) {
504
-                        $args[] = ' OBJECT ' . get_class($arg);
505
-                    } elseif (is_resource($arg)) {
506
-                        $args[] = get_resource_type($arg);
507
-                    } else {
508
-                        $args[] = $arg;
509
-                    }
510
-                }
511
-            }
512
-            $arg_string = implode(', ', $args);
513
-        }
514
-        if ($array) {
515
-            $arg_string .= ' )';
516
-        }
517
-        return $arg_string;
518
-    }
519
-
520
-
521
-
522
-    /**
523
-     *    add error message
524
-     *
525
-     * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
526
-     *                            separate messages for user || dev
527
-     * @param        string $file the file that the error occurred in - just use __FILE__
528
-     * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
529
-     * @param        string $line the line number where the error occurred - just use __LINE__
530
-     * @return        void
531
-     */
532
-    public static function add_error($msg = null, $file = null, $func = null, $line = null)
533
-    {
534
-        self::_add_notice('errors', $msg, $file, $func, $line);
535
-        self::$_error_count++;
536
-    }
537
-
538
-
539
-
540
-    /**
541
-     * If WP_DEBUG is active, throws an exception. If WP_DEBUG is off, just
542
-     * adds an error
543
-     *
544
-     * @param string $msg
545
-     * @param string $file
546
-     * @param string $func
547
-     * @param string $line
548
-     * @throws EE_Error
549
-     */
550
-    public static function throw_exception_if_debugging($msg = null, $file = null, $func = null, $line = null)
551
-    {
552
-        if (WP_DEBUG) {
553
-            throw new EE_Error($msg);
554
-        }
555
-        EE_Error::add_error($msg, $file, $func, $line);
556
-    }
557
-
558
-
559
-
560
-    /**
561
-     *    add success message
562
-     *
563
-     * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
564
-     *                            separate messages for user || dev
565
-     * @param        string $file the file that the error occurred in - just use __FILE__
566
-     * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
567
-     * @param        string $line the line number where the error occurred - just use __LINE__
568
-     * @return        void
569
-     */
570
-    public static function add_success($msg = null, $file = null, $func = null, $line = null)
571
-    {
572
-        self::_add_notice('success', $msg, $file, $func, $line);
573
-    }
574
-
575
-
576
-
577
-    /**
578
-     *    add attention message
579
-     *
580
-     * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
581
-     *                            separate messages for user || dev
582
-     * @param        string $file the file that the error occurred in - just use __FILE__
583
-     * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
584
-     * @param        string $line the line number where the error occurred - just use __LINE__
585
-     * @return        void
586
-     */
587
-    public static function add_attention($msg = null, $file = null, $func = null, $line = null)
588
-    {
589
-        self::_add_notice('attention', $msg, $file, $func, $line);
590
-    }
591
-
592
-
593
-
594
-    /**
595
-     *    add success message
596
-     *
597
-     * @param        string $type whether the message is for a success or error notification
598
-     * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
599
-     *                            separate messages for user || dev
600
-     * @param        string $file the file that the error occurred in - just use __FILE__
601
-     * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
602
-     * @param        string $line the line number where the error occurred - just use __LINE__
603
-     * @return        void
604
-     */
605
-    private static function _add_notice($type = 'success', $msg = null, $file = null, $func = null, $line = null)
606
-    {
607
-        if (empty($msg)) {
608
-            EE_Error::doing_it_wrong(
609
-                'EE_Error::add_' . $type . '()',
610
-                sprintf(
611
-                    __('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d',
612
-                        'event_espresso'),
613
-                    $type,
614
-                    $file,
615
-                    $line
616
-                ),
617
-                EVENT_ESPRESSO_VERSION
618
-            );
619
-        }
620
-        if ($type === 'errors' && (empty($file) || empty($func) || empty($line))) {
621
-            EE_Error::doing_it_wrong(
622
-                'EE_Error::add_error()',
623
-                __('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.',
624
-                    'event_espresso'),
625
-                EVENT_ESPRESSO_VERSION
626
-            );
627
-        }
628
-        // get separate user and developer messages if they exist
629
-        $msg = explode('||', $msg);
630
-        $user_msg = $msg[0];
631
-        $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0];
632
-        /**
633
-         * Do an action so other code can be triggered when a notice is created
634
-         *
635
-         * @param string $type     can be 'errors', 'attention', or 'success'
636
-         * @param string $user_msg message displayed to user when WP_DEBUG is off
637
-         * @param string $user_msg message displayed to user when WP_DEBUG is on
638
-         * @param string $file     file where error was generated
639
-         * @param string $func     function where error was generated
640
-         * @param string $line     line where error was generated
641
-         */
642
-        do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line);
643
-        $msg = WP_DEBUG ? $dev_msg : $user_msg;
644
-        // add notice if message exists
645
-        if (! empty($msg)) {
646
-            // get error code
647
-            $notice_code = EE_Error::generate_error_code($file, $func, $line);
648
-            if (WP_DEBUG && $type === 'errors') {
649
-                $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>';
650
-            }
651
-            // add notice. Index by code if it's not blank
652
-            if ($notice_code) {
653
-                self::$_espresso_notices[$type][$notice_code] = $msg;
654
-            } else {
655
-                self::$_espresso_notices[$type][] = $msg;
656
-            }
657
-            add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1);
658
-        }
659
-    }
660
-
661
-
662
-
663
-    /**
664
-     *    in some case it may be necessary to overwrite the existing success messages
665
-     *
666
-     * @return        void
667
-     */
668
-    public static function overwrite_success()
669
-    {
670
-        self::$_espresso_notices['success'] = false;
671
-    }
672
-
673
-
674
-
675
-    /**
676
-     *    in some case it may be necessary to overwrite the existing attention messages
677
-     *
678
-     * @return        void
679
-     */
680
-    public static function overwrite_attention()
681
-    {
682
-        self::$_espresso_notices['attention'] = false;
683
-    }
684
-
685
-
686
-
687
-    /**
688
-     *    in some case it may be necessary to overwrite the existing error messages
689
-     *
690
-     * @return        void
691
-     */
692
-    public static function overwrite_errors()
693
-    {
694
-        self::$_espresso_notices['errors'] = false;
695
-    }
696
-
697
-
698
-
699
-    /**
700
-     *    reset_notices
701
-     *
702
-     * @return void
703
-     */
704
-    public static function reset_notices()
705
-    {
706
-        self::$_espresso_notices['success'] = false;
707
-        self::$_espresso_notices['attention'] = false;
708
-        self::$_espresso_notices['errors'] = false;
709
-    }
710
-
711
-
712
-
713
-    /**
714
-     *    has_errors
715
-     *
716
-     * @return int
717
-     */
718
-    public static function has_notices()
719
-    {
720
-        $has_notices = 0;
721
-        // check for success messages
722
-        $has_notices = self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success']) ? 3
723
-            : $has_notices;
724
-        // check for attention messages
725
-        $has_notices = self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention']) ? 2
726
-            : $has_notices;
727
-        // check for error messages
728
-        $has_notices = self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors']) ? 1
729
-            : $has_notices;
730
-        return $has_notices;
731
-    }
732
-
733
-
734
-
735
-    /**
736
-     * This simply returns non formatted error notices as they were sent into the EE_Error object.
737
-     *
738
-     * @since 4.9.0
739
-     * @return array
740
-     */
741
-    public static function get_vanilla_notices()
742
-    {
743
-        return array(
744
-            'success'   => isset(self::$_espresso_notices['success']) ? self::$_espresso_notices['success'] : array(),
745
-            'attention' => isset(self::$_espresso_notices['attention']) ? self::$_espresso_notices['attention']
746
-                : array(),
747
-            'errors'    => isset(self::$_espresso_notices['errors']) ? self::$_espresso_notices['errors'] : array(),
748
-        );
749
-    }
750
-
751
-
752
-
753
-    /**
754
-     *    compile all error or success messages into one string
755
-     *
756
-     * @see EE_Error::get_raw_notices if you want the raw notices without any preparations made to them
757
-     * @param        boolean $format_output     whether or not to format the messages for display in the WP admin
758
-     * @param        boolean $save_to_transient whether or not to save notices to the db for retrieval on next request
759
-     *                                          - ONLY do this just before redirecting
760
-     * @param        boolean $remove_empty      whether or not to unset empty messages
761
-     * @return        array
762
-     */
763
-    public static function get_notices($format_output = true, $save_to_transient = false, $remove_empty = true)
764
-    {
765
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
766
-        $success_messages = '';
767
-        $attention_messages = '';
768
-        $error_messages = '';
769
-        $print_scripts = false;
770
-        // either save notices to the db
771
-        if ($save_to_transient) {
772
-            update_option('ee_notices', self::$_espresso_notices);
773
-            return array();
774
-        }
775
-        // grab any notices that have been previously saved
776
-        if ($notices = get_option('ee_notices', false)) {
777
-            foreach ($notices as $type => $notice) {
778
-                if (is_array($notice) && ! empty($notice)) {
779
-                    // make sure that existing notice type is an array
780
-                    self::$_espresso_notices[$type] = is_array(self::$_espresso_notices[$type])
781
-                                                      && ! empty(self::$_espresso_notices[$type])
782
-                        ? self::$_espresso_notices[$type] : array();
783
-                    // merge stored notices with any newly created ones
784
-                    self::$_espresso_notices[$type] = array_merge(self::$_espresso_notices[$type], $notice);
785
-                    $print_scripts = true;
786
-                }
787
-            }
788
-            // now clear any stored notices
789
-            update_option('ee_notices', false);
790
-        }
791
-        // check for success messages
792
-        if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) {
793
-            // combine messages
794
-            $success_messages .= implode(self::$_espresso_notices['success'], '<br /><br />');
795
-            $print_scripts = true;
796
-        }
797
-        // check for attention messages
798
-        if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) {
799
-            // combine messages
800
-            $attention_messages .= implode(self::$_espresso_notices['attention'], '<br /><br />');
801
-            $print_scripts = true;
802
-        }
803
-        // check for error messages
804
-        if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) {
805
-            $error_messages .= count(self::$_espresso_notices['errors']) > 1
806
-                ? __('The following errors have occurred:<br />', 'event_espresso')
807
-                : __('An error has occurred:<br />', 'event_espresso');
808
-            // combine messages
809
-            $error_messages .= implode(self::$_espresso_notices['errors'], '<br /><br />');
810
-            $print_scripts = true;
811
-        }
812
-        self::$_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false);
813
-        if ($format_output) {
814
-            $notices = '<div id="espresso-notices">';
815
-            $close = is_admin() ? ''
816
-                : '<a class="close-espresso-notice hide-if-no-js"><span class="dashicons dashicons-no"></span></a>';
817
-            if ($success_messages !== '') {
818
-                $css_id = is_admin() ? 'message' : 'espresso-notices-success';
819
-                $css_class = is_admin() ? 'updated fade' : 'success fade-away';
820
-                //showMessage( $success_messages );
821
-                $notices .= '<div id="'
822
-                            . $css_id
823
-                            . '" class="espresso-notices '
824
-                            . $css_class
825
-                            . '" style="display:none;"><p>'
826
-                            . $success_messages
827
-                            . '</p>'
828
-                            . $close
829
-                            . '</div>';
830
-            }
831
-            if ($attention_messages !== '') {
832
-                $css_id = is_admin() ? 'message' : 'espresso-notices-attention';
833
-                $css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away';
834
-                //showMessage( $error_messages, TRUE );
835
-                $notices .= '<div id="'
836
-                            . $css_id
837
-                            . '" class="espresso-notices '
838
-                            . $css_class
839
-                            . '" style="display:none;"><p>'
840
-                            . $attention_messages
841
-                            . '</p>'
842
-                            . $close
843
-                            . '</div>';
844
-            }
845
-            if ($error_messages !== '') {
846
-                $css_id = is_admin() ? 'message' : 'espresso-notices-error';
847
-                $css_class = is_admin() ? 'error' : 'error fade-away';
848
-                //showMessage( $error_messages, TRUE );
849
-                $notices .= '<div id="'
850
-                            . $css_id
851
-                            . '" class="espresso-notices '
852
-                            . $css_class
853
-                            . '" style="display:none;"><p>'
854
-                            . $error_messages
855
-                            . '</p>'
856
-                            . $close
857
-                            . '</div>';
858
-            }
859
-            $notices .= '</div>';
860
-        } else {
861
-            $notices = array(
862
-                'success'   => $success_messages,
863
-                'attention' => $attention_messages,
864
-                'errors'    => $error_messages,
865
-            );
866
-            if ($remove_empty) {
867
-                // remove empty notices
868
-                foreach ($notices as $type => $notice) {
869
-                    if (empty($notice)) {
870
-                        unset($notices[$type]);
871
-                    }
872
-                }
873
-            }
874
-        }
875
-        if ($print_scripts) {
876
-            self::_print_scripts();
877
-        }
878
-        return $notices;
879
-    }
880
-
881
-
882
-
883
-    /**
884
-     *    add_persistent_admin_notice
885
-     *
886
-     * @param        string $pan_name     the name, or key of the Persistent Admin Notice to be stored
887
-     * @param        string $pan_message  the message to be stored persistently until dismissed
888
-     * @param bool          $force_update allows one to enforce the reappearance of a persistent message.
889
-     * @return        void
890
-     */
891
-    public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false)
892
-    {
893
-        if (! empty($pan_name) && ! empty($pan_message)) {
894
-            $persistent_admin_notices = get_option('ee_pers_admin_notices', array());
895
-            //maybe initialize persistent_admin_notices
896
-            if (empty($persistent_admin_notices)) {
897
-                add_option('ee_pers_admin_notices', array(), '', 'no');
898
-            }
899
-            $pan_name = sanitize_key($pan_name);
900
-            if (! array_key_exists($pan_name, $persistent_admin_notices) || $force_update) {
901
-                $persistent_admin_notices[$pan_name] = $pan_message;
902
-                update_option('ee_pers_admin_notices', $persistent_admin_notices);
903
-            }
904
-        }
905
-    }
906
-
907
-
908
-
909
-    /**
910
-     *    dismiss_persistent_admin_notice
911
-     *
912
-     * @param        string $pan_name the name, or key of the Persistent Admin Notice to be dismissed
913
-     * @param bool          $purge
914
-     * @param bool          $return_immediately
915
-     * @return        void
916
-     */
917
-    public static function dismiss_persistent_admin_notice($pan_name = '', $purge = false, $return_immediately = false)
918
-    {
919
-        $pan_name = EE_Registry::instance()->REQ->is_set('ee_nag_notice')
920
-            ? EE_Registry::instance()->REQ->get('ee_nag_notice') : $pan_name;
921
-        if (! empty($pan_name)) {
922
-            $persistent_admin_notices = get_option('ee_pers_admin_notices', array());
923
-            // check if notice we wish to dismiss is actually in the $persistent_admin_notices array
924
-            if (is_array($persistent_admin_notices) && isset($persistent_admin_notices[$pan_name])) {
925
-                // completely delete nag notice, or just NULL message so that it can NOT be added again ?
926
-                if ($purge) {
927
-                    unset($persistent_admin_notices[$pan_name]);
928
-                } else {
929
-                    $persistent_admin_notices[$pan_name] = null;
930
-                }
931
-                if (update_option('ee_pers_admin_notices', $persistent_admin_notices) === false) {
932
-                    EE_Error::add_error(sprintf(__('The persistent admin notice for "%s" could not be deleted.',
933
-                        'event_espresso'), $pan_name), __FILE__, __FUNCTION__, __LINE__);
934
-                }
935
-            }
936
-        }
937
-        if ($return_immediately) {
938
-            return;
939
-        }
940
-        if (EE_Registry::instance()->REQ->ajax) {
941
-            // grab any notices and concatenate into string
942
-            echo wp_json_encode(array('errors' => implode('<br />', EE_Error::get_notices(false))));
943
-            exit();
944
-        }
945
-        // save errors to a transient to be displayed on next request (after redirect)
946
-        EE_Error::get_notices(false, true);
947
-        $return_url = EE_Registry::instance()->REQ->is_set('return_url')
948
-            ? EE_Registry::instance()->REQ->get('return_url') : '';
949
-        wp_safe_redirect(urldecode($return_url));
950
-    }
951
-
952
-
953
-
954
-    /**
955
-     * display_persistent_admin_notices
956
-     *
957
-     * @param  string $pan_name    the name, or key of the Persistent Admin Notice to be stored
958
-     * @param  string $pan_message the message to be stored persistently until dismissed
959
-     * @param  string $return_url  URL to go back to after nag notice is dismissed
960
-     * @return string
961
-     */
962
-    public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '')
963
-    {
964
-        if (! empty($pan_name) && ! empty($pan_message)) {
965
-            $args = array(
966
-                'nag_notice'    => $pan_name,
967
-                'return_url'    => urlencode($return_url),
968
-                'ajax_url'      => WP_AJAX_URL,
969
-                'unknown_error' => __('An unknown error has occurred on the server while attempting to dismiss this notice.',
970
-                    'event_espresso'),
971
-            );
972
-            wp_localize_script('espresso_core', 'ee_dismiss', $args);
973
-            return '
470
+		$output .= self::_print_scripts(true);
471
+		if (defined('DOING_AJAX')) {
472
+			echo wp_json_encode(array('error' => $output));
473
+			exit();
474
+		}
475
+		echo $output;
476
+		die();
477
+	}
478
+
479
+
480
+
481
+	/**
482
+	 *    generate string from exception trace args
483
+	 *
484
+	 * @param array $arguments
485
+	 * @param bool  $array
486
+	 * @return string
487
+	 */
488
+	private function _convert_args_to_string($arguments = array(), $array = false)
489
+	{
490
+		$arg_string = '';
491
+		if (! empty($arguments)) {
492
+			$args = array();
493
+			foreach ($arguments as $arg) {
494
+				if (! empty($arg)) {
495
+					if (is_string($arg)) {
496
+						$args[] = " '" . $arg . "'";
497
+					} elseif (is_array($arg)) {
498
+						$args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true);
499
+					} elseif ($arg === null) {
500
+						$args[] = ' NULL';
501
+					} elseif (is_bool($arg)) {
502
+						$args[] = ($arg) ? ' TRUE' : ' FALSE';
503
+					} elseif (is_object($arg)) {
504
+						$args[] = ' OBJECT ' . get_class($arg);
505
+					} elseif (is_resource($arg)) {
506
+						$args[] = get_resource_type($arg);
507
+					} else {
508
+						$args[] = $arg;
509
+					}
510
+				}
511
+			}
512
+			$arg_string = implode(', ', $args);
513
+		}
514
+		if ($array) {
515
+			$arg_string .= ' )';
516
+		}
517
+		return $arg_string;
518
+	}
519
+
520
+
521
+
522
+	/**
523
+	 *    add error message
524
+	 *
525
+	 * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
526
+	 *                            separate messages for user || dev
527
+	 * @param        string $file the file that the error occurred in - just use __FILE__
528
+	 * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
529
+	 * @param        string $line the line number where the error occurred - just use __LINE__
530
+	 * @return        void
531
+	 */
532
+	public static function add_error($msg = null, $file = null, $func = null, $line = null)
533
+	{
534
+		self::_add_notice('errors', $msg, $file, $func, $line);
535
+		self::$_error_count++;
536
+	}
537
+
538
+
539
+
540
+	/**
541
+	 * If WP_DEBUG is active, throws an exception. If WP_DEBUG is off, just
542
+	 * adds an error
543
+	 *
544
+	 * @param string $msg
545
+	 * @param string $file
546
+	 * @param string $func
547
+	 * @param string $line
548
+	 * @throws EE_Error
549
+	 */
550
+	public static function throw_exception_if_debugging($msg = null, $file = null, $func = null, $line = null)
551
+	{
552
+		if (WP_DEBUG) {
553
+			throw new EE_Error($msg);
554
+		}
555
+		EE_Error::add_error($msg, $file, $func, $line);
556
+	}
557
+
558
+
559
+
560
+	/**
561
+	 *    add success message
562
+	 *
563
+	 * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
564
+	 *                            separate messages for user || dev
565
+	 * @param        string $file the file that the error occurred in - just use __FILE__
566
+	 * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
567
+	 * @param        string $line the line number where the error occurred - just use __LINE__
568
+	 * @return        void
569
+	 */
570
+	public static function add_success($msg = null, $file = null, $func = null, $line = null)
571
+	{
572
+		self::_add_notice('success', $msg, $file, $func, $line);
573
+	}
574
+
575
+
576
+
577
+	/**
578
+	 *    add attention message
579
+	 *
580
+	 * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
581
+	 *                            separate messages for user || dev
582
+	 * @param        string $file the file that the error occurred in - just use __FILE__
583
+	 * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
584
+	 * @param        string $line the line number where the error occurred - just use __LINE__
585
+	 * @return        void
586
+	 */
587
+	public static function add_attention($msg = null, $file = null, $func = null, $line = null)
588
+	{
589
+		self::_add_notice('attention', $msg, $file, $func, $line);
590
+	}
591
+
592
+
593
+
594
+	/**
595
+	 *    add success message
596
+	 *
597
+	 * @param        string $type whether the message is for a success or error notification
598
+	 * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
599
+	 *                            separate messages for user || dev
600
+	 * @param        string $file the file that the error occurred in - just use __FILE__
601
+	 * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
602
+	 * @param        string $line the line number where the error occurred - just use __LINE__
603
+	 * @return        void
604
+	 */
605
+	private static function _add_notice($type = 'success', $msg = null, $file = null, $func = null, $line = null)
606
+	{
607
+		if (empty($msg)) {
608
+			EE_Error::doing_it_wrong(
609
+				'EE_Error::add_' . $type . '()',
610
+				sprintf(
611
+					__('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d',
612
+						'event_espresso'),
613
+					$type,
614
+					$file,
615
+					$line
616
+				),
617
+				EVENT_ESPRESSO_VERSION
618
+			);
619
+		}
620
+		if ($type === 'errors' && (empty($file) || empty($func) || empty($line))) {
621
+			EE_Error::doing_it_wrong(
622
+				'EE_Error::add_error()',
623
+				__('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.',
624
+					'event_espresso'),
625
+				EVENT_ESPRESSO_VERSION
626
+			);
627
+		}
628
+		// get separate user and developer messages if they exist
629
+		$msg = explode('||', $msg);
630
+		$user_msg = $msg[0];
631
+		$dev_msg = isset($msg[1]) ? $msg[1] : $msg[0];
632
+		/**
633
+		 * Do an action so other code can be triggered when a notice is created
634
+		 *
635
+		 * @param string $type     can be 'errors', 'attention', or 'success'
636
+		 * @param string $user_msg message displayed to user when WP_DEBUG is off
637
+		 * @param string $user_msg message displayed to user when WP_DEBUG is on
638
+		 * @param string $file     file where error was generated
639
+		 * @param string $func     function where error was generated
640
+		 * @param string $line     line where error was generated
641
+		 */
642
+		do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line);
643
+		$msg = WP_DEBUG ? $dev_msg : $user_msg;
644
+		// add notice if message exists
645
+		if (! empty($msg)) {
646
+			// get error code
647
+			$notice_code = EE_Error::generate_error_code($file, $func, $line);
648
+			if (WP_DEBUG && $type === 'errors') {
649
+				$msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>';
650
+			}
651
+			// add notice. Index by code if it's not blank
652
+			if ($notice_code) {
653
+				self::$_espresso_notices[$type][$notice_code] = $msg;
654
+			} else {
655
+				self::$_espresso_notices[$type][] = $msg;
656
+			}
657
+			add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1);
658
+		}
659
+	}
660
+
661
+
662
+
663
+	/**
664
+	 *    in some case it may be necessary to overwrite the existing success messages
665
+	 *
666
+	 * @return        void
667
+	 */
668
+	public static function overwrite_success()
669
+	{
670
+		self::$_espresso_notices['success'] = false;
671
+	}
672
+
673
+
674
+
675
+	/**
676
+	 *    in some case it may be necessary to overwrite the existing attention messages
677
+	 *
678
+	 * @return        void
679
+	 */
680
+	public static function overwrite_attention()
681
+	{
682
+		self::$_espresso_notices['attention'] = false;
683
+	}
684
+
685
+
686
+
687
+	/**
688
+	 *    in some case it may be necessary to overwrite the existing error messages
689
+	 *
690
+	 * @return        void
691
+	 */
692
+	public static function overwrite_errors()
693
+	{
694
+		self::$_espresso_notices['errors'] = false;
695
+	}
696
+
697
+
698
+
699
+	/**
700
+	 *    reset_notices
701
+	 *
702
+	 * @return void
703
+	 */
704
+	public static function reset_notices()
705
+	{
706
+		self::$_espresso_notices['success'] = false;
707
+		self::$_espresso_notices['attention'] = false;
708
+		self::$_espresso_notices['errors'] = false;
709
+	}
710
+
711
+
712
+
713
+	/**
714
+	 *    has_errors
715
+	 *
716
+	 * @return int
717
+	 */
718
+	public static function has_notices()
719
+	{
720
+		$has_notices = 0;
721
+		// check for success messages
722
+		$has_notices = self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success']) ? 3
723
+			: $has_notices;
724
+		// check for attention messages
725
+		$has_notices = self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention']) ? 2
726
+			: $has_notices;
727
+		// check for error messages
728
+		$has_notices = self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors']) ? 1
729
+			: $has_notices;
730
+		return $has_notices;
731
+	}
732
+
733
+
734
+
735
+	/**
736
+	 * This simply returns non formatted error notices as they were sent into the EE_Error object.
737
+	 *
738
+	 * @since 4.9.0
739
+	 * @return array
740
+	 */
741
+	public static function get_vanilla_notices()
742
+	{
743
+		return array(
744
+			'success'   => isset(self::$_espresso_notices['success']) ? self::$_espresso_notices['success'] : array(),
745
+			'attention' => isset(self::$_espresso_notices['attention']) ? self::$_espresso_notices['attention']
746
+				: array(),
747
+			'errors'    => isset(self::$_espresso_notices['errors']) ? self::$_espresso_notices['errors'] : array(),
748
+		);
749
+	}
750
+
751
+
752
+
753
+	/**
754
+	 *    compile all error or success messages into one string
755
+	 *
756
+	 * @see EE_Error::get_raw_notices if you want the raw notices without any preparations made to them
757
+	 * @param        boolean $format_output     whether or not to format the messages for display in the WP admin
758
+	 * @param        boolean $save_to_transient whether or not to save notices to the db for retrieval on next request
759
+	 *                                          - ONLY do this just before redirecting
760
+	 * @param        boolean $remove_empty      whether or not to unset empty messages
761
+	 * @return        array
762
+	 */
763
+	public static function get_notices($format_output = true, $save_to_transient = false, $remove_empty = true)
764
+	{
765
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
766
+		$success_messages = '';
767
+		$attention_messages = '';
768
+		$error_messages = '';
769
+		$print_scripts = false;
770
+		// either save notices to the db
771
+		if ($save_to_transient) {
772
+			update_option('ee_notices', self::$_espresso_notices);
773
+			return array();
774
+		}
775
+		// grab any notices that have been previously saved
776
+		if ($notices = get_option('ee_notices', false)) {
777
+			foreach ($notices as $type => $notice) {
778
+				if (is_array($notice) && ! empty($notice)) {
779
+					// make sure that existing notice type is an array
780
+					self::$_espresso_notices[$type] = is_array(self::$_espresso_notices[$type])
781
+													  && ! empty(self::$_espresso_notices[$type])
782
+						? self::$_espresso_notices[$type] : array();
783
+					// merge stored notices with any newly created ones
784
+					self::$_espresso_notices[$type] = array_merge(self::$_espresso_notices[$type], $notice);
785
+					$print_scripts = true;
786
+				}
787
+			}
788
+			// now clear any stored notices
789
+			update_option('ee_notices', false);
790
+		}
791
+		// check for success messages
792
+		if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) {
793
+			// combine messages
794
+			$success_messages .= implode(self::$_espresso_notices['success'], '<br /><br />');
795
+			$print_scripts = true;
796
+		}
797
+		// check for attention messages
798
+		if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) {
799
+			// combine messages
800
+			$attention_messages .= implode(self::$_espresso_notices['attention'], '<br /><br />');
801
+			$print_scripts = true;
802
+		}
803
+		// check for error messages
804
+		if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) {
805
+			$error_messages .= count(self::$_espresso_notices['errors']) > 1
806
+				? __('The following errors have occurred:<br />', 'event_espresso')
807
+				: __('An error has occurred:<br />', 'event_espresso');
808
+			// combine messages
809
+			$error_messages .= implode(self::$_espresso_notices['errors'], '<br /><br />');
810
+			$print_scripts = true;
811
+		}
812
+		self::$_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false);
813
+		if ($format_output) {
814
+			$notices = '<div id="espresso-notices">';
815
+			$close = is_admin() ? ''
816
+				: '<a class="close-espresso-notice hide-if-no-js"><span class="dashicons dashicons-no"></span></a>';
817
+			if ($success_messages !== '') {
818
+				$css_id = is_admin() ? 'message' : 'espresso-notices-success';
819
+				$css_class = is_admin() ? 'updated fade' : 'success fade-away';
820
+				//showMessage( $success_messages );
821
+				$notices .= '<div id="'
822
+							. $css_id
823
+							. '" class="espresso-notices '
824
+							. $css_class
825
+							. '" style="display:none;"><p>'
826
+							. $success_messages
827
+							. '</p>'
828
+							. $close
829
+							. '</div>';
830
+			}
831
+			if ($attention_messages !== '') {
832
+				$css_id = is_admin() ? 'message' : 'espresso-notices-attention';
833
+				$css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away';
834
+				//showMessage( $error_messages, TRUE );
835
+				$notices .= '<div id="'
836
+							. $css_id
837
+							. '" class="espresso-notices '
838
+							. $css_class
839
+							. '" style="display:none;"><p>'
840
+							. $attention_messages
841
+							. '</p>'
842
+							. $close
843
+							. '</div>';
844
+			}
845
+			if ($error_messages !== '') {
846
+				$css_id = is_admin() ? 'message' : 'espresso-notices-error';
847
+				$css_class = is_admin() ? 'error' : 'error fade-away';
848
+				//showMessage( $error_messages, TRUE );
849
+				$notices .= '<div id="'
850
+							. $css_id
851
+							. '" class="espresso-notices '
852
+							. $css_class
853
+							. '" style="display:none;"><p>'
854
+							. $error_messages
855
+							. '</p>'
856
+							. $close
857
+							. '</div>';
858
+			}
859
+			$notices .= '</div>';
860
+		} else {
861
+			$notices = array(
862
+				'success'   => $success_messages,
863
+				'attention' => $attention_messages,
864
+				'errors'    => $error_messages,
865
+			);
866
+			if ($remove_empty) {
867
+				// remove empty notices
868
+				foreach ($notices as $type => $notice) {
869
+					if (empty($notice)) {
870
+						unset($notices[$type]);
871
+					}
872
+				}
873
+			}
874
+		}
875
+		if ($print_scripts) {
876
+			self::_print_scripts();
877
+		}
878
+		return $notices;
879
+	}
880
+
881
+
882
+
883
+	/**
884
+	 *    add_persistent_admin_notice
885
+	 *
886
+	 * @param        string $pan_name     the name, or key of the Persistent Admin Notice to be stored
887
+	 * @param        string $pan_message  the message to be stored persistently until dismissed
888
+	 * @param bool          $force_update allows one to enforce the reappearance of a persistent message.
889
+	 * @return        void
890
+	 */
891
+	public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false)
892
+	{
893
+		if (! empty($pan_name) && ! empty($pan_message)) {
894
+			$persistent_admin_notices = get_option('ee_pers_admin_notices', array());
895
+			//maybe initialize persistent_admin_notices
896
+			if (empty($persistent_admin_notices)) {
897
+				add_option('ee_pers_admin_notices', array(), '', 'no');
898
+			}
899
+			$pan_name = sanitize_key($pan_name);
900
+			if (! array_key_exists($pan_name, $persistent_admin_notices) || $force_update) {
901
+				$persistent_admin_notices[$pan_name] = $pan_message;
902
+				update_option('ee_pers_admin_notices', $persistent_admin_notices);
903
+			}
904
+		}
905
+	}
906
+
907
+
908
+
909
+	/**
910
+	 *    dismiss_persistent_admin_notice
911
+	 *
912
+	 * @param        string $pan_name the name, or key of the Persistent Admin Notice to be dismissed
913
+	 * @param bool          $purge
914
+	 * @param bool          $return_immediately
915
+	 * @return        void
916
+	 */
917
+	public static function dismiss_persistent_admin_notice($pan_name = '', $purge = false, $return_immediately = false)
918
+	{
919
+		$pan_name = EE_Registry::instance()->REQ->is_set('ee_nag_notice')
920
+			? EE_Registry::instance()->REQ->get('ee_nag_notice') : $pan_name;
921
+		if (! empty($pan_name)) {
922
+			$persistent_admin_notices = get_option('ee_pers_admin_notices', array());
923
+			// check if notice we wish to dismiss is actually in the $persistent_admin_notices array
924
+			if (is_array($persistent_admin_notices) && isset($persistent_admin_notices[$pan_name])) {
925
+				// completely delete nag notice, or just NULL message so that it can NOT be added again ?
926
+				if ($purge) {
927
+					unset($persistent_admin_notices[$pan_name]);
928
+				} else {
929
+					$persistent_admin_notices[$pan_name] = null;
930
+				}
931
+				if (update_option('ee_pers_admin_notices', $persistent_admin_notices) === false) {
932
+					EE_Error::add_error(sprintf(__('The persistent admin notice for "%s" could not be deleted.',
933
+						'event_espresso'), $pan_name), __FILE__, __FUNCTION__, __LINE__);
934
+				}
935
+			}
936
+		}
937
+		if ($return_immediately) {
938
+			return;
939
+		}
940
+		if (EE_Registry::instance()->REQ->ajax) {
941
+			// grab any notices and concatenate into string
942
+			echo wp_json_encode(array('errors' => implode('<br />', EE_Error::get_notices(false))));
943
+			exit();
944
+		}
945
+		// save errors to a transient to be displayed on next request (after redirect)
946
+		EE_Error::get_notices(false, true);
947
+		$return_url = EE_Registry::instance()->REQ->is_set('return_url')
948
+			? EE_Registry::instance()->REQ->get('return_url') : '';
949
+		wp_safe_redirect(urldecode($return_url));
950
+	}
951
+
952
+
953
+
954
+	/**
955
+	 * display_persistent_admin_notices
956
+	 *
957
+	 * @param  string $pan_name    the name, or key of the Persistent Admin Notice to be stored
958
+	 * @param  string $pan_message the message to be stored persistently until dismissed
959
+	 * @param  string $return_url  URL to go back to after nag notice is dismissed
960
+	 * @return string
961
+	 */
962
+	public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '')
963
+	{
964
+		if (! empty($pan_name) && ! empty($pan_message)) {
965
+			$args = array(
966
+				'nag_notice'    => $pan_name,
967
+				'return_url'    => urlencode($return_url),
968
+				'ajax_url'      => WP_AJAX_URL,
969
+				'unknown_error' => __('An unknown error has occurred on the server while attempting to dismiss this notice.',
970
+					'event_espresso'),
971
+			);
972
+			wp_localize_script('espresso_core', 'ee_dismiss', $args);
973
+			return '
974 974
 			<div id="'
975
-                   . $pan_name
976
-                   . '" class="espresso-notices updated ee-nag-notice clearfix" style="border-left: 4px solid #fcb93c;">
975
+				   . $pan_name
976
+				   . '" class="espresso-notices updated ee-nag-notice clearfix" style="border-left: 4px solid #fcb93c;">
977 977
 				<p>'
978
-                   . $pan_message
979
-                   . '</p>
978
+				   . $pan_message
979
+				   . '</p>
980 980
 				<a class="dismiss-ee-nag-notice hide-if-no-js" style="float: right; cursor: pointer; text-decoration:none;" rel="'
981
-                   . $pan_name
982
-                   . '">
981
+				   . $pan_name
982
+				   . '">
983 983
 					<span class="dashicons dashicons-dismiss" style="position:relative; top:-1px; margin-right:.25em;"></span>'
984
-                   . __('Dismiss', 'event_espresso')
985
-                   . '
984
+				   . __('Dismiss', 'event_espresso')
985
+				   . '
986 986
 				</a>
987 987
 				<div style="clear:both;"></div>
988 988
 			</div>';
989
-        }
990
-        return '';
991
-    }
992
-
993
-
994
-
995
-    /**
996
-     *    get_persistent_admin_notices
997
-     *
998
-     * @param string $return_url
999
-     * @return string
1000
-     */
1001
-    public static function get_persistent_admin_notices($return_url = '')
1002
-    {
1003
-        $notices = '';
1004
-        // check for persistent admin notices
1005
-        //filter the list though so plugins can notify the admin in a different way if they want
1006
-        $persistent_admin_notices = apply_filters(
1007
-            'FHEE__EE_Error__get_persistent_admin_notices',
1008
-            get_option('ee_pers_admin_notices', false),
1009
-            'ee_pers_admin_notices',
1010
-            $return_url
1011
-        );
1012
-        if ($persistent_admin_notices) {
1013
-            // load scripts
1014
-            wp_register_script(
1015
-                'espresso_core',
1016
-                EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
1017
-                array('jquery'),
1018
-                EVENT_ESPRESSO_VERSION,
1019
-                true
1020
-            );
1021
-            wp_register_script(
1022
-                'ee_error_js',
1023
-                EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
1024
-                array('espresso_core'),
1025
-                EVENT_ESPRESSO_VERSION,
1026
-                true
1027
-            );
1028
-            wp_enqueue_script('ee_error_js');
1029
-            // and display notices
1030
-            foreach ($persistent_admin_notices as $pan_name => $pan_message) {
1031
-                $notices .= self::display_persistent_admin_notices($pan_name, $pan_message, $return_url);
1032
-            }
1033
-        }
1034
-        return $notices;
1035
-    }
1036
-
1037
-
1038
-
1039
-    /**
1040
-     * _print_scripts
1041
-     *
1042
-     * @param    bool $force_print
1043
-     * @return    string
1044
-     */
1045
-    private static function _print_scripts($force_print = false)
1046
-    {
1047
-        if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) {
1048
-            if (wp_script_is('ee_error_js', 'enqueued')) {
1049
-                return '';
1050
-            }
1051
-            if (wp_script_is('ee_error_js', 'registered')) {
1052
-                add_filter('FHEE_load_css', '__return_true');
1053
-                add_filter('FHEE_load_js', '__return_true');
1054
-                wp_enqueue_script('ee_error_js');
1055
-                wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG));
1056
-            }
1057
-        } else {
1058
-            return '
989
+		}
990
+		return '';
991
+	}
992
+
993
+
994
+
995
+	/**
996
+	 *    get_persistent_admin_notices
997
+	 *
998
+	 * @param string $return_url
999
+	 * @return string
1000
+	 */
1001
+	public static function get_persistent_admin_notices($return_url = '')
1002
+	{
1003
+		$notices = '';
1004
+		// check for persistent admin notices
1005
+		//filter the list though so plugins can notify the admin in a different way if they want
1006
+		$persistent_admin_notices = apply_filters(
1007
+			'FHEE__EE_Error__get_persistent_admin_notices',
1008
+			get_option('ee_pers_admin_notices', false),
1009
+			'ee_pers_admin_notices',
1010
+			$return_url
1011
+		);
1012
+		if ($persistent_admin_notices) {
1013
+			// load scripts
1014
+			wp_register_script(
1015
+				'espresso_core',
1016
+				EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
1017
+				array('jquery'),
1018
+				EVENT_ESPRESSO_VERSION,
1019
+				true
1020
+			);
1021
+			wp_register_script(
1022
+				'ee_error_js',
1023
+				EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
1024
+				array('espresso_core'),
1025
+				EVENT_ESPRESSO_VERSION,
1026
+				true
1027
+			);
1028
+			wp_enqueue_script('ee_error_js');
1029
+			// and display notices
1030
+			foreach ($persistent_admin_notices as $pan_name => $pan_message) {
1031
+				$notices .= self::display_persistent_admin_notices($pan_name, $pan_message, $return_url);
1032
+			}
1033
+		}
1034
+		return $notices;
1035
+	}
1036
+
1037
+
1038
+
1039
+	/**
1040
+	 * _print_scripts
1041
+	 *
1042
+	 * @param    bool $force_print
1043
+	 * @return    string
1044
+	 */
1045
+	private static function _print_scripts($force_print = false)
1046
+	{
1047
+		if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) {
1048
+			if (wp_script_is('ee_error_js', 'enqueued')) {
1049
+				return '';
1050
+			}
1051
+			if (wp_script_is('ee_error_js', 'registered')) {
1052
+				add_filter('FHEE_load_css', '__return_true');
1053
+				add_filter('FHEE_load_js', '__return_true');
1054
+				wp_enqueue_script('ee_error_js');
1055
+				wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG));
1056
+			}
1057
+		} else {
1058
+			return '
1059 1059
 <script>
1060 1060
 /* <![CDATA[ */
1061 1061
 var ee_settings = {"wp_debug":"' . WP_DEBUG . '"};
@@ -1065,143 +1065,143 @@  discard block
 block discarded – undo
1065 1065
 <script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
1066 1066
 <script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
1067 1067
 ';
1068
-        }
1069
-        return '';
1070
-    }
1071
-
1072
-
1073
-
1074
-    /**
1075
-     *    enqueue_error_scripts
1076
-     *
1077
-     * @return        void
1078
-     */
1079
-    public static function enqueue_error_scripts()
1080
-    {
1081
-        self::_print_scripts();
1082
-    }
1083
-
1084
-
1085
-
1086
-    /**
1087
-     *    create error code from filepath, function name,
1088
-     *    and line number where exception or error was thrown
1089
-     *
1090
-     * @param string $file
1091
-     * @param string $func
1092
-     * @param string $line
1093
-     * @return string
1094
-     */
1095
-    public static function generate_error_code($file = '', $func = '', $line = '')
1096
-    {
1097
-        $file = explode('.', basename($file));
1098
-        $error_code = ! empty($file[0]) ? $file[0] : '';
1099
-        $error_code .= ! empty($func) ? ' - ' . $func : '';
1100
-        $error_code .= ! empty($line) ? ' - ' . $line : '';
1101
-        return $error_code;
1102
-    }
1103
-
1104
-
1105
-
1106
-    /**
1107
-     *    write exception details to log file
1108
-     *
1109
-     * @param int   $time
1110
-     * @param array $ex
1111
-     * @param bool  $clear
1112
-     * @return void
1113
-     */
1114
-    public function write_to_error_log($time = 0, $ex = array(), $clear = false)
1115
-    {
1116
-        if (empty($ex)) {
1117
-            return;
1118
-        }
1119
-        if (! $time) {
1120
-            $time = time();
1121
-        }
1122
-        $exception_log = '----------------------------------------------------------------------------------------'
1123
-                         . PHP_EOL;
1124
-        $exception_log .= '[' . date('Y-m-d H:i:s', $time) . ']  Exception Details' . PHP_EOL;
1125
-        $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL;
1126
-        $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL;
1127
-        $exception_log .= 'File: ' . $ex['file'] . PHP_EOL;
1128
-        $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL;
1129
-        $exception_log .= 'Stack trace: ' . PHP_EOL;
1130
-        $exception_log .= $ex['string'] . PHP_EOL;
1131
-        $exception_log .= '----------------------------------------------------------------------------------------'
1132
-                          . PHP_EOL;
1133
-        try {
1134
-            EEH_File::ensure_file_exists_and_is_writable(
1135
-                EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file
1136
-            );
1137
-            EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs');
1138
-            if (! $clear) {
1139
-                //get existing log file and append new log info
1140
-                $exception_log = EEH_File::get_file_contents(
1141
-                    EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file
1142
-                ) . $exception_log;
1143
-            }
1144
-            EEH_File::write_to_file(
1145
-                EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file,
1146
-                $exception_log
1147
-            );
1148
-        } catch (EE_Error $e) {
1149
-            EE_Error::add_error(sprintf(__('Event Espresso error logging could not be setup because: %s',
1150
-                'event_espresso'), $e->getMessage()));
1151
-            return;
1152
-        }
1153
-    }
1154
-
1155
-
1156
-
1157
-    /**
1158
-     * This is just a wrapper for the EEH_Debug_Tools::instance()->doing_it_wrong() method.
1159
-     * doing_it_wrong() is used in those cases where a normal PHP error won't get thrown,
1160
-     * but the code execution is done in a manner that could lead to unexpected results
1161
-     * (i.e. running to early, or too late in WP or EE loading process).
1162
-     * A good test for knowing whether to use this method is:
1163
-     * 1. Is there going to be a PHP error if something isn't setup/used correctly?
1164
-     * Yes -> use EE_Error::add_error() or throw new EE_Error()
1165
-     * 2. If this is loaded before something else, it won't break anything,
1166
-     * but just wont' do what its supposed to do? Yes -> use EE_Error::doing_it_wrong()
1167
-     *
1168
-     * @uses   constant WP_DEBUG test if wp_debug is on or not
1169
-     * @param string $function      The function that was called
1170
-     * @param string $message       A message explaining what has been done incorrectly
1171
-     * @param string $version       The version of Event Espresso where the error was added
1172
-     * @param string $applies_when  a version string for when you want the doing_it_wrong notice to begin appearing
1173
-     *                              for a deprecated function. This allows deprecation to occur during one version,
1174
-     *                              but not have any notices appear until a later version. This allows developers
1175
-     *                              extra time to update their code before notices appear.
1176
-     * @param int    $error_type
1177
-     */
1178
-    public static function doing_it_wrong(
1179
-        $function,
1180
-        $message,
1181
-        $version,
1182
-        $applies_when = '',
1183
-        $error_type = null
1184
-    ) {
1185
-        if (defined('WP_DEBUG') && WP_DEBUG) {
1186
-            EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type);
1187
-        }
1188
-    }
1189
-
1190
-
1191
-
1192
-    /**
1193
-     * Like get_notices, but returns an array of all the notices of the given type.
1194
-     *
1195
-     * @return array {
1196
-     * @type array $success   all the success messages
1197
-     * @type array $errors    all the error messages
1198
-     * @type array $attention all the attention messages
1199
-     * }
1200
-     */
1201
-    public static function get_raw_notices()
1202
-    {
1203
-        return self::$_espresso_notices;
1204
-    }
1068
+		}
1069
+		return '';
1070
+	}
1071
+
1072
+
1073
+
1074
+	/**
1075
+	 *    enqueue_error_scripts
1076
+	 *
1077
+	 * @return        void
1078
+	 */
1079
+	public static function enqueue_error_scripts()
1080
+	{
1081
+		self::_print_scripts();
1082
+	}
1083
+
1084
+
1085
+
1086
+	/**
1087
+	 *    create error code from filepath, function name,
1088
+	 *    and line number where exception or error was thrown
1089
+	 *
1090
+	 * @param string $file
1091
+	 * @param string $func
1092
+	 * @param string $line
1093
+	 * @return string
1094
+	 */
1095
+	public static function generate_error_code($file = '', $func = '', $line = '')
1096
+	{
1097
+		$file = explode('.', basename($file));
1098
+		$error_code = ! empty($file[0]) ? $file[0] : '';
1099
+		$error_code .= ! empty($func) ? ' - ' . $func : '';
1100
+		$error_code .= ! empty($line) ? ' - ' . $line : '';
1101
+		return $error_code;
1102
+	}
1103
+
1104
+
1105
+
1106
+	/**
1107
+	 *    write exception details to log file
1108
+	 *
1109
+	 * @param int   $time
1110
+	 * @param array $ex
1111
+	 * @param bool  $clear
1112
+	 * @return void
1113
+	 */
1114
+	public function write_to_error_log($time = 0, $ex = array(), $clear = false)
1115
+	{
1116
+		if (empty($ex)) {
1117
+			return;
1118
+		}
1119
+		if (! $time) {
1120
+			$time = time();
1121
+		}
1122
+		$exception_log = '----------------------------------------------------------------------------------------'
1123
+						 . PHP_EOL;
1124
+		$exception_log .= '[' . date('Y-m-d H:i:s', $time) . ']  Exception Details' . PHP_EOL;
1125
+		$exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL;
1126
+		$exception_log .= 'Code: ' . $ex['code'] . PHP_EOL;
1127
+		$exception_log .= 'File: ' . $ex['file'] . PHP_EOL;
1128
+		$exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL;
1129
+		$exception_log .= 'Stack trace: ' . PHP_EOL;
1130
+		$exception_log .= $ex['string'] . PHP_EOL;
1131
+		$exception_log .= '----------------------------------------------------------------------------------------'
1132
+						  . PHP_EOL;
1133
+		try {
1134
+			EEH_File::ensure_file_exists_and_is_writable(
1135
+				EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file
1136
+			);
1137
+			EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs');
1138
+			if (! $clear) {
1139
+				//get existing log file and append new log info
1140
+				$exception_log = EEH_File::get_file_contents(
1141
+					EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file
1142
+				) . $exception_log;
1143
+			}
1144
+			EEH_File::write_to_file(
1145
+				EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file,
1146
+				$exception_log
1147
+			);
1148
+		} catch (EE_Error $e) {
1149
+			EE_Error::add_error(sprintf(__('Event Espresso error logging could not be setup because: %s',
1150
+				'event_espresso'), $e->getMessage()));
1151
+			return;
1152
+		}
1153
+	}
1154
+
1155
+
1156
+
1157
+	/**
1158
+	 * This is just a wrapper for the EEH_Debug_Tools::instance()->doing_it_wrong() method.
1159
+	 * doing_it_wrong() is used in those cases where a normal PHP error won't get thrown,
1160
+	 * but the code execution is done in a manner that could lead to unexpected results
1161
+	 * (i.e. running to early, or too late in WP or EE loading process).
1162
+	 * A good test for knowing whether to use this method is:
1163
+	 * 1. Is there going to be a PHP error if something isn't setup/used correctly?
1164
+	 * Yes -> use EE_Error::add_error() or throw new EE_Error()
1165
+	 * 2. If this is loaded before something else, it won't break anything,
1166
+	 * but just wont' do what its supposed to do? Yes -> use EE_Error::doing_it_wrong()
1167
+	 *
1168
+	 * @uses   constant WP_DEBUG test if wp_debug is on or not
1169
+	 * @param string $function      The function that was called
1170
+	 * @param string $message       A message explaining what has been done incorrectly
1171
+	 * @param string $version       The version of Event Espresso where the error was added
1172
+	 * @param string $applies_when  a version string for when you want the doing_it_wrong notice to begin appearing
1173
+	 *                              for a deprecated function. This allows deprecation to occur during one version,
1174
+	 *                              but not have any notices appear until a later version. This allows developers
1175
+	 *                              extra time to update their code before notices appear.
1176
+	 * @param int    $error_type
1177
+	 */
1178
+	public static function doing_it_wrong(
1179
+		$function,
1180
+		$message,
1181
+		$version,
1182
+		$applies_when = '',
1183
+		$error_type = null
1184
+	) {
1185
+		if (defined('WP_DEBUG') && WP_DEBUG) {
1186
+			EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type);
1187
+		}
1188
+	}
1189
+
1190
+
1191
+
1192
+	/**
1193
+	 * Like get_notices, but returns an array of all the notices of the given type.
1194
+	 *
1195
+	 * @return array {
1196
+	 * @type array $success   all the success messages
1197
+	 * @type array $errors    all the error messages
1198
+	 * @type array $attention all the attention messages
1199
+	 * }
1200
+	 */
1201
+	public static function get_raw_notices()
1202
+	{
1203
+		return self::$_espresso_notices;
1204
+	}
1205 1205
 
1206 1206
 
1207 1207
 
@@ -1217,27 +1217,27 @@  discard block
 block discarded – undo
1217 1217
  */
1218 1218
 function espresso_error_enqueue_scripts()
1219 1219
 {
1220
-    // js for error handling
1221
-    wp_register_script(
1222
-        'espresso_core',
1223
-        EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
1224
-        array('jquery'),
1225
-        EVENT_ESPRESSO_VERSION,
1226
-        false
1227
-    );
1228
-    wp_register_script(
1229
-        'ee_error_js',
1230
-        EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
1231
-        array('espresso_core'),
1232
-        EVENT_ESPRESSO_VERSION,
1233
-        false
1234
-    );
1220
+	// js for error handling
1221
+	wp_register_script(
1222
+		'espresso_core',
1223
+		EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
1224
+		array('jquery'),
1225
+		EVENT_ESPRESSO_VERSION,
1226
+		false
1227
+	);
1228
+	wp_register_script(
1229
+		'ee_error_js',
1230
+		EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
1231
+		array('espresso_core'),
1232
+		EVENT_ESPRESSO_VERSION,
1233
+		false
1234
+	);
1235 1235
 }
1236 1236
 
1237 1237
 if (is_admin()) {
1238
-    add_action('admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2);
1238
+	add_action('admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2);
1239 1239
 } else {
1240
-    add_action('wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2);
1240
+	add_action('wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2);
1241 1241
 }
1242 1242
 
1243 1243
 
Please login to merge, or discard this patch.
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -98,14 +98,14 @@  discard block
 block discarded – undo
98 98
             default :
99 99
                 $to = get_option('admin_email');
100 100
         }
101
-        $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url();
101
+        $subject = $type.' '.$message.' in '.EVENT_ESPRESSO_VERSION.' on '.site_url();
102 102
         $msg = EE_Error::_format_error($type, $message, $file, $line);
103 103
         if (function_exists('wp_mail')) {
104 104
             add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type'));
105 105
             wp_mail($to, $subject, $msg);
106 106
         }
107 107
         echo '<div id="message" class="espresso-notices error"><p>';
108
-        echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line;
108
+        echo $type.': '.$message.'<br />'.$file.' line '.$line;
109 109
         echo '<br /></p></div>';
110 110
     }
111 111
 
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
             ? true
255 255
             : false;
256 256
         if ($check_stored && ! $has_error) {
257
-            $notices = (array)get_option('ee_notices', array());
257
+            $notices = (array) get_option('ee_notices', array());
258 258
             foreach ($notices as $type => $notice) {
259 259
                 if ($type === $type_to_check && $notice) {
260 260
                     return true;
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
 	}
332 332
 </style>
333 333
 <div id="ee-error-message" class="error">';
334
-        if (! WP_DEBUG) {
334
+        if ( ! WP_DEBUG) {
335 335
             $output .= '
336 336
 	<p>';
337 337
         }
@@ -383,14 +383,14 @@  discard block
 block discarded – undo
383 383
                     $class_dsply = ! empty($class) ? $class : '&nbsp;';
384 384
                     $type_dsply = ! empty($type) ? $type : '&nbsp;';
385 385
                     $function_dsply = ! empty($function) ? $function : '&nbsp;';
386
-                    $args_dsply = ! empty($args) ? '( ' . $args . ' )' : '';
386
+                    $args_dsply = ! empty($args) ? '( '.$args.' )' : '';
387 387
                     $trace_details .= '
388 388
 					<tr>
389
-						<td align="right" class="' . $zebra . '">' . $nmbr_dsply . '</td>
390
-						<td align="right" class="' . $zebra . '">' . $line_dsply . '</td>
391
-						<td align="left" class="' . $zebra . '">' . $file_dsply . '</td>
392
-						<td align="left" class="' . $zebra . '">' . $class_dsply . '</td>
393
-						<td align="left" class="' . $zebra . '">' . $type_dsply . $function_dsply . $args_dsply . '</td>
389
+						<td align="right" class="' . $zebra.'">'.$nmbr_dsply.'</td>
390
+						<td align="right" class="' . $zebra.'">'.$line_dsply.'</td>
391
+						<td align="left" class="' . $zebra.'">'.$file_dsply.'</td>
392
+						<td align="left" class="' . $zebra.'">'.$class_dsply.'</td>
393
+						<td align="left" class="' . $zebra.'">'.$type_dsply.$function_dsply.$args_dsply.'</td>
394 394
 					</tr>';
395 395
                 }
396 396
                 $trace_details .= '
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
             }
400 400
             $ex['code'] = $ex['code'] ? $ex['code'] : $error_code;
401 401
             // add generic non-identifying messages for non-privileged users
402
-            if (! WP_DEBUG) {
402
+            if ( ! WP_DEBUG) {
403 403
                 $output .= '<span class="ee-error-user-msg-spn">'
404 404
                            . trim($ex['msg'])
405 405
                            . '</span> &nbsp; <sup>'
@@ -441,14 +441,14 @@  discard block
 block discarded – undo
441 441
                            . '-dv" class="ee-error-trace-dv" style="display: none;">
442 442
 				'
443 443
                            . $trace_details;
444
-                if (! empty($class)) {
444
+                if ( ! empty($class)) {
445 445
                     $output .= '
446 446
 				<div style="padding:3px; margin:0 0 1em; border:1px solid #666; background:#fff; border-radius:3px;">
447 447
 					<div style="padding:1em 2em; border:1px solid #666; background:#f9f9f9;">
448 448
 						<h3>Class Details</h3>';
449 449
                     $a = new ReflectionClass($class);
450 450
                     $output .= '
451
-						<pre>' . $a . '</pre>
451
+						<pre>' . $a.'</pre>
452 452
 					</div>
453 453
 				</div>';
454 454
                 }
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
         }
462 462
         // remove last linebreak
463 463
         $output = substr($output, 0, -6);
464
-        if (! WP_DEBUG) {
464
+        if ( ! WP_DEBUG) {
465 465
             $output .= '
466 466
 	</p>';
467 467
         }
@@ -488,20 +488,20 @@  discard block
 block discarded – undo
488 488
     private function _convert_args_to_string($arguments = array(), $array = false)
489 489
     {
490 490
         $arg_string = '';
491
-        if (! empty($arguments)) {
491
+        if ( ! empty($arguments)) {
492 492
             $args = array();
493 493
             foreach ($arguments as $arg) {
494
-                if (! empty($arg)) {
494
+                if ( ! empty($arg)) {
495 495
                     if (is_string($arg)) {
496
-                        $args[] = " '" . $arg . "'";
496
+                        $args[] = " '".$arg."'";
497 497
                     } elseif (is_array($arg)) {
498
-                        $args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true);
498
+                        $args[] = 'ARRAY('.$this->_convert_args_to_string($arg, true);
499 499
                     } elseif ($arg === null) {
500 500
                         $args[] = ' NULL';
501 501
                     } elseif (is_bool($arg)) {
502 502
                         $args[] = ($arg) ? ' TRUE' : ' FALSE';
503 503
                     } elseif (is_object($arg)) {
504
-                        $args[] = ' OBJECT ' . get_class($arg);
504
+                        $args[] = ' OBJECT '.get_class($arg);
505 505
                     } elseif (is_resource($arg)) {
506 506
                         $args[] = get_resource_type($arg);
507 507
                     } else {
@@ -606,7 +606,7 @@  discard block
 block discarded – undo
606 606
     {
607 607
         if (empty($msg)) {
608 608
             EE_Error::doing_it_wrong(
609
-                'EE_Error::add_' . $type . '()',
609
+                'EE_Error::add_'.$type.'()',
610 610
                 sprintf(
611 611
                     __('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d',
612 612
                         'event_espresso'),
@@ -642,11 +642,11 @@  discard block
 block discarded – undo
642 642
         do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line);
643 643
         $msg = WP_DEBUG ? $dev_msg : $user_msg;
644 644
         // add notice if message exists
645
-        if (! empty($msg)) {
645
+        if ( ! empty($msg)) {
646 646
             // get error code
647 647
             $notice_code = EE_Error::generate_error_code($file, $func, $line);
648 648
             if (WP_DEBUG && $type === 'errors') {
649
-                $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>';
649
+                $msg .= '<br/><span class="tiny-text">'.$notice_code.'</span>';
650 650
             }
651 651
             // add notice. Index by code if it's not blank
652 652
             if ($notice_code) {
@@ -890,14 +890,14 @@  discard block
 block discarded – undo
890 890
      */
891 891
     public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false)
892 892
     {
893
-        if (! empty($pan_name) && ! empty($pan_message)) {
893
+        if ( ! empty($pan_name) && ! empty($pan_message)) {
894 894
             $persistent_admin_notices = get_option('ee_pers_admin_notices', array());
895 895
             //maybe initialize persistent_admin_notices
896 896
             if (empty($persistent_admin_notices)) {
897 897
                 add_option('ee_pers_admin_notices', array(), '', 'no');
898 898
             }
899 899
             $pan_name = sanitize_key($pan_name);
900
-            if (! array_key_exists($pan_name, $persistent_admin_notices) || $force_update) {
900
+            if ( ! array_key_exists($pan_name, $persistent_admin_notices) || $force_update) {
901 901
                 $persistent_admin_notices[$pan_name] = $pan_message;
902 902
                 update_option('ee_pers_admin_notices', $persistent_admin_notices);
903 903
             }
@@ -918,7 +918,7 @@  discard block
 block discarded – undo
918 918
     {
919 919
         $pan_name = EE_Registry::instance()->REQ->is_set('ee_nag_notice')
920 920
             ? EE_Registry::instance()->REQ->get('ee_nag_notice') : $pan_name;
921
-        if (! empty($pan_name)) {
921
+        if ( ! empty($pan_name)) {
922 922
             $persistent_admin_notices = get_option('ee_pers_admin_notices', array());
923 923
             // check if notice we wish to dismiss is actually in the $persistent_admin_notices array
924 924
             if (is_array($persistent_admin_notices) && isset($persistent_admin_notices[$pan_name])) {
@@ -961,7 +961,7 @@  discard block
 block discarded – undo
961 961
      */
962 962
     public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '')
963 963
     {
964
-        if (! empty($pan_name) && ! empty($pan_message)) {
964
+        if ( ! empty($pan_name) && ! empty($pan_message)) {
965 965
             $args = array(
966 966
                 'nag_notice'    => $pan_name,
967 967
                 'return_url'    => urlencode($return_url),
@@ -1013,14 +1013,14 @@  discard block
 block discarded – undo
1013 1013
             // load scripts
1014 1014
             wp_register_script(
1015 1015
                 'espresso_core',
1016
-                EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
1016
+                EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js',
1017 1017
                 array('jquery'),
1018 1018
                 EVENT_ESPRESSO_VERSION,
1019 1019
                 true
1020 1020
             );
1021 1021
             wp_register_script(
1022 1022
                 'ee_error_js',
1023
-                EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
1023
+                EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js',
1024 1024
                 array('espresso_core'),
1025 1025
                 EVENT_ESPRESSO_VERSION,
1026 1026
                 true
@@ -1044,7 +1044,7 @@  discard block
 block discarded – undo
1044 1044
      */
1045 1045
     private static function _print_scripts($force_print = false)
1046 1046
     {
1047
-        if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) {
1047
+        if ( ! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) {
1048 1048
             if (wp_script_is('ee_error_js', 'enqueued')) {
1049 1049
                 return '';
1050 1050
             }
@@ -1058,12 +1058,12 @@  discard block
 block discarded – undo
1058 1058
             return '
1059 1059
 <script>
1060 1060
 /* <![CDATA[ */
1061
-var ee_settings = {"wp_debug":"' . WP_DEBUG . '"};
1061
+var ee_settings = {"wp_debug":"' . WP_DEBUG.'"};
1062 1062
 /* ]]> */
1063 1063
 </script>
1064
-<script src="' . includes_url() . 'js/jquery/jquery.js" type="text/javascript"></script>
1065
-<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
1066
-<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
1064
+<script src="' . includes_url().'js/jquery/jquery.js" type="text/javascript"></script>
1065
+<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js'.'?ver='.espresso_version().'" type="text/javascript"></script>
1066
+<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js'.'?ver='.espresso_version().'" type="text/javascript"></script>
1067 1067
 ';
1068 1068
         }
1069 1069
         return '';
@@ -1096,8 +1096,8 @@  discard block
 block discarded – undo
1096 1096
     {
1097 1097
         $file = explode('.', basename($file));
1098 1098
         $error_code = ! empty($file[0]) ? $file[0] : '';
1099
-        $error_code .= ! empty($func) ? ' - ' . $func : '';
1100
-        $error_code .= ! empty($line) ? ' - ' . $line : '';
1099
+        $error_code .= ! empty($func) ? ' - '.$func : '';
1100
+        $error_code .= ! empty($line) ? ' - '.$line : '';
1101 1101
         return $error_code;
1102 1102
     }
1103 1103
 
@@ -1116,33 +1116,33 @@  discard block
 block discarded – undo
1116 1116
         if (empty($ex)) {
1117 1117
             return;
1118 1118
         }
1119
-        if (! $time) {
1119
+        if ( ! $time) {
1120 1120
             $time = time();
1121 1121
         }
1122 1122
         $exception_log = '----------------------------------------------------------------------------------------'
1123 1123
                          . PHP_EOL;
1124
-        $exception_log .= '[' . date('Y-m-d H:i:s', $time) . ']  Exception Details' . PHP_EOL;
1125
-        $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL;
1126
-        $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL;
1127
-        $exception_log .= 'File: ' . $ex['file'] . PHP_EOL;
1128
-        $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL;
1129
-        $exception_log .= 'Stack trace: ' . PHP_EOL;
1130
-        $exception_log .= $ex['string'] . PHP_EOL;
1124
+        $exception_log .= '['.date('Y-m-d H:i:s', $time).']  Exception Details'.PHP_EOL;
1125
+        $exception_log .= 'Message: '.$ex['msg'].PHP_EOL;
1126
+        $exception_log .= 'Code: '.$ex['code'].PHP_EOL;
1127
+        $exception_log .= 'File: '.$ex['file'].PHP_EOL;
1128
+        $exception_log .= 'Line No: '.$ex['line'].PHP_EOL;
1129
+        $exception_log .= 'Stack trace: '.PHP_EOL;
1130
+        $exception_log .= $ex['string'].PHP_EOL;
1131 1131
         $exception_log .= '----------------------------------------------------------------------------------------'
1132 1132
                           . PHP_EOL;
1133 1133
         try {
1134 1134
             EEH_File::ensure_file_exists_and_is_writable(
1135
-                EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file
1135
+                EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.self::$_exception_log_file
1136 1136
             );
1137
-            EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs');
1138
-            if (! $clear) {
1137
+            EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR.'logs');
1138
+            if ( ! $clear) {
1139 1139
                 //get existing log file and append new log info
1140 1140
                 $exception_log = EEH_File::get_file_contents(
1141
-                    EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file
1142
-                ) . $exception_log;
1141
+                    EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.self::$_exception_log_file
1142
+                ).$exception_log;
1143 1143
             }
1144 1144
             EEH_File::write_to_file(
1145
-                EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file,
1145
+                EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.self::$_exception_log_file,
1146 1146
                 $exception_log
1147 1147
             );
1148 1148
         } catch (EE_Error $e) {
@@ -1220,14 +1220,14 @@  discard block
 block discarded – undo
1220 1220
     // js for error handling
1221 1221
     wp_register_script(
1222 1222
         'espresso_core',
1223
-        EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
1223
+        EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js',
1224 1224
         array('jquery'),
1225 1225
         EVENT_ESPRESSO_VERSION,
1226 1226
         false
1227 1227
     );
1228 1228
     wp_register_script(
1229 1229
         'ee_error_js',
1230
-        EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
1230
+        EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js',
1231 1231
         array('espresso_core'),
1232 1232
         EVENT_ESPRESSO_VERSION,
1233 1233
         false
Please login to merge, or discard this patch.
admin/extend/messages/Custom_Messages_Template_List_Table.class.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -409,7 +409,7 @@
 block discarded – undo
409 409
      * This provides a count of events using this custom template
410 410
      *
411 411
      * @param  EE_Message_Template_Group $item message_template group data
412
-     * @return string column output
412
+     * @return integer column output
413 413
      */
414 414
     function column_events($item)
415 415
     {
Please login to merge, or discard this patch.
Indentation   +476 added lines, -476 removed lines patch added patch discarded remove patch
@@ -12,481 +12,481 @@
 block discarded – undo
12 12
 class Custom_Messages_Template_List_Table extends EE_Admin_List_Table
13 13
 {
14 14
 
15
-    /**
16
-     * Custom_Messages_Template_List_Table constructor.
17
-     *
18
-     * @param EE_Admin_Page $admin_page
19
-     */
20
-    public function __construct($admin_page)
21
-    {
22
-        //Set parent defaults
23
-        parent::__construct($admin_page);
24
-    }
25
-
26
-
27
-    /**
28
-     * @return Messages_Admin_Page
29
-     */
30
-    public function get_admin_page()
31
-    {
32
-        return $this->_admin_page;
33
-    }
34
-
35
-    /**
36
-     * Setup initial data.
37
-     */
38
-    protected function _setup_data()
39
-    {
40
-        $this->_data           = $this->get_admin_page()->get_message_templates(
41
-            $this->_per_page,
42
-            $this->_view,
43
-            false,
44
-            false,
45
-            false
46
-        );
47
-        $this->_all_data_count = $this->get_admin_page()->get_message_templates(
48
-            $this->_per_page,
49
-            $this->_view,
50
-            true,
51
-            true,
52
-            false
53
-        );
54
-    }
55
-
56
-
57
-    /**
58
-     * Set initial properties
59
-     */
60
-    protected function _set_properties()
61
-    {
62
-        $this->_wp_list_args = array(
63
-            'singular' => esc_html__('Message Template Group', 'event_espresso'),
64
-            'plural'   => esc_html__('Message Template', 'event_espresso'),
65
-            'ajax'     => true, //for now,
66
-            'screen'   => $this->get_admin_page()->get_current_screen()->id,
67
-        );
68
-
69
-        $this->_columns = array(
70
-            'cb'           => '<input type="checkbox" />',
71
-            'name'         => esc_html__('Template Name', 'event_espresso'),
72
-            'message_type' => esc_html__('Message Type', 'event_espresso'),
73
-            'messenger'    => esc_html__('Messenger', 'event_espresso'),
74
-            'description'  => esc_html__('Description', 'event_espresso'),
75
-            'events'       => esc_html__('Events', 'event_espresso'),
76
-            //count of events using this template.
77
-            'actions'      => ''
78
-        );
79
-
80
-        $this->_sortable_columns = array(
81
-            'messenger' => array('MTP_messenger' => true),
82
-        );
83
-
84
-        $this->_hidden_columns = array();
85
-    }
86
-
87
-
88
-    /**
89
-     * Overriding the single_row method from parent to verify whether the $item has an accessible
90
-     * message_type or messenger object before generating the row.
91
-     *
92
-     * @param EE_Message_Template_Group $item
93
-     * @return string
94
-     */
95
-    public function single_row($item)
96
-    {
97
-        $message_type = $item->message_type_obj();
98
-        $messenger    = $item->messenger_obj();
99
-
100
-        if (! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) {
101
-            echo '';
102
-            return;
103
-        }
104
-
105
-        parent::single_row($item);
106
-    }
107
-
108
-
109
-    /**
110
-     * @return array
111
-     */
112
-    protected function _get_table_filters()
113
-    {
114
-        $filters = array();
115
-
116
-        //get select inputs
117
-        $select_inputs = array(
118
-            $this->_get_messengers_dropdown_filter(),
119
-            $this->_get_message_types_dropdown_filter(),
120
-        );
121
-
122
-        //set filters to select inputs if they aren't empty
123
-        foreach ($select_inputs as $select_input) {
124
-            if ($select_input) {
125
-                $filters[] = $select_input;
126
-            }
127
-        }
128
-        return $filters;
129
-    }
130
-
131
-    /**
132
-     * we're just removing the search box for message templates, not needed.
133
-     *
134
-     * @return string (empty);
135
-     */
136
-    function search_box($text, $input_id)
137
-    {
138
-        return '';
139
-    }
140
-
141
-
142
-    /**
143
-     * Set the view counts on the _views property
144
-     */
145
-    protected function _add_view_counts()
146
-    {
147
-        foreach ($this->_views as $view => $args) {
148
-            $this->_views[$view]['count'] = $this->get_admin_page()->get_message_templates(
149
-                $this->_per_page,
150
-                $view,
151
-                true,
152
-                true,
153
-                false
154
-            );
155
-        }
156
-    }
157
-
158
-
159
-    /**
160
-     * Custom message for when there are no items found.
161
-     *
162
-     * @since 4.3.0
163
-     * @return string
164
-     */
165
-    public function no_items()
166
-    {
167
-        if ($this->_view !== 'trashed') {
168
-            printf(
169
-                esc_html__(
170
-                    '%sNo Custom Templates found.%s To create your first custom message template, go to the "Default Message Templates" tab and click the "Create Custom" button next to the template you want to use as a base for the new one.',
171
-                    'event_espresso'
172
-                ),
173
-                '<strong>',
174
-                '</strong>'
175
-            );
176
-        } else {
177
-            parent::no_items();
178
-        }
179
-    }
180
-
181
-
182
-    /**
183
-     * @param EE_Message_Template_Group $item
184
-     * @return string
185
-     */
186
-    public function column_cb($item)
187
-    {
188
-        return sprintf('<input type="checkbox" name="checkbox[%s] value="1" />', $item->GRP_ID());
189
-    }
190
-
191
-
192
-    /**
193
-     * @param EE_Message_Template_Group $item
194
-     * @return string
195
-     */
196
-    function column_name($item)
197
-    {
198
-        return '<p>' . $item->name() . '</p>';
199
-    }
200
-
201
-
202
-    /**
203
-     * @param EE_Message_Template_Group $item
204
-     * @return string
205
-     */
206
-    function column_description($item)
207
-    {
208
-        return '<p>' . $item->description() . '</p>';
209
-    }
210
-
211
-
212
-    /**
213
-     * @param EE_Message_Template_Group $item
214
-     * @return string
215
-     */
216
-    function column_actions($item)
217
-    {
218
-        if (EE_Registry::instance()->CAP->current_user_can(
219
-            'ee_edit_messages',
220
-            'espresso_messages_add_new_message_template'
221
-        )) {
222
-            $create_args = array(
223
-                'GRP_ID'       => $item->ID(),
224
-                'messenger'    => $item->messenger(),
225
-                'message_type' => $item->message_type(),
226
-                'action'       => 'add_new_message_template',
227
-            );
228
-            $create_link = EE_Admin_Page::add_query_args_and_nonce($create_args, EE_MSG_ADMIN_URL);
229
-            return sprintf(
230
-                '<p><a href="%s" class="button button-small">%s</a></p>',
231
-                $create_link,
232
-                esc_html__('Create Custom', 'event_espresso')
233
-            );
234
-        }
235
-        return '';
236
-    }
237
-
238
-
239
-    /**
240
-     * Return the content for the messenger column
241
-     * @param EE_Message_Template_Group $item
242
-     * @return string
243
-     */
244
-    function column_messenger($item)
245
-    {
246
-
247
-        //Build row actions
248
-        $actions = array();
249
-        $edit_lnk_url = '';
250
-
251
-        // edit link but only if item isn't trashed.
252
-        if (! $item->get('MTP_deleted')
253
-            && EE_Registry::instance()->CAP->current_user_can(
254
-                'ee_edit_message',
255
-                'espresso_messages_edit_message_template',
256
-                $item->ID()
257
-            )
258
-        ) {
259
-            $edit_lnk_url    = EE_Admin_Page::add_query_args_and_nonce(array(
260
-                'action' => 'edit_m`es`sage_template',
261
-                'id'     => $item->GRP_ID(),
262
-            ), EE_MSG_ADMIN_URL);
263
-            $actions['edit'] = '<a href="' . $edit_lnk_url . '"'
264
-                               . ' class="' . $item->message_type() . '-edit-link"'
265
-                               . ' title="'
266
-                               . esc_attr__('Edit Template', 'event_espresso')
267
-                               . '">'
268
-                               . esc_html__('Edit', 'event_espresso')
269
-                               . '</a>';
270
-        }
271
-
272
-        $name_link     = ! $item->get('MTP_deleted')
273
-                         && EE_Registry::instance()->CAP->current_user_can(
274
-                             'ee_edit_message',
275
-                             'espresso_messages_edit_message_template',
276
-                             $item->ID()
277
-                         )
278
-                        && $edit_lnk_url
279
-            ? '<a href="'
280
-              . $edit_lnk_url
281
-              . '" title="'
282
-              . esc_attr__('Edit Template', 'event_espresso')
283
-              . '">'
284
-              . ucwords($item->messenger_obj()->label['singular'])
285
-              . '</a>'
286
-            : ucwords($item->messenger_obj()->label['singular']);
287
-        $trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action'   => 'trash_message_template',
288
-                                                                       'id'       => $item->GRP_ID(),
289
-                                                                       'noheader' => true,
290
-        ), EE_MSG_ADMIN_URL);
291
-        // restore link
292
-        $restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action'   => 'restore_message_template',
293
-                                                                         'id'       => $item->GRP_ID(),
294
-                                                                         'noheader' => true,
295
-        ), EE_MSG_ADMIN_URL);
296
-        // delete price link
297
-        $delete_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action'   => 'delete_message_template',
298
-                                                                        'id'       => $item->GRP_ID(),
299
-                                                                        'noheader' => true,
300
-        ), EE_MSG_ADMIN_URL);
301
-
302
-        if (! $item->get('MTP_deleted')
303
-            && EE_Registry::instance()->CAP->current_user_can(
304
-                'ee_delete_message',
305
-                'espresso_messages_trash_message_template',
306
-                $item->ID()
307
-            )
308
-        ) {
309
-            $actions['trash'] = '<a href="'
310
-                                . $trash_lnk_url
311
-                                . '" title="'
312
-                                . esc_attr__('Move Template Group to Trash', 'event_espresso')
313
-                                . '">'
314
-                                . esc_html__('Move to Trash', 'event_espresso')
315
-                                . '</a>';
316
-        } else {
317
-            if (EE_Registry::instance()->CAP->current_user_can(
318
-                'ee_delete_message',
319
-                'espresso_messages_restore_message_template',
320
-                $item->ID()
321
-            )) {
322
-                $actions['restore'] = '<a href="'
323
-                                      . $restore_lnk_url
324
-                                      . '" title="'
325
-                                      . esc_attr__('Restore Message Template', 'event_espresso')
326
-                                      . '">'
327
-                                      . esc_html__('Restore', 'event_espresso') . '</a>';
328
-            }
329
-
330
-            if ($this->_view == 'trashed'
331
-                && EE_Registry::instance()->CAP->current_user_can(
332
-                    'ee_delete_message',
333
-                    'espresso_messages_delete_message_template',
334
-                    $item->ID()
335
-                )) {
336
-                $actions['delete'] = '<a href="'
337
-                                     . $delete_lnk_url
338
-                                     . '" title="'
339
-                                     . esc_attr__('Delete Template Group Permanently', 'event_espresso')
340
-                                     . '">'
341
-                                     . esc_html__('Delete Permanently', 'event_espresso')
342
-                                     . '</a>';
343
-            }
344
-        }
345
-
346
-        //we want to display the contexts in here so we need to set them up
347
-        $c_label           = $item->context_label();
348
-        $c_configs         = $item->contexts_config();
349
-        $ctxt              = array();
350
-        $context_templates = $item->context_templates();
351
-        foreach ($context_templates as $context => $template_fields) {
352
-            $mtp_to        = ! empty($context_templates[$context]['to'])
353
-                             && $context_templates[$context]['to'] instanceof EE_Message_Template
354
-                ? $context_templates[$context]['to']->get('MTP_content')
355
-                : null;
356
-            $inactive      = empty($mtp_to) && ! empty($context_templates[$context]['to'])
357
-                ? ' class="mtp-inactive"'
358
-                : '';
359
-            $context_title = ucwords($c_configs[$context]['label']);
360
-            $edit_link     = EE_Admin_Page::add_query_args_and_nonce(array('action'  => 'edit_message_template',
361
-                                                                           'id'      => $item->GRP_ID(),
362
-                                                                           'context' => $context,
363
-            ), EE_MSG_ADMIN_URL);
364
-            $ctxt[]        = EE_Registry::instance()->CAP->current_user_can(
365
-                'ee_edit_message',
366
-                'espresso_messages_edit_message_template',
367
-                $item->ID()
368
-            )
369
-                ? '<a'
370
-                  . $inactive
371
-                  . ' class="' . $item->message_type() . '-' . $context . '-edit-link"'
372
-                  . ' href="' . $edit_link . '"'
373
-                  . ' title="' . esc_attr__('Edit Context', 'event_espresso') . '">'
374
-                  . $context_title
375
-                  . '</a>'
376
-                : $context_title;
377
-        }
378
-
379
-        $ctx_content = ! $item->get('MTP_deleted')
380
-                       && EE_Registry::instance()->CAP->current_user_can(
381
-                           'ee_edit_message',
382
-                           'espresso_messages_edit_message_template',
383
-                           $item->ID()
384
-                       )
385
-            ? sprintf(
386
-                '<strong>%s:</strong> ',
387
-                ucwords($c_label['plural'])
388
-            )
389
-              . implode(' | ', $ctxt)
390
-            : '';
391
-
392
-
393
-        //Return the name contents
394
-        return sprintf(
395
-            '%1$s <span style="color:silver">(id:%2$s)</span><br />%3$s%4$s',
396
-            /* $1%s */
397
-            $name_link,
398
-            /* $2%s */
399
-            $item->GRP_ID(),
400
-            /* %4$s */
401
-            $ctx_content,
402
-            /* $3%s */
403
-            $this->row_actions($actions)
404
-        );
405
-    }
406
-
407
-    /**
408
-     * column_events
409
-     * This provides a count of events using this custom template
410
-     *
411
-     * @param  EE_Message_Template_Group $item message_template group data
412
-     * @return string column output
413
-     */
414
-    function column_events($item)
415
-    {
416
-        return $item->count_events();
417
-    }
418
-
419
-    /**
420
-     * column_message_type
421
-     *
422
-     * @param  EE_Message_Template_Group $item message info for the row
423
-     * @return string       message_type name
424
-     */
425
-    function column_message_type($item)
426
-    {
427
-        return ucwords($item->message_type_obj()->label['singular']);
428
-    }
429
-
430
-
431
-    /**
432
-     * Generate dropdown filter select input for messengers
433
-     *
434
-     * @return string
435
-     */
436
-    protected function _get_messengers_dropdown_filter()
437
-    {
438
-        $messenger_options                                   = array();
439
-        $active_message_template_groups_grouped_by_messenger = EEM_Message_Template_Group::instance()->get_all(
440
-            array(
441
-                array(
442
-                    'MTP_is_active' => true,
443
-                    'MTP_is_global' => false,
444
-                ),
445
-                'group_by' => 'MTP_messenger',
446
-            )
447
-        );
448
-
449
-        foreach ($active_message_template_groups_grouped_by_messenger as $active_message_template_group) {
450
-            if ($active_message_template_group instanceof EE_Message_Template_Group) {
451
-                $messenger                                                      = $active_message_template_group->messenger_obj();
452
-                $messenger_label                                                = $messenger instanceof EE_messenger
453
-                    ? $messenger->label['singular']
454
-                    : $active_message_template_group->messenger();
455
-                $messenger_options[$active_message_template_group->messenger()] = ucwords($messenger_label);
456
-            }
457
-        }
458
-        return $this->get_admin_page()->get_messengers_select_input($messenger_options);
459
-    }
460
-
461
-
462
-    /**
463
-     * Generate dropdown filter select input for message types
464
-     *
465
-     * @return string
466
-     */
467
-    protected function _get_message_types_dropdown_filter()
468
-    {
469
-        $message_type_options                                   = array();
470
-        $active_message_template_groups_grouped_by_message_type = EEM_Message_Template_Group::instance()->get_all(
471
-            array(
472
-                array(
473
-                    'MTP_is_active' => true,
474
-                    'MTP_is_global' => false,
475
-                ),
476
-                'group_by' => 'MTP_message_type',
477
-            )
478
-        );
479
-
480
-        foreach ($active_message_template_groups_grouped_by_message_type as $active_message_template_group) {
481
-            if ($active_message_template_group instanceof EE_Message_Template_Group) {
482
-                $message_type                                                         = $active_message_template_group->message_type_obj();
483
-                $message_type_label                                                   = $message_type instanceof EE_message_type
484
-                    ? $message_type->label['singular']
485
-                    : $active_message_template_group->message_type();
486
-                $message_type_options[$active_message_template_group->message_type()] = ucwords($message_type_label);
487
-            }
488
-        }
489
-        return $this->get_admin_page()->get_message_types_select_input($message_type_options);
490
-    }
15
+	/**
16
+	 * Custom_Messages_Template_List_Table constructor.
17
+	 *
18
+	 * @param EE_Admin_Page $admin_page
19
+	 */
20
+	public function __construct($admin_page)
21
+	{
22
+		//Set parent defaults
23
+		parent::__construct($admin_page);
24
+	}
25
+
26
+
27
+	/**
28
+	 * @return Messages_Admin_Page
29
+	 */
30
+	public function get_admin_page()
31
+	{
32
+		return $this->_admin_page;
33
+	}
34
+
35
+	/**
36
+	 * Setup initial data.
37
+	 */
38
+	protected function _setup_data()
39
+	{
40
+		$this->_data           = $this->get_admin_page()->get_message_templates(
41
+			$this->_per_page,
42
+			$this->_view,
43
+			false,
44
+			false,
45
+			false
46
+		);
47
+		$this->_all_data_count = $this->get_admin_page()->get_message_templates(
48
+			$this->_per_page,
49
+			$this->_view,
50
+			true,
51
+			true,
52
+			false
53
+		);
54
+	}
55
+
56
+
57
+	/**
58
+	 * Set initial properties
59
+	 */
60
+	protected function _set_properties()
61
+	{
62
+		$this->_wp_list_args = array(
63
+			'singular' => esc_html__('Message Template Group', 'event_espresso'),
64
+			'plural'   => esc_html__('Message Template', 'event_espresso'),
65
+			'ajax'     => true, //for now,
66
+			'screen'   => $this->get_admin_page()->get_current_screen()->id,
67
+		);
68
+
69
+		$this->_columns = array(
70
+			'cb'           => '<input type="checkbox" />',
71
+			'name'         => esc_html__('Template Name', 'event_espresso'),
72
+			'message_type' => esc_html__('Message Type', 'event_espresso'),
73
+			'messenger'    => esc_html__('Messenger', 'event_espresso'),
74
+			'description'  => esc_html__('Description', 'event_espresso'),
75
+			'events'       => esc_html__('Events', 'event_espresso'),
76
+			//count of events using this template.
77
+			'actions'      => ''
78
+		);
79
+
80
+		$this->_sortable_columns = array(
81
+			'messenger' => array('MTP_messenger' => true),
82
+		);
83
+
84
+		$this->_hidden_columns = array();
85
+	}
86
+
87
+
88
+	/**
89
+	 * Overriding the single_row method from parent to verify whether the $item has an accessible
90
+	 * message_type or messenger object before generating the row.
91
+	 *
92
+	 * @param EE_Message_Template_Group $item
93
+	 * @return string
94
+	 */
95
+	public function single_row($item)
96
+	{
97
+		$message_type = $item->message_type_obj();
98
+		$messenger    = $item->messenger_obj();
99
+
100
+		if (! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) {
101
+			echo '';
102
+			return;
103
+		}
104
+
105
+		parent::single_row($item);
106
+	}
107
+
108
+
109
+	/**
110
+	 * @return array
111
+	 */
112
+	protected function _get_table_filters()
113
+	{
114
+		$filters = array();
115
+
116
+		//get select inputs
117
+		$select_inputs = array(
118
+			$this->_get_messengers_dropdown_filter(),
119
+			$this->_get_message_types_dropdown_filter(),
120
+		);
121
+
122
+		//set filters to select inputs if they aren't empty
123
+		foreach ($select_inputs as $select_input) {
124
+			if ($select_input) {
125
+				$filters[] = $select_input;
126
+			}
127
+		}
128
+		return $filters;
129
+	}
130
+
131
+	/**
132
+	 * we're just removing the search box for message templates, not needed.
133
+	 *
134
+	 * @return string (empty);
135
+	 */
136
+	function search_box($text, $input_id)
137
+	{
138
+		return '';
139
+	}
140
+
141
+
142
+	/**
143
+	 * Set the view counts on the _views property
144
+	 */
145
+	protected function _add_view_counts()
146
+	{
147
+		foreach ($this->_views as $view => $args) {
148
+			$this->_views[$view]['count'] = $this->get_admin_page()->get_message_templates(
149
+				$this->_per_page,
150
+				$view,
151
+				true,
152
+				true,
153
+				false
154
+			);
155
+		}
156
+	}
157
+
158
+
159
+	/**
160
+	 * Custom message for when there are no items found.
161
+	 *
162
+	 * @since 4.3.0
163
+	 * @return string
164
+	 */
165
+	public function no_items()
166
+	{
167
+		if ($this->_view !== 'trashed') {
168
+			printf(
169
+				esc_html__(
170
+					'%sNo Custom Templates found.%s To create your first custom message template, go to the "Default Message Templates" tab and click the "Create Custom" button next to the template you want to use as a base for the new one.',
171
+					'event_espresso'
172
+				),
173
+				'<strong>',
174
+				'</strong>'
175
+			);
176
+		} else {
177
+			parent::no_items();
178
+		}
179
+	}
180
+
181
+
182
+	/**
183
+	 * @param EE_Message_Template_Group $item
184
+	 * @return string
185
+	 */
186
+	public function column_cb($item)
187
+	{
188
+		return sprintf('<input type="checkbox" name="checkbox[%s] value="1" />', $item->GRP_ID());
189
+	}
190
+
191
+
192
+	/**
193
+	 * @param EE_Message_Template_Group $item
194
+	 * @return string
195
+	 */
196
+	function column_name($item)
197
+	{
198
+		return '<p>' . $item->name() . '</p>';
199
+	}
200
+
201
+
202
+	/**
203
+	 * @param EE_Message_Template_Group $item
204
+	 * @return string
205
+	 */
206
+	function column_description($item)
207
+	{
208
+		return '<p>' . $item->description() . '</p>';
209
+	}
210
+
211
+
212
+	/**
213
+	 * @param EE_Message_Template_Group $item
214
+	 * @return string
215
+	 */
216
+	function column_actions($item)
217
+	{
218
+		if (EE_Registry::instance()->CAP->current_user_can(
219
+			'ee_edit_messages',
220
+			'espresso_messages_add_new_message_template'
221
+		)) {
222
+			$create_args = array(
223
+				'GRP_ID'       => $item->ID(),
224
+				'messenger'    => $item->messenger(),
225
+				'message_type' => $item->message_type(),
226
+				'action'       => 'add_new_message_template',
227
+			);
228
+			$create_link = EE_Admin_Page::add_query_args_and_nonce($create_args, EE_MSG_ADMIN_URL);
229
+			return sprintf(
230
+				'<p><a href="%s" class="button button-small">%s</a></p>',
231
+				$create_link,
232
+				esc_html__('Create Custom', 'event_espresso')
233
+			);
234
+		}
235
+		return '';
236
+	}
237
+
238
+
239
+	/**
240
+	 * Return the content for the messenger column
241
+	 * @param EE_Message_Template_Group $item
242
+	 * @return string
243
+	 */
244
+	function column_messenger($item)
245
+	{
246
+
247
+		//Build row actions
248
+		$actions = array();
249
+		$edit_lnk_url = '';
250
+
251
+		// edit link but only if item isn't trashed.
252
+		if (! $item->get('MTP_deleted')
253
+			&& EE_Registry::instance()->CAP->current_user_can(
254
+				'ee_edit_message',
255
+				'espresso_messages_edit_message_template',
256
+				$item->ID()
257
+			)
258
+		) {
259
+			$edit_lnk_url    = EE_Admin_Page::add_query_args_and_nonce(array(
260
+				'action' => 'edit_m`es`sage_template',
261
+				'id'     => $item->GRP_ID(),
262
+			), EE_MSG_ADMIN_URL);
263
+			$actions['edit'] = '<a href="' . $edit_lnk_url . '"'
264
+							   . ' class="' . $item->message_type() . '-edit-link"'
265
+							   . ' title="'
266
+							   . esc_attr__('Edit Template', 'event_espresso')
267
+							   . '">'
268
+							   . esc_html__('Edit', 'event_espresso')
269
+							   . '</a>';
270
+		}
271
+
272
+		$name_link     = ! $item->get('MTP_deleted')
273
+						 && EE_Registry::instance()->CAP->current_user_can(
274
+							 'ee_edit_message',
275
+							 'espresso_messages_edit_message_template',
276
+							 $item->ID()
277
+						 )
278
+						&& $edit_lnk_url
279
+			? '<a href="'
280
+			  . $edit_lnk_url
281
+			  . '" title="'
282
+			  . esc_attr__('Edit Template', 'event_espresso')
283
+			  . '">'
284
+			  . ucwords($item->messenger_obj()->label['singular'])
285
+			  . '</a>'
286
+			: ucwords($item->messenger_obj()->label['singular']);
287
+		$trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action'   => 'trash_message_template',
288
+																	   'id'       => $item->GRP_ID(),
289
+																	   'noheader' => true,
290
+		), EE_MSG_ADMIN_URL);
291
+		// restore link
292
+		$restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action'   => 'restore_message_template',
293
+																		 'id'       => $item->GRP_ID(),
294
+																		 'noheader' => true,
295
+		), EE_MSG_ADMIN_URL);
296
+		// delete price link
297
+		$delete_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action'   => 'delete_message_template',
298
+																		'id'       => $item->GRP_ID(),
299
+																		'noheader' => true,
300
+		), EE_MSG_ADMIN_URL);
301
+
302
+		if (! $item->get('MTP_deleted')
303
+			&& EE_Registry::instance()->CAP->current_user_can(
304
+				'ee_delete_message',
305
+				'espresso_messages_trash_message_template',
306
+				$item->ID()
307
+			)
308
+		) {
309
+			$actions['trash'] = '<a href="'
310
+								. $trash_lnk_url
311
+								. '" title="'
312
+								. esc_attr__('Move Template Group to Trash', 'event_espresso')
313
+								. '">'
314
+								. esc_html__('Move to Trash', 'event_espresso')
315
+								. '</a>';
316
+		} else {
317
+			if (EE_Registry::instance()->CAP->current_user_can(
318
+				'ee_delete_message',
319
+				'espresso_messages_restore_message_template',
320
+				$item->ID()
321
+			)) {
322
+				$actions['restore'] = '<a href="'
323
+									  . $restore_lnk_url
324
+									  . '" title="'
325
+									  . esc_attr__('Restore Message Template', 'event_espresso')
326
+									  . '">'
327
+									  . esc_html__('Restore', 'event_espresso') . '</a>';
328
+			}
329
+
330
+			if ($this->_view == 'trashed'
331
+				&& EE_Registry::instance()->CAP->current_user_can(
332
+					'ee_delete_message',
333
+					'espresso_messages_delete_message_template',
334
+					$item->ID()
335
+				)) {
336
+				$actions['delete'] = '<a href="'
337
+									 . $delete_lnk_url
338
+									 . '" title="'
339
+									 . esc_attr__('Delete Template Group Permanently', 'event_espresso')
340
+									 . '">'
341
+									 . esc_html__('Delete Permanently', 'event_espresso')
342
+									 . '</a>';
343
+			}
344
+		}
345
+
346
+		//we want to display the contexts in here so we need to set them up
347
+		$c_label           = $item->context_label();
348
+		$c_configs         = $item->contexts_config();
349
+		$ctxt              = array();
350
+		$context_templates = $item->context_templates();
351
+		foreach ($context_templates as $context => $template_fields) {
352
+			$mtp_to        = ! empty($context_templates[$context]['to'])
353
+							 && $context_templates[$context]['to'] instanceof EE_Message_Template
354
+				? $context_templates[$context]['to']->get('MTP_content')
355
+				: null;
356
+			$inactive      = empty($mtp_to) && ! empty($context_templates[$context]['to'])
357
+				? ' class="mtp-inactive"'
358
+				: '';
359
+			$context_title = ucwords($c_configs[$context]['label']);
360
+			$edit_link     = EE_Admin_Page::add_query_args_and_nonce(array('action'  => 'edit_message_template',
361
+																		   'id'      => $item->GRP_ID(),
362
+																		   'context' => $context,
363
+			), EE_MSG_ADMIN_URL);
364
+			$ctxt[]        = EE_Registry::instance()->CAP->current_user_can(
365
+				'ee_edit_message',
366
+				'espresso_messages_edit_message_template',
367
+				$item->ID()
368
+			)
369
+				? '<a'
370
+				  . $inactive
371
+				  . ' class="' . $item->message_type() . '-' . $context . '-edit-link"'
372
+				  . ' href="' . $edit_link . '"'
373
+				  . ' title="' . esc_attr__('Edit Context', 'event_espresso') . '">'
374
+				  . $context_title
375
+				  . '</a>'
376
+				: $context_title;
377
+		}
378
+
379
+		$ctx_content = ! $item->get('MTP_deleted')
380
+					   && EE_Registry::instance()->CAP->current_user_can(
381
+						   'ee_edit_message',
382
+						   'espresso_messages_edit_message_template',
383
+						   $item->ID()
384
+					   )
385
+			? sprintf(
386
+				'<strong>%s:</strong> ',
387
+				ucwords($c_label['plural'])
388
+			)
389
+			  . implode(' | ', $ctxt)
390
+			: '';
391
+
392
+
393
+		//Return the name contents
394
+		return sprintf(
395
+			'%1$s <span style="color:silver">(id:%2$s)</span><br />%3$s%4$s',
396
+			/* $1%s */
397
+			$name_link,
398
+			/* $2%s */
399
+			$item->GRP_ID(),
400
+			/* %4$s */
401
+			$ctx_content,
402
+			/* $3%s */
403
+			$this->row_actions($actions)
404
+		);
405
+	}
406
+
407
+	/**
408
+	 * column_events
409
+	 * This provides a count of events using this custom template
410
+	 *
411
+	 * @param  EE_Message_Template_Group $item message_template group data
412
+	 * @return string column output
413
+	 */
414
+	function column_events($item)
415
+	{
416
+		return $item->count_events();
417
+	}
418
+
419
+	/**
420
+	 * column_message_type
421
+	 *
422
+	 * @param  EE_Message_Template_Group $item message info for the row
423
+	 * @return string       message_type name
424
+	 */
425
+	function column_message_type($item)
426
+	{
427
+		return ucwords($item->message_type_obj()->label['singular']);
428
+	}
429
+
430
+
431
+	/**
432
+	 * Generate dropdown filter select input for messengers
433
+	 *
434
+	 * @return string
435
+	 */
436
+	protected function _get_messengers_dropdown_filter()
437
+	{
438
+		$messenger_options                                   = array();
439
+		$active_message_template_groups_grouped_by_messenger = EEM_Message_Template_Group::instance()->get_all(
440
+			array(
441
+				array(
442
+					'MTP_is_active' => true,
443
+					'MTP_is_global' => false,
444
+				),
445
+				'group_by' => 'MTP_messenger',
446
+			)
447
+		);
448
+
449
+		foreach ($active_message_template_groups_grouped_by_messenger as $active_message_template_group) {
450
+			if ($active_message_template_group instanceof EE_Message_Template_Group) {
451
+				$messenger                                                      = $active_message_template_group->messenger_obj();
452
+				$messenger_label                                                = $messenger instanceof EE_messenger
453
+					? $messenger->label['singular']
454
+					: $active_message_template_group->messenger();
455
+				$messenger_options[$active_message_template_group->messenger()] = ucwords($messenger_label);
456
+			}
457
+		}
458
+		return $this->get_admin_page()->get_messengers_select_input($messenger_options);
459
+	}
460
+
461
+
462
+	/**
463
+	 * Generate dropdown filter select input for message types
464
+	 *
465
+	 * @return string
466
+	 */
467
+	protected function _get_message_types_dropdown_filter()
468
+	{
469
+		$message_type_options                                   = array();
470
+		$active_message_template_groups_grouped_by_message_type = EEM_Message_Template_Group::instance()->get_all(
471
+			array(
472
+				array(
473
+					'MTP_is_active' => true,
474
+					'MTP_is_global' => false,
475
+				),
476
+				'group_by' => 'MTP_message_type',
477
+			)
478
+		);
479
+
480
+		foreach ($active_message_template_groups_grouped_by_message_type as $active_message_template_group) {
481
+			if ($active_message_template_group instanceof EE_Message_Template_Group) {
482
+				$message_type                                                         = $active_message_template_group->message_type_obj();
483
+				$message_type_label                                                   = $message_type instanceof EE_message_type
484
+					? $message_type->label['singular']
485
+					: $active_message_template_group->message_type();
486
+				$message_type_options[$active_message_template_group->message_type()] = ucwords($message_type_label);
487
+			}
488
+		}
489
+		return $this->get_admin_page()->get_message_types_select_input($message_type_options);
490
+	}
491 491
 
492 492
 }
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
      */
38 38
     protected function _setup_data()
39 39
     {
40
-        $this->_data           = $this->get_admin_page()->get_message_templates(
40
+        $this->_data = $this->get_admin_page()->get_message_templates(
41 41
             $this->_per_page,
42 42
             $this->_view,
43 43
             false,
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
         $message_type = $item->message_type_obj();
98 98
         $messenger    = $item->messenger_obj();
99 99
 
100
-        if (! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) {
100
+        if ( ! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) {
101 101
             echo '';
102 102
             return;
103 103
         }
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
      */
196 196
     function column_name($item)
197 197
     {
198
-        return '<p>' . $item->name() . '</p>';
198
+        return '<p>'.$item->name().'</p>';
199 199
     }
200 200
 
201 201
 
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
      */
206 206
     function column_description($item)
207 207
     {
208
-        return '<p>' . $item->description() . '</p>';
208
+        return '<p>'.$item->description().'</p>';
209 209
     }
210 210
 
211 211
 
@@ -249,19 +249,19 @@  discard block
 block discarded – undo
249 249
         $edit_lnk_url = '';
250 250
 
251 251
         // edit link but only if item isn't trashed.
252
-        if (! $item->get('MTP_deleted')
252
+        if ( ! $item->get('MTP_deleted')
253 253
             && EE_Registry::instance()->CAP->current_user_can(
254 254
                 'ee_edit_message',
255 255
                 'espresso_messages_edit_message_template',
256 256
                 $item->ID()
257 257
             )
258 258
         ) {
259
-            $edit_lnk_url    = EE_Admin_Page::add_query_args_and_nonce(array(
259
+            $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
260 260
                 'action' => 'edit_m`es`sage_template',
261 261
                 'id'     => $item->GRP_ID(),
262 262
             ), EE_MSG_ADMIN_URL);
263
-            $actions['edit'] = '<a href="' . $edit_lnk_url . '"'
264
-                               . ' class="' . $item->message_type() . '-edit-link"'
263
+            $actions['edit'] = '<a href="'.$edit_lnk_url.'"'
264
+                               . ' class="'.$item->message_type().'-edit-link"'
265 265
                                . ' title="'
266 266
                                . esc_attr__('Edit Template', 'event_espresso')
267 267
                                . '">'
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
                                . '</a>';
270 270
         }
271 271
 
272
-        $name_link     = ! $item->get('MTP_deleted')
272
+        $name_link = ! $item->get('MTP_deleted')
273 273
                          && EE_Registry::instance()->CAP->current_user_can(
274 274
                              'ee_edit_message',
275 275
                              'espresso_messages_edit_message_template',
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
                                                                         'noheader' => true,
300 300
         ), EE_MSG_ADMIN_URL);
301 301
 
302
-        if (! $item->get('MTP_deleted')
302
+        if ( ! $item->get('MTP_deleted')
303 303
             && EE_Registry::instance()->CAP->current_user_can(
304 304
                 'ee_delete_message',
305 305
                 'espresso_messages_trash_message_template',
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
                                       . '" title="'
325 325
                                       . esc_attr__('Restore Message Template', 'event_espresso')
326 326
                                       . '">'
327
-                                      . esc_html__('Restore', 'event_espresso') . '</a>';
327
+                                      . esc_html__('Restore', 'event_espresso').'</a>';
328 328
             }
329 329
 
330 330
             if ($this->_view == 'trashed'
@@ -361,16 +361,16 @@  discard block
 block discarded – undo
361 361
                                                                            'id'      => $item->GRP_ID(),
362 362
                                                                            'context' => $context,
363 363
             ), EE_MSG_ADMIN_URL);
364
-            $ctxt[]        = EE_Registry::instance()->CAP->current_user_can(
364
+            $ctxt[] = EE_Registry::instance()->CAP->current_user_can(
365 365
                 'ee_edit_message',
366 366
                 'espresso_messages_edit_message_template',
367 367
                 $item->ID()
368 368
             )
369 369
                 ? '<a'
370 370
                   . $inactive
371
-                  . ' class="' . $item->message_type() . '-' . $context . '-edit-link"'
372
-                  . ' href="' . $edit_link . '"'
373
-                  . ' title="' . esc_attr__('Edit Context', 'event_espresso') . '">'
371
+                  . ' class="'.$item->message_type().'-'.$context.'-edit-link"'
372
+                  . ' href="'.$edit_link.'"'
373
+                  . ' title="'.esc_attr__('Edit Context', 'event_espresso').'">'
374 374
                   . $context_title
375 375
                   . '</a>'
376 376
                 : $context_title;
Please login to merge, or discard this patch.
admin_pages/messages/Messages_Template_List_Table.class.php 2 patches
Indentation   +320 added lines, -320 removed lines patch added patch discarded remove patch
@@ -13,325 +13,325 @@
 block discarded – undo
13 13
 {
14 14
 
15 15
 
16
-    /**
17
-     * @return Messages_Admin_Page
18
-     */
19
-    public function get_admin_page()
20
-    {
21
-        return $this->_admin_page;
22
-    }
23
-
24
-
25
-    /**
26
-     * Setup data object
27
-     */
28
-    protected function _setup_data()
29
-    {
30
-        $this->_data           = $this->get_admin_page()->get_message_templates(
31
-            $this->_per_page,
32
-            $this->_view,
33
-            false
34
-        );
35
-        $this->_all_data_count = $this->get_admin_page()->get_message_templates(
36
-            $this->_per_page,
37
-            $this->_view,
38
-            true,
39
-            true
40
-        );
41
-    }
42
-
43
-
44
-    /**
45
-     * Set internal properties
46
-     */
47
-    protected function _set_properties()
48
-    {
49
-        $this->_wp_list_args = array(
50
-            'singular' => esc_html__('Message Template Group', 'event_espresso'),
51
-            'plural'   => esc_html__('Message Template', 'event_espresso'),
52
-            'ajax'     => true, //for now,
53
-            'screen'   => $this->get_admin_page()->get_current_screen()->id,
54
-        );
55
-        $this->_columns      = array(
56
-            //'cb' => '<input type="checkbox" />', //no deleting default (global) templates!
57
-            'message_type' => esc_html__('Message Type', 'event_espresso'),
58
-            'messenger'    => esc_html__('Messenger', 'event_espresso'),
59
-            'description'  => esc_html__('Description', 'event_espresso'),
60
-        );
61
-
62
-        $this->_sortable_columns = array(
63
-            'messenger' => array('MTP_messenger' => true),
64
-        );
65
-
66
-        $this->_hidden_columns = array();
67
-    }
68
-
69
-
70
-    /**
71
-     * Overriding the single_row method from parent to verify whether the $item has an accessible
72
-     * message_type or messenger object before generating the row.
73
-     *
74
-     * @param EE_Message_Template_Group $item
75
-     * @return string
76
-     */
77
-    public function single_row($item)
78
-    {
79
-        $message_type = $item->message_type_obj();
80
-        $messenger    = $item->messenger_obj();
81
-
82
-        if (! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) {
83
-            echo '';
84
-            return;
85
-        }
86
-
87
-        parent::single_row($item);
88
-    }
89
-
90
-
91
-    /**
92
-     * @return array
93
-     */
94
-    protected function _get_table_filters()
95
-    {
96
-        $filters = array();
97
-
98
-        //get select inputs
99
-        $select_inputs = array(
100
-            $this->_get_messengers_dropdown_filter(),
101
-            $this->_get_message_types_dropdown_filter(),
102
-        );
103
-
104
-        //set filters to select inputs if they aren't empty
105
-        foreach ($select_inputs as $select_input) {
106
-            if ($select_input) {
107
-                $filters[] = $select_input;
108
-            }
109
-        }
110
-        return $filters;
111
-    }
112
-
113
-    /**
114
-     * we're just removing the search box for message templates, not needed.
115
-     *
116
-     * @return string (empty);
117
-     */
118
-    function search_box($text, $input_id)
119
-    {
120
-        return '';
121
-    }
122
-
123
-
124
-    /**
125
-     * Add counts to the _views property
126
-     */
127
-    protected function _add_view_counts()
128
-    {
129
-        foreach ($this->_views as $view => $args) {
130
-            $this->_views[$view]['count'] = $this->get_admin_page()->get_message_templates(
131
-                $this->_per_page,
132
-                $view,
133
-                true,
134
-                true
135
-            );
136
-        }
137
-    }
138
-
139
-
140
-    /**
141
-     * @param EE_Message_Template_Group $item
142
-     * @return string
143
-     */
144
-    public function column_cb($item)
145
-    {
146
-        return '';
147
-    }
148
-
149
-
150
-    /**
151
-     * @param EE_Message_Template_Group $item
152
-     * @return string
153
-     */
154
-    function column_description($item)
155
-    {
156
-        return '<p>' . $item->message_type_obj()->description . '</p>';
157
-    }
158
-
159
-
160
-    /**
161
-     * @param EE_Message_Template_Group $item
162
-     * @return string
163
-     */
164
-    function column_messenger($item)
165
-    {
166
-        //Build row actions
167
-        $actions = array();
168
-
169
-        // edit link but only if item isn't trashed.
170
-        if (! $item->get('MTP_deleted')
171
-            && EE_Registry::instance()->CAP->current_user_can(
172
-                'ee_edit_message',
173
-                'espresso_messages_edit_message_template',
174
-                $item->ID()
175
-            )) {
176
-            $edit_lnk_url    = EE_Admin_Page::add_query_args_and_nonce(
177
-                array(
178
-                    'action' => 'edit_message_template',
179
-                    'id'     => $item->GRP_ID(),
180
-                ),
181
-                EE_MSG_ADMIN_URL
182
-            );
183
-            $actions['edit'] = '<a href="' . $edit_lnk_url . '"'
184
-                               . ' class="' . $item->message_type() . '-edit-link"'
185
-                               . ' title="' . esc_attr__('Edit Template Group', 'event_espresso') . '">'
186
-                               . esc_html__('Edit', 'event_espresso')
187
-                               . '</a>';
188
-        }
189
-
190
-        $name_link = ! $item->get('MTP_deleted')
191
-                     && EE_Registry::instance()->CAP->current_user_can(
192
-                         'ee_edit_message',
193
-                         'espresso_messages_edit_message_template',
194
-                         $item->ID()
195
-                     )
196
-            ? '<a href="' . $edit_lnk_url . '"'
197
-              . ' title="' . esc_attr__('Edit Template Group', 'event_espresso') . '">'
198
-              . ucwords($item->messenger_obj()->label['singular'])
199
-              . '</a>'
200
-            : ucwords($item->messenger_obj()->label['singular']);
201
-
202
-        //we want to display the contexts in here so we need to set them up
203
-        $c_label           = $item->context_label();
204
-        $c_configs         = $item->contexts_config();
205
-        $ctxt              = array();
206
-        $context_templates = $item->context_templates();
207
-        foreach ($context_templates as $context => $template_fields) {
208
-            $mtp_to        = ! empty($context_templates[$context]['to'])
209
-                             && $context_templates[$context]['to'] instanceof EE_Message_Template
210
-                ? $context_templates[$context]['to']->get('MTP_content')
211
-                : null;
212
-            $inactive      = empty($mtp_to)
213
-                             && ! empty($context_templates[$context]['to'])
214
-                ? ' class="mtp-inactive"'
215
-                : '';
216
-            $context_title = ucwords($c_configs[$context]['label']);
217
-            $edit_link     = EE_Admin_Page::add_query_args_and_nonce(array('action'  => 'edit_message_template',
218
-                                                                           'id'      => $item->GRP_ID(),
219
-                                                                           'context' => $context,
220
-            ), EE_MSG_ADMIN_URL);
221
-            $ctxt[]        = EE_Registry::instance()->CAP->current_user_can(
222
-                'ee_edit_message',
223
-                'espresso_messages_edit_message_template',
224
-                $item->ID()
225
-            )
226
-                ? '<a' . $inactive
227
-                  . ' href="' . $edit_link . '"'
228
-                  . ' class="' . $item->message_type() . '-' . $context . '-edit-link"'
229
-                  . ' title="' . esc_attr__('Edit Context', 'event_espresso') . '">'
230
-                  . $context_title
231
-                  . '</a>'
232
-                : $context_title;
233
-        }
234
-
235
-        $ctx_content = ! $item->get('MTP_deleted')
236
-                       && EE_Registry::instance()->CAP->current_user_can(
237
-                           'ee_edit_message',
238
-                           'espresso_messages_edit_message_template',
239
-                           $item->ID()
240
-                       )
241
-            ? sprintf(
242
-                '<strong>%s:</strong> ',
243
-                ucwords($c_label['plural'])
244
-            )
245
-              . implode(' | ', $ctxt)
246
-            : '';
247
-
248
-
249
-        //Return the name contents
250
-        return sprintf(
251
-            '%1$s <span style="color:silver">(id:%2$s)</span><br />%3$s%4$s',
252
-            /* $1%s */
253
-            $name_link,
254
-            /* $2%s */
255
-            $item->GRP_ID(),
256
-            /* %4$s */
257
-            $ctx_content,
258
-            /* $3%s */
259
-            $this->row_actions($actions)
260
-        );
261
-    }
262
-
263
-    /**
264
-     * column_message_type
265
-     *
266
-     * @param  EE_Message_Template_Group  $item message info for the row
267
-     * @return string       message_type name
268
-     */
269
-    function column_message_type($item)
270
-    {
271
-        return ucwords($item->message_type_obj()->label['singular']);
272
-    }
273
-
274
-
275
-
276
-    /**
277
-     * Generate dropdown filter select input for messengers
278
-     *
279
-     * @return string
280
-     */
281
-    protected function _get_messengers_dropdown_filter()
282
-    {
283
-        $messenger_options                                   = array();
284
-        $active_message_template_groups_grouped_by_messenger = EEM_Message_Template_Group::instance()->get_all(
285
-            array(
286
-                array(
287
-                    'MTP_is_active' => true,
288
-                    'MTP_is_global' => true,
289
-                ),
290
-                'group_by' => 'MTP_messenger',
291
-            )
292
-        );
293
-
294
-        foreach ($active_message_template_groups_grouped_by_messenger as $active_message_template_group) {
295
-            if ($active_message_template_group instanceof EE_Message_Template_Group) {
296
-                $messenger                                                      = $active_message_template_group->messenger_obj();
297
-                $messenger_label                                                = $messenger instanceof EE_messenger
298
-                    ? $messenger->label['singular']
299
-                    : $active_message_template_group->messenger();
300
-                $messenger_options[$active_message_template_group->messenger()] = ucwords($messenger_label);
301
-            }
302
-        }
303
-        return $this->get_admin_page()->get_messengers_select_input($messenger_options);
304
-    }
305
-
306
-
307
-    /**
308
-     * Generate dropdown filter select input for message types
309
-     *
310
-     * @return string
311
-     */
312
-    protected function _get_message_types_dropdown_filter()
313
-    {
314
-        $message_type_options                                   = array();
315
-        $active_message_template_groups_grouped_by_message_type = EEM_Message_Template_Group::instance()->get_all(
316
-            array(
317
-                array(
318
-                    'MTP_is_active' => true,
319
-                    'MTP_is_global' => true,
320
-                ),
321
-                'group_by' => 'MTP_message_type',
322
-            )
323
-        );
324
-
325
-        foreach ($active_message_template_groups_grouped_by_message_type as $active_message_template_group) {
326
-            if ($active_message_template_group instanceof EE_Message_Template_Group) {
327
-                $message_type                                                         = $active_message_template_group->message_type_obj();
328
-                $message_type_label                                                   = $message_type instanceof EE_message_type
329
-                    ? $message_type->label['singular']
330
-                    : $active_message_template_group->message_type();
331
-                $message_type_options[$active_message_template_group->message_type()] = ucwords($message_type_label);
332
-            }
333
-        }
334
-        return $this->get_admin_page()->get_message_types_select_input($message_type_options);
335
-    }
16
+	/**
17
+	 * @return Messages_Admin_Page
18
+	 */
19
+	public function get_admin_page()
20
+	{
21
+		return $this->_admin_page;
22
+	}
23
+
24
+
25
+	/**
26
+	 * Setup data object
27
+	 */
28
+	protected function _setup_data()
29
+	{
30
+		$this->_data           = $this->get_admin_page()->get_message_templates(
31
+			$this->_per_page,
32
+			$this->_view,
33
+			false
34
+		);
35
+		$this->_all_data_count = $this->get_admin_page()->get_message_templates(
36
+			$this->_per_page,
37
+			$this->_view,
38
+			true,
39
+			true
40
+		);
41
+	}
42
+
43
+
44
+	/**
45
+	 * Set internal properties
46
+	 */
47
+	protected function _set_properties()
48
+	{
49
+		$this->_wp_list_args = array(
50
+			'singular' => esc_html__('Message Template Group', 'event_espresso'),
51
+			'plural'   => esc_html__('Message Template', 'event_espresso'),
52
+			'ajax'     => true, //for now,
53
+			'screen'   => $this->get_admin_page()->get_current_screen()->id,
54
+		);
55
+		$this->_columns      = array(
56
+			//'cb' => '<input type="checkbox" />', //no deleting default (global) templates!
57
+			'message_type' => esc_html__('Message Type', 'event_espresso'),
58
+			'messenger'    => esc_html__('Messenger', 'event_espresso'),
59
+			'description'  => esc_html__('Description', 'event_espresso'),
60
+		);
61
+
62
+		$this->_sortable_columns = array(
63
+			'messenger' => array('MTP_messenger' => true),
64
+		);
65
+
66
+		$this->_hidden_columns = array();
67
+	}
68
+
69
+
70
+	/**
71
+	 * Overriding the single_row method from parent to verify whether the $item has an accessible
72
+	 * message_type or messenger object before generating the row.
73
+	 *
74
+	 * @param EE_Message_Template_Group $item
75
+	 * @return string
76
+	 */
77
+	public function single_row($item)
78
+	{
79
+		$message_type = $item->message_type_obj();
80
+		$messenger    = $item->messenger_obj();
81
+
82
+		if (! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) {
83
+			echo '';
84
+			return;
85
+		}
86
+
87
+		parent::single_row($item);
88
+	}
89
+
90
+
91
+	/**
92
+	 * @return array
93
+	 */
94
+	protected function _get_table_filters()
95
+	{
96
+		$filters = array();
97
+
98
+		//get select inputs
99
+		$select_inputs = array(
100
+			$this->_get_messengers_dropdown_filter(),
101
+			$this->_get_message_types_dropdown_filter(),
102
+		);
103
+
104
+		//set filters to select inputs if they aren't empty
105
+		foreach ($select_inputs as $select_input) {
106
+			if ($select_input) {
107
+				$filters[] = $select_input;
108
+			}
109
+		}
110
+		return $filters;
111
+	}
112
+
113
+	/**
114
+	 * we're just removing the search box for message templates, not needed.
115
+	 *
116
+	 * @return string (empty);
117
+	 */
118
+	function search_box($text, $input_id)
119
+	{
120
+		return '';
121
+	}
122
+
123
+
124
+	/**
125
+	 * Add counts to the _views property
126
+	 */
127
+	protected function _add_view_counts()
128
+	{
129
+		foreach ($this->_views as $view => $args) {
130
+			$this->_views[$view]['count'] = $this->get_admin_page()->get_message_templates(
131
+				$this->_per_page,
132
+				$view,
133
+				true,
134
+				true
135
+			);
136
+		}
137
+	}
138
+
139
+
140
+	/**
141
+	 * @param EE_Message_Template_Group $item
142
+	 * @return string
143
+	 */
144
+	public function column_cb($item)
145
+	{
146
+		return '';
147
+	}
148
+
149
+
150
+	/**
151
+	 * @param EE_Message_Template_Group $item
152
+	 * @return string
153
+	 */
154
+	function column_description($item)
155
+	{
156
+		return '<p>' . $item->message_type_obj()->description . '</p>';
157
+	}
158
+
159
+
160
+	/**
161
+	 * @param EE_Message_Template_Group $item
162
+	 * @return string
163
+	 */
164
+	function column_messenger($item)
165
+	{
166
+		//Build row actions
167
+		$actions = array();
168
+
169
+		// edit link but only if item isn't trashed.
170
+		if (! $item->get('MTP_deleted')
171
+			&& EE_Registry::instance()->CAP->current_user_can(
172
+				'ee_edit_message',
173
+				'espresso_messages_edit_message_template',
174
+				$item->ID()
175
+			)) {
176
+			$edit_lnk_url    = EE_Admin_Page::add_query_args_and_nonce(
177
+				array(
178
+					'action' => 'edit_message_template',
179
+					'id'     => $item->GRP_ID(),
180
+				),
181
+				EE_MSG_ADMIN_URL
182
+			);
183
+			$actions['edit'] = '<a href="' . $edit_lnk_url . '"'
184
+							   . ' class="' . $item->message_type() . '-edit-link"'
185
+							   . ' title="' . esc_attr__('Edit Template Group', 'event_espresso') . '">'
186
+							   . esc_html__('Edit', 'event_espresso')
187
+							   . '</a>';
188
+		}
189
+
190
+		$name_link = ! $item->get('MTP_deleted')
191
+					 && EE_Registry::instance()->CAP->current_user_can(
192
+						 'ee_edit_message',
193
+						 'espresso_messages_edit_message_template',
194
+						 $item->ID()
195
+					 )
196
+			? '<a href="' . $edit_lnk_url . '"'
197
+			  . ' title="' . esc_attr__('Edit Template Group', 'event_espresso') . '">'
198
+			  . ucwords($item->messenger_obj()->label['singular'])
199
+			  . '</a>'
200
+			: ucwords($item->messenger_obj()->label['singular']);
201
+
202
+		//we want to display the contexts in here so we need to set them up
203
+		$c_label           = $item->context_label();
204
+		$c_configs         = $item->contexts_config();
205
+		$ctxt              = array();
206
+		$context_templates = $item->context_templates();
207
+		foreach ($context_templates as $context => $template_fields) {
208
+			$mtp_to        = ! empty($context_templates[$context]['to'])
209
+							 && $context_templates[$context]['to'] instanceof EE_Message_Template
210
+				? $context_templates[$context]['to']->get('MTP_content')
211
+				: null;
212
+			$inactive      = empty($mtp_to)
213
+							 && ! empty($context_templates[$context]['to'])
214
+				? ' class="mtp-inactive"'
215
+				: '';
216
+			$context_title = ucwords($c_configs[$context]['label']);
217
+			$edit_link     = EE_Admin_Page::add_query_args_and_nonce(array('action'  => 'edit_message_template',
218
+																		   'id'      => $item->GRP_ID(),
219
+																		   'context' => $context,
220
+			), EE_MSG_ADMIN_URL);
221
+			$ctxt[]        = EE_Registry::instance()->CAP->current_user_can(
222
+				'ee_edit_message',
223
+				'espresso_messages_edit_message_template',
224
+				$item->ID()
225
+			)
226
+				? '<a' . $inactive
227
+				  . ' href="' . $edit_link . '"'
228
+				  . ' class="' . $item->message_type() . '-' . $context . '-edit-link"'
229
+				  . ' title="' . esc_attr__('Edit Context', 'event_espresso') . '">'
230
+				  . $context_title
231
+				  . '</a>'
232
+				: $context_title;
233
+		}
234
+
235
+		$ctx_content = ! $item->get('MTP_deleted')
236
+					   && EE_Registry::instance()->CAP->current_user_can(
237
+						   'ee_edit_message',
238
+						   'espresso_messages_edit_message_template',
239
+						   $item->ID()
240
+					   )
241
+			? sprintf(
242
+				'<strong>%s:</strong> ',
243
+				ucwords($c_label['plural'])
244
+			)
245
+			  . implode(' | ', $ctxt)
246
+			: '';
247
+
248
+
249
+		//Return the name contents
250
+		return sprintf(
251
+			'%1$s <span style="color:silver">(id:%2$s)</span><br />%3$s%4$s',
252
+			/* $1%s */
253
+			$name_link,
254
+			/* $2%s */
255
+			$item->GRP_ID(),
256
+			/* %4$s */
257
+			$ctx_content,
258
+			/* $3%s */
259
+			$this->row_actions($actions)
260
+		);
261
+	}
262
+
263
+	/**
264
+	 * column_message_type
265
+	 *
266
+	 * @param  EE_Message_Template_Group  $item message info for the row
267
+	 * @return string       message_type name
268
+	 */
269
+	function column_message_type($item)
270
+	{
271
+		return ucwords($item->message_type_obj()->label['singular']);
272
+	}
273
+
274
+
275
+
276
+	/**
277
+	 * Generate dropdown filter select input for messengers
278
+	 *
279
+	 * @return string
280
+	 */
281
+	protected function _get_messengers_dropdown_filter()
282
+	{
283
+		$messenger_options                                   = array();
284
+		$active_message_template_groups_grouped_by_messenger = EEM_Message_Template_Group::instance()->get_all(
285
+			array(
286
+				array(
287
+					'MTP_is_active' => true,
288
+					'MTP_is_global' => true,
289
+				),
290
+				'group_by' => 'MTP_messenger',
291
+			)
292
+		);
293
+
294
+		foreach ($active_message_template_groups_grouped_by_messenger as $active_message_template_group) {
295
+			if ($active_message_template_group instanceof EE_Message_Template_Group) {
296
+				$messenger                                                      = $active_message_template_group->messenger_obj();
297
+				$messenger_label                                                = $messenger instanceof EE_messenger
298
+					? $messenger->label['singular']
299
+					: $active_message_template_group->messenger();
300
+				$messenger_options[$active_message_template_group->messenger()] = ucwords($messenger_label);
301
+			}
302
+		}
303
+		return $this->get_admin_page()->get_messengers_select_input($messenger_options);
304
+	}
305
+
306
+
307
+	/**
308
+	 * Generate dropdown filter select input for message types
309
+	 *
310
+	 * @return string
311
+	 */
312
+	protected function _get_message_types_dropdown_filter()
313
+	{
314
+		$message_type_options                                   = array();
315
+		$active_message_template_groups_grouped_by_message_type = EEM_Message_Template_Group::instance()->get_all(
316
+			array(
317
+				array(
318
+					'MTP_is_active' => true,
319
+					'MTP_is_global' => true,
320
+				),
321
+				'group_by' => 'MTP_message_type',
322
+			)
323
+		);
324
+
325
+		foreach ($active_message_template_groups_grouped_by_message_type as $active_message_template_group) {
326
+			if ($active_message_template_group instanceof EE_Message_Template_Group) {
327
+				$message_type                                                         = $active_message_template_group->message_type_obj();
328
+				$message_type_label                                                   = $message_type instanceof EE_message_type
329
+					? $message_type->label['singular']
330
+					: $active_message_template_group->message_type();
331
+				$message_type_options[$active_message_template_group->message_type()] = ucwords($message_type_label);
332
+			}
333
+		}
334
+		return $this->get_admin_page()->get_message_types_select_input($message_type_options);
335
+	}
336 336
 
337 337
 }
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
      */
28 28
     protected function _setup_data()
29 29
     {
30
-        $this->_data           = $this->get_admin_page()->get_message_templates(
30
+        $this->_data = $this->get_admin_page()->get_message_templates(
31 31
             $this->_per_page,
32 32
             $this->_view,
33 33
             false
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
             'ajax'     => true, //for now,
53 53
             'screen'   => $this->get_admin_page()->get_current_screen()->id,
54 54
         );
55
-        $this->_columns      = array(
55
+        $this->_columns = array(
56 56
             //'cb' => '<input type="checkbox" />', //no deleting default (global) templates!
57 57
             'message_type' => esc_html__('Message Type', 'event_espresso'),
58 58
             'messenger'    => esc_html__('Messenger', 'event_espresso'),
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
         $message_type = $item->message_type_obj();
80 80
         $messenger    = $item->messenger_obj();
81 81
 
82
-        if (! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) {
82
+        if ( ! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) {
83 83
             echo '';
84 84
             return;
85 85
         }
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
      */
154 154
     function column_description($item)
155 155
     {
156
-        return '<p>' . $item->message_type_obj()->description . '</p>';
156
+        return '<p>'.$item->message_type_obj()->description.'</p>';
157 157
     }
158 158
 
159 159
 
@@ -167,22 +167,22 @@  discard block
 block discarded – undo
167 167
         $actions = array();
168 168
 
169 169
         // edit link but only if item isn't trashed.
170
-        if (! $item->get('MTP_deleted')
170
+        if ( ! $item->get('MTP_deleted')
171 171
             && EE_Registry::instance()->CAP->current_user_can(
172 172
                 'ee_edit_message',
173 173
                 'espresso_messages_edit_message_template',
174 174
                 $item->ID()
175 175
             )) {
176
-            $edit_lnk_url    = EE_Admin_Page::add_query_args_and_nonce(
176
+            $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
177 177
                 array(
178 178
                     'action' => 'edit_message_template',
179 179
                     'id'     => $item->GRP_ID(),
180 180
                 ),
181 181
                 EE_MSG_ADMIN_URL
182 182
             );
183
-            $actions['edit'] = '<a href="' . $edit_lnk_url . '"'
184
-                               . ' class="' . $item->message_type() . '-edit-link"'
185
-                               . ' title="' . esc_attr__('Edit Template Group', 'event_espresso') . '">'
183
+            $actions['edit'] = '<a href="'.$edit_lnk_url.'"'
184
+                               . ' class="'.$item->message_type().'-edit-link"'
185
+                               . ' title="'.esc_attr__('Edit Template Group', 'event_espresso').'">'
186 186
                                . esc_html__('Edit', 'event_espresso')
187 187
                                . '</a>';
188 188
         }
@@ -193,8 +193,8 @@  discard block
 block discarded – undo
193 193
                          'espresso_messages_edit_message_template',
194 194
                          $item->ID()
195 195
                      )
196
-            ? '<a href="' . $edit_lnk_url . '"'
197
-              . ' title="' . esc_attr__('Edit Template Group', 'event_espresso') . '">'
196
+            ? '<a href="'.$edit_lnk_url.'"'
197
+              . ' title="'.esc_attr__('Edit Template Group', 'event_espresso').'">'
198 198
               . ucwords($item->messenger_obj()->label['singular'])
199 199
               . '</a>'
200 200
             : ucwords($item->messenger_obj()->label['singular']);
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
                              && $context_templates[$context]['to'] instanceof EE_Message_Template
210 210
                 ? $context_templates[$context]['to']->get('MTP_content')
211 211
                 : null;
212
-            $inactive      = empty($mtp_to)
212
+            $inactive = empty($mtp_to)
213 213
                              && ! empty($context_templates[$context]['to'])
214 214
                 ? ' class="mtp-inactive"'
215 215
                 : '';
@@ -218,15 +218,15 @@  discard block
 block discarded – undo
218 218
                                                                            'id'      => $item->GRP_ID(),
219 219
                                                                            'context' => $context,
220 220
             ), EE_MSG_ADMIN_URL);
221
-            $ctxt[]        = EE_Registry::instance()->CAP->current_user_can(
221
+            $ctxt[] = EE_Registry::instance()->CAP->current_user_can(
222 222
                 'ee_edit_message',
223 223
                 'espresso_messages_edit_message_template',
224 224
                 $item->ID()
225 225
             )
226
-                ? '<a' . $inactive
227
-                  . ' href="' . $edit_link . '"'
228
-                  . ' class="' . $item->message_type() . '-' . $context . '-edit-link"'
229
-                  . ' title="' . esc_attr__('Edit Context', 'event_espresso') . '">'
226
+                ? '<a'.$inactive
227
+                  . ' href="'.$edit_link.'"'
228
+                  . ' class="'.$item->message_type().'-'.$context.'-edit-link"'
229
+                  . ' title="'.esc_attr__('Edit Context', 'event_espresso').'">'
230 230
                   . $context_title
231 231
                   . '</a>'
232 232
                 : $context_title;
Please login to merge, or discard this patch.
acceptance_tests/Page/CoreAdmin.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -31,9 +31,9 @@
 block discarded – undo
31 31
      */
32 32
     public static function adminUrl($page = 'espresso_events', $action = 'default', $additional_params = '')
33 33
     {
34
-        $url = self::URL_PREFIX . $page;
35
-        $url .= $action ? '&action=' . $action : '';
36
-        $url .= $additional_params ? '&' . ltrim('&', ltrim('?', $additional_params)) : '';
34
+        $url = self::URL_PREFIX.$page;
35
+        $url .= $action ? '&action='.$action : '';
36
+        $url .= $additional_params ? '&'.ltrim('&', ltrim('?', $additional_params)) : '';
37 37
         return $url;
38 38
     }
39 39
 
Please login to merge, or discard this patch.
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -13,63 +13,63 @@
 block discarded – undo
13 13
 class CoreAdmin
14 14
 {
15 15
 
16
-    /**
17
-     * @var string
18
-     */
19
-    const URL_PREFIX = 'admin.php?page=';
16
+	/**
17
+	 * @var string
18
+	 */
19
+	const URL_PREFIX = 'admin.php?page=';
20 20
 
21 21
 
22
-    /**
23
-     * This is the selector for the next page button on list tables.
24
-     * @var string
25
-     */
26
-    const ADMIN_LIST_TABLE_NEXT_PAGE_CLASS = '.next-page';
22
+	/**
23
+	 * This is the selector for the next page button on list tables.
24
+	 * @var string
25
+	 */
26
+	const ADMIN_LIST_TABLE_NEXT_PAGE_CLASS = '.next-page';
27 27
 
28 28
 
29
-    /**
30
-     * The selector for the search input submit button on list table pages
31
-     * @var string
32
-     */
33
-    const LIST_TABLE_SEARCH_SUBMIT_SELECTOR = '#search-submit';
29
+	/**
30
+	 * The selector for the search input submit button on list table pages
31
+	 * @var string
32
+	 */
33
+	const LIST_TABLE_SEARCH_SUBMIT_SELECTOR = '#search-submit';
34 34
 
35 35
 
36
-    /**
37
-     * Selector for the screen options dropdown.
38
-     * @var string
39
-     */
40
-    const WP_SCREEN_SETTINGS_LINK_SELECTOR = '#show-settings-link';
36
+	/**
37
+	 * Selector for the screen options dropdown.
38
+	 * @var string
39
+	 */
40
+	const WP_SCREEN_SETTINGS_LINK_SELECTOR = '#show-settings-link';
41 41
 
42 42
 
43
-    /**
44
-     * Selector for the per page field setting selector (found within screen options dropdown)
45
-     * @var string
46
-     */
47
-    const WP_SCREEN_SETTINGS_PER_PAGE_FIELD_SELECTOR = '.screen-per-page';
43
+	/**
44
+	 * Selector for the per page field setting selector (found within screen options dropdown)
45
+	 * @var string
46
+	 */
47
+	const WP_SCREEN_SETTINGS_PER_PAGE_FIELD_SELECTOR = '.screen-per-page';
48 48
 
49 49
 
50
-    /**
51
-     * Selector for apply screen options settings.
52
-     * @var string
53
-     */
54
-    const WP_SCREEN_OPTIONS_APPLY_SETTINGS_BUTTON_SELECTOR = '#screen-options-apply';
50
+	/**
51
+	 * Selector for apply screen options settings.
52
+	 * @var string
53
+	 */
54
+	const WP_SCREEN_OPTIONS_APPLY_SETTINGS_BUTTON_SELECTOR = '#screen-options-apply';
55 55
 
56 56
 
57
-    /**
58
-     * Get the EE admin url for the given properties.
59
-     * Note, this is JUST the endpoint for the admin route.  It is expected that the actor/test would be calling this
60
-     * with `amOnAdminPage` action.
61
-     *
62
-     * @param string $page
63
-     * @param string $action
64
-     * @param string $additional_params
65
-     * @return string
66
-     */
67
-    public static function adminUrl($page = 'espresso_events', $action = 'default', $additional_params = '')
68
-    {
69
-        $url = self::URL_PREFIX . $page;
70
-        $url .= $action ? '&action=' . $action : '';
71
-        $url .= $additional_params ? '&' . ltrim('&', ltrim('?', $additional_params)) : '';
72
-        return $url;
73
-    }
57
+	/**
58
+	 * Get the EE admin url for the given properties.
59
+	 * Note, this is JUST the endpoint for the admin route.  It is expected that the actor/test would be calling this
60
+	 * with `amOnAdminPage` action.
61
+	 *
62
+	 * @param string $page
63
+	 * @param string $action
64
+	 * @param string $additional_params
65
+	 * @return string
66
+	 */
67
+	public static function adminUrl($page = 'espresso_events', $action = 'default', $additional_params = '')
68
+	{
69
+		$url = self::URL_PREFIX . $page;
70
+		$url .= $action ? '&action=' . $action : '';
71
+		$url .= $additional_params ? '&' . ltrim('&', ltrim('?', $additional_params)) : '';
72
+		return $url;
73
+	}
74 74
 
75 75
 }
76 76
\ No newline at end of file
Please login to merge, or discard this patch.
core/db_models/EEM_WP_User.model.php 2 patches
Indentation   +115 added lines, -115 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
 
@@ -15,129 +15,129 @@  discard block
 block discarded – undo
15 15
 class EEM_WP_User extends EEM_Base
16 16
 {
17 17
 
18
-    /**
19
-     * private instance of the EEM_WP_User object
20
-     *
21
-     * @type EEM_WP_User
22
-     */
23
-    protected static $_instance = null;
18
+	/**
19
+	 * private instance of the EEM_WP_User object
20
+	 *
21
+	 * @type EEM_WP_User
22
+	 */
23
+	protected static $_instance = null;
24 24
 
25 25
 
26 26
 
27
-    /**
28
-     *    constructor
29
-     *
30
-     * @param null $timezone
31
-     * @throws \EE_Error
32
-     */
33
-    protected function __construct($timezone = null)
34
-    {
35
-        $this->singular_item = __('WP_User', 'event_espresso');
36
-        $this->plural_item = __('WP_Users', 'event_espresso');
37
-        global $wpdb;
38
-        $this->_tables = array(
39
-            'WP_User' => new EE_Primary_Table($wpdb->users, 'ID', true),
40
-        );
41
-        $this->_fields = array(
42
-            'WP_User' => array(
43
-                'ID'                  => new EE_Primary_Key_Int_Field('ID', __('WP_User ID', 'event_espresso')),
44
-                'user_login'          => new EE_Plain_Text_Field(
45
-                    'user_login',
46
-                    __('User Login', 'event_espresso'),
47
-                    false,
48
-                    ''
49
-                ),
50
-                'user_pass'           => new EE_Plain_Text_Field(
51
-                    'user_pass',
52
-                    __('User Password', 'event_espresso'),
53
-                    false,
54
-                    ''
55
-                ),
56
-                'user_nicename'       => new EE_Plain_Text_Field(
57
-                    'user_nicename',
58
-                    __(' User Nice Name', 'event_espresso'),
59
-                    false,
60
-                    ''
61
-                ),
62
-                'user_email'          => new EE_Email_Field(
63
-                    'user_email',
64
-                    __('User Email', 'event_espresso'),
65
-                    false
66
-                ),
67
-                'user_registered'     => new EE_Datetime_Field(
68
-                    'user_registered',
69
-                    __('Date User Registered', 'event_espresso'),
70
-                    false,
71
-                    EE_Datetime_Field::now,
72
-                    $timezone
73
-                ),
74
-                'user_activation_key' => new EE_Plain_Text_Field(
75
-                    'user_activation_key',
76
-                    __('User Activation Key', 'event_espresso'),
77
-                    false,
78
-                    ''
79
-                ),
80
-                'user_status'         => new EE_Integer_Field(
81
-                    'user_status',
82
-                    __('User Status', 'event_espresso'),
83
-                    false,
84
-                    0
85
-                ),
86
-                'display_name'        => new EE_Plain_Text_Field(
87
-                    'display_name',
88
-                    __('Display Name', 'event_espresso'),
89
-                    false,
90
-                    ''
91
-                ),
92
-            ),
93
-        );
94
-        $this->_model_relations = array(
95
-            'Attendee'       => new EE_Has_Many_Relation(),
96
-            'Change_Log'     => new EE_Has_Many_Relation(),
97
-            'Event'          => new EE_Has_Many_Relation(),
98
-            'Payment_Method' => new EE_Has_Many_Relation(),
99
-            'Price'          => new EE_Has_Many_Relation(),
100
-            'Price_Type'     => new EE_Has_Many_Relation(),
101
-            'Question'       => new EE_Has_Many_Relation(),
102
-            'Question_Group' => new EE_Has_Many_Relation(),
103
-            'Ticket'         => new EE_Has_Many_Relation(),
104
-            'Venue'          => new EE_Has_Many_Relation(),
105
-            'Message'        => new EE_Has_Many_Relation(),
106
-        );
107
-        $this->_wp_core_model = true;
108
-        $this->_caps_slug = 'users';
109
-        $this->_cap_contexts_to_cap_action_map[EEM_Base::caps_read] = 'list';
110
-        $this->_cap_contexts_to_cap_action_map[EEM_Base::caps_read_admin] = 'list';
111
-        foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) {
112
-            $this->_cap_restriction_generators[$context] = new EE_Restriction_Generator_WP_User();
113
-        }
114
-        //@todo: account for create_users controls whether they can create users at all
115
-        parent::__construct($timezone);
116
-    }
27
+	/**
28
+	 *    constructor
29
+	 *
30
+	 * @param null $timezone
31
+	 * @throws \EE_Error
32
+	 */
33
+	protected function __construct($timezone = null)
34
+	{
35
+		$this->singular_item = __('WP_User', 'event_espresso');
36
+		$this->plural_item = __('WP_Users', 'event_espresso');
37
+		global $wpdb;
38
+		$this->_tables = array(
39
+			'WP_User' => new EE_Primary_Table($wpdb->users, 'ID', true),
40
+		);
41
+		$this->_fields = array(
42
+			'WP_User' => array(
43
+				'ID'                  => new EE_Primary_Key_Int_Field('ID', __('WP_User ID', 'event_espresso')),
44
+				'user_login'          => new EE_Plain_Text_Field(
45
+					'user_login',
46
+					__('User Login', 'event_espresso'),
47
+					false,
48
+					''
49
+				),
50
+				'user_pass'           => new EE_Plain_Text_Field(
51
+					'user_pass',
52
+					__('User Password', 'event_espresso'),
53
+					false,
54
+					''
55
+				),
56
+				'user_nicename'       => new EE_Plain_Text_Field(
57
+					'user_nicename',
58
+					__(' User Nice Name', 'event_espresso'),
59
+					false,
60
+					''
61
+				),
62
+				'user_email'          => new EE_Email_Field(
63
+					'user_email',
64
+					__('User Email', 'event_espresso'),
65
+					false
66
+				),
67
+				'user_registered'     => new EE_Datetime_Field(
68
+					'user_registered',
69
+					__('Date User Registered', 'event_espresso'),
70
+					false,
71
+					EE_Datetime_Field::now,
72
+					$timezone
73
+				),
74
+				'user_activation_key' => new EE_Plain_Text_Field(
75
+					'user_activation_key',
76
+					__('User Activation Key', 'event_espresso'),
77
+					false,
78
+					''
79
+				),
80
+				'user_status'         => new EE_Integer_Field(
81
+					'user_status',
82
+					__('User Status', 'event_espresso'),
83
+					false,
84
+					0
85
+				),
86
+				'display_name'        => new EE_Plain_Text_Field(
87
+					'display_name',
88
+					__('Display Name', 'event_espresso'),
89
+					false,
90
+					''
91
+				),
92
+			),
93
+		);
94
+		$this->_model_relations = array(
95
+			'Attendee'       => new EE_Has_Many_Relation(),
96
+			'Change_Log'     => new EE_Has_Many_Relation(),
97
+			'Event'          => new EE_Has_Many_Relation(),
98
+			'Payment_Method' => new EE_Has_Many_Relation(),
99
+			'Price'          => new EE_Has_Many_Relation(),
100
+			'Price_Type'     => new EE_Has_Many_Relation(),
101
+			'Question'       => new EE_Has_Many_Relation(),
102
+			'Question_Group' => new EE_Has_Many_Relation(),
103
+			'Ticket'         => new EE_Has_Many_Relation(),
104
+			'Venue'          => new EE_Has_Many_Relation(),
105
+			'Message'        => new EE_Has_Many_Relation(),
106
+		);
107
+		$this->_wp_core_model = true;
108
+		$this->_caps_slug = 'users';
109
+		$this->_cap_contexts_to_cap_action_map[EEM_Base::caps_read] = 'list';
110
+		$this->_cap_contexts_to_cap_action_map[EEM_Base::caps_read_admin] = 'list';
111
+		foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) {
112
+			$this->_cap_restriction_generators[$context] = new EE_Restriction_Generator_WP_User();
113
+		}
114
+		//@todo: account for create_users controls whether they can create users at all
115
+		parent::__construct($timezone);
116
+	}
117 117
 
118 118
 
119 119
 
120
-    /**
121
-     * We don't need a foreign key to the WP_User model, we just need its primary key
122
-     *
123
-     * @return string
124
-     */
125
-    public function wp_user_field_name()
126
-    {
127
-        return $this->primary_key_name();
128
-    }
120
+	/**
121
+	 * We don't need a foreign key to the WP_User model, we just need its primary key
122
+	 *
123
+	 * @return string
124
+	 */
125
+	public function wp_user_field_name()
126
+	{
127
+		return $this->primary_key_name();
128
+	}
129 129
 
130 130
 
131 131
 
132
-    /**
133
-     * This WP_User model IS owned, even though it doesn't have a foreign key to itself
134
-     *
135
-     * @return boolean
136
-     */
137
-    public function is_owned()
138
-    {
139
-        return true;
140
-    }
132
+	/**
133
+	 * This WP_User model IS owned, even though it doesn't have a foreign key to itself
134
+	 *
135
+	 * @return boolean
136
+	 */
137
+	public function is_owned()
138
+	{
139
+		return true;
140
+	}
141 141
 }
142 142
 // End of file EEM_WP_User.model.php
143 143
 // Location: /core/db_models/EEM_WP_User.model.php
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@
 block discarded – undo
1
-<?php if (! defined('EVENT_ESPRESSO_VERSION')) {
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2 2
     exit('No direct script access allowed');
3 3
 }
4 4
 
Please login to merge, or discard this patch.