Skip to content

Commit aae3c7b

Browse files
authored
Merge pull request #3 from saimonh3/fix/upload-image
refactor: show error notice if WPML is not activated
2 parents ba3b463 + 3a7c267 commit aae3c7b

File tree

1 file changed

+42
-28
lines changed

1 file changed

+42
-28
lines changed

dokan-wpml.php

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@
3535
* **********************************************************************
3636
*/
3737

38-
// don't call the file directly
39-
if ( !defined( 'ABSPATH' ) ) exit;
38+
defined( 'ABSPATH' ) || exit;
4039

4140
/**
4241
* Dokan_WPML class
@@ -57,7 +56,7 @@ class Dokan_WPML {
5756
* @uses add_action()
5857
*/
5958
public function __construct() {
60-
add_action( 'init', array( $this, 'is_dependency_installed' ) );
59+
register_activation_hook( __FILE__, array( $this, 'dependency_missing_notice' ) );
6160

6261
// Localize our plugin
6362
add_action( 'init', array( $this, 'localization_setup' ) );
@@ -67,6 +66,7 @@ public function __construct() {
6766
add_filter( 'dokan_force_load_extra_args', array( $this, 'load_scripts_and_style') );
6867
add_filter( 'dokan_seller_setup_wizard_url', array( $this, 'render_wmpl_home_url' ), 70 );
6968
add_filter( 'dokan_get_page_url', array( $this, 'reflect_page_url' ), 10, 3 );
69+
add_filter( 'dokan_get_terms_condition_url', array( $this, 'get_terms_condition_url' ), 10, 2 );
7070
add_filter( 'dokan_redirect_login', array( $this, 'redirect_if_not_login' ), 90 );
7171
add_filter( 'dokan_force_page_redirect', array( $this, 'force_redirect_page' ), 90, 2 );
7272

@@ -91,26 +91,27 @@ public static function init() {
9191
return $instance;
9292
}
9393

94-
95-
function is_dependency_installed(){
96-
if ( !class_exists( 'WeDevs_Dokan' )){
97-
add_action( 'admin_notices', array ( $this, 'need_dependency' ) );
98-
}
99-
}
100-
10194
/**
10295
* Print error notice if dependency not active
10396
*
104-
* @since 1.0.0
97+
* @since 1.0.1
98+
*
99+
* @return void
105100
*/
106-
function need_dependency(){
107-
$error = sprintf( __( '<b>Dokan - WPML Integration</b> requires %sDokan plugin%s to be installed & activated!' , 'dokan-wpml' ), '<a target="_blank" href="https://wedevs.com/products/plugins/dokan/">', '</a>' );
108-
109-
$message = '<div class="error"><p>' . $error . '</p></div>';
101+
public function dependency_missing_notice() {
102+
deactivate_plugins( plugin_basename( __FILE__ ) );
110103

111-
echo $message;
104+
if ( ! class_exists( 'WeDevs_Dokan' ) ) {
105+
$error = sprintf( __( '<b>Dokan - WPML Integration</b> requires %sDokan plugin%s to be installed & activated!' , 'dokan-wpml' ), '<a target="_blank" href="https://wedevs.com/products/plugins/dokan/">', '</a>' );
106+
$message = '<div class="error"><p>' . $error . '</p></div>';
107+
wp_die( $message );
108+
}
112109

113-
deactivate_plugins( plugin_basename( __FILE__ ) );
110+
if ( ! class_exists( 'SitePress' ) ) {
111+
$error = sprintf( __( '<b>Dokan - WPML Integration</b> requires %sWPML Multilingual CMS%s to be installed & activated!' , 'dokan-wpml' ), '<a target="_blank" href="https://wpml.org/">', '</a>' );
112+
$message = '<div class="error"><p>' . $error . '</p></div>';
113+
wp_die( $message );
114+
}
114115
}
115116

116117
/**
@@ -166,19 +167,32 @@ function load_translated_url( $url, $name ) {
166167
*
167168
* @return void
168169
**/
169-
function reflect_page_url( $url, $page_id, $context ) {
170+
public function reflect_page_url( $url, $page_id, $context ) {
170171
$lang_post_id = wpml_object_id_filter( $page_id , 'page', true, ICL_LANGUAGE_CODE );
171172
return get_permalink( $lang_post_id );
172173
}
173174

175+
/**
176+
* Get terms and condition page url
177+
*
178+
* @since 1.0.1
179+
*
180+
* @return url
181+
**/
182+
public function get_terms_condition_url( $url, $page_id ) {
183+
$page_id = wpml_object_id_filter( $page_id , 'page', true, ICL_LANGUAGE_CODE );
184+
185+
return get_permalink( $page_id );
186+
}
187+
174188
/**
175189
* Redirect if not login
176190
*
177191
* @since 1.0.1
178192
*
179193
* @return void
180194
**/
181-
function redirect_if_not_login( $url ) {
195+
public function redirect_if_not_login( $url ) {
182196
$page_id = wc_get_page_id( 'myaccount' );
183197
$lang_post_id = wpml_object_id_filter( $page_id , 'page', true, ICL_LANGUAGE_CODE );
184198
return get_permalink( $lang_post_id );
@@ -191,7 +205,7 @@ function redirect_if_not_login( $url ) {
191205
*
192206
* @return void
193207
**/
194-
function force_redirect_page( $flag, $page_id ) {
208+
public function force_redirect_page( $flag, $page_id ) {
195209
$lang_post_id = wpml_object_id_filter( $page_id , 'page', true, ICL_LANGUAGE_CODE );
196210

197211
if ( is_page( $lang_post_id ) ) {
@@ -210,7 +224,7 @@ function force_redirect_page( $flag, $page_id ) {
210224
*
211225
* @return string [$url]
212226
*/
213-
function get_dokan_url_for_language( $language ) {
227+
public function get_dokan_url_for_language( $language ) {
214228
$post_id = dokan_get_option( 'dashboard', 'dokan_pages' );
215229
$lang_post_id = wpml_object_id_filter( $post_id , 'page', true, $language );
216230

@@ -232,7 +246,7 @@ function get_dokan_url_for_language( $language ) {
232246
*
233247
* @param array $classes
234248
*/
235-
function add_dashboard_template_class_if_wpml( $classes ) {
249+
public function add_dashboard_template_class_if_wpml( $classes ) {
236250
if ( function_exists('wpml_object_id_filter') ) {
237251
global $post;
238252

@@ -259,17 +273,17 @@ function add_dashboard_template_class_if_wpml( $classes ) {
259273
*
260274
* @return void
261275
*/
262-
function load_scripts_and_style() {
276+
public function load_scripts_and_style() {
263277
if ( function_exists('wpml_object_id_filter') ) {
264278
global $post;
265279

266280
if( !$post ) {
267281
return false;
268282
}
269283

270-
$default_lang = apply_filters('wpml_default_language', NULL );
284+
$default_lang = apply_filters('wpml_default_language', NULL );
271285
$current_page_id = wpml_object_id_filter( $post->ID,'page',false, $default_lang );
272-
$page_id = dokan_get_option( 'dashboard', 'dokan_pages' );
286+
$page_id = dokan_get_option( 'dashboard', 'dokan_pages' );
273287

274288
if ( ( $current_page_id == $page_id ) || ( get_query_var( 'edit' ) && is_singular( 'product' ) ) ) {
275289
return true;
@@ -281,8 +295,8 @@ function load_scripts_and_style() {
281295

282296
} // Dokan_WPML
283297

284-
add_action( 'dokan_loaded', 'dokan_load_wpml', 15 );
285-
286298
function dokan_load_wpml() {
287299
$dokan_wpml = Dokan_WPML::init();
288-
}
300+
}
301+
302+
dokan_load_wpml();

0 commit comments

Comments
 (0)