PluginProbe
Stream – Activity Log & Audit Trail / 3.9.0
Stream – Activity Log & Audit Trail v3.9.0
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 | alerts/class-alert-type-highlight.php +88 -28 3.2.13.9.0 View file →
@@ -12,8 +12,9 @@
12 12 *
13 13 * @package WP_Stream
14 14 */
15 15 class Alert_Type_Highlight extends Alert_Type {
16 +
16 17 /**
17 18 * Main JS file script handle.
18 19 */
19 20 const SCRIPT_HANDLE = 'wp-stream-alert-highlight-js';
@@ -67,19 +68,55 @@
67 68 $this->plugin = $plugin;
68 69 if ( ! is_admin() ) {
69 70 return;
70 71 }
71 - add_filter( 'wp_stream_record_classes', array( $this, 'post_class' ), 10, 2 );
72 - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
73 - add_action( 'wp_ajax_' . self::REMOVE_ACTION, array( $this, 'ajax_remove_highlight' ) );
72 + add_filter(
73 + 'wp_stream_record_classes',
74 + array(
75 + $this,
76 + 'post_class',
77 + ),
78 + 10,
79 + 2
80 + );
81 + add_action(
82 + 'admin_enqueue_scripts',
83 + array(
84 + $this,
85 + 'enqueue_scripts',
86 + )
87 + );
88 + add_action(
89 + 'wp_ajax_' . self::REMOVE_ACTION,
90 + array(
91 + $this,
92 + 'ajax_remove_highlight',
93 + )
94 + );
74 95
75 96 if ( ! empty( $this->plugin->connectors->connectors ) && is_array( $this->plugin->connectors->connectors ) ) {
76 - foreach ( $this->plugin->connectors->connectors as $connector ) {
77 - add_filter( 'wp_stream_action_links_' . $connector->name, array( $this, 'action_link_remove_highlight' ), 10, 2 );
97 + foreach ( $this->plugin->connectors->connectors as $connector ) {
98 + add_filter(
99 + 'wp_stream_action_links_' . $connector->name,
100 + array(
101 + $this,
102 + 'action_link_remove_highlight',
103 + ),
104 + 10,
105 + 2
106 + );
78 107 }
79 108 }
80 109
81 - add_filter( 'wp_stream_alerts_save_meta', array( $this, 'add_alert_meta' ), 10, 2 );
110 + add_filter(
111 + 'wp_stream_alerts_save_meta',
112 + array(
113 + $this,
114 + 'add_alert_meta',
115 + ),
116 + 10,
117 + 2
118 + );
82 119 }
83 120
84 121 /**
85 122 * Record that the Alert was triggered by a Record.
@@ -92,12 +129,15 @@
92 129 * @param object $alert Alert options.
93 130 * @return void
94 131 */
95 132 public function alert( $record_id, $recordarr, $alert ) {
96 - $recordarr['ID'] = $record_id;
133 + $recordarr['ID'] = $record_id;
97 134 $this->single_alert_id = $alert->ID;
98 135 if ( ! empty( $alert->alert_meta['color'] ) ) {
99 - Alert::update_record_triggered_alerts( (object) $recordarr, $this->slug, array( 'highlight_color' => $alert->alert_meta['color'] ) );
136 + $alert_meta = array(
137 + 'highlight_color' => $alert->alert_meta['color'],
138 + );
139 + Alert::update_record_triggered_alerts( (object) $recordarr, $this->slug, $alert_meta );
100 140 }
101 141 }
102 142
103 143 /**
@@ -110,24 +150,31 @@
110 150 $alert_meta = array();
111 151 if ( is_object( $alert ) ) {
112 152 $alert_meta = $alert->alert_meta;
113 153 }
114 - $options = wp_parse_args( $alert_meta, array(
115 - 'color' => 'yellow',
116 - ) );
154 + $options = wp_parse_args(
155 + $alert_meta,
156 + array(
157 + 'color' => 'yellow',
158 + )
159 + );
117 160
118 - $form = new Form_Generator;
161 + $form = new Form_Generator();
119 162 echo '<span class="wp_stream_alert_type_description">' . esc_html__( 'Highlight this alert on the Stream records page.', 'stream' ) . '</span>';
120 163 echo '<label for="wp_stream_highlight_color"><span class="title">' . esc_html__( 'Color', 'stream' ) . '</span>';
121 164 echo '<span class="input-text-wrap">';
122 - echo $form->render_field( 'select', array( // Xss ok.
123 - 'name' => 'wp_stream_highlight_color',
124 - 'title' => esc_attr( __( 'Highlight Color', 'stream' ) ),
125 - 'options' => $this->get_highlight_options(),
126 - 'value' => $options['color'],
127 - ) );
165 + echo $form->render_field(
166 + 'select',
167 + array(
168 + 'name' => 'wp_stream_highlight_color',
169 + 'title' => esc_attr( __( 'Highlight Color', 'stream' ) ),
170 + 'options' => $this->get_highlight_options(),
171 + 'value' => $options['color'],
172 + )
173 + ); // Xss ok.
128 174 echo '</span></label>';
129 175 }
176 +
130 177 /**
131 178 * Lists available color options for alerts.
132 179 *
133 180 * @return array List of highlight color options.
@@ -153,9 +200,9 @@
153 200 if ( empty( $_POST['wp_stream_highlight_color'] ) ) {
154 201 $alert->alert_meta['color'] = 'yellow';
155 202 }
156 203 $input_color = sanitize_text_field( wp_unslash( $_POST['wp_stream_highlight_color'] ) );
157 - if ( ! array_key_exists( $input_color , $this->get_highlight_options() ) ) {
204 + if ( ! array_key_exists( $input_color, $this->get_highlight_options() ) ) {
158 205 $alert->alert_meta['color'] = 'yellow';
159 206 } else {
160 207 $alert->alert_meta['color'] = $input_color;
161 208 }
@@ -169,10 +216,12 @@
169 216 * @param object $record Record data.
170 217 * @return array New list of classes.
171 218 */
172 219 public function post_class( $classes, $record ) {
173 - if ( ! empty( $record->meta['wp_stream_alerts_triggered']['highlight']['highlight_color'] ) ) {
174 - $color = $record->meta['wp_stream_alerts_triggered']['highlight']['highlight_color'];
220 + $record = new Record( $record );
221 + $alerts_triggered = $record->get_meta( Alerts::ALERTS_TRIGGERED_META_KEY, true );
222 + if ( ! empty( $alerts_triggered[ $this->slug ]['highlight_color'] ) ) {
223 + $color = $alerts_triggered[ $this->slug ]['highlight_color'];
175 224 }
176 225
177 226 if ( empty( $color ) || ! is_string( $color ) ) {
178 227 return $classes;
@@ -198,9 +247,9 @@
198 247 *
199 248 * @return mixed
200 249 */
201 250 public function action_link_remove_highlight( $actions, $record ) {
202 - $record = new Record( $record );
251 + $record = new Record( $record );
203 252 $alerts_triggered = $record->get_meta( Alerts::ALERTS_TRIGGERED_META_KEY, true );
204 253 if ( ! empty( $alerts_triggered[ $this->slug ] ) ) {
205 254 $actions[ __( 'Remove Highlight', 'stream' ) ] = '#';
206 255 }
@@ -241,11 +290,11 @@
241 290
242 291 if ( ! is_numeric( $record_id ) ) {
243 292 wp_send_json_error( $failure_message );
244 293 }
245 - $record_obj = new \stdClass();
246 - $record_obj->ID = $record_id;
247 - $record = new Record( $record_obj );
294 + $record_obj = new \stdClass();
295 + $record_obj->ID = $record_id;
296 + $record = new Record( $record_obj );
248 297 $alerts_triggered = $record->get_meta( Alerts::ALERTS_TRIGGERED_META_KEY, true );
249 298 if ( isset( $alerts_triggered[ $this->slug ] ) ) {
250 299 unset( $alerts_triggered[ $this->slug ] );
251 300 }
@@ -259,14 +308,24 @@
259 308 * @param string $page WP admin page.
260 309 */
261 310 public function enqueue_scripts( $page ) {
262 311 if ( 'toplevel_page_wp_stream' === $page ) {
263 - wp_register_script( self::SCRIPT_HANDLE, $this->plugin->locations['url'] . 'alerts/js/alert-type-highlight.js', array( 'jquery' ) );
312 + $min = wp_stream_min_suffix();
264 313
314 + wp_register_script(
315 + self::SCRIPT_HANDLE,
316 + $this->plugin->locations['url'] . 'alerts/js/alert-type-highlight.' . $min . 'js',
317 + array(
318 + 'jquery',
319 + ),
320 + $this->plugin->get_version(),
321 + false
322 + );
323 +
265 324 $exports = array(
266 - 'ajaxUrl' => admin_url( 'admin-ajax.php' ),
325 + 'ajaxUrl' => admin_url( 'admin-ajax.php' ),
267 326 'removeAction' => self::REMOVE_ACTION,
268 - 'security' => wp_create_nonce( self::REMOVE_ACTION_NONCE ),
327 + 'security' => wp_create_nonce( self::REMOVE_ACTION_NONCE ),
269 328 );
270 329
271 330 wp_scripts()->add_data(
272 331 self::SCRIPT_HANDLE,
@@ -295,7 +354,8 @@
295 354 } else {
296 355 $alert_meta['color'] = $color;
297 356 }
298 357 }
358 +
299 359 return $alert_meta;
300 360 }
301 361 }