| 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 |
|