| 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 |
* Check the Plugins Meta-Information. |
| 21 |
* |
| 22 |
* ## OPTIONS |
| 23 |
* |
| 24 |
* [--Name] |
| 25 |
* The Plugin Name. |
| 26 |
* |
| 27 |
* [--PluginURI] |
| 28 |
* The Plugin URI. |
| 29 |
* |
| 30 |
* [--Version] |
| 31 |
* The Plugin Version. |
| 32 |
* |
| 33 |
* [--Description] |
| 34 |
* The Plugin Description. |
| 35 |
* |
| 36 |
* [--Author] |
| 37 |
* The Plugin Author. |
| 38 |
* |
| 39 |
* [--AuthorURI] |
| 40 |
* The Plugin Author URI. |
| 41 |
* |
| 42 |
* [--TextDomain] |
| 43 |
* The Plugin Text Domain. |
| 44 |
* |
| 45 |
* [--DomainPath] |
| 46 |
* The Plugin Domain Path. |
| 47 |
* |
| 48 |
* [--Network] |
| 49 |
* The Plugin Network. |
| 50 |
* |
| 51 |
* [--RequiresWP] |
| 52 |
* The Plugin Requires at least. |
| 53 |
* |
| 54 |
* [--RequiresPHP] |
| 55 |
* The Plugin Requires PHP. |
| 56 |
* |
| 57 |
* [--UpdateURI] |
| 58 |
* The Plugin Update URI. |
| 59 |
* |
| 60 |
* See: https://developer.wordpress.org/reference/functions/get_plugin_data/#return |
| 61 |
* |
| 62 |
* ## EXAMPLES |
| 63 |
* |
| 64 |
* $ wp activitypub meta |
| 65 |
* |
| 66 |
* $ wp activitypub meta --Version |
| 67 |
* Version: 1.0.0 |
| 68 |
* |
| 69 |
* @param array|null $args The arguments. |
| 70 |
* @param array|null $assoc_args The associative arguments. |
| 71 |
* |
| 72 |
* @return void |
| 73 |
*/ |
| 74 |
public function meta( $args, $assoc_args ) { |
| 75 |
$plugin_data = get_plugin_meta(); |
| 76 |
|
| 77 |
if ( $assoc_args ) { |
| 78 |
$plugin_data = array_intersect_key( $plugin_data, $assoc_args ); |
| 79 |
} else { |
| 80 |
WP_CLI::line( __( "ActivityPub Plugin Meta:\n", 'activitypub' ) ); |
| 81 |
} |
| 82 |
|
| 83 |
foreach ( $plugin_data as $key => $value ) { |
| 84 |
WP_CLI::line( $key . ': ' . $value ); |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* Remove the entire blog from the Fediverse. |
| 90 |
* |
| 91 |
* ## EXAMPLES |
| 92 |
* |
| 93 |
* $ wp activitypub self-destruct |
| 94 |
* |
| 95 |
* @param array|null $args The arguments. |
| 96 |
* @param array|null $assoc_args The associative arguments. |
| 97 |
* |
| 98 |
* @return void |
| 99 |
*/ |
| 100 |
public function self_destruct( $args, $assoc_args ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
| 101 |
WP_CLI::warning( __( 'Self-Destructing is not implemented yet.', 'activitypub' ) ); |
| 102 |
} |
| 103 |
|
| 104 |
/** |
| 105 |
* Delete or Update a Post, Page, Custom Post Type or Attachment. |
| 106 |
* |
| 107 |
* ## OPTIONS |
| 108 |
* |
| 109 |
* <action> |
| 110 |
* : The action to perform. Either `delete` or `update`. |
| 111 |
* --- |
| 112 |
* options: |
| 113 |
* - delete |
| 114 |
* - update |
| 115 |
* --- |
| 116 |
* |
| 117 |
* <id> |
| 118 |
* : The id of the Post, Page, Custom Post Type or Attachment. |
| 119 |
* |
| 120 |
* ## EXAMPLES |
| 121 |
* |
| 122 |
* $ wp activitypub post delete 1 |
| 123 |
* |
| 124 |
* @synopsis <action> <id> |
| 125 |
* |
| 126 |
* @param array|null $args The arguments. |
| 127 |
*/ |
| 128 |
public function post( $args ) { |
| 129 |
$post = get_post( $args[1] ); |
| 130 |
|
| 131 |
if ( ! $post ) { |
| 132 |
WP_CLI::error( __( 'Post not found.', 'activitypub' ) ); |
| 133 |
} |
| 134 |
|
| 135 |
switch ( $args[0] ) { |
| 136 |
case 'delete': |
| 137 |
// translators: %s is the ID of the post. |
| 138 |
WP_CLI::confirm( sprintf( __( 'Do you really want to delete the (Custom) Post with the ID: %s', 'activitypub' ), $args[1] ) ); |
| 139 |
Scheduler::schedule_post_activity( 'trash', 'publish', $args[1] ); |
| 140 |
WP_CLI::success( __( '"Delete"-Activity is queued.', 'activitypub' ) ); |
| 141 |
break; |
| 142 |
case 'update': |
| 143 |
Scheduler::schedule_post_activity( 'publish', 'publish', $args[1] ); |
| 144 |
WP_CLI::success( __( '"Update"-Activity is queued.', 'activitypub' ) ); |
| 145 |
break; |
| 146 |
default: |
| 147 |
WP_CLI::error( __( 'Unknown action.', 'activitypub' ) ); |
| 148 |
} |
| 149 |
} |
| 150 |
|
| 151 |
/** |
| 152 |
* Delete or Update a Comment. |
| 153 |
* |
| 154 |
* ## OPTIONS |
| 155 |
* |
| 156 |
* <action> |
| 157 |
* : The action to perform. Either `delete` or `update`. |
| 158 |
* --- |
| 159 |
* options: |
| 160 |
* - delete |
| 161 |
* - update |
| 162 |
* --- |
| 163 |
* |
| 164 |
* <id> |
| 165 |
* : The id of the Comment. |
| 166 |
* |
| 167 |
* ## EXAMPLES |
| 168 |
* |
| 169 |
* $ wp activitypub comment delete 1 |
| 170 |
* |
| 171 |
* @synopsis <action> <id> |
| 172 |
* |
| 173 |
* @param array|null $args The arguments. |
| 174 |
*/ |
| 175 |
public function comment( $args ) { |
| 176 |
$comment = get_comment( $args[1] ); |
| 177 |
|
| 178 |
if ( ! $comment ) { |
| 179 |
WP_CLI::error( __( 'Comment not found.', 'activitypub' ) ); |
| 180 |
} |
| 181 |
|
| 182 |
if ( was_comment_received( $comment ) ) { |
| 183 |
WP_CLI::error( __( 'This comment was received via ActivityPub and cannot be deleted or updated.', 'activitypub' ) ); |
| 184 |
} |
| 185 |
|
| 186 |
switch ( $args[0] ) { |
| 187 |
case 'delete': |
| 188 |
// translators: %s is the ID of the comment. |
| 189 |
WP_CLI::confirm( sprintf( __( 'Do you really want to delete the Comment with the ID: %s', 'activitypub' ), $args[1] ) ); |
| 190 |
Scheduler::schedule_comment_activity( 'trash', 'approved', $args[1] ); |
| 191 |
WP_CLI::success( __( '"Delete"-Activity is queued.', 'activitypub' ) ); |
| 192 |
break; |
| 193 |
case 'update': |
| 194 |
Scheduler::schedule_comment_activity( 'approved', 'approved', $args[1] ); |
| 195 |
WP_CLI::success( __( '"Update"-Activity is queued.', 'activitypub' ) ); |
| 196 |
break; |
| 197 |
default: |
| 198 |
WP_CLI::error( __( 'Unknown action.', 'activitypub' ) ); |
| 199 |
} |
| 200 |
} |
| 201 |
} |
| 202 |
|