/core/um-actions-account.php

  1. <?php 
  2.  
  3. /*** 
  4. *** @submit account page changes 
  5. ***/ 
  6. add_action('um_submit_account_details', 'um_submit_account_details'); 
  7. function um_submit_account_details( $args ) { 
  8. global $ultimatemember; 
  9.  
  10. $tab = ( get_query_var('um_tab') ) ? get_query_var('um_tab') : 'general'; 
  11.  
  12. if ( $_POST['user_password'] && $_POST['confirm_user_password'] ) { 
  13. $changes['user_pass'] = $_POST['user_password']; 
  14.  
  15. add_filter('send_password_change_email', 'um_send_password_change_email'); 
  16.  
  17. wp_set_password( $changes['user_pass'], um_user('ID') ); 
  18.  
  19. wp_signon( array('user_login' => um_user('user_login'), 'user_password' => $changes['user_pass']) ); 
  20.  
  21. $arr_fields = array(); 
  22. $secure_fields = get_user_meta( um_user('ID'), 'um_account_secure_fields', true ); 
  23. if( isset( $secure_fields ) ) { 
  24. foreach ( $secure_fields as $tab_key => $fields ) { 
  25. if( isset( $fields ) ) { 
  26. foreach ($fields as $key => $value) { 
  27. $arr_fields[ ] = $key; 
  28.  
  29. $changes = array(); 
  30. foreach( $_POST as $k => $v ) { 
  31. if ( !strstr( $k, 'password' ) && !strstr( $k, 'um_account' ) && in_array( $k, $arr_fields ) ) { 
  32. $changes[ $k ] = $v; 
  33. }  
  34.  
  35. if ( isset( $changes['hide_in_members'] ) && $changes['hide_in_members'] == __('No', 'ultimatemember') ) { 
  36. delete_user_meta( um_user('ID'), 'hide_in_members' ); 
  37. unset( $changes['hide_in_members'] ); 
  38.  
  39. // fired on account page, just before updating profile 
  40. do_action('um_account_pre_update_profile', $changes, um_user('ID') ); 
  41.  
  42. $ultimatemember->user->update_profile( $changes ); 
  43.  
  44. // delete account 
  45. $user = get_user_by('login', um_user('user_login') ); 
  46. $current_tab = isset( $_POST['_um_account_tab'] ) ? $_POST['_um_account_tab']: ''; 
  47.  
  48. if ( isset( $_POST['single_user_password'] ) && wp_check_password( $_POST['single_user_password'], $user->data->user_pass, $user->data->ID ) && $current_tab == 'delete' ) { 
  49. if ( current_user_can('delete_users') || um_user('can_delete_profile') ) { 
  50. if ( !um_user('super_admin') ) { 
  51. $ultimatemember->user->delete(); 
  52. if ( um_user('after_delete') && um_user('after_delete') == 'redirect_home' ) { 
  53. um_redirect_home(); 
  54. } elseif ( um_user('delete_redirect_url') ) { 
  55. exit( wp_redirect( um_user('delete_redirect_url') ) ); 
  56. } else { 
  57. um_redirect_home(); 
  58.  
  59. do_action('um_post_account_update'); 
  60.  
  61. do_action('um_after_user_account_updated', get_current_user_id() ); 
  62.  
  63. $url = $ultimatemember->account->tab_link( $tab ); 
  64.  
  65. $url = add_query_arg( 'updated', 'account', $url ); 
  66.  
  67. if ( function_exists('icl_get_current_language') ) { 
  68. if ( icl_get_current_language() != icl_get_default_language() ) { 
  69. $url = $ultimatemember->permalinks->get_current_url( true ); 
  70. $url = add_query_arg( 'updated', 'account', $url ); 
  71. exit( wp_redirect( $url ) ); 
  72.  
  73. exit( wp_redirect( $url ) ); 
  74.  
  75.  
  76. /*** 
  77. *** @validate for errors in account page 
  78. ***/ 
  79. add_action('um_submit_account_errors_hook', 'um_submit_account_errors_hook'); 
  80. function um_submit_account_errors_hook( $args ) { 
  81. global $ultimatemember; 
  82.  
  83. $current_tab = isset( $_POST['_um_account_tab'] ) ? $_POST['_um_account_tab']: ''; 
  84. $user = get_user_by('login', um_user('user_login') ); 
  85.  
  86. if( isset( $_POST['_um_account_tab'] ) && $current_tab != "delete" ) { 
  87. // errors on general tab 
  88. if ( isset($_POST['um_account_submit']) ) { 
  89.  
  90. if( $current_tab != 'password' ) { 
  91.  
  92. $account_name_require = um_get_option("account_name_require"); 
  93.  
  94. if ( isset($_POST['first_name']) && ( strlen(trim( $_POST['first_name'] ) ) == 0 && $account_name_require ) ) { 
  95. $ultimatemember->form->add_error('first_name', __('You must provide your first name', 'ultimatemember') ); 
  96.  
  97. if ( isset($_POST['last_name']) && ( strlen(trim( $_POST['last_name'] ) ) == 0 && $account_name_require ) ) { 
  98. $ultimatemember->form->add_error('last_name', __('You must provide your last name', 'ultimatemember') ); 
  99.  
  100. if ( isset($_POST['user_email']) && strlen(trim( $_POST['user_email'] ) ) == 0 ) { 
  101. $ultimatemember->form->add_error('user_email', __('You must provide your e-mail', 'ultimatemember') ); 
  102.  
  103. if ( isset($_POST['user_email']) && !is_email( $_POST['user_email'] ) ) { 
  104. $ultimatemember->form->add_error('user_email', __('Please provide a valid e-mail', 'ultimatemember') ); 
  105.  
  106. if ( email_exists( $_POST['user_email'] ) && email_exists( $_POST['user_email'] ) != get_current_user_id() ) { 
  107. $ultimatemember->form->add_error('user_email', __('Email already linked to another account', 'ultimatemember') ); 
  108.  
  109. $ultimatemember->account->current_tab = 'general'; 
  110.  
  111. // change password 
  112. if ( ( isset( $_POST['current_user_password'] ) && $_POST['current_user_password'] != '' ) || 
  113. ( isset( $_POST['user_password'] ) && $_POST['user_password'] != '' ) ||  
  114. ( isset( $_POST['confirm_user_password'] ) && $_POST['confirm_user_password'] != '') ) { 
  115.  
  116. if ( $_POST['current_user_password'] == '' || ! wp_check_password( $_POST['current_user_password'], $user->data->user_pass, $user->data->ID ) ) { 
  117.  
  118. $ultimatemember->form->add_error('current_user_password', __('This is not your password', 'ultimatemember') ); 
  119. $ultimatemember->account->current_tab = 'password'; 
  120. } else { // correct password 
  121.  
  122. if ( $_POST['user_password'] != $_POST['confirm_user_password'] && $_POST['user_password'] ) { 
  123. $ultimatemember->form->add_error('user_password', __('Your new password does not match', 'ultimatemember') ); 
  124. $ultimatemember->account->current_tab = 'password'; 
  125.  
  126. if ( um_get_option('account_require_strongpass') ) { 
  127.  
  128. if ( strlen( utf8_decode( $_POST['user_password'] ) ) < 8 ) { 
  129. $ultimatemember->form->add_error('user_password', __('Your password must contain at least 8 characters', 'ultimatemember') ); 
  130.  
  131. if ( strlen( utf8_decode( $_POST['user_password'] ) ) > 30 ) { 
  132. $ultimatemember->form->add_error('user_password', __('Your password must contain less than 30 characters', 'ultimatemember') ); 
  133.  
  134. if ( !$ultimatemember->validation->strong_pass( $_POST['user_password'] ) ) { 
  135. $ultimatemember->form->add_error('user_password', __('Your password must contain at least one lowercase letter, one capital letter and one number', 'ultimatemember') ); 
  136. $ultimatemember->account->current_tab = 'password'; 
  137.  
  138.  
  139.  
  140. if ( ! empty( $_POST['user_login'] ) && ! validate_username( $_POST['user_login'] ) ) { 
  141. $ultimatemember->form->add_error('user_login', __('Your username is invalid', 'ultimatemember') ); 
  142. return; 
  143. // delete account 
  144. if ( isset( $_POST['um_account_submit'] ) && $_POST['_um_account_tab'] == "delete" ) { 
  145. if ( strlen(trim( $_POST['single_user_password'] ) ) == 0 ) { 
  146. $ultimatemember->form->add_error('single_user_password', __('You must enter your password', 'ultimatemember') ); 
  147. } else { 
  148. if ( ! wp_check_password( $_POST['single_user_password'], $user->data->user_pass, $user->data->ID ) ) { 
  149. $ultimatemember->form->add_error('single_user_password', __('This is not your password', 'ultimatemember') ); 
  150.  
  151. $ultimatemember->account->current_tab = 'delete'; 
  152.  
  153.  
  154. /*** 
  155. *** @hidden inputs for account page 
  156. ***/ 
  157. add_action('um_account_page_hidden_fields', 'um_account_page_hidden_fields'); 
  158. function um_account_page_hidden_fields( $args ) { 
  159. global $ultimatemember; 
  160. ?> 
  161.  
  162. <input type="hidden" name="_um_account" id="_um_account" value="1" /> 
  163.  
  164. <?php $current_tab = $ultimatemember->account->current_tab; ?> 
  165.  
  166. <input type="hidden" name="_um_account_tab" id="_um_account_tab" value="<?php echo $current_tab;?>" /> 
  167.  
  168. <?php 
  169.  
  170.  
  171. /*** 
  172. *** @display tab "Delete" 
  173. ***/ 
  174. add_action('um_account_tab__delete', 'um_account_tab__delete'); 
  175. function um_account_tab__delete( $info ) { 
  176. global $ultimatemember; 
  177. extract( $info ); 
  178.  
  179. $output = $ultimatemember->account->get_tab_output('delete'); 
  180.  
  181. if ( $output ) { ?> 
  182.  
  183. <div class="um-account-heading uimob340-hide uimob500-hide"><i class="<?php echo $icon; ?>"></i><?php echo $title; ?></div> 
  184.  
  185. <?php echo wpautop( um_get_option('delete_account_text') ); ?> 
  186.  
  187. <?php echo $output; ?> 
  188.  
  189. <?php do_action('um_after_account_delete'); ?> 
  190.  
  191. <div class="um-col-alt um-col-alt-b"> 
  192. <div class="um-left"><input type="submit" name="um_account_submit" id="um_account_submit" value="<?php _e('Delete Account', 'ultimatemember'); ?>" class="um-button" /></div> 
  193. <?php do_action('um_after_account_delete_button'); ?> 
  194. <div class="um-clear"></div> 
  195. </div> 
  196.  
  197. <?php 
  198.  
  199.  
  200.  
  201. /*** 
  202. *** @display tab "Privacy" 
  203. ***/ 
  204. add_action('um_account_tab__privacy', 'um_account_tab__privacy'); 
  205. function um_account_tab__privacy( $info ) { 
  206. global $ultimatemember; 
  207. extract( $info ); 
  208.  
  209. $output = $ultimatemember->account->get_tab_output('privacy'); 
  210.  
  211. if ( $output ) { ?> 
  212.  
  213. <div class="um-account-heading uimob340-hide uimob500-hide"><i class="<?php echo $icon; ?>"></i><?php echo $title; ?></div> 
  214.  
  215. <?php echo $output; ?> 
  216.  
  217. <?php do_action('um_after_account_privacy'); ?> 
  218.  
  219. <div class="um-col-alt um-col-alt-b"> 
  220. <div class="um-left"><input type="submit" name="um_account_submit" id="um_account_submit" value="<?php _e('Update Privacy', 'ultimatemember'); ?>" class="um-button" /></div> 
  221. <?php do_action('um_after_account_privacy_button'); ?> 
  222. <div class="um-clear"></div> 
  223. </div> 
  224.  
  225. <?php 
  226.  
  227.  
  228.  
  229. /*** 
  230. *** @display tab "General" 
  231. ***/ 
  232. add_action('um_account_tab__general', 'um_account_tab__general'); 
  233. function um_account_tab__general( $info ) { 
  234. global $ultimatemember; 
  235. extract( $info ); 
  236.  
  237. $output = $ultimatemember->account->get_tab_output('general'); 
  238.  
  239. if ( $output ) { ?> 
  240.  
  241. <div class="um-account-heading uimob340-hide uimob500-hide"><i class="<?php echo $icon; ?>"></i><?php echo $title; ?></div> 
  242.  
  243. <?php echo $output; ?> 
  244.  
  245. <?php do_action('um_after_account_general'); ?> 
  246.  
  247. <div class="um-col-alt um-col-alt-b"> 
  248. <div class="um-left"><input type="submit" name="um_account_submit" id="um_account_submit" value="<?php _e('Update Account', 'ultimatemember'); ?>" class="um-button" /></div> 
  249. <?php do_action('um_after_account_general_button'); ?> 
  250. <div class="um-clear"></div> 
  251. </div> 
  252.  
  253. <?php 
  254.  
  255.  
  256.  
  257. /*** 
  258. *** @display tab "Password" 
  259. ***/ 
  260. add_action('um_account_tab__password', 'um_account_tab__password'); 
  261. function um_account_tab__password( $info ) { 
  262. global $ultimatemember; 
  263. extract( $info ); 
  264.  
  265. $output = $ultimatemember->account->get_tab_output('password'); 
  266.  
  267. if ( $output ) { ?> 
  268.  
  269. <div class="um-account-heading uimob340-hide uimob500-hide"><i class="<?php echo $icon; ?>"></i><?php echo $title; ?></div> 
  270.  
  271. <?php echo $output; ?> 
  272.  
  273. <?php do_action('um_after_account_password'); ?> 
  274.  
  275. <div class="um-col-alt um-col-alt-b"> 
  276. <div class="um-left"><input type="submit" name="um_account_submit" id="um_account_submit" value="<?php _e('Update Password', 'ultimatemember'); ?>" class="um-button" /></div> 
  277. <?php do_action('um_after_account_password_button'); ?> 
  278. <div class="um-clear"></div> 
  279. </div> 
  280.  
  281. <?php 
  282.  
  283.  
  284.  
  285. /*** 
  286. *** @display tab "Notifications" 
  287. ***/ 
  288. add_action('um_account_tab__notifications', 'um_account_tab__notifications'); 
  289. function um_account_tab__notifications( $info ) { 
  290. global $ultimatemember; 
  291. extract( $info ); 
  292.  
  293. $output = $ultimatemember->account->get_tab_output('notifications'); 
  294.  
  295. if ( $output ) { ?> 
  296.  
  297. <div class="um-account-heading uimob340-hide uimob500-hide"><i class="<?php echo $icon; ?>"></i><?php echo $title; ?></div> 
  298.  
  299. <?php if ( class_exists('UM_Messaging_API') || class_exists('UM_Followers_API') ) { ?> 
  300. <div class="um-field"> 
  301. <div class="um-field-label"><label for=""><?php _e('Email me when', 'ultimatemember'); ?></label><div class="um-clear"></div></div> 
  302. </div> 
  303. <?php } ?> 
  304.  
  305. <?php echo $output; ?> 
  306.  
  307. <?php do_action('um_after_account_notifications'); ?> 
  308.  
  309. <div class="um-col-alt um-col-alt-b"> 
  310. <div class="um-left"><input type="submit" name="um_account_submit" id="um_account_submit" value="<?php _e('Update Notifications', 'ultimatemember'); ?>" class="um-button" /></div> 
  311. <?php do_action('um_after_account_notifications_button'); ?> 
  312. <div class="um-clear"></div> 
  313. </div> 
  314.  
  315. <?php 
  316.  
  317.  
  318.  
  319. /*** 
  320. *** @display account photo and username 
  321. ***/ 
  322. add_action('um_account_user_photo_hook__mobile', 'um_account_user_photo_hook__mobile'); 
  323. function um_account_user_photo_hook__mobile( $args ) { 
  324. global $ultimatemember; 
  325. extract( $args ); 
  326.  
  327. ?> 
  328.  
  329. <div class="um-account-meta radius-<?php echo um_get_option('profile_photocorner'); ?> uimob340-show uimob500-show"> 
  330.  
  331. <div class="um-account-meta-img"><a href="<?php echo um_user_profile_url(); ?>"><?php echo get_avatar( um_user('ID'), 120); ?></a></div> 
  332.  
  333. <div class="um-account-name"> 
  334. <a href="<?php echo um_user_profile_url(); ?>"><?php echo um_user('display_name'); ?></a> 
  335. <div class="um-account-profile-link"><a href="<?php echo um_user_profile_url(); ?>" class="um-link"><?php _e('View profile', 'ultimatemember'); ?></a></div> 
  336. </div> 
  337.  
  338. </div> 
  339.  
  340. <?php 
  341.  
  342.  
  343. /*** 
  344. *** @display account photo and username 
  345. ***/ 
  346. add_action('um_account_user_photo_hook', 'um_account_user_photo_hook'); 
  347. function um_account_user_photo_hook( $args ) { 
  348. global $ultimatemember; 
  349. extract( $args ); 
  350.  
  351. ?> 
  352.  
  353. <div class="um-account-meta radius-<?php echo um_get_option('profile_photocorner'); ?>"> 
  354.  
  355. <div class="um-account-meta-img uimob800-hide"><a href="<?php echo um_user_profile_url(); ?>"><?php echo get_avatar( um_user('ID'), 120); ?></a></div> 
  356.  
  357. <?php if ( $ultimatemember->mobile->isMobile() ) { ?> 
  358.  
  359. <div class="um-account-meta-img-b uimob800-show" title="<?php echo um_user('display_name'); ?>"><a href="<?php echo um_user_profile_url(); ?>"><?php echo get_avatar( um_user('ID'), 120); ?></a></div> 
  360.  
  361. <?php } else { ?> 
  362.  
  363. <div class="um-account-meta-img-b uimob800-show um-tip-w" title="<?php echo um_user('display_name'); ?>"><a href="<?php echo um_user_profile_url(); ?>"><?php echo get_avatar( um_user('ID'), 120); ?></a></div> 
  364.  
  365. <?php } ?> 
  366.  
  367. <div class="um-account-name uimob800-hide"> 
  368. <a href="<?php echo um_user_profile_url(); ?>"><?php echo um_user('display_name', 'html'); ?></a> 
  369. <div class="um-account-profile-link"><a href="<?php echo um_user_profile_url(); ?>" class="um-link"><?php _e('View profile', 'ultimatemember'); ?></a></div> 
  370. </div> 
  371.  
  372. </div> 
  373.  
  374. <?php 
  375.  
  376.  
  377. /*** 
  378. *** @display account page tabs 
  379. ***/ 
  380. add_action('um_account_display_tabs_hook', 'um_account_display_tabs_hook'); 
  381. function um_account_display_tabs_hook( $args ) { 
  382. global $ultimatemember; 
  383. extract( $args ); 
  384.  
  385. $ultimatemember->account->tabs = apply_filters('um_account_page_default_tabs_hook', $tabs=array() ); 
  386.  
  387. ksort( $ultimatemember->account->tabs ); 
  388.  
  389. ?> 
  390.  
  391. <ul> 
  392.  
  393. <?php 
  394.  
  395. foreach( $ultimatemember->account->tabs as $k => $arr ) { 
  396. foreach( $arr as $id => $info ) { extract( $info ); 
  397.  
  398. $current_tab = $ultimatemember->account->current_tab; 
  399.  
  400. if ( isset($info['custom']) || um_get_option('account_tab_'.$id ) == 1 || $id == 'general' ) { ?> 
  401.  
  402. <li> 
  403. <a data-tab="<?php echo $id; ?>" href="<?php echo $ultimatemember->account->tab_link($id); ?>" class="um-account-link <?php if ( $id == $current_tab ) echo 'current'; ?>"> 
  404.  
  405. <?php if ( $ultimatemember->mobile->isMobile() ) { ?> 
  406. <span class="um-account-icontip uimob800-show" title="<?php echo $title; ?>"><i class="<?php echo $icon; ?>"></i></span> 
  407. <?php } else { ?> 
  408. <span class="um-account-icontip uimob800-show um-tip-w" title="<?php echo $title; ?>"><i class="<?php echo $icon; ?>"></i></span> 
  409. <?php } ?> 
  410.  
  411. <span class="um-account-icon uimob800-hide"><i class="<?php echo $icon; ?>"></i></span> 
  412. <span class="um-account-title uimob800-hide"><?php echo $title; ?></span> 
  413. <span class="um-account-arrow uimob800-hide"><?php echo ( is_rtl() ) ? '<i class="um-faicon-angle-left"></i>' : '<i class="um-faicon-angle-right"></i>'; ?></span> 
  414. </a> 
  415. </li> 
  416.  
  417. <?php 
  418.  
  419.  
  420. ?> 
  421.  
  422. </ul> 
  423.  
  424. <?php 
  425.  
.