updated plugin ActivityPub
version 5.8.0
This commit is contained in:
@ -7,83 +7,14 @@
|
||||
|
||||
namespace Activitypub;
|
||||
|
||||
use WP_CLI;
|
||||
use WP_CLI_Command;
|
||||
use Activitypub\Collection\Outbox;
|
||||
|
||||
/**
|
||||
* WP-CLI commands.
|
||||
*
|
||||
* @package Activitypub
|
||||
*/
|
||||
class Cli extends WP_CLI_Command {
|
||||
/**
|
||||
* Check the Plugins Meta-Information.
|
||||
*
|
||||
* ## OPTIONS
|
||||
*
|
||||
* [--Name]
|
||||
* The Plugin Name.
|
||||
*
|
||||
* [--PluginURI]
|
||||
* The Plugin URI.
|
||||
*
|
||||
* [--Version]
|
||||
* The Plugin Version.
|
||||
*
|
||||
* [--Description]
|
||||
* The Plugin Description.
|
||||
*
|
||||
* [--Author]
|
||||
* The Plugin Author.
|
||||
*
|
||||
* [--AuthorURI]
|
||||
* The Plugin Author URI.
|
||||
*
|
||||
* [--TextDomain]
|
||||
* The Plugin Text Domain.
|
||||
*
|
||||
* [--DomainPath]
|
||||
* The Plugin Domain Path.
|
||||
*
|
||||
* [--Network]
|
||||
* The Plugin Network.
|
||||
*
|
||||
* [--RequiresWP]
|
||||
* The Plugin Requires at least.
|
||||
*
|
||||
* [--RequiresPHP]
|
||||
* The Plugin Requires PHP.
|
||||
*
|
||||
* [--UpdateURI]
|
||||
* The Plugin Update URI.
|
||||
*
|
||||
* See: https://developer.wordpress.org/reference/functions/get_plugin_data/#return
|
||||
*
|
||||
* ## EXAMPLES
|
||||
*
|
||||
* $ wp webmention meta
|
||||
*
|
||||
* $ wp webmention meta --Version
|
||||
* Version: 1.0.0
|
||||
*
|
||||
* @param array|null $args The arguments.
|
||||
* @param array|null $assoc_args The associative arguments.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function meta( $args, $assoc_args ) {
|
||||
$plugin_data = get_plugin_meta();
|
||||
|
||||
if ( $assoc_args ) {
|
||||
$plugin_data = array_intersect_key( $plugin_data, $assoc_args );
|
||||
} else {
|
||||
WP_CLI::line( __( "ActivityPub Plugin Meta:\n", 'activitypub' ) );
|
||||
}
|
||||
|
||||
foreach ( $plugin_data as $key => $value ) {
|
||||
WP_CLI::line( $key . ': ' . $value );
|
||||
}
|
||||
}
|
||||
class Cli extends \WP_CLI_Command {
|
||||
|
||||
/**
|
||||
* Remove the entire blog from the Fediverse.
|
||||
@ -98,7 +29,7 @@ class Cli extends WP_CLI_Command {
|
||||
* @return void
|
||||
*/
|
||||
public function self_destruct( $args, $assoc_args ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
|
||||
WP_CLI::warning( __( 'Self-Destructing is not implemented yet.', 'activitypub' ) );
|
||||
\WP_CLI::warning( 'Self-Destructing is not implemented yet.' );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -123,28 +54,27 @@ class Cli extends WP_CLI_Command {
|
||||
*
|
||||
* @synopsis <action> <id>
|
||||
*
|
||||
* @param array|null $args The arguments.
|
||||
* @param array $args The arguments.
|
||||
*/
|
||||
public function post( $args ) {
|
||||
$post = get_post( $args[1] );
|
||||
|
||||
if ( ! $post ) {
|
||||
WP_CLI::error( __( 'Post not found.', 'activitypub' ) );
|
||||
\WP_CLI::error( 'Post not found.' );
|
||||
}
|
||||
|
||||
switch ( $args[0] ) {
|
||||
case 'delete':
|
||||
// translators: %s is the ID of the post.
|
||||
WP_CLI::confirm( sprintf( __( 'Do you really want to delete the (Custom) Post with the ID: %s', 'activitypub' ), $args[1] ) );
|
||||
Scheduler::schedule_post_activity( 'trash', 'publish', $args[1] );
|
||||
WP_CLI::success( __( '"Delete"-Activity is queued.', 'activitypub' ) );
|
||||
\WP_CLI::confirm( 'Do you really want to delete the (Custom) Post with the ID: ' . $args[1] );
|
||||
add_to_outbox( $post, 'Delete', $post->post_author );
|
||||
\WP_CLI::success( '"Delete" activity is queued.' );
|
||||
break;
|
||||
case 'update':
|
||||
Scheduler::schedule_post_activity( 'publish', 'publish', $args[1] );
|
||||
WP_CLI::success( __( '"Update"-Activity is queued.', 'activitypub' ) );
|
||||
add_to_outbox( $post, 'Update', $post->post_author );
|
||||
\WP_CLI::success( '"Update" activity is queued.' );
|
||||
break;
|
||||
default:
|
||||
WP_CLI::error( __( 'Unknown action.', 'activitypub' ) );
|
||||
\WP_CLI::error( 'Unknown action.' );
|
||||
}
|
||||
}
|
||||
|
||||
@ -170,32 +100,131 @@ class Cli extends WP_CLI_Command {
|
||||
*
|
||||
* @synopsis <action> <id>
|
||||
*
|
||||
* @param array|null $args The arguments.
|
||||
* @param array $args The arguments.
|
||||
*/
|
||||
public function comment( $args ) {
|
||||
$comment = get_comment( $args[1] );
|
||||
|
||||
if ( ! $comment ) {
|
||||
WP_CLI::error( __( 'Comment not found.', 'activitypub' ) );
|
||||
\WP_CLI::error( 'Comment not found.' );
|
||||
}
|
||||
|
||||
if ( was_comment_received( $comment ) ) {
|
||||
WP_CLI::error( __( 'This comment was received via ActivityPub and cannot be deleted or updated.', 'activitypub' ) );
|
||||
\WP_CLI::error( 'This comment was received via ActivityPub and cannot be deleted or updated.' );
|
||||
}
|
||||
|
||||
switch ( $args[0] ) {
|
||||
case 'delete':
|
||||
// translators: %s is the ID of the comment.
|
||||
WP_CLI::confirm( sprintf( __( 'Do you really want to delete the Comment with the ID: %s', 'activitypub' ), $args[1] ) );
|
||||
Scheduler::schedule_comment_activity( 'trash', 'approved', $args[1] );
|
||||
WP_CLI::success( __( '"Delete"-Activity is queued.', 'activitypub' ) );
|
||||
\WP_CLI::confirm( 'Do you really want to delete the Comment with the ID: ' . $args[1] );
|
||||
add_to_outbox( $comment, 'Delete', $comment->user_id );
|
||||
\WP_CLI::success( '"Delete" activity is queued.' );
|
||||
break;
|
||||
case 'update':
|
||||
Scheduler::schedule_comment_activity( 'approved', 'approved', $args[1] );
|
||||
WP_CLI::success( __( '"Update"-Activity is queued.', 'activitypub' ) );
|
||||
add_to_outbox( $comment, 'Update', $comment->user_id );
|
||||
\WP_CLI::success( '"Update" activity is queued.' );
|
||||
break;
|
||||
default:
|
||||
WP_CLI::error( __( 'Unknown action.', 'activitypub' ) );
|
||||
\WP_CLI::error( 'Unknown action.' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Undo an activity that was sent to the Fediverse.
|
||||
*
|
||||
* ## OPTIONS
|
||||
*
|
||||
* <outbox_item_id>
|
||||
* The ID or URL of the outbox item to undo.
|
||||
*
|
||||
* ## EXAMPLES
|
||||
*
|
||||
* $ wp activitypub undo 123
|
||||
* $ wp activitypub undo "https://example.com/?post_type=ap_outbox&p=123"
|
||||
*
|
||||
* @synopsis <outbox_item_id>
|
||||
*
|
||||
* @param array $args The arguments.
|
||||
*/
|
||||
public function undo( $args ) {
|
||||
$outbox_item_id = $args[0];
|
||||
if ( ! is_numeric( $outbox_item_id ) ) {
|
||||
$outbox_item_id = url_to_postid( $outbox_item_id );
|
||||
}
|
||||
|
||||
$outbox_item_id = get_post( $outbox_item_id );
|
||||
if ( ! $outbox_item_id ) {
|
||||
\WP_CLI::error( 'Activity not found.' );
|
||||
}
|
||||
|
||||
$undo_id = Outbox::undo( $outbox_item_id );
|
||||
if ( ! $undo_id ) {
|
||||
\WP_CLI::error( 'Failed to undo activity.' );
|
||||
}
|
||||
\WP_CLI::success( 'Undo activity scheduled.' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-Schedule an activity that was sent to the Fediverse before.
|
||||
*
|
||||
* ## OPTIONS
|
||||
*
|
||||
* <outbox_item_id>
|
||||
* The ID or URL of the outbox item to reschedule.
|
||||
*
|
||||
* ## EXAMPLES
|
||||
*
|
||||
* $ wp activitypub reschedule 123
|
||||
* $ wp activitypub reschedule "https://example.com/?post_type=ap_outbox&p=123"
|
||||
*
|
||||
* @synopsis <outbox_item_id>
|
||||
*
|
||||
* @param array $args The arguments.
|
||||
*/
|
||||
public function reschedule( $args ) {
|
||||
$outbox_item_id = $args[0];
|
||||
if ( ! is_numeric( $outbox_item_id ) ) {
|
||||
$outbox_item_id = url_to_postid( $outbox_item_id );
|
||||
}
|
||||
|
||||
$outbox_item_id = get_post( $outbox_item_id );
|
||||
if ( ! $outbox_item_id ) {
|
||||
\WP_CLI::error( 'Activity not found.' );
|
||||
}
|
||||
|
||||
Outbox::reschedule( $outbox_item_id );
|
||||
|
||||
\WP_CLI::success( 'Rescheduled activity.' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the blog to a new URL.
|
||||
*
|
||||
* ## OPTIONS
|
||||
*
|
||||
* <from>
|
||||
* The current URL of the blog.
|
||||
*
|
||||
* <to>
|
||||
* The new URL of the blog.
|
||||
*
|
||||
* ## EXAMPLES
|
||||
*
|
||||
* $ wp activitypub move https://example.com/ https://newsite.com/
|
||||
*
|
||||
* @synopsis <from> <to>
|
||||
*
|
||||
* @param array $args The arguments.
|
||||
*/
|
||||
public function move( $args ) {
|
||||
$from = $args[0];
|
||||
$to = $args[1];
|
||||
|
||||
$outbox_item_id = Move::account( $from, $to );
|
||||
|
||||
if ( is_wp_error( $outbox_item_id ) ) {
|
||||
\WP_CLI::error( $outbox_item_id->get_error_message() );
|
||||
} else {
|
||||
\WP_CLI::success( 'Move Scheduled.' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user