'ID' ) ) as $user_id ) { $followers = get_user_meta( $user_id, 'activitypub_followers', true ); if ( $followers ) { foreach ( $followers as $actor ) { Followers::add_follower( $user_id, $actor ); } } } Activitypub::flush_rewrite_rules(); } /** * Clear the cache after updating to 1.3.0. */ private static function migrate_from_1_2_0() { $user_ids = \get_users( array( 'fields' => 'ID', 'capability__in' => array( 'publish_posts' ), ) ); foreach ( $user_ids as $user_id ) { wp_cache_delete( sprintf( Followers::CACHE_KEY_INBOXES, $user_id ), 'activitypub' ); } } /** * Unschedule Hooks after updating to 2.0.0. */ private static function migrate_from_2_0_0() { wp_clear_scheduled_hook( 'activitypub_send_post_activity' ); wp_clear_scheduled_hook( 'activitypub_send_update_activity' ); wp_clear_scheduled_hook( 'activitypub_send_delete_activity' ); wp_unschedule_hook( 'activitypub_send_post_activity' ); wp_unschedule_hook( 'activitypub_send_update_activity' ); wp_unschedule_hook( 'activitypub_send_delete_activity' ); $object_type = \get_option( 'activitypub_object_type', ACTIVITYPUB_DEFAULT_OBJECT_TYPE ); if ( 'article' === $object_type ) { \update_option( 'activitypub_object_type', 'wordpress-post-format' ); } } /** * Add the ActivityPub capability to all users that can publish posts * Delete old meta to store followers. */ private static function migrate_from_2_2_0() { // Add the ActivityPub capability to all users that can publish posts. self::add_activitypub_capability(); } /** * Rename DB fields. */ private static function migrate_from_2_6_0() { wp_cache_flush(); self::update_usermeta_key( 'activitypub_user_description', 'activitypub_description' ); self::update_options_key( 'activitypub_blog_user_description', 'activitypub_blog_description' ); self::update_options_key( 'activitypub_blog_user_identifier', 'activitypub_blog_identifier' ); } /** * * Update actor-mode settings. * * Get the ID of the latest blog post and save it to the options table. */ private static function migrate_to_4_0_0() { $latest_post_id = 0; // Get the ID of the latest blog post and save it to the options table. $latest_post = get_posts( array( 'numberposts' => 1, 'orderby' => 'ID', 'order' => 'DESC', 'post_type' => 'any', 'post_status' => 'publish', ) ); if ( $latest_post ) { $latest_post_id = $latest_post[0]->ID; } \update_option( 'activitypub_last_post_with_permalink_as_id', $latest_post_id ); $users = \get_users( array( 'capability__in' => array( 'activitypub' ), ) ); foreach ( $users as $user ) { $followers = Followers::get_followers( $user->ID ); if ( $followers ) { \update_user_option( $user->ID, 'activitypub_use_permalink_as_id', '1' ); } } $followers = Followers::get_followers( Users::BLOG_USER_ID ); if ( $followers ) { \update_option( 'activitypub_use_permalink_as_id_for_blog', '1' ); } self::migrate_actor_mode(); } /** * Set the defaults needed for the plugin to work. * * Add the ActivityPub capability to all users that can publish posts. */ public static function add_default_settings() { self::add_activitypub_capability(); } /** * Add the ActivityPub capability to all users that can publish posts. */ private static function add_activitypub_capability() { // Get all WP_User objects that can publish posts. $users = \get_users( array( 'capability__in' => array( 'publish_posts' ), ) ); // Add ActivityPub capability to all users that can publish posts. foreach ( $users as $user ) { $user->add_cap( 'activitypub' ); } } /** * Rename meta keys. * * @param string $old_key The old comment meta key. * @param string $new_key The new comment meta key. */ private static function update_usermeta_key( $old_key, $new_key ) { global $wpdb; $wpdb->update( // phpcs:ignore WordPress.DB.DirectDatabaseQuery $wpdb->usermeta, array( 'meta_key' => $new_key ), // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key array( 'meta_key' => $old_key ), // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key array( '%s' ), array( '%s' ) ); } /** * Rename option keys. * * @param string $old_key The old option key. * @param string $new_key The new option key. */ private static function update_options_key( $old_key, $new_key ) { global $wpdb; $wpdb->update( // phpcs:ignore WordPress.DB.DirectDatabaseQuery $wpdb->options, array( 'option_name' => $new_key ), // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key array( 'option_name' => $old_key ), // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key array( '%s' ), 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', '1' ); 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 ); } } }