Last active
December 5, 2023 13:49
-
-
Save megane9988/4404835c86d2f265d294f58bb480468d to your computer and use it in GitHub Desktop.
特定の条件に基づいて利用可能なブロックタイプを制限または許可する関数です。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* 特定の条件に基づいて利用可能なブロックタイプを制限または許可する関数です。 | |
* | |
* @return array 制限または許可されるブロックタイプの配列。. | |
*/ | |
function mgn_custom_allowed_block_types() { | |
// 主要なroles: administrator, editor, author, contributor, subscriber. | |
$user_roll = 'contributor'; | |
// 現在のユーザー情報を取得. | |
$user = wp_get_current_user(); | |
// 特定の条件に基づいて利用可能なブロックタイプを許可. | |
if ( in_array( $user_roll, $user->roles, true ) ) { | |
$allowed_block_types = array( | |
'core/image', | |
'core/paragraph', | |
// ブロック一覧 | |
// 'core/audio' | |
// 'core/button' | |
// 'core/buttons' | |
// 'core/freeform' | |
// 'core/code' | |
// 'core/column' | |
// 'core/columns' | |
// 'core/details' | |
// 'core/group' | |
// 'core/html' | |
// 'core/list' | |
// 'core/list-item' | |
// 'core/media-text' | |
// 'core/missing' | |
// 'core/more' | |
// 'core/nextpage' | |
// 'core/paragraph' | |
// 'core/preformatted' | |
// 'core/pullquote' | |
// 'core/quote' | |
// 'core/separator' | |
// 'core/social-links' | |
// 'core/spacer' | |
// 'core/table' | |
// 'core/table-of-contents' | |
// 'core/text-columns' | |
// 'core/verse' | |
// 'core/video' | |
// 'core/embed' | |
// 'core/widget-area' | |
// 'core/social-link-amazon' | |
// 'core/social-link-bandcamp' | |
// 'core/social-link-behance' | |
// 'core/social-link-chain' | |
// 'core/social-link-codepen' | |
// 'core/social-link-deviantart' | |
// 'core/social-link-dribbble' | |
// 'core/social-link-dropbox' | |
// 'core/social-link-etsy' | |
// 'core/social-link-facebook' | |
// 'core/social-link-feed' | |
// 'core/social-link-fivehundredpx' | |
// 'core/social-link-flickr' | |
// 'core/social-link-foursquare' | |
// 'core/social-link-goodreads' | |
// 'core/social-link-google' | |
// 'core/social-link-github' | |
// 'core/social-link-instagram' | |
// 'core/social-link-lastfm' | |
// 'core/social-link-linkedin' | |
// 'core/social-link-mail' | |
// 'core/social-link-mastodon' | |
// 'core/social-link-meetup' | |
// 'core/social-link-medium' | |
// 'core/social-link-pinterest' | |
// 'core/social-link-pocket' | |
// 'core/social-link-reddit' | |
// 'core/social-link-skype' | |
// 'core/social-link-snapchat' | |
// 'core/social-link-soundcloud' | |
// 'core/social-link-spotify' | |
// 'core/social-link-tumblr' | |
// 'core/social-link-twitch' | |
// 'core/social-link-twitter' | |
// 'core/social-link-vimeo' | |
// 'core/social-link-vk' | |
// 'core/social-link-wordpress' | |
// 'core/social-link-yelp' | |
// 'core/social-link-youtube' | |
// 'advgb/recent-posts' | |
// 'core/archives' | |
// 'core/avatar' | |
// 'core/block' | |
// 'core/calendar' | |
// 'core/categories' | |
// 'core/cover' | |
// 'core/comment-author-avatar' | |
// 'core/comment-author-name' | |
// 'core/comment-content' | |
// 'core/comment-date' | |
// 'core/comment-edit-link' | |
// 'core/comment-reply-link' | |
// 'core/comment-template' | |
// 'core/comments-pagination' | |
// 'core/comments-pagination-next' | |
// 'core/comments-pagination-numbers' | |
// 'core/comments-pagination-previous' | |
// 'core/comments-title' | |
// 'core/comments' | |
// 'core/footnotes' | |
// 'core/file' | |
// 'core/home-link' | |
// 'core/image' | |
// 'core/gallery' | |
// 'core/heading' | |
// 'core/latest-comments' | |
// 'core/latest-posts' | |
// 'core/loginout' | |
// 'core/navigation' | |
// 'core/navigation-link' | |
// 'core/navigation-submenu' | |
// 'core/page-list' | |
// 'core/page-list-item' | |
// 'core/pattern' | |
// 'core/post-author' | |
// 'core/post-author-name' | |
// 'core/post-author-biography' | |
// 'core/post-comment' | |
// 'core/post-comments-count' | |
// 'core/post-comments-form' | |
// 'core/post-comments-link' | |
// 'core/post-content' | |
// 'core/post-date' | |
// 'core/post-excerpt' | |
// 'core/post-featured-image' | |
// 'core/post-navigation-link' | |
// 'core/post-terms' | |
// 'core/post-time-to-read' | |
// 'core/post-title' | |
// 'core/query' | |
// 'core/post-template' | |
// 'core/query-no-results' | |
// 'core/query-pagination' | |
// 'core/query-pagination-next' | |
// 'core/query-pagination-numbers' | |
// 'core/query-pagination-previous' | |
// 'core/query-title' | |
// 'core/read-more' | |
// 'core/rss' | |
// 'core/search' | |
// 'core/shortcode' | |
// 'core/social-link' | |
// 'core/site-logo' | |
// 'core/site-tagline' | |
// 'core/site-title' | |
// 'core/tag-cloud' | |
// 'core/template-part' | |
// 'core/term-description' | |
// 'core/legacy-widget' | |
// 'core/widget-group' | |
// 'core/post-comments' | |
// https://developer.wordpress.org/block-editor/developers/block-api/block-registration/ . | |
); | |
} | |
return $allowed_block_types; | |
} | |
add_filter( 'allowed_block_types_all', 'mgn_custom_allowed_block_types', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment