Completed
Branch master (1201db)
by
unknown
06:46 queued 02:25
created
PaymentMethods/Manager.php 2 patches
Indentation   +190 added lines, -190 removed lines patch added patch discarded remove patch
@@ -20,194 +20,194 @@
 block discarded – undo
20 20
  */
21 21
 class Manager
22 22
 {
23
-    /**
24
-     * List of PMs that can be replaced with PP Commerce.
25
-     * ['payment method name' => 'settings option']
26
-     *
27
-     * @var $pms_can_hide
28
-     */
29
-    protected static $pms_can_hide = [
30
-        'paypal_express' => 'api_username',
31
-        'paypal_pro'     => 'api_username',
32
-        'aim'            => 'login_id',
33
-    ];
34
-
35
-
36
-    /**
37
-     * Manager constructor.
38
-     */
39
-    public function __construct()
40
-    {
41
-        $this->loadPaymentMethods();
42
-        if (is_admin()) {
43
-            // Use only PayPal Commerce if it's a new setup.
44
-            add_filter(
45
-                'FHEE__Payments_Admin_Page___payment_methods_list__payment_methods',
46
-                [__CLASS__, 'hidePaymentMethods']
47
-            );
48
-            // Payment methods related admin notices.
49
-            add_action('admin_init', [__CLASS__, 'adminNotice']);
50
-        }
51
-    }
52
-
53
-
54
-    /**
55
-     * Load all payment methods that are in PaymentMethods folder.
56
-     *
57
-     * @return void
58
-     */
59
-    protected function loadPaymentMethods()
60
-    {
61
-        // Scan the PaymentMethods folder.
62
-        $pms_list = glob(EE_PLUGIN_DIR_PATH . 'PaymentMethods/*', GLOB_ONLYDIR);
63
-        // Filter the discovered PM list.
64
-        $pms_list = apply_filters('FHEE__PaymentMethods__Manager__loadPaymentMethods__pms_list', $pms_list);
65
-        // Clean from duplicates.
66
-        $pms_list = array_unique($pms_list);
67
-        foreach ($pms_list as $pm_path) {
68
-            $this->registerPaymentMethod($pm_path);
69
-        }
70
-    }
71
-
72
-
73
-    /**
74
-     * Looks for the main payment method file and loads it.
75
-     *
76
-     * @param string $pm_path path to the payment method folder
77
-     * @param string $file_ext
78
-     * @param string $pm_namespace
79
-     * @return boolean
80
-     */
81
-    public function registerPaymentMethod(
82
-        string $pm_path,
83
-        string $file_ext = '.php',
84
-        string $pm_namespace = 'EventEspresso\PaymentMethods'
85
-    ): bool {
86
-        do_action('AHEE__PaymentMethods__Manager__registerPaymentMethod__start', $pm_path);
87
-        // Separators should match.
88
-        $pm_path = str_replace('/\\', '/', $pm_path) . DS;
89
-        // Sanitize PM name.
90
-        $module_dir = basename($pm_path);
91
-        // Get class name.
92
-        $pm_class_name = str_replace(' ', '_', $module_dir);
93
-        // Check if file exists.
94
-        if (! is_readable($pm_path . $pm_class_name . $file_ext)) {
95
-            return false;
96
-        }
97
-        // Load the initial PM class.
98
-        require_once($pm_path . DS . $pm_class_name . $file_ext);
99
-        $pm_object = "$pm_namespace\\$pm_class_name";
100
-        if (! class_exists($pm_object)) {
101
-            return false;
102
-        }
103
-        new $pm_object();
104
-        return true;
105
-    }
106
-
107
-
108
-    /**
109
-     * Deactivate a few other PMs if it's a new setup. Use PP Commerce.
110
-     *
111
-     * @param array $pms_to_list
112
-     * @return array
113
-     * @throws EE_Error
114
-     * @throws ReflectionException
115
-     */
116
-    public static function hidePaymentMethods(array $pms_to_list): array
117
-    {
118
-        foreach (self::$pms_can_hide as $pm_name => $pm_option) {
119
-            // Can we deregister this PM ?
120
-            if (isset($pms_to_list[ $pm_name ]) && self::pmCanBeHidden($pm_name, $pm_option)) {
121
-                unset($pms_to_list[ $pm_name ]);
122
-            }
123
-        }
124
-        return $pms_to_list;
125
-    }
126
-
127
-
128
-    /**
129
-     * Deregisters the provided payment method if not used.
130
-     *
131
-     * @param string $pm_name
132
-     * @param string $pm_option
133
-     * @return bool
134
-     * @throws EE_Error
135
-     * @throws ReflectionException
136
-     */
137
-    public static function pmCanBeHidden(string $pm_name, string $pm_option): bool
138
-    {
139
-        $pm_to_hide = EEM_Payment_Method::instance()->get_one_by_slug($pm_name);
140
-        $pm_active  = $pm_active_before = false;
141
-        if ($pm_to_hide instanceof EE_Payment_Method) {
142
-            $pm_active = $pm_to_hide->active();
143
-            // Payment method used before ?
144
-            $option = $pm_to_hide->get_extra_meta($pm_option, true, false);
145
-            $pm_active_before = ! empty($option);
146
-        }
147
-        // If PM not used before and not active, deregister it.
148
-        if (
149
-            apply_filters(
150
-                "FHEE__PaymentMethods__Manager__register_payment_methods__hide_$pm_name",
151
-                ! $pm_active && ! $pm_active_before,
152
-                $pm_name
153
-            )
154
-        ) {
155
-            return true;
156
-        }
157
-        return false;
158
-    }
159
-
160
-
161
-    /**
162
-     * Payment methods related admin notices.
163
-     *
164
-     * @return void
165
-     */
166
-    public static function adminNotice()
167
-    {
168
-        // Is this an EE admin page ?
169
-        $request   = LoaderFactory::getLoader()->getShared(RequestInterface::class);
170
-        $page_name = $request->getRequestParam('page');
171
-        // Only show the notice on core EE pages
172
-        if (! str_contains($page_name, 'espresso')) {
173
-            return;
174
-        }
175
-        // Notice if one of the following payment methods is used: PayPal Express, PayPal Pro, Authorize.net AIM.
176
-        try {
177
-            $pp_commerce = EEM_Payment_Method::instance()->get_one_by_slug('paypalcheckout');
178
-            // Don't show notice if PayPal Commerce is active.
179
-            if ($pp_commerce instanceof EE_Payment_Method && $pp_commerce->active()) {
180
-                return;
181
-            }
182
-            foreach (self::$pms_can_hide as $pm_name => $pm_option) {
183
-                $payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_name);
184
-                if ($payment_method instanceof EE_Payment_Method && $payment_method->active()) {
185
-                    add_action('admin_notices', [__CLASS__, 'usePayPalCommerceNotice']);
186
-                    return;
187
-                }
188
-            }
189
-        } catch (EE_Error | ReflectionException $e) {
190
-            // No handling needed right now.
191
-        }
192
-    }
193
-
194
-
195
-    /**
196
-     * Recommend PayPal Commerce notice contents.
197
-     *
198
-     * @return void
199
-     */
200
-    public static function usePayPalCommerceNotice()
201
-    {
202
-        echo '<div class="error"><p>'
203
-         . sprintf(
204
-             esc_html__(
205
-                 'We recommend using our latest PayPal integration - %1$sPayPal Commerce%2$s payment method in place of PayPal Standard, PayPal Express and PayPal Pro.',
206
-                 'event_espresso'
207
-             ),
208
-             '<strong>',
209
-             '</strong>'
210
-         )
211
-         . '</p></div>';
212
-    }
23
+	/**
24
+	 * List of PMs that can be replaced with PP Commerce.
25
+	 * ['payment method name' => 'settings option']
26
+	 *
27
+	 * @var $pms_can_hide
28
+	 */
29
+	protected static $pms_can_hide = [
30
+		'paypal_express' => 'api_username',
31
+		'paypal_pro'     => 'api_username',
32
+		'aim'            => 'login_id',
33
+	];
34
+
35
+
36
+	/**
37
+	 * Manager constructor.
38
+	 */
39
+	public function __construct()
40
+	{
41
+		$this->loadPaymentMethods();
42
+		if (is_admin()) {
43
+			// Use only PayPal Commerce if it's a new setup.
44
+			add_filter(
45
+				'FHEE__Payments_Admin_Page___payment_methods_list__payment_methods',
46
+				[__CLASS__, 'hidePaymentMethods']
47
+			);
48
+			// Payment methods related admin notices.
49
+			add_action('admin_init', [__CLASS__, 'adminNotice']);
50
+		}
51
+	}
52
+
53
+
54
+	/**
55
+	 * Load all payment methods that are in PaymentMethods folder.
56
+	 *
57
+	 * @return void
58
+	 */
59
+	protected function loadPaymentMethods()
60
+	{
61
+		// Scan the PaymentMethods folder.
62
+		$pms_list = glob(EE_PLUGIN_DIR_PATH . 'PaymentMethods/*', GLOB_ONLYDIR);
63
+		// Filter the discovered PM list.
64
+		$pms_list = apply_filters('FHEE__PaymentMethods__Manager__loadPaymentMethods__pms_list', $pms_list);
65
+		// Clean from duplicates.
66
+		$pms_list = array_unique($pms_list);
67
+		foreach ($pms_list as $pm_path) {
68
+			$this->registerPaymentMethod($pm_path);
69
+		}
70
+	}
71
+
72
+
73
+	/**
74
+	 * Looks for the main payment method file and loads it.
75
+	 *
76
+	 * @param string $pm_path path to the payment method folder
77
+	 * @param string $file_ext
78
+	 * @param string $pm_namespace
79
+	 * @return boolean
80
+	 */
81
+	public function registerPaymentMethod(
82
+		string $pm_path,
83
+		string $file_ext = '.php',
84
+		string $pm_namespace = 'EventEspresso\PaymentMethods'
85
+	): bool {
86
+		do_action('AHEE__PaymentMethods__Manager__registerPaymentMethod__start', $pm_path);
87
+		// Separators should match.
88
+		$pm_path = str_replace('/\\', '/', $pm_path) . DS;
89
+		// Sanitize PM name.
90
+		$module_dir = basename($pm_path);
91
+		// Get class name.
92
+		$pm_class_name = str_replace(' ', '_', $module_dir);
93
+		// Check if file exists.
94
+		if (! is_readable($pm_path . $pm_class_name . $file_ext)) {
95
+			return false;
96
+		}
97
+		// Load the initial PM class.
98
+		require_once($pm_path . DS . $pm_class_name . $file_ext);
99
+		$pm_object = "$pm_namespace\\$pm_class_name";
100
+		if (! class_exists($pm_object)) {
101
+			return false;
102
+		}
103
+		new $pm_object();
104
+		return true;
105
+	}
106
+
107
+
108
+	/**
109
+	 * Deactivate a few other PMs if it's a new setup. Use PP Commerce.
110
+	 *
111
+	 * @param array $pms_to_list
112
+	 * @return array
113
+	 * @throws EE_Error
114
+	 * @throws ReflectionException
115
+	 */
116
+	public static function hidePaymentMethods(array $pms_to_list): array
117
+	{
118
+		foreach (self::$pms_can_hide as $pm_name => $pm_option) {
119
+			// Can we deregister this PM ?
120
+			if (isset($pms_to_list[ $pm_name ]) && self::pmCanBeHidden($pm_name, $pm_option)) {
121
+				unset($pms_to_list[ $pm_name ]);
122
+			}
123
+		}
124
+		return $pms_to_list;
125
+	}
126
+
127
+
128
+	/**
129
+	 * Deregisters the provided payment method if not used.
130
+	 *
131
+	 * @param string $pm_name
132
+	 * @param string $pm_option
133
+	 * @return bool
134
+	 * @throws EE_Error
135
+	 * @throws ReflectionException
136
+	 */
137
+	public static function pmCanBeHidden(string $pm_name, string $pm_option): bool
138
+	{
139
+		$pm_to_hide = EEM_Payment_Method::instance()->get_one_by_slug($pm_name);
140
+		$pm_active  = $pm_active_before = false;
141
+		if ($pm_to_hide instanceof EE_Payment_Method) {
142
+			$pm_active = $pm_to_hide->active();
143
+			// Payment method used before ?
144
+			$option = $pm_to_hide->get_extra_meta($pm_option, true, false);
145
+			$pm_active_before = ! empty($option);
146
+		}
147
+		// If PM not used before and not active, deregister it.
148
+		if (
149
+			apply_filters(
150
+				"FHEE__PaymentMethods__Manager__register_payment_methods__hide_$pm_name",
151
+				! $pm_active && ! $pm_active_before,
152
+				$pm_name
153
+			)
154
+		) {
155
+			return true;
156
+		}
157
+		return false;
158
+	}
159
+
160
+
161
+	/**
162
+	 * Payment methods related admin notices.
163
+	 *
164
+	 * @return void
165
+	 */
166
+	public static function adminNotice()
167
+	{
168
+		// Is this an EE admin page ?
169
+		$request   = LoaderFactory::getLoader()->getShared(RequestInterface::class);
170
+		$page_name = $request->getRequestParam('page');
171
+		// Only show the notice on core EE pages
172
+		if (! str_contains($page_name, 'espresso')) {
173
+			return;
174
+		}
175
+		// Notice if one of the following payment methods is used: PayPal Express, PayPal Pro, Authorize.net AIM.
176
+		try {
177
+			$pp_commerce = EEM_Payment_Method::instance()->get_one_by_slug('paypalcheckout');
178
+			// Don't show notice if PayPal Commerce is active.
179
+			if ($pp_commerce instanceof EE_Payment_Method && $pp_commerce->active()) {
180
+				return;
181
+			}
182
+			foreach (self::$pms_can_hide as $pm_name => $pm_option) {
183
+				$payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_name);
184
+				if ($payment_method instanceof EE_Payment_Method && $payment_method->active()) {
185
+					add_action('admin_notices', [__CLASS__, 'usePayPalCommerceNotice']);
186
+					return;
187
+				}
188
+			}
189
+		} catch (EE_Error | ReflectionException $e) {
190
+			// No handling needed right now.
191
+		}
192
+	}
193
+
194
+
195
+	/**
196
+	 * Recommend PayPal Commerce notice contents.
197
+	 *
198
+	 * @return void
199
+	 */
200
+	public static function usePayPalCommerceNotice()
201
+	{
202
+		echo '<div class="error"><p>'
203
+		 . sprintf(
204
+			 esc_html__(
205
+				 'We recommend using our latest PayPal integration - %1$sPayPal Commerce%2$s payment method in place of PayPal Standard, PayPal Express and PayPal Pro.',
206
+				 'event_espresso'
207
+			 ),
208
+			 '<strong>',
209
+			 '</strong>'
210
+		 )
211
+		 . '</p></div>';
212
+	}
213 213
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
     protected function loadPaymentMethods()
60 60
     {
61 61
         // Scan the PaymentMethods folder.
62
-        $pms_list = glob(EE_PLUGIN_DIR_PATH . 'PaymentMethods/*', GLOB_ONLYDIR);
62
+        $pms_list = glob(EE_PLUGIN_DIR_PATH.'PaymentMethods/*', GLOB_ONLYDIR);
63 63
         // Filter the discovered PM list.
64 64
         $pms_list = apply_filters('FHEE__PaymentMethods__Manager__loadPaymentMethods__pms_list', $pms_list);
65 65
         // Clean from duplicates.
@@ -85,19 +85,19 @@  discard block
 block discarded – undo
85 85
     ): bool {
86 86
         do_action('AHEE__PaymentMethods__Manager__registerPaymentMethod__start', $pm_path);
87 87
         // Separators should match.
88
-        $pm_path = str_replace('/\\', '/', $pm_path) . DS;
88
+        $pm_path = str_replace('/\\', '/', $pm_path).DS;
89 89
         // Sanitize PM name.
90 90
         $module_dir = basename($pm_path);
91 91
         // Get class name.
92 92
         $pm_class_name = str_replace(' ', '_', $module_dir);
93 93
         // Check if file exists.
94
-        if (! is_readable($pm_path . $pm_class_name . $file_ext)) {
94
+        if ( ! is_readable($pm_path.$pm_class_name.$file_ext)) {
95 95
             return false;
96 96
         }
97 97
         // Load the initial PM class.
98
-        require_once($pm_path . DS . $pm_class_name . $file_ext);
98
+        require_once($pm_path.DS.$pm_class_name.$file_ext);
99 99
         $pm_object = "$pm_namespace\\$pm_class_name";
100
-        if (! class_exists($pm_object)) {
100
+        if ( ! class_exists($pm_object)) {
101 101
             return false;
102 102
         }
103 103
         new $pm_object();
@@ -117,8 +117,8 @@  discard block
 block discarded – undo
117 117
     {
118 118
         foreach (self::$pms_can_hide as $pm_name => $pm_option) {
119 119
             // Can we deregister this PM ?
120
-            if (isset($pms_to_list[ $pm_name ]) && self::pmCanBeHidden($pm_name, $pm_option)) {
121
-                unset($pms_to_list[ $pm_name ]);
120
+            if (isset($pms_to_list[$pm_name]) && self::pmCanBeHidden($pm_name, $pm_option)) {
121
+                unset($pms_to_list[$pm_name]);
122 122
             }
123 123
         }
124 124
         return $pms_to_list;
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
         $request   = LoaderFactory::getLoader()->getShared(RequestInterface::class);
170 170
         $page_name = $request->getRequestParam('page');
171 171
         // Only show the notice on core EE pages
172
-        if (! str_contains($page_name, 'espresso')) {
172
+        if ( ! str_contains($page_name, 'espresso')) {
173 173
             return;
174 174
         }
175 175
         // Notice if one of the following payment methods is used: PayPal Express, PayPal Pro, Authorize.net AIM.
Please login to merge, or discard this patch.
modules/batch/EED_Batch.module.php 2 patches
Indentation   +434 added lines, -434 removed lines patch added patch discarded remove patch
@@ -29,438 +29,438 @@
 block discarded – undo
29 29
  */
30 30
 class EED_Batch extends EED_Module
31 31
 {
32
-    public const PAGE_SLUG = 'espresso_batch';
33
-
34
-    /**
35
-     * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that
36
-     * processes data only
37
-     */
38
-    const batch_job = 'job';
39
-
40
-    /**
41
-     * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that
42
-     * produces a file for download
43
-     */
44
-    const batch_file_job = 'file';
45
-
46
-    /**
47
-     * Possibly value for $_REQUEST[ 'batch' ]. Indicates this request is NOT
48
-     * for a batch job. It's the same as not providing the $_REQUEST[ 'batch' ]
49
-     * at all
50
-     */
51
-    const batch_not_job = 'none';
52
-
53
-    /**
54
-     *
55
-     * @var string 'file', or 'job', or false to indicate its not a batch request at all
56
-     */
57
-    protected $_batch_request_type = '';
58
-
59
-    /**
60
-     * Because we want to use the response in both the localized JS and in the body
61
-     * we need to make this response available between method calls
62
-     *
63
-     * @var JobStepResponse|null
64
-     */
65
-    protected $_job_step_response = null;
66
-
67
-    /**
68
-     * @var LoaderInterface|null
69
-     */
70
-    protected $loader = null;
71
-
72
-
73
-    /**
74
-     * Gets the batch instance
75
-     *
76
-     * @return  EED_Module|EED_Batch
77
-     * @throws EE_Error
78
-     * @throws ReflectionException
79
-     */
80
-    public static function instance(): EED_Batch
81
-    {
82
-        return parent::get_instance(__CLASS__);
83
-    }
84
-
85
-
86
-    /**
87
-     * Sets hooks to enable batch jobs on the frontend. Disabled by default
88
-     * because it's an attack vector and there are currently no implementations
89
-     *
90
-     * @throws EE_Error
91
-     * @throws ReflectionException
92
-     */
93
-    public static function set_hooks()
94
-    {
95
-        // because this is a possible attack vector, let's have this disabled until
96
-        // we at least have a real use for it on the frontend
97
-        if (apply_filters('FHEE__EED_Batch__set_hooks__enable_frontend_batch', false)) {
98
-            add_action('wp_enqueue_scripts', [self::instance(), 'enqueue_scripts']);
99
-            add_filter('template_include', [self::instance(), 'override_template'], 99);
100
-        }
101
-    }
102
-
103
-
104
-    /**
105
-     * Initializes some hooks for the admin in order to run batch jobs
106
-     *
107
-     * @throws EE_Error
108
-     * @throws ReflectionException
109
-     */
110
-    public static function set_hooks_admin()
111
-    {
112
-        add_action('admin_menu', [self::instance(), 'register_admin_pages']);
113
-        add_action('admin_enqueue_scripts', [self::instance(), 'enqueue_scripts']);
114
-
115
-        // ajax
116
-        add_action('wp_ajax_espresso_batch_continue', [self::instance(), 'continueBatchJob']);
117
-        add_action('wp_ajax_espresso_batch_advance', [self::instance(), 'advanceBatchJob']);
118
-        add_action('wp_ajax_espresso_batch_cleanup', [self::instance(), 'cleanupBatchJob']);
119
-        add_action('wp_ajax_nopriv_espresso_batch_continue', [self::instance(), 'continueBatchJob']);
120
-        add_action('wp_ajax_nopriv_espresso_batch_advance', [self::instance(), 'advanceBatchJob']);
121
-        add_action('wp_ajax_nopriv_espresso_batch_cleanup', [self::instance(), 'cleanupBatchJob']);
122
-    }
123
-
124
-
125
-    /**
126
-     * @return LoaderInterface
127
-     * @throws InvalidArgumentException
128
-     * @throws InvalidDataTypeException
129
-     * @throws InvalidInterfaceException
130
-     * @since 4.9.80.p
131
-     */
132
-    protected function getLoader(): LoaderInterface
133
-    {
134
-        if (! $this->loader instanceof LoaderInterface) {
135
-            $this->loader = LoaderFactory::getLoader();
136
-        }
137
-        return $this->loader;
138
-    }
139
-
140
-
141
-    /**
142
-     * Enqueues batch scripts on the frontend or admin, and creates a job
143
-     */
144
-    public function enqueue_scripts()
145
-    {
146
-        $request = EED_Batch::getRequest();
147
-        if (
148
-            $request->getRequestParam(EED_Batch::PAGE_SLUG)
149
-            || $request->getRequestParam('page') === EED_Batch::PAGE_SLUG
150
-        ) {
151
-            if (
152
-                ! $request->requestParamIsSet('default_nonce')
153
-                || ! wp_verify_nonce($request->getRequestParam('default_nonce'), 'default_nonce')
154
-            ) {
155
-                wp_die(
156
-                    esc_html__(
157
-                        'The link you clicked to start the batch job has expired. Please go back and refresh the previous page.',
158
-                        'event_espresso'
159
-                    )
160
-                );
161
-            }
162
-            switch ($this->batch_request_type()) {
163
-                case self::batch_job:
164
-                    $this->enqueue_scripts_styles_batch_create();
165
-                    break;
166
-                case self::batch_file_job:
167
-                    $this->enqueue_scripts_styles_batch_file_create();
168
-                    break;
169
-            }
170
-        }
171
-    }
172
-
173
-
174
-    /**
175
-     * Create a batch job, enqueues a script to run it, and localizes some data for it
176
-     */
177
-    public function enqueue_scripts_styles_batch_create()
178
-    {
179
-        $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job();
180
-        wp_enqueue_script(
181
-            'batch_runner_init',
182
-            BATCH_URL . 'assets/batch_runner_init.js',
183
-            ['batch_runner'],
184
-            date('Y-m-d-H:i', time()),
185
-            true
186
-        );
187
-        wp_localize_script('batch_runner_init', 'ee_job_response', $job_response->to_array());
188
-        wp_localize_script('batch_runner_init', 'eei18n', EE_Registry::$i18n_js_strings);
189
-
190
-        $return_url = EED_Batch::getRequest()->getRequestParam('return_url', '', DataType::URL);
191
-        if ($return_url) {
192
-            wp_localize_script(
193
-                'batch_runner_init',
194
-                'ee_job_i18n',
195
-                [
196
-                    'return_url'                => $return_url,
197
-                    'auto_redirect_on_complete' => EED_Batch::getRequest()->getRequestParam(
198
-                        'auto_redirect_on_complete'
199
-                    ),
200
-                    'user_message'              => EED_Batch::getRequest()->getRequestParam('assessment_notice')
201
-                        ?: EED_Batch::getRequest()->getRequestParam('job_start_notice'),
202
-                ]
203
-            );
204
-        }
205
-    }
206
-
207
-
208
-    /**
209
-     * Creates a batch job which will download a file, enqueues a script to run the job, and localizes some data for it
210
-     */
211
-    public function enqueue_scripts_styles_batch_file_create()
212
-    {
213
-        // creates a job based on the request variable
214
-        $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job();
215
-        wp_enqueue_script(
216
-            'batch_file_runner_init',
217
-            BATCH_URL . 'assets/batch_file_runner_init.js',
218
-            ['batch_runner'],
219
-            date('Y-m-d-H:i', time()),
220
-            true
221
-        );
222
-        wp_localize_script('batch_file_runner_init', 'ee_job_response', $job_response->to_array());
223
-        wp_localize_script('batch_file_runner_init', 'eei18n', EE_Registry::$i18n_js_strings);
224
-
225
-        $return_url = EED_Batch::getRequest()->getRequestParam('return_url', '', DataType::URL);
226
-        if ($return_url) {
227
-            wp_localize_script(
228
-                'batch_file_runner_init',
229
-                'ee_job_i18n',
230
-                ['return_url' => $return_url]
231
-            );
232
-        }
233
-    }
234
-
235
-
236
-    /**
237
-     * Enqueues scripts and styles common to any batch job, and creates
238
-     * a job from the request data, and stores the response in the
239
-     * $this->_job_step_response property
240
-     *
241
-     * @return JobStepResponse
242
-     */
243
-    protected function _enqueue_batch_job_scripts_and_styles_and_start_job(): JobStepResponse
244
-    {
245
-        // just copy the bits of EE admin's eei18n that we need in the JS
246
-        EE_Registry::$i18n_js_strings['batchJobError'] = __(
247
-            'An error occurred and the job has been stopped. Please refresh the page to try again.',
248
-            'event_espresso'
249
-        );
250
-        EE_Registry::$i18n_js_strings['is_admin']      = is_admin();
251
-        wp_enqueue_style(
252
-            EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_ADMIN,
253
-            EE_ADMIN_URL . 'assets/ee-admin-page.css',
254
-            [],
255
-            EVENT_ESPRESSO_VERSION
256
-        );
257
-        wp_enqueue_style(
258
-            'batch_runner',
259
-            BATCH_URL . 'assets/batch_runner.css',
260
-            [EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_ADMIN],
261
-            date('Y-m-d-H:i', time())
262
-        );
263
-        wp_register_script(
264
-            'progress_bar',
265
-            EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.js',
266
-            ['jquery'],
267
-            date('Y-m-d-H:i', time()),
268
-            true
269
-        );
270
-        wp_enqueue_style(
271
-            'progress_bar',
272
-            EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.css',
273
-            [],
274
-            date('Y-m-d-H:i', time())
275
-        );
276
-        wp_enqueue_script(
277
-            'batch_runner',
278
-            EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/batch_runner.js',
279
-            ['progress_bar', CoreAssetManager::JS_HANDLE_CORE],
280
-            date('Y-m-d-H:i', time()),
281
-            true
282
-        );
283
-        /** @var BatchRequestProcessor $batch_runner */
284
-        $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor');
285
-        // eg 'EventEspressoBatchRequest\JobHandlers\RegistrationsReport'
286
-        // remember the response for later. We need it to display the page body
287
-        $this->_job_step_response = $batch_runner->createJob();
288
-        return $this->_job_step_response;
289
-    }
290
-
291
-
292
-    /**
293
-     * If we are doing a frontend batch job, this makes it so WP shows our template's HTML
294
-     *
295
-     * @param string $template
296
-     * @return string
297
-     */
298
-    public function override_template(string $template): string
299
-    {
300
-        $request = EED_Batch::getRequest();
301
-        if ($request->requestParamIsSet('batch') && $request->requestParamIsSet(EED_Batch::PAGE_SLUG)) {
302
-            return EE_MODULES . 'batch/templates/batch_frontend_wrapper.template.php';
303
-        }
304
-        return $template;
305
-    }
306
-
307
-
308
-    /**
309
-     * Adds an admin page which doesn't appear in the admin menu
310
-     *
311
-     * @throws EE_Error
312
-     * @throws ReflectionException
313
-     */
314
-    public function register_admin_pages()
315
-    {
316
-        add_submenu_page(
317
-            '',
318
-            // parent slug. we don't want this to actually appear in the menu
319
-            esc_html__('Batch Job', 'event_espresso'),
320
-            // page title
321
-            'n/a',
322
-            // menu title
323
-            'read',
324
-            // we want this page to actually be accessible to anyone,
325
-            EED_Batch::PAGE_SLUG,
326
-            // menu slug
327
-            [self::instance(), 'show_admin_page']
328
-        );
329
-    }
330
-
331
-
332
-    /**
333
-     * Renders the admin page, after most of the work was already done during enqueuing scripts
334
-     * of creating the job and localizing some data
335
-     */
336
-    public function show_admin_page()
337
-    {
338
-        echo EEH_Template::locate_template(
339
-            EE_MODULES . 'batch/templates/batch_wrapper.template.php',
340
-            [
341
-                'batch_request_type'        => $this->batch_request_type(),
342
-                'auto_redirect_on_complete' => EED_Batch::getRequest()->getRequestParam('auto_redirect_on_complete'),
343
-                'user_message'              => EED_Batch::getRequest()->getRequestParam('assessment_notice')
344
-                    ?: EED_Batch::getRequest()->getRequestParam('job_start_notice'),
345
-            ]
346
-        );
347
-    }
348
-
349
-
350
-    private function runBatchRunnerJob(string $job)
351
-    {
352
-        $job_id = EED_Batch::getRequest()->getRequestParam('job_id');
353
-        /** @var BatchRequestProcessor $batch_runner */
354
-        $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor');
355
-        $job_response = $batch_runner->{$job}($job_id);
356
-        $this->_return_json($job_response->to_array());
357
-    }
358
-
359
-
360
-    /**
361
-     * Receives ajax calls for continuing a job
362
-     */
363
-    public function continueBatchJob()
364
-    {
365
-        $this->runBatchRunnerJob('continueJob');
366
-    }
367
-
368
-
369
-    /**
370
-     * Receives ajax calls for continuing a job
371
-     */
372
-    public function advanceBatchJob()
373
-    {
374
-        $this->runBatchRunnerJob('advanceJob');
375
-    }
376
-
377
-
378
-    /**
379
-     * Receives the ajax call to cleanup a job
380
-     *
381
-     * @return void
382
-     */
383
-    public function cleanupBatchJob()
384
-    {
385
-        $this->runBatchRunnerJob('cleanupJob');
386
-    }
387
-
388
-
389
-    /**
390
-     * Returns a json response
391
-     *
392
-     * @param array $data The data we want to send echo via in the JSON response's "data" element
393
-     *
394
-     * The returned json object is created from an array in the following format:
395
-     * array(
396
-     *    'notices' => '', // - contains any EE_Error formatted notices
397
-     *    'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js.
398
-     *    We're also going to include the template args with every package (so js can pick out any specific template
399
-     *    args that might be included in here)
400
-     *    'isEEajax' => true,//indicates this is a response from EE
401
-     * )
402
-     */
403
-    protected function _return_json(array $data)
404
-    {
405
-        $json = [
406
-            'data'     => $data,
407
-            'isEEajax' => true,
408
-            // special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
409
-        ];
410
-
411
-        // make sure there are no php errors or headers_sent.  Then we can set correct json header.
412
-        if (error_get_last() === null || ! headers_sent()) {
413
-            $notices = EE_Error::get_notices(false);
414
-            header('Content-Type: application/json; charset=UTF-8');
415
-            echo wp_json_encode($json + $notices);
416
-            exit();
417
-        }
418
-    }
419
-
420
-
421
-    /**
422
-     * Gets the job step response which was done during the enqueuing of scripts
423
-     *
424
-     * @return JobStepResponse
425
-     */
426
-    public function job_step_response(): JobStepResponse
427
-    {
428
-        return $this->_job_step_response;
429
-    }
430
-
431
-
432
-    /**
433
-     * Gets the batch request type indicated in the current request
434
-     *
435
-     * @return string: EED_Batch::batch_job, EED_Batch::batch_file_job, EED_Batch::batch_not_job
436
-     */
437
-    public function batch_request_type(): string
438
-    {
439
-        if (! $this->_batch_request_type) {
440
-            $request = EED_Batch::getRequest();
441
-            $batch   = $request->getRequestParam('batch');
442
-            switch ($batch) {
443
-                case self::batch_job:
444
-                    $this->_batch_request_type = self::batch_job;
445
-                    break;
446
-                case self::batch_file_job:
447
-                    $this->_batch_request_type = self::batch_file_job;
448
-                    break;
449
-                default:
450
-                    // if we didn't find that it was a batch request, indicate it wasn't
451
-                    $this->_batch_request_type = self::batch_not_job;
452
-            }
453
-        }
454
-        return $this->_batch_request_type;
455
-    }
456
-
457
-
458
-    /**
459
-     * Unnecessary
460
-     *
461
-     * @param WP $WP
462
-     */
463
-    public function run($WP)
464
-    {
465
-    }
32
+	public const PAGE_SLUG = 'espresso_batch';
33
+
34
+	/**
35
+	 * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that
36
+	 * processes data only
37
+	 */
38
+	const batch_job = 'job';
39
+
40
+	/**
41
+	 * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that
42
+	 * produces a file for download
43
+	 */
44
+	const batch_file_job = 'file';
45
+
46
+	/**
47
+	 * Possibly value for $_REQUEST[ 'batch' ]. Indicates this request is NOT
48
+	 * for a batch job. It's the same as not providing the $_REQUEST[ 'batch' ]
49
+	 * at all
50
+	 */
51
+	const batch_not_job = 'none';
52
+
53
+	/**
54
+	 *
55
+	 * @var string 'file', or 'job', or false to indicate its not a batch request at all
56
+	 */
57
+	protected $_batch_request_type = '';
58
+
59
+	/**
60
+	 * Because we want to use the response in both the localized JS and in the body
61
+	 * we need to make this response available between method calls
62
+	 *
63
+	 * @var JobStepResponse|null
64
+	 */
65
+	protected $_job_step_response = null;
66
+
67
+	/**
68
+	 * @var LoaderInterface|null
69
+	 */
70
+	protected $loader = null;
71
+
72
+
73
+	/**
74
+	 * Gets the batch instance
75
+	 *
76
+	 * @return  EED_Module|EED_Batch
77
+	 * @throws EE_Error
78
+	 * @throws ReflectionException
79
+	 */
80
+	public static function instance(): EED_Batch
81
+	{
82
+		return parent::get_instance(__CLASS__);
83
+	}
84
+
85
+
86
+	/**
87
+	 * Sets hooks to enable batch jobs on the frontend. Disabled by default
88
+	 * because it's an attack vector and there are currently no implementations
89
+	 *
90
+	 * @throws EE_Error
91
+	 * @throws ReflectionException
92
+	 */
93
+	public static function set_hooks()
94
+	{
95
+		// because this is a possible attack vector, let's have this disabled until
96
+		// we at least have a real use for it on the frontend
97
+		if (apply_filters('FHEE__EED_Batch__set_hooks__enable_frontend_batch', false)) {
98
+			add_action('wp_enqueue_scripts', [self::instance(), 'enqueue_scripts']);
99
+			add_filter('template_include', [self::instance(), 'override_template'], 99);
100
+		}
101
+	}
102
+
103
+
104
+	/**
105
+	 * Initializes some hooks for the admin in order to run batch jobs
106
+	 *
107
+	 * @throws EE_Error
108
+	 * @throws ReflectionException
109
+	 */
110
+	public static function set_hooks_admin()
111
+	{
112
+		add_action('admin_menu', [self::instance(), 'register_admin_pages']);
113
+		add_action('admin_enqueue_scripts', [self::instance(), 'enqueue_scripts']);
114
+
115
+		// ajax
116
+		add_action('wp_ajax_espresso_batch_continue', [self::instance(), 'continueBatchJob']);
117
+		add_action('wp_ajax_espresso_batch_advance', [self::instance(), 'advanceBatchJob']);
118
+		add_action('wp_ajax_espresso_batch_cleanup', [self::instance(), 'cleanupBatchJob']);
119
+		add_action('wp_ajax_nopriv_espresso_batch_continue', [self::instance(), 'continueBatchJob']);
120
+		add_action('wp_ajax_nopriv_espresso_batch_advance', [self::instance(), 'advanceBatchJob']);
121
+		add_action('wp_ajax_nopriv_espresso_batch_cleanup', [self::instance(), 'cleanupBatchJob']);
122
+	}
123
+
124
+
125
+	/**
126
+	 * @return LoaderInterface
127
+	 * @throws InvalidArgumentException
128
+	 * @throws InvalidDataTypeException
129
+	 * @throws InvalidInterfaceException
130
+	 * @since 4.9.80.p
131
+	 */
132
+	protected function getLoader(): LoaderInterface
133
+	{
134
+		if (! $this->loader instanceof LoaderInterface) {
135
+			$this->loader = LoaderFactory::getLoader();
136
+		}
137
+		return $this->loader;
138
+	}
139
+
140
+
141
+	/**
142
+	 * Enqueues batch scripts on the frontend or admin, and creates a job
143
+	 */
144
+	public function enqueue_scripts()
145
+	{
146
+		$request = EED_Batch::getRequest();
147
+		if (
148
+			$request->getRequestParam(EED_Batch::PAGE_SLUG)
149
+			|| $request->getRequestParam('page') === EED_Batch::PAGE_SLUG
150
+		) {
151
+			if (
152
+				! $request->requestParamIsSet('default_nonce')
153
+				|| ! wp_verify_nonce($request->getRequestParam('default_nonce'), 'default_nonce')
154
+			) {
155
+				wp_die(
156
+					esc_html__(
157
+						'The link you clicked to start the batch job has expired. Please go back and refresh the previous page.',
158
+						'event_espresso'
159
+					)
160
+				);
161
+			}
162
+			switch ($this->batch_request_type()) {
163
+				case self::batch_job:
164
+					$this->enqueue_scripts_styles_batch_create();
165
+					break;
166
+				case self::batch_file_job:
167
+					$this->enqueue_scripts_styles_batch_file_create();
168
+					break;
169
+			}
170
+		}
171
+	}
172
+
173
+
174
+	/**
175
+	 * Create a batch job, enqueues a script to run it, and localizes some data for it
176
+	 */
177
+	public function enqueue_scripts_styles_batch_create()
178
+	{
179
+		$job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job();
180
+		wp_enqueue_script(
181
+			'batch_runner_init',
182
+			BATCH_URL . 'assets/batch_runner_init.js',
183
+			['batch_runner'],
184
+			date('Y-m-d-H:i', time()),
185
+			true
186
+		);
187
+		wp_localize_script('batch_runner_init', 'ee_job_response', $job_response->to_array());
188
+		wp_localize_script('batch_runner_init', 'eei18n', EE_Registry::$i18n_js_strings);
189
+
190
+		$return_url = EED_Batch::getRequest()->getRequestParam('return_url', '', DataType::URL);
191
+		if ($return_url) {
192
+			wp_localize_script(
193
+				'batch_runner_init',
194
+				'ee_job_i18n',
195
+				[
196
+					'return_url'                => $return_url,
197
+					'auto_redirect_on_complete' => EED_Batch::getRequest()->getRequestParam(
198
+						'auto_redirect_on_complete'
199
+					),
200
+					'user_message'              => EED_Batch::getRequest()->getRequestParam('assessment_notice')
201
+						?: EED_Batch::getRequest()->getRequestParam('job_start_notice'),
202
+				]
203
+			);
204
+		}
205
+	}
206
+
207
+
208
+	/**
209
+	 * Creates a batch job which will download a file, enqueues a script to run the job, and localizes some data for it
210
+	 */
211
+	public function enqueue_scripts_styles_batch_file_create()
212
+	{
213
+		// creates a job based on the request variable
214
+		$job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job();
215
+		wp_enqueue_script(
216
+			'batch_file_runner_init',
217
+			BATCH_URL . 'assets/batch_file_runner_init.js',
218
+			['batch_runner'],
219
+			date('Y-m-d-H:i', time()),
220
+			true
221
+		);
222
+		wp_localize_script('batch_file_runner_init', 'ee_job_response', $job_response->to_array());
223
+		wp_localize_script('batch_file_runner_init', 'eei18n', EE_Registry::$i18n_js_strings);
224
+
225
+		$return_url = EED_Batch::getRequest()->getRequestParam('return_url', '', DataType::URL);
226
+		if ($return_url) {
227
+			wp_localize_script(
228
+				'batch_file_runner_init',
229
+				'ee_job_i18n',
230
+				['return_url' => $return_url]
231
+			);
232
+		}
233
+	}
234
+
235
+
236
+	/**
237
+	 * Enqueues scripts and styles common to any batch job, and creates
238
+	 * a job from the request data, and stores the response in the
239
+	 * $this->_job_step_response property
240
+	 *
241
+	 * @return JobStepResponse
242
+	 */
243
+	protected function _enqueue_batch_job_scripts_and_styles_and_start_job(): JobStepResponse
244
+	{
245
+		// just copy the bits of EE admin's eei18n that we need in the JS
246
+		EE_Registry::$i18n_js_strings['batchJobError'] = __(
247
+			'An error occurred and the job has been stopped. Please refresh the page to try again.',
248
+			'event_espresso'
249
+		);
250
+		EE_Registry::$i18n_js_strings['is_admin']      = is_admin();
251
+		wp_enqueue_style(
252
+			EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_ADMIN,
253
+			EE_ADMIN_URL . 'assets/ee-admin-page.css',
254
+			[],
255
+			EVENT_ESPRESSO_VERSION
256
+		);
257
+		wp_enqueue_style(
258
+			'batch_runner',
259
+			BATCH_URL . 'assets/batch_runner.css',
260
+			[EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_ADMIN],
261
+			date('Y-m-d-H:i', time())
262
+		);
263
+		wp_register_script(
264
+			'progress_bar',
265
+			EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.js',
266
+			['jquery'],
267
+			date('Y-m-d-H:i', time()),
268
+			true
269
+		);
270
+		wp_enqueue_style(
271
+			'progress_bar',
272
+			EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.css',
273
+			[],
274
+			date('Y-m-d-H:i', time())
275
+		);
276
+		wp_enqueue_script(
277
+			'batch_runner',
278
+			EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/batch_runner.js',
279
+			['progress_bar', CoreAssetManager::JS_HANDLE_CORE],
280
+			date('Y-m-d-H:i', time()),
281
+			true
282
+		);
283
+		/** @var BatchRequestProcessor $batch_runner */
284
+		$batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor');
285
+		// eg 'EventEspressoBatchRequest\JobHandlers\RegistrationsReport'
286
+		// remember the response for later. We need it to display the page body
287
+		$this->_job_step_response = $batch_runner->createJob();
288
+		return $this->_job_step_response;
289
+	}
290
+
291
+
292
+	/**
293
+	 * If we are doing a frontend batch job, this makes it so WP shows our template's HTML
294
+	 *
295
+	 * @param string $template
296
+	 * @return string
297
+	 */
298
+	public function override_template(string $template): string
299
+	{
300
+		$request = EED_Batch::getRequest();
301
+		if ($request->requestParamIsSet('batch') && $request->requestParamIsSet(EED_Batch::PAGE_SLUG)) {
302
+			return EE_MODULES . 'batch/templates/batch_frontend_wrapper.template.php';
303
+		}
304
+		return $template;
305
+	}
306
+
307
+
308
+	/**
309
+	 * Adds an admin page which doesn't appear in the admin menu
310
+	 *
311
+	 * @throws EE_Error
312
+	 * @throws ReflectionException
313
+	 */
314
+	public function register_admin_pages()
315
+	{
316
+		add_submenu_page(
317
+			'',
318
+			// parent slug. we don't want this to actually appear in the menu
319
+			esc_html__('Batch Job', 'event_espresso'),
320
+			// page title
321
+			'n/a',
322
+			// menu title
323
+			'read',
324
+			// we want this page to actually be accessible to anyone,
325
+			EED_Batch::PAGE_SLUG,
326
+			// menu slug
327
+			[self::instance(), 'show_admin_page']
328
+		);
329
+	}
330
+
331
+
332
+	/**
333
+	 * Renders the admin page, after most of the work was already done during enqueuing scripts
334
+	 * of creating the job and localizing some data
335
+	 */
336
+	public function show_admin_page()
337
+	{
338
+		echo EEH_Template::locate_template(
339
+			EE_MODULES . 'batch/templates/batch_wrapper.template.php',
340
+			[
341
+				'batch_request_type'        => $this->batch_request_type(),
342
+				'auto_redirect_on_complete' => EED_Batch::getRequest()->getRequestParam('auto_redirect_on_complete'),
343
+				'user_message'              => EED_Batch::getRequest()->getRequestParam('assessment_notice')
344
+					?: EED_Batch::getRequest()->getRequestParam('job_start_notice'),
345
+			]
346
+		);
347
+	}
348
+
349
+
350
+	private function runBatchRunnerJob(string $job)
351
+	{
352
+		$job_id = EED_Batch::getRequest()->getRequestParam('job_id');
353
+		/** @var BatchRequestProcessor $batch_runner */
354
+		$batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor');
355
+		$job_response = $batch_runner->{$job}($job_id);
356
+		$this->_return_json($job_response->to_array());
357
+	}
358
+
359
+
360
+	/**
361
+	 * Receives ajax calls for continuing a job
362
+	 */
363
+	public function continueBatchJob()
364
+	{
365
+		$this->runBatchRunnerJob('continueJob');
366
+	}
367
+
368
+
369
+	/**
370
+	 * Receives ajax calls for continuing a job
371
+	 */
372
+	public function advanceBatchJob()
373
+	{
374
+		$this->runBatchRunnerJob('advanceJob');
375
+	}
376
+
377
+
378
+	/**
379
+	 * Receives the ajax call to cleanup a job
380
+	 *
381
+	 * @return void
382
+	 */
383
+	public function cleanupBatchJob()
384
+	{
385
+		$this->runBatchRunnerJob('cleanupJob');
386
+	}
387
+
388
+
389
+	/**
390
+	 * Returns a json response
391
+	 *
392
+	 * @param array $data The data we want to send echo via in the JSON response's "data" element
393
+	 *
394
+	 * The returned json object is created from an array in the following format:
395
+	 * array(
396
+	 *    'notices' => '', // - contains any EE_Error formatted notices
397
+	 *    'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js.
398
+	 *    We're also going to include the template args with every package (so js can pick out any specific template
399
+	 *    args that might be included in here)
400
+	 *    'isEEajax' => true,//indicates this is a response from EE
401
+	 * )
402
+	 */
403
+	protected function _return_json(array $data)
404
+	{
405
+		$json = [
406
+			'data'     => $data,
407
+			'isEEajax' => true,
408
+			// special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
409
+		];
410
+
411
+		// make sure there are no php errors or headers_sent.  Then we can set correct json header.
412
+		if (error_get_last() === null || ! headers_sent()) {
413
+			$notices = EE_Error::get_notices(false);
414
+			header('Content-Type: application/json; charset=UTF-8');
415
+			echo wp_json_encode($json + $notices);
416
+			exit();
417
+		}
418
+	}
419
+
420
+
421
+	/**
422
+	 * Gets the job step response which was done during the enqueuing of scripts
423
+	 *
424
+	 * @return JobStepResponse
425
+	 */
426
+	public function job_step_response(): JobStepResponse
427
+	{
428
+		return $this->_job_step_response;
429
+	}
430
+
431
+
432
+	/**
433
+	 * Gets the batch request type indicated in the current request
434
+	 *
435
+	 * @return string: EED_Batch::batch_job, EED_Batch::batch_file_job, EED_Batch::batch_not_job
436
+	 */
437
+	public function batch_request_type(): string
438
+	{
439
+		if (! $this->_batch_request_type) {
440
+			$request = EED_Batch::getRequest();
441
+			$batch   = $request->getRequestParam('batch');
442
+			switch ($batch) {
443
+				case self::batch_job:
444
+					$this->_batch_request_type = self::batch_job;
445
+					break;
446
+				case self::batch_file_job:
447
+					$this->_batch_request_type = self::batch_file_job;
448
+					break;
449
+				default:
450
+					// if we didn't find that it was a batch request, indicate it wasn't
451
+					$this->_batch_request_type = self::batch_not_job;
452
+			}
453
+		}
454
+		return $this->_batch_request_type;
455
+	}
456
+
457
+
458
+	/**
459
+	 * Unnecessary
460
+	 *
461
+	 * @param WP $WP
462
+	 */
463
+	public function run($WP)
464
+	{
465
+	}
466 466
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
      */
132 132
     protected function getLoader(): LoaderInterface
133 133
     {
134
-        if (! $this->loader instanceof LoaderInterface) {
134
+        if ( ! $this->loader instanceof LoaderInterface) {
135 135
             $this->loader = LoaderFactory::getLoader();
136 136
         }
137 137
         return $this->loader;
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
         $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job();
180 180
         wp_enqueue_script(
181 181
             'batch_runner_init',
182
-            BATCH_URL . 'assets/batch_runner_init.js',
182
+            BATCH_URL.'assets/batch_runner_init.js',
183 183
             ['batch_runner'],
184 184
             date('Y-m-d-H:i', time()),
185 185
             true
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
         $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job();
215 215
         wp_enqueue_script(
216 216
             'batch_file_runner_init',
217
-            BATCH_URL . 'assets/batch_file_runner_init.js',
217
+            BATCH_URL.'assets/batch_file_runner_init.js',
218 218
             ['batch_runner'],
219 219
             date('Y-m-d-H:i', time()),
220 220
             true
@@ -247,35 +247,35 @@  discard block
 block discarded – undo
247 247
             'An error occurred and the job has been stopped. Please refresh the page to try again.',
248 248
             'event_espresso'
249 249
         );
250
-        EE_Registry::$i18n_js_strings['is_admin']      = is_admin();
250
+        EE_Registry::$i18n_js_strings['is_admin'] = is_admin();
251 251
         wp_enqueue_style(
252 252
             EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_ADMIN,
253
-            EE_ADMIN_URL . 'assets/ee-admin-page.css',
253
+            EE_ADMIN_URL.'assets/ee-admin-page.css',
254 254
             [],
255 255
             EVENT_ESPRESSO_VERSION
256 256
         );
257 257
         wp_enqueue_style(
258 258
             'batch_runner',
259
-            BATCH_URL . 'assets/batch_runner.css',
259
+            BATCH_URL.'assets/batch_runner.css',
260 260
             [EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_ADMIN],
261 261
             date('Y-m-d-H:i', time())
262 262
         );
263 263
         wp_register_script(
264 264
             'progress_bar',
265
-            EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.js',
265
+            EE_PLUGIN_DIR_URL.'core/libraries/batch/Assets/progress_bar.js',
266 266
             ['jquery'],
267 267
             date('Y-m-d-H:i', time()),
268 268
             true
269 269
         );
270 270
         wp_enqueue_style(
271 271
             'progress_bar',
272
-            EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.css',
272
+            EE_PLUGIN_DIR_URL.'core/libraries/batch/Assets/progress_bar.css',
273 273
             [],
274 274
             date('Y-m-d-H:i', time())
275 275
         );
276 276
         wp_enqueue_script(
277 277
             'batch_runner',
278
-            EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/batch_runner.js',
278
+            EE_PLUGIN_DIR_URL.'core/libraries/batch/Assets/batch_runner.js',
279 279
             ['progress_bar', CoreAssetManager::JS_HANDLE_CORE],
280 280
             date('Y-m-d-H:i', time()),
281 281
             true
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
     {
300 300
         $request = EED_Batch::getRequest();
301 301
         if ($request->requestParamIsSet('batch') && $request->requestParamIsSet(EED_Batch::PAGE_SLUG)) {
302
-            return EE_MODULES . 'batch/templates/batch_frontend_wrapper.template.php';
302
+            return EE_MODULES.'batch/templates/batch_frontend_wrapper.template.php';
303 303
         }
304 304
         return $template;
305 305
     }
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
     public function show_admin_page()
337 337
     {
338 338
         echo EEH_Template::locate_template(
339
-            EE_MODULES . 'batch/templates/batch_wrapper.template.php',
339
+            EE_MODULES.'batch/templates/batch_wrapper.template.php',
340 340
             [
341 341
                 'batch_request_type'        => $this->batch_request_type(),
342 342
                 'auto_redirect_on_complete' => EED_Batch::getRequest()->getRequestParam('auto_redirect_on_complete'),
@@ -436,7 +436,7 @@  discard block
 block discarded – undo
436 436
      */
437 437
     public function batch_request_type(): string
438 438
     {
439
-        if (! $this->_batch_request_type) {
439
+        if ( ! $this->_batch_request_type) {
440 440
             $request = EED_Batch::getRequest();
441 441
             $batch   = $request->getRequestParam('batch');
442 442
             switch ($batch) {
Please login to merge, or discard this patch.
caffeinated/admin/new/pricing/Pricing_Admin_Page.core.php 1 patch
Indentation   +1283 added lines, -1283 removed lines patch added patch discarded remove patch
@@ -12,1294 +12,1294 @@
 block discarded – undo
12 12
  */
13 13
 class Pricing_Admin_Page extends EE_Admin_Page
14 14
 {
15
-    protected function _init_page_props()
16
-    {
17
-        $this->page_slug        = PRICING_PG_SLUG;
18
-        $this->page_label       = PRICING_LABEL;
19
-        $this->_admin_base_url  = PRICING_ADMIN_URL;
20
-        $this->_admin_base_path = PRICING_ADMIN;
21
-    }
22
-
23
-
24
-    protected function _ajax_hooks()
25
-    {
26
-        add_action('wp_ajax_espresso_update_prices_order', [$this, 'update_price_order']);
27
-    }
28
-
29
-
30
-    protected function _define_page_props()
31
-    {
32
-        $this->_admin_page_title = PRICING_LABEL;
33
-        $this->_labels           = [
34
-            'buttons' => [
35
-                'add'         => esc_html__('Add New Default Price', 'event_espresso'),
36
-                'edit'        => esc_html__('Edit Default Price', 'event_espresso'),
37
-                'delete'      => esc_html__('Delete Default Price', 'event_espresso'),
38
-                'add_type'    => esc_html__('Add New Default Price Type', 'event_espresso'),
39
-                'edit_type'   => esc_html__('Edit Price Type', 'event_espresso'),
40
-                'delete_type' => esc_html__('Delete Price Type', 'event_espresso'),
41
-            ],
42
-            'publishbox' => [
43
-                'add_new_price'      => esc_html__('Add New Default Price', 'event_espresso'),
44
-                'edit_price'         => esc_html__('Edit Default Price', 'event_espresso'),
45
-                'add_new_price_type' => esc_html__('Add New Default Price Type', 'event_espresso'),
46
-                'edit_price_type'    => esc_html__('Edit Price Type', 'event_espresso'),
47
-            ],
48
-        ];
49
-    }
50
-
51
-
52
-    /**
53
-     * an array for storing request actions and their corresponding methods
54
-     *
55
-     * @return void
56
-     */
57
-    protected function _set_page_routes()
58
-    {
59
-        $PRC_ID             = $this->request->getRequestParam('PRC_ID', 0, DataType::INTEGER);
60
-        $PRT_ID             = $this->request->getRequestParam('PRT_ID', 0, DataType::INTEGER);
61
-        $this->_page_routes = [
62
-            'default'                     => [
63
-                'func'       => [$this, '_price_overview_list_table'],
64
-                'capability' => 'ee_read_default_prices',
65
-            ],
66
-            'add_new_price'               => [
67
-                'func'       => [$this, '_edit_price_details'],
68
-                'capability' => 'ee_edit_default_prices',
69
-            ],
70
-            'edit_price'                  => [
71
-                'func'       => [$this, '_edit_price_details'],
72
-                'capability' => 'ee_edit_default_price',
73
-                'obj_id'     => $PRC_ID,
74
-            ],
75
-            'insert_price'                => [
76
-                'func'       => [$this, '_insert_or_update_price'],
77
-                'args'       => ['insert' => true],
78
-                'noheader'   => true,
79
-                'capability' => 'ee_edit_default_prices',
80
-            ],
81
-            'update_price'                => [
82
-                'func'       => [$this, '_insert_or_update_price'],
83
-                'args'       => ['insert' => false],
84
-                'noheader'   => true,
85
-                'capability' => 'ee_edit_default_price',
86
-                'obj_id'     => $PRC_ID,
87
-            ],
88
-            'trash_price'                 => [
89
-                'func'       => [$this, '_trash_or_restore_price'],
90
-                'args'       => ['trash' => true],
91
-                'noheader'   => true,
92
-                'capability' => 'ee_delete_default_price',
93
-                'obj_id'     => $PRC_ID,
94
-            ],
95
-            'restore_price'               => [
96
-                'func'       => [$this, '_trash_or_restore_price'],
97
-                'args'       => ['trash' => false],
98
-                'noheader'   => true,
99
-                'capability' => 'ee_delete_default_price',
100
-                'obj_id'     => $PRC_ID,
101
-            ],
102
-            'delete_price'                => [
103
-                'func'       => [$this, '_delete_price'],
104
-                'noheader'   => true,
105
-                'capability' => 'ee_delete_default_price',
106
-                'obj_id'     => $PRC_ID,
107
-            ],
108
-            'espresso_update_price_order' => [
109
-                'func'       => [$this, 'update_price_order'],
110
-                'noheader'   => true,
111
-                'capability' => 'ee_edit_default_prices',
112
-            ],
113
-            // price types
114
-            'price_types'                 => [
115
-                'func'       => [$this, '_price_types_overview_list_table'],
116
-                'capability' => 'ee_read_default_price_types',
117
-            ],
118
-            'add_new_price_type'          => [
119
-                'func'       => [$this, '_edit_price_type_details'],
120
-                'capability' => 'ee_edit_default_price_types',
121
-            ],
122
-            'edit_price_type'             => [
123
-                'func'       => [$this, '_edit_price_type_details'],
124
-                'capability' => 'ee_edit_default_price_type',
125
-                'obj_id'     => $PRT_ID,
126
-            ],
127
-            'insert_price_type'           => [
128
-                'func'       => [$this, '_insert_or_update_price_type'],
129
-                'args'       => ['new_price_type' => true],
130
-                'noheader'   => true,
131
-                'capability' => 'ee_edit_default_price_types',
132
-            ],
133
-            'update_price_type'           => [
134
-                'func'       => [$this, '_insert_or_update_price_type'],
135
-                'args'       => ['new_price_type' => false],
136
-                'noheader'   => true,
137
-                'capability' => 'ee_edit_default_price_type',
138
-                'obj_id'     => $PRT_ID,
139
-            ],
140
-            'trash_price_type'            => [
141
-                'func'       => [$this, '_trash_or_restore_price_type'],
142
-                'args'       => ['trash' => true],
143
-                'noheader'   => true,
144
-                'capability' => 'ee_delete_default_price_type',
145
-                'obj_id'     => $PRT_ID,
146
-            ],
147
-            'restore_price_type'          => [
148
-                'func'       => [$this, '_trash_or_restore_price_type'],
149
-                'args'       => ['trash' => false],
150
-                'noheader'   => true,
151
-                'capability' => 'ee_delete_default_price_type',
152
-                'obj_id'     => $PRT_ID,
153
-            ],
154
-            'delete_price_type'           => [
155
-                'func'       => [$this, '_delete_price_type'],
156
-                'noheader'   => true,
157
-                'capability' => 'ee_delete_default_price_type',
158
-                'obj_id'     => $PRT_ID,
159
-            ],
160
-            'tax_settings'                => [
161
-                'func'       => [$this, '_tax_settings'],
162
-                'capability' => 'manage_options',
163
-            ],
164
-            'update_tax_settings'         => [
165
-                'func'       => [$this, '_update_tax_settings'],
166
-                'capability' => 'manage_options',
167
-                'noheader'   => true,
168
-            ],
169
-        ];
170
-    }
171
-
172
-
173
-    protected function _set_page_config()
174
-    {
175
-        $PRC_ID             = $this->request->getRequestParam('id', 0, DataType::INTEGER);
176
-        $this->_page_config = [
177
-            'default'            => [
178
-                'nav'           => [
179
-                    'label' => esc_html__('Default Pricing', 'event_espresso'),
180
-                    'icon' => 'dashicons-money-alt',
181
-                    'order' => 10,
182
-                ],
183
-                'list_table'    => 'Prices_List_Table',
184
-                'metaboxes'     => $this->_default_espresso_metaboxes,
185
-                'help_tabs'     => [
186
-                    'pricing_default_pricing_help_tab'                           => [
187
-                        'title'    => esc_html__('Default Pricing', 'event_espresso'),
188
-                        'filename' => 'pricing_default_pricing',
189
-                    ],
190
-                    'pricing_default_pricing_table_column_headings_help_tab'     => [
191
-                        'title'    => esc_html__('Default Pricing Table Column Headings', 'event_espresso'),
192
-                        'filename' => 'pricing_default_pricing_table_column_headings',
193
-                    ],
194
-                    'pricing_default_pricing_views_bulk_actions_search_help_tab' => [
195
-                        'title'    => esc_html__('Default Pricing Views & Bulk Actions & Search', 'event_espresso'),
196
-                        'filename' => 'pricing_default_pricing_views_bulk_actions_search',
197
-                    ],
198
-                ],
199
-                'require_nonce' => false,
200
-            ],
201
-            'add_new_price'      => [
202
-                'nav'           => [
203
-                    'label'      => esc_html__('Add New Default Price', 'event_espresso'),
204
-                    'icon' => 'dashicons-plus-alt',
205
-                    'order'      => 20,
206
-                    'persistent' => false,
207
-                ],
208
-                'help_tabs'     => [
209
-                    'add_new_default_price_help_tab' => [
210
-                        'title'    => esc_html__('Add New Default Price', 'event_espresso'),
211
-                        'filename' => 'pricing_add_new_default_price',
212
-                    ],
213
-                ],
214
-                'metaboxes'     => array_merge(
215
-                    ['_publish_post_box'],
216
-                    $this->_default_espresso_metaboxes
217
-                ),
218
-                'require_nonce' => false,
219
-            ],
220
-            'edit_price'         => [
221
-                'nav'           => [
222
-                    'label'      => esc_html__('Edit Default Price', 'event_espresso'),
223
-                    'icon' => 'dashicons-edit-large',
224
-                    'order'      => 20,
225
-                    'url'        => $PRC_ID
226
-                        ? add_query_arg(['id' => $PRC_ID], $this->_current_page_view_url)
227
-                        : $this->_admin_base_url,
228
-                    'persistent' => false,
229
-                ],
230
-                'metaboxes'     => array_merge(
231
-                    ['_publish_post_box'],
232
-                    $this->_default_espresso_metaboxes
233
-                ),
234
-                'help_tabs'     => [
235
-                    'edit_default_price_help_tab' => [
236
-                        'title'    => esc_html__('Edit Default Price', 'event_espresso'),
237
-                        'filename' => 'pricing_edit_default_price',
238
-                    ],
239
-                ],
240
-                'require_nonce' => false,
241
-            ],
242
-            'price_types'        => [
243
-                'nav'           => [
244
-                    'label' => esc_html__('Price Types', 'event_espresso'),
245
-                    'icon' => 'dashicons-networking',
246
-                    'order' => 30,
247
-                ],
248
-                'list_table'    => 'Price_Types_List_Table',
249
-                'help_tabs'     => [
250
-                    'pricing_price_types_help_tab'                           => [
251
-                        'title'    => esc_html__('Price Types', 'event_espresso'),
252
-                        'filename' => 'pricing_price_types',
253
-                    ],
254
-                    'pricing_price_types_table_column_headings_help_tab'     => [
255
-                        'title'    => esc_html__('Price Types Table Column Headings', 'event_espresso'),
256
-                        'filename' => 'pricing_price_types_table_column_headings',
257
-                    ],
258
-                    'pricing_price_types_views_bulk_actions_search_help_tab' => [
259
-                        'title'    => esc_html__('Price Types Views & Bulk Actions & Search', 'event_espresso'),
260
-                        'filename' => 'pricing_price_types_views_bulk_actions_search',
261
-                    ],
262
-                ],
263
-                'metaboxes'     => $this->_default_espresso_metaboxes,
264
-                'require_nonce' => false,
265
-            ],
266
-            'add_new_price_type' => [
267
-                'nav'           => [
268
-                    'label'      => esc_html__('Add New Price Type', 'event_espresso'),
269
-                    'icon' => 'dashicons-plus-alt',
270
-                    'order'      => 40,
271
-                    'persistent' => false,
272
-                ],
273
-                'help_tabs'     => [
274
-                    'add_new_price_type_help_tab' => [
275
-                        'title'    => esc_html__('Add New Price Type', 'event_espresso'),
276
-                        'filename' => 'pricing_add_new_price_type',
277
-                    ],
278
-                ],
279
-                'metaboxes'     => array_merge(
280
-                    ['_publish_post_box'],
281
-                    $this->_default_espresso_metaboxes
282
-                ),
283
-                'require_nonce' => false,
284
-            ],
285
-            'edit_price_type'    => [
286
-                'nav'           => [
287
-                    'label'      => esc_html__('Edit Price Type', 'event_espresso'),
288
-                    'icon' => 'dashicons-edit-large',
289
-                    'order'      => 40,
290
-                    'persistent' => false,
291
-                ],
292
-                'help_tabs'     => [
293
-                    'edit_price_type_help_tab' => [
294
-                        'title'    => esc_html__('Edit Price Type', 'event_espresso'),
295
-                        'filename' => 'pricing_edit_price_type',
296
-                    ],
297
-                ],
298
-                'metaboxes'     => array_merge(
299
-                    ['_publish_post_box'],
300
-                    $this->_default_espresso_metaboxes
301
-                ),
302
-                'require_nonce' => false,
303
-            ],
304
-            'tax_settings'       => [
305
-                'nav' => [
306
-                    'label' => esc_html__('Tax Settings', 'event_espresso'),
307
-                    'icon' => 'dashicons-sticky',
308
-                    'order' => 50,
309
-                ],
310
-                'labels'        => [
311
-                    'publishbox' => esc_html__('Update Tax Settings', 'event_espresso'),
312
-                ],
313
-                'metaboxes'     => array_merge(
314
-                    ['_publish_post_box'],
315
-                    $this->_default_espresso_metaboxes
316
-                ),
317
-                'require_nonce' => true,
318
-            ],
319
-        ];
320
-    }
321
-
322
-
323
-    protected function _add_screen_options()
324
-    {
325
-        // todo
326
-    }
327
-
328
-
329
-    protected function _add_screen_options_default()
330
-    {
331
-        $this->_per_page_screen_option();
332
-    }
333
-
334
-
335
-    protected function _add_screen_options_price_types()
336
-    {
337
-        $page_title              = $this->_admin_page_title;
338
-        $this->_admin_page_title = esc_html__('Price Types', 'event_espresso');
339
-        $this->_per_page_screen_option();
340
-        $this->_admin_page_title = $page_title;
341
-    }
342
-
343
-
344
-    protected function _add_feature_pointers()
345
-    {
346
-    }
347
-
348
-
349
-    public function load_scripts_styles()
350
-    {
351
-        // styles
352
-        wp_enqueue_style('espresso-ui-theme');
353
-        wp_register_style(
354
-            'espresso_pricing_css',
355
-            PRICING_ASSETS_URL . 'espresso_pricing_admin.css',
356
-            [EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_ADMIN],
357
-            EVENT_ESPRESSO_VERSION
358
-        );
359
-        wp_enqueue_style('espresso_pricing_css');
360
-
361
-        // scripts
362
-        wp_enqueue_script('ee_admin_js');
363
-        wp_enqueue_script('jquery-ui-position');
364
-        wp_enqueue_script('jquery-ui-widget');
365
-        wp_register_script(
366
-            'espresso_pricing_js',
367
-            PRICING_ASSETS_URL . 'espresso_pricing_admin.js',
368
-            ['jquery'],
369
-            EVENT_ESPRESSO_VERSION,
370
-            true
371
-        );
372
-        wp_enqueue_script('espresso_pricing_js');
373
-    }
374
-
375
-
376
-    public function load_scripts_styles_default()
377
-    {
378
-        wp_enqueue_script('espresso_ajax_table_sorting');
379
-    }
380
-
381
-
382
-    public function admin_footer_scripts()
383
-    {
384
-    }
385
-
386
-
387
-    public function admin_init()
388
-    {
389
-    }
390
-
391
-
392
-    public function admin_notices()
393
-    {
394
-    }
395
-
396
-
397
-    protected function _set_list_table_views_default()
398
-    {
399
-        $this->_views = [
400
-            'all' => [
401
-                'slug'        => 'all',
402
-                'label'       => esc_html__('View All Default Pricing', 'event_espresso'),
403
-                'count'       => 0,
404
-                'bulk_action' => [
405
-                    'trash_price' => esc_html__('Move to Trash', 'event_espresso'),
406
-                ],
407
-            ],
408
-        ];
409
-
410
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_default_prices', 'pricing_trash_price')) {
411
-            $this->_views['trashed'] = [
412
-                'slug'        => 'trashed',
413
-                'label'       => esc_html__('Trash', 'event_espresso'),
414
-                'count'       => 0,
415
-                'bulk_action' => [
416
-                    'restore_price' => esc_html__('Restore from Trash', 'event_espresso'),
417
-                    'delete_price'  => esc_html__('Delete Permanently', 'event_espresso'),
418
-                ],
419
-            ];
420
-        }
421
-    }
422
-
423
-
424
-    protected function _set_list_table_views_price_types()
425
-    {
426
-        $this->_views = [
427
-            'all' => [
428
-                'slug'        => 'all',
429
-                'label'       => esc_html__('All', 'event_espresso'),
430
-                'count'       => 0,
431
-                'bulk_action' => [
432
-                    'trash_price_type' => esc_html__('Move to Trash', 'event_espresso'),
433
-                ],
434
-            ],
435
-        ];
436
-
437
-        if (
438
-            EE_Registry::instance()->CAP->current_user_can(
439
-                'ee_delete_default_price_types',
440
-                'pricing_trash_price_type'
441
-            )
442
-        ) {
443
-            $this->_views['trashed'] = [
444
-                'slug'        => 'trashed',
445
-                'label'       => esc_html__('Trash', 'event_espresso'),
446
-                'count'       => 0,
447
-                'bulk_action' => [
448
-                    'restore_price_type' => esc_html__('Restore from Trash', 'event_espresso'),
449
-                    'delete_price_type'  => esc_html__('Delete Permanently', 'event_espresso'),
450
-                ],
451
-            ];
452
-        }
453
-    }
454
-
455
-
456
-    /**
457
-     * generates HTML for main Prices Admin page
458
-     *
459
-     * @return void
460
-     * @throws EE_Error
461
-     */
462
-    protected function _price_overview_list_table()
463
-    {
464
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
465
-            'add_new_price',
466
-            'add',
467
-            [],
468
-            'add-new-h2'
469
-        );
470
-        $this->_admin_page_title .= $this->_learn_more_about_pricing_link();
471
-        $this->_search_btn_label = esc_html__('Default Prices', 'event_espresso');
472
-        $this->display_admin_list_table_page_with_sidebar();
473
-    }
474
-
475
-
476
-    /**
477
-     * retrieve data for Prices List table
478
-     *
479
-     * @param int  $per_page how many prices displayed per page
480
-     * @param bool $count    return the count or objects
481
-     * @param bool $trashed  whether the current view is of the trash can - eww yuck!
482
-     * @return EE_Soft_Delete_Base_Class[]|int int = count || array of price objects
483
-     * @throws EE_Error
484
-     * @throws ReflectionException
485
-     */
486
-    public function get_prices_overview_data(int $per_page = 10, bool $count = false, bool $trashed = false)
487
-    {
488
-        // start with an empty array
489
-        $event_pricing = [];
490
-
491
-        require_once(PRICING_ADMIN . 'Prices_List_Table.class.php');
492
-
493
-        $orderby = $this->request->getRequestParam('orderby', '');
494
-        $order   = $this->request->getRequestParam('order', 'ASC');
495
-
496
-        switch ($orderby) {
497
-            case 'name':
498
-                $orderby = ['PRC_name' => $order];
499
-                break;
500
-            case 'type':
501
-                $orderby = ['Price_Type.PRT_name' => $order];
502
-                break;
503
-            case 'amount':
504
-                $orderby = ['PRC_amount' => $order];
505
-                break;
506
-            default:
507
-                $orderby = ['PRC_order' => $order, 'Price_Type.PRT_order' => $order, 'PRC_ID' => $order];
508
-        }
509
-
510
-        $current_page = $this->request->getRequestParam('paged', 1, DataType::INTEGER);
511
-        $per_page     = $this->request->getRequestParam('perpage', $per_page, DataType::INTEGER);
512
-
513
-        $where = [
514
-            'PRC_is_default' => 1,
515
-            'PRC_deleted'    => $trashed,
516
-        ];
517
-
518
-        $offset = ($current_page - 1) * $per_page;
519
-        $limit  = [$offset, $per_page];
520
-
521
-        $search_term = $this->request->getRequestParam('s');
522
-        if ($search_term) {
523
-            $search_term = "%{$search_term}%";
524
-            $where['OR'] = [
525
-                'PRC_name'            => ['LIKE', $search_term],
526
-                'PRC_desc'            => ['LIKE', $search_term],
527
-                'PRC_amount'          => ['LIKE', $search_term],
528
-                'Price_Type.PRT_name' => ['LIKE', $search_term],
529
-            ];
530
-        }
531
-
532
-        $query_params = [
533
-            $where,
534
-            'order_by' => $orderby,
535
-            'limit'    => $limit,
536
-            'group_by' => 'PRC_ID',
537
-        ];
538
-
539
-        if ($count) {
540
-            return $trashed
541
-                ? EEM_Price::instance()->count([$where])
542
-                : EEM_Price::instance()->count_deleted_and_undeleted([$where]);
543
-        }
544
-        return EEM_Price::instance()->get_all_deleted_and_undeleted($query_params);
545
-    }
546
-
547
-
548
-    /**
549
-     * @return void
550
-     * @throws EE_Error
551
-     * @throws ReflectionException
552
-     */
553
-    protected function _edit_price_details()
554
-    {
555
-        // grab price ID
556
-        $PRC_ID = $this->request->getRequestParam('id', 0, DataType::INTEGER);
557
-        // change page title based on request action
558
-        switch ($this->_req_action) {
559
-            case 'add_new_price':
560
-                $this->_admin_page_title = esc_html__('Add New Price', 'event_espresso');
561
-                break;
562
-            case 'edit_price':
563
-                $this->_admin_page_title = esc_html__('Edit Price', 'event_espresso');
564
-                break;
565
-            default:
566
-                $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action));
567
-        }
568
-        // add PRC_ID to title if editing
569
-        $this->_admin_page_title = $PRC_ID ? $this->_admin_page_title . ' # ' . $PRC_ID : $this->_admin_page_title;
570
-
571
-        if ($PRC_ID) {
572
-            $price                    = EEM_Price::instance()->get_one_by_ID($PRC_ID);
573
-            $additional_hidden_fields = [
574
-                'PRC_ID' => ['type' => 'hidden', 'value' => $PRC_ID],
575
-            ];
576
-            $this->_set_add_edit_form_tags('update_price', $additional_hidden_fields);
577
-        } else {
578
-            $price = EEM_Price::instance()->get_new_price();
579
-            $this->_set_add_edit_form_tags('insert_price');
580
-        }
581
-
582
-        if (! $price instanceof EE_Price) {
583
-            throw new RuntimeException(
584
-                sprintf(
585
-                    esc_html__(
586
-                        'A valid Price could not be retrieved from the database with ID: %1$s',
587
-                        'event_espresso'
588
-                    ),
589
-                    $PRC_ID
590
-                )
591
-            );
592
-        }
593
-
594
-        $this->_template_args['PRC_ID'] = $PRC_ID;
595
-        $this->_template_args['price']  = $price;
596
-
597
-        $default_base_price = $price->type_obj() && $price->type_obj()->base_type() === 1;
598
-
599
-        $this->_template_args['default_base_price'] = $default_base_price;
600
-
601
-        // get price types
602
-        $price_types = EEM_Price_Type::instance()->get_all([['PBT_ID' => ['!=', 1]]]);
603
-        if (empty($price_types)) {
604
-            $msg = esc_html__(
605
-                'You have no price types defined. Please add a price type before adding a price.',
606
-                'event_espresso'
607
-            );
608
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
609
-            $this->display_admin_page_with_sidebar();
610
-        }
611
-        $attributes       = [];
612
-        $price_type_names = [];
613
-        $attributes[]     = 'id="PRT_ID"';
614
-        if ($default_base_price) {
615
-            $attributes[]       = 'disabled="disabled"';
616
-            $price_type_names[] = ['id' => 1, 'text' => esc_html__('Base Price', 'event_espresso')];
617
-        }
618
-        foreach ($price_types as $type) {
619
-            $price_type_names[] = ['id' => $type->ID(), 'text' => $type->name()];
620
-        }
621
-        $this->_template_args['attributes']  = implode(' ', $attributes);
622
-        $this->_template_args['price_types'] = $price_type_names;
623
-
624
-        $this->_template_args['learn_more_about_pricing_link'] = $this->_learn_more_about_pricing_link();
625
-        $this->_template_args['admin_page_content']            = $this->_edit_price_details_meta_box();
626
-
627
-        $this->_set_publish_post_box_vars('id', $PRC_ID, '', '', true);
628
-        // the details template wrapper
629
-        $this->display_admin_page_with_sidebar();
630
-    }
631
-
632
-
633
-    /**
634
-     *
635
-     * @return string
636
-     */
637
-    public function _edit_price_details_meta_box(): string
638
-    {
639
-        return EEH_Template::display_template(
640
-            PRICING_TEMPLATE_PATH . 'pricing_details_main_meta_box.template.php',
641
-            $this->_template_args,
642
-            true
643
-        );
644
-    }
645
-
646
-
647
-    /**
648
-     * @return array
649
-     * @throws EE_Error
650
-     * @throws ReflectionException
651
-     */
652
-    protected function set_price_column_values(): array
653
-    {
654
-        $PRC_order = 0;
655
-        $PRT_ID    = $this->request->getRequestParam('PRT_ID', 0, DataType::INTEGER);
656
-        if ($PRT_ID) {
657
-            /** @var EE_Price_Type $price_type */
658
-            $price_type = EEM_Price_Type::instance()->get_one_by_ID($PRT_ID);
659
-            if ($price_type instanceof EE_Price_Type) {
660
-                $PRC_order = $price_type->order();
661
-            }
662
-        }
663
-        return [
664
-            'PRT_ID'         => $PRT_ID,
665
-            'PRC_amount'     => $this->request->getRequestParam('PRC_amount', 0, DataType::FLOAT),
666
-            'PRC_name'       => $this->request->getRequestParam('PRC_name'),
667
-            'PRC_desc'       => $this->request->getRequestParam('PRC_desc'),
668
-            'PRC_is_default' => 1,
669
-            'PRC_overrides'  => null,
670
-            'PRC_order'      => $PRC_order,
671
-            'PRC_deleted'    => 0,
672
-            'PRC_parent'     => 0,
673
-        ];
674
-    }
675
-
676
-
677
-    /**
678
-     * @param bool $insert - whether to insert or update
679
-     * @return void
680
-     * @throws EE_Error
681
-     * @throws ReflectionException
682
-     */
683
-    protected function _insert_or_update_price(bool $insert = false)
684
-    {
685
-        // why be so pessimistic ???  : (
686
-        $updated = 0;
687
-
688
-        $set_column_values = $this->set_price_column_values();
689
-        // is this a new Price ?
690
-        if ($insert) {
691
-            // run the insert
692
-            $PRC_ID = EEM_Price::instance()->insert($set_column_values);
693
-            if ($PRC_ID) {
694
-                // make sure this new price modifier is attached to the ticket but ONLY if it is not a tax type
695
-                $price = EEM_price::instance()->get_one_by_ID($PRC_ID);
696
-                if (
697
-                    $price instanceof EE_Price
698
-                    && $price->type_obj() instanceof EE_Price_type
699
-                    && $price->type_obj()->base_type() !== EEM_Price_Type::base_type_tax
700
-                ) {
701
-                    $ticket = EEM_Ticket::instance()->get_one_by_ID(1);
702
-                    $ticket->_add_relation_to($price, 'Price');
703
-                    $ticket->save();
704
-                }
705
-                $updated = 1;
706
-            }
707
-            $action_desc = 'created';
708
-        } else {
709
-            $PRC_ID = $this->request->getRequestParam('PRC_ID', 0, DataType::INTEGER);
710
-            // run the update
711
-            $where_cols_n_values = ['PRC_ID' => $PRC_ID];
712
-            $updated             = EEM_Price::instance()->update($set_column_values, [$where_cols_n_values]);
713
-
714
-            $price = EEM_Price::instance()->get_one_by_ID($PRC_ID);
715
-            if ($price instanceof EE_Price && $price->type_obj()->base_type() !== EEM_Price_Type::base_type_tax) {
716
-                // if this is $PRC_ID == 1,
717
-                // then we need to update the default ticket attached to this price so the TKT_price value is updated.
718
-                if ($PRC_ID === 1) {
719
-                    $ticket = $price->get_first_related('Ticket');
720
-                    if ($ticket) {
721
-                        $ticket->set('TKT_price', $price->get('PRC_amount'));
722
-                        $ticket->set('TKT_name', $price->get('PRC_name'));
723
-                        $ticket->set('TKT_description', $price->get('PRC_desc'));
724
-                        $ticket->save();
725
-                    }
726
-                } else {
727
-                    // we make sure this price is attached to base ticket. but ONLY if it's not a tax ticket type.
728
-                    $ticket = EEM_Ticket::instance()->get_one_by_ID(1);
729
-                    if ($ticket instanceof EE_Ticket) {
730
-                        $ticket->_add_relation_to($PRC_ID, 'Price');
731
-                        $ticket->save();
732
-                    }
733
-                }
734
-            }
735
-
736
-            $action_desc = 'updated';
737
-        }
738
-
739
-        $query_args = ['action' => 'edit_price', 'id' => $PRC_ID];
740
-
741
-        $this->_redirect_after_action($updated, 'Prices', $action_desc, $query_args);
742
-    }
743
-
744
-
745
-    /**
746
-     * @param bool $trash - whether to move item to trash (TRUE) or restore it (FALSE)
747
-     * @return void
748
-     * @throws EE_Error
749
-     */
750
-    protected function _trash_or_restore_price($trash = true)
751
-    {
752
-        $entity_model = EEM_Price::instance();
753
-        $action       = $trash ? EE_Admin_List_Table::ACTION_TRASH : EE_Admin_List_Table::ACTION_RESTORE;
754
-        $result       = $this->trashRestoreDeleteEntities(
755
-            $entity_model,
756
-            'id',
757
-            $action,
758
-            'PRC_deleted',
759
-            [$this, 'adjustTicketRelations']
760
-        );
761
-
762
-        if ($result) {
763
-            $msg = $trash
764
-                ? esc_html(
765
-                    _n(
766
-                        'The Price has been trashed',
767
-                        'The Prices have been trashed',
768
-                        $result,
769
-                        'event_espresso'
770
-                    )
771
-                )
772
-                : esc_html(
773
-                    _n(
774
-                        'The Price has been restored',
775
-                        'The Prices have been restored',
776
-                        $result,
777
-                        'event_espresso'
778
-                    )
779
-                );
780
-            EE_Error::add_success($msg);
781
-        }
782
-
783
-        $this->_redirect_after_action(
784
-            $result,
785
-            _n('Price', 'Prices', $result, 'event_espresso'),
786
-            $trash ? 'trashed' : 'restored',
787
-            ['action' => 'default'],
788
-            true
789
-        );
790
-    }
791
-
792
-
793
-    /**
794
-     * @param EEM_Base   $entity_model
795
-     * @param int|string $entity_ID
796
-     * @param string     $action
797
-     * @param int        $result
798
-     * @throws EE_Error
799
-     * @throws ReflectionException
800
-     * @since 4.10.30.p
801
-     */
802
-    public function adjustTicketRelations(
803
-        EEM_Base $entity_model,
804
-        $entity_ID,
805
-        string $action,
806
-        int $result
807
-    ) {
808
-        if (! $entity_ID || (float) $result < 1) {
809
-            return;
810
-        }
811
-
812
-        $entity = $entity_model->get_one_by_ID($entity_ID);
813
-        if (! $entity instanceof EE_Price || $entity->type_obj()->base_type() === EEM_Price_Type::base_type_tax) {
814
-            return;
815
-        }
816
-
817
-        // get default tickets for updating
818
-        $default_tickets = EEM_Ticket::instance()->get_all_default_tickets();
819
-        foreach ($default_tickets as $default_ticket) {
820
-            if (! $default_ticket instanceof EE_Ticket) {
821
-                continue;
822
-            }
823
-            switch ($action) {
824
-                case EE_Admin_List_Table::ACTION_DELETE:
825
-                case EE_Admin_List_Table::ACTION_TRASH:
826
-                    // if trashing then remove relations to base default ticket.
827
-                    $default_ticket->_remove_relation_to($entity_ID, 'Price');
828
-                    break;
829
-                case EE_Admin_List_Table::ACTION_RESTORE:
830
-                    // if restoring then add back to base default ticket
831
-                    $default_ticket->_add_relation_to($entity_ID, 'Price');
832
-                    break;
833
-            }
834
-            $default_ticket->save();
835
-        }
836
-    }
837
-
838
-
839
-    /**
840
-     * @return void
841
-     * @throws EE_Error
842
-     * @throws ReflectionException
843
-     */
844
-    protected function _delete_price()
845
-    {
846
-        $entity_model = EEM_Price::instance();
847
-        $deleted      = $this->trashRestoreDeleteEntities($entity_model, 'id');
848
-        $entity       = $entity_model->item_name($deleted);
849
-        $this->_redirect_after_action(
850
-            $deleted,
851
-            $entity,
852
-            'deleted',
853
-            ['action' => 'default']
854
-        );
855
-    }
856
-
857
-
858
-    /**
859
-     * @throws EE_Error
860
-     * @throws ReflectionException
861
-     */
862
-    public function update_price_order()
863
-    {
864
-        // grab our row IDs
865
-        $row_ids = $this->request->getRequestParam('row_ids', '');
866
-        $row_ids = explode(',', rtrim($row_ids, ','));
867
-
868
-        $all_updated = true;
869
-        foreach ($row_ids as $i => $row_id) {
870
-            // Update the prices when re-ordering
871
-            $fields_n_values = ['PRC_order' => $i + 1];
872
-            $query_params    = [['PRC_ID' => absint($row_id)]];
873
-            // any failure will toggle $all_updated to false
874
-            $all_updated = $row_id && EEM_Price::instance()->update($fields_n_values, $query_params) !== false
875
-                ? $all_updated
876
-                : false;
877
-        }
878
-        $success = $all_updated
879
-            ? esc_html__('Price order was updated successfully.', 'event_espresso')
880
-            : false;
881
-        $errors  = ! $all_updated
882
-            ? esc_html__('An error occurred. The price order was not updated.', 'event_espresso')
883
-            : false;
884
-
885
-        echo wp_json_encode(['return_data' => false, 'success' => $success, 'errors' => $errors]);
886
-        die();
887
-    }
888
-
889
-
890
-    /******************************************************************************************************************
15
+	protected function _init_page_props()
16
+	{
17
+		$this->page_slug        = PRICING_PG_SLUG;
18
+		$this->page_label       = PRICING_LABEL;
19
+		$this->_admin_base_url  = PRICING_ADMIN_URL;
20
+		$this->_admin_base_path = PRICING_ADMIN;
21
+	}
22
+
23
+
24
+	protected function _ajax_hooks()
25
+	{
26
+		add_action('wp_ajax_espresso_update_prices_order', [$this, 'update_price_order']);
27
+	}
28
+
29
+
30
+	protected function _define_page_props()
31
+	{
32
+		$this->_admin_page_title = PRICING_LABEL;
33
+		$this->_labels           = [
34
+			'buttons' => [
35
+				'add'         => esc_html__('Add New Default Price', 'event_espresso'),
36
+				'edit'        => esc_html__('Edit Default Price', 'event_espresso'),
37
+				'delete'      => esc_html__('Delete Default Price', 'event_espresso'),
38
+				'add_type'    => esc_html__('Add New Default Price Type', 'event_espresso'),
39
+				'edit_type'   => esc_html__('Edit Price Type', 'event_espresso'),
40
+				'delete_type' => esc_html__('Delete Price Type', 'event_espresso'),
41
+			],
42
+			'publishbox' => [
43
+				'add_new_price'      => esc_html__('Add New Default Price', 'event_espresso'),
44
+				'edit_price'         => esc_html__('Edit Default Price', 'event_espresso'),
45
+				'add_new_price_type' => esc_html__('Add New Default Price Type', 'event_espresso'),
46
+				'edit_price_type'    => esc_html__('Edit Price Type', 'event_espresso'),
47
+			],
48
+		];
49
+	}
50
+
51
+
52
+	/**
53
+	 * an array for storing request actions and their corresponding methods
54
+	 *
55
+	 * @return void
56
+	 */
57
+	protected function _set_page_routes()
58
+	{
59
+		$PRC_ID             = $this->request->getRequestParam('PRC_ID', 0, DataType::INTEGER);
60
+		$PRT_ID             = $this->request->getRequestParam('PRT_ID', 0, DataType::INTEGER);
61
+		$this->_page_routes = [
62
+			'default'                     => [
63
+				'func'       => [$this, '_price_overview_list_table'],
64
+				'capability' => 'ee_read_default_prices',
65
+			],
66
+			'add_new_price'               => [
67
+				'func'       => [$this, '_edit_price_details'],
68
+				'capability' => 'ee_edit_default_prices',
69
+			],
70
+			'edit_price'                  => [
71
+				'func'       => [$this, '_edit_price_details'],
72
+				'capability' => 'ee_edit_default_price',
73
+				'obj_id'     => $PRC_ID,
74
+			],
75
+			'insert_price'                => [
76
+				'func'       => [$this, '_insert_or_update_price'],
77
+				'args'       => ['insert' => true],
78
+				'noheader'   => true,
79
+				'capability' => 'ee_edit_default_prices',
80
+			],
81
+			'update_price'                => [
82
+				'func'       => [$this, '_insert_or_update_price'],
83
+				'args'       => ['insert' => false],
84
+				'noheader'   => true,
85
+				'capability' => 'ee_edit_default_price',
86
+				'obj_id'     => $PRC_ID,
87
+			],
88
+			'trash_price'                 => [
89
+				'func'       => [$this, '_trash_or_restore_price'],
90
+				'args'       => ['trash' => true],
91
+				'noheader'   => true,
92
+				'capability' => 'ee_delete_default_price',
93
+				'obj_id'     => $PRC_ID,
94
+			],
95
+			'restore_price'               => [
96
+				'func'       => [$this, '_trash_or_restore_price'],
97
+				'args'       => ['trash' => false],
98
+				'noheader'   => true,
99
+				'capability' => 'ee_delete_default_price',
100
+				'obj_id'     => $PRC_ID,
101
+			],
102
+			'delete_price'                => [
103
+				'func'       => [$this, '_delete_price'],
104
+				'noheader'   => true,
105
+				'capability' => 'ee_delete_default_price',
106
+				'obj_id'     => $PRC_ID,
107
+			],
108
+			'espresso_update_price_order' => [
109
+				'func'       => [$this, 'update_price_order'],
110
+				'noheader'   => true,
111
+				'capability' => 'ee_edit_default_prices',
112
+			],
113
+			// price types
114
+			'price_types'                 => [
115
+				'func'       => [$this, '_price_types_overview_list_table'],
116
+				'capability' => 'ee_read_default_price_types',
117
+			],
118
+			'add_new_price_type'          => [
119
+				'func'       => [$this, '_edit_price_type_details'],
120
+				'capability' => 'ee_edit_default_price_types',
121
+			],
122
+			'edit_price_type'             => [
123
+				'func'       => [$this, '_edit_price_type_details'],
124
+				'capability' => 'ee_edit_default_price_type',
125
+				'obj_id'     => $PRT_ID,
126
+			],
127
+			'insert_price_type'           => [
128
+				'func'       => [$this, '_insert_or_update_price_type'],
129
+				'args'       => ['new_price_type' => true],
130
+				'noheader'   => true,
131
+				'capability' => 'ee_edit_default_price_types',
132
+			],
133
+			'update_price_type'           => [
134
+				'func'       => [$this, '_insert_or_update_price_type'],
135
+				'args'       => ['new_price_type' => false],
136
+				'noheader'   => true,
137
+				'capability' => 'ee_edit_default_price_type',
138
+				'obj_id'     => $PRT_ID,
139
+			],
140
+			'trash_price_type'            => [
141
+				'func'       => [$this, '_trash_or_restore_price_type'],
142
+				'args'       => ['trash' => true],
143
+				'noheader'   => true,
144
+				'capability' => 'ee_delete_default_price_type',
145
+				'obj_id'     => $PRT_ID,
146
+			],
147
+			'restore_price_type'          => [
148
+				'func'       => [$this, '_trash_or_restore_price_type'],
149
+				'args'       => ['trash' => false],
150
+				'noheader'   => true,
151
+				'capability' => 'ee_delete_default_price_type',
152
+				'obj_id'     => $PRT_ID,
153
+			],
154
+			'delete_price_type'           => [
155
+				'func'       => [$this, '_delete_price_type'],
156
+				'noheader'   => true,
157
+				'capability' => 'ee_delete_default_price_type',
158
+				'obj_id'     => $PRT_ID,
159
+			],
160
+			'tax_settings'                => [
161
+				'func'       => [$this, '_tax_settings'],
162
+				'capability' => 'manage_options',
163
+			],
164
+			'update_tax_settings'         => [
165
+				'func'       => [$this, '_update_tax_settings'],
166
+				'capability' => 'manage_options',
167
+				'noheader'   => true,
168
+			],
169
+		];
170
+	}
171
+
172
+
173
+	protected function _set_page_config()
174
+	{
175
+		$PRC_ID             = $this->request->getRequestParam('id', 0, DataType::INTEGER);
176
+		$this->_page_config = [
177
+			'default'            => [
178
+				'nav'           => [
179
+					'label' => esc_html__('Default Pricing', 'event_espresso'),
180
+					'icon' => 'dashicons-money-alt',
181
+					'order' => 10,
182
+				],
183
+				'list_table'    => 'Prices_List_Table',
184
+				'metaboxes'     => $this->_default_espresso_metaboxes,
185
+				'help_tabs'     => [
186
+					'pricing_default_pricing_help_tab'                           => [
187
+						'title'    => esc_html__('Default Pricing', 'event_espresso'),
188
+						'filename' => 'pricing_default_pricing',
189
+					],
190
+					'pricing_default_pricing_table_column_headings_help_tab'     => [
191
+						'title'    => esc_html__('Default Pricing Table Column Headings', 'event_espresso'),
192
+						'filename' => 'pricing_default_pricing_table_column_headings',
193
+					],
194
+					'pricing_default_pricing_views_bulk_actions_search_help_tab' => [
195
+						'title'    => esc_html__('Default Pricing Views & Bulk Actions & Search', 'event_espresso'),
196
+						'filename' => 'pricing_default_pricing_views_bulk_actions_search',
197
+					],
198
+				],
199
+				'require_nonce' => false,
200
+			],
201
+			'add_new_price'      => [
202
+				'nav'           => [
203
+					'label'      => esc_html__('Add New Default Price', 'event_espresso'),
204
+					'icon' => 'dashicons-plus-alt',
205
+					'order'      => 20,
206
+					'persistent' => false,
207
+				],
208
+				'help_tabs'     => [
209
+					'add_new_default_price_help_tab' => [
210
+						'title'    => esc_html__('Add New Default Price', 'event_espresso'),
211
+						'filename' => 'pricing_add_new_default_price',
212
+					],
213
+				],
214
+				'metaboxes'     => array_merge(
215
+					['_publish_post_box'],
216
+					$this->_default_espresso_metaboxes
217
+				),
218
+				'require_nonce' => false,
219
+			],
220
+			'edit_price'         => [
221
+				'nav'           => [
222
+					'label'      => esc_html__('Edit Default Price', 'event_espresso'),
223
+					'icon' => 'dashicons-edit-large',
224
+					'order'      => 20,
225
+					'url'        => $PRC_ID
226
+						? add_query_arg(['id' => $PRC_ID], $this->_current_page_view_url)
227
+						: $this->_admin_base_url,
228
+					'persistent' => false,
229
+				],
230
+				'metaboxes'     => array_merge(
231
+					['_publish_post_box'],
232
+					$this->_default_espresso_metaboxes
233
+				),
234
+				'help_tabs'     => [
235
+					'edit_default_price_help_tab' => [
236
+						'title'    => esc_html__('Edit Default Price', 'event_espresso'),
237
+						'filename' => 'pricing_edit_default_price',
238
+					],
239
+				],
240
+				'require_nonce' => false,
241
+			],
242
+			'price_types'        => [
243
+				'nav'           => [
244
+					'label' => esc_html__('Price Types', 'event_espresso'),
245
+					'icon' => 'dashicons-networking',
246
+					'order' => 30,
247
+				],
248
+				'list_table'    => 'Price_Types_List_Table',
249
+				'help_tabs'     => [
250
+					'pricing_price_types_help_tab'                           => [
251
+						'title'    => esc_html__('Price Types', 'event_espresso'),
252
+						'filename' => 'pricing_price_types',
253
+					],
254
+					'pricing_price_types_table_column_headings_help_tab'     => [
255
+						'title'    => esc_html__('Price Types Table Column Headings', 'event_espresso'),
256
+						'filename' => 'pricing_price_types_table_column_headings',
257
+					],
258
+					'pricing_price_types_views_bulk_actions_search_help_tab' => [
259
+						'title'    => esc_html__('Price Types Views & Bulk Actions & Search', 'event_espresso'),
260
+						'filename' => 'pricing_price_types_views_bulk_actions_search',
261
+					],
262
+				],
263
+				'metaboxes'     => $this->_default_espresso_metaboxes,
264
+				'require_nonce' => false,
265
+			],
266
+			'add_new_price_type' => [
267
+				'nav'           => [
268
+					'label'      => esc_html__('Add New Price Type', 'event_espresso'),
269
+					'icon' => 'dashicons-plus-alt',
270
+					'order'      => 40,
271
+					'persistent' => false,
272
+				],
273
+				'help_tabs'     => [
274
+					'add_new_price_type_help_tab' => [
275
+						'title'    => esc_html__('Add New Price Type', 'event_espresso'),
276
+						'filename' => 'pricing_add_new_price_type',
277
+					],
278
+				],
279
+				'metaboxes'     => array_merge(
280
+					['_publish_post_box'],
281
+					$this->_default_espresso_metaboxes
282
+				),
283
+				'require_nonce' => false,
284
+			],
285
+			'edit_price_type'    => [
286
+				'nav'           => [
287
+					'label'      => esc_html__('Edit Price Type', 'event_espresso'),
288
+					'icon' => 'dashicons-edit-large',
289
+					'order'      => 40,
290
+					'persistent' => false,
291
+				],
292
+				'help_tabs'     => [
293
+					'edit_price_type_help_tab' => [
294
+						'title'    => esc_html__('Edit Price Type', 'event_espresso'),
295
+						'filename' => 'pricing_edit_price_type',
296
+					],
297
+				],
298
+				'metaboxes'     => array_merge(
299
+					['_publish_post_box'],
300
+					$this->_default_espresso_metaboxes
301
+				),
302
+				'require_nonce' => false,
303
+			],
304
+			'tax_settings'       => [
305
+				'nav' => [
306
+					'label' => esc_html__('Tax Settings', 'event_espresso'),
307
+					'icon' => 'dashicons-sticky',
308
+					'order' => 50,
309
+				],
310
+				'labels'        => [
311
+					'publishbox' => esc_html__('Update Tax Settings', 'event_espresso'),
312
+				],
313
+				'metaboxes'     => array_merge(
314
+					['_publish_post_box'],
315
+					$this->_default_espresso_metaboxes
316
+				),
317
+				'require_nonce' => true,
318
+			],
319
+		];
320
+	}
321
+
322
+
323
+	protected function _add_screen_options()
324
+	{
325
+		// todo
326
+	}
327
+
328
+
329
+	protected function _add_screen_options_default()
330
+	{
331
+		$this->_per_page_screen_option();
332
+	}
333
+
334
+
335
+	protected function _add_screen_options_price_types()
336
+	{
337
+		$page_title              = $this->_admin_page_title;
338
+		$this->_admin_page_title = esc_html__('Price Types', 'event_espresso');
339
+		$this->_per_page_screen_option();
340
+		$this->_admin_page_title = $page_title;
341
+	}
342
+
343
+
344
+	protected function _add_feature_pointers()
345
+	{
346
+	}
347
+
348
+
349
+	public function load_scripts_styles()
350
+	{
351
+		// styles
352
+		wp_enqueue_style('espresso-ui-theme');
353
+		wp_register_style(
354
+			'espresso_pricing_css',
355
+			PRICING_ASSETS_URL . 'espresso_pricing_admin.css',
356
+			[EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_ADMIN],
357
+			EVENT_ESPRESSO_VERSION
358
+		);
359
+		wp_enqueue_style('espresso_pricing_css');
360
+
361
+		// scripts
362
+		wp_enqueue_script('ee_admin_js');
363
+		wp_enqueue_script('jquery-ui-position');
364
+		wp_enqueue_script('jquery-ui-widget');
365
+		wp_register_script(
366
+			'espresso_pricing_js',
367
+			PRICING_ASSETS_URL . 'espresso_pricing_admin.js',
368
+			['jquery'],
369
+			EVENT_ESPRESSO_VERSION,
370
+			true
371
+		);
372
+		wp_enqueue_script('espresso_pricing_js');
373
+	}
374
+
375
+
376
+	public function load_scripts_styles_default()
377
+	{
378
+		wp_enqueue_script('espresso_ajax_table_sorting');
379
+	}
380
+
381
+
382
+	public function admin_footer_scripts()
383
+	{
384
+	}
385
+
386
+
387
+	public function admin_init()
388
+	{
389
+	}
390
+
391
+
392
+	public function admin_notices()
393
+	{
394
+	}
395
+
396
+
397
+	protected function _set_list_table_views_default()
398
+	{
399
+		$this->_views = [
400
+			'all' => [
401
+				'slug'        => 'all',
402
+				'label'       => esc_html__('View All Default Pricing', 'event_espresso'),
403
+				'count'       => 0,
404
+				'bulk_action' => [
405
+					'trash_price' => esc_html__('Move to Trash', 'event_espresso'),
406
+				],
407
+			],
408
+		];
409
+
410
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_default_prices', 'pricing_trash_price')) {
411
+			$this->_views['trashed'] = [
412
+				'slug'        => 'trashed',
413
+				'label'       => esc_html__('Trash', 'event_espresso'),
414
+				'count'       => 0,
415
+				'bulk_action' => [
416
+					'restore_price' => esc_html__('Restore from Trash', 'event_espresso'),
417
+					'delete_price'  => esc_html__('Delete Permanently', 'event_espresso'),
418
+				],
419
+			];
420
+		}
421
+	}
422
+
423
+
424
+	protected function _set_list_table_views_price_types()
425
+	{
426
+		$this->_views = [
427
+			'all' => [
428
+				'slug'        => 'all',
429
+				'label'       => esc_html__('All', 'event_espresso'),
430
+				'count'       => 0,
431
+				'bulk_action' => [
432
+					'trash_price_type' => esc_html__('Move to Trash', 'event_espresso'),
433
+				],
434
+			],
435
+		];
436
+
437
+		if (
438
+			EE_Registry::instance()->CAP->current_user_can(
439
+				'ee_delete_default_price_types',
440
+				'pricing_trash_price_type'
441
+			)
442
+		) {
443
+			$this->_views['trashed'] = [
444
+				'slug'        => 'trashed',
445
+				'label'       => esc_html__('Trash', 'event_espresso'),
446
+				'count'       => 0,
447
+				'bulk_action' => [
448
+					'restore_price_type' => esc_html__('Restore from Trash', 'event_espresso'),
449
+					'delete_price_type'  => esc_html__('Delete Permanently', 'event_espresso'),
450
+				],
451
+			];
452
+		}
453
+	}
454
+
455
+
456
+	/**
457
+	 * generates HTML for main Prices Admin page
458
+	 *
459
+	 * @return void
460
+	 * @throws EE_Error
461
+	 */
462
+	protected function _price_overview_list_table()
463
+	{
464
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
465
+			'add_new_price',
466
+			'add',
467
+			[],
468
+			'add-new-h2'
469
+		);
470
+		$this->_admin_page_title .= $this->_learn_more_about_pricing_link();
471
+		$this->_search_btn_label = esc_html__('Default Prices', 'event_espresso');
472
+		$this->display_admin_list_table_page_with_sidebar();
473
+	}
474
+
475
+
476
+	/**
477
+	 * retrieve data for Prices List table
478
+	 *
479
+	 * @param int  $per_page how many prices displayed per page
480
+	 * @param bool $count    return the count or objects
481
+	 * @param bool $trashed  whether the current view is of the trash can - eww yuck!
482
+	 * @return EE_Soft_Delete_Base_Class[]|int int = count || array of price objects
483
+	 * @throws EE_Error
484
+	 * @throws ReflectionException
485
+	 */
486
+	public function get_prices_overview_data(int $per_page = 10, bool $count = false, bool $trashed = false)
487
+	{
488
+		// start with an empty array
489
+		$event_pricing = [];
490
+
491
+		require_once(PRICING_ADMIN . 'Prices_List_Table.class.php');
492
+
493
+		$orderby = $this->request->getRequestParam('orderby', '');
494
+		$order   = $this->request->getRequestParam('order', 'ASC');
495
+
496
+		switch ($orderby) {
497
+			case 'name':
498
+				$orderby = ['PRC_name' => $order];
499
+				break;
500
+			case 'type':
501
+				$orderby = ['Price_Type.PRT_name' => $order];
502
+				break;
503
+			case 'amount':
504
+				$orderby = ['PRC_amount' => $order];
505
+				break;
506
+			default:
507
+				$orderby = ['PRC_order' => $order, 'Price_Type.PRT_order' => $order, 'PRC_ID' => $order];
508
+		}
509
+
510
+		$current_page = $this->request->getRequestParam('paged', 1, DataType::INTEGER);
511
+		$per_page     = $this->request->getRequestParam('perpage', $per_page, DataType::INTEGER);
512
+
513
+		$where = [
514
+			'PRC_is_default' => 1,
515
+			'PRC_deleted'    => $trashed,
516
+		];
517
+
518
+		$offset = ($current_page - 1) * $per_page;
519
+		$limit  = [$offset, $per_page];
520
+
521
+		$search_term = $this->request->getRequestParam('s');
522
+		if ($search_term) {
523
+			$search_term = "%{$search_term}%";
524
+			$where['OR'] = [
525
+				'PRC_name'            => ['LIKE', $search_term],
526
+				'PRC_desc'            => ['LIKE', $search_term],
527
+				'PRC_amount'          => ['LIKE', $search_term],
528
+				'Price_Type.PRT_name' => ['LIKE', $search_term],
529
+			];
530
+		}
531
+
532
+		$query_params = [
533
+			$where,
534
+			'order_by' => $orderby,
535
+			'limit'    => $limit,
536
+			'group_by' => 'PRC_ID',
537
+		];
538
+
539
+		if ($count) {
540
+			return $trashed
541
+				? EEM_Price::instance()->count([$where])
542
+				: EEM_Price::instance()->count_deleted_and_undeleted([$where]);
543
+		}
544
+		return EEM_Price::instance()->get_all_deleted_and_undeleted($query_params);
545
+	}
546
+
547
+
548
+	/**
549
+	 * @return void
550
+	 * @throws EE_Error
551
+	 * @throws ReflectionException
552
+	 */
553
+	protected function _edit_price_details()
554
+	{
555
+		// grab price ID
556
+		$PRC_ID = $this->request->getRequestParam('id', 0, DataType::INTEGER);
557
+		// change page title based on request action
558
+		switch ($this->_req_action) {
559
+			case 'add_new_price':
560
+				$this->_admin_page_title = esc_html__('Add New Price', 'event_espresso');
561
+				break;
562
+			case 'edit_price':
563
+				$this->_admin_page_title = esc_html__('Edit Price', 'event_espresso');
564
+				break;
565
+			default:
566
+				$this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action));
567
+		}
568
+		// add PRC_ID to title if editing
569
+		$this->_admin_page_title = $PRC_ID ? $this->_admin_page_title . ' # ' . $PRC_ID : $this->_admin_page_title;
570
+
571
+		if ($PRC_ID) {
572
+			$price                    = EEM_Price::instance()->get_one_by_ID($PRC_ID);
573
+			$additional_hidden_fields = [
574
+				'PRC_ID' => ['type' => 'hidden', 'value' => $PRC_ID],
575
+			];
576
+			$this->_set_add_edit_form_tags('update_price', $additional_hidden_fields);
577
+		} else {
578
+			$price = EEM_Price::instance()->get_new_price();
579
+			$this->_set_add_edit_form_tags('insert_price');
580
+		}
581
+
582
+		if (! $price instanceof EE_Price) {
583
+			throw new RuntimeException(
584
+				sprintf(
585
+					esc_html__(
586
+						'A valid Price could not be retrieved from the database with ID: %1$s',
587
+						'event_espresso'
588
+					),
589
+					$PRC_ID
590
+				)
591
+			);
592
+		}
593
+
594
+		$this->_template_args['PRC_ID'] = $PRC_ID;
595
+		$this->_template_args['price']  = $price;
596
+
597
+		$default_base_price = $price->type_obj() && $price->type_obj()->base_type() === 1;
598
+
599
+		$this->_template_args['default_base_price'] = $default_base_price;
600
+
601
+		// get price types
602
+		$price_types = EEM_Price_Type::instance()->get_all([['PBT_ID' => ['!=', 1]]]);
603
+		if (empty($price_types)) {
604
+			$msg = esc_html__(
605
+				'You have no price types defined. Please add a price type before adding a price.',
606
+				'event_espresso'
607
+			);
608
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
609
+			$this->display_admin_page_with_sidebar();
610
+		}
611
+		$attributes       = [];
612
+		$price_type_names = [];
613
+		$attributes[]     = 'id="PRT_ID"';
614
+		if ($default_base_price) {
615
+			$attributes[]       = 'disabled="disabled"';
616
+			$price_type_names[] = ['id' => 1, 'text' => esc_html__('Base Price', 'event_espresso')];
617
+		}
618
+		foreach ($price_types as $type) {
619
+			$price_type_names[] = ['id' => $type->ID(), 'text' => $type->name()];
620
+		}
621
+		$this->_template_args['attributes']  = implode(' ', $attributes);
622
+		$this->_template_args['price_types'] = $price_type_names;
623
+
624
+		$this->_template_args['learn_more_about_pricing_link'] = $this->_learn_more_about_pricing_link();
625
+		$this->_template_args['admin_page_content']            = $this->_edit_price_details_meta_box();
626
+
627
+		$this->_set_publish_post_box_vars('id', $PRC_ID, '', '', true);
628
+		// the details template wrapper
629
+		$this->display_admin_page_with_sidebar();
630
+	}
631
+
632
+
633
+	/**
634
+	 *
635
+	 * @return string
636
+	 */
637
+	public function _edit_price_details_meta_box(): string
638
+	{
639
+		return EEH_Template::display_template(
640
+			PRICING_TEMPLATE_PATH . 'pricing_details_main_meta_box.template.php',
641
+			$this->_template_args,
642
+			true
643
+		);
644
+	}
645
+
646
+
647
+	/**
648
+	 * @return array
649
+	 * @throws EE_Error
650
+	 * @throws ReflectionException
651
+	 */
652
+	protected function set_price_column_values(): array
653
+	{
654
+		$PRC_order = 0;
655
+		$PRT_ID    = $this->request->getRequestParam('PRT_ID', 0, DataType::INTEGER);
656
+		if ($PRT_ID) {
657
+			/** @var EE_Price_Type $price_type */
658
+			$price_type = EEM_Price_Type::instance()->get_one_by_ID($PRT_ID);
659
+			if ($price_type instanceof EE_Price_Type) {
660
+				$PRC_order = $price_type->order();
661
+			}
662
+		}
663
+		return [
664
+			'PRT_ID'         => $PRT_ID,
665
+			'PRC_amount'     => $this->request->getRequestParam('PRC_amount', 0, DataType::FLOAT),
666
+			'PRC_name'       => $this->request->getRequestParam('PRC_name'),
667
+			'PRC_desc'       => $this->request->getRequestParam('PRC_desc'),
668
+			'PRC_is_default' => 1,
669
+			'PRC_overrides'  => null,
670
+			'PRC_order'      => $PRC_order,
671
+			'PRC_deleted'    => 0,
672
+			'PRC_parent'     => 0,
673
+		];
674
+	}
675
+
676
+
677
+	/**
678
+	 * @param bool $insert - whether to insert or update
679
+	 * @return void
680
+	 * @throws EE_Error
681
+	 * @throws ReflectionException
682
+	 */
683
+	protected function _insert_or_update_price(bool $insert = false)
684
+	{
685
+		// why be so pessimistic ???  : (
686
+		$updated = 0;
687
+
688
+		$set_column_values = $this->set_price_column_values();
689
+		// is this a new Price ?
690
+		if ($insert) {
691
+			// run the insert
692
+			$PRC_ID = EEM_Price::instance()->insert($set_column_values);
693
+			if ($PRC_ID) {
694
+				// make sure this new price modifier is attached to the ticket but ONLY if it is not a tax type
695
+				$price = EEM_price::instance()->get_one_by_ID($PRC_ID);
696
+				if (
697
+					$price instanceof EE_Price
698
+					&& $price->type_obj() instanceof EE_Price_type
699
+					&& $price->type_obj()->base_type() !== EEM_Price_Type::base_type_tax
700
+				) {
701
+					$ticket = EEM_Ticket::instance()->get_one_by_ID(1);
702
+					$ticket->_add_relation_to($price, 'Price');
703
+					$ticket->save();
704
+				}
705
+				$updated = 1;
706
+			}
707
+			$action_desc = 'created';
708
+		} else {
709
+			$PRC_ID = $this->request->getRequestParam('PRC_ID', 0, DataType::INTEGER);
710
+			// run the update
711
+			$where_cols_n_values = ['PRC_ID' => $PRC_ID];
712
+			$updated             = EEM_Price::instance()->update($set_column_values, [$where_cols_n_values]);
713
+
714
+			$price = EEM_Price::instance()->get_one_by_ID($PRC_ID);
715
+			if ($price instanceof EE_Price && $price->type_obj()->base_type() !== EEM_Price_Type::base_type_tax) {
716
+				// if this is $PRC_ID == 1,
717
+				// then we need to update the default ticket attached to this price so the TKT_price value is updated.
718
+				if ($PRC_ID === 1) {
719
+					$ticket = $price->get_first_related('Ticket');
720
+					if ($ticket) {
721
+						$ticket->set('TKT_price', $price->get('PRC_amount'));
722
+						$ticket->set('TKT_name', $price->get('PRC_name'));
723
+						$ticket->set('TKT_description', $price->get('PRC_desc'));
724
+						$ticket->save();
725
+					}
726
+				} else {
727
+					// we make sure this price is attached to base ticket. but ONLY if it's not a tax ticket type.
728
+					$ticket = EEM_Ticket::instance()->get_one_by_ID(1);
729
+					if ($ticket instanceof EE_Ticket) {
730
+						$ticket->_add_relation_to($PRC_ID, 'Price');
731
+						$ticket->save();
732
+					}
733
+				}
734
+			}
735
+
736
+			$action_desc = 'updated';
737
+		}
738
+
739
+		$query_args = ['action' => 'edit_price', 'id' => $PRC_ID];
740
+
741
+		$this->_redirect_after_action($updated, 'Prices', $action_desc, $query_args);
742
+	}
743
+
744
+
745
+	/**
746
+	 * @param bool $trash - whether to move item to trash (TRUE) or restore it (FALSE)
747
+	 * @return void
748
+	 * @throws EE_Error
749
+	 */
750
+	protected function _trash_or_restore_price($trash = true)
751
+	{
752
+		$entity_model = EEM_Price::instance();
753
+		$action       = $trash ? EE_Admin_List_Table::ACTION_TRASH : EE_Admin_List_Table::ACTION_RESTORE;
754
+		$result       = $this->trashRestoreDeleteEntities(
755
+			$entity_model,
756
+			'id',
757
+			$action,
758
+			'PRC_deleted',
759
+			[$this, 'adjustTicketRelations']
760
+		);
761
+
762
+		if ($result) {
763
+			$msg = $trash
764
+				? esc_html(
765
+					_n(
766
+						'The Price has been trashed',
767
+						'The Prices have been trashed',
768
+						$result,
769
+						'event_espresso'
770
+					)
771
+				)
772
+				: esc_html(
773
+					_n(
774
+						'The Price has been restored',
775
+						'The Prices have been restored',
776
+						$result,
777
+						'event_espresso'
778
+					)
779
+				);
780
+			EE_Error::add_success($msg);
781
+		}
782
+
783
+		$this->_redirect_after_action(
784
+			$result,
785
+			_n('Price', 'Prices', $result, 'event_espresso'),
786
+			$trash ? 'trashed' : 'restored',
787
+			['action' => 'default'],
788
+			true
789
+		);
790
+	}
791
+
792
+
793
+	/**
794
+	 * @param EEM_Base   $entity_model
795
+	 * @param int|string $entity_ID
796
+	 * @param string     $action
797
+	 * @param int        $result
798
+	 * @throws EE_Error
799
+	 * @throws ReflectionException
800
+	 * @since 4.10.30.p
801
+	 */
802
+	public function adjustTicketRelations(
803
+		EEM_Base $entity_model,
804
+		$entity_ID,
805
+		string $action,
806
+		int $result
807
+	) {
808
+		if (! $entity_ID || (float) $result < 1) {
809
+			return;
810
+		}
811
+
812
+		$entity = $entity_model->get_one_by_ID($entity_ID);
813
+		if (! $entity instanceof EE_Price || $entity->type_obj()->base_type() === EEM_Price_Type::base_type_tax) {
814
+			return;
815
+		}
816
+
817
+		// get default tickets for updating
818
+		$default_tickets = EEM_Ticket::instance()->get_all_default_tickets();
819
+		foreach ($default_tickets as $default_ticket) {
820
+			if (! $default_ticket instanceof EE_Ticket) {
821
+				continue;
822
+			}
823
+			switch ($action) {
824
+				case EE_Admin_List_Table::ACTION_DELETE:
825
+				case EE_Admin_List_Table::ACTION_TRASH:
826
+					// if trashing then remove relations to base default ticket.
827
+					$default_ticket->_remove_relation_to($entity_ID, 'Price');
828
+					break;
829
+				case EE_Admin_List_Table::ACTION_RESTORE:
830
+					// if restoring then add back to base default ticket
831
+					$default_ticket->_add_relation_to($entity_ID, 'Price');
832
+					break;
833
+			}
834
+			$default_ticket->save();
835
+		}
836
+	}
837
+
838
+
839
+	/**
840
+	 * @return void
841
+	 * @throws EE_Error
842
+	 * @throws ReflectionException
843
+	 */
844
+	protected function _delete_price()
845
+	{
846
+		$entity_model = EEM_Price::instance();
847
+		$deleted      = $this->trashRestoreDeleteEntities($entity_model, 'id');
848
+		$entity       = $entity_model->item_name($deleted);
849
+		$this->_redirect_after_action(
850
+			$deleted,
851
+			$entity,
852
+			'deleted',
853
+			['action' => 'default']
854
+		);
855
+	}
856
+
857
+
858
+	/**
859
+	 * @throws EE_Error
860
+	 * @throws ReflectionException
861
+	 */
862
+	public function update_price_order()
863
+	{
864
+		// grab our row IDs
865
+		$row_ids = $this->request->getRequestParam('row_ids', '');
866
+		$row_ids = explode(',', rtrim($row_ids, ','));
867
+
868
+		$all_updated = true;
869
+		foreach ($row_ids as $i => $row_id) {
870
+			// Update the prices when re-ordering
871
+			$fields_n_values = ['PRC_order' => $i + 1];
872
+			$query_params    = [['PRC_ID' => absint($row_id)]];
873
+			// any failure will toggle $all_updated to false
874
+			$all_updated = $row_id && EEM_Price::instance()->update($fields_n_values, $query_params) !== false
875
+				? $all_updated
876
+				: false;
877
+		}
878
+		$success = $all_updated
879
+			? esc_html__('Price order was updated successfully.', 'event_espresso')
880
+			: false;
881
+		$errors  = ! $all_updated
882
+			? esc_html__('An error occurred. The price order was not updated.', 'event_espresso')
883
+			: false;
884
+
885
+		echo wp_json_encode(['return_data' => false, 'success' => $success, 'errors' => $errors]);
886
+		die();
887
+	}
888
+
889
+
890
+	/******************************************************************************************************************
891 891
      ***********************************************  TICKET PRICE TYPES  *********************************************
892 892
      ******************************************************************************************************************/
893 893
 
894 894
 
895
-    /**
896
-     * generates HTML for main Prices Admin page
897
-     *
898
-     * @return void
899
-     * @throws EE_Error
900
-     */
901
-    protected function _price_types_overview_list_table()
902
-    {
903
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
904
-            'add_new_price_type',
905
-            'add_type',
906
-            [],
907
-            'add-new-h2'
908
-        );
909
-        $this->_admin_page_title .= $this->_learn_more_about_pricing_link();
910
-        $this->_search_btn_label = esc_html__('Price Types', 'event_espresso');
911
-        $this->display_admin_list_table_page_with_sidebar();
912
-    }
913
-
914
-
915
-    /**
916
-     * retrieve data for Price Types List table
917
-     *
918
-     * @param int  $per_page how many prices displayed per page
919
-     * @param bool $count    return the count or objects
920
-     * @param bool $trashed  whether the current view is of the trash can - eww yuck!
921
-     * @return EE_Soft_Delete_Base_Class[]|int int = count || array of price objects
922
-     * @throws EE_Error
923
-     * @throws ReflectionException
924
-     */
925
-    public function get_price_types_overview_data(int $per_page = 10, bool $count = false, bool $trashed = false)
926
-    {
927
-        // start with an empty array
928
-        require_once(PRICING_ADMIN . 'Price_Types_List_Table.class.php');
929
-
930
-        $orderby = $this->request->getRequestParam('orderby', '');
931
-        $order   = $this->request->getRequestParam('order', 'ASC');
932
-
933
-        switch ($orderby) {
934
-            case 'name':
935
-                $orderby = ['PRT_name' => $order];
936
-                break;
937
-            default:
938
-                $orderby = ['PRT_order' => $order];
939
-        }
940
-
941
-        $current_page = $this->request->getRequestParam('paged', 1, DataType::INTEGER);
942
-        $per_page     = $this->request->getRequestParam('perpage', $per_page, DataType::INTEGER);
943
-
944
-        $offset = ($current_page - 1) * $per_page;
945
-        $limit  = [$offset, $per_page];
946
-
947
-        $where = ['PRT_deleted' => $trashed, 'PBT_ID' => ['!=', 1]];
948
-
949
-        $search_term = $this->request->getRequestParam('s');
950
-        if ($search_term) {
951
-            $where['OR'] = [
952
-                'PRT_name' => ['LIKE', "%{$search_term}%"],
953
-            ];
954
-        }
955
-        $query_params = [
956
-            $where,
957
-            'order_by' => $orderby,
958
-            'limit'    => $limit,
959
-        ];
960
-        return $count
961
-            ? EEM_Price_Type::instance()->count_deleted_and_undeleted($query_params)
962
-            : EEM_Price_Type::instance()->get_all_deleted_and_undeleted($query_params);
963
-    }
964
-
965
-
966
-    /**
967
-     * _edit_price_type_details
968
-     *
969
-     * @return void
970
-     * @throws EE_Error
971
-     * @throws ReflectionException
972
-     */
973
-    protected function _edit_price_type_details()
974
-    {
975
-        // grab price type ID
976
-        $PRT_ID = $this->request->getRequestParam('id', 0, DataType::INTEGER);
977
-        // change page title based on request action
978
-        switch ($this->_req_action) {
979
-            case 'add_new_price_type':
980
-                $this->_admin_page_title = esc_html__('Add New Price Type', 'event_espresso');
981
-                break;
982
-            case 'edit_price_type':
983
-                $this->_admin_page_title = esc_html__('Edit Price Type', 'event_espresso');
984
-                break;
985
-            default:
986
-                $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action));
987
-        }
988
-        // add PRT_ID to title if editing
989
-        $this->_admin_page_title = $PRT_ID ? $this->_admin_page_title . ' # ' . $PRT_ID : $this->_admin_page_title;
990
-
991
-        if ($PRT_ID) {
992
-            $price_type               = EEM_Price_Type::instance()->get_one_by_ID($PRT_ID);
993
-            $additional_hidden_fields = ['PRT_ID' => ['type' => 'hidden', 'value' => $PRT_ID]];
994
-            $this->_set_add_edit_form_tags('update_price_type', $additional_hidden_fields);
995
-        } else {
996
-            $price_type = EEM_Price_Type::instance()->get_new_price_type();
997
-            $this->_set_add_edit_form_tags('insert_price_type');
998
-        }
999
-
1000
-        if (! $price_type instanceof EE_Price_Type) {
1001
-            throw new RuntimeException(
1002
-                sprintf(
1003
-                    esc_html__(
1004
-                        'A valid Price Type could not be retrieved from the database with ID: %1$s',
1005
-                        'event_espresso'
1006
-                    ),
1007
-                    $PRT_ID
1008
-                )
1009
-            );
1010
-        }
1011
-
1012
-        $this->_template_args['PRT_ID']     = $PRT_ID;
1013
-        $this->_template_args['price_type'] = $price_type;
1014
-
1015
-        $base_types    = EEM_Price_Type::instance()->get_base_types();
1016
-        $select_values = [];
1017
-        foreach ($base_types as $ref => $text) {
1018
-            if ($ref == EEM_Price_Type::base_type_base_price) {
1019
-                // do not allow creation of base_type_base_prices because that's a system only base type.
1020
-                continue;
1021
-            }
1022
-            $select_values[] = ['id' => $ref, 'text' => $text];
1023
-        }
1024
-
1025
-        $this->_template_args['base_type_select'] = EEH_Form_Fields::select_input(
1026
-            'base_type',
1027
-            $select_values,
1028
-            $price_type->base_type(),
1029
-            'id="price-type-base-type-slct"'
1030
-        );
1031
-
1032
-        $this->_template_args['learn_more_about_pricing_link'] = $this->_learn_more_about_pricing_link();
1033
-        $this->_template_args['admin_page_content']            = $this->_edit_price_type_details_meta_box();
1034
-
1035
-        $redirect_URL = add_query_arg(['action' => 'price_types'], $this->_admin_base_url);
1036
-        $this->_set_publish_post_box_vars('id', $PRT_ID, false, $redirect_URL, true);
1037
-        // the details template wrapper
1038
-        $this->display_admin_page_with_sidebar();
1039
-    }
1040
-
1041
-
1042
-    /**
1043
-     * _edit_price_type_details_meta_box
1044
-     *
1045
-     * @return string
1046
-     */
1047
-    public function _edit_price_type_details_meta_box(): string
1048
-    {
1049
-        return EEH_Template::display_template(
1050
-            PRICING_TEMPLATE_PATH . 'pricing_type_details_main_meta_box.template.php',
1051
-            $this->_template_args,
1052
-            true
1053
-        );
1054
-    }
1055
-
1056
-
1057
-    /**
1058
-     * @return array
1059
-     */
1060
-    protected function set_price_type_column_values(): array
1061
-    {
1062
-        $base_type  = $this->request->getRequestParam(
1063
-            'base_type',
1064
-            EEM_Price_Type::base_type_base_price,
1065
-            DataType::INTEGER
1066
-        );
1067
-        $is_percent = $this->request->getRequestParam('PRT_is_percent', 0, DataType::INTEGER);
1068
-        $order      = $this->request->getRequestParam('PRT_order', 0, DataType::INTEGER);
1069
-        switch ($base_type) {
1070
-            case EEM_Price_Type::base_type_base_price:
1071
-                $is_percent = 0;
1072
-                $order      = 0;
1073
-                break;
1074
-
1075
-            case EEM_Price_Type::base_type_discount:
1076
-            case EEM_Price_Type::base_type_surcharge:
1077
-                break;
1078
-
1079
-            case EEM_Price_Type::base_type_tax:
1080
-                $is_percent = 1;
1081
-                break;
1082
-        }
1083
-
1084
-        return [
1085
-            'PBT_ID'         => $base_type,
1086
-            'PRT_name'       => $this->request->getRequestParam('PRT_name', ''),
1087
-            'PRT_is_percent' => $is_percent,
1088
-            'PRT_order'      => $order,
1089
-            'PRT_deleted'    => 0,
1090
-        ];
1091
-    }
1092
-
1093
-
1094
-    /**
1095
-     * @param bool $new_price_type - whether to insert or update
1096
-     * @return void
1097
-     * @throws EE_Error
1098
-     * @throws ReflectionException
1099
-     */
1100
-    protected function _insert_or_update_price_type(bool $new_price_type = false)
1101
-    {
1102
-        // why be so pessimistic ???  : (
1103
-        $success = 0;
1104
-
1105
-        $set_column_values = $this->set_price_type_column_values();
1106
-        // is this a new Price ?
1107
-        if ($new_price_type) {
1108
-            // run the insert
1109
-            if ($PRT_ID = EEM_Price_Type::instance()->insert($set_column_values)) {
1110
-                $success = 1;
1111
-            }
1112
-            $action_desc = 'created';
1113
-        } else {
1114
-            $PRT_ID = $this->request->getRequestParam('PRT_ID', 0, DataType::INTEGER);
1115
-            // run the update
1116
-            $where_cols_n_values = ['PRT_ID' => $PRT_ID];
1117
-            if (EEM_Price_Type::instance()->update($set_column_values, [$where_cols_n_values])) {
1118
-                $success = 1;
1119
-            }
1120
-            $action_desc = 'updated';
1121
-        }
1122
-
1123
-        $query_args = ['action' => 'edit_price_type', 'id' => $PRT_ID];
1124
-        $this->_redirect_after_action($success, 'Price Type', $action_desc, $query_args);
1125
-    }
1126
-
1127
-
1128
-    /**
1129
-     * @param bool $trash - whether to move item to trash (TRUE) or restore it (FALSE)
1130
-     * @return void
1131
-     * @throws EE_Error
1132
-     * @throws ReflectionException
1133
-     */
1134
-    protected function _trash_or_restore_price_type(bool $trash = true)
1135
-    {
1136
-        $entity_model = EEM_Price_Type::instance();
1137
-        $action       = $trash ? EE_Admin_List_Table::ACTION_TRASH : EE_Admin_List_Table::ACTION_RESTORE;
1138
-        $success      = $this->trashRestoreDeleteEntities($entity_model, 'id', $action, 'PRT_deleted');
1139
-        if ($success) {
1140
-            $msg = $trash
1141
-                ? esc_html(
1142
-                    _n(
1143
-                        'The Price Type has been trashed',
1144
-                        'The Price Types have been trashed',
1145
-                        $success,
1146
-                        'event_espresso'
1147
-                    )
1148
-                )
1149
-                : esc_html(
1150
-                    _n(
1151
-                        'The Price Type has been restored',
1152
-                        'The Price Types have been restored',
1153
-                        $success,
1154
-                        'event_espresso'
1155
-                    )
1156
-                );
1157
-            EE_Error::add_success($msg);
1158
-        }
1159
-        $this->_redirect_after_action('', '', '', ['action' => 'price_types'], true);
1160
-    }
1161
-
1162
-
1163
-    /**
1164
-     * @return void
1165
-     * @throws EE_Error
1166
-     * @throws ReflectionException
1167
-     */
1168
-    protected function _delete_price_type()
1169
-    {
1170
-        $entity_model = EEM_Price_Type::instance();
1171
-        $deleted      = $this->trashRestoreDeleteEntities($entity_model, 'id');
1172
-        $this->_redirect_after_action(
1173
-            $deleted,
1174
-            $entity_model->item_name($deleted),
1175
-            'deleted',
1176
-            ['action' => 'price_types']
1177
-        );
1178
-    }
1179
-
1180
-
1181
-    /**
1182
-     * @return string
1183
-     */
1184
-    protected function _learn_more_about_pricing_link(): string
1185
-    {
1186
-        return '
895
+	/**
896
+	 * generates HTML for main Prices Admin page
897
+	 *
898
+	 * @return void
899
+	 * @throws EE_Error
900
+	 */
901
+	protected function _price_types_overview_list_table()
902
+	{
903
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
904
+			'add_new_price_type',
905
+			'add_type',
906
+			[],
907
+			'add-new-h2'
908
+		);
909
+		$this->_admin_page_title .= $this->_learn_more_about_pricing_link();
910
+		$this->_search_btn_label = esc_html__('Price Types', 'event_espresso');
911
+		$this->display_admin_list_table_page_with_sidebar();
912
+	}
913
+
914
+
915
+	/**
916
+	 * retrieve data for Price Types List table
917
+	 *
918
+	 * @param int  $per_page how many prices displayed per page
919
+	 * @param bool $count    return the count or objects
920
+	 * @param bool $trashed  whether the current view is of the trash can - eww yuck!
921
+	 * @return EE_Soft_Delete_Base_Class[]|int int = count || array of price objects
922
+	 * @throws EE_Error
923
+	 * @throws ReflectionException
924
+	 */
925
+	public function get_price_types_overview_data(int $per_page = 10, bool $count = false, bool $trashed = false)
926
+	{
927
+		// start with an empty array
928
+		require_once(PRICING_ADMIN . 'Price_Types_List_Table.class.php');
929
+
930
+		$orderby = $this->request->getRequestParam('orderby', '');
931
+		$order   = $this->request->getRequestParam('order', 'ASC');
932
+
933
+		switch ($orderby) {
934
+			case 'name':
935
+				$orderby = ['PRT_name' => $order];
936
+				break;
937
+			default:
938
+				$orderby = ['PRT_order' => $order];
939
+		}
940
+
941
+		$current_page = $this->request->getRequestParam('paged', 1, DataType::INTEGER);
942
+		$per_page     = $this->request->getRequestParam('perpage', $per_page, DataType::INTEGER);
943
+
944
+		$offset = ($current_page - 1) * $per_page;
945
+		$limit  = [$offset, $per_page];
946
+
947
+		$where = ['PRT_deleted' => $trashed, 'PBT_ID' => ['!=', 1]];
948
+
949
+		$search_term = $this->request->getRequestParam('s');
950
+		if ($search_term) {
951
+			$where['OR'] = [
952
+				'PRT_name' => ['LIKE', "%{$search_term}%"],
953
+			];
954
+		}
955
+		$query_params = [
956
+			$where,
957
+			'order_by' => $orderby,
958
+			'limit'    => $limit,
959
+		];
960
+		return $count
961
+			? EEM_Price_Type::instance()->count_deleted_and_undeleted($query_params)
962
+			: EEM_Price_Type::instance()->get_all_deleted_and_undeleted($query_params);
963
+	}
964
+
965
+
966
+	/**
967
+	 * _edit_price_type_details
968
+	 *
969
+	 * @return void
970
+	 * @throws EE_Error
971
+	 * @throws ReflectionException
972
+	 */
973
+	protected function _edit_price_type_details()
974
+	{
975
+		// grab price type ID
976
+		$PRT_ID = $this->request->getRequestParam('id', 0, DataType::INTEGER);
977
+		// change page title based on request action
978
+		switch ($this->_req_action) {
979
+			case 'add_new_price_type':
980
+				$this->_admin_page_title = esc_html__('Add New Price Type', 'event_espresso');
981
+				break;
982
+			case 'edit_price_type':
983
+				$this->_admin_page_title = esc_html__('Edit Price Type', 'event_espresso');
984
+				break;
985
+			default:
986
+				$this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action));
987
+		}
988
+		// add PRT_ID to title if editing
989
+		$this->_admin_page_title = $PRT_ID ? $this->_admin_page_title . ' # ' . $PRT_ID : $this->_admin_page_title;
990
+
991
+		if ($PRT_ID) {
992
+			$price_type               = EEM_Price_Type::instance()->get_one_by_ID($PRT_ID);
993
+			$additional_hidden_fields = ['PRT_ID' => ['type' => 'hidden', 'value' => $PRT_ID]];
994
+			$this->_set_add_edit_form_tags('update_price_type', $additional_hidden_fields);
995
+		} else {
996
+			$price_type = EEM_Price_Type::instance()->get_new_price_type();
997
+			$this->_set_add_edit_form_tags('insert_price_type');
998
+		}
999
+
1000
+		if (! $price_type instanceof EE_Price_Type) {
1001
+			throw new RuntimeException(
1002
+				sprintf(
1003
+					esc_html__(
1004
+						'A valid Price Type could not be retrieved from the database with ID: %1$s',
1005
+						'event_espresso'
1006
+					),
1007
+					$PRT_ID
1008
+				)
1009
+			);
1010
+		}
1011
+
1012
+		$this->_template_args['PRT_ID']     = $PRT_ID;
1013
+		$this->_template_args['price_type'] = $price_type;
1014
+
1015
+		$base_types    = EEM_Price_Type::instance()->get_base_types();
1016
+		$select_values = [];
1017
+		foreach ($base_types as $ref => $text) {
1018
+			if ($ref == EEM_Price_Type::base_type_base_price) {
1019
+				// do not allow creation of base_type_base_prices because that's a system only base type.
1020
+				continue;
1021
+			}
1022
+			$select_values[] = ['id' => $ref, 'text' => $text];
1023
+		}
1024
+
1025
+		$this->_template_args['base_type_select'] = EEH_Form_Fields::select_input(
1026
+			'base_type',
1027
+			$select_values,
1028
+			$price_type->base_type(),
1029
+			'id="price-type-base-type-slct"'
1030
+		);
1031
+
1032
+		$this->_template_args['learn_more_about_pricing_link'] = $this->_learn_more_about_pricing_link();
1033
+		$this->_template_args['admin_page_content']            = $this->_edit_price_type_details_meta_box();
1034
+
1035
+		$redirect_URL = add_query_arg(['action' => 'price_types'], $this->_admin_base_url);
1036
+		$this->_set_publish_post_box_vars('id', $PRT_ID, false, $redirect_URL, true);
1037
+		// the details template wrapper
1038
+		$this->display_admin_page_with_sidebar();
1039
+	}
1040
+
1041
+
1042
+	/**
1043
+	 * _edit_price_type_details_meta_box
1044
+	 *
1045
+	 * @return string
1046
+	 */
1047
+	public function _edit_price_type_details_meta_box(): string
1048
+	{
1049
+		return EEH_Template::display_template(
1050
+			PRICING_TEMPLATE_PATH . 'pricing_type_details_main_meta_box.template.php',
1051
+			$this->_template_args,
1052
+			true
1053
+		);
1054
+	}
1055
+
1056
+
1057
+	/**
1058
+	 * @return array
1059
+	 */
1060
+	protected function set_price_type_column_values(): array
1061
+	{
1062
+		$base_type  = $this->request->getRequestParam(
1063
+			'base_type',
1064
+			EEM_Price_Type::base_type_base_price,
1065
+			DataType::INTEGER
1066
+		);
1067
+		$is_percent = $this->request->getRequestParam('PRT_is_percent', 0, DataType::INTEGER);
1068
+		$order      = $this->request->getRequestParam('PRT_order', 0, DataType::INTEGER);
1069
+		switch ($base_type) {
1070
+			case EEM_Price_Type::base_type_base_price:
1071
+				$is_percent = 0;
1072
+				$order      = 0;
1073
+				break;
1074
+
1075
+			case EEM_Price_Type::base_type_discount:
1076
+			case EEM_Price_Type::base_type_surcharge:
1077
+				break;
1078
+
1079
+			case EEM_Price_Type::base_type_tax:
1080
+				$is_percent = 1;
1081
+				break;
1082
+		}
1083
+
1084
+		return [
1085
+			'PBT_ID'         => $base_type,
1086
+			'PRT_name'       => $this->request->getRequestParam('PRT_name', ''),
1087
+			'PRT_is_percent' => $is_percent,
1088
+			'PRT_order'      => $order,
1089
+			'PRT_deleted'    => 0,
1090
+		];
1091
+	}
1092
+
1093
+
1094
+	/**
1095
+	 * @param bool $new_price_type - whether to insert or update
1096
+	 * @return void
1097
+	 * @throws EE_Error
1098
+	 * @throws ReflectionException
1099
+	 */
1100
+	protected function _insert_or_update_price_type(bool $new_price_type = false)
1101
+	{
1102
+		// why be so pessimistic ???  : (
1103
+		$success = 0;
1104
+
1105
+		$set_column_values = $this->set_price_type_column_values();
1106
+		// is this a new Price ?
1107
+		if ($new_price_type) {
1108
+			// run the insert
1109
+			if ($PRT_ID = EEM_Price_Type::instance()->insert($set_column_values)) {
1110
+				$success = 1;
1111
+			}
1112
+			$action_desc = 'created';
1113
+		} else {
1114
+			$PRT_ID = $this->request->getRequestParam('PRT_ID', 0, DataType::INTEGER);
1115
+			// run the update
1116
+			$where_cols_n_values = ['PRT_ID' => $PRT_ID];
1117
+			if (EEM_Price_Type::instance()->update($set_column_values, [$where_cols_n_values])) {
1118
+				$success = 1;
1119
+			}
1120
+			$action_desc = 'updated';
1121
+		}
1122
+
1123
+		$query_args = ['action' => 'edit_price_type', 'id' => $PRT_ID];
1124
+		$this->_redirect_after_action($success, 'Price Type', $action_desc, $query_args);
1125
+	}
1126
+
1127
+
1128
+	/**
1129
+	 * @param bool $trash - whether to move item to trash (TRUE) or restore it (FALSE)
1130
+	 * @return void
1131
+	 * @throws EE_Error
1132
+	 * @throws ReflectionException
1133
+	 */
1134
+	protected function _trash_or_restore_price_type(bool $trash = true)
1135
+	{
1136
+		$entity_model = EEM_Price_Type::instance();
1137
+		$action       = $trash ? EE_Admin_List_Table::ACTION_TRASH : EE_Admin_List_Table::ACTION_RESTORE;
1138
+		$success      = $this->trashRestoreDeleteEntities($entity_model, 'id', $action, 'PRT_deleted');
1139
+		if ($success) {
1140
+			$msg = $trash
1141
+				? esc_html(
1142
+					_n(
1143
+						'The Price Type has been trashed',
1144
+						'The Price Types have been trashed',
1145
+						$success,
1146
+						'event_espresso'
1147
+					)
1148
+				)
1149
+				: esc_html(
1150
+					_n(
1151
+						'The Price Type has been restored',
1152
+						'The Price Types have been restored',
1153
+						$success,
1154
+						'event_espresso'
1155
+					)
1156
+				);
1157
+			EE_Error::add_success($msg);
1158
+		}
1159
+		$this->_redirect_after_action('', '', '', ['action' => 'price_types'], true);
1160
+	}
1161
+
1162
+
1163
+	/**
1164
+	 * @return void
1165
+	 * @throws EE_Error
1166
+	 * @throws ReflectionException
1167
+	 */
1168
+	protected function _delete_price_type()
1169
+	{
1170
+		$entity_model = EEM_Price_Type::instance();
1171
+		$deleted      = $this->trashRestoreDeleteEntities($entity_model, 'id');
1172
+		$this->_redirect_after_action(
1173
+			$deleted,
1174
+			$entity_model->item_name($deleted),
1175
+			'deleted',
1176
+			['action' => 'price_types']
1177
+		);
1178
+	}
1179
+
1180
+
1181
+	/**
1182
+	 * @return string
1183
+	 */
1184
+	protected function _learn_more_about_pricing_link(): string
1185
+	{
1186
+		return '
1187 1187
             <a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >
1188 1188
                 ' . esc_html__('learn more about how pricing works', 'event_espresso') . '
1189 1189
             </a>';
1190
-    }
1191
-
1192
-
1193
-    /**
1194
-     * @throws EE_Error
1195
-     */
1196
-    protected function _tax_settings()
1197
-    {
1198
-        $this->_set_add_edit_form_tags('update_tax_settings');
1199
-        $this->_set_publish_post_box_vars();
1200
-        $this->_template_args['admin_page_content'] = $this->tax_settings_form()->get_html();
1201
-        $this->display_admin_page_with_sidebar();
1202
-    }
1203
-
1204
-
1205
-    /**
1206
-     * @return EE_Form_Section_Proper
1207
-     * @throws EE_Error
1208
-     */
1209
-    protected function tax_settings_form(): EE_Form_Section_Proper
1210
-    {
1211
-        $tax_settings = EE_Config::instance()->tax_settings;
1212
-        return new EE_Form_Section_Proper(
1213
-            [
1214
-                'name'            => 'tax_settings_form',
1215
-                'html_id'         => 'tax_settings_form',
1216
-                'html_class'      => 'padding',
1217
-                'layout_strategy' => new EE_Div_Per_Section_Layout(),
1218
-                'subsections'     => apply_filters(
1219
-                    'FHEE__Pricing_Admin_Page__tax_settings_form__form_subsections',
1220
-                    [
1221
-                        'tax_settings' => new EE_Form_Section_Proper(
1222
-                            [
1223
-                                'name'            => 'tax_settings_tbl',
1224
-                                'html_id'         => 'tax_settings_tbl',
1225
-                                'html_class'      => 'form-table',
1226
-                                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1227
-                                'subsections'     => [
1228
-                                    'prices_displayed_including_taxes' => new EE_Yes_No_Input(
1229
-                                        [
1230
-                                            'html_label_text'         => esc_html__(
1231
-                                                'Show Prices With Taxes Included?',
1232
-                                                'event_espresso'
1233
-                                            ),
1234
-                                            'html_help_text'          => esc_html__(
1235
-                                                'Indicates whether or not to display prices with the taxes included',
1236
-                                                'event_espresso'
1237
-                                            ),
1238
-                                            'default'                 => $tax_settings->prices_displayed_including_taxes
1239
-                                                                         ?? true,
1240
-                                            'display_html_label_text' => false,
1241
-                                        ]
1242
-                                    ),
1243
-                                ],
1244
-                            ]
1245
-                        ),
1246
-                    ]
1247
-                ),
1248
-            ]
1249
-        );
1250
-    }
1251
-
1252
-
1253
-    /**
1254
-     * _update_tax_settings
1255
-     *
1256
-     * @return void
1257
-     * @throws EE_Error
1258
-     * @throws ReflectionException
1259
-     * @since 4.9.13
1260
-     */
1261
-    public function _update_tax_settings()
1262
-    {
1263
-        $tax_settings = EE_Config::instance()->tax_settings;
1264
-        if (! $tax_settings instanceof EE_Tax_Config) {
1265
-            $tax_settings = new EE_Tax_Config();
1266
-        }
1267
-        try {
1268
-            $tax_form = $this->tax_settings_form();
1269
-            // check for form submission
1270
-            if ($tax_form->was_submitted()) {
1271
-                // capture form data
1272
-                $tax_form->receive_form_submission();
1273
-                // validate form data
1274
-                if ($tax_form->is_valid()) {
1275
-                    // grab validated data from form
1276
-                    $valid_data = $tax_form->valid_data();
1277
-                    // set data on config
1278
-                    $tax_settings->prices_displayed_including_taxes =
1279
-                        $valid_data['tax_settings']['prices_displayed_including_taxes'];
1280
-                } else {
1281
-                    if ($tax_form->submission_error_message() !== '') {
1282
-                        EE_Error::add_error(
1283
-                            $tax_form->submission_error_message(),
1284
-                            __FILE__,
1285
-                            __FUNCTION__,
1286
-                            __LINE__
1287
-                        );
1288
-                    }
1289
-                }
1290
-            }
1291
-        } catch (EE_Error $e) {
1292
-            EE_Error::add_error($e->get_error(), __FILE__, __FUNCTION__, __LINE__);
1293
-        }
1294
-
1295
-        $what    = 'Tax Settings';
1296
-        $success = $this->_update_espresso_configuration(
1297
-            $what,
1298
-            $tax_settings,
1299
-            __FILE__,
1300
-            __FUNCTION__,
1301
-            __LINE__
1302
-        );
1303
-        $this->_redirect_after_action($success, $what, 'updated', ['action' => 'tax_settings']);
1304
-    }
1190
+	}
1191
+
1192
+
1193
+	/**
1194
+	 * @throws EE_Error
1195
+	 */
1196
+	protected function _tax_settings()
1197
+	{
1198
+		$this->_set_add_edit_form_tags('update_tax_settings');
1199
+		$this->_set_publish_post_box_vars();
1200
+		$this->_template_args['admin_page_content'] = $this->tax_settings_form()->get_html();
1201
+		$this->display_admin_page_with_sidebar();
1202
+	}
1203
+
1204
+
1205
+	/**
1206
+	 * @return EE_Form_Section_Proper
1207
+	 * @throws EE_Error
1208
+	 */
1209
+	protected function tax_settings_form(): EE_Form_Section_Proper
1210
+	{
1211
+		$tax_settings = EE_Config::instance()->tax_settings;
1212
+		return new EE_Form_Section_Proper(
1213
+			[
1214
+				'name'            => 'tax_settings_form',
1215
+				'html_id'         => 'tax_settings_form',
1216
+				'html_class'      => 'padding',
1217
+				'layout_strategy' => new EE_Div_Per_Section_Layout(),
1218
+				'subsections'     => apply_filters(
1219
+					'FHEE__Pricing_Admin_Page__tax_settings_form__form_subsections',
1220
+					[
1221
+						'tax_settings' => new EE_Form_Section_Proper(
1222
+							[
1223
+								'name'            => 'tax_settings_tbl',
1224
+								'html_id'         => 'tax_settings_tbl',
1225
+								'html_class'      => 'form-table',
1226
+								'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1227
+								'subsections'     => [
1228
+									'prices_displayed_including_taxes' => new EE_Yes_No_Input(
1229
+										[
1230
+											'html_label_text'         => esc_html__(
1231
+												'Show Prices With Taxes Included?',
1232
+												'event_espresso'
1233
+											),
1234
+											'html_help_text'          => esc_html__(
1235
+												'Indicates whether or not to display prices with the taxes included',
1236
+												'event_espresso'
1237
+											),
1238
+											'default'                 => $tax_settings->prices_displayed_including_taxes
1239
+																		 ?? true,
1240
+											'display_html_label_text' => false,
1241
+										]
1242
+									),
1243
+								],
1244
+							]
1245
+						),
1246
+					]
1247
+				),
1248
+			]
1249
+		);
1250
+	}
1251
+
1252
+
1253
+	/**
1254
+	 * _update_tax_settings
1255
+	 *
1256
+	 * @return void
1257
+	 * @throws EE_Error
1258
+	 * @throws ReflectionException
1259
+	 * @since 4.9.13
1260
+	 */
1261
+	public function _update_tax_settings()
1262
+	{
1263
+		$tax_settings = EE_Config::instance()->tax_settings;
1264
+		if (! $tax_settings instanceof EE_Tax_Config) {
1265
+			$tax_settings = new EE_Tax_Config();
1266
+		}
1267
+		try {
1268
+			$tax_form = $this->tax_settings_form();
1269
+			// check for form submission
1270
+			if ($tax_form->was_submitted()) {
1271
+				// capture form data
1272
+				$tax_form->receive_form_submission();
1273
+				// validate form data
1274
+				if ($tax_form->is_valid()) {
1275
+					// grab validated data from form
1276
+					$valid_data = $tax_form->valid_data();
1277
+					// set data on config
1278
+					$tax_settings->prices_displayed_including_taxes =
1279
+						$valid_data['tax_settings']['prices_displayed_including_taxes'];
1280
+				} else {
1281
+					if ($tax_form->submission_error_message() !== '') {
1282
+						EE_Error::add_error(
1283
+							$tax_form->submission_error_message(),
1284
+							__FILE__,
1285
+							__FUNCTION__,
1286
+							__LINE__
1287
+						);
1288
+					}
1289
+				}
1290
+			}
1291
+		} catch (EE_Error $e) {
1292
+			EE_Error::add_error($e->get_error(), __FILE__, __FUNCTION__, __LINE__);
1293
+		}
1294
+
1295
+		$what    = 'Tax Settings';
1296
+		$success = $this->_update_espresso_configuration(
1297
+			$what,
1298
+			$tax_settings,
1299
+			__FILE__,
1300
+			__FUNCTION__,
1301
+			__LINE__
1302
+		);
1303
+		$this->_redirect_after_action($success, $what, 'updated', ['action' => 'tax_settings']);
1304
+	}
1305 1305
 }
Please login to merge, or discard this patch.
caffeinated/modules/event_single_caff/EED_Event_Single_Caff.module.php 1 patch
Indentation   +226 added lines, -226 removed lines patch added patch discarded remove patch
@@ -24,230 +24,230 @@
 block discarded – undo
24 24
  */
25 25
 class EED_Event_Single_Caff extends EED_Event_Single
26 26
 {
27
-    /**
28
-     * @return EED_Event_Single_Caff
29
-     */
30
-    public static function instance()
31
-    {
32
-        return parent::get_instance(__CLASS__);
33
-    }
34
-
35
-
36
-    /**
37
-     *    set_hooks - for hooking into EE Core, other modules, etc
38
-     *
39
-     * @access    public
40
-     * @return    void
41
-     */
42
-    public static function set_hooks()
43
-    {
44
-    }
45
-
46
-    /**
47
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
48
-     *
49
-     * @access    public
50
-     * @return    void
51
-     */
52
-    public static function set_hooks_admin()
53
-    {
54
-        self::setDefinitions();
55
-        add_action(
56
-            'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_events__template_settings',
57
-            array('EED_Event_Single_Caff', 'load_scripts_styles'),
58
-            10
59
-        );
60
-        add_action(
61
-            'AHEE__template_settings__template__before_settings_form',
62
-            array('EED_Event_Single_Caff', 'template_settings_form'),
63
-            10
64
-        );
65
-        add_filter(
66
-            'FHEE__General_Settings_Admin_Page__update_template_settings__data',
67
-            array('EED_Event_Single_Caff', 'update_template_settings'),
68
-            10,
69
-            2
70
-        );
71
-        // AJAX
72
-        add_action(
73
-            'wp_ajax_espresso_update_event_single_order',
74
-            array('EED_Event_Single_Caff', 'update_event_single_order')
75
-        );
76
-    }
77
-
78
-
79
-    public static function load_scripts_styles()
80
-    {
81
-        add_action('admin_enqueue_scripts', array('EED_Event_Single_Caff', 'enqueue_scripts_styles'), 10);
82
-    }
83
-
84
-
85
-    public static function enqueue_scripts_styles()
86
-    {
87
-        wp_register_style(
88
-            'eed-event-single-sortable',
89
-            EVENT_SINGLE_CAFF_ASSETS_URL . 'eed_event_single_sortable.css',
90
-            array(),
91
-            EVENT_ESPRESSO_VERSION
92
-        );
93
-        wp_enqueue_style('eed-event-single-sortable');
94
-        wp_register_script(
95
-            'eed-event-single-sortable',
96
-            EVENT_SINGLE_CAFF_ASSETS_URL . 'eed_event_single_sortable.js',
97
-            array('espresso_core', 'jquery-ui-sortable'),
98
-            EVENT_ESPRESSO_VERSION,
99
-            true
100
-        );
101
-        wp_enqueue_script('eed-event-single-sortable');
102
-    }
103
-
104
-
105
-    /**
106
-     * Set constants only if they haven't been set yet.
107
-     */
108
-    public static function setDefinitions()
109
-    {
110
-        if (! defined('EVENT_SINGLE_CAFF_TEMPLATES_PATH')) {
111
-            define('EVENT_SINGLE_CAFF_TEMPLATES_PATH', plugin_dir_path(__FILE__) . 'templates/');
112
-            define('EVENT_SINGLE_CAFF_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/');
113
-        }
114
-    }
115
-
116
-
117
-    /**
118
-     *    template_settings_form
119
-     *
120
-     * @access    public
121
-     * @static
122
-     * @return    void
123
-     */
124
-    public static function template_settings_form()
125
-    {
126
-        $config = EE_Registry::instance()->CFG->template_settings;
127
-        $config = isset($config->EED_Event_Single) && $config->EED_Event_Single instanceof EE_Event_Single_Config
128
-            ? $config->EED_Event_Single : new EE_Event_Single_Config();
129
-        $config->use_sortable_display_order = isset($config->use_sortable_display_order)
130
-            ? $config->use_sortable_display_order : false;
131
-        $config = apply_filters('FHEE__EED_Event_Single__template_settings_form__event_list_config', $config);
132
-
133
-        $event_single_order_array = array();
134
-        $event_single_order_array[ $config->display_order_tickets ] = 'tickets';
135
-        $event_single_order_array[ $config->display_order_datetimes ] = 'datetimes';
136
-        $event_single_order_array[ $config->display_order_event ] = 'event';
137
-        $event_single_order_array[ $config->display_order_venue ] = 'venue';
138
-        // get template parts
139
-        $template_parts = EED_Event_Single::instance()->initialize_template_parts($config);
140
-        // convert to array so that we can add more properties
141
-        $config = get_object_vars($config);
142
-        $config['event_single_display_order'] = $template_parts->generate_sortable_list_of_template_parts(
143
-            'event-single-sortable-js',
144
-            '',
145
-            'single-sortable-li single-sortable-js'
146
-        );
147
-        EEH_Template::display_template(
148
-            EVENT_SINGLE_CAFF_TEMPLATES_PATH . 'admin-event-single-settings.template.php',
149
-            $config
150
-        );
151
-    }
152
-
153
-
154
-    /**
155
-     * update_template_settings
156
-     *
157
-     * @param EE_Template_Config $CFG
158
-     * @param array              $REQ
159
-     * @return EE_Template_Config
160
-     */
161
-    public static function update_template_settings(EE_Template_Config $CFG, $REQ)
162
-    {
163
-        if (! $CFG->EED_Event_Single instanceof EE_Event_Single_Config) {
164
-            $CFG->EED_Event_Single = new EE_Event_Single_Config();
165
-        }
166
-        $display_order_event = $CFG->EED_Event_Single->display_order_event !== null
167
-            ? $CFG->EED_Event_Single->display_order_event
168
-            : EED_Event_Single::EVENT_DETAILS_PRIORITY;
169
-        $display_order_datetimes = $CFG->EED_Event_Single->display_order_datetimes !== null
170
-            ? $CFG->EED_Event_Single->display_order_datetimes
171
-            : EED_Event_Single::EVENT_DATETIMES_PRIORITY;
172
-        $display_order_tickets = $CFG->EED_Event_Single->display_order_tickets !== null
173
-            ? $CFG->EED_Event_Single->display_order_tickets
174
-            : EED_Event_Single::EVENT_TICKETS_PRIORITY;
175
-        $display_order_venue = $CFG->EED_Event_Single->display_order_venue !== null
176
-            ? $CFG->EED_Event_Single->display_order_venue
177
-            : EED_Event_Single::EVENT_VENUES_PRIORITY;
178
-        $CFG->EED_Event_Single = new EE_Event_Single_Config();
179
-        $CFG->EED_Event_Single->display_status_banner_single = ! empty($REQ['display_status_banner_single'])
180
-                                                               && $REQ['display_status_banner_single'];
181
-        $CFG->EED_Event_Single->display_venue = ! empty($REQ['display_venue']) && $REQ['display_venue'];
182
-        $CFG->EED_Event_Single->use_sortable_display_order = ! empty($REQ['EED_Events_Single_use_sortable_display_order'])
183
-            ? absint($REQ['EED_Events_Single_use_sortable_display_order'])
184
-            : 0;
185
-        $CFG->EED_Event_Single->display_order_event = $CFG->EED_Event_Single->use_sortable_display_order
186
-            ? $display_order_event
187
-            : EED_Event_Single::EVENT_DETAILS_PRIORITY;
188
-        $CFG->EED_Event_Single->display_order_datetimes = $CFG->EED_Event_Single->use_sortable_display_order
189
-            ? $display_order_datetimes
190
-            : EED_Event_Single::EVENT_DATETIMES_PRIORITY;
191
-        $CFG->EED_Event_Single->display_order_tickets = $CFG->EED_Event_Single->use_sortable_display_order
192
-            ? $display_order_tickets
193
-            : EED_Event_Single::EVENT_TICKETS_PRIORITY;
194
-        $CFG->EED_Event_Single->display_order_venue = $CFG->EED_Event_Single->use_sortable_display_order
195
-            ? $display_order_venue
196
-            : EED_Event_Single::EVENT_VENUES_PRIORITY;
197
-        do_action('AHEE__EED_Event_Single__update_template_settings__after_update', $CFG, $REQ);
198
-        return $CFG;
199
-    }
200
-
201
-
202
-    /**
203
-     * update_event_single_order
204
-     *
205
-     * @access    public
206
-     * @return    void
207
-     */
208
-    public static function update_event_single_order()
209
-    {
210
-        if (
211
-            ! isset(EE_Registry::instance()->CFG->template_settings->EED_Event_Single)
212
-            || ! EE_Registry::instance()->CFG->template_settings->EED_Event_Single instanceof EE_Event_Single_Config
213
-        ) {
214
-            EE_Registry::instance()->CFG->template_settings->EED_Event_Single = new EE_Event_Single_Config();
215
-        }
216
-        $config_saved = false;
217
-        $template_parts = EED_Event_Single_Caff::getRequest()->getRequestParam('elements');
218
-        if (! empty($template_parts)) {
219
-            $template_parts = explode(',', trim($template_parts, ','));
220
-            foreach ($template_parts as $key => $template_part) {
221
-                $template_part = "display_order_$template_part";
222
-                $priority = ($key * 10) + EED_Event_Single::EVENT_DETAILS_PRIORITY;
223
-                EE_Registry::instance()->CFG->template_settings->EED_Event_Single->{$template_part} = $priority;
224
-                do_action("AHEE__EED_Event_Single__update_event_single_order__$template_part", $priority);
225
-            }
226
-            $config_saved = EE_Registry::instance()->CFG->update_espresso_config(false, false);
227
-        }
228
-        if ($config_saved) {
229
-            EE_Error::add_success(esc_html__('Display Order has been successfully updated.', 'event_espresso'));
230
-        } else {
231
-            EE_Error::add_error(
232
-                esc_html__('Display Order was not updated.', 'event_espresso'),
233
-                __FILE__,
234
-                __FUNCTION__,
235
-                __LINE__
236
-            );
237
-        }
238
-        echo wp_json_encode(EE_Error::get_notices(false));
239
-        exit();
240
-    }
241
-
242
-
243
-    /**
244
-     *    run - initial module setup
245
-     *
246
-     * @access    public
247
-     * @param WP $WP
248
-     * @return    void
249
-     */
250
-    public function run($WP)
251
-    {
252
-    }
27
+	/**
28
+	 * @return EED_Event_Single_Caff
29
+	 */
30
+	public static function instance()
31
+	{
32
+		return parent::get_instance(__CLASS__);
33
+	}
34
+
35
+
36
+	/**
37
+	 *    set_hooks - for hooking into EE Core, other modules, etc
38
+	 *
39
+	 * @access    public
40
+	 * @return    void
41
+	 */
42
+	public static function set_hooks()
43
+	{
44
+	}
45
+
46
+	/**
47
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
48
+	 *
49
+	 * @access    public
50
+	 * @return    void
51
+	 */
52
+	public static function set_hooks_admin()
53
+	{
54
+		self::setDefinitions();
55
+		add_action(
56
+			'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_events__template_settings',
57
+			array('EED_Event_Single_Caff', 'load_scripts_styles'),
58
+			10
59
+		);
60
+		add_action(
61
+			'AHEE__template_settings__template__before_settings_form',
62
+			array('EED_Event_Single_Caff', 'template_settings_form'),
63
+			10
64
+		);
65
+		add_filter(
66
+			'FHEE__General_Settings_Admin_Page__update_template_settings__data',
67
+			array('EED_Event_Single_Caff', 'update_template_settings'),
68
+			10,
69
+			2
70
+		);
71
+		// AJAX
72
+		add_action(
73
+			'wp_ajax_espresso_update_event_single_order',
74
+			array('EED_Event_Single_Caff', 'update_event_single_order')
75
+		);
76
+	}
77
+
78
+
79
+	public static function load_scripts_styles()
80
+	{
81
+		add_action('admin_enqueue_scripts', array('EED_Event_Single_Caff', 'enqueue_scripts_styles'), 10);
82
+	}
83
+
84
+
85
+	public static function enqueue_scripts_styles()
86
+	{
87
+		wp_register_style(
88
+			'eed-event-single-sortable',
89
+			EVENT_SINGLE_CAFF_ASSETS_URL . 'eed_event_single_sortable.css',
90
+			array(),
91
+			EVENT_ESPRESSO_VERSION
92
+		);
93
+		wp_enqueue_style('eed-event-single-sortable');
94
+		wp_register_script(
95
+			'eed-event-single-sortable',
96
+			EVENT_SINGLE_CAFF_ASSETS_URL . 'eed_event_single_sortable.js',
97
+			array('espresso_core', 'jquery-ui-sortable'),
98
+			EVENT_ESPRESSO_VERSION,
99
+			true
100
+		);
101
+		wp_enqueue_script('eed-event-single-sortable');
102
+	}
103
+
104
+
105
+	/**
106
+	 * Set constants only if they haven't been set yet.
107
+	 */
108
+	public static function setDefinitions()
109
+	{
110
+		if (! defined('EVENT_SINGLE_CAFF_TEMPLATES_PATH')) {
111
+			define('EVENT_SINGLE_CAFF_TEMPLATES_PATH', plugin_dir_path(__FILE__) . 'templates/');
112
+			define('EVENT_SINGLE_CAFF_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/');
113
+		}
114
+	}
115
+
116
+
117
+	/**
118
+	 *    template_settings_form
119
+	 *
120
+	 * @access    public
121
+	 * @static
122
+	 * @return    void
123
+	 */
124
+	public static function template_settings_form()
125
+	{
126
+		$config = EE_Registry::instance()->CFG->template_settings;
127
+		$config = isset($config->EED_Event_Single) && $config->EED_Event_Single instanceof EE_Event_Single_Config
128
+			? $config->EED_Event_Single : new EE_Event_Single_Config();
129
+		$config->use_sortable_display_order = isset($config->use_sortable_display_order)
130
+			? $config->use_sortable_display_order : false;
131
+		$config = apply_filters('FHEE__EED_Event_Single__template_settings_form__event_list_config', $config);
132
+
133
+		$event_single_order_array = array();
134
+		$event_single_order_array[ $config->display_order_tickets ] = 'tickets';
135
+		$event_single_order_array[ $config->display_order_datetimes ] = 'datetimes';
136
+		$event_single_order_array[ $config->display_order_event ] = 'event';
137
+		$event_single_order_array[ $config->display_order_venue ] = 'venue';
138
+		// get template parts
139
+		$template_parts = EED_Event_Single::instance()->initialize_template_parts($config);
140
+		// convert to array so that we can add more properties
141
+		$config = get_object_vars($config);
142
+		$config['event_single_display_order'] = $template_parts->generate_sortable_list_of_template_parts(
143
+			'event-single-sortable-js',
144
+			'',
145
+			'single-sortable-li single-sortable-js'
146
+		);
147
+		EEH_Template::display_template(
148
+			EVENT_SINGLE_CAFF_TEMPLATES_PATH . 'admin-event-single-settings.template.php',
149
+			$config
150
+		);
151
+	}
152
+
153
+
154
+	/**
155
+	 * update_template_settings
156
+	 *
157
+	 * @param EE_Template_Config $CFG
158
+	 * @param array              $REQ
159
+	 * @return EE_Template_Config
160
+	 */
161
+	public static function update_template_settings(EE_Template_Config $CFG, $REQ)
162
+	{
163
+		if (! $CFG->EED_Event_Single instanceof EE_Event_Single_Config) {
164
+			$CFG->EED_Event_Single = new EE_Event_Single_Config();
165
+		}
166
+		$display_order_event = $CFG->EED_Event_Single->display_order_event !== null
167
+			? $CFG->EED_Event_Single->display_order_event
168
+			: EED_Event_Single::EVENT_DETAILS_PRIORITY;
169
+		$display_order_datetimes = $CFG->EED_Event_Single->display_order_datetimes !== null
170
+			? $CFG->EED_Event_Single->display_order_datetimes
171
+			: EED_Event_Single::EVENT_DATETIMES_PRIORITY;
172
+		$display_order_tickets = $CFG->EED_Event_Single->display_order_tickets !== null
173
+			? $CFG->EED_Event_Single->display_order_tickets
174
+			: EED_Event_Single::EVENT_TICKETS_PRIORITY;
175
+		$display_order_venue = $CFG->EED_Event_Single->display_order_venue !== null
176
+			? $CFG->EED_Event_Single->display_order_venue
177
+			: EED_Event_Single::EVENT_VENUES_PRIORITY;
178
+		$CFG->EED_Event_Single = new EE_Event_Single_Config();
179
+		$CFG->EED_Event_Single->display_status_banner_single = ! empty($REQ['display_status_banner_single'])
180
+															   && $REQ['display_status_banner_single'];
181
+		$CFG->EED_Event_Single->display_venue = ! empty($REQ['display_venue']) && $REQ['display_venue'];
182
+		$CFG->EED_Event_Single->use_sortable_display_order = ! empty($REQ['EED_Events_Single_use_sortable_display_order'])
183
+			? absint($REQ['EED_Events_Single_use_sortable_display_order'])
184
+			: 0;
185
+		$CFG->EED_Event_Single->display_order_event = $CFG->EED_Event_Single->use_sortable_display_order
186
+			? $display_order_event
187
+			: EED_Event_Single::EVENT_DETAILS_PRIORITY;
188
+		$CFG->EED_Event_Single->display_order_datetimes = $CFG->EED_Event_Single->use_sortable_display_order
189
+			? $display_order_datetimes
190
+			: EED_Event_Single::EVENT_DATETIMES_PRIORITY;
191
+		$CFG->EED_Event_Single->display_order_tickets = $CFG->EED_Event_Single->use_sortable_display_order
192
+			? $display_order_tickets
193
+			: EED_Event_Single::EVENT_TICKETS_PRIORITY;
194
+		$CFG->EED_Event_Single->display_order_venue = $CFG->EED_Event_Single->use_sortable_display_order
195
+			? $display_order_venue
196
+			: EED_Event_Single::EVENT_VENUES_PRIORITY;
197
+		do_action('AHEE__EED_Event_Single__update_template_settings__after_update', $CFG, $REQ);
198
+		return $CFG;
199
+	}
200
+
201
+
202
+	/**
203
+	 * update_event_single_order
204
+	 *
205
+	 * @access    public
206
+	 * @return    void
207
+	 */
208
+	public static function update_event_single_order()
209
+	{
210
+		if (
211
+			! isset(EE_Registry::instance()->CFG->template_settings->EED_Event_Single)
212
+			|| ! EE_Registry::instance()->CFG->template_settings->EED_Event_Single instanceof EE_Event_Single_Config
213
+		) {
214
+			EE_Registry::instance()->CFG->template_settings->EED_Event_Single = new EE_Event_Single_Config();
215
+		}
216
+		$config_saved = false;
217
+		$template_parts = EED_Event_Single_Caff::getRequest()->getRequestParam('elements');
218
+		if (! empty($template_parts)) {
219
+			$template_parts = explode(',', trim($template_parts, ','));
220
+			foreach ($template_parts as $key => $template_part) {
221
+				$template_part = "display_order_$template_part";
222
+				$priority = ($key * 10) + EED_Event_Single::EVENT_DETAILS_PRIORITY;
223
+				EE_Registry::instance()->CFG->template_settings->EED_Event_Single->{$template_part} = $priority;
224
+				do_action("AHEE__EED_Event_Single__update_event_single_order__$template_part", $priority);
225
+			}
226
+			$config_saved = EE_Registry::instance()->CFG->update_espresso_config(false, false);
227
+		}
228
+		if ($config_saved) {
229
+			EE_Error::add_success(esc_html__('Display Order has been successfully updated.', 'event_espresso'));
230
+		} else {
231
+			EE_Error::add_error(
232
+				esc_html__('Display Order was not updated.', 'event_espresso'),
233
+				__FILE__,
234
+				__FUNCTION__,
235
+				__LINE__
236
+			);
237
+		}
238
+		echo wp_json_encode(EE_Error::get_notices(false));
239
+		exit();
240
+	}
241
+
242
+
243
+	/**
244
+	 *    run - initial module setup
245
+	 *
246
+	 * @access    public
247
+	 * @param WP $WP
248
+	 * @return    void
249
+	 */
250
+	public function run($WP)
251
+	{
252
+	}
253 253
 }
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -37,124 +37,124 @@
 block discarded – undo
37 37
  * @since           4.0
38 38
  */
39 39
 if (function_exists('espresso_version')) {
40
-    if (! function_exists('espresso_duplicate_plugin_error')) {
41
-        /**
42
-         *    espresso_duplicate_plugin_error
43
-         *    displays if more than one version of EE is activated at the same time.
44
-         */
45
-        function espresso_duplicate_plugin_error()
46
-        {
47
-            ?>
40
+	if (! function_exists('espresso_duplicate_plugin_error')) {
41
+		/**
42
+		 *    espresso_duplicate_plugin_error
43
+		 *    displays if more than one version of EE is activated at the same time.
44
+		 */
45
+		function espresso_duplicate_plugin_error()
46
+		{
47
+			?>
48 48
             <div class="error">
49 49
                 <p>
50 50
                     <?php
51
-                    echo esc_html__(
52
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
53
-                        'event_espresso'
54
-                    ); ?>
51
+					echo esc_html__(
52
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
53
+						'event_espresso'
54
+					); ?>
55 55
                 </p>
56 56
             </div>
57 57
             <?php
58
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
59
-        }
60
-    }
61
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
58
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
59
+		}
60
+	}
61
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
62 62
 } else {
63
-    define('EE_MIN_PHP_VER_REQUIRED', '7.4.0');
64
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
65
-        /**
66
-         * espresso_minimum_php_version_error
67
-         *
68
-         * @return void
69
-         */
70
-        function espresso_minimum_php_version_error()
71
-        {
72
-            ?>
63
+	define('EE_MIN_PHP_VER_REQUIRED', '7.4.0');
64
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
65
+		/**
66
+		 * espresso_minimum_php_version_error
67
+		 *
68
+		 * @return void
69
+		 */
70
+		function espresso_minimum_php_version_error()
71
+		{
72
+			?>
73 73
             <div class="error">
74 74
                 <p>
75 75
                     <?php
76
-                    printf(
77
-                        esc_html__(
78
-                            'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
79
-                            'event_espresso'
80
-                        ),
81
-                        EE_MIN_PHP_VER_REQUIRED,
82
-                        PHP_VERSION,
83
-                        '<br/>',
84
-                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
85
-                    );
86
-                    ?>
76
+					printf(
77
+						esc_html__(
78
+							'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
79
+							'event_espresso'
80
+						),
81
+						EE_MIN_PHP_VER_REQUIRED,
82
+						PHP_VERSION,
83
+						'<br/>',
84
+						'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
85
+					);
86
+					?>
87 87
                 </p>
88 88
             </div>
89 89
             <?php
90
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
91
-        }
90
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
91
+		}
92 92
 
93
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
94
-    } else {
95
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
93
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
94
+	} else {
95
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
96 96
 
97
-        require_once __DIR__ . '/vendor/autoload.php';
98
-        require_once __DIR__ . '/vendor/wp-graphql/wp-graphql/wp-graphql.php';
97
+		require_once __DIR__ . '/vendor/autoload.php';
98
+		require_once __DIR__ . '/vendor/wp-graphql/wp-graphql/wp-graphql.php';
99 99
 
100
-        /**
101
-         * espresso_version
102
-         * Returns the plugin version
103
-         *
104
-         * @return string
105
-         */
106
-        function espresso_version()
107
-        {
108
-            return apply_filters('FHEE__espresso__espresso_version', '5.0.4.rc.000');
109
-        }
100
+		/**
101
+		 * espresso_version
102
+		 * Returns the plugin version
103
+		 *
104
+		 * @return string
105
+		 */
106
+		function espresso_version()
107
+		{
108
+			return apply_filters('FHEE__espresso__espresso_version', '5.0.4.rc.000');
109
+		}
110 110
 
111
-        /**
112
-         * espresso_plugin_activation
113
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
114
-         */
115
-        function espresso_plugin_activation()
116
-        {
117
-            update_option('ee_espresso_activation', true);
118
-            update_option('event-espresso-core_allow_tracking', 'no');
119
-            update_option('event-espresso-core_tracking_notice', 'hide');
120
-            // Run WP GraphQL activation callback
121
-            graphql_activation_callback();
122
-        }
111
+		/**
112
+		 * espresso_plugin_activation
113
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
114
+		 */
115
+		function espresso_plugin_activation()
116
+		{
117
+			update_option('ee_espresso_activation', true);
118
+			update_option('event-espresso-core_allow_tracking', 'no');
119
+			update_option('event-espresso-core_tracking_notice', 'hide');
120
+			// Run WP GraphQL activation callback
121
+			graphql_activation_callback();
122
+		}
123 123
 
124
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
124
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
125 125
 
126
-        /**
127
-         * espresso_plugin_deactivation
128
-         */
129
-        function espresso_plugin_deactivation()
130
-        {
131
-            // Run WP GraphQL deactivation callback
132
-            graphql_deactivation_callback();
133
-            delete_option('event-espresso-core_allow_tracking');
134
-            delete_option('event-espresso-core_tracking_notice');
135
-        }
136
-        register_deactivation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_deactivation');
126
+		/**
127
+		 * espresso_plugin_deactivation
128
+		 */
129
+		function espresso_plugin_deactivation()
130
+		{
131
+			// Run WP GraphQL deactivation callback
132
+			graphql_deactivation_callback();
133
+			delete_option('event-espresso-core_allow_tracking');
134
+			delete_option('event-espresso-core_tracking_notice');
135
+		}
136
+		register_deactivation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_deactivation');
137 137
 
138
-        require_once __DIR__ . '/core/bootstrap_espresso.php';
139
-        bootstrap_espresso();
140
-    }
138
+		require_once __DIR__ . '/core/bootstrap_espresso.php';
139
+		bootstrap_espresso();
140
+	}
141 141
 }
142 142
 
143 143
 if (! function_exists('espresso_deactivate_plugin')) {
144
-    /**
145
-     *    deactivate_plugin
146
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
147
-     *
148
-     * @access public
149
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
150
-     * @return    void
151
-     */
152
-    function espresso_deactivate_plugin($plugin_basename = '')
153
-    {
154
-        if (! function_exists('deactivate_plugins')) {
155
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
156
-        }
157
-        unset($_GET['activate'], $_REQUEST['activate']);
158
-        deactivate_plugins($plugin_basename);
159
-    }
144
+	/**
145
+	 *    deactivate_plugin
146
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
147
+	 *
148
+	 * @access public
149
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
150
+	 * @return    void
151
+	 */
152
+	function espresso_deactivate_plugin($plugin_basename = '')
153
+	{
154
+		if (! function_exists('deactivate_plugins')) {
155
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
156
+		}
157
+		unset($_GET['activate'], $_REQUEST['activate']);
158
+		deactivate_plugins($plugin_basename);
159
+	}
160 160
 }
Please login to merge, or discard this patch.
core/EE_Maintenance_Mode.core.php 2 patches
Indentation   +355 added lines, -355 removed lines patch added patch discarded remove patch
@@ -16,361 +16,361 @@
 block discarded – undo
16 16
  */
17 17
 class EE_Maintenance_Mode implements ResettableInterface
18 18
 {
19
-    /**
20
-     * constants available to client code for interpreting the values of EE_Maintenance_Mode::level().
21
-     * level_0_not_in_maintenance means the site is NOT in maintenance mode (so everything's normal)
22
-     */
23
-    const level_0_not_in_maintenance = 0;
24
-
25
-    /**
26
-     * level_1_frontend_only_maintenance means that the site's frontend EE code should be completely disabled
27
-     * but the admin backend should be running as normal. Maybe an admin can view the frontend though
28
-     */
29
-    const level_1_frontend_only_maintenance = 1;
30
-
31
-    /**
32
-     * level_2_complete_maintenance means the frontend AND EE backend code are disabled. The only system running
33
-     * is the maintenance mode stuff, which will require users to update all addons, and then finish running all
34
-     * migration scripts before taking the site out of maintenance mode
35
-     */
36
-    const level_2_complete_maintenance = 2;
37
-
38
-    /**
39
-     * the name of the option which stores the current level of maintenance mode
40
-     */
41
-    const option_name_maintenance_mode = 'ee_maintenance_mode';
42
-
43
-
44
-    /**
45
-     * @var EE_Maintenance_Mode $_instance
46
-     */
47
-    private static $_instance;
48
-
49
-    /**
50
-     * @var EE_Registry $EE
51
-     */
52
-    protected $EE;
53
-
54
-
55
-    /**
56
-     * @singleton method used to instantiate class object
57
-     * @return EE_Maintenance_Mode
58
-     */
59
-    public static function instance()
60
-    {
61
-        // check if class object is instantiated
62
-        if (! self::$_instance instanceof EE_Maintenance_Mode) {
63
-            self::$_instance = new self();
64
-        }
65
-        return self::$_instance;
66
-    }
67
-
68
-
69
-    /**
70
-     * Resets maintenance mode (mostly just re-checks whether we should be in maintenance mode)
71
-     *
72
-     * @return EE_Maintenance_Mode
73
-     * @throws EE_Error
74
-     */
75
-    public static function reset()
76
-    {
77
-        self::instance()->set_maintenance_mode_if_db_old();
78
-        return self::instance();
79
-    }
80
-
81
-
82
-    /**
83
-     *private constructor to prevent direct creation
84
-     */
85
-    private function __construct()
86
-    {
87
-        // if M-Mode level 2 is engaged, we still need basic assets loaded
88
-        add_action('wp_enqueue_scripts', [$this, 'load_assets_required_for_m_mode']);
89
-        // shut 'er down for maintenance ?
90
-        add_filter('the_content', [$this, 'the_content'], 2);
91
-        // redirect ee menus to maintenance page
92
-        add_action('admin_page_access_denied', [$this, 'redirect_to_maintenance']);
93
-        // add powered by EE msg
94
-        add_action('shutdown', [$this, 'display_maintenance_mode_notice'], 10);
95
-    }
96
-
97
-
98
-    /**
99
-     * retrieves the maintenance mode option value from the db
100
-     *
101
-     * @return int
102
-     */
103
-    public function real_level()
104
-    {
105
-        return (int) get_option(self::option_name_maintenance_mode, EE_Maintenance_Mode::level_0_not_in_maintenance);
106
-    }
107
-
108
-
109
-    /**
110
-     * Returns whether the models reportedly are able to run queries or not
111
-     * (ie, if the system thinks their tables are present and up-to-date).
112
-     *
113
-     * @return boolean
114
-     */
115
-    public function models_can_query()
116
-    {
117
-        return $this->real_level() !== EE_Maintenance_Mode::level_2_complete_maintenance;
118
-    }
119
-
120
-
121
-    /**
122
-     * Determines whether we're in maintenance mode and what level. However, while the site
123
-     * is in level 1 maintenance, and an admin visits the frontend, this function makes it appear
124
-     * to them as if teh site isn't in maintenance mode.
125
-     * EE_Maintenance_Mode::level_0_not_in_maintenance => not in maintenance mode (in normal mode)
126
-     * EE_Maintenance_Mode::level_1_frontend_only_maintenance=> frontend-only maintenance mode
127
-     * EE_Maintenance_Mode::level_2_complete_maintenance => frontend and backend maintenance mode
128
-     *
129
-     * @return int
130
-     */
131
-    public function level()
132
-    {
133
-        $maintenance_mode_level = $this->real_level();
134
-        // if this is an admin request, we'll be honest... except if it's ajax, because that might be from the frontend
135
-        if (
136
-            $maintenance_mode_level === EE_Maintenance_Mode::level_1_frontend_only_maintenance// we're in level 1
137
-            && ((defined('DOING_AJAX') && DOING_AJAX) || ! is_admin()) // on non-ajax frontend requests
138
-            && current_user_can('administrator') // when the user is an admin
139
-        ) {
140
-            $maintenance_mode_level = EE_Maintenance_Mode::level_0_not_in_maintenance;
141
-        }
142
-        return $maintenance_mode_level;
143
-    }
144
-
145
-
146
-    /**
147
-     * Determines if we need to put EE in maintenance mode because the database needs updating
148
-     *
149
-     * @return boolean true if DB is old and maintenance mode was triggered; false otherwise
150
-     * @throws EE_Error
151
-     */
152
-    public function set_maintenance_mode_if_db_old()
153
-    {
154
-        LoaderFactory::getLoader()->getShared('Data_Migration_Manager');
155
-        if (EE_Data_Migration_Manager::instance()->check_for_applicable_data_migration_scripts()) {
156
-            update_option(self::option_name_maintenance_mode, self::level_2_complete_maintenance);
157
-            return true;
158
-        }
159
-        if ($this->level() === self::level_2_complete_maintenance) {
160
-            // we also want to handle the opposite: if the site is mm2, but there aren't any migrations to run
161
-            // then we shouldn't be in mm2. (Maybe an addon got deactivated?)
162
-            update_option(self::option_name_maintenance_mode, self::level_0_not_in_maintenance);
163
-            return false;
164
-        }
165
-        return false;
166
-    }
167
-
168
-
169
-    /**
170
-     * Updates the maintenance level on the site
171
-     *
172
-     * @param int $level
173
-     * @return void
174
-     */
175
-    public function set_maintenance_level($level)
176
-    {
177
-        do_action('AHEE__EE_Maintenance_Mode__set_maintenance_level', $level);
178
-        update_option(self::option_name_maintenance_mode, (int) $level);
179
-    }
180
-
181
-
182
-    /**
183
-     * returns TRUE if M-Mode is engaged and the current request is not for the admin
184
-     *
185
-     * @return bool
186
-     */
187
-    public static function disable_frontend_for_maintenance()
188
-    {
189
-        return (! is_admin() && EE_Maintenance_Mode::instance()->level());
190
-    }
191
-
192
-
193
-    /**
194
-     * @return void
195
-     */
196
-    public function load_assets_required_for_m_mode()
197
-    {
198
-        if (
199
-            $this->real_level() === EE_Maintenance_Mode::level_2_complete_maintenance
200
-            && ! wp_script_is('espresso_core')
201
-        ) {
202
-            wp_register_style(
203
-                'espresso_default',
204
-                EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
205
-                ['dashicons'],
206
-                EVENT_ESPRESSO_VERSION
207
-            );
208
-            wp_enqueue_style('espresso_default');
209
-            wp_register_script(
210
-                'espresso_core',
211
-                EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
212
-                ['jquery'],
213
-                EVENT_ESPRESSO_VERSION,
214
-                true
215
-            );
216
-            wp_enqueue_script('espresso_core');
217
-        }
218
-    }
219
-
220
-
221
-    /**
222
-     * replacement EE CPT template that displays message notifying site visitors
223
-     * that EE has been temporarily placed into maintenance mode
224
-     * does NOT get called on non-EE-CPT requests
225
-     *
226
-     * @return    string
227
-     */
228
-    public static function template_include()
229
-    {
230
-        // shut 'er down for maintenance ? then don't use any of our templates for our endpoints
231
-        return get_template_directory() . '/index.php';
232
-    }
233
-
234
-
235
-    /**
236
-     * displays message notifying site visitors that EE has been temporarily
237
-     * placed into maintenance mode when post_type != EE CPT
238
-     *
239
-     * @param string $the_content
240
-     * @return string
241
-     */
242
-    public function the_content($the_content)
243
-    {
244
-        // check if M-mode is engaged and for EE shortcode
245
-        if ($this->level() && strpos($the_content, '[ESPRESSO_') !== false) {
246
-            // this can eventually be moved to a template, or edited via admin. But for now...
247
-            $the_content = sprintf(
248
-                esc_html__(
249
-                    '%sMaintenance Mode%sEvent Registration has been temporarily closed while system maintenance is being performed. We\'re sorry for any inconveniences this may have caused. Please try back again later.%s',
250
-                    'event_espresso'
251
-                ),
252
-                '<h3>',
253
-                '</h3><p>',
254
-                '</p>'
255
-            );
256
-        }
257
-        return $the_content;
258
-    }
259
-
260
-
261
-    /**
262
-     * displays message on frontend of site notifying admin that EE has been temporarily placed into maintenance mode
263
-     */
264
-    public function display_maintenance_mode_notice()
265
-    {
266
-        /** @var CurrentPage $current_page */
267
-        $current_page = LoaderFactory::getLoader()->getShared(CurrentPage::class);
268
-        // check if M-mode is engaged and for EE shortcode
269
-        if (
270
-            ! (defined('DOING_AJAX') && DOING_AJAX)
271
-            && $this->real_level()
272
-            && ! is_admin()
273
-            && current_user_can('administrator')
274
-            && $current_page->isEspressoPage()
275
-        ) {
276
-            printf(
277
-                esc_html__(
278
-                    '%sclose%sEvent Registration is currently disabled because Event Espresso has been placed into Maintenance Mode. To change Maintenance Mode settings, click here %sEE Maintenance Mode Admin Page%s',
279
-                    'event_espresso'
280
-                ),
281
-                '<div id="ee-m-mode-admin-notice-dv" class="ee-really-important-notice-dv"><a class="close-espresso-notice" title="',
282
-                '"><span class="dashicons dashicons-no"></span></a><p>',
283
-                ' &raquo; <a href="' . add_query_arg(
284
-                    ['page' => 'espresso_maintenance_settings'],
285
-                    admin_url('admin.php')
286
-                ) . '">',
287
-                '</a></p></div>'
288
-            );
289
-        }
290
-    }
291
-    // espresso-notices important-notice ee-attention
292
-
293
-    /**
294
-     * Redirects EE admin menu requests to the maintenance page
295
-     */
296
-    public function redirect_to_maintenance()
297
-    {
298
-        global $pagenow;
299
-        $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
300
-        $page   = $request->getRequestParam('page');
301
-
302
-        if (
303
-            $pagenow == 'admin.php'
304
-            && $page !== 'espresso_maintenance_settings'
305
-            && strpos($page, 'espresso_') !== false
306
-            && $this->real_level() == EE_Maintenance_Mode::level_2_complete_maintenance
307
-        ) {
308
-            EEH_URL::safeRedirectAndExit('admin.php?page=espresso_maintenance_settings');
309
-        }
310
-    }
311
-
312
-
313
-    /**
314
-     * override magic methods
315
-     */
316
-    final public function __destruct()
317
-    {
318
-    }
319
-
320
-
321
-    final public function __call($a, $b)
322
-    {
323
-    }
324
-
325
-
326
-    final public function __get($a)
327
-    {
328
-    }
329
-
330
-
331
-    final public function __set($a, $b)
332
-    {
333
-    }
334
-
335
-
336
-    final public function __isset($a)
337
-    {
338
-    }
339
-
340
-
341
-    final public function __unset($a)
342
-    {
343
-    }
344
-
345
-
346
-    final public function __sleep()
347
-    {
348
-        return [];
349
-    }
350
-
351
-
352
-    final public function __wakeup()
353
-    {
354
-    }
355
-
356
-
357
-    final public function __invoke()
358
-    {
359
-    }
360
-
361
-
362
-    final public static function __set_state($a = null)
363
-    {
364
-        return EE_Maintenance_Mode::instance();
365
-    }
366
-
367
-
368
-    final public function __clone()
369
-    {
370
-    }
19
+	/**
20
+	 * constants available to client code for interpreting the values of EE_Maintenance_Mode::level().
21
+	 * level_0_not_in_maintenance means the site is NOT in maintenance mode (so everything's normal)
22
+	 */
23
+	const level_0_not_in_maintenance = 0;
24
+
25
+	/**
26
+	 * level_1_frontend_only_maintenance means that the site's frontend EE code should be completely disabled
27
+	 * but the admin backend should be running as normal. Maybe an admin can view the frontend though
28
+	 */
29
+	const level_1_frontend_only_maintenance = 1;
30
+
31
+	/**
32
+	 * level_2_complete_maintenance means the frontend AND EE backend code are disabled. The only system running
33
+	 * is the maintenance mode stuff, which will require users to update all addons, and then finish running all
34
+	 * migration scripts before taking the site out of maintenance mode
35
+	 */
36
+	const level_2_complete_maintenance = 2;
37
+
38
+	/**
39
+	 * the name of the option which stores the current level of maintenance mode
40
+	 */
41
+	const option_name_maintenance_mode = 'ee_maintenance_mode';
42
+
43
+
44
+	/**
45
+	 * @var EE_Maintenance_Mode $_instance
46
+	 */
47
+	private static $_instance;
48
+
49
+	/**
50
+	 * @var EE_Registry $EE
51
+	 */
52
+	protected $EE;
53
+
54
+
55
+	/**
56
+	 * @singleton method used to instantiate class object
57
+	 * @return EE_Maintenance_Mode
58
+	 */
59
+	public static function instance()
60
+	{
61
+		// check if class object is instantiated
62
+		if (! self::$_instance instanceof EE_Maintenance_Mode) {
63
+			self::$_instance = new self();
64
+		}
65
+		return self::$_instance;
66
+	}
67
+
68
+
69
+	/**
70
+	 * Resets maintenance mode (mostly just re-checks whether we should be in maintenance mode)
71
+	 *
72
+	 * @return EE_Maintenance_Mode
73
+	 * @throws EE_Error
74
+	 */
75
+	public static function reset()
76
+	{
77
+		self::instance()->set_maintenance_mode_if_db_old();
78
+		return self::instance();
79
+	}
80
+
81
+
82
+	/**
83
+	 *private constructor to prevent direct creation
84
+	 */
85
+	private function __construct()
86
+	{
87
+		// if M-Mode level 2 is engaged, we still need basic assets loaded
88
+		add_action('wp_enqueue_scripts', [$this, 'load_assets_required_for_m_mode']);
89
+		// shut 'er down for maintenance ?
90
+		add_filter('the_content', [$this, 'the_content'], 2);
91
+		// redirect ee menus to maintenance page
92
+		add_action('admin_page_access_denied', [$this, 'redirect_to_maintenance']);
93
+		// add powered by EE msg
94
+		add_action('shutdown', [$this, 'display_maintenance_mode_notice'], 10);
95
+	}
96
+
97
+
98
+	/**
99
+	 * retrieves the maintenance mode option value from the db
100
+	 *
101
+	 * @return int
102
+	 */
103
+	public function real_level()
104
+	{
105
+		return (int) get_option(self::option_name_maintenance_mode, EE_Maintenance_Mode::level_0_not_in_maintenance);
106
+	}
107
+
108
+
109
+	/**
110
+	 * Returns whether the models reportedly are able to run queries or not
111
+	 * (ie, if the system thinks their tables are present and up-to-date).
112
+	 *
113
+	 * @return boolean
114
+	 */
115
+	public function models_can_query()
116
+	{
117
+		return $this->real_level() !== EE_Maintenance_Mode::level_2_complete_maintenance;
118
+	}
119
+
120
+
121
+	/**
122
+	 * Determines whether we're in maintenance mode and what level. However, while the site
123
+	 * is in level 1 maintenance, and an admin visits the frontend, this function makes it appear
124
+	 * to them as if teh site isn't in maintenance mode.
125
+	 * EE_Maintenance_Mode::level_0_not_in_maintenance => not in maintenance mode (in normal mode)
126
+	 * EE_Maintenance_Mode::level_1_frontend_only_maintenance=> frontend-only maintenance mode
127
+	 * EE_Maintenance_Mode::level_2_complete_maintenance => frontend and backend maintenance mode
128
+	 *
129
+	 * @return int
130
+	 */
131
+	public function level()
132
+	{
133
+		$maintenance_mode_level = $this->real_level();
134
+		// if this is an admin request, we'll be honest... except if it's ajax, because that might be from the frontend
135
+		if (
136
+			$maintenance_mode_level === EE_Maintenance_Mode::level_1_frontend_only_maintenance// we're in level 1
137
+			&& ((defined('DOING_AJAX') && DOING_AJAX) || ! is_admin()) // on non-ajax frontend requests
138
+			&& current_user_can('administrator') // when the user is an admin
139
+		) {
140
+			$maintenance_mode_level = EE_Maintenance_Mode::level_0_not_in_maintenance;
141
+		}
142
+		return $maintenance_mode_level;
143
+	}
144
+
145
+
146
+	/**
147
+	 * Determines if we need to put EE in maintenance mode because the database needs updating
148
+	 *
149
+	 * @return boolean true if DB is old and maintenance mode was triggered; false otherwise
150
+	 * @throws EE_Error
151
+	 */
152
+	public function set_maintenance_mode_if_db_old()
153
+	{
154
+		LoaderFactory::getLoader()->getShared('Data_Migration_Manager');
155
+		if (EE_Data_Migration_Manager::instance()->check_for_applicable_data_migration_scripts()) {
156
+			update_option(self::option_name_maintenance_mode, self::level_2_complete_maintenance);
157
+			return true;
158
+		}
159
+		if ($this->level() === self::level_2_complete_maintenance) {
160
+			// we also want to handle the opposite: if the site is mm2, but there aren't any migrations to run
161
+			// then we shouldn't be in mm2. (Maybe an addon got deactivated?)
162
+			update_option(self::option_name_maintenance_mode, self::level_0_not_in_maintenance);
163
+			return false;
164
+		}
165
+		return false;
166
+	}
167
+
168
+
169
+	/**
170
+	 * Updates the maintenance level on the site
171
+	 *
172
+	 * @param int $level
173
+	 * @return void
174
+	 */
175
+	public function set_maintenance_level($level)
176
+	{
177
+		do_action('AHEE__EE_Maintenance_Mode__set_maintenance_level', $level);
178
+		update_option(self::option_name_maintenance_mode, (int) $level);
179
+	}
180
+
181
+
182
+	/**
183
+	 * returns TRUE if M-Mode is engaged and the current request is not for the admin
184
+	 *
185
+	 * @return bool
186
+	 */
187
+	public static function disable_frontend_for_maintenance()
188
+	{
189
+		return (! is_admin() && EE_Maintenance_Mode::instance()->level());
190
+	}
191
+
192
+
193
+	/**
194
+	 * @return void
195
+	 */
196
+	public function load_assets_required_for_m_mode()
197
+	{
198
+		if (
199
+			$this->real_level() === EE_Maintenance_Mode::level_2_complete_maintenance
200
+			&& ! wp_script_is('espresso_core')
201
+		) {
202
+			wp_register_style(
203
+				'espresso_default',
204
+				EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
205
+				['dashicons'],
206
+				EVENT_ESPRESSO_VERSION
207
+			);
208
+			wp_enqueue_style('espresso_default');
209
+			wp_register_script(
210
+				'espresso_core',
211
+				EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
212
+				['jquery'],
213
+				EVENT_ESPRESSO_VERSION,
214
+				true
215
+			);
216
+			wp_enqueue_script('espresso_core');
217
+		}
218
+	}
219
+
220
+
221
+	/**
222
+	 * replacement EE CPT template that displays message notifying site visitors
223
+	 * that EE has been temporarily placed into maintenance mode
224
+	 * does NOT get called on non-EE-CPT requests
225
+	 *
226
+	 * @return    string
227
+	 */
228
+	public static function template_include()
229
+	{
230
+		// shut 'er down for maintenance ? then don't use any of our templates for our endpoints
231
+		return get_template_directory() . '/index.php';
232
+	}
233
+
234
+
235
+	/**
236
+	 * displays message notifying site visitors that EE has been temporarily
237
+	 * placed into maintenance mode when post_type != EE CPT
238
+	 *
239
+	 * @param string $the_content
240
+	 * @return string
241
+	 */
242
+	public function the_content($the_content)
243
+	{
244
+		// check if M-mode is engaged and for EE shortcode
245
+		if ($this->level() && strpos($the_content, '[ESPRESSO_') !== false) {
246
+			// this can eventually be moved to a template, or edited via admin. But for now...
247
+			$the_content = sprintf(
248
+				esc_html__(
249
+					'%sMaintenance Mode%sEvent Registration has been temporarily closed while system maintenance is being performed. We\'re sorry for any inconveniences this may have caused. Please try back again later.%s',
250
+					'event_espresso'
251
+				),
252
+				'<h3>',
253
+				'</h3><p>',
254
+				'</p>'
255
+			);
256
+		}
257
+		return $the_content;
258
+	}
259
+
260
+
261
+	/**
262
+	 * displays message on frontend of site notifying admin that EE has been temporarily placed into maintenance mode
263
+	 */
264
+	public function display_maintenance_mode_notice()
265
+	{
266
+		/** @var CurrentPage $current_page */
267
+		$current_page = LoaderFactory::getLoader()->getShared(CurrentPage::class);
268
+		// check if M-mode is engaged and for EE shortcode
269
+		if (
270
+			! (defined('DOING_AJAX') && DOING_AJAX)
271
+			&& $this->real_level()
272
+			&& ! is_admin()
273
+			&& current_user_can('administrator')
274
+			&& $current_page->isEspressoPage()
275
+		) {
276
+			printf(
277
+				esc_html__(
278
+					'%sclose%sEvent Registration is currently disabled because Event Espresso has been placed into Maintenance Mode. To change Maintenance Mode settings, click here %sEE Maintenance Mode Admin Page%s',
279
+					'event_espresso'
280
+				),
281
+				'<div id="ee-m-mode-admin-notice-dv" class="ee-really-important-notice-dv"><a class="close-espresso-notice" title="',
282
+				'"><span class="dashicons dashicons-no"></span></a><p>',
283
+				' &raquo; <a href="' . add_query_arg(
284
+					['page' => 'espresso_maintenance_settings'],
285
+					admin_url('admin.php')
286
+				) . '">',
287
+				'</a></p></div>'
288
+			);
289
+		}
290
+	}
291
+	// espresso-notices important-notice ee-attention
292
+
293
+	/**
294
+	 * Redirects EE admin menu requests to the maintenance page
295
+	 */
296
+	public function redirect_to_maintenance()
297
+	{
298
+		global $pagenow;
299
+		$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
300
+		$page   = $request->getRequestParam('page');
301
+
302
+		if (
303
+			$pagenow == 'admin.php'
304
+			&& $page !== 'espresso_maintenance_settings'
305
+			&& strpos($page, 'espresso_') !== false
306
+			&& $this->real_level() == EE_Maintenance_Mode::level_2_complete_maintenance
307
+		) {
308
+			EEH_URL::safeRedirectAndExit('admin.php?page=espresso_maintenance_settings');
309
+		}
310
+	}
311
+
312
+
313
+	/**
314
+	 * override magic methods
315
+	 */
316
+	final public function __destruct()
317
+	{
318
+	}
319
+
320
+
321
+	final public function __call($a, $b)
322
+	{
323
+	}
324
+
325
+
326
+	final public function __get($a)
327
+	{
328
+	}
329
+
330
+
331
+	final public function __set($a, $b)
332
+	{
333
+	}
334
+
335
+
336
+	final public function __isset($a)
337
+	{
338
+	}
339
+
340
+
341
+	final public function __unset($a)
342
+	{
343
+	}
344
+
345
+
346
+	final public function __sleep()
347
+	{
348
+		return [];
349
+	}
350
+
351
+
352
+	final public function __wakeup()
353
+	{
354
+	}
355
+
356
+
357
+	final public function __invoke()
358
+	{
359
+	}
360
+
361
+
362
+	final public static function __set_state($a = null)
363
+	{
364
+		return EE_Maintenance_Mode::instance();
365
+	}
366
+
367
+
368
+	final public function __clone()
369
+	{
370
+	}
371 371
 
372 372
 
373
-    final public static function __callStatic($a, $b)
374
-    {
375
-    }
373
+	final public static function __callStatic($a, $b)
374
+	{
375
+	}
376 376
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
     public static function instance()
60 60
     {
61 61
         // check if class object is instantiated
62
-        if (! self::$_instance instanceof EE_Maintenance_Mode) {
62
+        if ( ! self::$_instance instanceof EE_Maintenance_Mode) {
63 63
             self::$_instance = new self();
64 64
         }
65 65
         return self::$_instance;
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
      */
187 187
     public static function disable_frontend_for_maintenance()
188 188
     {
189
-        return (! is_admin() && EE_Maintenance_Mode::instance()->level());
189
+        return ( ! is_admin() && EE_Maintenance_Mode::instance()->level());
190 190
     }
191 191
 
192 192
 
@@ -201,14 +201,14 @@  discard block
 block discarded – undo
201 201
         ) {
202 202
             wp_register_style(
203 203
                 'espresso_default',
204
-                EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
204
+                EE_GLOBAL_ASSETS_URL.'css/espresso_default.css',
205 205
                 ['dashicons'],
206 206
                 EVENT_ESPRESSO_VERSION
207 207
             );
208 208
             wp_enqueue_style('espresso_default');
209 209
             wp_register_script(
210 210
                 'espresso_core',
211
-                EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
211
+                EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js',
212 212
                 ['jquery'],
213 213
                 EVENT_ESPRESSO_VERSION,
214 214
                 true
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
     public static function template_include()
229 229
     {
230 230
         // shut 'er down for maintenance ? then don't use any of our templates for our endpoints
231
-        return get_template_directory() . '/index.php';
231
+        return get_template_directory().'/index.php';
232 232
     }
233 233
 
234 234
 
@@ -280,10 +280,10 @@  discard block
 block discarded – undo
280 280
                 ),
281 281
                 '<div id="ee-m-mode-admin-notice-dv" class="ee-really-important-notice-dv"><a class="close-espresso-notice" title="',
282 282
                 '"><span class="dashicons dashicons-no"></span></a><p>',
283
-                ' &raquo; <a href="' . add_query_arg(
283
+                ' &raquo; <a href="'.add_query_arg(
284 284
                     ['page' => 'espresso_maintenance_settings'],
285 285
                     admin_url('admin.php')
286
-                ) . '">',
286
+                ).'">',
287 287
                 '</a></p></div>'
288 288
             );
289 289
         }
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
     {
298 298
         global $pagenow;
299 299
         $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
300
-        $page   = $request->getRequestParam('page');
300
+        $page = $request->getRequestParam('page');
301 301
 
302 302
         if (
303 303
             $pagenow == 'admin.php'
Please login to merge, or discard this patch.
core/domain/entities/routing/handlers/admin/EspressoLegacyAdmin.php 2 patches
Indentation   +133 added lines, -133 removed lines patch added patch discarded remove patch
@@ -17,143 +17,143 @@
 block discarded – undo
17 17
  */
18 18
 class EspressoLegacyAdmin extends AdminRoute
19 19
 {
20
-    /**
21
-     * @var LegacyAccountingAssetManager $asset_manager
22
-     */
23
-    protected $asset_manager;
20
+	/**
21
+	 * @var LegacyAccountingAssetManager $asset_manager
22
+	 */
23
+	protected $asset_manager;
24 24
 
25 25
 
26
-    /**
27
-     * returns true if the current request matches this route
28
-     *
29
-     * @return bool
30
-     * @since   5.0.0.p
31
-     */
32
-    public function matchesCurrentRequest(): bool
33
-    {
34
-        global $pagenow;
35
-        $page = $this->request->getRequestParam('page');
36
-        return (
37
-                   $pagenow === 'admin.php'
38
-                   || $pagenow === 'admin-ajax.php'
39
-               ) && (
40
-                   $page === 'pricing'
41
-                   || $page === 'mailchimp'
42
-                   || $page === 'eea_barcode_scanner'
43
-                   || str_contains($page, 'espresso')
44
-               ) && parent::matchesCurrentRequest();
45
-    }
26
+	/**
27
+	 * returns true if the current request matches this route
28
+	 *
29
+	 * @return bool
30
+	 * @since   5.0.0.p
31
+	 */
32
+	public function matchesCurrentRequest(): bool
33
+	{
34
+		global $pagenow;
35
+		$page = $this->request->getRequestParam('page');
36
+		return (
37
+				   $pagenow === 'admin.php'
38
+				   || $pagenow === 'admin-ajax.php'
39
+			   ) && (
40
+				   $page === 'pricing'
41
+				   || $page === 'mailchimp'
42
+				   || $page === 'eea_barcode_scanner'
43
+				   || str_contains($page, 'espresso')
44
+			   ) && parent::matchesCurrentRequest();
45
+	}
46 46
 
47 47
 
48
-    /**
49
-     * @since 5.0.0.p
50
-     */
51
-    protected function registerDependencies()
52
-    {
53
-        $asset_manger_dependencies = [
54
-            'EventEspresso\core\domain\Domain'                   => EE_Dependency_Map::load_from_cache,
55
-            'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_new_object,
56
-            'EventEspresso\core\services\assets\Registry'        => EE_Dependency_Map::load_from_cache,
57
-        ];
58
-        $this->dependency_map->registerDependencies(JqueryAssetManager::class, $asset_manger_dependencies);
59
-        $this->dependency_map->registerDependencies(EspressoLegacyAdminAssetManager::class, $asset_manger_dependencies);
60
-        $this->dependency_map->registerDependencies(
61
-            LegacyAccountingAssetManager::class,
62
-            ['EE_Currency_Config' => EE_Dependency_Map::load_from_cache] + $asset_manger_dependencies
63
-        );
64
-        $this->dependency_map->registerDependencies(
65
-            'EE_Admin_Transactions_List_Table',
66
-            [
67
-                null,
68
-                'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache,
69
-            ]
70
-        );
71
-        $this->dependency_map->registerDependencies(
72
-            'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings',
73
-            ['EE_Registration_Config' => EE_Dependency_Map::load_from_cache]
74
-        );
75
-        $this->dependency_map->registerDependencies(
76
-            'EventEspresso\admin_pages\general_settings\OrganizationSettings',
77
-            [
78
-                'EE_Registry'                                             => EE_Dependency_Map::load_from_cache,
79
-                'EE_Organization_Config'                                  => EE_Dependency_Map::load_from_cache,
80
-                'EE_Core_Config'                                          => EE_Dependency_Map::load_from_cache,
81
-                'EE_Network_Core_Config'                                  => EE_Dependency_Map::load_from_cache,
82
-                'EventEspresso\core\services\address\CountrySubRegionDao' => EE_Dependency_Map::load_from_cache,
83
-            ]
84
-        );
85
-        $this->dependency_map->registerDependencies(
86
-            'EventEspresso\core\services\address\CountrySubRegionDao',
87
-            [
88
-                'EEM_State'                                            => EE_Dependency_Map::load_from_cache,
89
-                'EventEspresso\core\services\validators\JsonValidator' => EE_Dependency_Map::load_from_cache
90
-            ]
91
-        );
92
-        $this->dependency_map->registerDependencies(
93
-            'EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder',
94
-            [
95
-                'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
96
-                'EEM_Registration'                            => EE_Dependency_Map::load_from_cache,
97
-                null,
98
-            ]
99
-        );
100
-        $this->dependency_map->registerDependencies(
101
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\AttendeeFilterHeader',
102
-            [
103
-                'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
104
-                'EEM_Attendee'                                => EE_Dependency_Map::load_from_cache,
105
-            ]
106
-        );
107
-        $this->dependency_map->registerDependencies(
108
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\DateFilterHeader',
109
-            [
110
-                'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
111
-                'EEM_Datetime'                                => EE_Dependency_Map::load_from_cache,
112
-            ]
113
-        );
114
-        $this->dependency_map->registerDependencies(
115
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\EventFilterHeader',
116
-            [
117
-                'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
118
-                'EEM_Event'                                   => EE_Dependency_Map::load_from_cache,
119
-            ]
120
-        );
121
-        $this->dependency_map->registerDependencies(
122
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\TicketFilterHeader',
123
-            [
124
-                'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
125
-                'EEM_Ticket'                                  => EE_Dependency_Map::load_from_cache,
126
-            ]
127
-        );
128
-        $this->dependency_map->registerDependencies(
129
-            'EventEspresso\core\services\admin\AdminListTableFilters',
130
-            [
131
-                'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
132
-            ]
133
-        );
134
-    }
48
+	/**
49
+	 * @since 5.0.0.p
50
+	 */
51
+	protected function registerDependencies()
52
+	{
53
+		$asset_manger_dependencies = [
54
+			'EventEspresso\core\domain\Domain'                   => EE_Dependency_Map::load_from_cache,
55
+			'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_new_object,
56
+			'EventEspresso\core\services\assets\Registry'        => EE_Dependency_Map::load_from_cache,
57
+		];
58
+		$this->dependency_map->registerDependencies(JqueryAssetManager::class, $asset_manger_dependencies);
59
+		$this->dependency_map->registerDependencies(EspressoLegacyAdminAssetManager::class, $asset_manger_dependencies);
60
+		$this->dependency_map->registerDependencies(
61
+			LegacyAccountingAssetManager::class,
62
+			['EE_Currency_Config' => EE_Dependency_Map::load_from_cache] + $asset_manger_dependencies
63
+		);
64
+		$this->dependency_map->registerDependencies(
65
+			'EE_Admin_Transactions_List_Table',
66
+			[
67
+				null,
68
+				'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache,
69
+			]
70
+		);
71
+		$this->dependency_map->registerDependencies(
72
+			'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings',
73
+			['EE_Registration_Config' => EE_Dependency_Map::load_from_cache]
74
+		);
75
+		$this->dependency_map->registerDependencies(
76
+			'EventEspresso\admin_pages\general_settings\OrganizationSettings',
77
+			[
78
+				'EE_Registry'                                             => EE_Dependency_Map::load_from_cache,
79
+				'EE_Organization_Config'                                  => EE_Dependency_Map::load_from_cache,
80
+				'EE_Core_Config'                                          => EE_Dependency_Map::load_from_cache,
81
+				'EE_Network_Core_Config'                                  => EE_Dependency_Map::load_from_cache,
82
+				'EventEspresso\core\services\address\CountrySubRegionDao' => EE_Dependency_Map::load_from_cache,
83
+			]
84
+		);
85
+		$this->dependency_map->registerDependencies(
86
+			'EventEspresso\core\services\address\CountrySubRegionDao',
87
+			[
88
+				'EEM_State'                                            => EE_Dependency_Map::load_from_cache,
89
+				'EventEspresso\core\services\validators\JsonValidator' => EE_Dependency_Map::load_from_cache
90
+			]
91
+		);
92
+		$this->dependency_map->registerDependencies(
93
+			'EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder',
94
+			[
95
+				'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
96
+				'EEM_Registration'                            => EE_Dependency_Map::load_from_cache,
97
+				null,
98
+			]
99
+		);
100
+		$this->dependency_map->registerDependencies(
101
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\AttendeeFilterHeader',
102
+			[
103
+				'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
104
+				'EEM_Attendee'                                => EE_Dependency_Map::load_from_cache,
105
+			]
106
+		);
107
+		$this->dependency_map->registerDependencies(
108
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\DateFilterHeader',
109
+			[
110
+				'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
111
+				'EEM_Datetime'                                => EE_Dependency_Map::load_from_cache,
112
+			]
113
+		);
114
+		$this->dependency_map->registerDependencies(
115
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\EventFilterHeader',
116
+			[
117
+				'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
118
+				'EEM_Event'                                   => EE_Dependency_Map::load_from_cache,
119
+			]
120
+		);
121
+		$this->dependency_map->registerDependencies(
122
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\TicketFilterHeader',
123
+			[
124
+				'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
125
+				'EEM_Ticket'                                  => EE_Dependency_Map::load_from_cache,
126
+			]
127
+		);
128
+		$this->dependency_map->registerDependencies(
129
+			'EventEspresso\core\services\admin\AdminListTableFilters',
130
+			[
131
+				'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
132
+			]
133
+		);
134
+	}
135 135
 
136 136
 
137
-    /**
138
-     * implements logic required to run during request
139
-     *
140
-     * @return bool
141
-     * @since   5.0.0.p
142
-     */
143
-    protected function requestHandler(): bool
144
-    {
145
-        add_filter(
146
-            'admin_body_class',
147
-            function ($classes) {
148
-                if (strpos($classes, 'espresso-admin') === false) {
149
-                    $classes .= ' espresso-admin';
150
-                }
151
-                return $classes;
152
-            }
153
-        );
154
-        $this->loader->getShared(JqueryAssetManager::class);
155
-        $this->loader->getShared(EspressoLegacyAdminAssetManager::class);
156
-        $this->loader->getShared(LegacyAccountingAssetManager::class);
157
-        return true;
158
-    }
137
+	/**
138
+	 * implements logic required to run during request
139
+	 *
140
+	 * @return bool
141
+	 * @since   5.0.0.p
142
+	 */
143
+	protected function requestHandler(): bool
144
+	{
145
+		add_filter(
146
+			'admin_body_class',
147
+			function ($classes) {
148
+				if (strpos($classes, 'espresso-admin') === false) {
149
+					$classes .= ' espresso-admin';
150
+				}
151
+				return $classes;
152
+			}
153
+		);
154
+		$this->loader->getShared(JqueryAssetManager::class);
155
+		$this->loader->getShared(EspressoLegacyAdminAssetManager::class);
156
+		$this->loader->getShared(LegacyAccountingAssetManager::class);
157
+		return true;
158
+	}
159 159
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -144,7 +144,7 @@
 block discarded – undo
144 144
     {
145 145
         add_filter(
146 146
             'admin_body_class',
147
-            function ($classes) {
147
+            function($classes) {
148 148
                 if (strpos($classes, 'espresso-admin') === false) {
149 149
                     $classes .= ' espresso-admin';
150 150
                 }
Please login to merge, or discard this patch.
core/domain/entities/routing/handlers/admin/EspressoEventsAdmin.php 1 patch
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -14,30 +14,30 @@
 block discarded – undo
14 14
  */
15 15
 class EspressoEventsAdmin extends AdminRoute
16 16
 {
17
-    /**
18
-     * returns true if the current request matches this route
19
-     *
20
-     * @return bool
21
-     * @since   5.0.0.p
22
-     */
23
-    public function matchesCurrentRequest(): bool
24
-    {
25
-        global $pagenow;
26
-        return parent::matchesCurrentRequest()
27
-               && $pagenow
28
-               && $pagenow === 'admin.php'
29
-               && $this->request->getRequestParam('page') === 'espresso_events';
30
-    }
17
+	/**
18
+	 * returns true if the current request matches this route
19
+	 *
20
+	 * @return bool
21
+	 * @since   5.0.0.p
22
+	 */
23
+	public function matchesCurrentRequest(): bool
24
+	{
25
+		global $pagenow;
26
+		return parent::matchesCurrentRequest()
27
+			   && $pagenow
28
+			   && $pagenow === 'admin.php'
29
+			   && $this->request->getRequestParam('page') === 'espresso_events';
30
+	}
31 31
 
32 32
 
33
-    /**
34
-     * @since 5.0.0.p
35
-     */
36
-    protected function registerDependencies()
37
-    {
38
-        $this->dependency_map->registerDependencies(
39
-            'EventEspresso\core\domain\services\admin\events\default_settings\AdvancedEditorAdminFormSection',
40
-            AdminRoute::getDefaultDependencies()
41
-        );
42
-    }
33
+	/**
34
+	 * @since 5.0.0.p
35
+	 */
36
+	protected function registerDependencies()
37
+	{
38
+		$this->dependency_map->registerDependencies(
39
+			'EventEspresso\core\domain\services\admin\events\default_settings\AdvancedEditorAdminFormSection',
40
+			AdminRoute::getDefaultDependencies()
41
+		);
42
+	}
43 43
 }
Please login to merge, or discard this patch.
core/libraries/payment_methods/EE_PMT_Base.lib.php 1 patch
Indentation   +834 added lines, -834 removed lines patch added patch discarded remove patch
@@ -16,838 +16,838 @@
 block discarded – undo
16 16
  */
17 17
 abstract class EE_PMT_Base
18 18
 {
19
-    const onsite  = 'on-site';
20
-
21
-    const offsite = 'off-site';
22
-
23
-    const offline = 'off-line';
24
-
25
-    /**
26
-     * @var EE_Payment_Method
27
-     */
28
-    protected $_pm_instance = null;
29
-
30
-    /**
31
-     * @var boolean
32
-     */
33
-    protected $_requires_https = false;
34
-
35
-    /**
36
-     * @var boolean
37
-     */
38
-    protected $_has_billing_form;
39
-
40
-    /**
41
-     * @var EE_Gateway
42
-     */
43
-    protected $_gateway = null;
44
-
45
-    /**
46
-     * @var EE_Payment_Method_Form
47
-     */
48
-    protected $_settings_form = null;
49
-
50
-    /**
51
-     * @var EE_Form_Section_Proper
52
-     */
53
-    protected $_billing_form = null;
54
-
55
-    /**
56
-     * @var boolean
57
-     */
58
-    protected $_cache_billing_form = true;
59
-
60
-    /**
61
-     * String of the absolute path to the folder containing this file, with a trailing slash.
62
-     * eg '/public_html/wp-site/wp-content/plugins/event-espresso/payment_methods/Invoice/'
63
-     *
64
-     * @var string|null
65
-     */
66
-    protected $_file_folder = null;
67
-
68
-    /**
69
-     * String to the absolute URL to this file (useful for getting its web-accessible resources
70
-     * like images, js, or css)
71
-     *
72
-     * @var string|null
73
-     */
74
-    protected $_file_url = null;
75
-
76
-    /**
77
-     * Pretty name for the payment method
78
-     *
79
-     * @var string|null
80
-     */
81
-    protected $_pretty_name = null;
82
-
83
-    /**
84
-     * @var string|null
85
-     */
86
-    protected $_default_button_url = null;
87
-
88
-    /**
89
-     * @var string|null
90
-     */
91
-    protected $_default_description = null;
92
-
93
-    /**
94
-     *  @var string|null
95
-     */
96
-    protected $_template_path = null;
97
-
98
-    /**
99
-     * @param EE_Payment_Method|null $pm_instance
100
-     * @throws ReflectionException
101
-     * @throws EE_Error
102
-     */
103
-    public function __construct($pm_instance = null)
104
-    {
105
-        if ($pm_instance instanceof EE_Payment_Method) {
106
-            $this->set_instance($pm_instance);
107
-        }
108
-        if ($this->_gateway) {
109
-            $this->_gateway->set_payment_model(EEM_Payment::instance());
110
-            $this->_gateway->set_payment_log(EEM_Change_Log::instance());
111
-            $this->_gateway->set_template_helper(new EEH_Template());
112
-            $this->_gateway->set_line_item_helper(new EEH_Line_Item());
113
-            $this->_gateway->set_money_helper(new EEH_Money());
114
-            $this->_gateway->set_gateway_data_formatter(new GatewayDataFormatter());
115
-            $this->_gateway->set_unsupported_character_remover(new AsciiOnly());
116
-            do_action('AHEE__EE_PMT_Base___construct__done_initializing_gateway_class', $this, $this->_gateway);
117
-        }
118
-        if (! isset($this->_has_billing_form)) {
119
-            // by default, On Site gateways have a billing form
120
-            if ($this->payment_occurs() == EE_PMT_Base::onsite) {
121
-                $this->set_has_billing_form(true);
122
-            } else {
123
-                $this->set_has_billing_form(false);
124
-            }
125
-        }
126
-
127
-        if (! $this->_pretty_name) {
128
-            throw new EE_Error(
129
-                esc_html__(
130
-                    'You must set the pretty name for the Payment Method Type in the constructor (_pretty_name), and please make it internationalized',
131
-                    'event_espresso'
132
-                )
133
-            );
134
-        }
135
-        // if the child didn't specify a default button, use the credit card one
136
-        if ($this->_default_button_url === null) {
137
-            $this->_default_button_url = EE_PLUGIN_DIR_URL . 'payment_methods/pay-by-credit-card.png';
138
-        }
139
-    }
140
-
141
-
142
-    /**
143
-     * @param boolean $has_billing_form
144
-     */
145
-    public function set_has_billing_form(bool $has_billing_form)
146
-    {
147
-        $this->_has_billing_form = filter_var($has_billing_form, FILTER_VALIDATE_BOOLEAN);
148
-    }
149
-
150
-
151
-    /**
152
-     * sets the file_folder property
153
-     */
154
-    protected function _set_file_folder()
155
-    {
156
-        $reflector          = new ReflectionClass(get_class($this));
157
-        $fn                 = $reflector->getFileName();
158
-        $this->_file_folder = dirname($fn) . '/';
159
-    }
160
-
161
-
162
-    /**
163
-     * sets the file URL with a trailing slash for this PMT
164
-     */
165
-    protected function _set_file_url()
166
-    {
167
-        $plugins_dir_fixed = str_replace('\\', '/', WP_PLUGIN_DIR);
168
-        $file_folder_fixed = str_replace('\\', '/', $this->file_folder());
169
-        $file_path         = str_replace($plugins_dir_fixed, WP_PLUGIN_URL, $file_folder_fixed);
170
-        $this->_file_url   = set_url_scheme($file_path);
171
-    }
172
-
173
-
174
-    /**
175
-     * Gets the default description on all payment methods of this type
176
-     *
177
-     * @return string
178
-     */
179
-    public function default_description(): ?string
180
-    {
181
-        return $this->_default_description;
182
-    }
183
-
184
-
185
-    /**
186
-     * Returns the folder containing the PMT child class, with a trailing slash
187
-     *
188
-     * @return string
189
-     */
190
-    public function file_folder(): ?string
191
-    {
192
-        if (! $this->_file_folder) {
193
-            $this->_set_file_folder();
194
-        }
195
-        return $this->_file_folder;
196
-    }
197
-
198
-
199
-    /**
200
-     * @return string
201
-     */
202
-    public function file_url(): ?string
203
-    {
204
-        if (! $this->_file_url) {
205
-            $this->_set_file_url();
206
-        }
207
-        return $this->_file_url;
208
-    }
209
-
210
-
211
-    /**
212
-     * Sets the payment method instance this payment method type is for.
213
-     * Its important teh payment method instance is set before
214
-     *
215
-     * @param EE_Payment_Method $payment_method_instance
216
-     * @throws EE_Error
217
-     * @throws ReflectionException
218
-     */
219
-    public function set_instance(EE_Payment_Method $payment_method_instance)
220
-    {
221
-        $this->_pm_instance = $payment_method_instance;
222
-        // if they have already requested the settings form, make sure its
223
-        // data matches this model object
224
-        if ($this->_settings_form) {
225
-            $this->settings_form()->populate_model_obj($payment_method_instance);
226
-        }
227
-        if ($this->_gateway instanceof EE_Gateway) {
228
-            $this->_gateway->set_settings($payment_method_instance->settings_array());
229
-        }
230
-    }
231
-
232
-
233
-    /**
234
-     * Gets teh form for displaying to admins where they set up the payment method
235
-     *
236
-     * @return EE_Payment_Method_Form
237
-     * @throws EE_Error
238
-     * @throws ReflectionException
239
-     */
240
-    public function settings_form(): EE_Payment_Method_Form
241
-    {
242
-        if (! $this->_settings_form) {
243
-            $this->_settings_form = $this->generate_new_settings_form();
244
-            $this->_settings_form->set_payment_method_type($this);
245
-            // if we have already assigned a model object to this pmt, make
246
-            // sure it's reflected in the form we just generated
247
-            if ($this->_pm_instance) {
248
-                $this->_settings_form->populate_model_obj($this->_pm_instance);
249
-            }
250
-        }
251
-        return $this->_settings_form;
252
-    }
253
-
254
-
255
-    /**
256
-     * Gets the form for all the settings related to this payment method type
257
-     *
258
-     * @return EE_Payment_Method_Form
259
-     */
260
-    abstract public function generate_new_settings_form();
261
-
262
-
263
-    /**
264
-     * Sets the form for settings. This may be useful if we have already received
265
-     * a form submission and have form data it in, and want to use it anytime we're showing
266
-     * this payment method type's settings form later in the request
267
-     *
268
-     * @param EE_Payment_Method_Form $form
269
-     */
270
-    public function set_settings_form(EE_Payment_Method_Form $form)
271
-    {
272
-        $this->_settings_form = $form;
273
-    }
274
-
275
-
276
-    /**
277
-     * @return boolean
278
-     */
279
-    public function has_billing_form(): bool
280
-    {
281
-        return $this->_has_billing_form;
282
-    }
283
-
284
-
285
-    /**
286
-     * Gets the form for displaying to attendees where they can enter their billing info
287
-     * which will be sent to teh gateway (can be null)
288
-     *
289
-     * @param EE_Transaction|null $transaction
290
-     * @param array               $extra_args
291
-     * @return EE_Billing_Attendee_Info_Form|EE_Billing_Info_Form|null
292
-     * @throws EE_Error
293
-     * @throws ReflectionException
294
-     */
295
-    public function billing_form(EE_Transaction $transaction = null, array $extra_args = [])
296
-    {
297
-        // has billing form already been regenerated ? or overwrite cache?
298
-        if (! $this->_billing_form instanceof EE_Billing_Info_Form || ! $this->_cache_billing_form) {
299
-            $this->_billing_form = $this->generate_new_billing_form($transaction, $extra_args);
300
-        }
301
-        // if we know who the attendee is, and this is a billing form
302
-        // that uses attendee info, populate it
303
-        if (
304
-            apply_filters(
305
-                'FHEE__populate_billing_form_fields_from_attendee',
306
-                (
307
-                    $this->_billing_form instanceof EE_Billing_Attendee_Info_Form
308
-                    && $transaction instanceof EE_Transaction
309
-                    && $transaction->primary_registration() instanceof EE_Registration
310
-                    && $transaction->primary_registration()->attendee() instanceof EE_Attendee
311
-                ),
312
-                $this->_billing_form,
313
-                $transaction
314
-            )
315
-        ) {
316
-            $this->_billing_form->populate_from_attendee($transaction->primary_registration()->attendee());
317
-        }
318
-        return $this->_billing_form;
319
-    }
320
-
321
-
322
-    /**
323
-     * Creates the billing form for this payment method type
324
-     *
325
-     * @param EE_Transaction|null $transaction
326
-     * @return EE_Billing_Info_Form|null
327
-     */
328
-    abstract public function generate_new_billing_form(EE_Transaction $transaction = null);
329
-
330
-
331
-    /**
332
-     * applies debug data to the form
333
-     *
334
-     * @param EE_Billing_Info_Form $billing_form
335
-     * @return EE_Billing_Info_Form|null
336
-     */
337
-    public function apply_billing_form_debug_settings(EE_Billing_Info_Form $billing_form)
338
-    {
339
-        return $billing_form;
340
-    }
341
-
342
-
343
-    /**
344
-     * Sets the billing form for this payment method type. You may want to use this
345
-     * if you have form
346
-     *
347
-     * @param EE_Payment_Method $form
348
-     */
349
-    public function set_billing_form(EE_Payment_Method $form)
350
-    {
351
-        $this->_billing_form = $form;
352
-    }
353
-
354
-
355
-    /**
356
-     * Returns whether this payment method requires HTTPS to be used
357
-     *
358
-     * @return boolean
359
-     */
360
-    public function requires_https(): bool
361
-    {
362
-        return $this->_requires_https;
363
-    }
364
-
365
-
366
-    /**
367
-     * @param EE_Transaction            $transaction
368
-     * @param float|null                $amount
369
-     * @param EE_Billing_Info_Form|null $billing_info
370
-     * @param string|null               $return_url
371
-     * @param string                    $fail_url
372
-     * @param string                    $method
373
-     * @param bool                      $by_admin
374
-     * @return EE_Payment
375
-     * @throws EE_Error
376
-     * @throws ReflectionException
377
-     */
378
-    public function process_payment(
379
-        EE_Transaction $transaction,
380
-        $amount = NULL,
381
-        $billing_info = NULL,
382
-        $return_url = NULL,
383
-        $fail_url = '',
384
-        $method = 'CART',
385
-        $by_admin = false
386
-    ) {
387
-        // @todo: add surcharge for the payment method, if any
388
-        if ($this->_gateway) {
389
-            // there is a gateway, so we're going to make a payment object
390
-            // but wait! do they already have a payment in progress that we thought was failed?
391
-            $duplicate_properties = [
392
-                'STS_ID'               => EEM_Payment::status_id_failed,
393
-                'TXN_ID'               => $transaction->ID(),
394
-                'PMD_ID'               => $this->_pm_instance->ID(),
395
-                'PAY_source'           => $method,
396
-                'PAY_amount'           => $amount !== null
397
-                    ? $amount
398
-                    : $transaction->remaining(),
399
-                'PAY_gateway_response' => null,
400
-            ];
401
-            $payment              = EEM_Payment::instance()->get_one([$duplicate_properties]);
402
-            // if we didn't already have a payment in progress for the same thing,
403
-            // then we actually want to make a new payment
404
-            if (! $payment instanceof EE_Payment) {
405
-                $payment = EE_Payment::new_instance(
406
-                    array_merge(
407
-                        $duplicate_properties,
408
-                        [
409
-                            'PAY_timestamp'       => time(),
410
-                            'PAY_txn_id_chq_nmbr' => null,
411
-                            'PAY_po_number'       => null,
412
-                            'PAY_extra_accntng'   => null,
413
-                            'PAY_details'         => null,
414
-                        ]
415
-                    )
416
-                );
417
-            }
418
-            // make sure the payment has been saved to show we started it, and so it has an ID should the gateway try to log it
419
-            $payment->save();
420
-            $billing_values = $this->_get_billing_values_from_form($billing_info);
421
-
422
-            //  Offsite Gateway
423
-            if ($this->_gateway instanceof EE_Offsite_Gateway) {
424
-                $payment = $this->_gateway->set_redirection_info(
425
-                    $payment,
426
-                    $billing_values,
427
-                    $return_url,
428
-                    EE_Config::instance()->core->txn_page_url(
429
-                        [
430
-                            'e_reg_url_link'    => $transaction->primary_registration()->reg_url_link(),
431
-                            'ee_payment_method' => $this->_pm_instance->slug(),
432
-                        ]
433
-                    ),
434
-                    $fail_url
435
-                );
436
-                $payment->save();
437
-                //  Onsite Gateway
438
-            } elseif ($this->_gateway instanceof EE_Onsite_Gateway) {
439
-                $payment = $this->_gateway->do_direct_payment($payment, $billing_values);
440
-                $payment->save();
441
-            } else {
442
-                throw new EE_Error(
443
-                    sprintf(
444
-                        esc_html__(
445
-                            'Gateway for payment method type "%s" is "%s", not a subclass of either EE_Offsite_Gateway or EE_Onsite_Gateway, or null (to indicate NO gateway)',
446
-                            'event_espresso'
447
-                        ),
448
-                        get_class($this),
449
-                        gettype($this->_gateway)
450
-                    )
451
-                );
452
-            }
453
-        } else {
454
-            // no gateway provided
455
-            // there is no payment. Must be an offline gateway
456
-            // create a payment object anyways, but dont save it
457
-            $payment = EE_Payment::new_instance(
458
-                [
459
-                    'STS_ID'        => EEM_Payment::status_id_pending,
460
-                    'TXN_ID'        => $transaction->ID(),
461
-                    'PMD_ID'        => $transaction->payment_method_ID(),
462
-                    'PAY_amount'    => 0.00,
463
-                    'PAY_timestamp' => time(),
464
-                ]
465
-            );
466
-        }
467
-
468
-        // if there is billing info, clean it and save it now
469
-        if ($billing_info instanceof EE_Billing_Attendee_Info_Form) {
470
-            $this->_save_billing_info_to_attendee($billing_info, $transaction);
471
-        }
472
-
473
-        return $payment;
474
-    }
475
-
476
-
477
-    /**
478
-     * Gets the values we want to pass onto the gateway. Normally these
479
-     * are just the 'pretty' values, but there may be times the data may need
480
-     * a  little massaging. Proper subsections will become arrays of inputs
481
-     *
482
-     * @param EE_Billing_Info_Form|null $billing_form
483
-     * @return array
484
-     * @throws EE_Error
485
-     */
486
-    protected function _get_billing_values_from_form($billing_form)
487
-    {
488
-        return $billing_form instanceof EE_Form_Section_Proper
489
-            ? $billing_form->input_pretty_values(true)
490
-            : [];
491
-    }
492
-
493
-
494
-    /**
495
-     * Handles an instant payment notification when the transaction is known (by default).
496
-     *
497
-     * @param array          $req_data
498
-     * @param EE_Transaction $transaction
499
-     * @return EE_Payment
500
-     * @throws EE_Error
501
-     * @throws ReflectionException
502
-     */
503
-    public function handle_ipn(array $req_data, EE_Transaction $transaction): EE_Payment
504
-    {
505
-        $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
506
-        if (! $this->_gateway instanceof EE_Offsite_Gateway) {
507
-            throw new EE_Error(
508
-                sprintf(
509
-                    esc_html__("Could not handle IPN because '%s' is not an offsite gateway", "event_espresso"),
510
-                    print_r($this->_gateway, true)
511
-                )
512
-            );
513
-        }
514
-        return $this->_gateway->handle_payment_update($req_data, $transaction);
515
-    }
516
-
517
-
518
-    /**
519
-     * Saves the billing info onto the attendee of the primary registrant on this transaction, and
520
-     * cleans it first.
521
-     *
522
-     * @param EE_Billing_Attendee_Info_Form $billing_form
523
-     * @param EE_Transaction|null           $transaction
524
-     * @return boolean success
525
-     * @throws EE_Error
526
-     * @throws ReflectionException
527
-     */
528
-    protected function _save_billing_info_to_attendee(
529
-        EE_Billing_Attendee_Info_Form $billing_form,
530
-        ?EE_Transaction $transaction
531
-    ): bool {
532
-        if (! $transaction instanceof EE_Transaction) {
533
-            EE_Error::add_error(
534
-                esc_html__("Cannot save billing info because no transaction was specified", "event_espresso"),
535
-                __FILE__,
536
-                __FUNCTION__,
537
-                __LINE__
538
-            );
539
-            return false;
540
-        }
541
-        $primary_reg = $transaction->primary_registration();
542
-        if (! $primary_reg) {
543
-            EE_Error::add_error(
544
-                esc_html__(
545
-                    "Cannot save billing info because the transaction has no primary registration",
546
-                    "event_espresso"
547
-                ),
548
-                __FILE__,
549
-                __FUNCTION__,
550
-                __LINE__
551
-            );
552
-            return false;
553
-        }
554
-        $attendee = $primary_reg->attendee();
555
-        if (! $attendee) {
556
-            EE_Error::add_error(
557
-                esc_html__(
558
-                    "Cannot save billing info because the transaction's primary registration has no attendee!",
559
-                    "event_espresso"
560
-                ),
561
-                __FILE__,
562
-                __FUNCTION__,
563
-                __LINE__
564
-            );
565
-            return false;
566
-        }
567
-        return $attendee->save_and_clean_billing_info_for_payment_method($billing_form, $transaction->payment_method());
568
-    }
569
-
570
-
571
-    /**
572
-     * Gets the payment this IPN is for. Children may often want to
573
-     * override this to inspect the request
574
-     *
575
-     * @param EE_Transaction $transaction
576
-     * @param array          $req_data
577
-     * @return EE_Payment
578
-     * @throws EE_Error
579
-     * @throws ReflectionException
580
-     */
581
-    protected function find_payment_for_ipn(EE_Transaction $transaction, array $req_data = []): EE_Payment
582
-    {
583
-        return $transaction->last_payment();
584
-    }
585
-
586
-
587
-    /**
588
-     * In case generic code cannot provide the payment processor with a specific payment method
589
-     * and transaction, it will try calling this method on each activate payment method.
590
-     * If the payment method is able to identify the request as being for it, it should fetch
591
-     * the payment it's for and return it. If not, it should throw an EE_Error to indicate it cannot
592
-     * handle the IPN
593
-     *
594
-     * @param array $req_data
595
-     * @return EE_Payment only if this payment method can find the info its needs from $req_data
596
-     * and identifies the IPN as being for this payment method (not just fo ra payment method of this type)
597
-     * @throws EE_Error
598
-     */
599
-    public function handle_unclaimed_ipn(array $req_data = []): EE_Payment
600
-    {
601
-        throw new EE_Error(
602
-            sprintf(
603
-                esc_html__("Payment Method '%s' cannot handle unclaimed IPNs", "event_espresso"),
604
-                get_class($this)
605
-            )
606
-        );
607
-    }
608
-
609
-
610
-    /**
611
-     * Logic to be accomplished when the payment attempt is complete.
612
-     * Most payment methods don't need to do anything at this point; but some, like Mijireh, do.
613
-     * (Mijireh is an offsite gateway which doesn't send an IPN. So when the user returns to EE from
614
-     * mijireh, this method needs to be called so the Mijireh PM can ping Mijireh to know the status
615
-     * of the payment). Fed a transaction because it's always assumed to be the last payment that
616
-     * we're dealing with. Returns that last payment (if there is one)
617
-     *
618
-     * @param EE_Transaction $transaction
619
-     * @return EE_Payment|null
620
-     * @throws EE_Error
621
-     * @throws ReflectionException
622
-     */
623
-    public function finalize_payment_for(EE_Transaction $transaction): ?EE_Payment
624
-    {
625
-        return $transaction->last_payment();
626
-    }
627
-
628
-
629
-    /**
630
-     * Whether this payment method's gateway supports sending refund requests
631
-     *
632
-     * @return boolean
633
-     */
634
-    public function supports_sending_refunds(): bool
635
-    {
636
-        return $this->_gateway instanceof EE_Gateway && $this->_gateway->supports_sending_refunds();
637
-    }
638
-
639
-
640
-    /**
641
-     * @param EE_Payment $payment
642
-     * @param array      $refund_info
643
-     * @return EE_Payment
644
-     * @throws EE_Error
645
-     */
646
-    public function process_refund(EE_Payment $payment, array $refund_info = []): EE_Payment
647
-    {
648
-        if ($this->_gateway instanceof EE_Gateway) {
649
-            return $this->_gateway->do_direct_refund($payment, $refund_info);
650
-        } else {
651
-            throw new EE_Error(
652
-                sprintf(
653
-                    esc_html__('Payment Method Type "%s" does not support sending refund requests', 'event_espresso'),
654
-                    get_class($this)
655
-                )
656
-            );
657
-        }
658
-    }
659
-
660
-
661
-    /**
662
-     * Returns one the class's constants onsite,offsite, or offline, depending on this
663
-     * payment method's gateway.
664
-     *
665
-     * @return string
666
-     * @throws EE_Error
667
-     */
668
-    public function payment_occurs(): string
669
-    {
670
-        if (! $this->_gateway) {
671
-            return EE_PMT_Base::offline;
672
-        }
673
-        if ($this->_gateway instanceof EE_Onsite_Gateway) {
674
-            return EE_PMT_Base::onsite;
675
-        }
676
-        if ($this->_gateway instanceof EE_Offsite_Gateway) {
677
-            return EE_PMT_Base::offsite;
678
-        }
679
-        throw new EE_Error(
680
-            sprintf(
681
-                esc_html__(
682
-                    "Payment method type '%s's gateway isn't an instance of EE_Onsite_Gateway, EE_Offsite_Gateway, or null. It must be one of those",
683
-                    "event_espresso"
684
-                ),
685
-                get_class($this)
686
-            )
687
-        );
688
-    }
689
-
690
-
691
-    /**
692
-     * For adding any html output ab ove the payment overview.
693
-     * Many gateways won't want ot display anything, so this function just returns an empty string.
694
-     * Other gateways may want to override this, such as offline gateways.
695
-     *
696
-     * @param EE_Payment $payment
697
-     * @return string
698
-     */
699
-    public function payment_overview_content(EE_Payment $payment)
700
-    {
701
-        return EEH_Template::display_template(
702
-            EE_LIBRARIES . 'payment_methods/templates/payment_details_content.template.php',
703
-            ['payment_method' => $this->_pm_instance, 'payment' => $payment],
704
-            true
705
-        );
706
-    }
707
-
708
-
709
-    /**
710
-     * @return array where keys are the help tab name,
711
-     * values are: array {
712
-     * @type string $title         i18n name for the help tab
713
-     * @type string $filename      name of the file located in ./help_tabs/ (ie, in a folder next to this file)
714
-     * @type array  $template_args any arguments you want passed to the template file while rendering.
715
-     *                             Keys will be variable names and values with be their values.
716
-     */
717
-    public function help_tabs_config()
718
-    {
719
-        return [];
720
-    }
721
-
722
-
723
-    /**
724
-     * The system name for this PMT (eg AIM, Paypal_Pro, Invoice... what gets put into
725
-     * the payment method's table's PMT_type column)
726
-     *
727
-     * @return string
728
-     */
729
-    public function system_name()
730
-    {
731
-        $classname = get_class($this);
732
-        return str_replace("EE_PMT_", '', $classname);
733
-    }
734
-
735
-
736
-    /**
737
-     * A pretty i18n version of the PMT name. Often the same as the "pretty_name", but you can change it by overriding
738
-     * this method.
739
-     *
740
-     * @return string|null
741
-     */
742
-    public function defaultFrontendName()
743
-    {
744
-        return $this->pretty_name();
745
-    }
746
-
747
-
748
-    /**
749
-     * A pretty i18n version of the PMT name
750
-     *
751
-     * @return string|null
752
-     */
753
-    public function pretty_name(): ?string
754
-    {
755
-        return $this->_pretty_name;
756
-    }
757
-
758
-
759
-    /**
760
-     * Gets the default absolute URL to the payment method type's button
761
-     *
762
-     * @return string|null
763
-     */
764
-    public function default_button_url(): ?string
765
-    {
766
-        return $this->_default_button_url;
767
-    }
768
-
769
-
770
-    /**
771
-     * Gets the gateway used by this payment method (if any)
772
-     *
773
-     * @return EE_Gateway
774
-     */
775
-    public function get_gateway(): ?EE_Gateway
776
-    {
777
-        return $this->_gateway;
778
-    }
779
-
780
-
781
-    /**
782
-     * @return string html for the link to a help tab
783
-     */
784
-    public function get_help_tab_link(): string
785
-    {
786
-        return EEH_Template::get_help_tab_link(
787
-            $this->get_help_tab_name(),
788
-            'espresso_payment_settings',
789
-            'default'
790
-        );
791
-    }
792
-
793
-
794
-    /**
795
-     * Returns the name of the help tab for this PMT
796
-     *
797
-     * @return string
798
-     */
799
-    public function get_help_tab_name(): string
800
-    {
801
-        return 'ee_' . strtolower($this->system_name()) . '_help_tab';
802
-    }
803
-
804
-
805
-    /**
806
-     * The name of the wp capability that should be associated with the usage of
807
-     * this PMT by an admin
808
-     *
809
-     * @return string
810
-     */
811
-    public function cap_name(): string
812
-    {
813
-        return 'ee_payment_method_' . strtolower($this->system_name());
814
-    }
815
-
816
-
817
-    /**
818
-     * Called by client code to tell the gateway that if it wants to change
819
-     * the transaction or line items or registrations related to teh payment it already
820
-     * processed (we think, but possibly not) that now's the time to do it.
821
-     * It is expected that gateways will store any info they need for this on the PAY_details,
822
-     * or maybe an extra meta value
823
-     *
824
-     * @param EE_Payment $payment
825
-     * @return void
826
-     */
827
-    public function update_txn_based_on_payment($payment)
828
-    {
829
-        if ($this->_gateway instanceof EE_Gateway) {
830
-            $this->_gateway->update_txn_based_on_payment($payment);
831
-        }
832
-    }
833
-
834
-
835
-    /**
836
-     * Returns a string of HTML describing this payment method type for an admin,
837
-     * primarily intended for them to read before activating it.
838
-     * The easiest way to set this is to create a folder 'templates' alongside
839
-     * your EE_PMT_{System_Name} file, and in it create a file named "{system_name}_intro.template.php".
840
-     * Eg, if your payment method file is named "EE_PMT_Foo_Bar.pm.php",
841
-     * then you'd create a file named "templates" in the same folder as it, and name the file
842
-     * "foo_bar_intro.template.php", and its content will be returned by this method
843
-     *
844
-     * @return string
845
-     */
846
-    public function introductory_html(): string
847
-    {
848
-        return EEH_Template::locate_template(
849
-            $this->file_folder() . 'templates/' . strtolower($this->system_name()) . '_intro.template.php',
850
-            ['pmt_obj' => $this, 'pm_instance' => $this->_pm_instance]
851
-        );
852
-    }
19
+	const onsite  = 'on-site';
20
+
21
+	const offsite = 'off-site';
22
+
23
+	const offline = 'off-line';
24
+
25
+	/**
26
+	 * @var EE_Payment_Method
27
+	 */
28
+	protected $_pm_instance = null;
29
+
30
+	/**
31
+	 * @var boolean
32
+	 */
33
+	protected $_requires_https = false;
34
+
35
+	/**
36
+	 * @var boolean
37
+	 */
38
+	protected $_has_billing_form;
39
+
40
+	/**
41
+	 * @var EE_Gateway
42
+	 */
43
+	protected $_gateway = null;
44
+
45
+	/**
46
+	 * @var EE_Payment_Method_Form
47
+	 */
48
+	protected $_settings_form = null;
49
+
50
+	/**
51
+	 * @var EE_Form_Section_Proper
52
+	 */
53
+	protected $_billing_form = null;
54
+
55
+	/**
56
+	 * @var boolean
57
+	 */
58
+	protected $_cache_billing_form = true;
59
+
60
+	/**
61
+	 * String of the absolute path to the folder containing this file, with a trailing slash.
62
+	 * eg '/public_html/wp-site/wp-content/plugins/event-espresso/payment_methods/Invoice/'
63
+	 *
64
+	 * @var string|null
65
+	 */
66
+	protected $_file_folder = null;
67
+
68
+	/**
69
+	 * String to the absolute URL to this file (useful for getting its web-accessible resources
70
+	 * like images, js, or css)
71
+	 *
72
+	 * @var string|null
73
+	 */
74
+	protected $_file_url = null;
75
+
76
+	/**
77
+	 * Pretty name for the payment method
78
+	 *
79
+	 * @var string|null
80
+	 */
81
+	protected $_pretty_name = null;
82
+
83
+	/**
84
+	 * @var string|null
85
+	 */
86
+	protected $_default_button_url = null;
87
+
88
+	/**
89
+	 * @var string|null
90
+	 */
91
+	protected $_default_description = null;
92
+
93
+	/**
94
+	 *  @var string|null
95
+	 */
96
+	protected $_template_path = null;
97
+
98
+	/**
99
+	 * @param EE_Payment_Method|null $pm_instance
100
+	 * @throws ReflectionException
101
+	 * @throws EE_Error
102
+	 */
103
+	public function __construct($pm_instance = null)
104
+	{
105
+		if ($pm_instance instanceof EE_Payment_Method) {
106
+			$this->set_instance($pm_instance);
107
+		}
108
+		if ($this->_gateway) {
109
+			$this->_gateway->set_payment_model(EEM_Payment::instance());
110
+			$this->_gateway->set_payment_log(EEM_Change_Log::instance());
111
+			$this->_gateway->set_template_helper(new EEH_Template());
112
+			$this->_gateway->set_line_item_helper(new EEH_Line_Item());
113
+			$this->_gateway->set_money_helper(new EEH_Money());
114
+			$this->_gateway->set_gateway_data_formatter(new GatewayDataFormatter());
115
+			$this->_gateway->set_unsupported_character_remover(new AsciiOnly());
116
+			do_action('AHEE__EE_PMT_Base___construct__done_initializing_gateway_class', $this, $this->_gateway);
117
+		}
118
+		if (! isset($this->_has_billing_form)) {
119
+			// by default, On Site gateways have a billing form
120
+			if ($this->payment_occurs() == EE_PMT_Base::onsite) {
121
+				$this->set_has_billing_form(true);
122
+			} else {
123
+				$this->set_has_billing_form(false);
124
+			}
125
+		}
126
+
127
+		if (! $this->_pretty_name) {
128
+			throw new EE_Error(
129
+				esc_html__(
130
+					'You must set the pretty name for the Payment Method Type in the constructor (_pretty_name), and please make it internationalized',
131
+					'event_espresso'
132
+				)
133
+			);
134
+		}
135
+		// if the child didn't specify a default button, use the credit card one
136
+		if ($this->_default_button_url === null) {
137
+			$this->_default_button_url = EE_PLUGIN_DIR_URL . 'payment_methods/pay-by-credit-card.png';
138
+		}
139
+	}
140
+
141
+
142
+	/**
143
+	 * @param boolean $has_billing_form
144
+	 */
145
+	public function set_has_billing_form(bool $has_billing_form)
146
+	{
147
+		$this->_has_billing_form = filter_var($has_billing_form, FILTER_VALIDATE_BOOLEAN);
148
+	}
149
+
150
+
151
+	/**
152
+	 * sets the file_folder property
153
+	 */
154
+	protected function _set_file_folder()
155
+	{
156
+		$reflector          = new ReflectionClass(get_class($this));
157
+		$fn                 = $reflector->getFileName();
158
+		$this->_file_folder = dirname($fn) . '/';
159
+	}
160
+
161
+
162
+	/**
163
+	 * sets the file URL with a trailing slash for this PMT
164
+	 */
165
+	protected function _set_file_url()
166
+	{
167
+		$plugins_dir_fixed = str_replace('\\', '/', WP_PLUGIN_DIR);
168
+		$file_folder_fixed = str_replace('\\', '/', $this->file_folder());
169
+		$file_path         = str_replace($plugins_dir_fixed, WP_PLUGIN_URL, $file_folder_fixed);
170
+		$this->_file_url   = set_url_scheme($file_path);
171
+	}
172
+
173
+
174
+	/**
175
+	 * Gets the default description on all payment methods of this type
176
+	 *
177
+	 * @return string
178
+	 */
179
+	public function default_description(): ?string
180
+	{
181
+		return $this->_default_description;
182
+	}
183
+
184
+
185
+	/**
186
+	 * Returns the folder containing the PMT child class, with a trailing slash
187
+	 *
188
+	 * @return string
189
+	 */
190
+	public function file_folder(): ?string
191
+	{
192
+		if (! $this->_file_folder) {
193
+			$this->_set_file_folder();
194
+		}
195
+		return $this->_file_folder;
196
+	}
197
+
198
+
199
+	/**
200
+	 * @return string
201
+	 */
202
+	public function file_url(): ?string
203
+	{
204
+		if (! $this->_file_url) {
205
+			$this->_set_file_url();
206
+		}
207
+		return $this->_file_url;
208
+	}
209
+
210
+
211
+	/**
212
+	 * Sets the payment method instance this payment method type is for.
213
+	 * Its important teh payment method instance is set before
214
+	 *
215
+	 * @param EE_Payment_Method $payment_method_instance
216
+	 * @throws EE_Error
217
+	 * @throws ReflectionException
218
+	 */
219
+	public function set_instance(EE_Payment_Method $payment_method_instance)
220
+	{
221
+		$this->_pm_instance = $payment_method_instance;
222
+		// if they have already requested the settings form, make sure its
223
+		// data matches this model object
224
+		if ($this->_settings_form) {
225
+			$this->settings_form()->populate_model_obj($payment_method_instance);
226
+		}
227
+		if ($this->_gateway instanceof EE_Gateway) {
228
+			$this->_gateway->set_settings($payment_method_instance->settings_array());
229
+		}
230
+	}
231
+
232
+
233
+	/**
234
+	 * Gets teh form for displaying to admins where they set up the payment method
235
+	 *
236
+	 * @return EE_Payment_Method_Form
237
+	 * @throws EE_Error
238
+	 * @throws ReflectionException
239
+	 */
240
+	public function settings_form(): EE_Payment_Method_Form
241
+	{
242
+		if (! $this->_settings_form) {
243
+			$this->_settings_form = $this->generate_new_settings_form();
244
+			$this->_settings_form->set_payment_method_type($this);
245
+			// if we have already assigned a model object to this pmt, make
246
+			// sure it's reflected in the form we just generated
247
+			if ($this->_pm_instance) {
248
+				$this->_settings_form->populate_model_obj($this->_pm_instance);
249
+			}
250
+		}
251
+		return $this->_settings_form;
252
+	}
253
+
254
+
255
+	/**
256
+	 * Gets the form for all the settings related to this payment method type
257
+	 *
258
+	 * @return EE_Payment_Method_Form
259
+	 */
260
+	abstract public function generate_new_settings_form();
261
+
262
+
263
+	/**
264
+	 * Sets the form for settings. This may be useful if we have already received
265
+	 * a form submission and have form data it in, and want to use it anytime we're showing
266
+	 * this payment method type's settings form later in the request
267
+	 *
268
+	 * @param EE_Payment_Method_Form $form
269
+	 */
270
+	public function set_settings_form(EE_Payment_Method_Form $form)
271
+	{
272
+		$this->_settings_form = $form;
273
+	}
274
+
275
+
276
+	/**
277
+	 * @return boolean
278
+	 */
279
+	public function has_billing_form(): bool
280
+	{
281
+		return $this->_has_billing_form;
282
+	}
283
+
284
+
285
+	/**
286
+	 * Gets the form for displaying to attendees where they can enter their billing info
287
+	 * which will be sent to teh gateway (can be null)
288
+	 *
289
+	 * @param EE_Transaction|null $transaction
290
+	 * @param array               $extra_args
291
+	 * @return EE_Billing_Attendee_Info_Form|EE_Billing_Info_Form|null
292
+	 * @throws EE_Error
293
+	 * @throws ReflectionException
294
+	 */
295
+	public function billing_form(EE_Transaction $transaction = null, array $extra_args = [])
296
+	{
297
+		// has billing form already been regenerated ? or overwrite cache?
298
+		if (! $this->_billing_form instanceof EE_Billing_Info_Form || ! $this->_cache_billing_form) {
299
+			$this->_billing_form = $this->generate_new_billing_form($transaction, $extra_args);
300
+		}
301
+		// if we know who the attendee is, and this is a billing form
302
+		// that uses attendee info, populate it
303
+		if (
304
+			apply_filters(
305
+				'FHEE__populate_billing_form_fields_from_attendee',
306
+				(
307
+					$this->_billing_form instanceof EE_Billing_Attendee_Info_Form
308
+					&& $transaction instanceof EE_Transaction
309
+					&& $transaction->primary_registration() instanceof EE_Registration
310
+					&& $transaction->primary_registration()->attendee() instanceof EE_Attendee
311
+				),
312
+				$this->_billing_form,
313
+				$transaction
314
+			)
315
+		) {
316
+			$this->_billing_form->populate_from_attendee($transaction->primary_registration()->attendee());
317
+		}
318
+		return $this->_billing_form;
319
+	}
320
+
321
+
322
+	/**
323
+	 * Creates the billing form for this payment method type
324
+	 *
325
+	 * @param EE_Transaction|null $transaction
326
+	 * @return EE_Billing_Info_Form|null
327
+	 */
328
+	abstract public function generate_new_billing_form(EE_Transaction $transaction = null);
329
+
330
+
331
+	/**
332
+	 * applies debug data to the form
333
+	 *
334
+	 * @param EE_Billing_Info_Form $billing_form
335
+	 * @return EE_Billing_Info_Form|null
336
+	 */
337
+	public function apply_billing_form_debug_settings(EE_Billing_Info_Form $billing_form)
338
+	{
339
+		return $billing_form;
340
+	}
341
+
342
+
343
+	/**
344
+	 * Sets the billing form for this payment method type. You may want to use this
345
+	 * if you have form
346
+	 *
347
+	 * @param EE_Payment_Method $form
348
+	 */
349
+	public function set_billing_form(EE_Payment_Method $form)
350
+	{
351
+		$this->_billing_form = $form;
352
+	}
353
+
354
+
355
+	/**
356
+	 * Returns whether this payment method requires HTTPS to be used
357
+	 *
358
+	 * @return boolean
359
+	 */
360
+	public function requires_https(): bool
361
+	{
362
+		return $this->_requires_https;
363
+	}
364
+
365
+
366
+	/**
367
+	 * @param EE_Transaction            $transaction
368
+	 * @param float|null                $amount
369
+	 * @param EE_Billing_Info_Form|null $billing_info
370
+	 * @param string|null               $return_url
371
+	 * @param string                    $fail_url
372
+	 * @param string                    $method
373
+	 * @param bool                      $by_admin
374
+	 * @return EE_Payment
375
+	 * @throws EE_Error
376
+	 * @throws ReflectionException
377
+	 */
378
+	public function process_payment(
379
+		EE_Transaction $transaction,
380
+		$amount = NULL,
381
+		$billing_info = NULL,
382
+		$return_url = NULL,
383
+		$fail_url = '',
384
+		$method = 'CART',
385
+		$by_admin = false
386
+	) {
387
+		// @todo: add surcharge for the payment method, if any
388
+		if ($this->_gateway) {
389
+			// there is a gateway, so we're going to make a payment object
390
+			// but wait! do they already have a payment in progress that we thought was failed?
391
+			$duplicate_properties = [
392
+				'STS_ID'               => EEM_Payment::status_id_failed,
393
+				'TXN_ID'               => $transaction->ID(),
394
+				'PMD_ID'               => $this->_pm_instance->ID(),
395
+				'PAY_source'           => $method,
396
+				'PAY_amount'           => $amount !== null
397
+					? $amount
398
+					: $transaction->remaining(),
399
+				'PAY_gateway_response' => null,
400
+			];
401
+			$payment              = EEM_Payment::instance()->get_one([$duplicate_properties]);
402
+			// if we didn't already have a payment in progress for the same thing,
403
+			// then we actually want to make a new payment
404
+			if (! $payment instanceof EE_Payment) {
405
+				$payment = EE_Payment::new_instance(
406
+					array_merge(
407
+						$duplicate_properties,
408
+						[
409
+							'PAY_timestamp'       => time(),
410
+							'PAY_txn_id_chq_nmbr' => null,
411
+							'PAY_po_number'       => null,
412
+							'PAY_extra_accntng'   => null,
413
+							'PAY_details'         => null,
414
+						]
415
+					)
416
+				);
417
+			}
418
+			// make sure the payment has been saved to show we started it, and so it has an ID should the gateway try to log it
419
+			$payment->save();
420
+			$billing_values = $this->_get_billing_values_from_form($billing_info);
421
+
422
+			//  Offsite Gateway
423
+			if ($this->_gateway instanceof EE_Offsite_Gateway) {
424
+				$payment = $this->_gateway->set_redirection_info(
425
+					$payment,
426
+					$billing_values,
427
+					$return_url,
428
+					EE_Config::instance()->core->txn_page_url(
429
+						[
430
+							'e_reg_url_link'    => $transaction->primary_registration()->reg_url_link(),
431
+							'ee_payment_method' => $this->_pm_instance->slug(),
432
+						]
433
+					),
434
+					$fail_url
435
+				);
436
+				$payment->save();
437
+				//  Onsite Gateway
438
+			} elseif ($this->_gateway instanceof EE_Onsite_Gateway) {
439
+				$payment = $this->_gateway->do_direct_payment($payment, $billing_values);
440
+				$payment->save();
441
+			} else {
442
+				throw new EE_Error(
443
+					sprintf(
444
+						esc_html__(
445
+							'Gateway for payment method type "%s" is "%s", not a subclass of either EE_Offsite_Gateway or EE_Onsite_Gateway, or null (to indicate NO gateway)',
446
+							'event_espresso'
447
+						),
448
+						get_class($this),
449
+						gettype($this->_gateway)
450
+					)
451
+				);
452
+			}
453
+		} else {
454
+			// no gateway provided
455
+			// there is no payment. Must be an offline gateway
456
+			// create a payment object anyways, but dont save it
457
+			$payment = EE_Payment::new_instance(
458
+				[
459
+					'STS_ID'        => EEM_Payment::status_id_pending,
460
+					'TXN_ID'        => $transaction->ID(),
461
+					'PMD_ID'        => $transaction->payment_method_ID(),
462
+					'PAY_amount'    => 0.00,
463
+					'PAY_timestamp' => time(),
464
+				]
465
+			);
466
+		}
467
+
468
+		// if there is billing info, clean it and save it now
469
+		if ($billing_info instanceof EE_Billing_Attendee_Info_Form) {
470
+			$this->_save_billing_info_to_attendee($billing_info, $transaction);
471
+		}
472
+
473
+		return $payment;
474
+	}
475
+
476
+
477
+	/**
478
+	 * Gets the values we want to pass onto the gateway. Normally these
479
+	 * are just the 'pretty' values, but there may be times the data may need
480
+	 * a  little massaging. Proper subsections will become arrays of inputs
481
+	 *
482
+	 * @param EE_Billing_Info_Form|null $billing_form
483
+	 * @return array
484
+	 * @throws EE_Error
485
+	 */
486
+	protected function _get_billing_values_from_form($billing_form)
487
+	{
488
+		return $billing_form instanceof EE_Form_Section_Proper
489
+			? $billing_form->input_pretty_values(true)
490
+			: [];
491
+	}
492
+
493
+
494
+	/**
495
+	 * Handles an instant payment notification when the transaction is known (by default).
496
+	 *
497
+	 * @param array          $req_data
498
+	 * @param EE_Transaction $transaction
499
+	 * @return EE_Payment
500
+	 * @throws EE_Error
501
+	 * @throws ReflectionException
502
+	 */
503
+	public function handle_ipn(array $req_data, EE_Transaction $transaction): EE_Payment
504
+	{
505
+		$transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
506
+		if (! $this->_gateway instanceof EE_Offsite_Gateway) {
507
+			throw new EE_Error(
508
+				sprintf(
509
+					esc_html__("Could not handle IPN because '%s' is not an offsite gateway", "event_espresso"),
510
+					print_r($this->_gateway, true)
511
+				)
512
+			);
513
+		}
514
+		return $this->_gateway->handle_payment_update($req_data, $transaction);
515
+	}
516
+
517
+
518
+	/**
519
+	 * Saves the billing info onto the attendee of the primary registrant on this transaction, and
520
+	 * cleans it first.
521
+	 *
522
+	 * @param EE_Billing_Attendee_Info_Form $billing_form
523
+	 * @param EE_Transaction|null           $transaction
524
+	 * @return boolean success
525
+	 * @throws EE_Error
526
+	 * @throws ReflectionException
527
+	 */
528
+	protected function _save_billing_info_to_attendee(
529
+		EE_Billing_Attendee_Info_Form $billing_form,
530
+		?EE_Transaction $transaction
531
+	): bool {
532
+		if (! $transaction instanceof EE_Transaction) {
533
+			EE_Error::add_error(
534
+				esc_html__("Cannot save billing info because no transaction was specified", "event_espresso"),
535
+				__FILE__,
536
+				__FUNCTION__,
537
+				__LINE__
538
+			);
539
+			return false;
540
+		}
541
+		$primary_reg = $transaction->primary_registration();
542
+		if (! $primary_reg) {
543
+			EE_Error::add_error(
544
+				esc_html__(
545
+					"Cannot save billing info because the transaction has no primary registration",
546
+					"event_espresso"
547
+				),
548
+				__FILE__,
549
+				__FUNCTION__,
550
+				__LINE__
551
+			);
552
+			return false;
553
+		}
554
+		$attendee = $primary_reg->attendee();
555
+		if (! $attendee) {
556
+			EE_Error::add_error(
557
+				esc_html__(
558
+					"Cannot save billing info because the transaction's primary registration has no attendee!",
559
+					"event_espresso"
560
+				),
561
+				__FILE__,
562
+				__FUNCTION__,
563
+				__LINE__
564
+			);
565
+			return false;
566
+		}
567
+		return $attendee->save_and_clean_billing_info_for_payment_method($billing_form, $transaction->payment_method());
568
+	}
569
+
570
+
571
+	/**
572
+	 * Gets the payment this IPN is for. Children may often want to
573
+	 * override this to inspect the request
574
+	 *
575
+	 * @param EE_Transaction $transaction
576
+	 * @param array          $req_data
577
+	 * @return EE_Payment
578
+	 * @throws EE_Error
579
+	 * @throws ReflectionException
580
+	 */
581
+	protected function find_payment_for_ipn(EE_Transaction $transaction, array $req_data = []): EE_Payment
582
+	{
583
+		return $transaction->last_payment();
584
+	}
585
+
586
+
587
+	/**
588
+	 * In case generic code cannot provide the payment processor with a specific payment method
589
+	 * and transaction, it will try calling this method on each activate payment method.
590
+	 * If the payment method is able to identify the request as being for it, it should fetch
591
+	 * the payment it's for and return it. If not, it should throw an EE_Error to indicate it cannot
592
+	 * handle the IPN
593
+	 *
594
+	 * @param array $req_data
595
+	 * @return EE_Payment only if this payment method can find the info its needs from $req_data
596
+	 * and identifies the IPN as being for this payment method (not just fo ra payment method of this type)
597
+	 * @throws EE_Error
598
+	 */
599
+	public function handle_unclaimed_ipn(array $req_data = []): EE_Payment
600
+	{
601
+		throw new EE_Error(
602
+			sprintf(
603
+				esc_html__("Payment Method '%s' cannot handle unclaimed IPNs", "event_espresso"),
604
+				get_class($this)
605
+			)
606
+		);
607
+	}
608
+
609
+
610
+	/**
611
+	 * Logic to be accomplished when the payment attempt is complete.
612
+	 * Most payment methods don't need to do anything at this point; but some, like Mijireh, do.
613
+	 * (Mijireh is an offsite gateway which doesn't send an IPN. So when the user returns to EE from
614
+	 * mijireh, this method needs to be called so the Mijireh PM can ping Mijireh to know the status
615
+	 * of the payment). Fed a transaction because it's always assumed to be the last payment that
616
+	 * we're dealing with. Returns that last payment (if there is one)
617
+	 *
618
+	 * @param EE_Transaction $transaction
619
+	 * @return EE_Payment|null
620
+	 * @throws EE_Error
621
+	 * @throws ReflectionException
622
+	 */
623
+	public function finalize_payment_for(EE_Transaction $transaction): ?EE_Payment
624
+	{
625
+		return $transaction->last_payment();
626
+	}
627
+
628
+
629
+	/**
630
+	 * Whether this payment method's gateway supports sending refund requests
631
+	 *
632
+	 * @return boolean
633
+	 */
634
+	public function supports_sending_refunds(): bool
635
+	{
636
+		return $this->_gateway instanceof EE_Gateway && $this->_gateway->supports_sending_refunds();
637
+	}
638
+
639
+
640
+	/**
641
+	 * @param EE_Payment $payment
642
+	 * @param array      $refund_info
643
+	 * @return EE_Payment
644
+	 * @throws EE_Error
645
+	 */
646
+	public function process_refund(EE_Payment $payment, array $refund_info = []): EE_Payment
647
+	{
648
+		if ($this->_gateway instanceof EE_Gateway) {
649
+			return $this->_gateway->do_direct_refund($payment, $refund_info);
650
+		} else {
651
+			throw new EE_Error(
652
+				sprintf(
653
+					esc_html__('Payment Method Type "%s" does not support sending refund requests', 'event_espresso'),
654
+					get_class($this)
655
+				)
656
+			);
657
+		}
658
+	}
659
+
660
+
661
+	/**
662
+	 * Returns one the class's constants onsite,offsite, or offline, depending on this
663
+	 * payment method's gateway.
664
+	 *
665
+	 * @return string
666
+	 * @throws EE_Error
667
+	 */
668
+	public function payment_occurs(): string
669
+	{
670
+		if (! $this->_gateway) {
671
+			return EE_PMT_Base::offline;
672
+		}
673
+		if ($this->_gateway instanceof EE_Onsite_Gateway) {
674
+			return EE_PMT_Base::onsite;
675
+		}
676
+		if ($this->_gateway instanceof EE_Offsite_Gateway) {
677
+			return EE_PMT_Base::offsite;
678
+		}
679
+		throw new EE_Error(
680
+			sprintf(
681
+				esc_html__(
682
+					"Payment method type '%s's gateway isn't an instance of EE_Onsite_Gateway, EE_Offsite_Gateway, or null. It must be one of those",
683
+					"event_espresso"
684
+				),
685
+				get_class($this)
686
+			)
687
+		);
688
+	}
689
+
690
+
691
+	/**
692
+	 * For adding any html output ab ove the payment overview.
693
+	 * Many gateways won't want ot display anything, so this function just returns an empty string.
694
+	 * Other gateways may want to override this, such as offline gateways.
695
+	 *
696
+	 * @param EE_Payment $payment
697
+	 * @return string
698
+	 */
699
+	public function payment_overview_content(EE_Payment $payment)
700
+	{
701
+		return EEH_Template::display_template(
702
+			EE_LIBRARIES . 'payment_methods/templates/payment_details_content.template.php',
703
+			['payment_method' => $this->_pm_instance, 'payment' => $payment],
704
+			true
705
+		);
706
+	}
707
+
708
+
709
+	/**
710
+	 * @return array where keys are the help tab name,
711
+	 * values are: array {
712
+	 * @type string $title         i18n name for the help tab
713
+	 * @type string $filename      name of the file located in ./help_tabs/ (ie, in a folder next to this file)
714
+	 * @type array  $template_args any arguments you want passed to the template file while rendering.
715
+	 *                             Keys will be variable names and values with be their values.
716
+	 */
717
+	public function help_tabs_config()
718
+	{
719
+		return [];
720
+	}
721
+
722
+
723
+	/**
724
+	 * The system name for this PMT (eg AIM, Paypal_Pro, Invoice... what gets put into
725
+	 * the payment method's table's PMT_type column)
726
+	 *
727
+	 * @return string
728
+	 */
729
+	public function system_name()
730
+	{
731
+		$classname = get_class($this);
732
+		return str_replace("EE_PMT_", '', $classname);
733
+	}
734
+
735
+
736
+	/**
737
+	 * A pretty i18n version of the PMT name. Often the same as the "pretty_name", but you can change it by overriding
738
+	 * this method.
739
+	 *
740
+	 * @return string|null
741
+	 */
742
+	public function defaultFrontendName()
743
+	{
744
+		return $this->pretty_name();
745
+	}
746
+
747
+
748
+	/**
749
+	 * A pretty i18n version of the PMT name
750
+	 *
751
+	 * @return string|null
752
+	 */
753
+	public function pretty_name(): ?string
754
+	{
755
+		return $this->_pretty_name;
756
+	}
757
+
758
+
759
+	/**
760
+	 * Gets the default absolute URL to the payment method type's button
761
+	 *
762
+	 * @return string|null
763
+	 */
764
+	public function default_button_url(): ?string
765
+	{
766
+		return $this->_default_button_url;
767
+	}
768
+
769
+
770
+	/**
771
+	 * Gets the gateway used by this payment method (if any)
772
+	 *
773
+	 * @return EE_Gateway
774
+	 */
775
+	public function get_gateway(): ?EE_Gateway
776
+	{
777
+		return $this->_gateway;
778
+	}
779
+
780
+
781
+	/**
782
+	 * @return string html for the link to a help tab
783
+	 */
784
+	public function get_help_tab_link(): string
785
+	{
786
+		return EEH_Template::get_help_tab_link(
787
+			$this->get_help_tab_name(),
788
+			'espresso_payment_settings',
789
+			'default'
790
+		);
791
+	}
792
+
793
+
794
+	/**
795
+	 * Returns the name of the help tab for this PMT
796
+	 *
797
+	 * @return string
798
+	 */
799
+	public function get_help_tab_name(): string
800
+	{
801
+		return 'ee_' . strtolower($this->system_name()) . '_help_tab';
802
+	}
803
+
804
+
805
+	/**
806
+	 * The name of the wp capability that should be associated with the usage of
807
+	 * this PMT by an admin
808
+	 *
809
+	 * @return string
810
+	 */
811
+	public function cap_name(): string
812
+	{
813
+		return 'ee_payment_method_' . strtolower($this->system_name());
814
+	}
815
+
816
+
817
+	/**
818
+	 * Called by client code to tell the gateway that if it wants to change
819
+	 * the transaction or line items or registrations related to teh payment it already
820
+	 * processed (we think, but possibly not) that now's the time to do it.
821
+	 * It is expected that gateways will store any info they need for this on the PAY_details,
822
+	 * or maybe an extra meta value
823
+	 *
824
+	 * @param EE_Payment $payment
825
+	 * @return void
826
+	 */
827
+	public function update_txn_based_on_payment($payment)
828
+	{
829
+		if ($this->_gateway instanceof EE_Gateway) {
830
+			$this->_gateway->update_txn_based_on_payment($payment);
831
+		}
832
+	}
833
+
834
+
835
+	/**
836
+	 * Returns a string of HTML describing this payment method type for an admin,
837
+	 * primarily intended for them to read before activating it.
838
+	 * The easiest way to set this is to create a folder 'templates' alongside
839
+	 * your EE_PMT_{System_Name} file, and in it create a file named "{system_name}_intro.template.php".
840
+	 * Eg, if your payment method file is named "EE_PMT_Foo_Bar.pm.php",
841
+	 * then you'd create a file named "templates" in the same folder as it, and name the file
842
+	 * "foo_bar_intro.template.php", and its content will be returned by this method
843
+	 *
844
+	 * @return string
845
+	 */
846
+	public function introductory_html(): string
847
+	{
848
+		return EEH_Template::locate_template(
849
+			$this->file_folder() . 'templates/' . strtolower($this->system_name()) . '_intro.template.php',
850
+			['pmt_obj' => $this, 'pm_instance' => $this->_pm_instance]
851
+		);
852
+	}
853 853
 }
Please login to merge, or discard this patch.