ACF\CLI

JsonCommand::statuspublicACF 6.8

Shows the sync status for ACF items.

Displays how many items are pending sync. Items are considered "pending" when the JSON file is newer than the database entry, or when the item exists in JSON but not in the database.

OPTIONS

[--type=<type>]
Limit to field groups, post types, taxonomies, or options pages. Defaults to all item types (field groups, post types, taxonomies, options pages).
--- options:
  • field-group
  • post-type
  • taxonomy
  • options-page

[--detailed]
Show detailed list of modified items instead of just counts.
[--format=<format>]
Output format.
--- default: table options:
  • table
  • json
  • yaml
  • csv

EXAMPLES

# Check all item types
$ wp acf json status
+---------------+---------+-------+----------------+
| Type          | Pending | Total | Status         |
+---------------+---------+-------+----------------+
| field-group   | 3       | 12    | Sync available |
| post-type     | 0       | 2     | In sync        |
| taxonomy      | 1       | 3     | Sync available |
| options-page  | 0       | 1     | In sync        |
+---------------+---------+-------+----------------+
# Check only field groups
$ wp acf json status --type=field-group
# Show detailed list of pending items
$ wp acf json status --detailed
+-------------------+------------------+---------------+--------+
| Key               | Title            | Type          | Action |
+-------------------+------------------+---------------+--------+
| group_abc123      | Product Fields   | field-group   | Update |
| group_def456      | Homepage         | field-group   | Create |
| taxonomy_ghi789   | Product Category | taxonomy      | Update |
+-------------------+------------------+---------------+--------+
# Output status as JSON for scripts
$ wp acf json status --format=json
[{"Type":"field-group","Pending":3,"Total":12,"Status":"Sync available"}]

Method of the class: JsonCommand{}

No Hooks.

Returns

null. Nothing (null).

Usage

$JsonCommand = new JsonCommand();
$JsonCommand->status( $args, $assoc_args );
$args(array) (required)
Positional arguments.
$assoc_args(array) (required)
Associative arguments.

Changelog

Since 6.8 Introduced.

JsonCommand::status() code ACF 6.8.8

public function status( $args, $assoc_args ) {
	$this->log_command( 'status' );

	$type_filter = get_flag_value( $assoc_args, 'type' );
	$format      = get_flag_value( $assoc_args, 'format', 'table' );
	$detailed    = get_flag_value( $assoc_args, 'detailed', false );
	$post_types  = $this->get_post_types( $type_filter );

	if ( $detailed ) {
		$this->display_detailed_status( $post_types, $format );
		return;
	}

	$rows          = array();
	$total_pending = 0;

	foreach ( $post_types as $post_type ) {
		$syncable       = $this->get_syncable_items( $post_type );
		$all_items      = acf_get_internal_post_type_posts( $post_type );
		$count          = count( $syncable );
		$total_count    = count( $all_items );
		$total_pending += $count;

		$rows[] = array(
			'Type'    => $this->get_type_label( $post_type ),
			'Pending' => $count,
			'Total'   => $total_count,
			'Status'  => $count > 0 ? 'Sync available' : 'In sync',
		);
	}

	format_items( $format, $rows, array( 'Type', 'Pending', 'Total', 'Status' ) );

	if ( 'table' === $format ) {
		if ( $total_pending > 0 ) {
			WP_CLI::log( sprintf( '%d item(s) pending sync. Run `wp acf json sync` to apply changes.', $total_pending ) );
		} else {
			WP_CLI::success( self::MESSAGE_ALREADY_IN_SYNC );
		}
	}
}