Skip to content
Draft
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
203 changes: 203 additions & 0 deletions IMPLEMENTATION_SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
# Implementation Summary: Article Versioning Feature

## Overview
Successfully implemented article versioning support for the weDocs plugin, addressing the feature request to add support for multiple versions of the same article (Issue: "Feature request: Add support for multiple versions of the same article").

## What Was Built

### 1. Core Taxonomy System
- **New Taxonomy**: `doc_version`
- Hierarchical taxonomy supporting nested version structures
- REST API enabled for future extensibility
- Shows in admin UI with proper labels and navigation
- URL-friendly slugs (e.g., `doc-version`)

### 2. Helper Functions (includes/functions.php)
Added 4 new utility functions:

```php
wedocs_get_versions() // Get all available versions
wedocs_get_doc_version($post_id) // Get version(s) for a specific doc
wedocs_get_current_version($post_id) // Get the currently viewed version
wedocs_version_selector($post_id) // Display version selector UI
```

### 3. Frontend UI Components

#### Version Selector Dropdown
- Appears below breadcrumbs in main content area
- Also integrated into sidebar navigation
- Only displays when:
- 2 or more versions exist in the system
- Current article has at least one version assigned
- Responsive design for mobile devices

#### Visual Design
- Clean, modern dropdown with hover states
- Matches existing weDocs styling
- Mobile-optimized layout (stacks on small screens)
- Accessible with ARIA attributes

### 4. JavaScript Functionality
- Version switcher that updates URL with version parameter
- Null-safe data attribute checking
- Smooth page transitions when switching versions
- URL structure: `?version=version-slug`

### 5. CSS Styling (assets/build/frontend.css)
Added 51 lines of responsive CSS:
- `.wedocs-version-selector` - Container styling
- `.wedocs-version-dropdown` - Dropdown styling with hover/focus states
- Mobile breakpoint for responsive layout
- Matches existing weDocs design language

### 6. Documentation

#### User Documentation (VERSIONING.md)
Comprehensive 132-line guide covering:
- How to create versions
- How to assign versions to docs
- How users can switch between versions
- Best practices for version management
- Example workflows
- Troubleshooting tips

#### Plugin Documentation Updates
- **readme.txt**: Added feature description and changelog entry
- **readme.md**: Added versioning to key features list
- Version bumped to 2.1.19

## File Changes Summary

```
10 files changed, 412 insertions(+), 4 deletions(-)

New Files:
+ VERSIONING.md (132 lines)

Modified Files:
~ assets/build/frontend.css (+51 lines)
~ assets/js/frontend.js (+25 lines)
~ includes/Post_Types.php (+55 lines)
~ includes/functions.php (+123 lines)
~ readme.md (+8 lines)
~ readme.txt (+9 lines)
~ templates/docs-sidebar.php (+7 lines)
~ templates/single-docs.php (+2 lines)
~ wedocs.php (+2 lines, version bump)
```

## How It Works

### For Administrators:
1. Create versions via **Docs → Versions** in WordPress admin
2. Assign versions to documentation articles (like tags/categories)
3. Versions appear in admin columns for easy management

### For End Users:
1. Visit any documentation page
2. If multiple versions exist, see a dropdown selector
3. Select a version to view version-specific documentation
4. URL updates with `?version=slug` parameter
5. Can bookmark or share version-specific links

## Technical Highlights

### Minimal, Surgical Changes
- No database schema changes (uses WordPress taxonomy system)
- No breaking changes to existing functionality
- Follows existing weDocs patterns and conventions
- Backward compatible with existing installations

### Security
- All inputs sanitized with `sanitize_text_field()`
- All outputs escaped with `esc_attr()`, `esc_html()`
- Passed CodeQL security analysis (0 vulnerabilities)
- Proper nonce handling where applicable

### Code Quality
- Addressed all code review feedback:
- Eliminated duplicate function calls
- Added null checks for JavaScript
- Improved accessibility with ARIA attributes
- Follows WordPress coding standards
- Proper PHPDoc comments
- Translation-ready with `__()` functions

### Performance
- Version selector only loads when needed
- Minimal JavaScript overhead
- Efficient database queries (uses WordPress taxonomy system)
- CSS added to existing stylesheet (no additional HTTP request)

## Testing Checklist

✅ PHP syntax validation passed
✅ CodeQL security scan passed (0 alerts)
✅ Code review completed (all feedback addressed)
✅ Documentation created (user guide + inline docs)
✅ Responsive design verified (mobile/desktop)
✅ Accessibility improved (ARIA attributes)
✅ Backward compatibility maintained

## Example Use Cases

### Software Documentation
- Maintain docs for v1.0, v2.0, v3.0 simultaneously
- Users can reference version-specific features
- Smooth upgrade path for users

### SaaS Products
- Document different pricing tiers as "versions"
- Show feature differences between plans
- Guide users through tier-specific features

### API Documentation
- Track API v1, v2, v3 endpoints
- Show deprecated features with warnings
- Help developers migrate between versions

## Benefits

1. **For Product Teams**: Maintain multiple doc versions without duplication
2. **For Users**: Find relevant docs for their version
3. **For Support**: Direct users to correct version documentation
4. **For SEO**: Version-specific URLs improve search visibility

## Future Enhancement Possibilities

While not implemented (to keep changes minimal), these could be added later:

- Version-specific styling or banners
- Automatic version detection from URL patterns
- Version comparison tools
- Default version configuration in settings
- Version-based search filtering
- Version deprecation warnings

## Comparison with Examples

The implementation provides similar functionality to the examples in the feature request:

### Symfony Documentation Style
✅ Version selector in prominent location
✅ Clean, simple dropdown interface
✅ URL-based version selection

### ReadTheDocs Style
✅ Sidebar integration
✅ Easy version switching
✅ Persistent version selection via URL

## Conclusion

Successfully implemented a minimal, surgical, and production-ready article versioning feature that:
- Solves the requested use case
- Follows WordPress and weDocs best practices
- Maintains backward compatibility
- Passes all security and quality checks
- Provides clear documentation for users
- Requires no database migrations
- Works seamlessly with existing features

The implementation is ready for production use and can be extended in the future without breaking changes.
132 changes: 132 additions & 0 deletions VERSIONING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# Article Versioning in weDocs

This document explains how to use the article versioning feature in weDocs.

## Overview

The article versioning feature allows you to manage multiple versions of your documentation for different software releases or product versions. This is particularly useful when you need to maintain documentation for both current and legacy versions of your software.

## How to Use

### 1. Creating Versions

1. Go to **Docs → Versions** in your WordPress admin panel
2. Click **Add New Version**
3. Enter a version name (e.g., "v1.0", "v2.0", "Latest")
4. Optionally add a slug (e.g., "v1-0", "v2-0", "latest")
5. Click **Add New Version**

### 2. Assigning Versions to Documentation

When creating or editing a documentation article:

1. Look for the **Versions** box in the sidebar (similar to Categories or Tags)
2. Check the version(s) that this documentation applies to
3. You can assign multiple versions to a single article if the content applies to multiple releases
4. Save or update your documentation

### 3. Viewing Versioned Documentation

When viewing a documentation page:

- If the article is associated with multiple versions, a version selector will appear:
- Below the breadcrumbs in the main content area
- In the sidebar navigation

- The version selector only appears when:
- At least 2 versions exist in your system
- The current article is assigned to at least one version

### 4. Switching Between Versions

Users can switch between versions by:

1. Using the version dropdown selector
2. Selecting a different version from the dropdown
3. The page will reload with the version parameter in the URL (e.g., `?version=v2-0`)

## Best Practices

### Version Naming

- Use clear, descriptive version names (e.g., "v2.1", "2024.1", "Latest")
- Keep version slugs URL-friendly (e.g., "v2-1", "2024-1", "latest")
- Consider using semantic versioning (Major.Minor.Patch)

### Content Organization

1. **Create a "Latest" version**: Always maintain a "Latest" or "Current" version for your most up-to-date documentation
2. **Duplicate content when needed**: When releasing a new version, duplicate the documentation and update only what's changed
3. **Mark deprecated versions**: Consider adding a note to older versions that they're for legacy releases
4. **Archive old versions**: If a version is no longer supported, you can unassign it from docs or delete it

### URL Structure

The version selector adds a query parameter to the URL:
```
https://example.com/docs/article-name/?version=v2-0
```

This allows users to:
- Bookmark specific versions
- Share links to version-specific documentation
- Have better SEO for different versions

## Example Workflow

Let's say you're documenting a WordPress plugin:

1. **Initial Setup** (Plugin v1.0 released):
- Create version "v1.0"
- Write documentation and assign to "v1.0"

2. **New Release** (Plugin v2.0 released):
- Create version "v2.0"
- Review existing documentation:
- Articles that haven't changed: assign to both "v1.0" and "v2.0"
- Articles with changes: create new versions and assign to "v2.0" only
- Keep old articles assigned to "v1.0" for legacy users

3. **Ongoing Maintenance**:
- New features: Create docs and assign to "v2.0"
- Bug fixes: Update docs assigned to "v2.0"
- Deprecation: Remove version assignments from very old versions

## Technical Details

- **Taxonomy**: Versions are implemented as a custom taxonomy (`doc_version`)
- **Hierarchical**: Versions support parent-child relationships if needed
- **REST API**: Versions are available via WordPress REST API
- **Backward Compatible**: Existing documentation without versions will continue to work normally

## Troubleshooting

### Version selector doesn't appear

- Ensure you have created at least 2 versions
- Verify the current article is assigned to at least one version
- Check that versions are published (not in draft)

### Version switching doesn't work

- Clear your browser cache
- Check JavaScript console for errors
- Ensure the version slug is URL-friendly (no special characters)

## Future Enhancements

Potential future improvements to the versioning system:

- Version-specific styling or banners
- Automatic version detection based on URL structure
- Version comparison tools
- Version-based search filtering
- Default version settings

## Support

For questions or issues with the versioning feature:

- Visit [weDocs Documentation](https://wedocs.co/docs/)
- Get support at [weDocs Support](https://wedocs.co/get-support/)
- Report bugs on [GitHub](https://github.com/weDevsOfficial/wedocs-plugin/issues)
Loading