Proper this second, we’ll discuss some strategies how one can monetize your communities, itemizing and multivendor web sites. You need to use this for BuddyPress web sites, for web sites the place prospects can submit posts, multivendor web sites the place prospects promote one factor. We’ll current you some suggestions and extended function, mixtures with membership plugins, WC Vendor, Buddypress, reputation system.

To start with, in our article we’ll use S2Member plugin. We found that that is possible one of many biggest membership plugins, on account of it has many capabilities, developer nice and has paypal button and url entry even in free mannequin.

1: Basic settings for S2Member

After placing in, you probably can go to S2Member – Getting Started to confirm some docs. Most crucial components for setting are welcome net web page, registration net web page and membership decisions net web page.

S2Member has very extremely efficient conditional shortcodes, which can assist to level out content material materials for varied roles and capabilities. Moreover, S2Get shortcode could be useful to level out some details about current client

Welcome net web page (S2 Member – Regular settings – Login Welcome net web page) is net web page which could be used after client logged on web site. This net web page could be seen moreover with out spending a dime subscription prospects, so, make this net web page informative and add messages how prospects can administration their memberships, add benefits of paid subscription and hyperlinks on net web page the place they will exchange their membership (membership chance net web page). It’s moreover good in order so as to add some plugin shortcodes to this net web page, which offers potential to fluctuate profile information. Default plugin shortcode for that’s

[s2Member-Profile /]
Vital!!! S2Member plugin provides redirect to vendor web page on wp_signon wordpress operate. Typically, in case your theme or plugin has login popup, it won’t work with S2Member. For WPsoul themes we added possibility to alter login popup to static button for login/register. Theme possibility – Header – Kind url for login button. Use there hyperlink in your registration web page

Often, I take advantage of tabs on welcome web page. Every tab has some logical half. For instance, in a single tab you may add data find out how to purchase prolonged membership account, on one other, you may add particular shortcode of plugin which provides profile type

[s2Member-Profile /]

Find tab shortcode in your theme. Wpsoul themes has next shortcode example which can help

[wpsm_tabgroup]<br />[wpsm_tab title="Update profile"][s2Member-Profile /][/wpsm_tab]<br />[wpsm_tab title="Get extended function"]Information about subscription[/wpsm_tab]<br />[/wpsm_tabgroup]

Registration net web page. By default, S2member makes use of customary wordpress login/register net web page. You can also customise it in S2Member – Regular Alternative – Login/Registration design. In fairly frequent situations, it could be greatest to make use of frontend register net web page. Many plugins add private register net web page. For Buddypress, you presumably can administration such net web page in Settings – Buddypress – Pages. For multivendor web sites, it’s increased to utilize woocommerce register net web page. Yow will uncover it in Woocommerce – Settings – Accounts. Every plugin’s type are supported by S2Member. You’ll add additional fields to type which is perhaps saved to individual meta. S2Member moreover synchronized it’s roles with BuddyPress. For WC Vendor and woocommerce synchronization – please, study information beneath.

By default, S2Member plugin moreover supplies additional fields for establish to register type – you presumably can cease this in S2Member – Regular Alternative – Registration/Profile Fields & Decisions

You can also want to fully conceal wp-admin pages from clients in S2Member – Regular Alternative – Member Profile Modifications

Membership selections. This net web page is perhaps in use when individual will try to get restricted content material materials and when he want to buy entry or subscription. It’s moreover important to have good and clear information what individual will get after price and what benefits he’ll get. Don’t overlook in order so as to add all circumstances for price and cellphone particulars if individual can have a difficulty. You moreover should create all buttons for purchases in S2member – Paypal settings (or in PRO varieties for skilled mannequin). Moreover, don’t overlook to create cancel subscription button

Also, it’s good point when you place price table on this page. In our theme we have bundled shortcode for this which supports custom buttons. This is example of such shortcode

[wpsm_price_table]
[wpsm_price_column size="3" featured="no" name="Free" price="0" per="month" ]
<ul>
 	<li>Profile page</li>
 	<li>Order story</li>
 	<li>Friendships</li>
 	<li>Activity</li>
 	<li>Add deals</li>
</ul>
<a href="#">Free registration</a>

[/wpsm_price_column]
[wpsm_price_column size="3" featured="yes" name="Member PRO level" price="$9.99" per="month"]
<ul>
 	<li>All free features +</li>
 	<li>Add deals</li>
 	<li>Sell your products</li>
 	<li>Your own store page</li>
 	<li>Better profile page</li>
</ul>
[s2Member-PayPal-Button level="1" ccaps="" desc="PRO Member / 7 days FREE, after only 1 cent/month." ps="paypal" lc="" cc="USD" dg="0" ns="1" custom="testkassa.wpsoul.net" ta="0" tp="7" tt="D" ra="0.01" rp="1" rt="M" rr="1" rrt="" rra="1" image="default" output="button" /]
[/wpsm_price_column]
[wpsm_price_column size="3" featured="no" name="Member MEGA level" price="$19.99" per="month"]
<ul>
 	<li>All free features +</li>
 	<li>AllPRO features +</li>
 	<li>Add 5 products on homepage</li>
 	<li>Help with promotion</li>
 	<li>Better statistic</li>
</ul>
[s2Member-PayPal-Button level="2" ccaps="" desc="MEGA Member / 7 days FREE, after only 1 cent/month." ps="paypal" lc="" cc="USD" dg="0" ns="1" custom="testkassa.wpsoul.net" ta="0" tp="7" tt="D" ra="0.01" rp="1" rt="M" rr="1" rrt="" rra="1" image="default" output="button" /]
[/wpsm_price_column]
[/wpsm_price_table]

Additionally, word, that after registration from woocommerce kind, customers can be redirected to vendor dashboard in theme. To forestall this – disable this in theme choice – store settings – WC Vendor setting

Mix your content material shortcodes with S2 conditional shortcodes to point out totally different content material and choices for various person roles and you’re going to get the most effective member choice web page.

It’s additionally a good suggestion to load css and js of S2member solely on their pages. Verify S2Member – Basic Possibility – Lazy loading

Now, when all most necessary pages are prepared, it’s time to offer you some prolonged snippets and concepts.

All snippets should be added in the long run features.php file of theme or youngster theme (earlier than closed ?> tag in case you have it). Don’t overlook that it is best to add this code additionally after every replace of theme

2:Synchronization WC Vendor roles and S2Member

By default, WC Vendor has 2 roles – pending_vendor (when you’ve got person moderation) and vendorposition. One of many drawback is that S2member requires to make use of personal roles to deal with with permissions. These roles are

s2member_level1, s2member_level2, s2member_level3, s2member_level4

Additionally, there may be digital s2member_level0 degree which is the same as Subscriber position of WordPress.

So, once you promote member degree, for instance, s2member_level1, after buy, person will get this position, however vendor position can be deleted and person will lose vendor skills.

Thank’s to GOD, WordPress has means for multi roles, so, you possibly can add vendor position once more to paid member roles of S2member after every time when person or admin change position. Right here the snippet.

add_action( 'set_user_role', 'add_vendor_to_s2member_role', 30, 3 );
function add_vendor_to_s2member_role( $user_id, $new_role, $old_roles ) {
	$wp_user_object = new WP_User($user_id);
	$vendor_role   = 'vendor';
	$member_roles = array( 's2member_level1', 's2member_level2', 's2member_level3', 's2member_level4' );
	if ( in_array($new_role, $member_roles) ) {
		$wp_user_object->add_role( $vendor_role ); 
	}
	else {
		return;
	}
}

Explanation. set_user_role is hook in wordpress which is triggered once user change role. So, we will use it to add vendor role to user once he get one of S2member roles. You can also use this snippet when you want to sell Vendor role for users. All S2Member level with > 0 are paid levels, so, when user purchase level 1 or more, he will get also vendor role. You can also add snippet which makes user losing vendor role once he get downgrade to free level (for example, when his subscription will be expired).

add_action( 'set_user_role', 'add_vendor_to_s2member_role', 30, 3 );
function add_vendor_to_s2member_role( $user_id, $new_role, $old_roles ) {
	$wp_user_object = new WP_User($user_id);
	$vendor_role   = 'vendor';
	$member_roles = array( 's2member_level1', 's2member_level2', 's2member_level3', 's2member_level4' );
 	if ( $new_role == 's2member_level0' ) {
  		$wp_user_object->remove_role( $vendor_role ); 
	}
 	elseif ( $new_role == 'subscriber' ) {
  		$wp_user_object->remove_role( $vendor_role ); 
	}
	elseif ( in_array($new_role, $member_roles) ) {
		$wp_user_object->add_role( $vendor_role ); 
	}
	else {
		return;
	}
}

Also, maybe you need also to hide vendor dashboard from free users. Example code will hide dashboard if user doesn’t have level 1

[s2If current_user_can(access_s2member_level1)]
    [wcv_vendor_dashboard]
[/s2If]

[s2If !current_user_can(access_s2member_level1)]
    Some public content. Place here link on membership page or paypal button to update membership
[/s2If]

Also, one more useful snippet. You can add S2member role once vendor role will be applied to user from WC Vendor plugin. Code for this

add_action('wcvendors_application_submited', 'add_s2role_to_apply_vendor_form', 10, 1);
function add_s2role_to_apply_vendor_form( $user_id) {
	$wp_user_object = new WP_User($user_id);
	$wp_user_object->add_role( 's2member_level1' ); 
}

3:How to make limited post submission for free members

One of popular requests from my buyers is question how to limit user submit. For example, you want free users to have only 5 free post submission. I will show you some snippets for my bundled RH Frontend PRO plugin. If you have another submit plugin – code will be the same, difference is only in name of hooks in plugin. You can know names from plugin’s author.

Let’s start. First of all, You need to save custom field for submit form with form ID. This will allow to count how much posts user submits from this form (you can skip this step if you want to count all posts which were submitted from plugin).

My plugin has hidden field in form with form ID. It looks like

So, name of field is form_id, and my code to save custom field for post will be

wpfepp_form_1_actions is hook which runs before form save. If you use own plugin, make sure that you use correct name of hook.

_submitformid_topost – is custom field which will store form ID

Now, let’s add some counter when post will be published

add_action( 'publish_post', 'rh_counter_for_user_submit_form', 10, 2 );
function rh_counter_for_user_submit_form( $ID, $post ) {
	$default_counter = 5;
	$paid_form_id = get_post_meta( $ID, '_submitformid_topost', true );
	if ( !$paid_form_id or $paid_form_id <= 0 )
		return;
	
	$user_numb_post_meta = '_user_submit_counter_'. $paid_form_id;
	$author_number_post_package = get_user_meta( $post->post_author, $user_numb_post_meta, true );
	
	if ( !$author_number_post_package) {
		update_user_meta( $post->post_author, $user_numb_post_meta, $default_counter );	
	} else {
		$author_number_post_package = $author_number_post_package - 1;
		update_user_meta( $post->post_author, $user_numb_post_meta, $author_number_post_package );	
	}
}

Explanation. This function will be triggered when user submission will be published. Default limit for submit is 5. Code will save this limit to _user_submit_counter_1, where 1 is ID of form which will have limits. If you want to create code to count posts from all submit forms of all plugins, set

$paid_form_id = 'all';

So, code will save rely to _user_submit_counter_all. After every revealed posts, this counter can have minus 1. So, when it was 0 – you’ll be able to cover kind and present one thing one other (hyperlink on paid subscription web page, and many others)

Now, we will use this consumer knowledge for conditional logic. In my plugin there’s a hook which runs earlier than submit kind is printed on web page.

This hook is wpfepp_do_before_print_form for all varieties and wpfepp_do_before_1_print_form for kind with ID 1 (works on model greater than 3.25, when you have older model – replace plugin)

So, I can add subsequent code to restrict consumer entry to kind.

add_action('wpfepp_do_before_1_print_form', 'rh_limit_access_for_form');
function rh_limit_access_for_form(){
	$userid = get_current_user_id();
	$user_numb_post_meta = '_user_submit_counter_1';
	$message_for_no_posts = 'You riched limit of post submission. Please, <a href="http://site.com/link_to_member_update">update your membership</a>';	
	$author_number_post_package = get_user_meta( $userid, $user_numb_post_meta, true );
	if ($author_number_post_package){
		if ($author_number_post_package <= 0) {
			exit($message_for_no_posts);
		}
	}	
}

When person richs it’s restrict – he can’t see kind. As an alternative of this, he’ll see your customized message. This code will add restrict for kind ID = 1. Now you can create second kind which is obtainable just for member stage 1 (wrap it with conditional shortcodes from S2Member) and doesn’t have limits.

4:Url restrictions

S2member plugin has one good function even in free model. You possibly can conceal entry by url. That is very useful while you need limit entry to a part of website. For instance, you may disable entry for including profile picture header in Buddypress profiles. For instance, hyperlink the place person can change profile photograph in BuddyPress is http://website.com/members/rehubdemo/profile/change-avatar/

This hyperlinks is similar for all customers besides rehubdemo which is person nicename. S2member helps code replacements. So, hyperlink for including restrictions might be

http://website.com/members/%%current_user_nicename%%/profile/change-avatar/

5:Altering position based mostly on MyCred reputations

This code will change person position as soon as person will get popularity stage

/**
 * Promote Based on Balance
 * Changes a users role based on their myCRED balance.
 * @version 1.0.4
 */
add_filter( 'mycred_add_finished', 'rh_mycred_check_for_role_change', 99, 3 );
function rh_mycred_for_role_change( $reply, $request, $mycred ) {
	// Make sure that if any other filter has declined this we also decline
	if ( $reply === false ) return $reply;

	// Exclude admins
	if ( user_can( $request['user_id'], 'manage_options' ) ) return $reply;

	extract( $request );

	// Minimum balance requirement for each role
	$thresholds = array(
		's2member_level1'   => 100,
		's2member_level2'   => 1000,
		's2member_level3'   => 10000,
		's2member_level4' => 100000
	);

    // Get users current balance
	$current_balance = $mycred->get_users_balance( $user_id, $type );
	$current_balance = $current_balance + $amount;

	// Check if the users current balance awards a new role
	$new_role = false;
	foreach ( $thresholds as $role => $min ) {
		if ( $current_balance > $min )
			$new_role = $role;
	}

	// Change users role if we have one
	if ( $new_role !== false ){
		$wp_user_object = new WP_User($user_id);
		if (in_array( $new_role, (array) $wp_user_object->roles )){
	    	$wp_user_object->add_role($new_role);
		}
	}
	return $reply;
}

Further options

There’s yet another prolonged characteristic in plugin. It’s Customized Caps. You’ll be able to add further customized capabilities to existed roles and promote such functionality. For instance, you need to promote entry to particular web page, however you don’t need to add this to separate member position. Extra about Customized capabilities

If you want to setup extended membership logic and don’t want to do this yourself – contact with us. Note, that currently we create customization and setup only for our products.