/** * Check Access for a specific user * @author Howard R <*****@*****.**> * @static * @param string $access * @param int $owner_id * @param int $user_id * @return boolean */ public static function check_access($access, $owner_id = 0, $user_id = '') { /** get current user id **/ if (trim($user_id) == '') { $user_id = wpl_users::get_cur_user_id(); } $user_data = wpl_users::get_wpl_data($user_id); /** user is registered in WordPress but not in WPL so we choose guest user for accesses **/ if (!$user_data) { $user_data = wpl_users::get_wpl_data(0); } if ($access == 'edit') { if ($owner_id == $user_id or wpl_users::is_administrator($user_id)) { return true; } } elseif ($access == 'add') { $num_prop_limit = $user_data->maccess_num_prop; $num_prop = wpl_users::get_users_properties_count($user_id); if ($num_prop_limit == '-1') { return true; } # unlimited if ($num_prop_limit <= $num_prop and !wpl_users::is_administrator($user_id)) { return false; } else { return true; } } elseif ($access == 'delete') { if ($user_data->access_delete and ($owner_id == $user_id or wpl_users::is_administrator($user_id))) { return true; } } elseif ($access == 'confirm') { if ($user_data->access_confirm and ($owner_id == $user_id or wpl_users::is_administrator($user_id))) { return true; } } else { return isset($user_data->{'access_' . $access}) ? $user_data->{'access_' . $access} : 0; } return false; }