PluginProbe
User Notes / 1.0.2
User Notes v1.0.2
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
← All changes | user-notes.php +115 -90 trunk1.0.2 View file →
@@ -1,90 +1,115 @@
1 -<?php
2 -/*
3 -Plugin Name: User Notes
4 -Plugin URI: https://github.com/cartpauj/user-notes
5 -Description: Keep private, timestamped notes about each of your users that only Administrators can see.
6 -Version: 2.1.1
7 -Author: cartpauj
8 -Author URI: https://github.com/cartpauj
9 -Text Domain: user-notes
10 -License: GPLv2 or later
11 -License URI: https://www.gnu.org/licenses/gpl-2.0.html
12 -
13 -This program is free software; you can redistribute it and/or modify
14 -it under the terms of the GNU General Public License as published by
15 -the Free Software Foundation; either version 2 of the License, or
16 -(at your option) any later version.
17 -
18 -This program is distributed in the hope that it will be useful,
19 -but WITHOUT ANY WARRANTY; without even the implied warranty of
20 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 -GNU General Public License for more details.
22 -*/
23 -
24 -if (!defined('ABSPATH')) exit;
25 -
26 -define('USER_NOTES_PLUGIN_DIR', plugin_dir_path(__FILE__));
27 -define('USER_NOTES_PLUGIN_URL', plugin_dir_url(__FILE__));
28 -define('USER_NOTES_PLUGIN_FILE', __FILE__);
29 -
30 -function user_notes_version() {
31 - static $v = null;
32 - if ($v !== null) return $v;
33 - $data = get_file_data(USER_NOTES_PLUGIN_FILE, array('Version' => 'Version'));
34 - $v = !empty($data['Version']) ? $data['Version'] : '0.0.0';
35 - return $v;
36 -}
37 -
38 -require_once USER_NOTES_PLUGIN_DIR . 'includes/class-notes-repo.php';
39 -require_once USER_NOTES_PLUGIN_DIR . 'includes/caps.php';
40 -require_once USER_NOTES_PLUGIN_DIR . 'includes/render.php';
41 -require_once USER_NOTES_PLUGIN_DIR . 'includes/ajax.php';
42 -require_once USER_NOTES_PLUGIN_DIR . 'includes/migrate.php';
43 -
44 -register_activation_hook(__FILE__, 'user_notes_activate');
45 -
46 -function user_notes_activate() {
47 - User_Notes_Repo::install_table();
48 - user_notes_run_migration_if_needed();
49 -}
50 -
51 -add_action('plugins_loaded', function () {
52 - // Safety: run migration on upgrade too.
53 - if (get_option('user_notes_db_version') !== user_notes_version()) {
54 - User_Notes_Repo::install_table();
55 - user_notes_run_migration_if_needed();
56 - }
57 -});
58 -
59 -add_action('admin_enqueue_scripts', function ($hook) {
60 - if (!in_array($hook, array('profile.php', 'user-edit.php', 'users.php'), true)) return;
61 - if (!user_notes_current_user_can_view()) return;
62 -
63 - wp_enqueue_style('user-notes', USER_NOTES_PLUGIN_URL . 'assets/user-notes.css', array(), user_notes_version());
64 - wp_enqueue_script('user-notes', USER_NOTES_PLUGIN_URL . 'assets/user-notes.js', array('jquery'), user_notes_version(), true);
65 - wp_localize_script('user-notes', 'UserNotes', array(
66 - 'ajaxUrl' => admin_url('admin-ajax.php'),
67 - 'nonce' => wp_create_nonce('user_notes_ajax'),
68 - 'canDelete' => current_user_can('delete_users'),
69 - 'i18n' => array(
70 - 'confirmDelete' => __('Delete this note permanently? This cannot be undone.', 'user-notes'),
71 - 'saving' => __('Saving…', 'user-notes'),
72 - 'error' => __('Something went wrong. Please try again.', 'user-notes'),
73 - 'edited' => __('edited', 'user-notes'),
74 - 'by' => __('by', 'user-notes'),
75 - 'addNote' => __('Add Note', 'user-notes'),
76 - 'addPlaceholder' => __('Add a note…', 'user-notes'),
77 - 'starThis' => __('Star this note', 'user-notes'),
78 - 'noNotes' => __('No notes yet.', 'user-notes'),
79 - 'loading' => __('Loading…', 'user-notes'),
80 - /* translators: %s: user display name. */
81 - 'notesFor' => __('Notes for %s', 'user-notes'),
82 - 'close' => __('Close', 'user-notes'),
83 - 'edit' => __('Edit', 'user-notes'),
84 - 'del' => __('Delete', 'user-notes'),
85 - 'save' => __('Save', 'user-notes'),
86 - 'cancel' => __('Cancel', 'user-notes'),
87 - 'toggleStar' => __('Toggle star', 'user-notes'),
88 - ),
89 - ));
90 -});
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.2
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="' . admin_url('user-edit.php?user_id=' . $user_id . '#wp-user_notes_note-wrap') . '">' . __('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 $user_id; ?>" style="display:none;">
95 + <?php echo wpautop($notes); ?>
96 + <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>
97 + </div>
98 + <strong><a href="#TB_inline<?php echo $delim; ?>inlineId=user_notes_thickbox_<?php echo $user_id; ?>" class="thickbox" title="<?php echo $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');