CCAP with Apprentice Course custom posts

I’m using Thrive Apprentice plugin to create courses. The lesson pages are custom posts not in the WP dashboard under Posts or Pages. The content for the pages is edited in the Apprentice plugin. The pages end up under the /courses/ path.

I see how to use URI to limit the /courses/ path to a membership.

But I want to use CCAPs to sell individual courses. However, usually you can assign those to a Page or Post in the WP dashboard when editing the page/post. But the Apprentice plugin where you manage a course page’s content doesn’t have the s2 Member widget with the Require Custom Capabilities field.

Is there a way to set these “under the hood” in the database or php?

Or open to other best practices to manage Apprentice courses with s2 Member.

Thanks

Perhaps I can ask this in a different way.

If for a normal Page or Post, I put ccaps into the Require Custom Capabilities field of the s2Member widget, where is the information encoded for s2Member to apply later? Is it in a table in the DB or in files. Some hint at how it works might let me manually set them for the custom posts in Apprentice.

Thanks

Ccaps are stored in the database. You can give a member a ccap programmatically by incorporating something like this into a function:

$ccap = 'access_s2member_ccap_' . name-of-ccap;
$user = new WP_User( $user_id );
$user->add_cap( $ccap );

You can set the ccap for a post by using something like this:

add_post_meta( $post_id, 's2member_ccaps_req', [$ccap] );
1 Like

Awesome, thanks, Tim.

So adding the ccap to a member could be done via a regular s2Member form/payment setup, right?

Adding them to the page, I simply need to execute a function to add_post_meta for each custom post ID - ccaps combination, in place of filling it out in the WP editor Require Custom Capabilities field of the s2Member section.

So a really basic question – what’s the simplest way to run those one time add_post_meta calls? Does WP dashboard have a command line mechanism? Or have to execute a script somewhere? (Yes, 1st time really using Wordpress beyond publishing posts! :wink:

THANKS!

Yes.[quote=“stlb, post:4, topic:3843”]
what’s the simplest way to run those one time add_post_meta calls?
[/quote]

Try adding this as an mu-plugin (i.e. save it as add-cap.php and upload it to the mu-plugins folder) after replacing name-of-ccap1 and name-of-ccap2 as appropriate:

<?php
function kts_add_ccap( $user_id, $role, $old_role ) {
	if ( !$user_id > 0 ) {
		return;
	}
	if ( $role == 's2member_level1' ) {
		$ccap = 'access_s2member_ccap_' . name-of-ccap1;
		add_post_meta( $post_id, 's2member_ccaps_req', [$ccap] );
	}
	if ( $role == 's2member_level2' ) {
		$ccap = 'access_s2member_ccap_' . name-of-ccap2;
		add_post_meta( $post_id, 's2member_ccaps_req', [$ccap] );
	}
}
add_action( 'set_user_role', 'kts_add_ccap', 20, 3 );

Hello, I don’t know if someone is still interested in using TA with S2member, I could do it with a workaround: The new TA lessons can’t be protected with s2member but the old apprentice lessons can. I just did setup a redirect, the new lessons (that can’t be protected with s2member) just redirect to the old ones (protected with s2member).

It just took a couple of hour to duplicate the titles of the lessons in the new TA menu, and then create the redirects. I think it’s easier than messing with the database. What do you think?
Cheers
Leo

1 Like