| 1 |
<?php |
| 2 |
// @codingStandardsIgnoreFile |
| 3 |
/** |
| 4 |
* Administrative notes. |
| 5 |
* |
| 6 |
* Copyright: © 2009-2011 |
| 7 |
* {@link http://websharks-inc.com/ WebSharks, Inc.} |
| 8 |
* (coded in the USA) |
| 9 |
* |
| 10 |
* Released under the terms of the GNU General Public License. |
| 11 |
* You should have received a copy of the GNU General Public License, |
| 12 |
* along with this software. In the main directory, see: /licensing/ |
| 13 |
* If not, see: {@link http://www.gnu.org/licenses/}. |
| 14 |
* |
| 15 |
* @package s2Member\Admin_Notes |
| 16 |
* @since 3.5 |
| 17 |
*/ |
| 18 |
if(!defined('WPINC')) // MUST have WordPress. |
| 19 |
exit ("Do not access this file directly."); |
| 20 |
|
| 21 |
if (!class_exists ("c_ws_plugin__s2member_user_notes")) |
| 22 |
{ |
| 23 |
/** |
| 24 |
* Administrative notes. |
| 25 |
* |
| 26 |
* @package s2Member\Admin_Notes |
| 27 |
* @since 3.5 |
| 28 |
*/ |
| 29 |
class c_ws_plugin__s2member_user_notes |
| 30 |
{ |
| 31 |
/** |
| 32 |
* Appends a note onto a specific User/Member's account. |
| 33 |
* |
| 34 |
* @package s2Member\Admin_Notes |
| 35 |
* @since 3.5 |
| 36 |
* |
| 37 |
* @param int|string $user_id A numeric WordPress User ID. |
| 38 |
* @param string $notes The string of notes to append. One note, or many. |
| 39 |
* @return string The full set of notes, including appendage. |
| 40 |
*/ |
| 41 |
public static function append_user_notes ($user_id = FALSE, $notes = FALSE) |
| 42 |
{ |
| 43 |
foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v; |
| 44 |
do_action("ws_plugin__s2member_before_append_user_notes", get_defined_vars ()); |
| 45 |
unset($__refs, $__v); |
| 46 |
|
| 47 |
if ($user_id && $notes && is_string ($notes)) // Must have these. |
| 48 |
{ |
| 49 |
foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v; |
| 50 |
do_action("ws_plugin__s2member_during_append_user_notes", get_defined_vars ()); |
| 51 |
unset($__refs, $__v); |
| 52 |
|
| 53 |
$notes = trim (get_user_option ("s2member_notes", $user_id) . "\n" . $notes); |
| 54 |
|
| 55 |
update_user_option ($user_id, "s2member_notes", $notes); |
| 56 |
} |
| 57 |
|
| 58 |
return apply_filters("ws_plugin__s2member_append_user_notes", ((!empty($notes)) ? $notes : ""), get_defined_vars ()); |
| 59 |
} |
| 60 |
/** |
| 61 |
* Clear specific notes from a User/Member's account; based on line-by-line regex. |
| 62 |
* |
| 63 |
* @package s2Member\Admin_Notes |
| 64 |
* @since 3.5 |
| 65 |
* |
| 66 |
* @param int|string $user_id A numeric WordPress User ID. |
| 67 |
* @param string $regex A regular expression to match against each line. |
| 68 |
* @return string The full set of notes, after clearing. |
| 69 |
*/ |
| 70 |
public static function clear_user_note_lines ($user_id = FALSE, $regex = FALSE) |
| 71 |
{ |
| 72 |
foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v; |
| 73 |
do_action("ws_plugin__s2member_before_clear_user_note_lines", get_defined_vars ()); |
| 74 |
unset($__refs, $__v); |
| 75 |
|
| 76 |
if ($user_id && $regex && is_string ($regex) && ($lines = array())) |
| 77 |
{ |
| 78 |
// Careful here to preserve empty lines. |
| 79 |
$notes = trim (get_user_option ("s2member_notes", $user_id)); |
| 80 |
foreach (preg_split ("/\n/", $notes) as $line) |
| 81 |
if (!preg_match ($regex, $line)) |
| 82 |
$lines[] = $line; |
| 83 |
|
| 84 |
$notes = trim (implode ("\n", $lines)); |
| 85 |
|
| 86 |
foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v; |
| 87 |
do_action("ws_plugin__s2member_during_clear_user_note_lines", get_defined_vars ()); |
| 88 |
unset($__refs, $__v); |
| 89 |
|
| 90 |
update_user_option ($user_id, "s2member_notes", $notes); |
| 91 |
} |
| 92 |
|
| 93 |
return apply_filters("ws_plugin__s2member_clear_user_note_lines", ((!empty($notes)) ? $notes : ""), get_defined_vars ()); |
| 94 |
} |
| 95 |
} |
| 96 |
} |
| 97 |
|