PluginProbe
Email Log / 2.63
Email Log v2.63
2.63 2.4.8 2.4.9 2.6 2.61 2.62 trunk 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.8.1 0.9 0.9.1 0.9.2 1.1 1.5 1.5.1 1.5.2 1.5.3 1.5.4 All 61 releases
email-log / include / Core / AdminCapabilityGiver.php

AdminCapabilityGiver.php in Email Log 2.63, at include/Core/AdminCapabilityGiver.php

60 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php namespace EmailLog\Core;
2
3 use EmailLog\Core\UI\Page\LogListPage;
4
5 defined( 'ABSPATH' ) || exit; // Exit if accessed directly.
6
7 /**
8 * Gives capability to admin.
9 * By default admins should be able to manage email logs.
10 *
11 * @since 2.1.0
12 */
13 class AdminCapabilityGiver implements Loadie {
14
15 public function load() {
16 add_filter( 'user_has_cap', array( $this, 'add_cap_to_admin_cap_list' ), 10, 4 );
17 }
18
19 /**
20 * Add `manage_email_logs` capability to admin's list of capabilities during `user_has_cap` check.
21 *
22 * In new installs this capability will be added to admins on plugin install.
23 * But in old installs the admins will not have this capability and that's why we need to add it using the filter.
24 *
25 * @param array $allcaps An array of all the user's capabilities.
26 * @param array $caps Actual capabilities for meta capability.
27 * @param array $args Optional parameters passed to has_cap(), typically object ID.
28 * @param \WP_User $user The user object.
29 *
30 * @return array Modified list of user's capabilities.
31 */
32 public function add_cap_to_admin_cap_list( $allcaps, $caps, $args, $user ) {
33 if ( ! in_array( 'administrator', $user->roles ) ) {
34 return $allcaps;
35 }
36
37 if ( array_key_exists( LogListPage::CAPABILITY, $allcaps ) ) {
38 return $allcaps;
39 }
40
41 $allcaps[ LogListPage::CAPABILITY ] = true;
42
43 return $allcaps;
44 }
45
46 /**
47 * Add Manage Email Logs capability to administrator role.
48 * This will be called on install.
49 */
50 public function add_cap_to_admin() {
51 $admin = get_role( 'administrator' );
52
53 if ( is_null( $admin ) ) {
54 return;
55 }
56
57 $admin->add_cap( LogListPage::CAPABILITY );
58 }
59 }
60