PluginProbe
User Notes / 2.0.0
User Notes v2.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 2.0.0, at user-notes.php

71 lines 2.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: 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.0.0
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_VERSION', '2.0.0');
27 define('USER_NOTES_DB_VERSION', '2.0');
28 define('USER_NOTES_PLUGIN_DIR', plugin_dir_path(__FILE__));
29 define('USER_NOTES_PLUGIN_URL', plugin_dir_url(__FILE__));
30
31 require_once USER_NOTES_PLUGIN_DIR . 'includes/class-notes-repo.php';
32 require_once USER_NOTES_PLUGIN_DIR . 'includes/caps.php';
33 require_once USER_NOTES_PLUGIN_DIR . 'includes/render.php';
34 require_once USER_NOTES_PLUGIN_DIR . 'includes/ajax.php';
35 require_once USER_NOTES_PLUGIN_DIR . 'includes/migrate.php';
36
37 register_activation_hook(__FILE__, 'user_notes_activate');
38
39 function user_notes_activate() {
40 User_Notes_Repo::install_table();
41 user_notes_run_migration_if_needed();
42 }
43
44 add_action('plugins_loaded', function () {
45 // Safety: run migration on upgrade too.
46 if (get_option('user_notes_db_version') !== USER_NOTES_DB_VERSION) {
47 User_Notes_Repo::install_table();
48 user_notes_run_migration_if_needed();
49 }
50 });
51
52 add_action('admin_enqueue_scripts', function ($hook) {
53 if (!in_array($hook, array('profile.php', 'user-edit.php', 'users.php'), true)) return;
54 if (!user_notes_current_user_can_view()) return;
55
56 wp_enqueue_style('user-notes', USER_NOTES_PLUGIN_URL . 'assets/user-notes.css', array(), USER_NOTES_VERSION);
57 wp_enqueue_script('user-notes', USER_NOTES_PLUGIN_URL . 'assets/user-notes.js', array('jquery'), USER_NOTES_VERSION, true);
58 wp_localize_script('user-notes', 'UserNotes', array(
59 'ajaxUrl' => admin_url('admin-ajax.php'),
60 'nonce' => wp_create_nonce('user_notes_ajax'),
61 'canDelete' => current_user_can('delete_users'),
62 'i18n' => array(
63 'confirmDelete' => __('Delete this note permanently? This cannot be undone.', 'user-notes'),
64 'saving' => __('Saving…', 'user-notes'),
65 'error' => __('Something went wrong. Please try again.', 'user-notes'),
66 'edited' => __('edited', 'user-notes'),
67 'by' => __('by', 'user-notes'),
68 ),
69 ));
70 });
71