Hi @websavers
Unfortunately, this requires customization. You can try the following code snippet to save a UM Content Restriction on saving a custom post type:
add_action("save_post","um_110921_save_content_restrictions", 99999 );
function um_110921_save_content_restrictions( $post_id ){
$content_restrictions = maybe_unserialize('a:9:{s:26:"_um_custom_access_settings";b:1;s:14:"_um_accessible";i:2;s:16:"_um_access_roles";a:1:{s:10:"subscriber";s:1:"1";}s:28:"_um_access_hide_from_queries";b:0;s:19:"_um_noaccess_action";i:0;s:30:"_um_restrict_by_custom_message";i:0;s:27:"_um_restrict_custom_message";s:0:"";s:19:"_um_access_redirect";i:0;s:23:"_um_access_redirect_url";s:0:"";}');
unset( $content_restrictions['_um_access_roles'] );
$content_restrictions['_um_access_roles']['subscriber'] = 1;
$content_restrictions['_um_access_roles']['um_user-role-a'] = 1;
update_post_meta( $post_id, "um_content_restriction", $content_restrictions );
}
The above code will enable the UM Content Restriction with Subscriber( subscriber )
and User Role A ( um_user-role-a )
roles of a post/custom post type. You can change the role slug to match the roles on your site that you want to enable the content restriction. Also, the above code uses save_post
as an action hook, if you have a custom post type, just change it to save_post_{your custom post type slug}
e.g. save_post_myproducts
.
Regards,
-
This reply was modified 2 years, 5 months ago by Champ Camba.
-
This reply was modified 2 years, 5 months ago by Champ Camba.
-
This reply was modified 2 years, 5 months ago by Champ Camba.
Thank you @champsupertramp !
I am not a huge fan of the need to add this data to postmeta for every post when it applies to every single one of them. It just seems wasteful to me, though I get why this is a good option for some.
Instead of this method (and because I found the original devs of this site already had a custom page template for the post type) I modified the page template and put my display conditionals based on user role in there.
-
This reply was modified 2 years, 5 months ago by websavers.
Thanks for letting us know how you resolve the issue.
Regards,