/** * @param integer|WP_user $user User object to check. * @param string $action Type of action, either 'view' or 'edit'. * @return boolean If user has access or not. */ public function UserCan($user, $action) { if (is_int($user)) { $user = get_userdata($user); } $allowed = array(); switch ($action) { case 'view': $allowed = $this->GetAllowedPluginViewers(); $allowed = array_merge($allowed, $this->GetAllowedPluginEditors()); $allowed = array_merge($allowed, $this->GetSuperAdmins()); $allowed = array_merge($allowed, $this->GetAdmins()); break; case 'edit': $allowed = $this->GetAllowedPluginEditors(); $allowed = array_merge($allowed, $this->_plugin->IsMultisite() ? $this->GetSuperAdmins() : $this->GetAdmins()); break; default: throw new Exception('Unknown action "' . $action . '".'); } $check = array_merge($user->roles, array($user->user_login)); if (is_multisite()) { $allowed = array_merge($allowed, get_super_admins()); } else { $allowed[] = 'administrator'; } foreach ($check as $item) { if (in_array($item, $allowed)) { return true; } } return false; }
/** * Returns access tokens for a particular action. * @param string $action Type of action. * @return string[] List of tokens (usernames, roles etc). */ public function GetAccessTokens($action) { $allowed = array(); switch ($action) { case 'view': $allowed = $this->GetAllowedPluginViewers(); $allowed = array_merge($allowed, $this->GetAllowedPluginEditors()); if (!$this->IsRestrictAdmins()) { $allowed = array_merge($allowed, $this->GetSuperAdmins()); $allowed = array_merge($allowed, $this->GetAdmins()); } break; case 'edit': $allowed = $this->GetAllowedPluginEditors(); if (!$this->IsRestrictAdmins()) { $allowed = array_merge($allowed, $this->_plugin->IsMultisite() ? $this->GetSuperAdmins() : $this->GetAdmins()); } break; default: throw new Exception('Unknown action "' . $action . '".'); } if (!$this->IsRestrictAdmins()) { if (is_multisite()) { $allowed = array_merge($allowed, get_super_admins()); } else { $allowed[] = 'administrator'; } } return array_unique($allowed); }
public function GetColumns() { $columns = array('alert_code' => '1', 'type' => '1', 'date' => '1', 'username' => '1', 'source_ip' => '1', 'message' => '1'); if ($this->_plugin->IsMultisite()) { $columns = array_slice($columns, 0, 5, true) + array('site' => '1') + array_slice($columns, 5, null, true); } $selected = $this->GetColumnsSelected(); if (!empty($selected)) { $columns = array('alert_code' => '0', 'type' => '0', 'date' => '0', 'username' => '0', 'source_ip' => '0', 'message' => '0'); if ($this->_plugin->IsMultisite()) { $columns = array_slice($columns, 0, 5, true) + array('site' => '0') + array_slice($columns, 5, null, true); } $selected = (array) json_decode($selected); $columns = array_merge($columns, $selected); return $columns; } else { return $columns; } }
public function DeactivateLicense($name, $license = null) { $this->plugin->settings->SetLicenseStatus($name, ''); // deactivate it on the server (if license was given) if (!is_null($license)) { $plugins = $this->Plugins(); $api_params = array('edd_action' => 'deactivate_license', 'license' => urlencode($license), 'item_name' => urlencode($plugins[$name]['PluginData']['Name']), 'url' => urlencode(home_url())); $blog_ids = $this->plugin->IsMultisite() ? $this->GetBlogIds() : array(1); foreach ($blog_ids as $blog_id) { if ($this->plugin->IsMultisite()) { $api_params['url'] = urlencode(get_home_url($blog_id)); } $response = wp_remote_get(esc_url_raw(add_query_arg($api_params, $this->GetStoreUrl())), array('timeout' => 15, 'sslverify' => false)); if (is_wp_error($response)) { return false; } wp_remote_retrieve_body($response); } } }
protected function is_multisite() { return $this->_plugin->IsMultisite(); }