| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: User Notes |
| 4 |
Plugin URI: http://cartpauj.com |
| 5 |
Description: Keep private notes about each of your users that only Administrators can see. |
| 6 |
Version: 1.0.3 |
| 7 |
Author: Cartpauj |
| 8 |
Author URI: http://cartpauj.com |
| 9 |
Text Domain: user-notes |
| 10 |
|
| 11 |
This program is free software; you can redistribute it and/or modify |
| 12 |
it under the terms of the GNU General Public License as published by |
| 13 |
the Free Software Foundation; either version 2 of the License, or |
| 14 |
(at your option) any later version. |
| 15 |
|
| 16 |
This program is distributed in the hope that it will be useful, |
| 17 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 |
GNU General Public License for more details. |
| 20 |
|
| 21 |
You should have received a copy of the GNU General Public License |
| 22 |
along with this program; if not, write to the Free Software |
| 23 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 24 |
*/ |
| 25 |
|
| 26 |
function user_notes_get_delim($link) { |
| 27 |
return ((preg_match("#\?#",$link))?'&':'?'); |
| 28 |
} |
| 29 |
|
| 30 |
function user_notes_show_field($wp_user) { |
| 31 |
//If not an admin -- don't show this -- that would be bad :) |
| 32 |
if(!current_user_can('list_users')) |
| 33 |
return; |
| 34 |
|
| 35 |
$notes = get_user_meta($wp_user->ID, 'user-notes-note', true); |
| 36 |
|
| 37 |
?> |
| 38 |
<h3><?php _e('User Notes', 'user-notes'); ?></h3> |
| 39 |
|
| 40 |
<table class="form-table"> |
| 41 |
<tbody> |
| 42 |
<tr> |
| 43 |
<td colspan="2"> |
| 44 |
<?php wp_editor($notes, 'user_notes_note', array('teeny' => true)); ?> |
| 45 |
</td> |
| 46 |
</tr> |
| 47 |
</tbody> |
| 48 |
</table> |
| 49 |
<?php |
| 50 |
} |
| 51 |
add_action('show_user_profile', 'user_notes_show_field'); |
| 52 |
add_action('edit_user_profile', 'user_notes_show_field'); |
| 53 |
|
| 54 |
function user_notes_save_note($user_id) { |
| 55 |
//Only admins, and only if it's set (so we don't wipe out the notes when non-admins save the profile) |
| 56 |
if(!current_user_can('list_users') || !isset($_POST['user_notes_note'])) |
| 57 |
return; |
| 58 |
|
| 59 |
$notes = (!empty($_POST['user_notes_note']))?wp_kses_post(stripslashes($_POST['user_notes_note'])):''; |
| 60 |
|
| 61 |
update_user_meta($user_id, 'user-notes-note', $notes); |
| 62 |
} |
| 63 |
add_action('personal_options_update', 'user_notes_save_note'); |
| 64 |
add_action('edit_user_profile_update', 'user_notes_save_note'); |
| 65 |
|
| 66 |
function user_notes_add_users_column($cols) { |
| 67 |
$cols = array_merge($cols, array('user_notes_note' => __('Notes', 'user-notes'))); |
| 68 |
|
| 69 |
return $cols; |
| 70 |
} |
| 71 |
add_filter('manage_users_columns', 'user_notes_add_users_column'); |
| 72 |
|
| 73 |
function user_notes_display_column($val, $col_name, $user_id) { |
| 74 |
if($col_name == 'user_notes_note') { |
| 75 |
$notes = get_user_meta($user_id, 'user-notes-note', true); |
| 76 |
|
| 77 |
//If no notes -- return none |
| 78 |
if(empty($notes)) |
| 79 |
return '<a href="' . esc_url(admin_url('user-edit.php?user_id=' . $user_id . '#wp-user_notes_note-wrap')) . '">' . esc_html__('Add Note', 'user-notes') . '</a>'; |
| 80 |
|
| 81 |
$notes_excerpt = strip_tags(substr($notes, 0, 100)) . ' ...'; |
| 82 |
$notes_excerpt = trim(preg_replace('/\s+/', ' ', $notes_excerpt)); |
| 83 |
|
| 84 |
$user = new WP_User($user_id); |
| 85 |
$title = __('Note for', 'user-notes') . ' ' . $user->user_login . "\n" . $notes_excerpt; |
| 86 |
|
| 87 |
//Get the dilimiter |
| 88 |
$uri = $_SERVER['REQUEST_URI']; |
| 89 |
$delim = user_notes_get_delim($uri); |
| 90 |
|
| 91 |
ob_start(); |
| 92 |
|
| 93 |
?> |
| 94 |
<div id="user_notes_thickbox_<?php echo esc_attr($user_id); ?>" style="display:none;"> |
| 95 |
<?php echo wp_kses_post(wpautop($notes)); ?> |
| 96 |
<p><a href="<?php echo esc_url(admin_url('user-edit.php?user_id=' . $user_id . '#wp-user_notes_note-wrap')); ?>"><?php _e('Edit Note'); ?></a></p> |
| 97 |
</div> |
| 98 |
<strong><a href="#TB_inline<?php echo esc_attr($delim); ?>inlineId=user_notes_thickbox_<?php echo esc_attr($user_id); ?>" class="thickbox" title="<?php echo esc_attr($title); ?>" style="color:navy;"><?php _e('View Note', 'user-notes'); ?></a></strong> |
| 99 |
<?php |
| 100 |
|
| 101 |
return ob_get_clean(); |
| 102 |
} |
| 103 |
|
| 104 |
return $val; |
| 105 |
} |
| 106 |
add_action('manage_users_custom_column', 'user_notes_display_column', 10, 3); |
| 107 |
|
| 108 |
function user_notes_enqueue_thickbox($hook) { |
| 109 |
if($hook != 'users.php') |
| 110 |
return; |
| 111 |
|
| 112 |
wp_enqueue_style('thickbox'); |
| 113 |
wp_enqueue_script('thickbox'); |
| 114 |
} |
| 115 |
add_action('admin_enqueue_scripts', 'user_notes_enqueue_thickbox'); |
| 116 |
|