Skip to content
StaticScope
Overview
Get StaticScope

Sync hooks

All 15 hooks in the Content Sync add-on, with signatures, firing points and examples.

Developers Updated 21 November 2026 6 min read

Content Sync owns 15 hooks: 14 filters and one action. They cover the pieces the add-on cannot model for you: a custom field, an extra image reference, a host that is no longer live, a different place to store the ledger.

All of them use the staticscope_sync_ prefix. File paths in this reference are relative to wp-content/plugins/staticscope-addon-sync/.

What Sync does with core hooks

Sync does not fire any core hooks of its own. It listens to five:

Core hookWhat Sync does
staticscope_addonsRegisters itself as a sync add-on.
staticscope_before_build at 10Runs the preflight pull before a build. A publish-bound build stops on error; a preview carries on with a warning.
staticscope_before_publish at 10Runs the same check before an existing build is published.
staticscope_publish_blocked_reason at 10, 2 argsReturns a sentence when the build predates the last successful sync.
staticscope_menu_after_publishOrders the Sync screen next to Publish site.

Setup and storage

staticscope_sync_hosts

Filters the host tabs on the Sync setup screen. Each entry has label, short, create_url, token_url, username, clone, notes and steps. Empty create_url or token_url hides that button. Use it when your team runs Gitea, Forgejo or an internal Git service.

add_filter( 'staticscope_sync_hosts', function ( array $hosts ) {
	$hosts['gitea'] = [
		'label'      => 'Gitea',
		'short'      => 'Self-hosted Git.',
		'create_url' => 'https://git.example.com/repo/create',
		'token_url'  => 'https://git.example.com/user/settings/applications',
		'username'   => 'oauth2',
		'clone'      => 'https://git.example.com/OWNER/REPO.git',
		'notes'      => [ 'Make the repository private.' ],
		'steps'      => [ 'Create a token with repository write access.' ],
	];

	return $hosts;
} );

staticscope_sync_ledger

Filters the ledger an engine is built with. It receives the current ledger and all saved add-on settings. Return an object implementing StaticScopeSync\Sync\Ledger, which means snapshot(), push(), media() and pushMedia(). Use it to keep documents in object storage instead of a Git branch.

add_filter( 'staticscope_sync_ledger', function ( $ledger, array $settings ) {
	return new My_Object_Store_Ledger( $settings );
}, 10, 2 );

staticscope_sync_preflight

Filters whether a build pulls first. Default true. It runs inside Sync’s staticscope_before_build listener, so returning false skips the pull but the build still runs. Use it on a solo site or for an offline build.

add_filter( 'staticscope_sync_preflight', '__return_false' );

Documents

staticscope_sync_exported_document

Filters a post or page as it is written to the ledger, with the WP_Post as the second argument. Unknown keys are preserved, merged and synced, so this is the supported way to carry a custom field to every site.

add_filter( 'staticscope_sync_exported_document', function ( array $doc, WP_Post $post ) {
	$doc['reading_time'] = (int) get_post_meta( $post->ID, 'reading_time', true );

	return $doc;
}, 10, 2 );

staticscope_sync_imported_document

Filters a document after validation and before it is applied here. Read the field you exported and save it. The importer runs this before it writes the post, so a lookup by document ID finds the existing post when there is one.

add_filter( 'staticscope_sync_imported_document', function ( array $doc ) {
	if ( ! isset( $doc['reading_time'], $doc['id'] ) ) {
		return $doc;
	}

	$post_id = \StaticScopeSync\Content\Importer::find( (string) $doc['id'] );

	if ( $post_id > 0 ) {
		update_post_meta( $post_id, 'reading_time', (int) $doc['reading_time'] );
	}

	return $doc;
} );

On a first import there is no post to update yet. The export filter adds the field to the ledger on the next push, so the value settles after one round trip.

staticscope_sync_fallback_author

Filters the local user a post belongs to when its author has no account here. It receives a fallback ID and the document author. The document keeps the author either way; this only controls who can edit the post. The default is the person syncing, or the first administrator for a background sync.

add_filter( 'staticscope_sync_fallback_author', function ( int $fallback, array $author ) {
	$user = get_user_by( 'login', 'editor' );

	return $user instanceof WP_User ? (int) $user->ID : $fallback;
}, 10, 2 );

staticscope_sync_internal_hosts

Filters the hosts treated as this site when post links become portable references. Add hosts without a scheme or path. The current home and site hosts are always included, so you only add history or variants.

add_filter( 'staticscope_sync_internal_hosts', function ( array $hosts ) {
	$hosts[] = 'old.example.com';
	$hosts[] = 'www.example.com';

	return $hosts;
} );

Media

staticscope_sync_media_max_bytes

Filters the per-file limit, in bytes. Default 26214400, which is 25 MB. Larger files stay local and are counted as skipped_media. Raise it when your PDFs and video posters are bigger than that, and remember the repository or object store has to hold them.

add_filter( 'staticscope_sync_media_max_bytes', function () {
	return 50 * 1024 * 1024;
} );

staticscope_sync_attachment_record

Filters each attachment record as it is written to the ledger, with the attachment ID as the second argument. Add metadata that should travel with the file, such as a credit or a licence.

add_filter( 'staticscope_sync_attachment_record', function ( array $record, int $id ) {
	$record['credit'] = (string) get_post_meta( $id, 'credit', true );

	return $record;
}, 10, 2 );

staticscope_sync_post_attachments

Filters the attachment IDs a post uses, with the post as the second argument. Add IDs stored by a plugin in a way Sync does not recognise, such as a hero image in post meta.

add_filter( 'staticscope_sync_post_attachments', function ( array $ids, WP_Post $post ) {
	$hero = (int) get_post_meta( $post->ID, 'hero_image', true );

	if ( $hero > 0 ) {
		$ids[] = $hero;
	}

	return $ids;
}, 10, 2 );

Environment and collaboration

staticscope_sync_environment

Filters this site’s fingerprint before it is written and compared with other sites. It already contains theme file hashes, plugins, permalinks, post types, updated_by and updated_at. Add your own signal, such as a theme build number.

add_filter( 'staticscope_sync_environment', function ( array $environment ) {
	$environment['build'] = (string) get_option( 'my_theme_build', '' );

	return $environment;
} );

staticscope_sync_theme_manifest

Filters a theme folder’s hash map, which is relative path to short SHA-256. The scanned directory is the second argument. Use it to ignore generated files so a build stamp does not look like a theme change.

add_filter( 'staticscope_sync_theme_manifest', function ( array $files ) {
	unset( $files['assets/generated.css'] );

	return $files;
} );

staticscope_sync_collaboration_items

Filters the “Worth a conversation” list. It receives the items, this site’s fingerprint and every other site’s. Copy the shape of an existing item so the screen can render yours. An item without an id is skipped, and a dismissed item comes back when its value changes.

add_filter( 'staticscope_sync_collaboration_items', function ( array $items, array $ours, array $others ) {
	foreach ( $others as $other ) {
		if ( ( $other['build'] ?? '' ) === ( $ours['build'] ?? '' ) ) {
			continue;
		}

		$items[] = [
			'id'       => 'build:' . ( $other['site'] ?? '' ),
			'value'    => (string) ( $other['build'] ?? '' ),
			'title'    => 'The theme builds differ',
			'summary'  => 'One site is running an older build of the theme.',
			'severity' => 'medium',
		];
	}

	return $items;
}, 10, 3 );

staticscope_sync_commit_message

Filters the message used when content is pushed. The second argument is the site name and the third is the documents being pushed. Make the message useful in git log; “Sync from Example” repeated forty times is not.

add_filter( 'staticscope_sync_commit_message', function ( string $message, string $site ) {
	return $message . ' [' . $site . ']';
}, 10, 2 );

Results

staticscope_sync_finished

Fires after every successful sync: REST requests, the cron run, the build preflight and conflict resolution. The result array has pulled, pushed, deleted, conflicts, commit, pushed_at_all and skipped_media. It does not fire on failure, so do not use it as a failure alert.

add_action( 'staticscope_sync_finished', function ( array $result ) {
	if ( $result['conflicts'] > 0 ) {
		wp_mail( 'editors@example.com', 'Sync conflicts', 'Someone needs to resolve them.' );
	}
}, 10, 1 );

Next