PluginProbe
ActivityPub / 5.2.0
ActivityPub v5.2.0
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 / class-cli.php

class-cli.php in ActivityPub 5.2.0, at includes/class-cli.php

134 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WP-CLI file.
4 *
5 * @package Activitypub
6 */
7
8 namespace Activitypub;
9
10 use WP_CLI;
11 use WP_CLI_Command;
12 use Activitypub\Scheduler\Post;
13 use Activitypub\Scheduler\Comment;
14
15 /**
16 * WP-CLI commands.
17 *
18 * @package Activitypub
19 */
20 class Cli extends WP_CLI_Command {
21
22 /**
23 * Remove the entire blog from the Fediverse.
24 *
25 * ## EXAMPLES
26 *
27 * $ wp activitypub self-destruct
28 *
29 * @param array|null $args The arguments.
30 * @param array|null $assoc_args The associative arguments.
31 *
32 * @return void
33 */
34 public function self_destruct( $args, $assoc_args ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
35 WP_CLI::warning( 'Self-Destructing is not implemented yet.' );
36 }
37
38 /**
39 * Delete or Update a Post, Page, Custom Post Type or Attachment.
40 *
41 * ## OPTIONS
42 *
43 * <action>
44 * : The action to perform. Either `delete` or `update`.
45 * ---
46 * options:
47 * - delete
48 * - update
49 * ---
50 *
51 * <id>
52 * : The id of the Post, Page, Custom Post Type or Attachment.
53 *
54 * ## EXAMPLES
55 *
56 * $ wp activitypub post delete 1
57 *
58 * @synopsis <action> <id>
59 *
60 * @param array $args The arguments.
61 */
62 public function post( $args ) {
63 $post = get_post( $args[1] );
64
65 if ( ! $post ) {
66 WP_CLI::error( 'Post not found.' );
67 }
68
69 switch ( $args[0] ) {
70 case 'delete':
71 WP_CLI::confirm( 'Do you really want to delete the (Custom) Post with the ID: ' . $args[1] );
72 Post::schedule_post_activity( 'trash', 'publish', $post );
73 WP_CLI::success( '"Delete" activity is queued.' );
74 break;
75 case 'update':
76 Post::schedule_post_activity( 'publish', 'publish', $post );
77 WP_CLI::success( '"Update" activity is queued.' );
78 break;
79 default:
80 WP_CLI::error( 'Unknown action.' );
81 }
82 }
83
84 /**
85 * Delete or Update a Comment.
86 *
87 * ## OPTIONS
88 *
89 * <action>
90 * : The action to perform. Either `delete` or `update`.
91 * ---
92 * options:
93 * - delete
94 * - update
95 * ---
96 *
97 * <id>
98 * : The id of the Comment.
99 *
100 * ## EXAMPLES
101 *
102 * $ wp activitypub comment delete 1
103 *
104 * @synopsis <action> <id>
105 *
106 * @param array $args The arguments.
107 */
108 public function comment( $args ) {
109 $comment = get_comment( $args[1] );
110
111 if ( ! $comment ) {
112 WP_CLI::error( 'Comment not found.' );
113 }
114
115 if ( was_comment_received( $comment ) ) {
116 WP_CLI::error( 'This comment was received via ActivityPub and cannot be deleted or updated.' );
117 }
118
119 switch ( $args[0] ) {
120 case 'delete':
121 WP_CLI::confirm( 'Do you really want to delete the Comment with the ID: ' . $args[1] );
122 Comment::schedule_comment_activity( 'trash', 'approved', $comment );
123 WP_CLI::success( '"Delete" activity is queued.' );
124 break;
125 case 'update':
126 Comment::schedule_comment_activity( 'approved', 'approved', $comment );
127 WP_CLI::success( '"Update" activity is queued.' );
128 break;
129 default:
130 WP_CLI::error( 'Unknown action.' );
131 }
132 }
133 }
134