PluginProbe
Texty – SMS Notification for WordPress, WooCommerce, Dokan and more / 0.2
Texty – SMS Notification for WordPress, WooCommerce, Dokan and more v0.2
2.0.2 trunk 0.2 1.0 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 2.0.0 2.0.1
texty / includes / Notifications / Comment.php

Comment.php in Texty – SMS Notification for WordPress, WooCommerce, Dokan and more 0.2, at includes/Notifications/Comment.php

90 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Texty\Notifications;
4
5 class Comment extends Notification {
6
7 /**
8 * @var int
9 */
10 private $comment_id;
11
12 /**
13 * Initialize
14 */
15 public function __construct() {
16 $this->title = __( 'New Comment', 'texty' );
17 $this->id = 'comment';
18 $this->default_recipients = [ 'administrator' ];
19 $this->default = <<<'EOD'
20 A new comment added on the post "{post_title}" by {author} ({email}).
21
22 View comment: {post_url}
23 EOD;
24 }
25
26 /**
27 * Set the user ID
28 *
29 * @param int $comment_id
30 *
31 * @return self
32 */
33 public function set_comment( $comment_id ) {
34 $this->comment_id = $comment_id;
35
36 return $this;
37 }
38
39 /**
40 * Return the message
41 *
42 * @return string
43 */
44 public function get_message() {
45 $message = parent::get_message_raw();
46
47 if ( ! $this->comment_id ) {
48 return $message;
49 }
50
51 $comment = get_comment( $this->comment_id );
52
53 foreach ( $this->replacement_keys() as $search => $value ) {
54 $value = ( $search === 'post_url' ) ? get_permalink( $comment->comment_post_ID ) : $comment->$value;
55 $message = str_replace( '{' . $search . '}', $value, $message );
56 }
57
58 $message = $this->replace_global_keys( $message );
59
60 return $message;
61 }
62
63 /**
64 * Return recipients
65 *
66 * @return array
67 */
68 public function get_recipients() {
69 return $this->get_numbers_by_roles();
70 }
71
72 /**
73 * Get replacement keys
74 *
75 * @return array
76 */
77 public function replacement_keys() {
78 return [
79 'author' => 'comment_author',
80 'email' => 'comment_author_email',
81 'author_url' => 'comment_author_url',
82 'comment' => 'comment_content',
83 'ip' => 'comment_author_ip',
84 'post_id' => 'comment_post_ID',
85 'post_title' => 'post_title',
86 'post_url' => '',
87 ];
88 }
89 }
90