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 4 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
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
65 changes: 65 additions & 0 deletions dokan-wpml.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@ public function plugins_loaded() {
add_filter( 'wp', [ $this, 'set_translated_query_var_to_default_query_var' ], 11 );
add_filter( 'dokan_set_store_categories', [ $this, 'set_translated_category' ] );
add_filter( 'dokan_get_store_categories_in_vendor', [ $this, 'get_translated_category' ] );

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

}

/**
Expand Down Expand Up @@ -1316,6 +1323,64 @@ public function get_translated_verification_method_title( $title ) {
public function get_translated_verification_method_help_text( $help_text ) {
return $this->get_translated_single_string( $help_text, 'dokan', 'Dokan Vendor Verification Method Help Text: ' . substr( $help_text, 0, 116 ) );
}

/**
* 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 );
}
kzamanbd marked this conversation as resolved.
Show resolved Hide resolved


/**
* 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' );
}


} // Dokan_WPML

function dokan_load_wpml() { // phpcs:ignore
Expand Down