Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/changelog/fix-3332-migration-cpt-order
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Fixed a PHP notice that could appear when ActivityPub migration ran before custom post types were registered.
2 changes: 1 addition & 1 deletion includes/class-migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Migration {
* Initialize the class, registering WordPress hooks.
*/
public static function init() {
self::maybe_migrate();
\add_action( 'init', array( self::class, 'maybe_migrate' ), 20 );

Scheduler::register_async_batch_callback( 'activitypub_migrate_from_0_17', array( self::class, 'migrate_from_0_17' ) );
Scheduler::register_async_batch_callback( 'activitypub_update_comment_counts', array( self::class, 'update_comment_counts' ) );
Expand Down
13 changes: 13 additions & 0 deletions tests/phpunit/tests/includes/class-test-migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,19 @@ public function mock_webfinger() {
);
}

/**
* Test migration is deferred until post types are registered.
*/
public function test_init_defers_migration_until_after_post_types() {
\remove_action( 'init', array( Migration::class, 'maybe_migrate' ), 20 );
$this->setExpectedIncorrectUsage( 'Activitypub\\Scheduler::register_async_batch_callback' );

Migration::init();

$this->assertSame( 20, \has_action( 'init', array( Migration::class, 'maybe_migrate' ) ) );
\remove_action( 'init', array( Migration::class, 'maybe_migrate' ), 20 );
}

/**
* Test add_default_extra_field.
*/
Expand Down