Skip to content

Feature/better diff#59

Merged
erseco merged 2 commits intomainfrom
feature/better-diff
Nov 28, 2025
Merged

Feature/better diff#59
erseco merged 2 commits intomainfrom
feature/better-diff

Conversation

@erseco
Copy link
Copy Markdown
Collaborator

@erseco erseco commented Nov 28, 2025

This pull request introduces a new enhancement for the WordPress revisions comparison screen in the Documentate plugin. The main goal is to improve the readability of revision diffs for custom document types by replacing raw HTML comment markers with styled, human-readable field section headers and separators. The implementation includes new PHP logic for asset loading and label mapping, a dedicated CSS file for visual styling, and a JavaScript module for dynamic content transformation.

Revision Diff View Enhancement

  • Added the enqueue_revisions_assets method to class-documentate-admin.php, which conditionally loads new CSS and JavaScript assets for the revision and document edit screens, and passes field label data to the frontend. Also includes helper methods to retrieve field labels from the document type schema.
  • Registered the new asset enqueueing method in the plugin admin hooks, ensuring the enhancement is activated on relevant admin pages.

Frontend Styling and Functionality

  • Introduced documentate-revisions.css to provide visually distinct section headers, separators, and improved diff highlighting for added/removed content, with support for dark mode, high contrast, and responsive layouts.
  • Added documentate-revisions.js, which scans revision diff tables for custom field markers, replaces them with styled headers and separators, and updates dynamically as users interact with the revision slider or page controls.

@erseco erseco self-assigned this Nov 28, 2025
@erseco erseco added the enhancement New feature or request label Nov 28, 2025
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

Comment on lines +402 to +461
public function enqueue_revisions_assets( $hook_suffix ) {
// Check if we're on the revision screen or document edit screen.
if ( 'revision.php' !== $hook_suffix && 'post.php' !== $hook_suffix ) {
return;
}

// On post.php, only load for our post type.
if ( 'post.php' === $hook_suffix ) {
$screen = get_current_screen();
if ( ! $screen || 'documentate_document' !== $screen->post_type ) {
return;
}
}

// For revision.php, check if it's a revision of our post type.
if ( 'revision.php' === $hook_suffix ) {
$revision_id = isset( $_GET['revision'] ) ? intval( $_GET['revision'] ) : 0;
if ( $revision_id > 0 ) {
$revision = wp_get_post_revision( $revision_id );
if ( $revision ) {
$parent = get_post( $revision->post_parent );
if ( ! $parent || 'documentate_document' !== $parent->post_type ) {
return;
}
}
}
}

// Enqueue CSS (dashicons dependency for icons).
wp_enqueue_style(
'documentate-revisions',
plugin_dir_url( __FILE__ ) . 'css/documentate-revisions.css',
array( 'dashicons' ),
$this->version
);

// Enqueue JavaScript.
wp_enqueue_script(
'documentate-revisions',
plugin_dir_url( __FILE__ ) . 'js/documentate-revisions.js',
array(),
$this->version,
true
);

// Get field labels for the current document type.
$field_labels = $this->get_revision_field_labels();

// Pass data to JavaScript.
wp_localize_script(
'documentate-revisions',
'documentateRevisions',
array(
'fieldLabels' => $field_labels,
'strings' => array(
'fieldContent' => __( 'Contenido del campo ↓', 'documentate' ),
),
)
);
}

Check warning

Code scanning / PHPMD

Code Size Rules: CyclomaticComplexity Warning

The method enqueue_revisions_assets() has a Cyclomatic Complexity of 12. The configured cyclomatic complexity threshold is 10.
@erseco erseco merged commit 7f45454 into main Nov 28, 2025
4 checks passed
@erseco erseco deleted the feature/better-diff branch November 28, 2025 23:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants