入力フォームプラグイン「Contact Form 7」 を使用している際、データベースに情報を保存してくれるアドオン「flamingo」のいろいろな権限をコントロールする方法です。
以下のコードでは、「flamingo」のあらゆる権限をedit_posts
と同等に扱うよう指定しています。
php.function.php
/**
*
* flamingo custom capability
*
*/
function flamingo_custom_cap( $caps, $cap, $user_id, $args ) {
$meta_caps = array(
'flamingo_edit_contacts' => 'edit_posts',
'flamingo_edit_contact' => 'edit_posts',
'flamingo_delete_contact' => 'edit_posts',
'flamingo_edit_inbound_messages' => 'edit_posts',
'flamingo_delete_inbound_message' => 'edit_posts',
'flamingo_delete_inbound_messages' => 'edit_posts',
'flamingo_spam_inbound_message' => 'edit_posts',
'flamingo_unspam_inbound_message' => 'edit_posts',
'flamingo_edit_outbound_messages' => 'edit_posts',
'flamingo_edit_outbound_message' => 'edit_posts',
'flamingo_delete_outbound_message' => 'edit_posts' );
$caps = array_diff( $caps, array_keys( $meta_caps ) );
if ( isset( $meta_caps[$cap] ) )
$caps[] = $meta_caps[$cap];
return $caps;
}
remove_filter( 'map_meta_cap', 'flamingo_map_meta_cap' );
add_filter( 'map_meta_cap', 'flamingo_custom_cap', 5, 4 );
edit_posts
を任意のものに変更すると、その権限が付与されているユーザーが「flamingo」の閲覧削除などができるようになります。
おわります。