diff --git a/activitypub.php b/activitypub.php index 1645a484e..0e620ca41 100644 --- a/activitypub.php +++ b/activitypub.php @@ -22,7 +22,7 @@ require_once __DIR__ . '/includes/compat.php'; require_once __DIR__ . '/includes/functions.php'; -\define( 'ACTIVITYPUB_PLUGIN_VERSION', '3.3.3' ); +\define( 'ACTIVITYPUB_PLUGIN_VERSION', '4.0.0' ); /** * Initialize the plugin constants. @@ -46,6 +46,11 @@ \defined( 'ACTIVITYPUB_SEND_VARY_HEADER' ) || \define( 'ACTIVITYPUB_SEND_VARY_HEADER', false ); \defined( 'ACTIVITYPUB_DEFAULT_OBJECT_TYPE' ) || \define( 'ACTIVITYPUB_DEFAULT_OBJECT_TYPE', 'note' ); +// Define Actor-Modes for the plugin. +\define( 'ACTIVITYPUB_ACTOR_MODE', 'actor' ); +\define( 'ACTIVITYPUB_BLOG_MODE', 'blog' ); +\define( 'ACTIVITYPUB_ACTOR_AND_BLOG_MODE', 'actor_blog' ); + // Post visibility constants. \define( 'ACTIVITYPUB_CONTENT_VISIBILITY_PUBLIC', '' ); \define( 'ACTIVITYPUB_CONTENT_VISIBILITY_QUIET_PUBLIC', 'quiet_public' ); diff --git a/includes/class-admin.php b/includes/class-admin.php index 5745b3cab..6fec55eb0 100644 --- a/includes/class-admin.php +++ b/includes/class-admin.php @@ -269,22 +269,14 @@ public static function register_settings() { ); \register_setting( 'activitypub', - 'activitypub_enable_users', + 'activitypub_actor_mode', array( - 'type' => 'boolean', - 'description' => \__( 'Every Author on this Blog (with the publish_posts capability) gets his own ActivityPub enabled Profile.', 'activitypub' ), + 'type' => 'integer', + 'description' => \__( 'Choose your preferred Actor-Mode.', 'activitypub' ), 'default' => '1', ) ); - \register_setting( - 'activitypub', - 'activitypub_enable_blog_user', - array( - 'type' => 'boolean', - 'description' => \__( 'Your Blog becomes an ActivityPub compatible Profile.', 'activitypub' ), - 'default' => '0', - ) - ); + \register_setting( 'activitypub', 'activitypub_attribution_domains', diff --git a/includes/class-migration.php b/includes/class-migration.php index ca4353fdf..8e1e78c58 100644 --- a/includes/class-migration.php +++ b/includes/class-migration.php @@ -87,7 +87,7 @@ public static function is_locked() { * @return bool True if the database structure is up to date, false otherwise. */ public static function is_latest_version() { - return (bool) version_compare( + return (bool) \version_compare( self::get_version(), self::get_target_version(), '==' @@ -120,23 +120,34 @@ public static function maybe_migrate() { if ( ! \wp_next_scheduled( 'activitypub_migrate', $version_from_db ) ) { \wp_schedule_single_event( \time(), 'activitypub_migrate', array( $version_from_db ) ); } - if ( version_compare( $version_from_db, '0.17.0', '<' ) ) { + if ( \version_compare( $version_from_db, '0.17.0', '<' ) ) { self::migrate_from_0_16(); } - if ( version_compare( $version_from_db, '1.3.0', '<' ) ) { + if ( \version_compare( $version_from_db, '1.3.0', '<' ) ) { self::migrate_from_1_2_0(); } - if ( version_compare( $version_from_db, '2.1.0', '<' ) ) { + if ( \version_compare( $version_from_db, '2.1.0', '<' ) ) { self::migrate_from_2_0_0(); } - if ( version_compare( $version_from_db, '2.3.0', '<' ) ) { + if ( \version_compare( $version_from_db, '2.3.0', '<' ) ) { self::migrate_from_2_2_0(); } - if ( version_compare( $version_from_db, '3.0.0', '<' ) ) { + if ( \version_compare( $version_from_db, '3.0.0', '<' ) ) { self::migrate_from_2_6_0(); } + if ( \version_compare( $version_from_db, '4.0.0', '<' ) ) { + self::migrate_to_4_0_0(); + } + + /** + * Fires when the system has to be migrated. + * + * @param string $version_from_db The version from which to migrate. + * @param string $target_version The target version to migrate to. + */ + \do_action( 'activitypub_migrate', $version_from_db, self::get_target_version() ); - update_option( 'activitypub_db_version', self::get_target_version() ); + \update_option( 'activitypub_db_version', self::get_target_version() ); self::unlock(); } @@ -147,7 +158,7 @@ public static function maybe_migrate() { * @param string $version_from_db The version from which to migrate. */ public static function async_migration( $version_from_db ) { - if ( version_compare( $version_from_db, '1.0.0', '<' ) ) { + if ( \version_compare( $version_from_db, '1.0.0', '<' ) ) { self::migrate_from_0_17(); } } @@ -262,6 +273,13 @@ private static function migrate_from_2_6_0() { self::update_options_key( 'activitypub_blog_user_identifier', 'activitypub_blog_identifier' ); } + /** + * Update actor-mode settings. + */ + private static function migrate_to_4_0_0() { + self::migrate_actor_mode(); + } + /** * Set the defaults needed for the plugin to work. * @@ -323,4 +341,29 @@ private static function update_options_key( $old_key, $new_key ) { array( '%s' ) ); } + + /** + * Migrate the actor mode settings. + */ + public static function migrate_actor_mode() { + $blog_profile = \get_option( 'activitypub_enable_blog_user', '0' ); + $author_profiles = \get_option( 'activitypub_enable_users', '0' ); + + if ( + '1' === $blog_profile && + '1' === $author_profiles + ) { + \update_option( 'activitypub_actor_mode', ACTIVITYPUB_ACTOR_AND_BLOG_MODE ); + } elseif ( + '1' === $blog_profile && + '1' !== $author_profiles + ) { + \update_option( 'activitypub_actor_mode', ACTIVITYPUB_BLOG_MODE ); + } elseif ( + '1' !== $blog_profile && + '1' === $author_profiles + ) { + \update_option( 'activitypub_actor_mode', ACTIVITYPUB_ACTOR_MODE ); + } + } } diff --git a/includes/functions.php b/includes/functions.php index 7ff5caabb..095abb041 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -504,7 +504,7 @@ function is_user_type_disabled( $type ) { break; } - if ( '1' !== \get_option( 'activitypub_enable_blog_user', '0' ) ) { + if ( ACTIVITYPUB_ACTOR_MODE === \get_option( 'activitypub_actor_mode', ACTIVITYPUB_ACTOR_MODE ) ) { $disabled = true; break; } @@ -524,7 +524,7 @@ function is_user_type_disabled( $type ) { break; } - if ( '1' !== \get_option( 'activitypub_enable_users', '1' ) ) { + if ( ACTIVITYPUB_BLOG_MODE === \get_option( 'activitypub_actor_mode', ACTIVITYPUB_ACTOR_MODE ) ) { $disabled = true; break; } diff --git a/templates/settings.php b/templates/settings.php index 8716b33c8..2df41f288 100644 --- a/templates/settings.php +++ b/templates/settings.php @@ -29,8 +29,8 @@

@@ -41,12 +41,21 @@

- + +

+

+ +

+

+

diff --git a/tests/test-class-activitypub-migrate.php b/tests/test-class-activitypub-migrate.php new file mode 100644 index 000000000..01ead3270 --- /dev/null +++ b/tests/test-class-activitypub-migrate.php @@ -0,0 +1,51 @@ +assertEquals( ACTIVITYPUB_ACTOR_MODE, \get_option( 'activitypub_actor_mode', ACTIVITYPUB_ACTOR_MODE ) ); + + \update_option( 'activitypub_enable_blog_user', '0' ); + \update_option( 'activitypub_enable_users', '1' ); + \delete_option( 'activitypub_actor_mode' ); + + \Activitypub\Migration::migrate_actor_mode(); + + $this->assertEquals( ACTIVITYPUB_ACTOR_MODE, \get_option( 'activitypub_actor_mode', ACTIVITYPUB_ACTOR_MODE ) ); + + \update_option( 'activitypub_enable_blog_user', '1' ); + \update_option( 'activitypub_enable_users', '1' ); + \delete_option( 'activitypub_actor_mode' ); + + \Activitypub\Migration::migrate_actor_mode(); + + $this->assertEquals( ACTIVITYPUB_ACTOR_AND_BLOG_MODE, \get_option( 'activitypub_actor_mode', ACTIVITYPUB_ACTOR_MODE ) ); + + \update_option( 'activitypub_enable_blog_user', '1' ); + \update_option( 'activitypub_enable_users', '0' ); + \delete_option( 'activitypub_actor_mode' ); + + \Activitypub\Migration::migrate_actor_mode(); + + $this->assertEquals( ACTIVITYPUB_BLOG_MODE, \get_option( 'activitypub_actor_mode', ACTIVITYPUB_ACTOR_MODE ) ); + + \delete_option( 'activitypub_enable_blog_user' ); + \update_option( 'activitypub_enable_users', '0' ); + \delete_option( 'activitypub_actor_mode' ); + + \Activitypub\Migration::migrate_actor_mode(); + + $this->assertEquals( ACTIVITYPUB_ACTOR_MODE, \get_option( 'activitypub_actor_mode', ACTIVITYPUB_ACTOR_MODE ) ); + + \update_option( 'activitypub_enable_blog_user', '0' ); + \delete_option( 'activitypub_enable_users' ); + \delete_option( 'activitypub_actor_mode' ); + + \Activitypub\Migration::migrate_actor_mode(); + + $this->assertEquals( ACTIVITYPUB_ACTOR_MODE, \get_option( 'activitypub_actor_mode', ACTIVITYPUB_ACTOR_MODE ) ); + } +}