How to autofill ccaps and roles in s2Member metabox?

I have some code to autogenerate pages. What I’d like to be able to do at the same time is to fill the ccap field in the s2Member metabox, instead of having to remember to do this manually after creating the page.

It would also be great to be able to autofill the role field at the same time.

What would then make this really awesome would be code that forced any sub-page to inherit the role and/or ccap requirement(s) of its parent.

Any suggestions?

This is strange. I have found that this code:

add_post_meta( $page_id, 's2member_ccaps_req', 'name-of-ccap');

does autofill the ccap metabox on the page edit screen.

But that isn’t reflected in the (s2) column in the list of pages in the admin, and it doesn’t protect the page from being accessed by users without that ccap.

Getting closer! This code produces the same ultimate result in that it fills the page metabox, but does not protect the page:

global $wpdb;
$wpdb->insert( $wpdb->postmeta, array(
'post_id'    =>  $page_id,
'meta_key'   =>  's2member_ccaps_req',
'meta_value' =>  serialize( 'name-of-ccap' )

) );
``
But the entry in the database is now much closer to what it needs to be. So I think it just needs a tweak.