| 1 |
<?php |
| 2 |
/** |
| 3 |
* Comments handling |
| 4 |
* |
| 5 |
* Handles all comments operations and detection. |
| 6 |
* |
| 7 |
* @package System |
| 8 |
* @author Pierre Lannoy <https://pierre.lannoy.fr/>. |
| 9 |
* @since 1.0.0 |
| 10 |
*/ |
| 11 |
|
| 12 |
namespace POSessions\System; |
| 13 |
|
| 14 |
/** |
| 15 |
* Define the comments functionality. |
| 16 |
* |
| 17 |
* Handles all comments operations and detection. |
| 18 |
* |
| 19 |
* @package System |
| 20 |
* @author Pierre Lannoy <https://pierre.lannoy.fr/>. |
| 21 |
* @since 1.0.0 |
| 22 |
*/ |
| 23 |
class Comment { |
| 24 |
|
| 25 |
/** |
| 26 |
* Initializes the class and set its properties. |
| 27 |
* |
| 28 |
* @since 1.0.0 |
| 29 |
*/ |
| 30 |
public function __construct() { |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* Get a fully qualified comment name. |
| 35 |
* |
| 36 |
* @param mixed $id Optional. The comment id or WP_comment instance. |
| 37 |
* @return string The comment pseudo name if detected. |
| 38 |
* @since 1.0.0 |
| 39 |
*/ |
| 40 |
public static function get_full_comment_name( $id ) { |
| 41 |
$comment = null; |
| 42 |
if ( is_numeric( $id ) ) { |
| 43 |
$comment = get_comment( $id ); |
| 44 |
} |
| 45 |
if ( $id instanceof \WP_Comment ) { |
| 46 |
$comment = $id; |
| 47 |
} |
| 48 |
if ( $comment instanceof \WP_Comment ) { |
| 49 |
return sprintf( '"%s" (comment ID %s)', wp_trim_words( wp_kses( $comment->comment_content, [] ), 8 ), $comment->comment_ID ); |
| 50 |
} else { |
| 51 |
return 'unknow comment'; |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
} |
| 56 |
|