Skip Navigation

[Resolved] Create a Full membership Site with CRED

This thread is resolved. Here is a description of the problem and solution.

Problem:
Can I create a Full memnership site with CRED?
If so, how do I do it?

Solution:
You can create membership Sites with CRED.
YOu can add Form to let users register and also update theor Profiles.
Views Provides Login and Logout ShortCodes.

Usually you will not need more customization for memebership sites, but if you need a "full" memebership site, where also other users can view profiles of other users, where you hide the WordPress backend, where you can use your User's to set up relations to posts, then you need further customization.
Please read this set of handy Code snippets to csutomize your Membership Site:
https://toolset.com/forums/topic/using-author-archives-as-user-profiles-to-be-viewed-by-other-users/#post-401106

Relevant Documentation:
https://toolset.com/documentation/woocommerce-views-shortcodes/
https://toolset.com/documentation/user-guides/cred-user-forms/
https://toolset.com/documentation/user-guides/access-control-for-cred-forms/

100% of people find this useful.

This support ticket is created 7 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 10 replies, has 2 voices.

Last updated by Geoffrey Cleverley 7 years, 11 months ago.

Assisted by: Beda.

Author
Posts
#400465

I am making a membership 'book review' site.

For the my profile page, at the moment I am using a static page that displays the current users profile details and a view of their review custom posts.

However this doesn't allow other users to view their page.

I was hoping to use the Author archive as the basis for viewing other users reviews and profile details.

I have not had much success so far.

Can you explain how to create an author archive page that will feature:

1. That authors profile details
2. That authors custom posts (book review posts)

Thanks

Jeff

#400517
Screen Shot 2016-05-22 at 2.14.28 PM.png

Update:

I deleted my Author archives and started again following the documentation.

While creating my general Author archive for users I noticed that the external link next to the selected Author archives in the loops selection is linking to:

'home/author/admin' (as you can see in my screenshot)

The previous Author archive pages I made were displaying the reviews and posts from myself (admin) on my archive page, but when I tried to go to other users archive pages nothing was being displayed.

Perhaps this would suggest why?

Am I right in thinking that I want to create an Author Archive that directs to:

'home/author'

Look forward to your advice.

Jeff

#400591

This is where your Custom Post type "user" would come in helpful. (as discussed in the previous threads)

1. That authors profile details
This (on a static page) will usually display "current logged in user" information or information by a User which ID you pass manually in the ShortCode.

Both is not desired in your case.

2. That authors custom posts (book review posts)

Again, this could be done with a View, that lists Posts of the User set by the Query Filter, which can be:
- Post author is the same as the logged in user
- Post author is the author of the page where this View is shown
- Post author is the author of the current post in the loop
- Post author is set by the parent User View
- Post author [text search]
- Post author is set by the URL parameter
- Post author is set by the View shortcode attribute

None really applies to what you need.

You need Profile Pages (posts)

And then, on each of those, also a View of the Posts that this specific user (which the profile is about) authored.

Simplest and safest approach is:

1. Create a Custom post "Members"
2. "Mimic" the users on this Post Type (this means, you create kid of a duplicate to the WordPress users, using Posts)
3. Each Member Post is Author > the user you are creating a profile for
4. You then create a View, list the Posts you want to to display and pass:
Post author is the author of the page where this View is shown

This view is then inserted in the Content Template with which you style the Members posts.

This will allow you to:
- visit a Members Profile, also as an "other user"
- See their posts with full parametric search, pagination and more features
- Also, you can use the Member profile to further connect posts to single members.

This would be the most straight forward and also most "advanced" in terms of "what you can do with" approach.

#400621

Earlier I read another of your support threads detailing this process, and decided that is the best way to go.

Thanks for your clear description. I will get onto it tomorrow. Once I have these done and a 'Members' archive functioning correctly I will close the thread.

Nice one Beda

Jeff

#400744

Thanks for the update.

I know that it is something "tedious", but you can also somehow automate this whole process by using CRED Forms and letting the Users Create their Profiles instead.

With Some Custom Code you can even "Talk" To the DataBase and update User Meta when a profile (CPT) gets submitted or edited.
I think I have this one Code Snippet (huge CRED API) that shows you some of the more intricate Fields ever, and how to pass the values from a Post to a User with a CRED API Function:
http://pastebin.com/Y1pWeJnP

I can not assist on this Custom Code but with that example, you will have all possible information to create your own Application logic, in case you want to automate this more.

In my personal cases where I developed such things, I even fully renounced to use User Profiles and store everything in a Post Type (Of course users are still users, but I use the User Profile only for Login Data and User Level)

#400754

I created the Members post type and made it a parent of Reviews post type.

Thinking about mimicking the wordpress user profiles and redundancy of values got me to thinking about how this plan will work with the user registration, member profile post creation, displaying, editing flow etc.

I apologise for the lengthiness of my support requests and thank you for your patience, but I have read several of your threads dealing with membership sites and would greatly welcome your opinion and thoughts on the flow detailed below. Please tell me where you see issues arising and if somethings aren't possible or there are better ways to achieve my desired output.

Hopefully the details will help others contemplating similar issues too.

=====================
-------------------------------------
Registration of new users
-------------------------------------
=====================

When a user registers make it a two step process.

Step 1 > WordPress User Registration

CRED New User Form - only contains necessary information required by wordpress
* Username (warning that this can't be changed and will be their site handle)
* Email
* Password

With message at bottom above the submit button with something like, "Please click submit to continue to profile creation".

When user submits redirect them to...

Step 2 > Member Post creation

CRED submit post form - contains custom fields mimicking wordpress user fields
*First name, Last name
*Biographty (about me)
*User image/photo
*Social Media links
*Anything else.

As each user has a membership post, which is also parent to their reviews, I can use views and templates to allow users to see and search for each other and their reviews.

----------------------------------
Issues to be considered
===================

1. Membership posts are created separately from User profiles, so it's possible for users to not complete step 2. They may register and then click through to different area of the site before completing their Membership post.

>>>>Solution
a). Mitigate likelihood of this happening through direction in user experience. Using visual and text cues to frame registration as just 2 steps in the same process. Use indicators such as, 'nearly finished' etc. Create similar experience to setting up a phone or OS.

b). Include a terms of service or membership agreement that clearly states that if they do not complete step 2, their account will be deleted.

c). Is it possible to hide elements of the site via html conditionals and layouts? If a user hasn't created a 'Member' post, ie completed the registration, then menu links don't appear, the only links available is a 'logout' link. Whenever a member who hasn't completed a 'Member' post logs in, this is all they see.

===================

2. Membership posts are just custom posts created by users and not really user profiles, therefore users can create multiple member profiles.

>>>>Solution
Step 2 is carried out on a 'your membership' page, the same page that a user is directed to when they login.

This page has a view that queries 'Members' posts, filtered by 'posts authored by the currently logged in user'.

a). If the user has registered and created their 'Members' post, then the page will display their membership information and an edit link.

b). If the user is a new user or hasn't completed their 'Members' post then the view would normally return a "no posts found", replace this statement with the CRED create 'Member' post form.

So the form to create a 'Member' post only shows if a user has not created one before.

Viewing your profile is then done via this 'My Membership Page', showing a view that displays content from the currently logged in users 'Member' posts, and another view displaying content from the currently logged in users 'Review' posts.

Viewing other peoples profiles is done by viewing their Membership posts. I will create another page to display a view of members via parametric search, and or table, and or selection of reviews etc.

The content template for 'My Membership' page and 'Member' posts will be nearly identical.

Users will also be kept out of dashboard area via (many) plugins and custom code to hide admin bar so they can't create more members profiles:
hidden link

In addition to your advice I also found these support threads useful:
https://toolset.com/forums/topic/cred-user-profile-editing/
https://toolset.com/forums/topic/making-a-linkedin-style-member-directory-urgent-request/

====================

3. Post Author Links on Review Posts will direct to WordPress User author archive and not the users 'Members' post.

>>>>Solution
Remove and replace author link
a). Perhaps remove this link via css

.class {display: none !important}

- although it will still be searchable by robots
b). Or Edit php, find and change

the_author_posts_link();

to

the_author();

c). Or Use a theme that doesn't display author link
d). Replace the original author link with a link to the 'Member' Post created by the same author.

====================

4. Users who haven't completed their 'Members' post will still be able to post reviews of books.

4.1 Other users who read their review can't click a link through to their 'Members' post to see their profile and other reviews they have submitted.

>>>>Solution
Have the link, from 3 d) above, appear conditionally:
If the review author has created a 'Member' post, then show the link to their member post.
If the review author hasn't created a 'Member' post show a link to:
a). An archive page? if so then I still need help created author archive pages!
b). A hidden page that contains a view showing the reviews of that user, via their user_id. For this will I need custom code, can you detail it for me?
c). Can you think of any other elegant solution.

4.2 On the 'All Members' page or archive that contains a view and parametric search of all the members profiles, these users won't appear.

>>>>Solution
No ide (other than below), can you think of any?

=====================

Membership agreement solution.

In membership agreement, state that all users who don't complete their members profile will have their accounts and reviews deleted as part of the terms of service.

Give them a timeframe to complete their 'Members' post.

Whenever a user who hasn't completed their 'Members' post signs they will be greeted with the create 'Member' post form, and a warning that if they don't complete it their account will be erased.

Is there anyway to automate a countdown?

A little unpleasant but will mitigate issue 1 and solve issue 4, and with a time cost due to administrator management of membership.

Do you know of any plugins that work well with toolset that can help with such things?

======================

Thanks for all your help.

#400755

Regarding your advice about 'automating this whole process by using CRED Forms and letting the Users Create their Profiles instead.'

During my research i found these threads:
https://toolset.com/forums/topic/member-directory-linking-to-user-profile/
https://toolset.com/forums/topic/making-a-linkedin-style-member-directory-urgent-request/

and this regarding cred_save_data: (action)
https://toolset.com/documentation/user-guides/cred-api/

I was going to ask this in a seperate thread, but was drafting the reply above when you responded.

So basically with custom code my CRED 'Member' post forms can amend the wordpress database with regards to user profile entries? So a CRED form can both create/update a user profile and create/update a 'member' CPT at the same time?

I have been looking at this, and hopefully in future I can work out how to automate things further. Thanks for the snippet.

You mentioned, "In my personal cases where I developed such things, I even fully renounced to use User Profiles and store everything in a Post Type (Of course users are still users, but I use the User Profile only for Login Data and User Level)"

I think this is what I am detailing above, just using the wordpress registration for Login, User level, etc. And having the 'Member' CPT for every other use.

I look forward to your reply

Jeff

edit. Just looked at that snippet, that is awesome, big thanks.

#401106

You are about right.

Let me specify some details.

1. All the issues with "User can see things even if his Membership Post is not created yet", or, "user can create many Membership Posts", are to solve by Custom PHP Code - for which I will plant some examples below.

2. It's right, with the CRED API you can run Custom Code using the WordPress API and PHP to do anything on form submit - even create a new User Profile.

I solved this on my cases by letting the User Sign in by Google Login Plugin, which creates a User Profile (WordPress native)
Then with Custom Code I hide everything but a Button (CRED Form) "Create a Profile"
Until this isn't done, the user can't do anything but create a profile or Log Out.

Once this is done, a Custom Code checks the amount of Profiles (Custom post) created.
If "1", it hides the create profile Forms and Links, and presents the full site to the user.

Also I hide Admin Bar, just as you plan to do.

3. With above you will solve most of the issues.
I suggest to use a very minimal Theme so to customize it - best case, create your own theme that comes with the functionality you need.

I regnet to say, that such "complex" user sites are difficult to set up - not due to Toolset, it makes it easier, but also due to WordPress, which isn't exactly a "membership CMS", but a blogging Software.

Of course, with correct Codes everything is possible, and Toolset API will let you do this easier - along with the GUI that lets you display all the content easily.

Below a set of codes that I created during above processes, I hope they can be useful to you (and others)

1. User Profile Pic

/**
 * Add Gravatar Support for Views 
 */
function otgs_gravatar($atts) {
   return get_avatar( $atts['email'] );
}
add_shortcode('otgs-gravatar', 'otgs_gravatar');

Use it like this:

[otgs-gravatar email="user_email@site.com"]

2. Count Posts per user (helpful to check how many Profile Posts created, and hide things accordingly)

/**
 *Count posts of given type, so each user can create post only once
 */
function u_post_count() {
    $user_post_count = count( get_posts( array( 
    'post_type' => 'your_post_type', 
    'author'    => get_current_user_id(), 
) ) );
        
    return $user_post_count;
}

It will count all Posts of the current logged in user.
Make sure to define the Post type in 'post_type'
It returns a numeric count.
It's to be used in a HTML Conditional using the function
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-custom-functions-in-conditions/

3. Adds a simple Logout Link with BootsTrap Style as a ShortCode to your System. Make sure to register it in Views previous to usage.

/** Custom Logout Shortcode
 */
<?php
 function custom_logout_link_func() {
            $return = wp_logout_url();?>
            <a href="<?php echo $return; ?>" class="btn btn-primary btn-xs btn-block" role="button">Logout</a>
            <?php
        }
        
    add_shortcode('logout_link', 'custom_logout_link_func');?>

4. Redirects to the Home URL if the login failed.

/**
 *Used to redirect if login failed
 */
 
 
function login_failed() {
    $login_page  = home_url();
    wp_redirect( $login_page . '' );
    exit;
}
add_action( 'wp_login_failed', 'login_failed' );

5.
Redirects to the Home URL after Logout from the Admin (or elsewhere)

/**
 *Used to redirect if logout 
 */
 
function logout_page() {
    $login_page  = home_url();
    wp_redirect( $login_page . "" );
    exit;
}
add_action('wp_logout','logout_page');

6. Hides the “default” menu for non logged in users and instead displays a Custom Menu (in this case called “unlogged”)
The menu must of course be set up as a menu in Dashboard > Appearance A Menu, but not be displayed anywhere by default.

/**
 *Used to remove menu for non logged users and display custom menu instead 
 *Do NOT redecalre the menu LOGGED in users see, because, other wise he will see always the SAME menu (like in custom menus, he will see the default menu)
 */
 
function my_wp_nav_menu_args( $args = '' ) {
 
        if( !is_user_logged_in() ) {
 
            $args['menu'] = 'unlogged';
 
    }
 
        return $args;
 
}
 
    add_filter( 'wp_nav_menu_args', 'my_wp_nav_menu_args' );

7. By default CRED parent Picker lets you choose from all available parent Posts.
This snippet lets you populate the picker with only the parent posts of the current logged in user
https://toolset.com/forums/topic/i-want-to-only-display-the-parent-items-of-the-current-user-in-a-select-box-2/

8. This snippet allows “Members only” sites.

It redirects always to a custom PHP template (noaccess) if the user is not logged in, and obviously it will NOT redirect anywhere if the User access the custom template (noaccess).

Other wise a infinite loop would be generated.

/**
 *Used to redirect if not logged in
 */
 
function admin_redirect() {
    if ( !is_page('noaccess') && ! is_user_logged_in() ) {
    
        wp_redirect( home_url('/noaccess/') );
        exit;
    }
}
add_action('get_header', 'admin_redirect');

9. Limit the number of featured posts which user can submit. This Code limit to 1 featured post for each user.
The “wpcf-mls” is the custom field which define if the post is featured or not. It should store 1 for featured.

This hook will be triggered as soon as this custom field sent “1”.
Then check how many featured posts the current user has. Limit this number to “1”.

add_filter('cred_form_validate','my_validation',10,2);
function my_validation($field_data, $form_data){
global $wpdb; 
list($fields,$errors)=$field_data;
   if ($form_data['id']==241){	
      if ($fields['wpcf-mls']['value'] == 1){
         $results = $wpdb->get_results( 'SELECT * FROM '.$wpdb->posts.' post, '.$wpdb->postmeta.' meta WHERE post.ID = meta.post_id and post.post_status = "publish" and meta.meta_key = "wpcf-mls" and meta.meta_value = "1" AND post.post_author = "'.get_current_user_id().'"', OBJECT );
         if (count($results) > 1){
            $errors['mls']='Your limit for featured posts is 1';
         }    
      }
      return array($fields,$errors);
   }
}

10. Removes the WP Admin Bar for a given Role (contributor in this case)

function remove_admin_bar_user() {
	if( current_user_can('contributor')) {
		show_admin_bar(false);
	}
}
add_action('after_setup_theme', 'remove_admin_bar_user');

11. Update user Meta with values of a post meta:
http://pastebin.com/Y1pWeJnP

Please acknowledge - this are only reference Snippets, but it's pretty much what you will need anyway to achieve a great Members only site, with the features you describe.

As you see, advanced knowledge of WordPress API and PHP is needed - Toolset helps to hook into the right place at the right moment, and will save you great time to display the stuff created, once this is done.

We dos not support this sort of customized Codes, it can't be expected from a Supporter to debug above codes or help with. But seen the great demand of this snippets - here they are at your disposal

I hope this helps

#401125

What can I say...?

Absolutely fantastic support Beda, above and well beyond the scope of what any supporter can be reasonably expected to provide.

I know what you mean about pushing the envelope of WordPress's expected use cases, square peg and round hole and all that. I can also see that, with advanced knowledge of the WordPress api, php and toolset, it is possible to go beyond using WordPress as just a blog.

I completely acknowledge that these snippets are for my (our reference) and appreciate the extra help and potential you've enabled providing them.

With regards to this user profile, membership query etc, I know what I am doing now, what I am capable of at the moment and therefore how I should execute, and in which direction and of what I need to learn to achieve my future desired output. Your code snippets are a superb resource, thank you for sharing.

Given the value of your snippets, I also hope others can find this thread easily enough, I am a little concerned given the title that others may not come across it easily enough.

Therefore, for everyones and If it's okay with support thread policy, I will open a new thread with a more appropriate title, specify the contents of this thread and link to it, and close the thread as resolved immediately.

It's all very much appreciated. I'll resolve this as soon as you let me know if it's okay to repost linking to this thread.

Jeff

#401186

Never mind Jeff.

I can update the Title of this Thread here as soon you click on "Resolved"

No need to open a new one - although if you want, go ahead 🙂

Thank you - I hope I have been of some useful help.

#401197

If you can update the title of thread, that seems better, less convoluted.

You have been a great help, I couldn't be happier with the support you've provided.

Jeff

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.