Example #1
0
 /**
  * Returns a wp user object containg user's data.
  * The user is retrieved based on the current permalink structure.
  * This function is currently used only through the wpum_profile shortcode.
  * If no data is set, returns currently logged in user data.
  *
  * @since 1.0.0
  * @access public
  * @return object
  */
 function wpum_get_user_by_data()
 {
     $user_data = null;
     $permalink_structure = get_option('wpum_permalink', 'user_id');
     $who = get_query_var('user') ? get_query_var('user') : null;
     // Checks we are on the profile page
     if (is_page(wpum_get_core_page_id('profile'))) {
         // Verify the user isset
         if ($who) {
             switch ($permalink_structure) {
                 case 'user_id':
                     $user_data = get_user_by('id', intval(get_query_var('user')));
                     break;
                 case 'username':
                     $user_data = get_user_by('login', esc_attr(get_query_var('user')));
                     break;
                 case 'nickname':
                     // WP_User_Query arguments
                     $args = array('search' => esc_attr(get_query_var('user')), 'search_columns' => array('user_nicename'));
                     // The User Query
                     $user_query = new WP_User_Query($args);
                     $user_query = $user_query->get_results();
                     $user_data = $user_query[0];
                     break;
                 default:
                     $user_data = apply_filters("wpum_get_user_by_data", $permalink_structure, $who);
                     break;
             }
         } else {
             $user_data = get_user_by('id', get_current_user_id());
         }
     }
     return $user_data;
 }
 /**
  * Adds new rewrite rules to create pretty permalinks for users profiles.
  *
  * @access public
  * @since 1.0.0
  * @global object $wp
  * @return void
  */
 public function profile_rewrite_rules()
 {
     global $wp;
     // Define args for profile pages
     $wp->add_query_var('user');
     $wp->add_query_var('tab');
     $page_id = wpum_get_core_page_id('profile');
     $page_slug = esc_attr(get_post_field('post_name', intval($page_id)));
     add_rewrite_rule($page_slug . '/([^/]*)/([^/]*)/page/([0-9]+)', 'index.php?page_id=' . $page_id . '&user=$matches[1]&tab=$matches[2]&paged=$matches[3]', 'top');
     add_rewrite_rule($page_slug . '/([^/]*)/([^/]*)', 'index.php?page_id=' . $page_id . '&user=$matches[1]&tab=$matches[2]', 'top');
     add_rewrite_rule($page_slug . '/([^/]*)', 'index.php?page_id=' . $page_id . '&user=$matches[1]', 'top');
     // Define args for account page
     $wp->add_query_var('account_tab');
     $account_page_id = wpum_get_core_page_id('account');
     $account_page_slug = esc_attr(get_post_field('post_name', intval($account_page_id)));
     add_rewrite_rule($account_page_slug . '/([^/]*)', 'index.php?page_id=' . $account_page_id . '&account_tab=$matches[1]', 'top');
 }
Example #3
0
/**
 * 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();
    }
}
Example #4
0
/**
 * 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;
}
Example #5
0
<?php

/**
 * WPUM Template: Upload Field Template.
 *
 * @package     wp-user-manager
 * @copyright   Copyright (c) 2015, Alessandro Tesoro
 * @license     http://opensource.org/licenses/gpl-2.0.php GNU Public License
 * @since       1.0.0
 */
$classes = array('input-upload');
$allowed_mime_types = array_keys(!empty($field['allowed_mime_types']) ? $field['allowed_mime_types'] : get_allowed_mime_types());
$field_name = isset($field['name']) ? $field['name'] : $key;
$field_name .= !empty($field['multiple']) ? '[]' : '';
if (!is_page(wpum_get_core_page_id('register'))) {
    ?>
<div class="wpum-uploaded-files">
	<?php 
    if (!empty($field['value']) && !is_wp_error($field['value'])) {
        ?>
		<?php 
        if (is_array($field['value'])) {
            ?>
			<?php 
            foreach ($field['value'] as $value) {
                ?>
				<?php 
                get_wpum_template('form-fields/uploaded-file-html.php', array('key' => $key, 'name' => 'current_' . $field_name, 'value' => $value, 'field' => $field, 'field_name' => $field_name));
                ?>
			<?php 
            }
Example #6
0
/**
 * Highlight which pages are selected as plugin's core page
 * within the Pages management screen.
 *
 * @since 1.0.0
 * @param array $post_states An array of post display states.
 * @param int   $post        The post ID.
 * @return array
 */
function wpum_highlight_pages($post_states, $post)
{
    $icon = '<i class="wpum-shortcodes-icon" title="' . __('WPUM Page', 'wpum') . '"></i>';
    if (wpum_get_core_page_id('login') == $post->ID) {
        $post_states['page_for_login'] = $icon;
    } else {
        if (wpum_get_core_page_id('account') == $post->ID) {
            $post_states['page_for_account'] = $icon;
        } else {
            if (wpum_get_core_page_id('password') == $post->ID) {
                $post_states['page_for_password'] = $icon;
            } else {
                if (wpum_get_core_page_id('register') == $post->ID) {
                    $post_states['page_for_registration'] = $icon;
                } else {
                    if (wpum_get_core_page_id('profile') == $post->ID) {
                        $post_states['page_for_profiles'] = $icon;
                    }
                }
            }
        }
    }
    return $post_states;
}
/**
 * Function to display content of the "wpum_profile_permalink" option.
 *
 * @since 1.0.0
 * @return array
*/
function wpum_profile_permalink()
{
    $output = '<p>' . sprintf(__('Current profile permalink structure: %s%s', 'wpum'), wpum_get_core_page_url('profile'), get_option('wpum_permalink', 'user_id')) . '</p>';
    $output .= '<p class="description">' . sprintf(__('You can change the profiles permalink structure into your <a href="%s">permalink settings page</a>.', 'wpum'), admin_url('options-permalink.php')) . '</p>';
    // Display error if something is wrong
    if (!wpum_get_core_page_id('profile')) {
        $output = '<p style="color:red;"><strong>' . __('Your users profile page is not configured.', 'wpum') . '</strong>' . ' ' . sprintf(__('<a href="%s">Setup your profile page here.</a>', 'wpum'), admin_url('users.php?page=wpum-settings&tab=general')) . '</p>';
    }
    if (get_option('permalink_structure') == '') {
        $output = '<p style="color:red;"><strong>' . sprintf(__('You must <a href="%s">change your permalinks</a> to anything else other than "default" for profiles to work.', 'wpum'), admin_url('options-permalink.php')) . '</strong></p>';
    }
    echo $output;
}
/**
 * Get URL of a core page.
 *
 * @since 1.0.0
 * @param string  $name the name of the page. Supports: login, register, password, account, profile.
 * @return string $url of the core page.
 */
function wpum_get_core_page_url($page)
{
    $url = null;
    switch ($page) {
        case 'login':
            $url = esc_url(get_permalink(wpum_get_core_page_id('login')));
            break;
        case 'register':
            $url = esc_url(get_permalink(wpum_get_core_page_id('register')));
            break;
        case 'password':
            $url = esc_url(get_permalink(wpum_get_core_page_id('password')));
            break;
        case 'account':
            $url = esc_url(get_permalink(wpum_get_core_page_id('account')));
            break;
        case 'profile':
            $url = esc_url(get_permalink(wpum_get_core_page_id('profile')));
            break;
        default:
            // nothing
            break;
    }
    return $url;
}
Example #9
0
/**
 * Get URL of a core page.
 *
 * @since 1.0.0
 * @param string  $name the name of the page. Supports: login, register, password, account, profile.
 * @return string $url of the core page.
 */
function wpum_get_core_page_url($page)
{
    $url = null;
    switch ($page) {
        case 'login':
            $url = esc_url(get_permalink(wpum_get_core_page_id('login')));
            break;
        case 'register':
            $url = esc_url(get_permalink(wpum_get_core_page_id('register')));
            break;
        case 'password':
            $url = esc_url(get_permalink(wpum_get_core_page_id('password')));
            break;
        case 'account':
            $url = esc_url(get_permalink(wpum_get_core_page_id('account')));
            break;
        case 'profile':
            $url = esc_url(get_permalink(wpum_get_core_page_id('profile')));
            break;
    }
    return apply_filters('wpum_get_core_page_url', $url, $page);
}
Example #10
0
/**
 * Add a "view profile" link to the admin user table.
 *
 * @since 1.1.0
 * @param  array $actions     list of actions
 * @param  object $user_object user details
 * @return array              list of actions
 */
function wpum_admin_user_action_link($actions, $user_object)
{
    if (wpum_get_core_page_id('profile')) {
        $actions['view_profile'] = '<a href="' . wpum_get_user_profile_url($user_object) . '">' . esc_html__('View Profile', 'wpum') . '</a>';
    }
    return $actions;
}