Skip to content

Commit

Permalink
Merge pull request #5 from saimonh3/fix/func-check
Browse files Browse the repository at this point in the history
fix: various improvements
  • Loading branch information
sabbir1991 authored Nov 23, 2019
2 parents 2b46d6a + 9e7e8a5 commit a09bff8
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 43 deletions.
129 changes: 89 additions & 40 deletions dokan-wpml.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,16 @@ public function render_wmpl_home_url( $url ) {
* @return string
*/
function load_translated_url( $url, $name ) {
if ( function_exists('wpml_object_id_filter') ) {
$page_id = dokan_get_option( 'dashboard', 'dokan_pages' );

if ( ! empty( $name ) ) {
$url = $this->get_dokan_url_for_language( ICL_LANGUAGE_CODE ).$name.'/';
} else {
$url = $this->get_dokan_url_for_language( ICL_LANGUAGE_CODE );
}
if ( ! function_exists( 'wpml_object_id_filter' ) ) {
return $url;
}

if ( ! empty( $name ) ) {
$url = $this->get_dokan_url_for_language( ICL_LANGUAGE_CODE ).$name.'/';
} else {
$url = $this->get_dokan_url_for_language( ICL_LANGUAGE_CODE );
}

return $url;
}

Expand All @@ -169,8 +168,13 @@ function load_translated_url( $url, $name ) {
* @return void
**/
public function reflect_page_url( $url, $page_id, $context ) {
$lang_post_id = wpml_object_id_filter( $page_id , 'page', true, ICL_LANGUAGE_CODE );
return get_permalink( $lang_post_id );
if ( ! function_exists( 'wpml_object_id_filter' ) ) {
return $url;
}

$page_id = wpml_object_id_filter( $page_id , 'page', true, ICL_LANGUAGE_CODE );

return get_permalink( $page_id );
}

/**
Expand All @@ -181,6 +185,10 @@ public function reflect_page_url( $url, $page_id, $context ) {
* @return url
**/
public function get_terms_condition_url( $url, $page_id ) {
if ( ! function_exists( 'wpml_object_id_filter' ) ) {
return $url;
}

$page_id = wpml_object_id_filter( $page_id , 'page', true, ICL_LANGUAGE_CODE );

return get_permalink( $page_id );
Expand All @@ -194,8 +202,13 @@ public function get_terms_condition_url( $url, $page_id ) {
* @return void
**/
public function redirect_if_not_login( $url ) {
$page_id = wc_get_page_id( 'myaccount' );
if ( ! function_exists( 'wpml_object_id_filter' ) ) {
return $url;
}

$page_id = wc_get_page_id( 'myaccount' );
$lang_post_id = wpml_object_id_filter( $page_id , 'page', true, ICL_LANGUAGE_CODE );

return get_permalink( $lang_post_id );
}

Expand All @@ -207,6 +220,10 @@ public function redirect_if_not_login( $url ) {
* @return void
**/
public function force_redirect_page( $flag, $page_id ) {
if ( ! function_exists( 'wpml_object_id_filter' ) ) {
return false;
}

$lang_post_id = wpml_object_id_filter( $page_id , 'page', true, ICL_LANGUAGE_CODE );

if ( is_page( $lang_post_id ) ) {
Expand All @@ -226,17 +243,21 @@ public function force_redirect_page( $flag, $page_id ) {
* @return string [$url]
*/
public function get_dokan_url_for_language( $language ) {
$post_id = dokan_get_option( 'dashboard', 'dokan_pages' );
$lang_post_id = wpml_object_id_filter( $post_id , 'page', true, $language );
$post_id = $this->get_raw_option( 'dashboard', 'dokan_pages' );
$lang_post_id = '';

if ( function_exists( 'wpml_object_id_filter' ) ) {
$lang_post_id = wpml_object_id_filter( $post_id , 'page', true, $language );
}

$url = "";
if ($lang_post_id != 0) {

if ( $lang_post_id != 0 ) {
$url = get_permalink( $lang_post_id );
} else {
// No page found, it's most likely the homepage
$url = apply_filters( 'wpml_home_url', get_option( 'home' ) );

}

return $url;
}

Expand All @@ -248,22 +269,23 @@ public function get_dokan_url_for_language( $language ) {
* @param array $classes
*/
public function add_dashboard_template_class_if_wpml( $classes ) {
if ( function_exists('wpml_object_id_filter') ) {
global $post;
if ( ! function_exists( 'wpml_object_id_filter' ) ) {
return $classes;
}

if( !$post ) {
return $classes;
}
global $post;

$default_lang = apply_filters('wpml_default_language', NULL );
if ( ! is_object( $post ) ) {
return $classes;
}

$current_page_id = wpml_object_id_filter( $post->ID,'page',false, $default_lang );
$page_id = dokan_get_option( 'dashboard', 'dokan_pages' );
$page_id = $this->get_raw_option( 'dashboard', 'dokan_pages' );
$current_page_id = wpml_object_id_filter( $post->ID, 'page', true, wpml_get_default_language() );

if ( ( $current_page_id == $page_id ) ) {
$classes[] = 'dokan-dashboard';
}
if ( ( $current_page_id == $page_id ) ) {
$classes[] = 'dokan-dashboard';
}

return $classes;
}

Expand All @@ -275,23 +297,22 @@ public function add_dashboard_template_class_if_wpml( $classes ) {
* @return void
*/
public function load_scripts_and_style() {
if ( function_exists('wpml_object_id_filter') ) {
global $post;

if( !$post ) {
return false;
}
if ( ! function_exists( 'wpml_object_id_filter' ) ) {
return false;
}

$default_lang = apply_filters('wpml_default_language', NULL );
$current_page_id = wpml_object_id_filter( $post->ID,'page',false, $default_lang );
$page_id = dokan_get_option( 'dashboard', 'dokan_pages' );
global $post;

if ( ( $current_page_id == $page_id ) || ( get_query_var( 'edit' ) && is_singular( 'product' ) ) ) {
return true;
}
if ( ! is_object( $post ) ) {
return false;
}

return false;
$page_id = $this->get_raw_option( 'dashboard', 'dokan_pages' );
$current_page_id = wpml_object_id_filter( $post->ID, 'page', true, wpml_get_default_language() );

if ( ( $current_page_id == $page_id ) || ( get_query_var( 'edit' ) && is_singular( 'product' ) ) ) {
return true;
}
}

/**
Expand All @@ -304,9 +325,37 @@ public function load_scripts_and_style() {
* @return int
*/
public function dokan_set_current_page_id( $page_id ) {
if ( ! function_exists( 'wpml_object_id_filter' ) ) {
return $page_id;
}

return wpml_object_id_filter( $page_id, 'page', true, wpml_get_default_language() );
}

/**
* Get raw value from database
*
* @since DOKAN_WPML_SINCE
*
* @param string $option
* @param string $section
* @param mix $default
*
* @return mix
*/
public function get_raw_option( $option, $section, $default = '' ) {
if ( ! class_exists( 'WPML_Multilingual_Options_Utils' ) ) {
return dokan_get_option( $option, $section, $default );
}

global $wpdb;

$util = new WPML_Multilingual_Options_Utils( $wpdb );
$options = $util->get_option_without_filtering( $section );

return isset( $options[ $option ] ) ? $options[ $option ] : $default;
}

} // Dokan_WPML

function dokan_load_wpml() {
Expand Down
6 changes: 3 additions & 3 deletions languages/dokan-wpml.pot
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Dokan - WPML Integration 1.0.1\n"
"Report-Msgid-Bugs-To: http://wedevs.com/support/\n"
"POT-Creation-Date: 2019-06-20 03:55:12+00:00\n"
"POT-Creation-Date: 2019-11-20 08:00:42+00:00\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand All @@ -13,13 +13,13 @@ msgstr ""
"Language-Team: LANGUAGE <EMAIL@ADDRESS>\n"
"X-Generator: grunt-wp-i18n 0.4.9\n"

#: dokan-wpml.php:105
#: dokan-wpml.php:106
msgid ""
"<b>Dokan - WPML Integration</b> requires %sDokan plugin%s to be installed & "
"activated!"
msgstr ""

#: dokan-wpml.php:111
#: dokan-wpml.php:112
msgid ""
"<b>Dokan - WPML Integration</b> requires %sWPML Multilingual CMS%s to be "
"installed & activated!"
Expand Down

0 comments on commit a09bff8

Please sign in to comment.