shvsh > /home/1168859.cloudwaysapps.com/rcyqmhwrmv/public_html/docs/wp-content/plugins/ht-knowledge-base/ht-knowledge-base.php
shvsh > /home/1168859.cloudwaysapps.com/rcyqmhwrmv/public_html/docs/wp-content/plugins/ht-knowledge-base/ht-knowledge-base.php
shvsh > /home/1168859.cloudwaysapps.com/rcyqmhwrmv/public_html/docs/wp-content/plugins/ht-knowledge-base/ht-knowledge-base.php

Restrict Blocks access to Instructors

The Gutenberg editor provides a set of default core blocks which can be used to create your course content.

But apart from the core blocks many different plugins such as LearnDash, Woocommerce, etc. provide additional blocks to display interactive content.

Screenshot for LearnDash LMS Blocks

Few examples of the LearnDash blocks would be

  • LearnDash Login Block
  • LearnDash Profile Block
  • LearnDash Course List Block

By default an instructor has access to all these blocks.

In order to restrict access to only the default WP Core Blocks, use the following code snippet in either

  • Your child theme’s functions.php file
  • Make use of the Code Snippets add-on
/**
 * Restrict access to core blocks for instructors
 *
 * @param bool|array $allowed_block_types    Array of block type slugs, or boolean to enable/disable all.
 * @param object     $post                   The post resource data.
 *
 * @return bool|array                        Updated array of block type slugs, or boolean to enable/disable all.
 *
 * @author Kumar Rajpurohit <[email protected]>
 */
function ir_custom_filter_instructor_blocks( $allowed_block_types, $post ) {
    // Check if instructor.
    if ( ! function_exists( 'wdm_is_instructor' ) || ! wdm_is_instructor() ) {
        return $allowed_block_types;
    }

    // List of all WP core block slugs.
    $core_blocks = array(
	 	'core/paragraph',	// Paragraph Block
        'core/image',   // Image Block
        'core/heading', // Heading Block
        'core/gallery', // Gallery Block
        'core/list',    // List Block
        'core/quote',   // Quote Block
        'core/shortcode',   // Shortcode Block
        'core/archives',    // Archives Block
        'core/audio',   // Audio Block
        'core/button',  // Button Block
        'core/buttons', // Buttons Block
        'core/calendar',    // Calendar Block
        'core/categories',  // Categories Block
        'core/code',    // Code Block
        'core/columns', // Columns Block
        'core/column',  // Column Block
        'core/cover',   // Cover Block
        'core/embed',   // Embed Block
        'core-embed/twitter',   // Embed Twitter Block
        'core-embed/youtube',   // Embed Youtube Block
        'core-embed/facebook',  // Embed Facebook Block
        'core-embed/instagram', // Embed Instagram Block
        'core-embed/wordpress', // Embed WordPress Block
        'core-embed/soundcloud',    // Embed Soundcloud Block
        'core-embed/spotify',   // Embed Spotify Block
        'core-embed/flickr',    // Embed Flickr Block
        'core-embed/vimeo', // Embed Vimeo Block
        'core-embed/animoto',   // Embed Animoto Block
        'core-embed/cloudup',   // Embed Cloudup Block
        'core-embed/collegehumor',  // Embed Collegehumor Block
        'core-embed/crowdsignal',   // Embed Crowdsignal Block
        'core-embed/dailymotion',   // Embed Dailymotion Block
        'core-embed/hulu',  // Embed Hulu Block
        'core-embed/imgur', // Embed Imgur Block
        'core-embed/issuu', // Embed Issuu Block
        'core-embed/kickstarter',   // Embed Kickstarter Block
        'core-embed/meetup-com',    // Embed Meetup com Block
        'core-embed/mixcloud',  // Embed Mixcloud Block
        'core-embed/polldaddy', // Embed Polldaddy Block
        'core-embed/reddit',    // Embed Reddit Block
        'core-embed/reverbnation',  // Embed Reverbnation Block
        'core-embed/screencast',    // Embed Screencast Block
        'core-embed/scribd',    // Embed Scribd Block
        'core-embed/slideshare',    // Embed Slideshare Block
        'core-embed/smugmug',   // Embed Smugmug Block
        'core-embed/speaker',   // Embed Speaker Block
        'core-embed/speaker-deck',  // Embed Deck Block
        'core-embed/tiktok',    // Embed Tiktok Block
        'core-embed/ted',   // Embed Ted Block
        'core-embed/tumblr',    // Embed Tumblr Block
        'core-embed/videopress',    // Embed Videopress Block
        'core-embed/wordpress-tv',  // Embed Tv Block
        'core-embed/amazon-kindle', // Embed Kindle Block
        'core/file',    // File Block
        'core/group',   // Group Block
        'core/freeform',    // Freeform Block
        'core/html',    // HTML Block
        'core/media-text',  // Media Text Block
        'core/latest-comments', // Latest Comments Block
        'core/latest-posts',    // Latest Posts Block
        'core/missing', // Missing Block
        'core/more',    // More Block
        'core/nextpage',    // Nextpage Block
        'core/preformatted',    // Preformatted Block
        'core/pullquote',   // Pullquote Block
        'core/rss', // RSS Block
        'core/search',  // Search Block
        'core/separator',   // Separator Block
        'core/block',   // Block Block
        'core/social-links',    // Social Links Block
        'core/social-link', // SOcial Link Block
        'core/spacer',  // Spacer Block
        'core/subhead', // Subhead Block
        'core/table',   // Table Block
        'core/tag-cloud',   // Cloud Block
        'core/text-columns',    // Text Columns Block
        'core/verse',   // Verse Block
        'core/video'    // Video Block
    );

    $allowed_block_types = $core_blocks;

    return $allowed_block_types;
}
add_filter( 'allowed_block_types', 'ir_custom_filter_instructor_blocks', 10, 2 );

You can even take it a step further and select chosen from the above core blocks list or add additional blocks to it.

Updated on September 23, 2020
shvsh > /home/1168859.cloudwaysapps.com/rcyqmhwrmv/public_html/docs/wp-content/plugins/ht-knowledge-base/ht-knowledge-base.php
shvsh > /home/1168859.cloudwaysapps.com/rcyqmhwrmv/public_html/docs/wp-content/plugins/ht-knowledge-base/ht-knowledge-base.php
shvsh > /home/1168859.cloudwaysapps.com/rcyqmhwrmv/public_html/docs/wp-content/plugins/ht-knowledge-base/ht-knowledge-base.php

Was this article helpful?

shvsh > /home/1168859.cloudwaysapps.com/rcyqmhwrmv/public_html/docs/wp-content/plugins/ht-knowledge-base/ht-knowledge-base.php
shvsh > /home/1168859.cloudwaysapps.com/rcyqmhwrmv/public_html/docs/wp-content/plugins/ht-knowledge-base/ht-knowledge-base.php

Related Articles