UM_Account

The Ultimate Member UM Account class.

Defined (1)

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

/core/um-account.php  
  1. class UM_Account { 
  2.  
  3. function __construct() { 
  4.  
  5. add_shortcode('ultimatemember_account', array(&$this, 'ultimatemember_account'), 1); 
  6.  
  7. add_filter('um_account_page_default_tabs_hook', array(&$this, 'core_tabs'), 1); 
  8.  
  9. add_action('template_redirect', array(&$this, 'account'), 10001 ); 
  10.  
  11. add_action('template_redirect', array(&$this, 'form_init'), 10002); 
  12.  
  13. add_filter('um_predefined_fields_hook', array(&$this, 'predefined_fields_hook'), 1 ); 
  14.  
  15. $this->current_tab = 'general'; 
  16.  
  17.  
  18. /*** 
  19. *** @get core account tabs 
  20. ***/ 
  21. function core_tabs() { 
  22.  
  23. $tabs[100]['general']['icon'] = 'um-faicon-user'; 
  24. $tabs[100]['general']['title'] = __('Account', 'ultimatemember'); 
  25.  
  26. $tabs[200]['password']['icon'] = 'um-faicon-asterisk'; 
  27. $tabs[200]['password']['title'] = __('Change Password', 'ultimatemember'); 
  28.  
  29. $tabs[300]['privacy']['icon'] = 'um-faicon-lock'; 
  30. $tabs[300]['privacy']['title'] = __('Privacy', 'ultimatemember'); 
  31.  
  32. $tabs[400]['notifications']['icon'] = 'um-faicon-envelope'; 
  33. $tabs[400]['notifications']['title'] = __('Notifications', 'ultimatemember'); 
  34.  
  35. $tabs[9999]['delete']['icon'] = 'um-faicon-trash-o'; 
  36. $tabs[9999]['delete']['title'] = __('Delete Account', 'ultimatemember'); 
  37.  
  38. return $tabs; 
  39.  
  40. /*** 
  41. *** @account page form 
  42. ***/ 
  43. function form_init() { 
  44. global $ultimatemember; 
  45.  
  46. if ( um_submitting_account_page() ) { 
  47.  
  48. $ultimatemember->form->post_form = $_POST; 
  49.  
  50. do_action('um_submit_account_errors_hook', $ultimatemember->form->post_form ); 
  51.  
  52. if ( !isset($ultimatemember->form->errors) ) { 
  53.  
  54. if ( get_query_var('um_tab') ) { 
  55. $this->current_tab = get_query_var('um_tab'); 
  56.  
  57. do_action('um_submit_account_details', $ultimatemember->form->post_form ); 
  58.  
  59.  
  60.  
  61.  
  62. /*** 
  63. *** @can access account page 
  64. ***/ 
  65. function account() { 
  66. global $ultimatemember; 
  67.  
  68. if ( um_is_core_page('account') && !is_user_logged_in() ) { 
  69.  
  70. $redirect_to = add_query_arg(  
  71. 'redirect_to',  
  72. urlencode_deep( um_get_core_page('account') ) ,  
  73. um_get_core_page('login')  
  74. ); 
  75.  
  76. exit( wp_redirect( $redirect_to ) ); 
  77.  
  78.  
  79. if ( um_is_core_page('account') ) { 
  80.  
  81. $ultimatemember->fields->set_mode = 'account'; 
  82.  
  83. $ultimatemember->fields->editing = true; 
  84.  
  85. if ( get_query_var('um_tab') ) { 
  86. $this->current_tab = get_query_var('um_tab'); 
  87.  
  88.  
  89.  
  90. /*** 
  91. *** @get tab link 
  92. ***/ 
  93. function tab_link( $id ) { 
  94.  
  95. if ( get_option('permalink_structure') ) { 
  96.  
  97. $url = trailingslashit( untrailingslashit( um_get_core_page('account') ) ); 
  98. $url = $url . $id . '/'; 
  99.  
  100. } else { 
  101.  
  102. $url = add_query_arg( 'um_tab', $id, um_get_core_page('account') ); 
  103.  
  104.  
  105. return $url; 
  106.  
  107. /*** 
  108. *** @Add class based on shortcode 
  109. ***/ 
  110. function get_class( $mode ) { 
  111.  
  112. global $ultimatemember; 
  113.  
  114. $classes = 'um-'.$mode; 
  115.  
  116. if ( is_admin() ) { 
  117. $classes .= ' um-in-admin'; 
  118.  
  119. if ( $ultimatemember->fields->editing == true ) { 
  120. $classes .= ' um-editing'; 
  121.  
  122. if ( $ultimatemember->fields->viewing == true ) { 
  123. $classes .= ' um-viewing'; 
  124.  
  125. $classes = apply_filters('um_form_official_classes__hook', $classes); 
  126. return $classes; 
  127.  
  128. /*** 
  129. *** @get tab output 
  130. ***/ 
  131. function get_tab_output( $id ) { 
  132. global $ultimatemember; 
  133.  
  134. $output = null; 
  135.  
  136. switch( $id ) { 
  137.  
  138. case 'notifications': 
  139.  
  140. $output = apply_filters("um_account_content_hook_{$id}", $output); 
  141. return $output; 
  142.  
  143. break; 
  144.  
  145. case 'privacy': 
  146.  
  147. $args = 'profile_privacy, hide_in_members'; 
  148. $args = apply_filters('um_account_tab_privacy_fields', $args ); 
  149.  
  150. $fields = $ultimatemember->builtin->get_specific_fields( $args ); 
  151.  
  152. $fields = apply_filters('um_account_secure_fields', $fields, $id ); 
  153.  
  154. foreach( $fields as $key => $data ) { 
  155. $output .= $ultimatemember->fields->edit_field( $key, $data ); 
  156.  
  157. return $output; 
  158.  
  159. break; 
  160.  
  161. case 'delete': 
  162.  
  163. $args = 'single_user_password'; 
  164.  
  165. $fields = $ultimatemember->builtin->get_specific_fields( $args ); 
  166.  
  167. $fields = apply_filters('um_account_secure_fields', $fields, $id ); 
  168.  
  169. foreach( $fields as $key => $data ) { 
  170. $output .= $ultimatemember->fields->edit_field( $key, $data ); 
  171.  
  172. return $output; 
  173.  
  174. break; 
  175.  
  176. case 'general': 
  177.  
  178. $args = 'user_login, first_name, last_name, user_email'; 
  179.  
  180. if ( !um_get_option('account_name') ) { 
  181. $args = 'user_login, user_email'; 
  182.  
  183. if ( !um_get_option('account_email') && !um_user('can_edit_everyone') ) { 
  184. $args = str_replace(', user_email', '', $args ); 
  185.  
  186. $fields = $ultimatemember->builtin->get_specific_fields( $args ); 
  187.  
  188. $fields = apply_filters('um_account_secure_fields', $fields, $id ); 
  189.  
  190. foreach( $fields as $key => $data ) { 
  191. $output .= $ultimatemember->fields->edit_field( $key, $data ); 
  192.  
  193. return $output; 
  194.  
  195. break; 
  196.  
  197. case 'password': 
  198.  
  199. $args = 'user_password'; 
  200.  
  201. $fields = $ultimatemember->builtin->get_specific_fields( $args ); 
  202.  
  203. $fields = apply_filters('um_account_secure_fields', $fields, $id ); 
  204.  
  205. foreach( $fields as $key => $data ) { 
  206. $output .= $ultimatemember->fields->edit_field( $key, $data ); 
  207.  
  208. return $output; 
  209.  
  210. break; 
  211.  
  212. default : 
  213.  
  214. $output = apply_filters("um_account_content_hook_{$id}", $output); 
  215. return $output; 
  216.  
  217. break; 
  218.  
  219.  
  220. /*** 
  221. *** @Shortcode 
  222. ***/ 
  223. function ultimatemember_account( $args = array() ) { 
  224. return $this->load( $args ); 
  225.  
  226. /*** 
  227. *** @Load a module with global function 
  228. ***/ 
  229. function load( $args ) { 
  230.  
  231. global $ultimatemember; 
  232.  
  233. $ultimatemember->user->set( get_current_user_id() ); 
  234.  
  235. ob_start(); 
  236.  
  237. $defaults = array( 
  238. 'template' => 'account',  
  239. 'mode' => 'account',  
  240. 'form_id' => 'um_account_id',  
  241. ); 
  242. $args = wp_parse_args( $args, $defaults ); 
  243.  
  244. if ( isset( $args['use_globals'] ) && $args['use_globals'] == 1 ) { 
  245. $args = array_merge( $args, $this->get_css_args( $args ) ); 
  246. } else { 
  247. $args = array_merge( $this->get_css_args( $args ), $args ); 
  248.  
  249. $args = apply_filters('um_account_shortcode_args_filter', $args); 
  250.  
  251. extract( $args, EXTR_SKIP ); 
  252.  
  253. do_action("um_pre_{$mode}_shortcode", $args); 
  254.  
  255. do_action("um_before_form_is_loaded", $args); 
  256.  
  257. do_action("um_before_{$mode}_form_is_loaded", $args); 
  258.  
  259. $this->template_load( $template, $args ); 
  260.  
  261. if ( !is_admin() && !defined( 'DOING_AJAX' ) ) { 
  262. $this->dynamic_css( $args ); 
  263.  
  264. $output = ob_get_contents(); 
  265. ob_end_clean(); 
  266. return $output; 
  267.  
  268.  
  269. /*** 
  270. *** @Get dynamic css args 
  271. ***/ 
  272. function get_css_args( $args ) { 
  273. $arr = um_styling_defaults( $args['mode'] ); 
  274. $arr = array_merge( $arr, array( 'form_id' => $args['form_id'], 'mode' => $args['mode'] ) ); 
  275. return $arr; 
  276.  
  277. /*** 
  278. *** @Load dynamic css 
  279. ***/ 
  280. function dynamic_css( $args=array() ) { 
  281. extract($args); 
  282. $global = um_path . 'assets/dynamic_css/dynamic_global.php'; 
  283. $file = um_path . 'assets/dynamic_css/dynamic_'.$mode.'.php'; 
  284. include $global; 
  285. if ( file_exists( $file ) ) 
  286. include $file; 
  287.  
  288. /*** 
  289. *** @Loads a template file 
  290. ***/ 
  291. function template_load( $template, $args=array() ) { 
  292. global $ultimatemember; 
  293. if ( is_array( $args ) ) { 
  294. $ultimatemember->shortcodes->set_args = $args; 
  295. $ultimatemember->shortcodes->load_template( $template ); 
  296.  
  297. /*** 
  298. ** @filter account fields 
  299. ****/ 
  300. function predefined_fields_hook( $predefined_fields ) { 
  301.  
  302. $account_hide_in_directory = um_get_option('account_hide_in_directory'); 
  303. if( ! $account_hide_in_directory ) { 
  304. unset( $predefined_fields['hide_in_members'] ); 
  305.  
  306. return $predefined_fields;