PluginProbe
User Notes / 2.0.1
User Notes v2.0.1
2.1.1 2.1.0 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 2.0.0 2.0.1
user-notes / includes / caps.php

caps.php in User Notes 2.0.1, at includes/caps.php

41 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if (!defined('ABSPATH')) exit;
3
4 /**
5 * Can the current user view/manage notes for $target_user_id?
6 * Users can NEVER see notes on their own profile.
7 */
8 function user_notes_current_user_can_view($target_user_id = 0) {
9 if (!current_user_can('list_users')) return false;
10 if ($target_user_id && get_current_user_id() == $target_user_id) return false;
11 return true;
12 }
13
14 function user_notes_current_user_can_edit($target_user_id = 0) {
15 return user_notes_current_user_can_view($target_user_id);
16 }
17
18 function user_notes_current_user_can_delete($target_user_id = 0) {
19 if (!current_user_can('delete_users')) return false;
20 if ($target_user_id && get_current_user_id() == $target_user_id) return false;
21 return true;
22 }
23
24 function user_notes_format_author($author_id) {
25 if (!$author_id) return __('System', 'user-notes');
26 $u = get_userdata($author_id);
27 /* translators: %d: numeric user ID */
28 return $u ? $u->display_name : sprintf(__('User #%d', 'user-notes'), $author_id);
29 }
30
31 function user_notes_format_time($mysql_dt) {
32 $ts = strtotime(get_gmt_from_date($mysql_dt) . ' UTC');
33 if (!$ts) return esc_html($mysql_dt);
34 $diff = time() - $ts;
35 if ($diff < DAY_IN_SECONDS) {
36 /* translators: %s: human-readable time difference, e.g. "3 hours" */
37 return sprintf(__('%s ago', 'user-notes'), human_time_diff($ts));
38 }
39 return date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $ts + (get_option('gmt_offset') * HOUR_IN_SECONDS));
40 }
41