Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: vendor vacation, biography dokan-pro support #91

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

kzamanbd
Copy link

@kzamanbd kzamanbd commented Nov 19, 2024

Related PR: Link

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features
    • Introduced enhanced functionality for managing vendor vacation messages and biographies, allowing for translation.
    • Added new actions and filters to facilitate the updating and retrieval of translated vendor content.

Copy link

coderabbitai bot commented Nov 19, 2024

Walkthrough

The changes in this pull request introduce new methods and hooks to the Dokan_WPML class in the dokan-wpml.php file. These additions facilitate the translation of vendor vacation messages and biographies, enhancing the plugin's functionality in managing vendor-specific content. Specifically, two new actions and two filters are implemented to handle the updates and retrieval of translated messages and biographies.

Changes

File Change Summary
dokan-wpml.php - Added methods for vendor vacation message and biography translation: dokan_vendor_vacation_message_updated, get_translated_dokan_vendor_vacation_message, dokan_vendor_biography_updated, get_translated_dokan_vendor_biography_text.
- Added hooks for actions and filters related to the new methods.

Possibly related PRs

Suggested labels

Dev Review Done

Suggested reviewers

  • MdAsifHossainNadim
  • shohag121

Poem

🐰 In the land of code where vendors play,
New messages and tales come out to sway.
With translations bright, their stories unfold,
A vacation message, a biography bold.
Hops of joy for updates so neat,
In the world of Dokan, our work is complete! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 9ecb21d and e41ad05.

📒 Files selected for processing (1)
  • dokan-wpml.php (2 hunks)
🔇 Additional comments (1)
dokan-wpml.php (1)

172-178: LGTM: Hook declarations follow WordPress conventions.

The new action hooks and filters for vendor vacation messages and biography translations are properly integrated into the existing architecture.

dokan-wpml.php Outdated
Comment on lines 1355 to 1382

/**
* Translate Vendor Biography Text
*
* @param $text
* @param $name
*
* @return void
*/
public function dokan_vendor_biography_updated($text, $name) {
$this->register_single_string(
'dokan',
'Vendor Biography Text: ' . $name,
$text
);
}

/**
* Translated Vendor Biography Text
*
* @param string $text
* @param $name
*
* @return string
*/
public function get_translated_dokan_vendor_biography_text(string $text , $name) {
return $this->get_translated_single_string( $text, 'dokan', 'Vendor Biography Text: '.$name );
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Refactor biography methods to reduce code duplication.

The vendor biography methods have similar issues as the vacation message methods and share duplicate code patterns.

  1. First, apply similar improvements as suggested for vacation messages:
     /**
      * Translate Vendor Biography Text
      *
-     * @param $text
-     * @param $name
+     * @param string $text The biography text to translate
+     * @param string $name The vendor name or identifier
      *
      * @return void
      */
-    public function dokan_vendor_biography_updated($text, $name) {
+    public function dokan_vendor_biography_updated( string $text, string $name ) {
+        if ( empty( $text ) || empty( $name ) ) {
+            return;
+        }
+
         $this->register_single_string(
             'dokan',
             'Vendor Biography Text: ' . $name,
             $text
         );
     }

     /**
      * Translated Vendor Biography Text
      *
      * @param string $text
-     * @param $name
+     * @param string $name The vendor name or identifier
      *
      * @return string
      */
-    public function get_translated_dokan_vendor_biography_text(string $text , $name) {
-        return $this->get_translated_single_string( $text, 'dokan', 'Vendor Biography Text: '.$name );
+    public function get_translated_dokan_vendor_biography_text( string $text, string $name ) {
+        if ( empty( $text ) || empty( $name ) ) {
+            return $text;
+        }
+        return $this->get_translated_single_string( $text, 'dokan', 'Vendor Biography Text: ' . $name );
     }
  1. Consider extracting common functionality into private helper methods:
private function register_vendor_text( string $text, string $name, string $type ) {
    if ( empty( $text ) || empty( $name ) ) {
        return;
    }
    $this->register_single_string(
        'dokan',
        "Vendor {$type}: " . $name,
        $text
    );
}

private function get_translated_vendor_text( string $text, string $name, string $type ) {
    if ( empty( $text ) || empty( $name ) ) {
        return $text;
    }
    return $this->get_translated_single_string( $text, 'dokan', "Vendor {$type}: " . $name );
}

Then update the public methods to use these helpers:

public function dokan_vendor_biography_updated( string $text, string $name ) {
    $this->register_vendor_text( $text, $name, 'Biography Text' );
}

public function get_translated_dokan_vendor_biography_text( string $text, string $name ) {
    return $this->get_translated_vendor_text( $text, $name, 'Biography Text' );
}

Comment on lines +1326 to +1353

/**
* Translate Vendor Vacation Message
*
* @param $text
* @param $name
*
* @return void
*/
public function dokan_vendor_vacation_message_updated($text, $name) {
$this->register_single_string(
'dokan',
'Vendor Vacation Message: ' . $name,
$text
);
}

/**
* Translated Vendor Vacation Message
*
* @param string $text
* @param $name
*
* @return string
*/
public function get_translated_dokan_vendor_vacation_message(string $text , $name) {
return $this->get_translated_single_string( $text, 'dokan', 'Vendor Vacation Message: '.$name );
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve method documentation and input validation.

The vendor vacation message methods need the following improvements:

  1. Add complete PHPDoc parameter type hints and descriptions
  2. Add input validation for parameters
  3. Fix inconsistent spacing in string concatenation

Apply this diff to improve the implementation:

     /**
      * Translate Vendor Vacation Message
      *
-     * @param $text
-     * @param $name
+     * @param string $text The vacation message text to translate
+     * @param string $name The vendor name or identifier
      *
      * @return void
      */
-    public function dokan_vendor_vacation_message_updated($text, $name) {
+    public function dokan_vendor_vacation_message_updated( string $text, string $name ) {
+        if ( empty( $text ) || empty( $name ) ) {
+            return;
+        }
+
         $this->register_single_string(
             'dokan',
             'Vendor Vacation Message: ' . $name,
             $text
         );
     }

     /**
      * Translated Vendor Vacation Message
      *
      * @param string $text
-     * @param $name
+     * @param string $name The vendor name or identifier
      *
      * @return string
      */
-    public function get_translated_dokan_vendor_vacation_message(string $text , $name) {
-        return $this->get_translated_single_string( $text, 'dokan', 'Vendor Vacation Message: '.$name );
+    public function get_translated_dokan_vendor_vacation_message( string $text, string $name ) {
+        if ( empty( $text ) || empty( $name ) ) {
+            return $text;
+        }
+        return $this->get_translated_single_string( $text, 'dokan', 'Vendor Vacation Message: ' . $name );
     }
📝 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
/**
* Translate Vendor Vacation Message
*
* @param $text
* @param $name
*
* @return void
*/
public function dokan_vendor_vacation_message_updated($text, $name) {
$this->register_single_string(
'dokan',
'Vendor Vacation Message: ' . $name,
$text
);
}
/**
* Translated Vendor Vacation Message
*
* @param string $text
* @param $name
*
* @return string
*/
public function get_translated_dokan_vendor_vacation_message(string $text , $name) {
return $this->get_translated_single_string( $text, 'dokan', 'Vendor Vacation Message: '.$name );
}
/**
* Translate Vendor Vacation Message
*
* @param string $text The vacation message text to translate
* @param string $name The vendor name or identifier
*
* @return void
*/
public function dokan_vendor_vacation_message_updated( string $text, string $name ) {
if ( empty( $text ) || empty( $name ) ) {
return;
}
$this->register_single_string(
'dokan',
'Vendor Vacation Message: ' . $name,
$text
);
}
/**
* Translated Vendor Vacation Message
*
* @param string $text
* @param string $name The vendor name or identifier
*
* @return string
*/
public function get_translated_dokan_vendor_vacation_message( string $text, string $name ) {
if ( empty( $text ) || empty( $name ) ) {
return $text;
}
return $this->get_translated_single_string( $text, 'dokan', 'Vendor Vacation Message: ' . $name );
}

@kzamanbd kzamanbd self-assigned this Nov 20, 2024
@kzamanbd kzamanbd requested review from mrabbani and removed request for MdAsifHossainNadim November 21, 2024 07:50
@kzamanbd kzamanbd linked an issue Nov 21, 2024 that may be closed by this pull request
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: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8760b7b and 095787d.

📒 Files selected for processing (1)
  • dokan-wpml.php (5 hunks)
🔇 Additional comments (8)
dokan-wpml.php (8)

130-131: No issues found with these filter hooks.
They match the corresponding callback signatures, and the usage appears consistent with the defined methods.


132-132: Looks good.
Hooking 'dokan_vendor_subscription_package_id' to get_product_id_in_base_language is consistent with the method's single-argument signature.


144-145: These filter hooks are well-defined.
Their callback methods accept the correct number of parameters, and no errors are apparent.


1327-1341: Add input validation and type hints.
This method lacks parameter checks and does not guard against empty or invalid values. Additionally, the docblock could specify types (string). This was previously recommended.


1343-1353: Enforce input validation and clarify docblocks.
Just like the vacation message method, please verify $text and $name before usage, and ensure the docblock uses typed parameters.


1356-1370: Check array keys and reduce duplication.
$store_info might not always have vendor_biography. Consider adding a guard and reusing a helper, as previously suggested in older reviews.


1372-1382: Refactor to reduce duplication across biography and vacation methods.
Both sets of methods mirror each other. Centralize shared logic and add input validation.


160-161: Confirm that each action passes the expected method ID.
While register_vendor_verification_method accepts an int $method_id, ensure that both 'dokan_pro_vendor_verification_method_created' and 'dokan_pro_vendor_verification_method_updated' indeed pass that parameter in the first position.

Comment on lines +177 to +178
add_action( 'dokan_vendor_biography_after_update', [ $this, 'dokan_vendor_biography_updated' ], 10, 3 );
add_filter( 'dokan_get_vendor_biography_text', [ $this, 'get_translated_dokan_vendor_biography_text' ], 10, 2 );
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Mismatch in action parameters.
Similarly, 'dokan_vendor_biography_after_update' is hooked with 10, 3 arguments, but dokan_vendor_biography_updated($store_info, $name) only accepts 2. Adjust the hook or function signature to avoid passing extra parameters.

-add_action( 'dokan_vendor_biography_after_update', [ $this, 'dokan_vendor_biography_updated' ], 10, 3 );
+add_action( 'dokan_vendor_biography_after_update', [ $this, 'dokan_vendor_biography_updated' ], 10, 2 );
📝 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
add_action( 'dokan_vendor_biography_after_update', [ $this, 'dokan_vendor_biography_updated' ], 10, 3 );
add_filter( 'dokan_get_vendor_biography_text', [ $this, 'get_translated_dokan_vendor_biography_text' ], 10, 2 );
add_action( 'dokan_vendor_biography_after_update', [ $this, 'dokan_vendor_biography_updated' ], 10, 2 );
add_filter( 'dokan_get_vendor_biography_text', [ $this, 'get_translated_dokan_vendor_biography_text' ], 10, 2 );

Comment on lines +173 to +175
add_action( 'dokan_vendor_vacation_message_updated', [ $this, 'dokan_vendor_vacation_message_updated' ], 10, 3 );
add_action( 'dokan_vendor_vacation_message_schedule_after_update', [ $this, 'dokan_vendor_vacation_message_updated' ], 10, 3 );
add_filter( 'dokan_get_vendor_vacation_message', [ $this, 'get_translated_dokan_vendor_vacation_message' ], 10, 2 );
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Mismatch in action parameters.
The action 'dokan_vendor_vacation_message_updated' is hooked with 10, 3 arguments, but dokan_vendor_vacation_message_updated($text, $name) only accepts 2 parameters. This may cause inconsistencies or notices in production.

-add_action( 'dokan_vendor_vacation_message_updated', [ $this, 'dokan_vendor_vacation_message_updated' ], 10, 3 );
-add_action( 'dokan_vendor_vacation_message_schedule_after_update', [ $this, 'dokan_vendor_vacation_message_updated' ], 10, 3 );
+add_action( 'dokan_vendor_vacation_message_updated', [ $this, 'dokan_vendor_vacation_message_updated' ], 10, 2 );
+add_action( 'dokan_vendor_vacation_message_schedule_after_update', [ $this, 'dokan_vendor_vacation_message_updated' ], 10, 2 );
📝 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
add_action( 'dokan_vendor_vacation_message_updated', [ $this, 'dokan_vendor_vacation_message_updated' ], 10, 3 );
add_action( 'dokan_vendor_vacation_message_schedule_after_update', [ $this, 'dokan_vendor_vacation_message_updated' ], 10, 3 );
add_filter( 'dokan_get_vendor_vacation_message', [ $this, 'get_translated_dokan_vendor_vacation_message' ], 10, 2 );
add_action( 'dokan_vendor_vacation_message_updated', [ $this, 'dokan_vendor_vacation_message_updated' ], 10, 2 );
add_action( 'dokan_vendor_vacation_message_schedule_after_update', [ $this, 'dokan_vendor_vacation_message_updated' ], 10, 2 );
add_filter( 'dokan_get_vendor_vacation_message', [ $this, 'get_translated_dokan_vendor_vacation_message' ], 10, 2 );

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

Successfully merging this pull request may close these issues.

Make $setting_vacation_message and $biography translatable with WPML
1 participant