/app/view/shortcode/class-ms-view-shortcode-registeruser.php

  1. <?php 
  2.  
  3. class MS_View_Shortcode_RegisterUser extends MS_View { 
  4.  
  5. public function to_html() { 
  6. $fields = $this->prepare_fields(); 
  7.  
  8. // When redirecting to login form we want to keep the previously submitted form data. 
  9. $url_data = $_POST; 
  10. $url_data['do-login'] = '1'; 
  11. $login_url = esc_url_raw( add_query_arg( $url_data ) ); 
  12.  
  13. if ( ! empty( $_REQUEST['do-login'] ) ) { 
  14. $register_url = esc_url_raw( remove_query_arg( 'do-login' ) ); 
  15.  
  16. $back_link = array( 
  17. 'url' => $register_url,  
  18. 'class' => 'alignleft',  
  19. 'value' => __( 'Cancel', MS_TEXT_DOMAIN ),  
  20. ); 
  21.  
  22. $html = do_shortcode( 
  23. sprintf( 
  24. '[%s show_note=false title="%s"]',  
  25. MS_Helper_Shortcode::SCODE_LOGIN,  
  26. __( 'Login', MS_TEXT_DOMAIN ) 
  27. ); 
  28. $html .= MS_Helper_Html::html_link( $back_link, true ); 
  29. return $html; 
  30.  
  31. $login_link = array( 
  32. 'title' => __( 'Login', MS_TEXT_DOMAIN ),  
  33. 'url' => $login_url,  
  34. 'class' => 'alignleft',  
  35. 'value' => __( 'Already have a user account?', MS_TEXT_DOMAIN ),  
  36. ); 
  37.  
  38. $register_button = array( 
  39. 'id' => 'register',  
  40. 'type' => MS_Helper_Html::INPUT_TYPE_SUBMIT,  
  41. 'value' => $this->data['label_register'],  
  42. ); 
  43.  
  44. $title = $this->data['title']; 
  45. ob_start(); 
  46.  
  47. $reg_url = MS_Model_Pages::get_page_url( MS_Model_Pages::MS_PAGE_REGISTER ); 
  48. $reg_url = esc_url_raw( 
  49. add_query_arg( 'action', 'register_user', $reg_url ) 
  50. ); 
  51.  
  52. // Default WP action hook 
  53. do_action( 'before_signup_form' ); 
  54. ?> 
  55. <div class="ms-membership-form-wrapper"> 
  56. <?php $this->render_errors(); ?> 
  57. <form id="ms-shortcode-register-user-form" class="form-membership" action="<?php echo esc_url( $reg_url ); ?>" method="post"> 
  58. <?php wp_nonce_field( $this->data['action'] ); ?> 
  59. <?php if ( ! empty( $title ) ) : ?> 
  60. <legend> 
  61. <?php echo '' . $title; ?> 
  62. </legend> 
  63. <?php endif; ?> 
  64.  
  65. <?php foreach ( $fields as $field ) { 
  66. if ( MS_Helper_Html::INPUT_TYPE_HIDDEN == $field['type'] ) { 
  67. MS_Helper_Html::html_element( $field ); 
  68. } else { 
  69. ?> 
  70. <div class="ms-form-element ms-form-element-<?php echo esc_attr( $field['id'] ); ?>"> 
  71. <?php MS_Helper_Html::html_element( $field ); ?> 
  72. </div> 
  73. <?php 
  74.  
  75. /** 
  76. * Trigger default WordPress action to allow other plugins 
  77. * to add custom fields to the registration form. 
  78. * 
  79. * @since 1.1.0 
  80. */ 
  81. do_action( 'register_form' ); 
  82. do_action( 'signup_extra_fields', array() ); 
  83.  
  84. MS_Helper_Html::html_element( $register_button ); 
  85.  
  86. if ( is_wp_error( $this->error ) ) { 
  87. /** 
  88. * Display registration errors. 
  89. * 
  90. * @since 1.1.0 
  91. */ 
  92. do_action( 'registration_errors', $this->error ); 
  93. ?> 
  94. </form> 
  95. <?php 
  96. if ( $this->data['loginlink'] ) { 
  97. MS_Helper_Html::html_link( $login_link ); 
  98. ?> 
  99. </div> 
  100. <?php 
  101. // Default WP action hook
  102. do_action( 'signup_blogform', array() ); 
  103. do_action( 'after_signup_form' ); 
  104.  
  105. $html = ob_get_clean(); 
  106.  
  107. return apply_filters( 
  108. 'ms_shortcode_register',  
  109. $html,  
  110. $this->data 
  111. ); 
  112.  
  113. public function prepare_fields() { 
  114. $data = $this->data; 
  115.  
  116. $fields = array( 
  117. 'membership_id' => array( 
  118. 'id' => 'membership_id',  
  119. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  120. 'value' => $data['membership_id'],  
  121. ),  
  122.  
  123. 'first_name' => array( 
  124. 'id' => 'first_name',  
  125. 'title' => $data['label_first_name'],  
  126. 'placeholder' => $data['hint_first_name'],  
  127. 'type' => MS_Helper_Html::INPUT_TYPE_TEXT,  
  128. 'value' => $data['first_name'],  
  129. ),  
  130.  
  131. 'last_name' => array( 
  132. 'id' => 'last_name',  
  133. 'title' => $data['label_last_name'],  
  134. 'placeholder' => $data['hint_last_name'],  
  135. 'type' => MS_Helper_Html::INPUT_TYPE_TEXT,  
  136. 'value' => $data['last_name'],  
  137. ),  
  138.  
  139. 'username' => array( 
  140. 'id' => 'username',  
  141. 'title' => $data['label_username'],  
  142. 'placeholder' => $data['hint_username'],  
  143. 'type' => MS_Helper_Html::INPUT_TYPE_TEXT,  
  144. 'value' => $data['username'],  
  145. ),  
  146.  
  147. 'email' => array( 
  148. 'id' => 'email',  
  149. 'title' => $data['label_email'],  
  150. 'placeholder' => $data['hint_email'],  
  151. 'type' => MS_Helper_Html::INPUT_TYPE_TEXT,  
  152. 'value' => $data['email'],  
  153. ),  
  154.  
  155. 'password' => array( 
  156. 'id' => 'password',  
  157. 'title' => $data['label_password'],  
  158. 'placeholder' => $data['hint_password'],  
  159. 'type' => MS_Helper_Html::INPUT_TYPE_PASSWORD,  
  160. 'value' => '',  
  161. ),  
  162.  
  163. 'password2' => array( 
  164. 'id' => 'password2',  
  165. 'title' => $data['label_password2'],  
  166. 'placeholder' => $data['hint_password2'],  
  167. 'type' => MS_Helper_Html::INPUT_TYPE_PASSWORD,  
  168. 'value' => '',  
  169. ),  
  170.  
  171. 'action' => array( 
  172. 'id' => 'action',  
  173. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  174. 'value' => $data['action'],  
  175. ),  
  176.  
  177. 'step' => array( 
  178. 'id' => 'step',  
  179. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  180. 'value' => $data['step'],  
  181. ),  
  182. ); 
  183.  
  184. return $fields; 
  185.  
  186. /** 
  187. * Renders error messages. 
  188. * 
  189. * @access private 
  190. */ 
  191. private function render_errors() { 
  192. if ( ! empty( $this->data['errors'] ) ) { 
  193. ?> 
  194. <div class="ms-alert-box ms-alert-error"> 
  195. <?php echo $this->data['errors']; ?> 
  196. </div> 
  197. <?php 
  198.  
.