| 1 |
<?php |
| 2 |
/** |
| 3 |
* Follow CLI Command. |
| 4 |
* |
| 5 |
* @package Activitypub |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace Activitypub\Cli; |
| 9 |
|
| 10 |
use function Activitypub\follow; |
| 11 |
|
| 12 |
/** |
| 13 |
* Follow a remote ActivityPub user. |
| 14 |
* |
| 15 |
* @package Activitypub |
| 16 |
*/ |
| 17 |
class Follow_Command extends \WP_CLI_Command { |
| 18 |
|
| 19 |
/** |
| 20 |
* Follow a remote user. |
| 21 |
* |
| 22 |
* Sends a Follow activity to subscribe to a remote ActivityPub user. |
| 23 |
* Use --user flag to specify which local user should follow. |
| 24 |
* |
| 25 |
* ## OPTIONS |
| 26 |
* |
| 27 |
* <remote_user> |
| 28 |
* : The remote user to follow (URL or @user@domain format). |
| 29 |
* |
| 30 |
* ## EXAMPLES |
| 31 |
* |
| 32 |
* # Follow a remote user |
| 33 |
* $ wp activitypub follow https://example.com/@user |
| 34 |
* |
| 35 |
* # Follow as a specific local user |
| 36 |
* $ wp --user=pfefferle activitypub follow https://example.com/@user |
| 37 |
* |
| 38 |
* @param array $args The positional arguments. |
| 39 |
* @param array $assoc_args The associative arguments (unused). |
| 40 |
*/ |
| 41 |
public function __invoke( $args, $assoc_args ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
| 42 |
$user_id = \get_current_user_id(); |
| 43 |
$follow_result = follow( $args[0], $user_id ); |
| 44 |
|
| 45 |
if ( \is_wp_error( $follow_result ) ) { |
| 46 |
\WP_CLI::error( $follow_result->get_error_message() ); |
| 47 |
} else { |
| 48 |
\WP_CLI::success( 'Follow Scheduled.' ); |
| 49 |
} |
| 50 |
} |
| 51 |
} |
| 52 |
|