Skip to content

Conversation

@Akhill2020
Copy link
Contributor

@Akhill2020 Akhill2020 commented Oct 9, 2025

Summary by CodeRabbit

  • New Features
    • Added multilingual compatibility: calendar AJAX requests now include the current language when available (WPML), ensuring language-appropriate data.
  • Bug Fixes
    • Improved resilience of tooltips: failures during tooltip initialization no longer break calendar rendering; errors are safely logged.
  • Documentation
    • Updated shortcode reference to use [simple_calendar] for embedding calendars.

@Akhill2020 Akhill2020 changed the title WPML event bubble issue Fix WPML Compatibility Issue with Event Bubbles Revert Oct 9, 2025
@coderabbitai
Copy link

coderabbitai bot commented Oct 9, 2025

Walkthrough

Adds WPML language propagation to AJAX requests and localized script variables, updates shortcode name in documentation, and wraps qTip2 initialization in try-catch. JavaScript now uses shared ajaxData for grid/list navigation and includes lang when available. PHP appends lang to admin-ajax URL and exposes wpml_language to scripts.

Changes

Cohort / File(s) Summary of Changes
Documentation update
CLAUDE.md
Replace shortcode reference from "[calendar]" to "[simple_calendar]".
AJAX data + tooltip handling
assets/js/default-calendar.js
Switch to shared ajaxData for grid/list navigation; include lang when available; add try-catch around qTip2 initialization; keep existing behavior for positioning/show/hide/render.
WPML var localization
includes/functions/shared.php
Inject wpml_language into localized JS variables when ICL_LANGUAGE_CODE is defined.
AJAX URL language support
includes/main.php
Modify ajax_url() to append lang query parameter when WPML is active; otherwise return base admin-ajax.php URL.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User as User
  participant UI as Calendar UI (JS)
  participant WP as WordPress admin-ajax.php
  participant WPML as WPML (lang context)

  Note over UI: Localized vars include wpml_language (if defined)
  User->>UI: Navigate calendar (grid/list)
  UI->>UI: Build ajaxData { action, ... , id, lang? }
  alt WPML active
    UI->>WP: AJAX request with lang query + ajaxData.lang
    WP->>WPML: Resolve language context
    WPML-->>WP: Language applied
  else No WPML
    UI->>WP: AJAX request without lang
  end
  WP-->>UI: JSON response (events/calendar HTML)
  rect rgba(230,250,230,0.6)
    Note right of UI: Initialize qTip2 tooltips
    UI->>UI: try { qTip2(...) } catch { warn and continue }
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • enginnk

Poem

A hop, a skip, a multilingual spin—
Calendars whisper, “lang” tucked in.
Tooltips behave (we try, we catch),
Dates align, a perfect match.
From grid to list, I thump with cheer—
Simple hops, clearer days appear! 🐇📅

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Title Check ⚠️ Warning The title is confusing and does not clearly convey the main change because it awkwardly combines “Fix WPML Compatibility Issue with Event Bubbles” and “Revert” without explaining what is being reverted, and the summary changes do not actually perform a revert, making the title misleading and unclear. Rename the title to clearly reflect the actual change, for example “Restore WPML compatibility for event bubbles” or “Add WPML language support to event bubble AJAX calls,” so that it clearly and concisely summarizes the main update.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch rohit/wpml-event-bubble-issue-revert

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
assets/js/default-calendar.js (1)

114-124: Rename variable to avoid redeclaration.

The variable ajaxData is declared again here, which was flagged by static analysis. While both declarations are in separate scopes (grid vs. list navigation), using different variable names would improve code clarity.

Based on learnings
Apply this diff to use distinct variable names:

-			var ajaxData = {
+			var listAjaxData = {
 				action: action,
 				ts: timestamp,
 				id: id,
 			};
 
 			// WPML compatibility: Include language parameter if available
 			if (simcal_default_calendar.wpml_language) {
-				ajaxData.lang = simcal_default_calendar.wpml_language;
+				listAjaxData.lang = simcal_default_calendar.wpml_language;
 			}
 
 			$.ajax({
 				url: simcal_default_calendar.ajax_url,
 				type: 'POST',
 				dataType: 'json',
 				cache: false,
-				data: ajaxData,
+				data: listAjaxData,

Alternatively, rename the grid navigation variable to gridAjaxData for consistency.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ee3e5bd and d822d31.

📒 Files selected for processing (4)
  • CLAUDE.md (1 hunks)
  • assets/js/default-calendar.js (3 hunks)
  • includes/functions/shared.php (1 hunks)
  • includes/main.php (1 hunks)
🧰 Additional context used
🪛 Biome (2.1.2)
assets/js/default-calendar.js

[error] 114-114: Shouldn't redeclare 'ajaxData'. Consider to delete it or rename it.

'ajaxData' is defined here:

(lint/suspicious/noRedeclare)

🔇 Additional comments (4)
CLAUDE.md (1)

16-16: LGTM! Documentation updated to reflect correct shortcode.

The shortcode reference has been updated from [calendar] to [simple_calendar], which aligns with the plugin's naming convention.

assets/js/default-calendar.js (2)

65-76: LGTM! AJAX data properly structured with WPML support.

The grid navigation now uses a shared ajaxData object and correctly includes the language parameter when WPML is active.


353-408: LGTM! Robust error handling for qTip2 initialization.

The try-catch block gracefully handles qTip2 initialization failures, preventing calendar rendering from breaking. The error is logged for debugging while allowing the calendar to continue functioning.

includes/main.php (1)

277-284: Confirm server-side handling of lang in AJAX handlers.

The lang query parameter is appended client-side but neither draw_list_ajax nor draw_grid_ajax reads or validates it. If WPML language support is intended:

  • Read $_REQUEST['lang'] in each handler
  • Sanitize with sanitize_text_field()
  • Validate against your language pattern (e.g. /^[a-z]{2}(?:_[A-Z]{2})?$/)
  • Pass the sanitized $lang into your drawing methods

Otherwise, remove the client-side append to avoid unused parameters.

Comment on lines +180 to +184
// WPML compatibility: Add current language code to JavaScript variables
if (defined('ICL_LANGUAGE_CODE')) {
$vars['wpml_language'] = ICL_LANGUAGE_CODE;
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Verify that ICL_LANGUAGE_CODE is safe for JavaScript output.

The WPML language code is being added to JavaScript variables without explicit sanitization. While ICL_LANGUAGE_CODE is a WPML-provided constant, ensure it's safe for direct output to JavaScript.

Run the following script to verify how WPML defines and uses this constant:

Additionally, consider applying esc_js() or similar sanitization if the constant could contain untrusted data:

 // WPML compatibility: Add current language code to JavaScript variables
 if (defined('ICL_LANGUAGE_CODE')) {
-	$vars['wpml_language'] = ICL_LANGUAGE_CODE;
+	$vars['wpml_language'] = esc_js(ICL_LANGUAGE_CODE);
 }

🏁 Script executed:

#!/bin/bash
# Description: Check WPML's ICL_LANGUAGE_CODE usage and validation

# Search for ICL_LANGUAGE_CODE definition and usage patterns in WPML contexts
rg -nP --type=php -C5 "define\s*\(\s*['\"]ICL_LANGUAGE_CODE['\"]"

# Look for any sanitization patterns around language code usage
rg -nP --type=php -C3 "ICL_LANGUAGE_CODE.*esc_|sanitize_"

Length of output: 30646


Sanitize WPML language code before JS export

Wrap ICL_LANGUAGE_CODE in esc_js() to ensure safe JavaScript output:

 // WPML compatibility: Add current language code to JavaScript variables
 if (defined('ICL_LANGUAGE_CODE')) {
-	$vars['wpml_language'] = ICL_LANGUAGE_CODE;
+	$vars['wpml_language'] = esc_js(ICL_LANGUAGE_CODE);
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// WPML compatibility: Add current language code to JavaScript variables
if (defined('ICL_LANGUAGE_CODE')) {
$vars['wpml_language'] = ICL_LANGUAGE_CODE;
}
// WPML compatibility: Add current language code to JavaScript variables
if (defined('ICL_LANGUAGE_CODE')) {
$vars['wpml_language'] = esc_js(ICL_LANGUAGE_CODE);
}
🤖 Prompt for AI Agents
In includes/functions/shared.php around lines 180 to 184, the WPML language
constant ICL_LANGUAGE_CODE is being exported directly into the $vars array for
JavaScript; wrap the value in esc_js() before assigning to
$vars['wpml_language'] so the language code is properly escaped for safe JS
output (e.g., $vars['wpml_language'] = esc_js(ICL_LANGUAGE_CODE)); ensure
esc_js() is available in this context or use a PHP fallback/explicit casting to
string before escaping.

@github-actions
Copy link

github-actions bot commented Dec 8, 2025

This pull request has been marked as stale due to inactivity. It will be closed in 30 days if no further updates are made.

@github-actions github-actions bot added the stale label Dec 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants