| 1 |
<?php |
| 2 |
/** |
| 3 |
* Class that manages the display and processing of the registration form. |
| 4 |
* |
| 5 |
* @package Charitable/Classes/Charitable_Registration_Form |
| 6 |
* @version 1.0.0 |
| 7 |
* @author Eric Daams |
| 8 |
* @copyright Copyright (c) 2015, Studio 164a |
| 9 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 10 |
*/ |
| 11 |
|
| 12 |
// Exit if accessed directly |
| 13 |
if ( ! defined( 'ABSPATH' ) ) exit; |
| 14 |
|
| 15 |
if ( ! class_exists( 'Charitable_Registration_Form' ) ) : |
| 16 |
|
| 17 |
/** |
| 18 |
* Charitable_Registration_Form |
| 19 |
* |
| 20 |
* @since 1.0.0 |
| 21 |
*/ |
| 22 |
class Charitable_Registration_Form extends Charitable_Form { |
| 23 |
|
| 24 |
/** |
| 25 |
* Shortcode parameters. |
| 26 |
* |
| 27 |
* @var array |
| 28 |
* @access protected |
| 29 |
*/ |
| 30 |
protected $shortcode_args; |
| 31 |
|
| 32 |
/** |
| 33 |
* @var string |
| 34 |
*/ |
| 35 |
protected $nonce_action = 'charitable_user_registration'; |
| 36 |
|
| 37 |
/** |
| 38 |
* @var string |
| 39 |
*/ |
| 40 |
protected $nonce_name = '_charitable_user_registration_nonce'; |
| 41 |
|
| 42 |
/** |
| 43 |
* Action to be executed upon form submission. |
| 44 |
* |
| 45 |
* @var string |
| 46 |
* @access protected |
| 47 |
*/ |
| 48 |
protected $form_action = 'save_registration'; |
| 49 |
|
| 50 |
/** |
| 51 |
* The current donor. |
| 52 |
* |
| 53 |
* @var Charitable_Donor |
| 54 |
* @access protected |
| 55 |
*/ |
| 56 |
protected $donor; |
| 57 |
|
| 58 |
/** |
| 59 |
* Create class object. |
| 60 |
* |
| 61 |
* @param array $args User-defined shortcode attributes. |
| 62 |
* @access public |
| 63 |
* @since 1.0.0 |
| 64 |
*/ |
| 65 |
public function __construct( $args = array() ) { |
| 66 |
$this->id = uniqid(); |
| 67 |
$this->shortcode_args = $args; |
| 68 |
$this->attach_hooks_and_filters(); |
| 69 |
} |
| 70 |
|
| 71 |
/** |
| 72 |
* Profile fields to be displayed. |
| 73 |
* |
| 74 |
* @return array |
| 75 |
* @access public |
| 76 |
* @since 1.0.0 |
| 77 |
*/ |
| 78 |
public function get_fields() { |
| 79 |
$fields = apply_filters( 'charitable_user_registration_fields', array( |
| 80 |
'user_email' => array( |
| 81 |
'label' => __( 'Email', 'charitable' ), |
| 82 |
'type' => 'email', |
| 83 |
'required' => true, |
| 84 |
'priority' => 4, |
| 85 |
'value' => isset( $_POST[ 'user_email' ] ) ? $_POST[ 'user_email' ] : '' |
| 86 |
), |
| 87 |
'user_login' => array( |
| 88 |
'label' => __( 'Username', 'charitable' ), |
| 89 |
'type' => 'text', |
| 90 |
'priority' => 6, |
| 91 |
'required' => true, |
| 92 |
'value' => isset( $_POST[ 'user_login' ] ) ? $_POST[ 'user_login' ] : '' |
| 93 |
), |
| 94 |
'user_pass' => array( |
| 95 |
'label' => __( 'Password', 'charitable' ), |
| 96 |
'type' => 'password', |
| 97 |
'priority' => 8, |
| 98 |
'required' => true, |
| 99 |
'value' => isset( $_POST[ 'user_pass' ] ) ? $_POST[ 'user_pass' ] : '' |
| 100 |
) |
| 101 |
) ); |
| 102 |
|
| 103 |
uasort( $fields, 'charitable_priority_sort' ); |
| 104 |
|
| 105 |
return $fields; |
| 106 |
} |
| 107 |
|
| 108 |
/** |
| 109 |
* Update registration after form submission. |
| 110 |
* |
| 111 |
* @return void |
| 112 |
* @access public |
| 113 |
* @static |
| 114 |
* @since 1.0.0 |
| 115 |
*/ |
| 116 |
public static function save_registration() { |
| 117 |
$form = new Charitable_Registration_Form(); |
| 118 |
|
| 119 |
if ( ! $form->validate_nonce() ) { |
| 120 |
return; |
| 121 |
} |
| 122 |
|
| 123 |
$fields = $form->get_fields(); |
| 124 |
|
| 125 |
$valid = $form->check_required_fields( $fields ); |
| 126 |
|
| 127 |
if ( ! $valid ) { |
| 128 |
return; |
| 129 |
} |
| 130 |
|
| 131 |
$submitted = apply_filters( 'charitable_registration_values', $_POST, $fields, $form ); |
| 132 |
|
| 133 |
$user = new Charitable_User(); |
| 134 |
$user_id = $user->update_profile( $submitted, array_keys( $fields ) ); |
| 135 |
|
| 136 |
/** |
| 137 |
* If the user was successfully created, redirect to the login redirect URL. |
| 138 |
* If there was a problem, this simply falls through and keeps the user on the |
| 139 |
* registration page. |
| 140 |
*/ |
| 141 |
if ( $user_id ) { |
| 142 |
wp_safe_redirect( charitable_get_login_redirect_url() ); |
| 143 |
exit(); |
| 144 |
} |
| 145 |
} |
| 146 |
} |
| 147 |
|
| 148 |
endif; // End class_exists check |