PluginProbe
Texty – SMS Notification for WordPress, WooCommerce, Dokan and more / 2.0.0
Texty – SMS Notification for WordPress, WooCommerce, Dokan and more v2.0.0
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 / WP / Comment.php

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

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