| @@ -1,107 +1,104 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -// Do not allow the file to be called directly. | |
| 4 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 5 | - exit; | |
| 6 | -} | |
| 7 | - | |
| 8 | -/** | |
| 9 | - * This class is used to log any comment related action. | |
| 10 | - */ | |
| 11 | -class P_Event_Comments extends P_Event_Log { | |
| 12 | - | |
| 13 | - /** | |
| 14 | - * Hook into the actions so we can log it. | |
| 15 | - * | |
| 16 | - * @return void | |
| 17 | - */ | |
| 18 | - public function __construct() { | |
| 19 | - if ( ! get_option( 'patchstack_activity_log_comments', 0 ) ) { | |
| 20 | - return; | |
| 21 | - } | |
| 22 | - | |
| 23 | - add_action( 'wp_insert_comment', [ &$this, 'handleCommentLog' ], 10, 2 ); | |
| 24 | - add_action( 'edit_comment', [ &$this, 'handleCommentLog' ] ); | |
| 25 | - add_action( 'trash_comment', [ &$this, 'handleCommentLog' ] ); | |
| 26 | - add_action( 'untrash_comment', [ &$this, 'handleCommentLog' ] ); | |
| 27 | - add_action( 'spam_comment', [ &$this, 'handleCommentLog' ] ); | |
| 28 | - add_action( 'unspam_comment', [ &$this, 'handleCommentLog' ] ); | |
| 29 | - add_action( 'delete_comment', [ &$this, 'handleCommentLog' ] ); | |
| 30 | - add_action( 'transition_comment_status', [ &$this, 'transitionCommentStatus' ], 10, 3 ); | |
| 31 | - } | |
| 32 | - | |
| 33 | - /** | |
| 34 | - * Log the action regarding the comment. | |
| 35 | - * | |
| 36 | - * @param integer $id | |
| 37 | - * @param string $action | |
| 38 | - * @param string $comment | |
| 39 | - * @return void | |
| 40 | - */ | |
| 41 | - protected function _addCommentLog( $id, $action, $comment = null ) { | |
| 42 | - if ( is_null( $comment ) ) { | |
| 43 | - $comment = get_comment( $id ); | |
| 44 | - } | |
| 45 | - | |
| 46 | - $this->insert( | |
| 47 | - [ | |
| 48 | - 'action' => $action, | |
| 49 | - 'object' => 'comment', | |
| 50 | - 'object_id' => $id, | |
| 51 | - 'object_name' => esc_html( get_the_title( $comment->comment_post_ID ) ), | |
| 52 | - ] | |
| 53 | - ); | |
| 54 | - } | |
| 55 | - | |
| 56 | - /** | |
| 57 | - * Determine what kind of comment action is executed. | |
| 58 | - * | |
| 59 | - * @param integer $comment_id | |
| 60 | - * @param string $comment | |
| 61 | - * @return void | |
| 62 | - */ | |
| 63 | - public function handleCommentLog( $comment_id, $comment = null ) { | |
| 64 | - if ( is_null( $comment ) ) { | |
| 65 | - $comment = get_comment( $comment_id ); | |
| 66 | - } | |
| 67 | - | |
| 68 | - $action = 'created'; | |
| 69 | - switch ( current_filter() ) { | |
| 70 | - case 'wp_insert_comment': | |
| 71 | - $action = 1 === (int) $comment->comment_approved ? 'approved' : 'pending'; | |
| 72 | - break; | |
| 73 | - case 'edit_comment': | |
| 74 | - $action = 'updated'; | |
| 75 | - break; | |
| 76 | - case 'delete_comment': | |
| 77 | - $action = 'deleted'; | |
| 78 | - break; | |
| 79 | - case 'trash_comment': | |
| 80 | - $action = 'trashed'; | |
| 81 | - break; | |
| 82 | - case 'untrash_comment': | |
| 83 | - $action = 'untrashed'; | |
| 84 | - break; | |
| 85 | - case 'spam_comment': | |
| 86 | - $action = 'spammed'; | |
| 87 | - break; | |
| 88 | - case 'unspam_comment': | |
| 89 | - $action = 'unspammed'; | |
| 90 | - break; | |
| 91 | - } | |
| 92 | - | |
| 93 | - $this->_addCommentLog( $comment_id, $action, $comment ); | |
| 94 | - } | |
| 95 | - | |
| 96 | - /** | |
| 97 | - * When the status of a comment is transitioned. | |
| 98 | - * | |
| 99 | - * @param string $new_status | |
| 100 | - * @param string $old_status | |
| 101 | - * @param string $comment | |
| 102 | - * @return void | |
| 103 | - */ | |
| 104 | - public function transitionCommentStatus( $new_status, $old_status, $comment ) { | |
| 105 | - $this->_addCommentLog( $comment->comment_ID, $new_status, $comment ); | |
| 106 | - } | |
| 107 | -} | |
| 1 | +<?php | |
| 2 | + | |
| 3 | +// Do not allow the file to be called directly. | |
| 4 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 5 | + exit; | |
| 6 | +} | |
| 7 | + | |
| 8 | +/** | |
| 9 | + * This class is used to log any comment related action. | |
| 10 | + */ | |
| 11 | +class P_Event_Comments extends P_Event_Log { | |
| 12 | + | |
| 13 | + /** | |
| 14 | + * Hook into the actions so we can log it. | |
| 15 | + * | |
| 16 | + * @return void | |
| 17 | + */ | |
| 18 | + public function __construct() { | |
| 19 | + add_action( 'wp_insert_comment', array( &$this, 'handleCommentLog' ), 10, 2 ); | |
| 20 | + add_action( 'edit_comment', array( &$this, 'handleCommentLog' ) ); | |
| 21 | + add_action( 'trash_comment', array( &$this, 'handleCommentLog' ) ); | |
| 22 | + add_action( 'untrash_comment', array( &$this, 'handleCommentLog' ) ); | |
| 23 | + add_action( 'spam_comment', array( &$this, 'handleCommentLog' ) ); | |
| 24 | + add_action( 'unspam_comment', array( &$this, 'handleCommentLog' ) ); | |
| 25 | + add_action( 'delete_comment', array( &$this, 'handleCommentLog' ) ); | |
| 26 | + add_action( 'transition_comment_status', array( &$this, 'transitionCommentStatus' ), 10, 3 ); | |
| 27 | + | |
| 28 | + } | |
| 29 | + | |
| 30 | + /** | |
| 31 | + * Log the action regarding the comment. | |
| 32 | + * | |
| 33 | + * @param integer $id | |
| 34 | + * @param string $action | |
| 35 | + * @param string $comment | |
| 36 | + * @return void | |
| 37 | + */ | |
| 38 | + protected function _addCommentLog( $id, $action, $comment = null ) { | |
| 39 | + if ( is_null( $comment ) ) { | |
| 40 | + $comment = get_comment( $id ); | |
| 41 | + } | |
| 42 | + | |
| 43 | + $this->insert( | |
| 44 | + array( | |
| 45 | + 'action' => $action, | |
| 46 | + 'object' => 'comment', | |
| 47 | + 'object_id' => $id, | |
| 48 | + 'object_name' => esc_html( get_the_title( $comment->comment_post_ID ) ), | |
| 49 | + ) | |
| 50 | + ); | |
| 51 | + } | |
| 52 | + | |
| 53 | + /** | |
| 54 | + * Determine what kind of comment action is executed. | |
| 55 | + * | |
| 56 | + * @param integer $comment_id | |
| 57 | + * @param string $comment | |
| 58 | + * @return void | |
| 59 | + */ | |
| 60 | + public function handleCommentLog( $comment_id, $comment = null ) { | |
| 61 | + if ( is_null( $comment ) ) { | |
| 62 | + $comment = get_comment( $comment_id ); | |
| 63 | + } | |
| 64 | + | |
| 65 | + $action = 'created'; | |
| 66 | + switch ( current_filter() ) { | |
| 67 | + case 'wp_insert_comment': | |
| 68 | + $action = 1 === (int) $comment->comment_approved ? 'approved' : 'pending'; | |
| 69 | + break; | |
| 70 | + case 'edit_comment': | |
| 71 | + $action = 'updated'; | |
| 72 | + break; | |
| 73 | + case 'delete_comment': | |
| 74 | + $action = 'deleted'; | |
| 75 | + break; | |
| 76 | + case 'trash_comment': | |
| 77 | + $action = 'trashed'; | |
| 78 | + break; | |
| 79 | + case 'untrash_comment': | |
| 80 | + $action = 'untrashed'; | |
| 81 | + break; | |
| 82 | + case 'spam_comment': | |
| 83 | + $action = 'spammed'; | |
| 84 | + break; | |
| 85 | + case 'unspam_comment': | |
| 86 | + $action = 'unspammed'; | |
| 87 | + break; | |
| 88 | + } | |
| 89 | + | |
| 90 | + $this->_addCommentLog( $comment_id, $action, $comment ); | |
| 91 | + } | |
| 92 | + | |
| 93 | + /** | |
| 94 | + * When the status of a comment is transitioned. | |
| 95 | + * | |
| 96 | + * @param string $new_status | |
| 97 | + * @param string $old_status | |
| 98 | + * @param string $comment | |
| 99 | + * @return void | |
| 100 | + */ | |
| 101 | + public function transitionCommentStatus( $new_status, $old_status, $comment ) { | |
| 102 | + $this->_addCommentLog( $comment->comment_ID, $new_status, $comment ); | |
| 103 | + } | |
| 104 | +} | |