Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

《Wordpress》Contact Form 7で「Flamingo」の権限をコントロールする。

More than 3 years have passed since last update.

入力フォームプラグイン「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」の閲覧削除などができるようになります。

おわります。

uto-usui
Branding Engineer @ Condé Nast 🇯🇵 for VOUGE GQ WIRED/Songwriter/Fav. 🐈 🌸 🎸 📸 📚 🛠🍎☕️🍷👩🏻‍💻
https://uto-usui.com/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away