/** * Adjust the output of the first name/last name field to display a full name if the option is enabled. * If the option is enabled into the first name field, WPUM will display the first name + last name, * if the option is enabled into the last name field, WPUM will display the last name + first name. * * @param string $value the value of field. * @param string $field field object. * @return string output of this field. * @since 1.2.0 */ function wpum_adjust_name_meta_output($value, $field) { if (wpum_is_single_profile()) { if ($field->meta == 'first_name' && wpum_get_field_option($field->id, 'display_full_name')) { $value = $value . ' ' . wpum_get_user_lname(wpum_get_displayed_user_id()); } elseif ($field->meta == 'last_name' && wpum_get_field_option($field->id, 'display_full_name')) { $value = $value . ' ' . wpum_get_user_fname(wpum_get_displayed_user_id()); } } return $value; }
/** * Force 404 error if user or tabs do not exist. * * @since 1.0.0 * @access public * @return void */ function wpum_profile_force_404_error() { // Bail if not on the profile page if (!is_page(wpum_get_core_page_id('profile'))) { return; } // Bail if viewing single profile only and not another user profile if (!wpum_is_single_profile()) { return; } // Trigger if tab is set and does not exist if (wpum_get_current_profile_tab() !== null && !wpum_profile_tab_exists(wpum_get_current_profile_tab())) { wpum_trigger_404(); } // Trigger if profile is set and does not exist if (wpum_is_single_profile() && !wpum_user_exists(wpum_is_single_profile(), get_option('wpum_permalink'))) { wpum_trigger_404(); } }
/** * Retrieve the user id number of the currently displayed user. * This function works only within the profile page. * * @since 1.2.0 * @return mixed user id if found - false if not found. */ function wpum_get_displayed_user_id() { $user_id = false; $who = wpum_is_single_profile(); $structure = get_option('wpum_permalink', 'user_id'); // If we're on the profile but no user has been given, we return the current user id. if (!$who && !empty($structure) && is_page(wpum_get_core_page_id('profile'))) { return get_current_user_id(); } // Process the retrieved user. if ($who && !empty($structure)) { switch ($structure) { case 'user_id': $user_id = esc_attr($who); break; case 'username': $retrieve = get_user_by('login', esc_attr($who)); $user_id = $retrieve->data->ID; break; case 'nickname': // WP_User_Query arguments. $args = array('search' => esc_attr($who), 'search_columns' => array('user_nicename')); // The User Query. $user_query = new WP_User_Query($args); $user_query = $user_query->get_results(); $user_id = $user_query[0]->data->ID; break; } } return $user_id; }
/** * Checks if profiles are available. * * @uses wpum_is_single_profile * @uses wpum_guests_can_view_profiles * @uses wpum_members_can_view_profiles * @since 1.0.0 * @return bool */ function wpum_can_access_profile() { $pass = true; // Check if not logged in and on profile page - no given user if (!is_user_logged_in() && !wpum_is_single_profile()) { // Display error message $args = array('id' => 'wpum-guests-disabled', 'type' => 'notice', 'text' => sprintf(__('This content is available to members only. Please <a href="%s">login</a> or <a href="%s">register</a> to view this area.', 'wpum'), wpum_get_core_page_url('login'), wpum_get_core_page_url('register'))); wpum_message($args); $pass = false; } // Block guests on single profile page if option disabled if (!is_user_logged_in() && wpum_is_single_profile() && !wpum_guests_can_view_profiles()) { // Display error message $args = array('id' => 'wpum-guests-disabled', 'type' => 'notice', 'text' => sprintf(__('This content is available to members only. Please <a href="%s">login</a> or <a href="%s">register</a> to view this area.', 'wpum'), wpum_get_core_page_url('login'), wpum_get_core_page_url('register'))); wpum_message($args); $pass = false; } // Block members on single profile page if option disabled if (is_user_logged_in() && wpum_is_single_profile() && !wpum_members_can_view_profiles() && !wpum_is_own_profile()) { // Display error message $args = array('id' => 'wpum-no-access', 'type' => 'notice', 'text' => __('You are not authorized to access this area.', 'wpum')); wpum_message($args); $pass = false; } return apply_filters('wpum_can_access_profile', $pass); }
/** * Add custom classes to body tag * * @since 1.0.0 * @param array $classes * @return array */ function wpum_body_classes($classes) { if (is_page(wpum_get_core_page_id('login'))) { // add class if we're on a login page $classes[] = 'wpum-login-page'; } else { if (is_page(wpum_get_core_page_id('register'))) { // add class if we're on a register page $classes[] = 'wpum-register-page'; } else { if (is_page(wpum_get_core_page_id('account'))) { // add class if we're on a account page $classes[] = 'wpum-account-page'; } else { if (is_page(wpum_get_core_page_id('profile'))) { // add class if we're on a profile page $classes[] = 'wpum-profile-page'; // add user to body class if set if (wpum_is_single_profile()) { $classes[] = 'wpum-user-' . wpum_is_single_profile(); } } else { if (is_page(wpum_get_core_page_id('password'))) { // add class if we're on a password page $classes[] = 'wpum-password-page'; } } } } } return $classes; }