PluginProbe
User Notes / 1.0.0
User Notes v1.0.0
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 / user-notes.php

user-notes.php in User Notes 1.0.0, at user-notes.php

113 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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.0
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']))?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="' . admin_url('user-edit.php?user_id=' . $user_id . '#wp-user_notes_note-wrap') . '">' . __('Add', 'user-notes') . '</a>';
80
81 $user = new WP_User($user_id);
82 $title = __('Note for', 'user-notes') . ': ' . $user->user_login;
83
84 //Get the dilimiter
85 $uri = $_SERVER['REQUEST_URI'];
86 $delim = user_notes_get_delim($uri);
87
88 ob_start();
89
90 ?>
91 <div id="user_notes_thickbox_<?php echo $user_id; ?>" style="display:none;">
92 <?php echo wpautop($notes); ?>
93 <p><a href="<?php echo admin_url('user-edit.php?user_id=' . $user_id . '#wp-user_notes_note-wrap'); ?>"><?php _e('Edit Note'); ?></a></p>
94 </div>
95 <strong><a href="#TB_inline<?php echo $delim; ?>inlineId=user_notes_thickbox_<?php echo $user_id; ?>" class="thickbox" title="<?php echo $title; ?>"><?php _e('View', 'user-notes'); ?></a></strong>
96 <?php
97
98 return ob_get_clean();
99 }
100
101 return $val;
102 }
103 add_action('manage_users_custom_column', 'user_notes_display_column', 10, 3);
104
105 function user_notes_enqueue_thickbox($hook) {
106 if($hook != 'users.php')
107 return;
108
109 wp_enqueue_style('thickbox');
110 wp_enqueue_script('thickbox');
111 }
112 add_action('admin_enqueue_scripts', 'user_notes_enqueue_thickbox');
113