PluginProbe
ActivityPub / 4.2.0
ActivityPub v4.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 4.2.0, at includes/class-cli.php

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