PluginProbe
User Notes / 1.0.5
User Notes v1.0.5
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.5, at user-notes.php

121 lines 4.5 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: https://github.com/cartpauj/user-notes
5 Description: Keep private notes about each of your users that only Administrators can see.
6 Version: 1.0.5
7 Author: Cartpauj
8 Author URI: https//github.com/cartpauj
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_nonce_field('user_notes_save_' . $wp_user->ID, 'user_notes_nonce'); ?>
45 <?php wp_editor($notes, 'user_notes_note', array('teeny' => true)); ?>
46 </td>
47 </tr>
48 </tbody>
49 </table>
50 <?php
51 }
52 add_action('show_user_profile', 'user_notes_show_field');
53 add_action('edit_user_profile', 'user_notes_show_field');
54
55 function user_notes_save_note($user_id) {
56 //Only admins, and only if it's set (so we don't wipe out the notes when non-admins save the profile)
57 if(!current_user_can('list_users') || !isset($_POST['user_notes_note']))
58 return;
59
60 //Verify nonce for CSRF protection
61 if(!isset($_POST['user_notes_nonce']) || !wp_verify_nonce($_POST['user_notes_nonce'], 'user_notes_save_' . $user_id))
62 return;
63
64 $notes = (!empty($_POST['user_notes_note']))?wp_kses_post(stripslashes($_POST['user_notes_note'])):'';
65
66 update_user_meta($user_id, 'user-notes-note', $notes);
67 }
68 add_action('personal_options_update', 'user_notes_save_note');
69 add_action('edit_user_profile_update', 'user_notes_save_note');
70
71 function user_notes_add_users_column($cols) {
72 $cols = array_merge($cols, array('user_notes_note' => __('Notes', 'user-notes')));
73
74 return $cols;
75 }
76 add_filter('manage_users_columns', 'user_notes_add_users_column');
77
78 function user_notes_display_column($val, $col_name, $user_id) {
79 if($col_name == 'user_notes_note') {
80 $notes = get_user_meta($user_id, 'user-notes-note', true);
81
82 //If no notes -- return none
83 if(empty($notes))
84 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>';
85
86 $notes_excerpt = strip_tags(substr($notes, 0, 100)) . ' ...';
87 $notes_excerpt = trim(preg_replace('/\s+/', ' ', $notes_excerpt));
88
89 $user = new WP_User($user_id);
90 $title = __('Note for', 'user-notes') . ' ' . $user->user_login . "\n" . $notes_excerpt;
91
92 //Get the dilimiter
93 $uri = $_SERVER['REQUEST_URI'];
94 $delim = user_notes_get_delim($uri);
95
96 ob_start();
97
98 ?>
99 <div id="user_notes_thickbox_<?php echo esc_attr($user_id); ?>" style="display:none;">
100 <?php echo wp_kses_post(wpautop($notes)); ?>
101 <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', 'user-notes'); ?></a></p>
102 </div>
103 <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>
104 <?php
105
106 return ob_get_clean();
107 }
108
109 return $val;
110 }
111 add_action('manage_users_custom_column', 'user_notes_display_column', 10, 3);
112
113 function user_notes_enqueue_thickbox($hook) {
114 if($hook != 'users.php')
115 return;
116
117 wp_enqueue_style('thickbox');
118 wp_enqueue_script('thickbox');
119 }
120 add_action('admin_enqueue_scripts', 'user_notes_enqueue_thickbox');
121