Example #1
0
/**
 * Display user name in profile.php template.
 *
 * @since 1.0.0
 * @param object $user_data holds WP_User object
 * @access public
 * @return void
 */
function wpum_profile_show_user_name($user_data)
{
    $output = '<div class="wpum-user-display-name">';
    $output .= '<a href="' . wpum_get_user_profile_url($user_data) . '">' . esc_attr($user_data->display_name) . '</a>';
    // Show edit account only when viewing own profile
    if ($user_data->ID == get_current_user_id()) {
        $output .= '<small><a href="' . wpum_get_core_page_url('account') . '" class="wpum-profile-account-edit">' . __(' (Edit Account)', 'wpum') . '</a></small>';
    }
    $output .= '</div>';
    echo $output;
}
    /**
     * Displays the new settings section into the permalinks page.
     *
     * @access public
     * @since 1.0.0
     * @return void
     */
    public function display_settings()
    {
        $structures = wpum_get_permalink_structures();
        $saved_structure = get_option('wpum_permalink', 'user_id');
        ob_start();
        ?>

		<?php 
        if (get_option('permalink_structure') == '') {
            ?>

		<p><?php 
            printf(__('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'));
            ?>
</p>

		<?php 
        } else {
            ?>

			<p><?php 
            _e('These settings control the permalinks used for users profiles. These settings only apply when <strong>not using "default" permalinks above</strong>.', 'wpum');
            ?>
</p>

			<table class="form-table">
				<tbody>
					<?php 
            foreach ($structures as $key => $settings) {
                ?>
						<tr>
							<th>
								<label>
									<input name="user_permalink" type="radio" value="<?php 
                echo $settings['name'];
                ?>
" <?php 
                checked($settings['name'], $saved_structure);
                ?>
 />
									<?php 
                echo $settings['label'];
                ?>
								</label>
							</th>
							<td>
								<code>
									<?php 
                echo wpum_get_core_page_url('profile');
                echo $settings['sample'];
                ?>
								</code>
							</td>
						</tr>
					<?php 
            }
            ?>
					<input type="hidden" name="wpum-action" value="save_permalink_structure"/>
				</tbody>
			</table>

		<?php 
        }
        ?>

		<?php 
        echo ob_get_clean();
    }
 /**
  * Call Envato api and request access token
  *
  * @uses grant_access() - returns an object containing refresh_token and access_token
  * @uses get_username() - pass access_token to the function
  * @return void
  */
 public function load_access_token()
 {
     if (isset($_GET['envato_registration']) && isset($_GET['code'])) {
         // Get response of the api
         $api_response = $this->grant_access();
         $username = $this->get_username($api_response->access_token);
         $email = $this->get_email($api_response->access_token);
         // Verify that the api returned something
         // if not - redirect to an error page
         if (empty($username) || empty($email)) {
             $error_url = add_query_arg(array('registration_error' => 'envato_offline'), wpum_get_core_page_url('register'));
             wp_redirect($error_url);
             exit;
         }
         // Do registration
         $new_user = WP_Envato_Login()->user->register($username, $email);
         // Finish registration process
         if (is_wp_error($new_user)) {
             WP_Envato_Login()->user->error_redirect($new_user->get_error_code());
         } else {
             // Save refresh token
             WP_Envato_Login()->user->save_token($new_user, $api_response->refresh_token);
             do_action('wpel_after_registration', $new_user, $api_response);
             // Redirect user to successful page
             WP_Envato_Login()->user->success_redirect();
         }
     }
 }
</a>
	</div>

	<div class="wpum_three_fourth user-content last">
		
		<a href="<?php 
echo esc_url($user_profile_user);
?>
"><?php 
echo $current_user->display_name;
?>
</a>
		
		<ul class="wpum-overview-links">
			<li><a href="<?php 
echo esc_url(wpum_get_core_page_url('account'));
?>
"><?php 
_e('Edit Account', 'wpum');
?>
</a></li>
			<li>|</li>
			<li><a href="<?php 
echo esc_url(wpum_logout_url(get_permalink()));
?>
"><?php 
_e('Logout', 'wpum');
?>
</a></li>
		</ul>
Example #5
0
/**
 * 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);
}
Example #6
0
/**
 * Properly setup links for wpum powered nav menu items.
 * Determines which links should be displayed and what their url should be.
 *
 * @since 1.1.0
 * @param  object $menu_item the menu item object
 * @return object            the modified menu item object
 */
function wpum_setup_nav_menu_item($menu_item)
{
    if (is_admin()) {
        return $menu_item;
    }
    // Prevent a notice error when using the customizer
    $menu_classes = $menu_item->classes;
    if (is_array($menu_classes)) {
        $menu_classes = implode(' ', $menu_item->classes);
    }
    switch ($menu_classes) {
        case 'wpum-register-nav':
            if (is_user_logged_in()) {
                $menu_item->_invalid = true;
            } else {
                $menu_item->url = wpum_get_core_page_url('register');
            }
            break;
        case 'wpum-login-nav':
            if (is_user_logged_in()) {
                $menu_item->_invalid = true;
            } else {
                $menu_item->url = wpum_get_core_page_url('login');
            }
            break;
        case 'wpum-account-nav':
            if (!is_user_logged_in()) {
                $menu_item->_invalid = true;
            } else {
                $menu_item->url = wpum_get_core_page_url('account');
            }
            break;
        case 'wpum-logout-nav':
            if (!is_user_logged_in()) {
                $menu_item->_invalid = true;
            } else {
                $menu_item->url = wpum_logout_url();
            }
            break;
        case 'wpum-psw-recovery-nav':
            if (is_user_logged_in()) {
                $menu_item->_invalid = true;
            } else {
                $menu_item->url = wpum_get_core_page_url('password');
            }
            break;
    }
    return $menu_item;
}
 /**
  * Restrict content to logged in users only and by user roles.
  *
  * @access public
  * @since  1.0.0
  * @return $output shortcode output
  */
 public function wpum_restrict_to_user_roles($atts, $content = null)
 {
     extract(shortcode_atts(array('roles' => null), $atts));
     ob_start();
     $allowed_roles = explode(',', $roles);
     $allowed_roles = array_map('trim', $allowed_roles);
     $current_user = wp_get_current_user();
     if (is_user_logged_in() && !is_null($content) && !is_feed() && array_intersect($current_user->roles, $allowed_roles)) {
         echo do_shortcode($content);
     } else {
         $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')));
         $warning = wpum_message(apply_filters('wpum_restrict_to_user_roles_args', $args), true);
     }
     $output = ob_get_clean();
     return $output;
 }
/**
 * 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;
}
Example #9
0
/**
 * Create a fake post object for the wp menu manager.
 * This function creates the list of Logged-Out only pages,
 * for the admin menu manager.
 *
 * @since 1.1.0
 * @return array
 */
function wpum_nav_menu_get_loggedout_pages()
{
    $wpum_menu_items = array();
    $wpum_menu_items[] = array('name' => __('Register', 'wpum'), 'slug' => 'register', 'link' => wpum_get_core_page_url('register'));
    $wpum_menu_items[] = array('name' => __('Log in', 'wpum'), 'slug' => 'login', 'link' => wpum_get_core_page_url('login'));
    $wpum_menu_items[] = array('name' => __('Password recovery', 'wpum'), 'slug' => 'psw-recovery', 'link' => wpum_get_core_page_url('password'));
    $wpum_menu_items = apply_filters('wpum_nav_menu_get_loggedout_pages', $wpum_menu_items);
    // If there's nothing to show, we're done
    if (count($wpum_menu_items) < 1) {
        return false;
    }
    $page_args = array();
    foreach ($wpum_menu_items as $wpum_item) {
        $page_args[$wpum_item['slug']] = (object) array('ID' => -1, 'post_title' => $wpum_item['name'], 'post_author' => 0, 'post_date' => 0, 'post_excerpt' => $wpum_item['slug'], 'post_type' => 'page', 'post_status' => 'publish', 'comment_status' => 'closed', 'guid' => $wpum_item['link']);
    }
    return $page_args;
}
/**
 * Generates url of a single account tab.
 *
 * @since 1.0.0
 * @return string $tab_url url of the tab.
 */
function wpum_get_account_tab_url($tab)
{
    if (get_option('permalink_structure') == '') {
        $tab_url = add_query_arg('account_tab', $tab, wpum_get_core_page_url('account'));
    } else {
        $tab_url = wpum_get_core_page_url('account') . $tab;
    }
    return esc_url($tab_url);
}
 /**
  * Redirect user to error page if an error occured
  * @param  string $error_code code of the error
  * @return void
  */
 public static function error_redirect($error_code)
 {
     $error_url = add_query_arg(array('registration_error' => $error_code), wpum_get_core_page_url('register'));
     wp_redirect($error_url);
     exit;
 }