MS_View_Frontend_Profile

The Membership 2 MS View Frontend Profile class.

Defined (1)

The class is defined in the following location(s).

/app/view/frontend/class-ms-view-frontend-profile.php  
  1. class MS_View_Frontend_Profile extends MS_View { 
  2.  
  3. /** 
  4. * Return the HTML code. 
  5. * @since 1.0.0 
  6. * @return string 
  7. */ 
  8. public function to_html() { 
  9. $fields = $this->prepare_fields(); 
  10.  
  11. $cancel = array( 
  12. 'id' => 'cancel',  
  13. 'type' => MS_Helper_Html::TYPE_HTML_LINK,  
  14. 'title' => __( 'Cancel', 'membership2' ),  
  15. 'value' => __( 'Cancel', 'membership2' ),  
  16. 'url' => esc_url_raw( remove_query_arg( array( 'action' ) ) ),  
  17. 'class' => 'wpmui-field-button button',  
  18. ); 
  19.  
  20. $this->add_action( 
  21. 'ms_view_frontend_profile_after_fields',  
  22. 'add_scripts' 
  23. ); 
  24.  
  25. ob_start(); 
  26. ?> 
  27. <div class="ms-membership-form-wrapper"> 
  28. <?php $this->render_errors() ?> 
  29. <form id="ms-view-frontend-profile-form" class="form-membership" action="" method="post"> 
  30. <legend><?php _e( 'Edit profile', 'membership2' ); ?></legend> 
  31. <?php foreach ( $fields as $field ) { 
  32. if ( is_string( $field ) ) { 
  33. MS_Helper_Html::html_element( $field ); 
  34. } elseif ( MS_Helper_Html::INPUT_TYPE_HIDDEN == $field['type'] ) { 
  35. MS_Helper_Html::html_element( $field ); 
  36. } else { 
  37. ?> 
  38. <div class="ms-form-element ms-form-element-<?php echo esc_attr( $field['id'] ); ?>"> 
  39. <?php MS_Helper_Html::html_element( $field ); ?> 
  40. </div> 
  41. <?php 
  42. do_action( 'ms_view_frontend_profile_after_fields' ); 
  43. do_action( 'ms_view_frontend_profile_extra_fields', $this->error ); 
  44. ?> 
  45. </form> 
  46. <div class="ms-form-element"> 
  47. <?php MS_Helper_Html::html_link( $cancel ); ?> 
  48. </div> 
  49. </div> 
  50. <?php 
  51. $html = ob_get_clean(); 
  52. $html = apply_filters( 'ms_compact_code', $html ); 
  53.  
  54. return $html; 
  55.  
  56. /** 
  57. * Prepare the fields that are displayed in the form. 
  58. * @since 1.0.0 
  59. * @return array 
  60. */ 
  61. public function prepare_fields() { 
  62. $member = $this->data['member']; 
  63.  
  64. $fields = array( 
  65. 'first_name' => array( 
  66. 'id' => 'first_name',  
  67. 'title' => __( 'First Name', 'membership2' ),  
  68. 'type' => MS_Helper_Html::INPUT_TYPE_TEXT,  
  69. 'value' => $member->first_name,  
  70. ),  
  71. 'last_name' => array( 
  72. 'id' => 'last_name',  
  73. 'title' => __( 'Last Name', 'membership2' ),  
  74. 'type' => MS_Helper_Html::INPUT_TYPE_TEXT,  
  75. 'value' => $member->last_name,  
  76. ),  
  77. 'email' => array( 
  78. 'id' => 'email',  
  79. 'title' => __( 'Email Address', 'membership2' ),  
  80. 'type' => MS_Helper_Html::INPUT_TYPE_TEXT,  
  81. 'value' => $member->email,  
  82. ),  
  83. 'password' => array( 
  84. 'id' => 'password',  
  85. 'title' => __( 'Password', 'membership2' ),  
  86. 'type' => MS_Helper_Html::INPUT_TYPE_PASSWORD,  
  87. 'value' => '',  
  88. ),  
  89. 'password2' => array( 
  90. 'id' => 'password2',  
  91. 'title' => __( 'Confirm Password', 'membership2' ),  
  92. 'type' => MS_Helper_Html::INPUT_TYPE_PASSWORD,  
  93. 'value' => '',  
  94. ),  
  95. 'submit' => array( 
  96. 'id' => 'submit',  
  97. 'type' => MS_Helper_Html::INPUT_TYPE_SUBMIT,  
  98. 'value' => __( 'Save Changes', 'membership2' ),  
  99. ),  
  100. '_wpnonce' => array( 
  101. 'id' => '_wpnonce',  
  102. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  103. 'value' => wp_create_nonce( $this->data['action'] ),  
  104. ),  
  105. 'action' => array( 
  106. 'id' => 'action',  
  107. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  108. 'value' => $this->data['action'],  
  109. ),  
  110. ); 
  111.  
  112. $fields = apply_filters( 
  113. 'ms_view_profile_fields',  
  114. $fields,  
  115. $this 
  116. ); 
  117.  
  118. return $fields; 
  119.  
  120. /** 
  121. * Outputs the javascript used by the registration form. 
  122. * @since 1.0.1.0 
  123. */ 
  124. static public function add_scripts() { 
  125. static $Scripts_Done = false; 
  126.  
  127. // Make sure to only execute that function once. 
  128. if ( $Scripts_Done ) { return; } 
  129. $Scripts_Done = true; 
  130.  
  131. $rule_data = array( 
  132. 'email' => array( 
  133. 'required' => true,  
  134. ),  
  135. 'password' => array( 
  136. 'minlength' => 5,  
  137. ),  
  138. 'password2' => array( 
  139. 'equalTo' => '#password',  
  140. ),  
  141. ); 
  142.  
  143. /** 
  144. * Allow other plugins or Add-ons to modify the validation rules on the 
  145. * registration page. 
  146. * @since 1.0.1.0 
  147. * @var array 
  148. */ 
  149. $rule_data = apply_filters( 
  150. 'ms_view_profile_form_rules',  
  151. $rule_data 
  152. ); 
  153.  
  154. ob_start(); 
  155. ?> 
  156. jQuery(function() { 
  157. var args = { 
  158. onkeyup: false,  
  159. errorClass: 'ms-validation-error',  
  160. rules: <?php echo json_encode( $rule_data ); ?> 
  161. }; 
  162.  
  163. jQuery( '#ms-view-frontend-profile-form' ).validate( args ); 
  164. }); 
  165. <?php 
  166. $script = ob_get_clean(); 
  167. lib3()->ui->script( $script ); 
  168.  
  169. /** 
  170. * Renders error messages. 
  171. * @since 1.0.0 
  172. * @internal 
  173. */ 
  174. protected function render_errors() { 
  175. if ( ! empty( $this->data['errors'] ) ) { 
  176. ?> 
  177. <div class="ms-alert-box ms-alert-error"> 
  178. <?php echo $this->data['errors']; ?> 
  179. </div> 
  180. <?php 
  181.