Skip to content

Conversation

@eug-L
Copy link
Contributor

@eug-L eug-L commented Nov 25, 2024

  • fix translation loaded too early warning, moved get_plugin_data to wp_loaded hook

wordpress hooks order

Summary by CodeRabbit

Summary by CodeRabbit

  • Chores
    • Updated parameters in the plugin initialization method for improved compatibility.
    • Modified UI test workflow to use the newer Docker CLI syntax for starting services.

@coderabbitai
Copy link

coderabbitai bot commented Nov 25, 2024

Walkthrough

The changes include the addition of an init method in the TawkTo_Settings class within the tawkto/tawkto.php file, which initializes plugin data by retrieving the plugin version using the get_plugin_data function. This method is hooked to the wp_loaded action. Additionally, the command for starting Docker services in the UI tests workflow has been updated from docker-compose to docker compose, reflecting a shift to the newer Docker CLI syntax. No other significant modifications were made to the logic or structure of the existing code.

Changes

File Change Summary
tawkto/tawkto.php Added public function init() to TawkTo_Settings class; updated get_plugin_data call from get_plugin_data( __FILE__ ) to get_plugin_data( __FILE__, false, false ).
.github/workflows/ui-tests.yml Updated Docker command from docker-compose to docker compose in the UI tests workflow.

Poem

In the code where rabbits play,
A small change brightens the day.
With new parameters set just right,
TawkTo hops into the light.
Future hooks await their chance,
As we code and dance a dance! 🐇✨


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@eug-L
Copy link
Contributor Author

eug-L commented Nov 26, 2024

@coderabbitai full review

@coderabbitai
Copy link

coderabbitai bot commented Nov 26, 2024

✅ Actions performed

Full review triggered.

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: 0

🧹 Outside diff range and nitpick comments (2)
tawkto/tawkto.php (2)

71-76: Add missing @SInCE tag in PHPDoc

The method documentation should include the @since tag to indicate when this method was added, following WordPress coding standards.

 /**
  * Initializes the plugin data
  *
  * @return void
+ * @since 0.8.6
  */

Line range hint 76-85: Consider optimizing plugin version retrieval

The current implementation has several potential improvements:

  1. Error handling for get_plugin_data is missing
  2. Storing version in a property consumes memory even when not needed
  3. get_file_data would be more efficient than get_plugin_data for just getting the version

Consider this more efficient implementation:

 public function init() {
     if ( is_admin() ) {
-        if ( false === function_exists( 'get_plugin_data' ) ) {
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
+        $plugin_data = get_file_data(
+            __FILE__,
+            array(
+                'Version' => 'Version'
+            ),
+            'plugin'
+        );
-        }
-
-        $plugin_data = get_plugin_data( __FILE__ );
-
-        $this->plugin_ver = $plugin_data['Version'];
+        $this->plugin_ver = $plugin_data['Version'] ?: '0.8.6';
     }
 }

This change:

  • Uses the lighter get_file_data function
  • Provides a fallback version
  • Removes unnecessary include
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 9198110 and b2a81a1.

📒 Files selected for processing (2)
  • .github/workflows/ui-tests.yml (1 hunks)
  • tawkto/tawkto.php (1 hunks)
🔇 Additional comments (4)
.github/workflows/ui-tests.yml (2)

66-66: LGTM! Updated to recommended Docker Compose syntax.

The change from docker-compose to docker compose follows Docker's current best practices, as the Compose command is now integrated into the Docker CLI.


66-66: Verify Docker version compatibility in CI environment.

The new docker compose syntax requires Docker Engine 19.03.0+ and Docker Compose v2. Let's ensure the CI environment meets these requirements.

✅ Verification successful

Docker Compose usage is safe in GitHub Actions environment

The workflow is using Ubuntu latest runner which comes with Docker and Docker Compose v2 pre-installed. GitHub Actions' ubuntu-latest images are regularly updated and maintain compatibility with modern Docker tooling. The workflow is also using standard Docker Compose commands that are well-supported in the CI environment.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check Docker and Docker Compose versions in the CI environment

# Check Docker version
docker --version

# Check Docker Compose version
docker compose version

# Verify if the compose plugin is installed
docker info | grep -i "compose"

Length of output: 367


Script:

#!/bin/bash
# Let's check the GitHub Actions workflow file to see how Docker is set up
cat .github/workflows/ui-tests.yml

Length of output: 2486

tawkto/tawkto.php (2)

62-69: LGTM! Good choice of hook for plugin initialization.

The addition of the wp_loaded hook is appropriate for initializing plugin data, as it ensures WordPress is fully loaded before accessing plugin information.


Line range hint 62-85: Verify the timing of plugin version usage

Let's verify that moving plugin data initialization to wp_loaded doesn't cause issues with early access to the version number.

✅ Verification successful

Let me gather more specific information about how plugin_ver is being used.


Moving plugin version initialization to wp_loaded is safe

The version number (plugin_ver) is only used in the following contexts:

  • In tawk_settings_assets() which is hooked to admin_enqueue_scripts
  • In the settings template for script enqueuing
  • There's a separate static version handling through get_plugin_version() for upgrades

Since all usages occur after wp_loaded in the WordPress lifecycle, and the version is only needed for admin-side functionality, the initialization timing is appropriate.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for uses of plugin_ver property
rg -l "plugin_ver" --type php

# Search for calls to get_plugin_data before wp_loaded
ast-grep --pattern 'function $FUNC($$$) {
  $$$
  get_plugin_data($$$)
  $$$
}'

Length of output: 159


Script:

#!/bin/bash
# Check the content of files using plugin_ver to understand the usage context
rg "plugin_ver" -B 3 -A 3 --type php

# Check if there are any hooks or actions that might need the version before wp_loaded
rg "add_action|add_filter" -B 2 -A 2 --type php tawkto/tawkto.php

Length of output: 4715

@eug-L
Copy link
Contributor Author

eug-L commented Nov 27, 2024

Assessing $plugin_ver being initialized as empty string:

  • wp_enqueue_script() & wp_register_style() will default to wordpress version

@eug-L eug-L merged commit 53800b4 into master Nov 27, 2024
3 of 6 checks passed
@eug-L eug-L deleted the release/support-version-67 branch March 11, 2025 02:34
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.

2 participants