• Resolved Vray admin

    (@vray-admin)


    Hi,
    I am trying to use Content Control in a .php WordPress template file.
    I have tried

    <?php echo do_shortcode('[content_control allowed_roles="subscriber"]'); ?>
    Content
    <?php echo do_shortcode('[/content_control]'); ?>

    But this isn’t working. Is there a way to restrict the content in my php file rather than using WordPress blocks?

    Thanks
    Richard

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

    (@kimmyx)

    Hi @vray-admin,

    Content Control restricts content generated within WordPress’ the_content() function, so post/page contents.

    If your PHP file is not within this function, our plugin cannot restrict it.

    Hope that helps! Let us know if you have other questions. 🙏

    Plugin Author Daniel Iser

    (@danieliser)

    @vray-admin – Technically speaking yes, there are underlying functions you can call passing in the check details, with or without using out global restrictions or blocks.

    You can use helper functions to check if a given post is visible to the current user based on global restrictions in the settings page, or use other helper functions to check manually user permissions such as \ContentControl\user_is_excluded() or \ContentControl\user_meets_requirements( $user_status, $user_roles = [], $role_match = 'match' )
    https://github.com/code-atlantic/content-control/blob/master/inc/functions/restrictions.php#L45-L126

    That said, given your simple example, you could bypass our plugin entirely:

    $user = wp_get_current_user();
    $allowed_roles = array( 'editor', 'administrator', 'author' );
    if ( array_intersect( $allowed_roles, $user->roles ) ) {
    // Stuff here for allowed roles
    }
Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Use Content Control in a PHP Template File’ is closed to new replies.