PluginProbe
LoginPress | wp-login Custom Login Page Customizer / 3.0.2
LoginPress | wp-login Custom Login Page Customizer v3.0.2
6.2.5 6.2.4 6.2.3 6.2.2 6.2.1 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 1.0.22 1.0.23 1.0.3 1.0.4 All 118 releases
loginpress / include / class-remote-notification-client.php

class-remote-notification-client.php in LoginPress | wp-login Custom Login Page Customizer 3.0.2, at include/class-remote-notification-client.php

866 lines 22.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Remote Dashboard Notifications.
4 *
5 * This class is part of the Remote Dashboard Notifications plugin.
6 * This plugin allows you to send notifications to your client's
7 * WordPress dashboard easily.
8 *
9 * Notification you send will be displayed as admin notifications
10 * using the standard WordPress hooks. A "dismiss" option is added
11 * in order to let the user hide the notification.
12 *
13 * @package Remote Dashboard Notifications
14 * @author ThemeAvenue <web@themeavenue.net>
15 * @license GPL-2.0+
16 * @link http://themeavenue.net
17 * @link http://wordpress.org/plugins/remote-dashboard-notifications/
18 * @link https://github.com/ThemeAvenue/Remote-Dashboard-Notifications
19 * @copyright 2016 ThemeAvenue
20 */
21
22 // If this file is called directly, abort.
23 if ( ! defined( 'WPINC' ) ) {
24 die;
25 }
26
27 if ( ! class_exists( 'Remote_Dashboard_Notifications_Client' ) ) {
28
29 final class Remote_Dashboard_Notifications_Client {
30
31 /**
32 * @var Remote_Dashboard_Notifications_Client Holds the unique instance
33 * @since 1.3.0
34 */
35 private static $instance;
36
37 /**
38 * Minimum version of WordPress required ot run the plugin
39 *
40 * @since 1.3.0
41 * @var string
42 */
43 public $wordpress_version_required = '3.8';
44
45 /**
46 * Required version of PHP.
47 *
48 * Follow WordPress latest requirements and require
49 * PHP version 5.2 at least.
50 *
51 * @since 1.3.0
52 * @var string
53 */
54 public $php_version_required = '5.2';
55
56 /**
57 * Holds all the registered notifications
58 *
59 * @since 1.3.0
60 * @var array
61 */
62 public $notifications = array();
63
64 /**
65 * Instantiate and return the unique object
66 *
67 * @since 1.2.0
68 * @return object Remote_Dashboard_Notifications_Client Unique instance
69 */
70 public static function instance() {
71
72 if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Awesome_Support ) ) {
73 self::$instance = new Remote_Dashboard_Notifications_Client;
74 self::$instance->init();
75 }
76
77 return self::$instance;
78
79 }
80
81 /**
82 * Instantiate the plugin
83 *
84 * @since 1.3.0
85 * @return void
86 */
87 private function init() {
88
89 // Make sure the WordPress version is recent enough
90 if ( ! self::$instance->is_version_compatible() ) {
91 return;
92 }
93
94 // Make sure we have a version of PHP that's not too old
95 if ( ! self::$instance->is_php_version_enough() ) {
96 return;
97 }
98
99 // Call the dismiss method before testing for Ajax
100 if ( isset( $_GET['rn'] ) && isset( $_GET['notification'] ) ) {
101 add_action( 'plugins_loaded', array( self::$instance, 'dismiss' ) );
102 }
103
104 if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) {
105 add_action( 'admin_print_styles', array( self::$instance, 'style' ), 100 );
106 add_action( 'admin_notices', array( self::$instance, 'show_notices' ) );
107 add_action( 'admin_footer', array( self::$instance, 'script' ) );
108 }
109
110 add_action( 'wp_ajax_rdn_fetch_notifications', array( $this, 'remote_get_notice_ajax' ) );
111 add_filter( 'heartbeat_received', array( self::$instance, 'heartbeat' ), 10, 2 );
112
113 }
114
115 /**
116 * Throw error on object clone
117 *
118 * The whole idea of the singleton design pattern is that there is a single
119 * object therefore, we don't want the object to be cloned.
120 *
121 * @since 3.2.5
122 * @return void
123 */
124 public function __clone() {
125 // Cloning instances of the class is forbidden
126 _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'awesome-support' ), '3.2.5' );
127 }
128
129 /**
130 * Disable unserializing of the class
131 *
132 * @since 3.2.5
133 * @return void
134 */
135 public function __wakeup() {
136 // Unserializing instances of the class is forbidden
137 _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'awesome-support' ), '3.2.5' );
138 }
139
140 /**
141 * Check if the core version is compatible with this addon.
142 *
143 * @since 1.3.0
144 * @return boolean
145 */
146 private function is_version_compatible() {
147
148 if ( empty( self::$instance->wordpress_version_required ) ) {
149 return true;
150 }
151
152 if ( version_compare( get_bloginfo( 'version' ), self::$instance->wordpress_version_required, '<' ) ) {
153 return false;
154 }
155
156 return true;
157
158 }
159
160 /**
161 * Check if the version of PHP is compatible with this addon.
162 *
163 * @since 1.3.0
164 * @return boolean
165 */
166 private function is_php_version_enough() {
167
168 /**
169 * No version set, we assume everything is fine.
170 */
171 if ( empty( self::$instance->php_version_required ) ) {
172 return true;
173 }
174
175 if ( version_compare( phpversion(), self::$instance->php_version_required, '<' ) ) {
176 return false;
177 }
178
179 return true;
180
181 }
182
183 /**
184 * Register a new remote notification
185 *
186 * @since 1.3.0
187 *
188 * @param int $channel_id Channel ID on the remote server
189 * @param string $channel_key Channel key for authentication with the server
190 * @param string $server Notification server URL
191 * @param int $cache Cache lifetime (in hours)
192 *
193 * @return bool|string
194 */
195 public function add_notification( $channel_id, $channel_key, $server, $cache = 6 ) {
196
197 $notification = array(
198 'channel_id' => (int) $channel_id,
199 'channel_key' => $channel_key,
200 'server_url' => esc_url( $server ),
201 'cache_lifetime' => apply_filters( 'rn_notice_caching_time', $cache ),
202 );
203
204 // Generate the notice unique ID
205 $notification['notice_id'] = $notification['channel_id'] . substr( $channel_key, 0, 5 );
206
207 // Double check that the required info is here
208 if ( '' === ( $notification['channel_id'] || $notification['channel_key'] || $notification['server_url'] ) ) {
209 return false;
210 }
211
212 // Check that there is no notification with the same ID
213 if ( array_key_exists( $notification['notice_id'], $this->notifications ) ) {
214 return false;
215 }
216
217 $this->notifications[ $notification['notice_id'] ] = $notification;
218
219 return $notification['notice_id'];
220
221 }
222
223 /**
224 * Remove a registered notification
225 *
226 * @since 1.3.0
227 *
228 * @param string $notice_id ID of the notice to remove
229 *
230 * @return void
231 */
232 public function remove_notification( $notice_id ) {
233 if ( array_key_exists( $notice_id, $this->notifications ) ) {
234 unset( $this->notifications[ $notice_id ] );
235 }
236 }
237
238 /**
239 * Get all registered notifications
240 *
241 * @since 1.3.0
242 * @return array
243 */
244 public function get_notifications() {
245 return $this->notifications;
246 }
247
248 /**
249 * Get a specific notification
250 *
251 * @since 1.3.0
252 *
253 * @param string $notice_id ID of the notice to retrieve
254 *
255 * @return bool|array
256 */
257 public function get_notification( $notice_id ) {
258
259 if ( ! array_key_exists( $notice_id, $this->notifications ) ) {
260 return false;
261 }
262
263 return $this->notifications[ $notice_id ];
264 }
265
266 /**
267 * Adds inline style for non standard notices
268 *
269 * This function will only be called if the notice style is not standard.
270 *
271 * @since 0.1.0
272 */
273 public function style() { ?>
274 <style type="text/css">div.rn-alert{padding:15px 35px 15px 15px;margin-bottom:20px;border:1px solid transparent;-webkit-box-shadow:none;box-shadow:none}div.rn-alert p:empty{display:none}div.rn-alert ol,div.rn-alert ol li,div.rn-alert ul,div.rn-alert ul li{list-style:inherit!important}div.rn-alert ol,div.rn-alert ul{padding-left:30px}div.rn-alert hr{-moz-box-sizing:content-box;box-sizing:content-box;height:0;margin-top:20px;margin-bottom:20px;border:0;border-top:1px solid #eee}div.rn-alert h1,div.rn-alert h2,div.rn-alert h3,div.rn-alert h4,div.rn-alert h5,div.rn-alert h6{margin-top:0;color:inherit}div.rn-alert a{font-weight:700}div.rn-alert a:hover{text-decoration:underline}div.rn-alert>p{margin:0;padding:0;line-height:1}div.rn-alert>p,div.rn-alert>ul{margin-bottom:0}div.rn-alert>p+p{margin-top:5px}div.rn-alert .rn-dismiss-btn{font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;position:relative;top:-2px;right:-21px;padding:0;cursor:pointer;background:0;border:0;-webkit-appearance:none;float:right;font-size:21px;font-weight:700;line-height:1;color:#000;text-shadow:0 1px 0 #fff;opacity:.2;filter:alpha(opacity=20);text-decoration:none}div.rn-alert-success{background-color:#dff0d8;border-color:#d6e9c6;color:#3c763d}div.rn-alert-success hr{border-top-color:#c9e2b3}div.rn-alert-success a{color:#2b542c}div.rn-alert-info{background-color:#d9edf7;border-color:#bce8f1;color:#31708f}div.rn-alert-info hr{border-top-color:#a6e1ec}div.rn-alert-info a{color:#245269}div.rn-alert-warning{background-color:#fcf8e3;border-color:#faebcc;color:#8a6d3b}div.rn-alert-warning hr{border-top-color:#f7e1b5}div.rn-alert-warning a{color:#66512c}div.rn-alert-danger{background-color:#f2dede;border-color:#ebccd1;color:#a94442}div.rn-alert-danger hr{border-top-color:#e4b9c0}div.rn-alert-danger a{color:#843534}</style>
275 <?php
276 }
277
278 /**
279 * Display all the registered and available notifications
280 *
281 * @since 1.3.0
282 * @return void
283 */
284 public function show_notices() {
285
286 foreach ( $this->notifications as $id => $notification ) {
287
288 $rn = $this->get_remote_notification( $notification );
289
290 if ( empty( $rn ) || is_wp_error( $rn ) ) {
291 continue;
292 }
293
294 if ( $this->is_notification_error( $rn ) ) {
295 continue;
296 }
297
298 if ( $this->is_notice_dismissed( $rn->slug ) ) {
299 continue;
300 }
301
302 if ( $this->is_post_type_restricted( $rn ) ) {
303 continue;
304 }
305
306 if ( ! $this->is_notification_started( $rn ) ) {
307 continue;
308 }
309
310 if ( $this->has_notification_ended( $rn ) ) {
311 continue;
312 }
313
314 // Output the admin notice
315 $this->create_admin_notice( $rn->message, $this->get_notice_class( isset( $rn->style ) ? $rn->style : 'updated' ), $this->get_notice_dismissal_url( $rn->slug ) );
316
317 }
318
319 }
320
321 /**
322 * Check if the notification has been dismissed
323 *
324 * @since 1.2.0
325 *
326 * @param string $slug Slug of the notice to check
327 *
328 * @return bool
329 */
330 protected function is_notice_dismissed( $slug ) {
331
332 global $current_user;
333
334 $dismissed = array_filter( (array) get_user_meta( $current_user->ID, '_rn_dismissed', true ) );
335
336 if ( is_array( $dismissed ) && in_array( $slug, $dismissed ) ) {
337 return true;
338 }
339
340 return false;
341
342 }
343
344 /**
345 * Check if the notification can be displayed for the current post type
346 *
347 * @since 1.2.0
348 *
349 * @param stdClass $notification The notification object
350 *
351 * @return bool
352 */
353 protected function is_post_type_restricted( $notification ) {
354
355 /* If the type array isn't empty we have a limitation */
356 if ( isset( $notification->type ) && is_array( $notification->type ) && ! empty( $notification->type ) ) {
357
358 /* Get current post type */
359 $pt = get_post_type();
360
361 /**
362 * If the current post type can't be retrieved
363 * or if it's not in the allowed post types,
364 * then we don't display the admin notice.
365 */
366 if ( false === $pt || ! in_array( $pt, $notification->type ) ) {
367 return true;
368 }
369
370 }
371
372 return false;
373
374 }
375
376 /**
377 * Check if the notification has started yet
378 *
379 * @since 1.2.0
380 *
381 * @param stdClass $notification The notification object
382 *
383 * @return bool
384 */
385 protected function is_notification_started( $notification ) {
386
387 if ( ! isset( $notification->date_start ) ) {
388 return true;
389 }
390
391 if ( empty( $notification->date_start ) || strtotime( $notification->date_start ) < time() ) {
392 return true;
393 }
394
395 return false;
396
397 }
398
399 /**
400 * Check if the notification has expired
401 *
402 * @since 1.2.0
403 *
404 * @param stdClass $notification The notification object
405 *
406 * @return bool
407 */
408 protected function has_notification_ended( $notification ) {
409
410 if ( ! isset( $notification->date_end ) ) {
411 return false;
412 }
413
414 if ( empty( $notification->date_end ) || strtotime( $notification->date_end ) > time() ) {
415 return false;
416 }
417
418 return true;
419
420 }
421
422 /**
423 * Get the remote notification object
424 *
425 * @since 1.3.0
426 *
427 * @param array $notification The notification data array
428 *
429 * @return object|false
430 */
431 protected function get_remote_notification( $notification ) {
432
433 $content = get_transient( 'rn_last_notification_' . $notification['notice_id'] );
434
435 if ( false === $content ) {
436 add_option( 'rdn_fetch_' . $notification['notice_id'], 'fetch' );
437 }
438
439 return $content;
440
441 }
442
443 /**
444 * Get the admin notice class attribute
445 *
446 * @since 1.3.0
447 *
448 * @param string $style Notification style
449 *
450 * @return string
451 */
452 protected function get_notice_class( $style ) {
453
454 switch ( $style ) {
455 case 'updated':
456 $class = $style;
457 break;
458
459 case 'error':
460 $class = 'updated error';
461 break;
462
463 default:
464 $class = "updated rn-alert rn-alert-$style";
465 }
466
467 return $class;
468
469 }
470
471 /**
472 * Prepare the dismissal URL for the notice
473 *
474 * @since 1.3.0
475 *
476 * @param string $slug Notice slug
477 *
478 * @return string
479 */
480 protected function get_notice_dismissal_url( $slug ) {
481
482 $args = $_GET;
483 $args['rn'] = wp_create_nonce( 'rn-dismiss' );
484 $args['notification'] = trim( $slug );
485
486 return esc_url( add_query_arg( $args, '' ) );
487
488 }
489
490 /**
491 * Create the actual admin notice
492 *
493 * @since 1.3.0
494 *
495 * @param string $contents Notice contents
496 * @param string $class Wrapper class
497 * @param string $dismiss Dismissal link
498 *
499 * @return void
500 */
501 protected function create_admin_notice( $contents, $class, $dismiss ) { ?>
502 <div class="<?php echo $class; ?>">
503 <a href="<?php echo $dismiss; ?>" id="rn-dismiss" class="rn-dismiss-btn" title="<?php _e( 'Dismiss notification', 'remote-notifications' ); ?>">&times;</a>
504 <p><?php echo html_entity_decode( $contents ); ?></p>
505 </div>
506 <?php }
507
508 /**
509 * Dismiss notice
510 *
511 * When the user dismisses a notice, its slug
512 * is added to the _rn_dismissed entry in the DB options table.
513 * This entry is then used to check if a notice has been dismissed
514 * before displaying it on the dashboard.
515 *
516 * @since 0.1.0
517 */
518 public function dismiss() {
519
520 global $current_user;
521
522 /* Check if we have all the vars */
523 if ( ! isset( $_GET['rn'] ) || ! isset( $_GET['notification'] ) ) {
524 return;
525 }
526
527 /* Validate nonce */
528 if ( ! wp_verify_nonce( sanitize_key( $_GET['rn'] ), 'rn-dismiss' ) ) {
529 return;
530 }
531
532 /* Get dismissed list */
533 $dismissed = array_filter( (array) get_user_meta( $current_user->ID, '_rn_dismissed', true ) );
534
535 /* Add the current notice to the list if needed */
536 if ( is_array( $dismissed ) && ! in_array( $_GET['notification'], $dismissed ) ) {
537 array_push( $dismissed, $_GET['notification'] );
538 }
539
540 /* Update option */
541 update_user_meta( $current_user->ID, '_rn_dismissed', $dismissed );
542
543 }
544
545 /**
546 * Adds the script that hooks into the Heartbeat API
547 *
548 * @since 1.3.0
549 * @return void
550 */
551 public function script() {
552
553 $maybe_fetch = array();
554
555 foreach ( $this->get_notifications() as $id => $n ) {
556 $maybe_fetch[] = (string) $id;
557 }
558
559 // var_dump( 'RND_FETCH_NOTIFICATIONS' );
560 // var_dump( get_transient( 'loginpress_rdn_fetch_notifications' ) );
561
562 if ( false === get_transient( 'loginpress_rdn_fetch_notifications' ) ) { ?>
563
564 <script type="text/javascript">
565 jQuery(document).ready(function ($) {
566
567 // Hook into the heartbeat-send
568 $(document).on('heartbeat-send', function (e, data) {
569 data['rdn_maybe_fetch'] = <?php echo json_encode( $maybe_fetch ); ?>;
570 });
571
572 // Listen for the custom event "heartbeat-tick" on $(document).
573 $(document).on('heartbeat-tick', function (e, data) {
574
575 if (data.rdn_fetch !== '') {
576
577 ajax_data = {
578 'action': 'rdn_fetch_notifications',
579 'notices': data.rdn_fetch
580 };
581
582 $.post(ajaxurl, ajax_data);
583
584 }
585
586 });
587 });
588 </script>
589 <?php
590 }
591 }
592
593 /**
594 * Hook into the Heartbeat API.
595 *
596 * @since 1.3.0
597 *
598 * @param array $response Heartbeat tick response
599 * @param array $data Heartbeat tick data
600 *
601 * @return array Updated Heartbeat tick response
602 */
603 function heartbeat( $response, $data ) {
604
605 if ( isset( $data['rdn_maybe_fetch'] ) ) {
606
607 $notices = $data['rdn_maybe_fetch'];
608
609 if ( ! is_array( $notices ) ) {
610 $notices = array( $notices );
611 }
612
613 foreach ( $notices as $notice_id ) {
614
615 $fetch = get_option( "rdn_fetch_$notice_id", false );
616
617 if ( 'fetch' === $fetch ) {
618
619 if ( ! isset( $response['rdn_fetch'] ) ) {
620 $response['rdn_fetch'] = array();
621 }
622
623 $response['rdn_fetch'][] = $notice_id;
624
625 }
626
627 }
628
629 }
630
631 return $response;
632
633 }
634
635 /**
636 * Triggers the remote requests that fetches notices for this particular instance
637 *
638 * @since 1.3.0
639 * @return void
640 */
641 public function remote_get_notice_ajax() {
642 // Transient set for 1 week.
643 set_transient( 'loginpress_rdn_fetch_notifications', 'rdn_fetch_notifications', 604800 );
644
645 if ( isset( $_POST['notices'] ) ) {
646 $notices = $_POST['notices'];
647 } else {
648 echo 'No notice ID';
649 die();
650 }
651
652 if ( ! is_array( $notices ) ) {
653 $notices = array( $notices );
654 }
655
656 foreach ( $notices as $notice_id ) {
657
658 $notification = $this->get_notification( $notice_id );
659 $rn = $this->remote_get_notification( $notification );
660
661 if ( is_wp_error( $rn ) ) {
662 echo $rn->get_error_message();
663 } else {
664 echo json_encode( $rn );
665 }
666
667 }
668
669 die();
670
671 }
672
673 /**
674 * Get the remote server URL
675 *
676 * @since 1.2.0
677 *
678 * @param string $url THe server URL to sanitize
679 *
680 * @return string
681 */
682 protected function get_remote_url( $url ) {
683
684 $url = explode( '?', $url );
685
686 return esc_url( $url[0] );
687
688 }
689
690 /**
691 * Maybe get a notification from the remote server
692 *
693 * @since 1.2.0
694 *
695 * @param array $notification The notification data array
696 *
697 * @return string|WP_Error
698 */
699 protected function remote_get_notification( $notification ) {
700
701 /* Query the server */
702 $response = wp_remote_get( $this->build_query_url( $notification['server_url'], $this->get_payload( $notification ) ), array( 'timeout' => apply_filters( 'rn_http_request_timeout', 5 ) ) );
703
704 /* If we have a WP_Error object we abort */
705 if ( is_wp_error( $response ) ) {
706 return $response;
707 }
708
709 if ( 200 !== (int) wp_remote_retrieve_response_code( $response ) ) {
710 return new WP_Error( 'invalid_response', sprintf( __( 'The server response was invalid (code %s)', 'remote-notifications' ), wp_remote_retrieve_response_code( $response ) ) );
711 }
712
713 $body = wp_remote_retrieve_body( $response );
714
715 if ( empty( $body ) ) {
716 return new WP_Error( 'empty_response', __( 'The server response is empty', 'remote-notifications' ) );
717 }
718
719 $body = json_decode( $body );
720
721 if ( is_null( $body ) ) {
722 return new WP_Error( 'json_decode_error', __( 'Cannot decode the response content', 'remote-notifications' ) );
723 }
724
725 set_transient( 'rn_last_notification_' . $notification['notice_id'], $body, $notification['cache_lifetime'] * 60 * 60 );
726 delete_option( 'rdn_fetch_' . $notification['notice_id'] );
727
728 if ( $this->is_notification_error( $body ) ) {
729 return new WP_Error( 'notification_error', $this->get_notification_error_message( $body ) );
730 }
731
732 return $body;
733
734 }
735
736 /**
737 * Check if the notification returned by the server is an error
738 *
739 * @since 1.2.0
740 *
741 * @param object $notification Notification returned
742 *
743 * @return bool
744 */
745 protected function is_notification_error( $notification ) {
746
747 if ( false === $this->get_notification_error_message( $notification ) ) {
748 return false;
749 }
750
751 return true;
752
753 }
754
755 /**
756 * Get the error message returned by the remote server
757 *
758 * @since 1.2.0
759 *
760 * @param object $notification Notification returned
761 *
762 * @return bool|string
763 */
764 protected function get_notification_error_message( $notification ) {
765
766 if ( ! is_object( $notification ) ) {
767 return false;
768 }
769
770 if ( ! isset( $notification->error ) ) {
771 return false;
772 }
773
774 return sanitize_text_field( $notification->error );
775
776 }
777
778 /**
779 * Get the payload required for querying the remote server
780 *
781 * @since 1.2.0
782 *
783 * @param array $notification The notification data array
784 *
785 * @return string
786 */
787 protected function get_payload( $notification ) {
788 return base64_encode( json_encode( array(
789 'channel' => is_array( $notification ) && isset( $notification['channel_id'] ) ? $notification['channel_id'] : '',
790 'key' => is_array( $notification ) && isset( $notification['channel_key'] ) ? $notification['channel_key'] : ''
791 ) ) );
792 }
793
794 /**
795 * Get the full URL used for the remote get
796 *
797 * @since 1.2.0
798 *
799 * @param string $url The remote server URL
800 * @param string $payload The encoded payload
801 *
802 * @return string
803 */
804 protected function build_query_url( $url, $payload ) {
805 return add_query_arg( array(
806 'post_type' => 'notification',
807 'payload' => $payload
808 ), $this->get_remote_url( $url ) );
809 }
810
811 }
812
813 }
814
815 /**
816 * The main function responsible for returning the unique RDN client
817 *
818 * Use this function like you would a global variable, except without needing
819 * to declare the global.
820 *
821 * @since 1.3.0
822 * @return object Remote_Dashboard_Notifications_Client
823 */
824 function RDNC() {
825 return Remote_Dashboard_Notifications_Client::instance();
826 }
827
828 // Get Awesome Support Running
829 RDNC();
830
831 /**
832 * Register a new remote notification
833 *
834 * Helper function for registering new notifications through the Remote_Dashboard_Notifications_Client class
835 *
836 * @since 1.3.0
837 *
838 * @param int $channel_id Channel ID on the remote server
839 * @param string $channel_key Channel key for authentication with the server
840 * @param string $server Notification server URL
841 * @param int $cache Cache lifetime (in hours)
842 *
843 * @return bool|string
844 */
845 function rdnc_add_notification( $channel_id, $channel_key, $server, $cache = 6 ) {
846 return RDNC()->add_notification( $channel_id, $channel_key, $server, $cache );
847 }
848
849 if ( ! class_exists( 'TAV_Remote_Notification_Client' ) ) {
850
851 /**
852 * Class TAV_Remote_Notification_Client
853 *
854 * This class, even though deprecated, is kept here for backwards compatibility. It is now just a wrapper for the new notification registration method.
855 *
856 * @deprecated @1.3.0
857 */
858 class TAV_Remote_Notification_Client {
859
860 public function __construct( $channel_id = false, $channel_key = false, $server = false ) {
861 rdnc_add_notification( $channel_id, $channel_key, $server );
862 }
863 }
864
865 }
866