| 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.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 |
), |
| 76 |
)); |
| 77 |
}); |
| 78 |
|