PluginProbe
ActivityPub / 8.0.1
ActivityPub v8.0.1
9.3.1 9.3.0 9.2.2 9.2.1 9.2.0 9.1.0 9.0.2 9.0.1 9.0.0 8.3.0 8.2.1 8.2.0 8.1.1 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.2.0 1.3.0 2.0.0 2.0.1 2.1.0 2.1.1 All 160 releases
activitypub / includes / cli / class-comment-command.php

class-comment-command.php in ActivityPub 8.0.1, at includes/cli/class-comment-command.php

96 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Comment CLI Command.
4 *
5 * @package Activitypub
6 */
7
8 namespace Activitypub\Cli;
9
10 use function Activitypub\add_to_outbox;
11 use function Activitypub\was_comment_received;
12
13 /**
14 * Manage ActivityPub comments.
15 *
16 * @package Activitypub
17 */
18 class Comment_Command extends \WP_CLI_Command {
19
20 /**
21 * Delete a Comment from the Fediverse.
22 *
23 * Sends a Delete activity to all followers to remove the comment from
24 * federated instances.
25 *
26 * ## OPTIONS
27 *
28 * <id>
29 * : The ID of the Comment.
30 *
31 * [--yes]
32 * : Skip the confirmation prompt.
33 *
34 * ## EXAMPLES
35 *
36 * # Delete comment with ID 123
37 * $ wp activitypub comment delete 123
38 *
39 * @subcommand delete
40 *
41 * @param array $args The positional arguments.
42 * @param array $assoc_args The associative arguments.
43 */
44 public function delete( $args, $assoc_args ) {
45 $comment = \get_comment( $args[0] );
46
47 if ( ! $comment ) {
48 \WP_CLI::error( 'Comment not found.' );
49 }
50
51 if ( was_comment_received( $comment ) ) {
52 \WP_CLI::error( 'This comment was received via ActivityPub and cannot be deleted or updated.' );
53 }
54
55 \WP_CLI::confirm( 'Do you really want to delete the Comment with the ID: ' . $args[0], $assoc_args );
56 add_to_outbox( $comment, 'Delete', $comment->user_id );
57 \WP_CLI::success( '"Delete" activity is queued.' );
58 }
59
60 /**
61 * Update a Comment on the Fediverse.
62 *
63 * Sends an Update activity to all followers to refresh the comment content
64 * on federated instances.
65 *
66 * ## OPTIONS
67 *
68 * <id>
69 * : The ID of the Comment.
70 *
71 * ## EXAMPLES
72 *
73 * # Update comment with ID 123
74 * $ wp activitypub comment update 123
75 *
76 * @subcommand update
77 *
78 * @param array $args The positional arguments.
79 * @param array $assoc_args The associative arguments (unused).
80 */
81 public function update( $args, $assoc_args ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
82 $comment = \get_comment( $args[0] );
83
84 if ( ! $comment ) {
85 \WP_CLI::error( 'Comment not found.' );
86 }
87
88 if ( was_comment_received( $comment ) ) {
89 \WP_CLI::error( 'This comment was received via ActivityPub and cannot be deleted or updated.' );
90 }
91
92 add_to_outbox( $comment, 'Update', $comment->user_id );
93 \WP_CLI::success( '"Update" activity is queued.' );
94 }
95 }
96