PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / trunk
GiveWP – Donation Plugin and Fundraising Platform vtrunk
4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / includes / class-give-comment.php
give / includes Last commit date
admin 19 hours ago api 3 years ago database 5 months ago deprecated 1 month ago donors 5 months ago emails 9 months ago forms 19 hours ago frontend 6 years ago gateways 9 months ago libraries 9 months ago payments 2 months ago actions.php 9 months ago ajax-functions.php 2 days ago class-give-async-process.php 1 year ago class-give-background-updater.php 9 months ago class-give-cache-setting.php 1 year ago class-give-cache.php 9 months ago class-give-cli-commands.php 1 year ago class-give-comment.php 9 months ago class-give-cron.php 9 months ago class-give-donate-form.php 1 year ago class-give-donor.php 2 years ago class-give-email-access.php 5 years ago class-give-license-handler.php 1 month ago class-give-logging.php 9 months ago class-give-readme-parser.php 4 years ago class-give-roles.php 5 months ago class-give-scripts.php 2 weeks ago class-give-session.php 9 months ago class-give-stats.php 6 years ago class-give-template-loader.php 6 years ago class-give-tooltips.php 6 years ago class-give-translation.php 4 years ago class-notices.php 9 months ago country-functions.php 7 months ago currencies-list.php 7 months ago currency-functions.php 3 years ago error-tracking.php 6 years ago filters.php 9 months ago formatting.php 9 months ago install.php 9 months ago login-register.php 2 years ago misc-functions.php 1 month ago plugin-compatibility.php 6 years ago post-types.php 1 year ago price-functions.php 6 years ago process-donation.php 1 year ago setting-functions.php 6 years ago shortcodes.php 1 year ago template-functions.php 1 year ago user-functions.php 3 years ago
class-give-comment.php
718 lines
1 <?php
2
3 /**
4 * Class for managing comments
5 *
6 * @package Give
7 * @subpackage Classes/Give_Cache
8 * @copyright Copyright (c) 2018, GiveWP
9 * @license https://opensource.org/licenses/gpl-license GNU Public License
10 * @since 2.2.0
11 */
12 class Give_Comment {
13 /**
14 * Instance.
15 *
16 * @since 2.2.0
17 * @access private
18 * @var
19 */
20 private static $instance;
21
22 /**
23 * Comment Types.
24 *
25 * @since 2.2.0
26 * @access private
27 * @var array
28 */
29 private $comment_types;
30
31 /**
32 * Comment Table.
33 *
34 * @since 2.3.0
35 * @access public
36 * @var Give_DB_Comments
37 */
38 public $db;
39
40 /**
41 * Comment Meta Table.
42 *
43 * @since 2.3.0
44 * @access public
45 * @var Give_DB_Comment_Meta
46 */
47 public $db_meta;
48
49 /**
50 * Singleton pattern.
51 *
52 * @since 2.2.0
53 * @access private
54 */
55 private function __construct() {
56 }
57
58
59 /**
60 * Get instance.
61 *
62 * @since 2.2.0
63 * @access pu
64 * @return Give_Comment
65 */
66 public static function get_instance() {
67 if ( null === static::$instance ) {
68 self::$instance = new static();
69 self::$instance->init();
70 }
71
72 return self::$instance;
73 }
74
75 /**
76 * Initialize
77 *
78 * @since 2.2.0
79 * @access private
80 */
81 private function init() {
82 $this->db = new Give_DB_Comments();
83 $this->db_meta = new Give_DB_Comment_Meta();
84
85 /**
86 * Filter the comment type
87 *
88 * @since 2.2.0
89 */
90 $this->comment_types = apply_filters(
91 'give_comment_type',
92 self::get_comment_types( array( 'payment', 'donor' ) )
93 );
94
95 // Backward compatibility.
96 if ( ! give_has_upgrade_completed( 'v230_move_donation_note' ) ) {
97 add_action( 'pre_get_comments', array( $this, 'hide_comments' ), 10 );
98 add_filter( 'comments_clauses', array( $this, 'hide_comments_pre_wp_41' ), 10, 1 );
99 add_filter( 'comment_feed_where', array( $this, 'hide_comments_from_feeds' ), 10, 1 );
100 add_filter( 'wp_count_comments', array( $this, 'remove_comments_from_comment_counts' ), 10, 2 );
101 add_filter( 'get_comment_author', array($this, 'get_comment_author'), 10, 3 );
102 }
103 }
104
105 /**
106 * Insert/Update comment
107 *
108 * @since 2.2.0
109 * @access public
110 *
111 * @param array $comment_args Comment arguments.
112 *
113 * @return int|WP_Error
114 */
115 public static function add( $comment_args = array() ) {
116 // Backward compatibility.
117 $func_args = func_get_args();
118 $comment_id = self::_bc_add( $func_args );
119 if ( ! is_null( $comment_id ) ) {
120 return $comment_id;
121 }
122
123 // Backward compatibility.
124 if ( is_numeric( $comment_args ) ) {
125 $comment_args = array(
126 'comment_parent' => $func_args[0],
127 'comment_content' => $func_args[1],
128 'comment_type' => 'payment' === $func_args[2] ? 'donation' : $func_args[1],
129 );
130 }
131
132 $comment_args = wp_parse_args(
133 $comment_args,
134 array(
135 'comment_ID' => 0,
136 'comment_parent' => 0,
137 'comment_type' => 'general',
138 )
139 );
140
141 $is_existing_comment = array_key_exists( 'comment_ID', $comment_args ) && ! empty( $comment_args['comment_ID'] );
142 $action_type = $is_existing_comment ? 'update' : 'insert';
143
144 /**
145 * Fires before inserting/updating payment|donor comment.
146 *
147 * @param int $id Payment|Donor ID.
148 * @param string $note Comment text.
149 *
150 * @since 1.0
151 */
152 do_action(
153 "give_pre_{$action_type}_{$comment_args['comment_type']}_note",
154 $comment_args['comment_parent'],
155 $comment_args['comment_content'],
156 $comment_args
157 );
158
159 $comment_id = Give()->comment->db->add(
160 array(
161 'comment_ID' => absint( $comment_args['comment_ID'] ),
162 'comment_content' => $comment_args['comment_content'],
163 'comment_parent' => $comment_args['comment_parent'],
164 'comment_type' => $comment_args['comment_type'],
165 )
166 );
167
168 /**
169 * Fires after payment|donor comment inserted/updated.
170 *
171 * @param int $comment_id Comment ID.
172 * @param int $id Payment|Donor ID.
173 * @param string $note Comment text.
174 *
175 * @since 1.0
176 */
177 do_action(
178 "give_{$action_type}_{$comment_args['comment_type']}_note",
179 $comment_args['comment_ID'],
180 $comment_args['comment_parent'],
181 $comment_args['comment_content'],
182 $comment_args
183 );
184
185 return $comment_id;
186 }
187
188
189 /**
190 * Delete comment
191 *
192 * @since 2.2.0
193 * @access public
194 *
195 * @param int $comment_id The comment ID to delete.
196 *
197 * @since 1.0
198 *
199 * @return bool True on success, false otherwise.
200 */
201 public static function delete( $comment_id ) {
202 // Backward compatibility.
203 $func_args = func_get_args();
204 $ret = self::_bc_delete( $func_args );
205 if ( ! is_null( $ret ) ) {
206 return $ret;
207 }
208
209 $ret = false;
210
211 // Bailout
212 if ( empty( $comment_id ) ) {
213 return $ret;
214 }
215
216 /* @var stdClass $comment */
217 $comment = Give()->comment->db->get_by( 'comment_ID', $comment_id );
218
219 if ( ! is_object( $comment ) ) {
220 return $ret;
221 }
222
223 $comment_type = $comment->comment_type;
224 $comment_parent = $comment->comment_parent;
225
226 /**
227 * Fires before deleting donation note.
228 *
229 * @param int $comment_id Comment ID.
230 * @param int $id Payment|Donor ID.
231 *
232 * @since 1.0
233 */
234 do_action( "give_pre_delete_{$comment_type}_note", $comment_id, $comment_parent );
235
236 $ret = Give()->comment->db->delete( $comment_id );
237
238 // Delete comment meta.
239 Give()->comment->db_meta->delete_all_meta( $comment_id );
240
241 /**
242 * Fires after donation note deleted.
243 *
244 * @param int $comment_id Note ID.
245 * @param int $id Payment|Donor ID.
246 * @param bool $ret Flag to check if comment deleted or not.
247 *
248 * @since 1.0
249 */
250 do_action( "give_post_delete_{$comment_type}_note", $comment_id, $comment_parent, $ret );
251
252 return $ret;
253 }
254
255
256 /**
257 * Get comments
258 *
259 * @since 2.2.0
260 * @access public
261 *
262 * @param array $comment_args
263 *
264 * @return array
265 */
266 public static function get( $comment_args ) {
267 global $wpdb;
268
269 // Backward compatibility.
270 $func_args = func_get_args();
271 $comments = self::_bc_get( $func_args );
272 if ( ! is_null( $comments ) ) {
273 return $comments;
274 }
275
276 // Backward compatibility.
277 if ( is_numeric( $comment_args ) ) {
278 $comment_args = array(
279 'comment_parent' => $func_args[0],
280 'comment_type' => 'payment' === $func_args[1] ? 'donation' : $func_args[1],
281 );
282 }
283
284 $comments = $wpdb->get_results( Give()->comment->db->get_sql( $comment_args ) );
285
286 return $comments;
287 }
288
289 /**
290 * Exclude comments from showing in Recent
291 * Comments widgets
292 *
293 * @since 2.2.0
294 * @access public
295 *
296 * @param object $query WordPress Comment Query Object.
297 *
298 * @return void
299 */
300 public function hide_comments( $query ) {
301 if ( version_compare( floatval( get_bloginfo( 'version' ) ), '4.1', '>=' ) ) {
302 $types = isset( $query->query_vars['type__not_in'] ) ? $query->query_vars['type__not_in'] : array();
303 if ( ! is_array( $types ) ) {
304 $types = array( $types );
305 }
306
307 $types = array_filter( array_merge( $types, $this->comment_types ) );
308
309 $query->query_vars['type__not_in'] = $types;
310 }
311 }
312
313 /**
314 * Exclude notes (comments) from showing in Recent Comments widgets
315 *
316 * @since 2.2.0
317 * @access public
318 *
319 * @param array $clauses Comment clauses for comment query.
320 *
321 * @return array $clauses Updated comment clauses.
322 */
323 public function hide_comments_pre_wp_41( $clauses ) {
324 if ( version_compare( floatval( get_bloginfo( 'version' ) ), '4.1', '<' ) ) {
325 foreach ( $this->comment_types as $comment_type ) {
326 $clauses['where'] .= " AND comment_type != \"{$comment_type}\"";
327 }
328 }
329
330 return $clauses;
331 }
332
333 /**
334 * Exclude notes (comments) from showing in comment feeds
335 *
336 * @since 2.2.0
337 * @access public
338 *
339 * @param string $where
340 *
341 * @return string $where
342 */
343 public function hide_comments_from_feeds( $where ) {
344 global $wpdb;
345
346 foreach ( $this->comment_types as $comment_type ) {
347 $where .= $wpdb->prepare( ' AND comment_type!=%s', $comment_type );
348 }
349
350 return $where;
351 }
352
353 /**
354 * Remove Give Comments from the wp_count_comments function
355 *
356 * @since 2.2.0
357 * @access public
358 *
359 * @param array $stats (empty from core filter).
360 * @param int $post_id Post ID.
361 *
362 * @return array|object Array of comment counts.
363 */
364 public function remove_comments_from_comment_counts( $stats, $post_id ) {
365 global $wpdb;
366
367 $post_id = (int) $post_id;
368
369 if ( apply_filters( 'give_count_payment_notes_in_comments', false ) ) {
370 return $stats;
371 }
372
373 $stats = Give_Cache::get_group( "comments-{$post_id}", 'counts' );
374
375 // Return result from cache.
376 if ( ! is_null( $stats ) ) {
377 return $stats;
378 }
379
380 $where = 'WHERE';
381
382 foreach ( $this->comment_types as $index => $comment_type ) {
383 $where .= ( $index ? ' AND ' : ' ' ) . "comment_type != \"{$comment_type}\"";
384 }
385
386 if ( $post_id > 0 ) {
387 $where .= $wpdb->prepare( ' AND comment_post_ID = %d', $post_id );
388 }
389
390 $count = $wpdb->get_results(
391 "
392 SELECT comment_approved, COUNT( * ) AS num_comments
393 FROM {$wpdb->comments} {$where}
394 GROUP BY comment_approved
395 ",
396 ARRAY_A
397 );
398
399 $total = 0;
400 $approved = array(
401 '0' => 'moderated',
402 '1' => 'approved',
403 'spam' => 'spam',
404 'trash' => 'trash',
405 'post-trashed' => 'post-trashed',
406 );
407
408 foreach ( (array) $count as $row ) {
409 // Don't count post-trashed toward totals.
410 if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] ) {
411 $total += $row['num_comments'];
412 }
413 if ( isset( $approved[ $row['comment_approved'] ] ) ) {
414 $stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments'];
415 }
416 }
417
418 $stats['total_comments'] = $stats['all'] = $total;
419 foreach ( $approved as $key ) {
420 if ( empty( $stats[ $key ] ) ) {
421 $stats[ $key ] = 0;
422 }
423 }
424
425 $stats = (object) $stats;
426
427 Give_Cache::set_group( "comments-{$post_id}", $stats, 'counts' );
428
429 return $stats;
430 }
431
432 /**
433 * Get donor name
434 *
435 * @since 4.9.0 rename function - PHP 8 compatibility
436 * @since 2.2.0
437 * @access public
438 *
439 * @param string $author
440 * @param int $comment_id
441 * @param WP_Comment $comment
442 *
443 * @return mixed
444 */
445 public function get_comment_author( $author, $comment_id, $comment ) {
446 if ( in_array( $comment->comment_type, $this->comment_types ) ) {
447 switch ( $comment->comment_type ) {
448 case 'give_payment_note':
449 if ( get_comment_meta( $comment_id, '_give_donor_id', true ) ) {
450 $author = give_get_donor_name_by( $comment->comment_post_ID );
451 }
452 }
453 }
454
455 return $author;
456 }
457
458
459 /**
460 * Get comment types
461 *
462 * @since 2.2.0
463 * @access public
464 *
465 * @param array @comment_types
466 *
467 * @return array
468 */
469 public static function get_comment_types( $comment_types ) {
470 $_comment_types = array();
471 foreach ( $comment_types as $comment_type ) {
472 $_comment_types[] = "give_{$comment_type}_note";
473 }
474
475 return $_comment_types;
476 }
477
478 /**
479 * Get comments
480 * Note: This function add backward compatibility for get function
481 *
482 * @since 2.3.0
483 * @access public
484 *
485 * @param array $comment_args
486 *
487 * @return array|null
488 */
489 private static function _bc_get( $comment_args ) {
490 $comments = null;
491
492 if ( ! give_has_upgrade_completed( 'v230_move_donor_note' ) ) {
493 $id = $comment_args[0];
494 $comment_type = $comment_args[1];
495 $comment_args = isset( $comment_args[2] ) ? $comment_args[2] : array();
496 $search = isset( $comment_args[3] ) ? $comment_args[3] : '';
497
498 // Set default meta_query value.
499 if ( ! isset( $comment_args['meta_query'] ) ) {
500 $comment_args['meta_query'] = array();
501 }
502
503 // Bailout
504 if ( empty( $id ) || empty( $comment_type ) ) {
505 return $comments;
506 }
507
508 remove_action( 'pre_get_comments', array( self::$instance, 'hide_comments' ), 10 );
509 remove_filter( 'comments_clauses', array( self::$instance, 'hide_comments_pre_wp_41' ), 10 );
510
511 switch ( $comment_type ) {
512 case 'payment':
513 $comment_args['meta_query'] = ! empty( $comment_args['meta_query'] )
514 ? $comment_args['meta_query']
515 : array(
516 array(
517 'key' => '_give_donor_id',
518 'compare' => 'NOT EXISTS',
519 ),
520 );
521
522 $comments = get_comments(
523 wp_parse_args(
524 $comment_args,
525 array(
526 'post_id' => $id,
527 'order' => 'ASC',
528 'search' => $search,
529 'type' => 'give_payment_note',
530 )
531 )
532 );
533 break;
534
535 case 'donor':
536 $comment_args['meta_query'] = ! empty( $comment_args['meta_query'] )
537 ? $comment_args['meta_query']
538 : array(
539 array(
540 'key' => "_give_{$comment_type}_id",
541 'value' => $id,
542 ),
543 );
544
545 $comments = get_comments(
546 wp_parse_args(
547 $comment_args,
548 array(
549 'order' => 'ASC',
550 'search' => $search,
551 'type' => 'give_donor_note',
552 )
553 )
554 );
555 break;
556 }
557
558 add_action( 'pre_get_comments', array( self::$instance, 'hide_comments' ), 10, 1 );
559 add_filter( 'comments_clauses', array( self::$instance, 'hide_comments_pre_wp_41' ), 10, 1 );
560 }
561
562 return $comments;
563 }
564
565
566 /**
567 * Insert/Update comment
568 * Note: This function add backward compatibility for add function
569 *
570 * @since 2.3.0
571 * @access public
572 *
573 * @param array $comment_args Comment arguments.
574 *
575 * @return int|null|WP_Error
576 */
577 private static function _bc_add( $comment_args = array() ) {
578 $comment_id = null;
579
580 if ( ! give_has_upgrade_completed( 'v230_move_donor_note' ) ) {
581 $id = $comment_args[0];
582 $note = $comment_args[1];
583 $comment_type = $comment_args[2];
584 $comment_args = isset( $comment_args[3] ) ? $comment_args[3] : array();
585
586 // Bailout
587 if ( empty( $id ) || empty( $note ) || empty( $comment_type ) ) {
588 return new WP_Error( 'give_invalid_required_param', __( 'This comment has invalid ID or comment text or comment type', 'give' ) );
589 }
590
591 $is_existing_comment = array_key_exists( 'comment_ID', $comment_args ) && ! empty( $comment_args['comment_ID'] );
592 $action_type = $is_existing_comment ? 'update' : 'insert';
593
594 /**
595 * Fires before inserting/updating payment|donor comment.
596 *
597 * @param int $id Payment|Donor ID.
598 * @param string $note Comment text.
599 *
600 * @since 1.0
601 */
602 do_action( "give_pre_{$action_type}_{$comment_type}_note", $id, $note );
603
604 $comment_args = wp_parse_args(
605 $comment_args,
606 array(
607 'comment_post_ID' => $id,
608 'comment_content' => $note,
609 'user_id' => is_admin() ? get_current_user_id() : 0,
610 'comment_date' => current_time( 'mysql' ),
611 'comment_date_gmt' => current_time( 'mysql', 1 ),
612 'comment_approved' => 1,
613 'comment_parent' => 0,
614 'comment_author' => '',
615 'comment_author_IP' => '',
616 'comment_author_url' => '',
617 'comment_author_email' => '',
618 'comment_type' => "give_{$comment_type}_note",
619
620 )
621 );
622
623 // Check comment max length.
624 $error = wp_check_comment_data_max_lengths( $comment_args );
625 if ( is_wp_error( $error ) ) {
626 return $error;
627 }
628
629 // Remove moderation emails when comment posted.
630 remove_action( 'comment_post', 'wp_new_comment_notify_moderator' );
631 remove_action( 'comment_post', 'wp_new_comment_notify_postauthor' );
632
633 // Remove comment flood check.
634 remove_action( 'check_comment_flood', 'check_comment_flood_db', 10 );
635
636 $comment_id = $is_existing_comment
637 ? wp_update_comment( $comment_args )
638 : wp_new_comment( $comment_args, true );
639
640 // Add moderation emails when comment posted.
641 add_action( 'comment_post', 'wp_new_comment_notify_moderator' );
642 add_action( 'comment_post', 'wp_new_comment_notify_postauthor' );
643
644 // Add comment flood check.
645 add_action( 'check_comment_flood', 'check_comment_flood_db', 10, 4 );
646
647 update_comment_meta( $comment_id, "_give_{$comment_type}_id", $id );
648
649 /**
650 * Fires after payment|donor comment inserted/updated.
651 *
652 * @param int $comment_id Comment ID.
653 * @param int $id Payment|Donor ID.
654 * @param string $note Comment text.
655 *
656 * @since 1.0
657 */
658 do_action( "give_{$action_type}_{$comment_type}_note", $comment_id, $id, $note );
659 }
660
661 return $comment_id;
662 }
663
664 /**
665 * Delete comment
666 * Note: This function add backward compatibility for delete function
667 *
668 * @since 2.3.0
669 * @access public
670 *
671 * @param array $comment_args Comment arguments.
672 *
673 * @since 1.0
674 *
675 * @return bool True on success, false otherwise.
676 */
677 private static function _bc_delete( $comment_args ) {
678 $ret = null;
679
680 if ( ! give_has_upgrade_completed( 'v230_move_donor_note' ) ) {
681 $comment_id = $comment_args[0];
682 $id = $comment_args[1];
683 $comment_type = $comment_args[2];
684
685 $ret = false;
686
687 // Bailout
688 if ( empty( $id ) || empty( $comment_id ) || empty( $comment_type ) ) {
689 return $ret;
690 }
691 /**
692 * Fires before deleting donation note.
693 *
694 * @param int $comment_id Comment ID.
695 * @param int $id Payment|Donor ID.
696 *
697 * @since 1.0
698 */
699 do_action( "give_pre_delete_{$comment_type}_note", $comment_id, $id );
700
701 $ret = wp_delete_comment( $comment_id, true );
702
703 /**
704 * Fires after donation note deleted.
705 *
706 * @param int $comment_id Note ID.
707 * @param int $id Payment|Donor ID.
708 * @param bool $ret Flag to check if comment deleted or not.
709 *
710 * @since 1.0
711 */
712 do_action( "give_post_delete_{$comment_type}_note", $comment_id, $id, $ret );
713 }
714
715 return $ret;
716 }
717 }
718