Skip to content

Commit ba64775

Browse files
Store form options as class property
1 parent 9c3efc6 commit ba64775

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

includes/class-form-request.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ class MC4WP_Lite_Form_Request {
3030
*/
3131
private $error_code = 'error';
3232

33+
/**
34+
* @var array The form options
35+
*/
36+
private $options;
37+
3338
/**
3439
* Constructor
3540
*
@@ -81,6 +86,9 @@ public function act() {
8186
// store number of submitted form
8287
$this->form_instance_number = absint( $_POST['_mc4wp_form_instance'] );
8388

89+
// store form options
90+
$this->form_options = mc4wp_get_options( 'form' );
91+
8492
// validate form nonce
8593
if ( ! isset( $_POST['_mc4wp_form_nonce'] ) || ! wp_verify_nonce( $_POST['_mc4wp_form_nonce'], '_mc4wp_form_nonce' ) ) {
8694
$this->error_code = 'invalid_nonce';
@@ -140,11 +148,9 @@ public function act() {
140148
// do stuff on success
141149
if( true === $this->success ) {
142150

143-
$opts = mc4wp_get_options('form');
144-
145151
// check if we want to redirect the visitor
146-
if ( ! empty( $opts['redirect'] ) ) {
147-
wp_redirect( $opts['redirect'] );
152+
if ( ! empty( $this->form_options['redirect'] ) ) {
153+
wp_redirect( $this->form_options['redirect'] );
148154
exit;
149155
}
150156

@@ -266,7 +272,6 @@ private function subscribe( $email, $merge_vars = array() ) {
266272
}
267273

268274
$api = mc4wp_get_api();
269-
$opts = mc4wp_get_options( 'form' );
270275

271276
// get lists to subscribe to
272277
$lists = $this->get_lists();
@@ -292,7 +297,7 @@ private function subscribe( $email, $merge_vars = array() ) {
292297
$list_merge_vars = apply_filters( 'mc4wp_merge_vars', $merge_vars, 0, $list_id );
293298

294299
// send a subscribe request to MailChimp for each list
295-
$result = $api->subscribe( $list_id, $email, $list_merge_vars, $email_type, $opts['double_optin'] );
300+
$result = $api->subscribe( $list_id, $email, $list_merge_vars, $email_type, $this->form_options['double_optin'] );
296301
}
297302

298303
do_action( 'mc4wp_after_subscribe', $email, $merge_vars, 0, $result );
@@ -411,9 +416,7 @@ private function get_email_type( ) {
411416
*/
412417
private function get_lists() {
413418

414-
$opts = mc4wp_get_options('form');
415-
416-
$lists = $opts['lists'];
419+
$lists = $this->form_options['lists'];
417420

418421
// get lists from form, if set.
419422
if( isset( $_POST['_mc4wp_lists'] ) && ! empty( $_POST['_mc4wp_lists'] ) ) {

0 commit comments

Comments
 (0)