LoginSignup
2
2

More than 5 years have passed since last update.

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

Posted at

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

おわります。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2