• Resolved hannahestes

    (@hannahestes)


    The content restriction is working great for us when it comes to viewing pages, I am just struggling with figuring out how to get and set the restriction settings for posts and terms via php code. I’d like to add hooks to my wordpress server that modify the visibility of a term, and allow me to see which roles are permitted to view a term.

    Is there any documented API for this? Or does anybody have ideas on how I might accomplish this?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Yurii

    (@yuriinalivaiko)

    Hello @hannahestes

    You can use the get_post_privacy_settings method to get the post restriction settings. This method tries to get restriction settings from the um_content_restriction post meta first, then tries to get restriction settings from related terms. return bool|array

    $post_id = 233;
    $restriction = UM()->access()->get_post_privacy_settings( $post_id );

    You can use the is_restricted method to test if the post is restricted or not. return bool

    $post_id = 233;
    $restricted = UM()->access()->is_restricted( $post_id );

    You can use the um_is_restricted_post hook to change the result of the is_restricted method. This hook does not work for administrators because administrators can access restricted posts.

    function um_is_restricted_post_filter( $restricted, $post_id, $on_single_page ) {
    	if ( $post_id === 233 ) {
    		$restricted = true;
    	}
    	return $restricted;
    }
    add_filter( 'um_is_restricted_post', 'um_is_restricted_post_filter', 10, 3 );

    You can get the term restriction settings from the um_content_restriction term meta.

    $term_id = 45;
    $restriction = get_term_meta( $term_id, 'um_content_restriction', true );

    You can use the is_restricted_term method to test if the term is restricted or not. return bool

    $term_id = 45;
    $restricted = UM()->access()->is_restricted_term( $term_id );

    You can use the um_is_restricted_term hook to change the result of the is_restricted_term method. This hook does not work for administrators because administrators can access restricted terms.

    function um_is_restricted_term_filter( $restricted, $term_id, $on_term_page ) {
    	if ( $term_id === 45 ) {
    		$restricted = true;
    	}
    	return $restricted;
    }
    add_filter( 'um_is_restricted_term', 'um_is_restricted_term_filter', 10, 3 );

    Regards

    Plugin Support andrewshu

    (@andrewshu)

    Hi @hannahestes

    This thread has been inactive for a while so we’re going to go ahead and mark it Resolved.

    Please feel free to re-open this thread if any other questions come up and we’d be happy to help. 🙂

    Regards

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Modify post and term descriptions in code’ is closed to new replies.