PluginProbe
Stream – Activity Log & Audit Trail / 3.4.2
Stream – Activity Log & Audit Trail v3.4.2
4.4.0 4.3.0 4.2.2 4.2.1 trunk 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.1 3.1.1 3.10.0 3.2.0 3.2.1 3.2.2 3.2.3 All 50 releases
← All changes | classes/class-alert.php +17 -44 4.2.23.4.2 View file →
@@ -1,7 +1,7 @@
1 1 <?php
2 2 /**
3 - * Manages a single alert, acting as a model.
3 + * Single Alert handler.
4 4 *
5 5 * @package WP_Stream
6 6 */
7 7
@@ -56,9 +56,9 @@
56 56 */
57 57 public $alert_meta;
58 58
59 59 /**
60 - * Holds instance of plugin object
60 + * Hold Plugin class
61 61 *
62 62 * @var Plugin
63 63 */
64 64 public $plugin;
@@ -65,11 +65,10 @@
65 65
66 66 /**
67 67 * Class constructor
68 68 *
69 - * @param ?object $item Alert data.
70 - * @param Plugin $plugin Instance of plugin object.
71 - *
69 + * @param object $item Alert data.
70 + * @param Plugin $plugin Plugin class.
72 71 * @return void
73 72 */
74 73 public function __construct( $item, $plugin ) {
75 74 $this->plugin = $plugin;
@@ -83,11 +82,10 @@
83 82 $this->alert_meta = isset( $item->alert_meta ) ? $item->alert_meta : array();
84 83 }
85 84
86 85 /**
87 - * Saves alert state.
86 + * Save state of the Alert to database
88 87 *
89 - * @todo Clean up/Remove unnecessary conditional statements.
90 88 * @return int The Post ID of the alert.
91 89 */
92 90 public function save() {
93 91
@@ -100,20 +98,17 @@
100 98 'post_author' => $this->author,
101 99 'post_type' => Alerts::POST_TYPE,
102 100 );
103 101
104 - // Remove empty "ID" field, if new post.
105 102 if ( empty( $args['ID'] ) ) {
106 103 unset( $args['ID'] );
107 104 }
108 105
109 - // Create or update alert and assign the ID.
110 106 $post_id = wp_insert_post( $args );
111 107 if ( empty( $args['ID'] ) ) {
112 108 $this->ID = $post_id;
113 109 }
114 110
115 - // Save alert type and meta.
116 111 $meta = array(
117 112 'alert_type' => $this->alert_type,
118 113 'alert_meta' => $this->alert_meta,
119 114 );
@@ -125,30 +120,10 @@
125 120 return $post_id;
126 121 }
127 122
128 123 /**
129 - * Permanently delete the underlying alert post.
130 - *
131 - * @return bool True if the post was deleted, false otherwise.
132 - */
133 - public function delete() {
134 - if ( empty( $this->ID ) ) {
135 - return false;
136 - }
137 -
138 - $post = get_post( $this->ID );
139 - if ( ! ( $post instanceof \WP_Post ) || Alerts::POST_TYPE !== $post->post_type ) {
140 - return false;
141 - }
142 -
143 - return (bool) wp_delete_post( $this->ID, true );
144 - }
145 -
146 - /**
147 124 * Process settings form data
148 125 *
149 - * @todo Confirm if the function is necessary, it's currently unreference
150 - * anywhere else in the plugin.
151 126 * @param array $data Processed post object data.
152 127 * @return array New post object data.
153 128 */
154 129 public function process_settings_form( $data ) {
@@ -204,9 +179,9 @@
204 179
205 180 /**
206 181 * Determine the title of the alert.
207 182 *
208 - * @todo enhance human readability
183 + * @todo enhance human readibility
209 184 * @return string The title of the alert
210 185 */
211 186 public function get_title() {
212 187
@@ -225,9 +200,9 @@
225 200 return $title;
226 201 }
227 202
228 203 /**
229 - * Retrieve current alert type object
204 + * Retrive current alert type object
230 205 *
231 206 * @return Alert_Type
232 207 */
233 208 public function get_alert_type_obj() {
@@ -254,8 +229,9 @@
254 229 * Trigger alert for a specific record.
255 230 *
256 231 * @param int $record_id Record ID.
257 232 * @param int $recordarr Record Data.
233 + * @return void
258 234 */
259 235 public function send_alert( $record_id, $recordarr ) {
260 236 $this->get_alert_type_obj()->alert( $record_id, $recordarr, $this );
261 237 }
@@ -316,18 +292,18 @@
316 292 *
317 293 * Using that ID, it fetches that Alert post's meta, then
318 294 * returns the value of the requested setting (ie., "post meta" field).
319 295 *
320 - * @param object $record The Record object.
321 - * @param string $alert_slug The slug of the Alert Type.
322 - * @param string $setting The requested meta value of the Alert.
323 - * @param mixed $default_value The default value if no value is found.
296 + * @see Alert_Type_Highlight::post_class() for an example.
324 297 *
325 - * @see Alert_Type_Highlight::post_class() for an example.
298 + * @param object $record The Record object.
299 + * @param string $alert_slug The slug of the Alert Type.
300 + * @param string $setting The requested meta value of the Alert.
301 + * @param mixed $default The default value if no value is found.
326 302 *
327 303 * @return mixed
328 304 */
329 - public function get_single_alert_setting_from_record( $record, $alert_slug, $setting, $default_value = false ) {
305 + public function get_single_alert_setting_from_record( $record, $alert_slug, $setting, $default = false ) {
330 306 if ( ! is_object( $record ) || ! is_string( $alert_slug ) || ! is_string( $setting ) ) {
331 307 return false;
332 308 }
333 309 $record = new Record( $record );
@@ -342,13 +318,10 @@
342 318 if ( empty( $values ) ) {
343 319 return false;
344 320 }
345 321
346 - /**
347 - * Grab an Alert post ID.
348 - *
349 - * @todo Determine which Alert post takes priority.
350 - */
322 + // Grab an Alert post ID.
323 + // @todo determine which Alert post takes priority.
351 324 if ( is_array( $values ) ) {
352 325 $post_id = $values[0];
353 326 } else {
354 327 $post_id = $values;
@@ -359,8 +332,8 @@
359 332 }
360 333
361 334 $alert = $this->plugin->alerts->get_alert( $post_id );
362 335
363 - $value = ! empty( $alert->alert_meta[ $setting ] ) ? $alert->alert_meta[ $setting ] : $default_value;
336 + $value = ! empty( $alert->alert_meta[ $setting ] ) ? $alert->alert_meta[ $setting ] : $default;
364 337 return $value;
365 338 }
366 339 }