404 ) ); } // Disable filters and load field group directly from database. acf_disable_filters(); $field_group = acf_get_field_group( $id ); if ( ! $field_group ) { return new WP_Error( 'acf_invalid_id', __( 'Invalid field group ID.', 'acf' ), array( 'status' => 404 ) ); } $field_group['fields'] = acf_get_fields( $field_group ); $field_group['modified'] = get_post_modified_time( 'U', true, $field_group['ID'] ); $field_group = acf_prepare_field_group_for_export( $field_group ); // Load local field group file. $files = acf_get_local_json_files(); $key = $field_group['key']; if ( ! isset( $files[ $key ] ) ) { return new WP_Error( 'acf_cannot_compare', __( 'Sorry, this field group is unavailable for diff comparison.', 'acf' ), array( 'status' => 404 ) ); } $local_field_group = json_decode( file_get_contents( $files[ $key ] ), true ); // Render diff HTML. $date_format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' ); $date_template = __( 'Last updated: %s', 'acf' ); $json['html'] = '
' . __( 'Original field group', 'acf' ) . ' ' . sprintf( $date_template, wp_date( $date_format, $field_group['modified'] ) ) . '
' . __( 'JSON field group (newer)', 'acf' ) . ' ' . sprintf( $date_template, wp_date( $date_format, $local_field_group['modified'] ) ) . '
' . wp_text_diff( acf_json_encode( $field_group ), acf_json_encode( $local_field_group ) ) . '
'; return $json; } } acf_new_instance( 'ACF_Ajax_Local_JSON_Diff' ); endif; // class_exists check