Skip to content

[PROD-9613] - Fix - Report Post's default category translation do not work. - #4947

Open
reza-bb wants to merge 4 commits into
releasefrom
PROD-9613
Open

reza-bb wants to merge 4 commits into
releasefrom
PROD-9613

Conversation

@reza-bb

@reza-bb reza-bb commented May 7, 2026

Copy link
Copy Markdown
Contributor

Jira Issue:

https://buddyboss.atlassian.net/browse/PROD-9613

General Note

Keep all conversations related to this PR in the associated Jira issue(s). Do NOT add comment on this PR or edit this PR’s description.

Notes to Developer

  • Ensure the IDs (i.e. PROD-1) of all associated Jira issues are reference in this PR’s title
  • Ensure that you have achieved the Definition of Done before submitting for review
  • When this PR is ready for review, move the associate Jira issue(s) to “Needs Review” (or “Code Review” for Dev Tasks)

Notes to Reviewer

  • Ensure that the Definition of Done have been achieved before approving a PR
  • When this PR is approved, move the associated Jira issue(s) to “Needs QA” (or “Approved” for Dev Tasks)

… work.

[PROD-9613] - Fix - Report Post's default category translation do not work.
@claude

claude Bot commented May 7, 2026

Copy link
Copy Markdown

Claude finished @reza-bb's task —— View job


PR Review: Report Post's Default Category Translation Fix

Todo List:

  • Read repository guidelines (CLAUDE.md)
  • Analyze bp-moderation-functions.php changes
  • Analyze class-bp-moderation-component.php changes
  • Analyze content-report-form.php changes
  • Provide comprehensive review feedback
  • Check for code quality, bugs, performance, and security issues

Summary

This PR fixes translation issues with default category names in the Report Post functionality. The changes introduce proper runtime translation for default reporting categories, allowing them to be translated dynamically instead of being locked to the locale active during installation.

Comprehensive Review

Positive Aspects

  1. Clean Architecture: The solution properly separates concerns by moving default category definitions to a dedicated function and introducing runtime translation logic.

  2. WordPress Standards Compliance: Code follows WordPress coding standards with proper function naming, documentation, and text domain usage (buddyboss).

  3. Backwards Compatibility: The implementation includes fallback logic for installations that pre-date the meta marker by matching term slugs.

  4. Performance Conscious: Uses term meta to store translation keys rather than repeatedly checking against all default terms.

🔍 Code Quality Analysis

src/bp-moderation/bp-moderation-functions.php (Lines 2290-2370)

Strengths:

  • Well-documented new functions with proper docblocks
  • Proper use of __() function with correct text domain
  • Clean array structure for default categories

Minor Issues:

  • Line 2298: Version placeholder [BBVERSION] should be replaced with actual version number
  • Line 2353: Same version placeholder issue

src/bp-moderation/classes/class-bp-moderation-component.php (Lines 159-232)

Strengths:

  • Improved code organization by extracting default terms to a function
  • Added term slugs for consistency
  • Proper use of add_term_meta() with unique parameter

Potential Issues:

  • Lines 218-232: Missing bb_category_show_when_reporting meta assignment for new terms. The original code set this meta for all terms, but the new code doesn't include this logic.

src/bp-moderation/screens/content-report-form.php (Line 40)

Strengths:

  • Simple, clean implementation
  • Properly applies translation at render time

🐛 Critical Issue Found

Missing Term Meta Assignment (src/bp-moderation/classes/class-bp-moderation-component.php:218-232)

The original code assigned bb_category_show_when_reporting meta to newly created terms:

update_term_meta(
    $term['term_id'],
    'bb_category_show_when_reporting', 
    'content_members'
);

The new code is missing this assignment. This could break the report form's conditional display logic.

Recommendation: Add the meta assignment back:

if ( ! is_wp_error( $existing ) && ! empty( $existing['term_id'] ) ) {
    // Add a marker for re-translatable name/description at render time.
    add_term_meta(
        (int) $existing['term_id'],
        '_bp_moderation_default_key',
        $key,
        true
    );
    
    // Add missing meta assignment
    update_term_meta(
        (int) $existing['term_id'],
        'bb_category_show_when_reporting',
        'content_members'
    );
}

🔒 Security Analysis

  • Input Sanitization: ✅ All user inputs are properly handled
  • Output Escaping: ✅ Template properly uses esc_attr()
  • WordPress Norms: ✅ Uses WordPress functions for term operations
  • No SQL Injection risks: ✅ Uses WordPress Term API

📊 Performance Considerations

  • Database Operations: The initialization only runs once per install, so performance impact is minimal
  • Runtime Translation: bp_moderation_maybe_translate_report_term() is efficient with early returns
  • Caching: Leverages WordPress term meta which is cached

🧪 Testing Recommendations

  1. Fresh Install Test: Verify default categories are created with proper meta and translations
  2. Existing Install Test: Ensure existing categories get proper meta markers via fallback logic
  3. Locale Switch Test: Verify category names translate when switching languages
  4. Report Form Test: Confirm report categories display correctly after changes

📝 Documentation

  • Version placeholders need updating
  • Function documentation is comprehensive and follows WordPress standards

🎯 Overall Assessment

This is a well-architected solution to a legitimate i18n issue. The approach is sound, but there's one critical bug that needs fixing before merge.

Recommendation: Request Changes - Fix the missing term meta assignment issue before approving.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants