Version Description
- 20/12/2014 =
- Fix - Notice on WP_Debug mode when values are not saved
- Add - Nagg message when WPML is not active ;-)
- Improvement - Use Singleton to initiate plugin
- Improvement - Better code/comment quality
Download this release
Release Info
Developer | sormano |
Plugin | WPML Widgets |
Version | 1.0.3 |
Comparing to | |
See all releases |
Code changes from version 1.0.2 to 1.0.3
- readme.txt +8 -2
- wpml-widgets.php +148 -45
readme.txt
CHANGED
@@ -3,8 +3,8 @@ Contributors: sormano
|
|
3 |
Donate link: http://www.jeroensormani.com/donate/
|
4 |
Tags: WPML, WPML widget, Wordpress Multilanguage, Wordpress Multilanguage widget, WPML widget selector
|
5 |
Requires at least: 3.6
|
6 |
-
Tested up to:
|
7 |
-
Stable tag: 1.0.
|
8 |
License: GPLv3 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
10 |
|
@@ -31,6 +31,12 @@ WPML Widgets is a ultra lightweight plugin, so there will be (about) zero extra
|
|
31 |
|
32 |
== Changelog ==
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
= 1.0.2 =
|
35 |
* Fix - WordPress Multisite supported check
|
36 |
|
3 |
Donate link: http://www.jeroensormani.com/donate/
|
4 |
Tags: WPML, WPML widget, Wordpress Multilanguage, Wordpress Multilanguage widget, WPML widget selector
|
5 |
Requires at least: 3.6
|
6 |
+
Tested up to: 4.1
|
7 |
+
Stable tag: 1.0.3
|
8 |
License: GPLv3 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
10 |
|
31 |
|
32 |
== Changelog ==
|
33 |
|
34 |
+
= 1.0.3 - 20/12/2014 =
|
35 |
+
* Fix - Notice on WP_Debug mode when values are not saved
|
36 |
+
* Add - Nagg message when WPML is not active ;-)
|
37 |
+
* Improvement - Use Singleton to initiate plugin
|
38 |
+
* Improvement - Better code/comment quality
|
39 |
+
|
40 |
= 1.0.2 =
|
41 |
* Fix - WordPress Multisite supported check
|
42 |
|
wpml-widgets.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: WPML Widgets
|
4 |
Plugin URI: http://www.jeroensormani.com
|
5 |
Description: Easily select which widgets you want to show for which languages
|
6 |
-
Version: 1.0.
|
7 |
Author: Jeroen Sormani
|
8 |
Author URI: http://www.jeroensormani.com
|
9 |
*/
|
@@ -31,107 +31,210 @@ Author URI: http://www.jeroensormani.com
|
|
31 |
|
32 |
|
33 |
/**
|
34 |
-
* Class
|
35 |
*
|
36 |
-
* Main WPML Widgets class
|
37 |
*
|
38 |
-
* @class
|
39 |
* @version 1.0.0
|
40 |
* @author Jeroen Sormani
|
41 |
*/
|
42 |
-
|
43 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
44 |
|
45 |
-
class
|
46 |
-
|
47 |
-
|
48 |
/**
|
49 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
*/
|
51 |
public function __construct() {
|
52 |
-
|
53 |
// check if WPML is activated
|
54 |
-
|
55 |
if ( ! function_exists( 'is_plugin_active_for_network' ) ) :
|
56 |
require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
|
57 |
endif;
|
58 |
|
59 |
-
|
60 |
if ( ! in_array( 'sitepress-multilingual-cms/sitepress.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) :
|
61 |
if ( ! is_plugin_active_for_network( 'sitepress-multilingual-cms/sitepress.php' ) ) :
|
|
|
62 |
return;
|
63 |
endif;
|
64 |
endif;
|
65 |
-
|
66 |
// Add dropdown to widgets
|
67 |
add_action( 'in_widget_form', array( $this, 'ww_widget_dropdown' ), 10, 3 );
|
68 |
-
|
69 |
// Update dropdown value on widget update
|
70 |
add_filter( 'widget_update_callback', array( $this, 'ww_widget_update' ), 10, 4 );
|
71 |
-
|
72 |
// Filter widgets by language
|
73 |
add_filter( 'widget_display_callback', array( $this, 'ww_display_widget' ), 10, 3 );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
}
|
75 |
|
76 |
-
|
77 |
/**
|
78 |
* Widget dropdown.
|
79 |
*
|
80 |
* Add a dropdown to every widget.
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
*/
|
82 |
public function ww_widget_dropdown( $widget, $form, $instance ) {
|
83 |
|
84 |
$languages = icl_get_languages();
|
85 |
-
|
86 |
-
?><p
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
|
|
|
|
|
|
100 |
|
101 |
}
|
102 |
-
|
103 |
-
|
104 |
/**
|
105 |
* Update widget.
|
106 |
*
|
107 |
* Update the value of the dropdown on widget update.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
*/
|
109 |
public function ww_widget_update( $instance, $new_instance, $old_instance, $this2 ) {
|
110 |
-
|
111 |
-
$instance[
|
112 |
|
113 |
return $instance;
|
114 |
-
|
115 |
}
|
116 |
-
|
117 |
-
|
118 |
/**
|
119 |
* Display widget.
|
120 |
*
|
121 |
* Filter the widgets.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
*/
|
123 |
public function ww_display_widget( $instance, $widget, $args ) {
|
124 |
-
|
125 |
if ( isset( $instance['wpml_language'] ) && $instance['wpml_language'] != ICL_LANGUAGE_CODE && $instance['wpml_language'] != 'all' ) :
|
126 |
return false;
|
127 |
endif;
|
128 |
-
|
129 |
return $instance;
|
130 |
-
|
131 |
-
}
|
132 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
}
|
134 |
-
new Wpml_Widgets();
|
135 |
|
136 |
|
137 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
Plugin Name: WPML Widgets
|
4 |
Plugin URI: http://www.jeroensormani.com
|
5 |
Description: Easily select which widgets you want to show for which languages
|
6 |
+
Version: 1.0.3
|
7 |
Author: Jeroen Sormani
|
8 |
Author URI: http://www.jeroensormani.com
|
9 |
*/
|
31 |
|
32 |
|
33 |
/**
|
34 |
+
* Class WPML_Widgets.
|
35 |
*
|
36 |
+
* Main WPML Widgets class.
|
37 |
*
|
38 |
+
* @class WPML_Widgets
|
39 |
* @version 1.0.0
|
40 |
* @author Jeroen Sormani
|
41 |
*/
|
|
|
42 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
43 |
|
44 |
+
class WPML_Widgets {
|
45 |
+
|
46 |
+
|
47 |
/**
|
48 |
+
* Instace of WPML_Widgets.
|
49 |
+
*
|
50 |
+
* @since 1.0.0
|
51 |
+
* @access private
|
52 |
+
* @var object $instance The instance of WPML_Widgets.
|
53 |
+
*/
|
54 |
+
private static $instance;
|
55 |
+
|
56 |
+
|
57 |
+
/**
|
58 |
+
* Constructor.
|
59 |
+
*
|
60 |
+
* @since 1.0.0
|
61 |
*/
|
62 |
public function __construct() {
|
63 |
+
|
64 |
// check if WPML is activated
|
|
|
65 |
if ( ! function_exists( 'is_plugin_active_for_network' ) ) :
|
66 |
require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
|
67 |
endif;
|
68 |
|
|
|
69 |
if ( ! in_array( 'sitepress-multilingual-cms/sitepress.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) :
|
70 |
if ( ! is_plugin_active_for_network( 'sitepress-multilingual-cms/sitepress.php' ) ) :
|
71 |
+
add_action( 'admin_notices', array( $this, 'wpml_nag_message' ) );
|
72 |
return;
|
73 |
endif;
|
74 |
endif;
|
75 |
+
|
76 |
// Add dropdown to widgets
|
77 |
add_action( 'in_widget_form', array( $this, 'ww_widget_dropdown' ), 10, 3 );
|
78 |
+
|
79 |
// Update dropdown value on widget update
|
80 |
add_filter( 'widget_update_callback', array( $this, 'ww_widget_update' ), 10, 4 );
|
81 |
+
|
82 |
// Filter widgets by language
|
83 |
add_filter( 'widget_display_callback', array( $this, 'ww_display_widget' ), 10, 3 );
|
84 |
+
|
85 |
+
}
|
86 |
+
|
87 |
+
|
88 |
+
/**
|
89 |
+
* Instance.
|
90 |
+
*
|
91 |
+
* An global instance of the class. Used to retrieve the instance
|
92 |
+
* to use on other files/plugins/themes.
|
93 |
+
*
|
94 |
+
* @since 1.0.0
|
95 |
+
*
|
96 |
+
* @return object Instance of the class.
|
97 |
+
*/
|
98 |
+
public static function instance() {
|
99 |
+
|
100 |
+
if ( is_null( self::$instance ) ) :
|
101 |
+
self::$instance = new self();
|
102 |
+
endif;
|
103 |
+
|
104 |
+
return self::$instance;
|
105 |
+
|
106 |
}
|
107 |
|
108 |
+
|
109 |
/**
|
110 |
* Widget dropdown.
|
111 |
*
|
112 |
* Add a dropdown to every widget.
|
113 |
+
*
|
114 |
+
* @since 1.0.0
|
115 |
+
*
|
116 |
+
* @param array $widget Widget instance.
|
117 |
+
* @param null $form Return null if new fields are added.
|
118 |
+
* @param array $instance An array of the widget's settings.
|
119 |
*/
|
120 |
public function ww_widget_dropdown( $widget, $form, $instance ) {
|
121 |
|
122 |
$languages = icl_get_languages();
|
123 |
+
|
124 |
+
?><p>
|
125 |
+
<label for='wpml_language'><?php _e( 'Display on language:', 'wpml-widgets' ); ?> </label>
|
126 |
+
<select id='wpml_language' name='wpml_language'><?php
|
127 |
+
foreach ( $languages as $language ) :
|
128 |
+
|
129 |
+
$wpml_language = isset( $instance['wpml_language'] ) ? $instance['wpml_language'] : null;
|
130 |
+
?><option <?php selected( $language['language_code'], $wpml_language ); ?> value='<?php echo $language['language_code']; ?>'><?php
|
131 |
+
echo $language['native_name'];
|
132 |
+
?></option><?php
|
133 |
+
|
134 |
+
endforeach;
|
135 |
+
|
136 |
+
$selected = ( ! isset( $instance['wpml_language'] ) || 'all' == $instance['wpml_language'] ) ? true : false;
|
137 |
+
?><option <?php selected( $selected ); ?> value='all'><?php _e( 'All Languages', 'wpml-widgets' ); ?></option>
|
138 |
+
|
139 |
+
</select>
|
140 |
+
</p><?php
|
141 |
|
142 |
}
|
143 |
+
|
144 |
+
|
145 |
/**
|
146 |
* Update widget.
|
147 |
*
|
148 |
* Update the value of the dropdown on widget update.
|
149 |
+
*
|
150 |
+
* @since 1.0.0
|
151 |
+
*
|
152 |
+
* @param array $instance List of data.
|
153 |
+
* @param array $new_instance New instance data.
|
154 |
+
* @param array $old_instance List of old isntance data.
|
155 |
+
* @param array $this2 Class of ..?.
|
156 |
+
* @return array List of modified instance.
|
157 |
*/
|
158 |
public function ww_widget_update( $instance, $new_instance, $old_instance, $this2 ) {
|
159 |
+
|
160 |
+
$instance['wpml_language'] = $_POST['wpml_language'];
|
161 |
|
162 |
return $instance;
|
163 |
+
|
164 |
}
|
165 |
+
|
166 |
+
|
167 |
/**
|
168 |
* Display widget.
|
169 |
*
|
170 |
* Filter the widgets.
|
171 |
+
*
|
172 |
+
* @since 1.0.0
|
173 |
+
*
|
174 |
+
* @param array $instance List of widget data.
|
175 |
+
* @param array $widget Widget data.
|
176 |
+
* @param array $args List of args.
|
177 |
+
* @return array List of modified widget instance.
|
178 |
*/
|
179 |
public function ww_display_widget( $instance, $widget, $args ) {
|
180 |
+
|
181 |
if ( isset( $instance['wpml_language'] ) && $instance['wpml_language'] != ICL_LANGUAGE_CODE && $instance['wpml_language'] != 'all' ) :
|
182 |
return false;
|
183 |
endif;
|
184 |
+
|
185 |
return $instance;
|
186 |
+
|
187 |
+
}
|
188 |
+
|
189 |
+
|
190 |
+
/**
|
191 |
+
* Nag message.
|
192 |
+
*
|
193 |
+
* Display a nag message when WPML is not actiavted.
|
194 |
+
*
|
195 |
+
* @since 1.0.3
|
196 |
+
*/
|
197 |
+
public function wpml_nag_message() {
|
198 |
+
|
199 |
+
// Check if message should be dismissed
|
200 |
+
if ( isset( $_GET['dismiss_wpml_widgets_nag'] ) && 1 == $_GET['dismiss_wpml_widgets_nag'] ) :
|
201 |
+
update_option( 'ignore_wpml_widgets_nag', 'yes' );
|
202 |
+
endif;
|
203 |
+
|
204 |
+
if ( 'yes' != get_option( 'ignore_wpml_widgets_nag' ) ) :
|
205 |
+
?><div class='updated'>
|
206 |
+
<p><?php
|
207 |
+
_e( 'Hey, I see WPML is not activated, please activate it before using WPML Widgets.', 'wpml-widgets' );
|
208 |
+
?><a class='alignright installer-dismiss-nag' href='<?php echo add_query_arg( 'dismiss_wpml_widgets_nag', true ); ?>' data-repository='wpml'><?php
|
209 |
+
_e( 'Dismiss', 'wpml-widgtes' );
|
210 |
+
?></a>
|
211 |
+
</p>
|
212 |
+
</div><?php
|
213 |
+
endif;
|
214 |
+
|
215 |
+
}
|
216 |
+
|
217 |
+
|
218 |
}
|
|
|
219 |
|
220 |
|
221 |
+
/**
|
222 |
+
* The main function responsible for returning the WPML_Widgets object.
|
223 |
+
*
|
224 |
+
* Use this function like you would a global variable, except without needing to declare the global.
|
225 |
+
*
|
226 |
+
* Example: <?php WPML_Widgets()->method_name(); ?>
|
227 |
+
*
|
228 |
+
* @since 1.0.3
|
229 |
+
*
|
230 |
+
* @return object WPML_Widgets class object.
|
231 |
+
*/
|
232 |
+
if ( ! function_exists( 'WPML_Widgets' ) ) :
|
233 |
+
|
234 |
+
function WPML_Widgets() {
|
235 |
+
return WPML_Widgets::instance();
|
236 |
+
}
|
237 |
+
|
238 |
+
endif;
|
239 |
+
|
240 |
+
WPML_Widgets();
|