Version Description
- Compatibility: dFactory Responsive Lightbox widget option. #33
- Tested with WP 5.0.
Download this release
Release Info
Developer | keraweb |
Plugin | Widget CSS Classes |
Version | 1.5.3 |
Comparing to | |
See all releases |
Code changes from version 1.5.2.1 to 1.5.3
- css/widget-css-classes.css +1 -1
- includes/widget-css-classes-library.class.php +8 -8
- includes/widget-css-classes-settings.class.php +120 -33
- includes/widget-css-classes.class.php +68 -47
- js/widget-css-classes.js +4 -3
- readme.txt +6 -2
- widget-css-classes.php +4 -4
css/widget-css-classes.css
CHANGED
@@ -25,4 +25,4 @@
|
|
25 |
.wcssc_sortable .wcssc_drop_placeholder {
|
26 |
background: #e5e5e5;
|
27 |
height: 30px;
|
28 |
-
}
|
25 |
.wcssc_sortable .wcssc_drop_placeholder {
|
26 |
background: #e5e5e5;
|
27 |
height: 30px;
|
28 |
+
}
|
includes/widget-css-classes-library.class.php
CHANGED
@@ -72,10 +72,10 @@ class WCSSC_Lib {
|
|
72 |
public static function admin_footer() {
|
73 |
$plugin_data = get_plugin_data( WCSSC_FILE );
|
74 |
echo $plugin_data['Title'] // @codingStandardsIgnoreLine >> no valid esc function.
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
<br />';
|
80 |
}
|
81 |
|
@@ -184,9 +184,9 @@ class WCSSC_Lib {
|
|
184 |
if ( ! is_string( $key ) ) {
|
185 |
return false;
|
186 |
}
|
187 |
-
self::$settings
|
188 |
self::$settings[ $key ] = $settings;
|
189 |
-
$settings
|
190 |
}
|
191 |
elseif ( ! is_array( $settings ) ) {
|
192 |
return false;
|
@@ -263,7 +263,7 @@ class WCSSC_Lib {
|
|
263 |
}
|
264 |
|
265 |
if ( is_string( $value ) ) {
|
266 |
-
$settings[ $key ] =
|
267 |
}
|
268 |
|
269 |
// Validate var types.
|
@@ -299,7 +299,7 @@ class WCSSC_Lib {
|
|
299 |
$new_classes = array();
|
300 |
// Parse each value the same way.
|
301 |
foreach ( $classes as $key => $class ) {
|
302 |
-
$class
|
303 |
$new_classes = array_merge( $new_classes, $class );
|
304 |
}
|
305 |
|
72 |
public static function admin_footer() {
|
73 |
$plugin_data = get_plugin_data( WCSSC_FILE );
|
74 |
echo $plugin_data['Title'] // @codingStandardsIgnoreLine >> no valid esc function.
|
75 |
+
. ' | ' . esc_attr__( 'Version', WCSSC_Lib::DOMAIN ) . ' ' . esc_html( $plugin_data['Version'] )
|
76 |
+
. ' | ' . $plugin_data['Author'] // @codingStandardsIgnoreLine >> no valid esc function.
|
77 |
+
. ' | <a href="http://codebrainmedia.com">CodeBrain Media</a>'
|
78 |
+
. ' | <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=cindy@cleverness.org">' . esc_attr__( 'Donate', self::DOMAIN ) . '</a>
|
79 |
<br />';
|
80 |
}
|
81 |
|
184 |
if ( ! is_string( $key ) ) {
|
185 |
return false;
|
186 |
}
|
187 |
+
self::$settings = (array) self::$settings;
|
188 |
self::$settings[ $key ] = $settings;
|
189 |
+
$settings = self::$settings;
|
190 |
}
|
191 |
elseif ( ! is_array( $settings ) ) {
|
192 |
return false;
|
263 |
}
|
264 |
|
265 |
if ( is_string( $value ) ) {
|
266 |
+
$settings[ $key ] = wp_strip_all_tags( stripslashes( $value ) );
|
267 |
}
|
268 |
|
269 |
// Validate var types.
|
299 |
$new_classes = array();
|
300 |
// Parse each value the same way.
|
301 |
foreach ( $classes as $key => $class ) {
|
302 |
+
$class = self::parse_defined_classes( $class );
|
303 |
$new_classes = array_merge( $new_classes, $class );
|
304 |
}
|
305 |
|
includes/widget-css-classes-settings.class.php
CHANGED
@@ -5,7 +5,7 @@
|
|
5 |
* Settings
|
6 |
* @author C.M. Kendrick <cindy@cleverness.org>
|
7 |
* @package widget-css-classes
|
8 |
-
* @version 1.5.
|
9 |
*/
|
10 |
|
11 |
/**
|
@@ -16,10 +16,29 @@
|
|
16 |
*/
|
17 |
class WCSSC_Settings {
|
18 |
|
|
|
|
|
|
|
19 |
protected $general_key = '';
|
|
|
|
|
|
|
|
|
20 |
protected $plugin_key = 'widget-css-classes-settings';
|
|
|
|
|
|
|
|
|
21 |
protected $plugin_tabs = array();
|
|
|
|
|
|
|
|
|
22 |
protected $general_settings = array();
|
|
|
|
|
|
|
|
|
23 |
protected $current_tab = '';
|
24 |
|
25 |
public function __construct() {
|
@@ -31,7 +50,7 @@ class WCSSC_Settings {
|
|
31 |
|
32 |
public function load_settings() {
|
33 |
$this->general_settings = WCSSC_Lib::get_settings();
|
34 |
-
$this->general_key
|
35 |
}
|
36 |
|
37 |
public function section_general_desc() {
|
@@ -44,34 +63,95 @@ class WCSSC_Settings {
|
|
44 |
|
45 |
register_setting( $this->general_key, $this->general_key, array( $this, 'validate_input' ) );
|
46 |
add_settings_section( 'section_general', esc_attr__( 'Widget CSS Classes Settings', WCSSC_Lib::DOMAIN ), array( $this, 'section_general_desc' ), $this->general_key );
|
47 |
-
add_settings_field(
|
48 |
-
'
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
'
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
'
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
do_action( 'widget_css_classes_settings' );
|
76 |
}
|
77 |
|
@@ -195,13 +275,16 @@ class WCSSC_Settings {
|
|
195 |
$wcssc_message = 3;
|
196 |
if ( $_FILES['widget-css-classes-settings-import-file']['tmp_name'] ) {
|
197 |
$wcssc_message = 2;
|
198 |
-
$import
|
|
|
199 |
// @codingStandardsIgnoreLine >> yeah yeah, I know...
|
200 |
-
file_get_contents( $_FILES['widget-css-classes-settings-import-file']['tmp_name'] )
|
|
|
201 |
if ( array_shift( $import ) === '[START=WCSSC SETTINGS]' && array_pop( $import ) === '[STOP=WCSSC SETTINGS]' ) {
|
202 |
$options = WCSSC_Lib::get_settings();
|
203 |
foreach ( $import as $import_option ) {
|
204 |
list( $key, $value ) = explode( "\t", $import_option );
|
|
|
205 |
$options[ $key ] = json_decode( sanitize_text_field( $value ) );
|
206 |
if ( $options['dropdown'] ) { // Update for 1.3.0
|
207 |
$options['defined_classes'] = $options['dropdown'];
|
@@ -213,11 +296,15 @@ class WCSSC_Settings {
|
|
213 |
}
|
214 |
}
|
215 |
|
216 |
-
|
217 |
exit;
|
218 |
}
|
219 |
}
|
220 |
|
|
|
|
|
|
|
|
|
221 |
public function validate_input( $input ) {
|
222 |
WCSSC_Lib::set_settings( $input );
|
223 |
return WCSSC_Lib::get_settings();
|
5 |
* Settings
|
6 |
* @author C.M. Kendrick <cindy@cleverness.org>
|
7 |
* @package widget-css-classes
|
8 |
+
* @version 1.5.3
|
9 |
*/
|
10 |
|
11 |
/**
|
16 |
*/
|
17 |
class WCSSC_Settings {
|
18 |
|
19 |
+
/**
|
20 |
+
* @var string
|
21 |
+
*/
|
22 |
protected $general_key = '';
|
23 |
+
|
24 |
+
/**
|
25 |
+
* @var string
|
26 |
+
*/
|
27 |
protected $plugin_key = 'widget-css-classes-settings';
|
28 |
+
|
29 |
+
/**
|
30 |
+
* @var array
|
31 |
+
*/
|
32 |
protected $plugin_tabs = array();
|
33 |
+
|
34 |
+
/**
|
35 |
+
* @var array
|
36 |
+
*/
|
37 |
protected $general_settings = array();
|
38 |
+
|
39 |
+
/**
|
40 |
+
* @var string
|
41 |
+
*/
|
42 |
protected $current_tab = '';
|
43 |
|
44 |
public function __construct() {
|
50 |
|
51 |
public function load_settings() {
|
52 |
$this->general_settings = WCSSC_Lib::get_settings();
|
53 |
+
$this->general_key = WCSSC_Lib::$settings_key;
|
54 |
}
|
55 |
|
56 |
public function section_general_desc() {
|
63 |
|
64 |
register_setting( $this->general_key, $this->general_key, array( $this, 'validate_input' ) );
|
65 |
add_settings_section( 'section_general', esc_attr__( 'Widget CSS Classes Settings', WCSSC_Lib::DOMAIN ), array( $this, 'section_general_desc' ), $this->general_key );
|
66 |
+
add_settings_field(
|
67 |
+
'show_number',
|
68 |
+
esc_attr__( 'Add Widget Number Classes', WCSSC_Lib::DOMAIN ),
|
69 |
+
array( $this, 'show_yes_no_option' ),
|
70 |
+
$this->general_key,
|
71 |
+
'section_general',
|
72 |
+
array(
|
73 |
+
'key' => 'show_number',
|
74 |
+
)
|
75 |
+
);
|
76 |
+
add_settings_field(
|
77 |
+
'show_location',
|
78 |
+
esc_attr__( 'Add First/Last Classes', WCSSC_Lib::DOMAIN ),
|
79 |
+
array( $this, 'show_yes_no_option' ),
|
80 |
+
$this->general_key,
|
81 |
+
'section_general',
|
82 |
+
array(
|
83 |
+
'key' => 'show_location',
|
84 |
+
)
|
85 |
+
);
|
86 |
+
add_settings_field(
|
87 |
+
'show_evenodd',
|
88 |
+
esc_attr__( 'Add Even/Odd Classes', WCSSC_Lib::DOMAIN ),
|
89 |
+
array( $this, 'show_yes_no_option' ),
|
90 |
+
$this->general_key,
|
91 |
+
'section_general',
|
92 |
+
array(
|
93 |
+
'key' => 'show_evenodd',
|
94 |
+
)
|
95 |
+
);
|
96 |
+
add_settings_field(
|
97 |
+
'show_id',
|
98 |
+
esc_attr__( 'Show Additional Field for ID', WCSSC_Lib::DOMAIN ),
|
99 |
+
array( $this, 'show_yes_no_option' ),
|
100 |
+
$this->general_key,
|
101 |
+
'section_general',
|
102 |
+
array(
|
103 |
+
'key' => 'show_id',
|
104 |
+
)
|
105 |
+
);
|
106 |
+
add_settings_field(
|
107 |
+
'type',
|
108 |
+
esc_attr__( 'Class Field Type', WCSSC_Lib::DOMAIN ),
|
109 |
+
array( $this, 'type_option' ),
|
110 |
+
$this->general_key,
|
111 |
+
'section_general'
|
112 |
+
);
|
113 |
+
add_settings_field(
|
114 |
+
'defined_classes',
|
115 |
+
esc_attr__( 'Predefined Classes', WCSSC_Lib::DOMAIN ),
|
116 |
+
array( $this, 'defined_classes_option' ),
|
117 |
+
$this->general_key,
|
118 |
+
'section_general'
|
119 |
+
);
|
120 |
+
add_settings_field(
|
121 |
+
'fix_widget_params',
|
122 |
+
esc_attr__( 'Fix widget parameters', WCSSC_Lib::DOMAIN ),
|
123 |
+
array( $this, 'show_yes_no_option' ),
|
124 |
+
$this->general_key,
|
125 |
+
'section_general',
|
126 |
+
array(
|
127 |
+
'key' => 'fix_widget_params',
|
128 |
+
'desc' => esc_html__( 'Wrap widget in a <div> element if the parameters are invalid.', WCSSC_Lib::DOMAIN ),
|
129 |
+
)
|
130 |
+
);
|
131 |
+
add_settings_field(
|
132 |
+
'filter_unique',
|
133 |
+
esc_attr__( 'Remove duplicate classes', WCSSC_Lib::DOMAIN ),
|
134 |
+
array( $this, 'show_yes_no_option' ),
|
135 |
+
$this->general_key,
|
136 |
+
'section_general',
|
137 |
+
array(
|
138 |
+
'key' => 'filter_unique',
|
139 |
+
'desc' => esc_html__( 'Plugins that run after this plugin could still add duplicates.', WCSSC_Lib::DOMAIN ),
|
140 |
+
)
|
141 |
+
);
|
142 |
+
add_settings_field(
|
143 |
+
'translate_classes',
|
144 |
+
esc_attr__( 'Translate classes', WCSSC_Lib::DOMAIN ),
|
145 |
+
array( $this, 'show_yes_no_option' ),
|
146 |
+
$this->general_key,
|
147 |
+
'section_general',
|
148 |
+
array(
|
149 |
+
'key' => 'translate_classes',
|
150 |
+
'desc' => esc_html__( 'Translate classes like `widget-first` and `widget-even`.', WCSSC_Lib::DOMAIN )
|
151 |
+
// Translators: %s stands for a link to translate.wordpress.org.
|
152 |
+
. ' ' . sprintf( esc_html__( 'Translations are taken from %s', WCSSC_Lib::DOMAIN ), '<a href="https://translate.wordpress.org/projects/wp-plugins/widget-css-classes" target="_blank">translate.wordpress.org</a>' ),
|
153 |
+
)
|
154 |
+
);
|
155 |
do_action( 'widget_css_classes_settings' );
|
156 |
}
|
157 |
|
275 |
$wcssc_message = 3;
|
276 |
if ( $_FILES['widget-css-classes-settings-import-file']['tmp_name'] ) {
|
277 |
$wcssc_message = 2;
|
278 |
+
$import = explode(
|
279 |
+
"\n",
|
280 |
// @codingStandardsIgnoreLine >> yeah yeah, I know...
|
281 |
+
file_get_contents( $_FILES['widget-css-classes-settings-import-file']['tmp_name'] )
|
282 |
+
);
|
283 |
if ( array_shift( $import ) === '[START=WCSSC SETTINGS]' && array_pop( $import ) === '[STOP=WCSSC SETTINGS]' ) {
|
284 |
$options = WCSSC_Lib::get_settings();
|
285 |
foreach ( $import as $import_option ) {
|
286 |
list( $key, $value ) = explode( "\t", $import_option );
|
287 |
+
|
288 |
$options[ $key ] = json_decode( sanitize_text_field( $value ) );
|
289 |
if ( $options['dropdown'] ) { // Update for 1.3.0
|
290 |
$options['defined_classes'] = $options['dropdown'];
|
296 |
}
|
297 |
}
|
298 |
|
299 |
+
wp_safe_redirect( admin_url( '/options-general.php?page=widget-css-classes-settings&tab=importexport&wcssc_message=' . esc_attr( $wcssc_message ) ) );
|
300 |
exit;
|
301 |
}
|
302 |
}
|
303 |
|
304 |
+
/**
|
305 |
+
* @param array $input
|
306 |
+
* @return array
|
307 |
+
*/
|
308 |
public function validate_input( $input ) {
|
309 |
WCSSC_Lib::set_settings( $input );
|
310 |
return WCSSC_Lib::get_settings();
|
includes/widget-css-classes.class.php
CHANGED
@@ -5,7 +5,7 @@
|
|
5 |
* Loader
|
6 |
* @author C.M. Kendrick <cindy@cleverness.org>
|
7 |
* @package widget-css-classes
|
8 |
-
* @version 1.5.
|
9 |
*/
|
10 |
|
11 |
/**
|
@@ -123,14 +123,17 @@ class WCSSC {
|
|
123 |
*/
|
124 |
public static function extend_widget_form( $widget, $return, $instance ) {
|
125 |
self::init();
|
126 |
-
$instance = wp_parse_args(
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
|
|
|
|
|
|
134 |
$access_predefined = current_user_can( self::$caps['defined'] );
|
135 |
if ( ! $access_predefined ) {
|
136 |
$access_class = false;
|
@@ -203,8 +206,8 @@ class WCSSC {
|
|
203 |
*/
|
204 |
private static function do_id_field( $widget, $instance ) {
|
205 |
$field = '';
|
206 |
-
$id
|
207 |
-
$name
|
208 |
/**
|
209 |
* Change the label for the CSS ID form field.
|
210 |
*
|
@@ -230,8 +233,8 @@ class WCSSC {
|
|
230 |
*/
|
231 |
private static function do_class_field( $widget, $instance ) {
|
232 |
$field = '';
|
233 |
-
$id
|
234 |
-
$name
|
235 |
|
236 |
/**
|
237 |
* Change the label for the CSS Classes form field.
|
@@ -240,6 +243,7 @@ class WCSSC {
|
|
240 |
* @return string
|
241 |
*/
|
242 |
$label = apply_filters( 'widget_css_classes_class', esc_html__( 'CSS Classes', WCSSC_Lib::DOMAIN ) );
|
|
|
243 |
$field .= self::do_label( $label, $id );
|
244 |
|
245 |
$field .= "<input type='text' name='{$name}' id='{$id}' value='{$instance['classes']}' class='widefat' />";
|
@@ -258,10 +262,9 @@ class WCSSC {
|
|
258 |
* @return string
|
259 |
*/
|
260 |
private static function do_predefined_field( $widget, $instance, $do_class_field = null ) {
|
261 |
-
|
262 |
$field = '';
|
263 |
-
$id
|
264 |
-
$name
|
265 |
|
266 |
/**
|
267 |
* @see WCSSC::do_class_field()
|
@@ -309,6 +312,7 @@ class WCSSC {
|
|
309 |
if ( null !== $do_class_field ) {
|
310 |
if ( $do_class_field ) {
|
311 |
$field .= self::do_class_field( $widget, $instance );
|
|
|
312 |
$style['margin-top'] = 'margin-top: -10px;';
|
313 |
} else {
|
314 |
$field .= self::do_hidden( $widget->get_field_name( 'classes' ), $instance['classes'] );
|
@@ -318,7 +322,7 @@ class WCSSC {
|
|
318 |
$field .= self::do_label( $label, $id );
|
319 |
}
|
320 |
|
321 |
-
$style
|
322 |
$field .= "<ul id='{$id}' style='{$style}'>";
|
323 |
foreach ( $predefined_classes as $preset ) {
|
324 |
$preset_checked = '';
|
@@ -326,9 +330,11 @@ class WCSSC {
|
|
326 |
$preset_checked = ' checked="checked"';
|
327 |
}
|
328 |
$option_id = $id . '-' . esc_attr( $preset );
|
329 |
-
|
|
|
330 |
$option .= "<input id='{$option_id}' name='{$name}[]' type='checkbox' value='{$preset}' {$preset_checked} />";
|
331 |
$option .= ' ' . $preset . '</label>';
|
|
|
332 |
$field .= "<li>{$option}</li>";
|
333 |
}
|
334 |
$field .= '</ul>';
|
@@ -373,23 +379,26 @@ class WCSSC {
|
|
373 |
/**
|
374 |
* Updates the Widget with the classes
|
375 |
* @static
|
376 |
-
* @param $instance
|
377 |
-
* @param $new_instance
|
378 |
* @return array
|
379 |
* @since 1.0
|
380 |
*/
|
381 |
public static function update_widget( $instance, $new_instance ) {
|
382 |
self::init();
|
383 |
-
$new_instance = wp_parse_args(
|
384 |
-
|
385 |
-
|
386 |
-
|
|
|
|
|
|
|
387 |
|
388 |
if ( current_user_can( self::$caps['ids'] ) && WCSSC_Lib::get_settings( 'show_id' ) ) {
|
389 |
$instance['ids'] = sanitize_text_field( $new_instance['ids'] );
|
390 |
}
|
391 |
|
392 |
-
$access_class
|
393 |
$access_predefined = current_user_can( self::$caps['defined'] );
|
394 |
if ( ! $access_predefined ) {
|
395 |
$access_class = false;
|
@@ -418,6 +427,7 @@ class WCSSC {
|
|
418 |
|
419 |
// Remove empty and duplicate values and overwrite the original instance.
|
420 |
$new_classes = array_filter( array_unique( $new_classes ) );
|
|
|
421 |
$instance['classes'] = sanitize_text_field( implode( ' ', $new_classes ) );
|
422 |
}
|
423 |
|
@@ -439,7 +449,7 @@ class WCSSC {
|
|
439 |
* @todo Refactor to enable above checks.
|
440 |
*
|
441 |
* @static
|
442 |
-
* @param $params
|
443 |
* @return mixed
|
444 |
* @since 1.0
|
445 |
*/
|
@@ -481,7 +491,7 @@ class WCSSC {
|
|
481 |
// Add custom and predefined classes.
|
482 |
if ( ! empty( $widget_opt[ $widget_num ]['classes'] ) ) {
|
483 |
|
484 |
-
$custom_classes
|
485 |
$defined_classes = WCSSC_Lib::get_settings( 'defined_classes' );
|
486 |
|
487 |
// Order classes by predefined classes order and append the other (custom) classes.
|
@@ -520,9 +530,10 @@ class WCSSC {
|
|
520 |
} // End if().
|
521 |
|
522 |
// Add first, last, even, and odd classes.
|
523 |
-
if (
|
524 |
-
|
525 |
-
|
|
|
526 |
) {
|
527 |
|
528 |
if ( ! self::$widget_counter ) {
|
@@ -540,9 +551,10 @@ class WCSSC {
|
|
540 |
array_unshift( $classes, $class );
|
541 |
}
|
542 |
|
543 |
-
if (
|
544 |
-
|
545 |
-
|
|
|
546 |
) {
|
547 |
$widget_first = apply_filters( 'widget_css_classes_first', self::$core_classes['widget_first'] );
|
548 |
$widget_last = apply_filters( 'widget_css_classes_last', self::$core_classes['widget_last'] );
|
@@ -557,7 +569,7 @@ class WCSSC {
|
|
557 |
if ( WCSSC_Lib::get_settings( 'show_evenodd' ) ) {
|
558 |
$widget_even = apply_filters( 'widget_css_classes_even', self::$core_classes['widget_even'] );
|
559 |
$widget_odd = apply_filters( 'widget_css_classes_odd', self::$core_classes['widget_odd'] );
|
560 |
-
$class
|
561 |
array_unshift( $classes, $class );
|
562 |
}
|
563 |
|
@@ -675,7 +687,7 @@ class WCSSC {
|
|
675 |
} else {
|
676 |
$str = preg_replace(
|
677 |
'/' . preg_quote( $attr, '/' ) . '/',
|
678 |
-
$attr . $content_extra . ' '
|
679 |
$str,
|
680 |
1
|
681 |
);
|
@@ -690,6 +702,7 @@ class WCSSC {
|
|
690 |
*
|
691 |
* // Disable complexity check because of third part plugin handling.
|
692 |
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
|
|
693 |
*
|
694 |
* @static
|
695 |
* @since 1.5.0
|
@@ -700,16 +713,14 @@ class WCSSC {
|
|
700 |
$widget_opt = null;
|
701 |
|
702 |
$active_plugins = apply_filters( 'active_plugins', get_option( 'active_plugins' ) );
|
703 |
-
// If Widget Logic plugin is enabled, use it's callback
|
704 |
if ( in_array( 'widget-logic/widget_logic.php', $active_plugins, true ) ) {
|
705 |
$widget_logic_options = get_option( 'widget_logic' );
|
706 |
if ( ! empty( $widget_logic_options['widget_logic-options-filter'] ) ) {
|
707 |
$widget_opt = get_option( $widget_obj['callback_wl_redirect'][0]->option_name );
|
708 |
-
} else {
|
709 |
-
$widget_opt = get_option( $widget_obj['callback'][0]->option_name );
|
710 |
}
|
711 |
}
|
712 |
-
// If Widget Context plugin is enabled, use it's callback
|
713 |
elseif ( in_array( 'widget-context/widget-context.php', $active_plugins, true ) ) {
|
714 |
$callback = isset( $widget_obj['callback_original_wc'] ) ? $widget_obj['callback_original_wc'] : null;
|
715 |
$callback = ! $callback && isset( $widget_obj['callback'] ) ? $widget_obj['callback'] : null;
|
@@ -718,24 +729,34 @@ class WCSSC {
|
|
718 |
$widget_opt = get_option( $callback[0]->option_name );
|
719 |
}
|
720 |
}
|
721 |
-
// If Widget Output filter is enabled (f.e. by WP External Links plugin), don't use it's callback but the original callback
|
722 |
elseif ( isset( $widget_obj['_wo_original_callback'] ) ) {
|
723 |
$widget_opt = get_option( $widget_obj['_wo_original_callback'][0]->option_name );
|
724 |
}
|
725 |
|
726 |
-
// Default callback
|
727 |
-
|
728 |
-
// Check if WP Page Widget is in use
|
729 |
global $post;
|
730 |
$id = ( isset( $post->ID ) ? get_the_ID() : null );
|
731 |
if ( isset( $id ) && get_post_meta( $id, '_customize_sidebars' ) ) {
|
732 |
$custom_sidebarcheck = get_post_meta( $id, '_customize_sidebars' );
|
733 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
734 |
if ( isset( $custom_sidebarcheck[0] ) && ( 'yes' === $custom_sidebarcheck[0] ) ) {
|
735 |
-
$widget_opt = get_option( 'widget_' . $id . '_' . substr( $
|
736 |
-
}
|
737 |
-
|
738 |
-
|
|
|
739 |
}
|
740 |
}
|
741 |
|
5 |
* Loader
|
6 |
* @author C.M. Kendrick <cindy@cleverness.org>
|
7 |
* @package widget-css-classes
|
8 |
+
* @version 1.5.3
|
9 |
*/
|
10 |
|
11 |
/**
|
123 |
*/
|
124 |
public static function extend_widget_form( $widget, $return, $instance ) {
|
125 |
self::init();
|
126 |
+
$instance = wp_parse_args(
|
127 |
+
$instance,
|
128 |
+
array(
|
129 |
+
'ids' => '',
|
130 |
+
'classes' => '',
|
131 |
+
'classes-defined' => array(),
|
132 |
+
)
|
133 |
+
);
|
134 |
+
|
135 |
+
$access_id = current_user_can( self::$caps['ids'] );
|
136 |
+
$access_class = current_user_can( self::$caps['classes'] );
|
137 |
$access_predefined = current_user_can( self::$caps['defined'] );
|
138 |
if ( ! $access_predefined ) {
|
139 |
$access_class = false;
|
206 |
*/
|
207 |
private static function do_id_field( $widget, $instance ) {
|
208 |
$field = '';
|
209 |
+
$id = $widget->get_field_id( 'ids' );
|
210 |
+
$name = $widget->get_field_name( 'ids' );
|
211 |
/**
|
212 |
* Change the label for the CSS ID form field.
|
213 |
*
|
233 |
*/
|
234 |
private static function do_class_field( $widget, $instance ) {
|
235 |
$field = '';
|
236 |
+
$id = $widget->get_field_id( 'classes' );
|
237 |
+
$name = $widget->get_field_name( 'classes' );
|
238 |
|
239 |
/**
|
240 |
* Change the label for the CSS Classes form field.
|
243 |
* @return string
|
244 |
*/
|
245 |
$label = apply_filters( 'widget_css_classes_class', esc_html__( 'CSS Classes', WCSSC_Lib::DOMAIN ) );
|
246 |
+
|
247 |
$field .= self::do_label( $label, $id );
|
248 |
|
249 |
$field .= "<input type='text' name='{$name}' id='{$id}' value='{$instance['classes']}' class='widefat' />";
|
262 |
* @return string
|
263 |
*/
|
264 |
private static function do_predefined_field( $widget, $instance, $do_class_field = null ) {
|
|
|
265 |
$field = '';
|
266 |
+
$id = $widget->get_field_id( 'classes-defined' );
|
267 |
+
$name = $widget->get_field_name( 'classes-defined' );
|
268 |
|
269 |
/**
|
270 |
* @see WCSSC::do_class_field()
|
312 |
if ( null !== $do_class_field ) {
|
313 |
if ( $do_class_field ) {
|
314 |
$field .= self::do_class_field( $widget, $instance );
|
315 |
+
|
316 |
$style['margin-top'] = 'margin-top: -10px;';
|
317 |
} else {
|
318 |
$field .= self::do_hidden( $widget->get_field_name( 'classes' ), $instance['classes'] );
|
322 |
$field .= self::do_label( $label, $id );
|
323 |
}
|
324 |
|
325 |
+
$style = implode( ' ', $style );
|
326 |
$field .= "<ul id='{$id}' style='{$style}'>";
|
327 |
foreach ( $predefined_classes as $preset ) {
|
328 |
$preset_checked = '';
|
330 |
$preset_checked = ' checked="checked"';
|
331 |
}
|
332 |
$option_id = $id . '-' . esc_attr( $preset );
|
333 |
+
|
334 |
+
$option = "<label for='{$option_id}'>";
|
335 |
$option .= "<input id='{$option_id}' name='{$name}[]' type='checkbox' value='{$preset}' {$preset_checked} />";
|
336 |
$option .= ' ' . $preset . '</label>';
|
337 |
+
|
338 |
$field .= "<li>{$option}</li>";
|
339 |
}
|
340 |
$field .= '</ul>';
|
379 |
/**
|
380 |
* Updates the Widget with the classes
|
381 |
* @static
|
382 |
+
* @param array $instance
|
383 |
+
* @param array $new_instance
|
384 |
* @return array
|
385 |
* @since 1.0
|
386 |
*/
|
387 |
public static function update_widget( $instance, $new_instance ) {
|
388 |
self::init();
|
389 |
+
$new_instance = wp_parse_args(
|
390 |
+
$new_instance,
|
391 |
+
array(
|
392 |
+
'classes' => null,
|
393 |
+
'classes-defined' => array(),
|
394 |
+
)
|
395 |
+
);
|
396 |
|
397 |
if ( current_user_can( self::$caps['ids'] ) && WCSSC_Lib::get_settings( 'show_id' ) ) {
|
398 |
$instance['ids'] = sanitize_text_field( $new_instance['ids'] );
|
399 |
}
|
400 |
|
401 |
+
$access_class = current_user_can( self::$caps['classes'] );
|
402 |
$access_predefined = current_user_can( self::$caps['defined'] );
|
403 |
if ( ! $access_predefined ) {
|
404 |
$access_class = false;
|
427 |
|
428 |
// Remove empty and duplicate values and overwrite the original instance.
|
429 |
$new_classes = array_filter( array_unique( $new_classes ) );
|
430 |
+
|
431 |
$instance['classes'] = sanitize_text_field( implode( ' ', $new_classes ) );
|
432 |
}
|
433 |
|
449 |
* @todo Refactor to enable above checks.
|
450 |
*
|
451 |
* @static
|
452 |
+
* @param array $params
|
453 |
* @return mixed
|
454 |
* @since 1.0
|
455 |
*/
|
491 |
// Add custom and predefined classes.
|
492 |
if ( ! empty( $widget_opt[ $widget_num ]['classes'] ) ) {
|
493 |
|
494 |
+
$custom_classes = explode( ' ', (string) $widget_opt[ $widget_num ]['classes'] );
|
495 |
$defined_classes = WCSSC_Lib::get_settings( 'defined_classes' );
|
496 |
|
497 |
// Order classes by predefined classes order and append the other (custom) classes.
|
530 |
} // End if().
|
531 |
|
532 |
// Add first, last, even, and odd classes.
|
533 |
+
if (
|
534 |
+
WCSSC_Lib::get_settings( 'show_number' )
|
535 |
+
|| WCSSC_Lib::get_settings( 'show_location' )
|
536 |
+
|| WCSSC_Lib::get_settings( 'show_evenodd' )
|
537 |
) {
|
538 |
|
539 |
if ( ! self::$widget_counter ) {
|
551 |
array_unshift( $classes, $class );
|
552 |
}
|
553 |
|
554 |
+
if (
|
555 |
+
WCSSC_Lib::get_settings( 'show_location' )
|
556 |
+
&& isset( $arr_registered_widgets[ $this_id ] )
|
557 |
+
&& is_array( $arr_registered_widgets[ $this_id ] )
|
558 |
) {
|
559 |
$widget_first = apply_filters( 'widget_css_classes_first', self::$core_classes['widget_first'] );
|
560 |
$widget_last = apply_filters( 'widget_css_classes_last', self::$core_classes['widget_last'] );
|
569 |
if ( WCSSC_Lib::get_settings( 'show_evenodd' ) ) {
|
570 |
$widget_even = apply_filters( 'widget_css_classes_even', self::$core_classes['widget_even'] );
|
571 |
$widget_odd = apply_filters( 'widget_css_classes_odd', self::$core_classes['widget_odd'] );
|
572 |
+
$class = ( ( self::$widget_counter[ $this_id ] % 2 ) ? $widget_odd : $widget_even );
|
573 |
array_unshift( $classes, $class );
|
574 |
}
|
575 |
|
687 |
} else {
|
688 |
$str = preg_replace(
|
689 |
'/' . preg_quote( $attr, '/' ) . '/',
|
690 |
+
$attr . $content_extra . ' ',
|
691 |
$str,
|
692 |
1
|
693 |
);
|
702 |
*
|
703 |
* // Disable complexity check because of third part plugin handling.
|
704 |
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
705 |
+
* @SuppressWarnings(PHPMD.NPathComplexity)
|
706 |
*
|
707 |
* @static
|
708 |
* @since 1.5.0
|
713 |
$widget_opt = null;
|
714 |
|
715 |
$active_plugins = apply_filters( 'active_plugins', get_option( 'active_plugins' ) );
|
716 |
+
// If Widget Logic plugin is enabled, use it's callback.
|
717 |
if ( in_array( 'widget-logic/widget_logic.php', $active_plugins, true ) ) {
|
718 |
$widget_logic_options = get_option( 'widget_logic' );
|
719 |
if ( ! empty( $widget_logic_options['widget_logic-options-filter'] ) ) {
|
720 |
$widget_opt = get_option( $widget_obj['callback_wl_redirect'][0]->option_name );
|
|
|
|
|
721 |
}
|
722 |
}
|
723 |
+
// If Widget Context plugin is enabled, use it's callback.
|
724 |
elseif ( in_array( 'widget-context/widget-context.php', $active_plugins, true ) ) {
|
725 |
$callback = isset( $widget_obj['callback_original_wc'] ) ? $widget_obj['callback_original_wc'] : null;
|
726 |
$callback = ! $callback && isset( $widget_obj['callback'] ) ? $widget_obj['callback'] : null;
|
729 |
$widget_opt = get_option( $callback[0]->option_name );
|
730 |
}
|
731 |
}
|
732 |
+
// If Widget Output filter is enabled (f.e. by WP External Links plugin), don't use it's callback but the original callback.
|
733 |
elseif ( isset( $widget_obj['_wo_original_callback'] ) ) {
|
734 |
$widget_opt = get_option( $widget_obj['_wo_original_callback'][0]->option_name );
|
735 |
}
|
736 |
|
737 |
+
// Default callback.
|
738 |
+
if ( null === $widget_opt ) {
|
739 |
+
// Check if WP Page Widget is in use.
|
740 |
global $post;
|
741 |
$id = ( isset( $post->ID ) ? get_the_ID() : null );
|
742 |
if ( isset( $id ) && get_post_meta( $id, '_customize_sidebars' ) ) {
|
743 |
$custom_sidebarcheck = get_post_meta( $id, '_customize_sidebars' );
|
744 |
}
|
745 |
+
|
746 |
+
$option_name = '';
|
747 |
+
if ( isset( $widget_obj['callback'][0]->option_name ) ) {
|
748 |
+
$option_name = $widget_obj['callback'][0]->option_name;
|
749 |
+
} elseif ( isset( $widget_obj['original_callback'][0]->option_name ) ) {
|
750 |
+
// @since 1.5.3 Compatibility with dFactory Responsive Lightbox plugin.
|
751 |
+
$option_name = $widget_obj['original_callback'][0]->option_name;
|
752 |
+
}
|
753 |
+
|
754 |
if ( isset( $custom_sidebarcheck[0] ) && ( 'yes' === $custom_sidebarcheck[0] ) ) {
|
755 |
+
$widget_opt = get_option( 'widget_' . $id . '_' . substr( $option_name, 7 ) );
|
756 |
+
}
|
757 |
+
elseif ( $option_name ) {
|
758 |
+
// Default.
|
759 |
+
$widget_opt = get_option( $option_name );
|
760 |
}
|
761 |
}
|
762 |
|
js/widget-css-classes.js
CHANGED
@@ -3,10 +3,11 @@
|
|
3 |
*
|
4 |
* @author C.M. Kendrick <cindy@cleverness.org>
|
5 |
* @package widget-css-classes
|
6 |
-
* @version 1.5.
|
|
|
7 |
*/
|
8 |
|
9 |
-
jQuery(
|
10 |
|
11 |
// Change opacity if predefined classes is disabled.
|
12 |
$( 'input.wcssc_type' ).on( 'change', function() {
|
@@ -42,4 +43,4 @@ jQuery( document ).ready( function ( $ ) {
|
|
42 |
});
|
43 |
}
|
44 |
|
45 |
-
} );
|
3 |
*
|
4 |
* @author C.M. Kendrick <cindy@cleverness.org>
|
5 |
* @package widget-css-classes
|
6 |
+
* @version 1.5.3
|
7 |
+
* @preserve
|
8 |
*/
|
9 |
|
10 |
+
jQuery( function ( $ ) {
|
11 |
|
12 |
// Change opacity if predefined classes is disabled.
|
13 |
$( 'input.wcssc_type' ).on( 'change', function() {
|
43 |
});
|
44 |
}
|
45 |
|
46 |
+
} );
|
readme.txt
CHANGED
@@ -7,9 +7,9 @@ Tags: widgets, classes, css, widget classes, widget css
|
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
Requires at least: 3.3
|
10 |
-
Tested up to:
|
11 |
Requires PHP: 5.2.4
|
12 |
-
Stable tag: 1.5.
|
13 |
|
14 |
Add custom classes and ids plus first, last, even, odd, and numbered classes to your widgets.
|
15 |
|
@@ -96,6 +96,10 @@ Please file a [bug report on GitHub](https://github.com/cleverness/widget-css-cl
|
|
96 |
|
97 |
== Changelog ==
|
98 |
|
|
|
|
|
|
|
|
|
99 |
= 1.5.2.1 =
|
100 |
* **i18n:** Remove sv_SE translation from the plugin directory. It's 95% on translate.wordpress.org and accepted as the better version. [#23](https://github.com/cleverness/widget-css-classes/issues/23)
|
101 |
* **Documentation:** Readme & Wiki. [#31](https://github.com/cleverness/widget-css-classes/issues/31)
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
Requires at least: 3.3
|
10 |
+
Tested up to: 5.0
|
11 |
Requires PHP: 5.2.4
|
12 |
+
Stable tag: 1.5.3
|
13 |
|
14 |
Add custom classes and ids plus first, last, even, odd, and numbered classes to your widgets.
|
15 |
|
96 |
|
97 |
== Changelog ==
|
98 |
|
99 |
+
= 1.5.3 =
|
100 |
+
* **Compatibility:** dFactory Responsive Lightbox widget option. #33
|
101 |
+
* Tested with WP 5.0.
|
102 |
+
|
103 |
= 1.5.2.1 =
|
104 |
* **i18n:** Remove sv_SE translation from the plugin directory. It's 95% on translate.wordpress.org and accepted as the better version. [#23](https://github.com/cleverness/widget-css-classes/issues/23)
|
105 |
* **Documentation:** Readme & Wiki. [#31](https://github.com/cleverness/widget-css-classes/issues/31)
|
widget-css-classes.php
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
* Plugin Name: Widget CSS Classes
|
4 |
-
* Version: 1.5.
|
5 |
* Description: Add custom, first, last, even, odd, and numbered classes to your widgets.
|
6 |
* Author: C.M. Kendrick
|
7 |
* Author URI: http://cleverness.org
|
@@ -27,7 +27,7 @@ function widget_css_classes_loader() {
|
|
27 |
|
28 |
if ( is_admin() ) {
|
29 |
|
30 |
-
if ( ! defined( 'WCSSC_PLUGIN_VERSION' ) ) define( 'WCSSC_PLUGIN_VERSION', '1.5.
|
31 |
if ( ! defined( 'WCSSC_FILE' ) ) define( 'WCSSC_FILE', __FILE__ );
|
32 |
if ( ! defined( 'WCSSC_BASENAME' ) ) define( 'WCSSC_BASENAME', plugin_basename( __FILE__ ) );
|
33 |
if ( ! defined( 'WCSSC_PLUGIN_DIR' ) ) define( 'WCSSC_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
|
@@ -61,13 +61,13 @@ function widget_css_classes_activation() {
|
|
61 |
// Add admin notice.
|
62 |
add_action( 'admin_notices', 'widget_css_classes_notice_wp_version' );
|
63 |
// Deactivate.
|
64 |
-
require_once
|
65 |
deactivate_plugins( plugin_basename( __FILE__ ) );
|
66 |
return;
|
67 |
}
|
68 |
|
69 |
if ( ! defined( 'WCSSC_BASENAME' ) ) define( 'WCSSC_BASENAME', plugin_basename( __FILE__ ) );
|
70 |
-
if ( ! defined( 'WCSSC_DB_VERSION' ) ) define( 'WCSSC_DB_VERSION', '1.5.
|
71 |
if ( ! defined( 'WCSSC_FILE' ) ) define( 'WCSSC_FILE', __FILE__ );
|
72 |
include_once 'includes/widget-css-classes-library.class.php';
|
73 |
|
1 |
<?php
|
2 |
/**
|
3 |
* Plugin Name: Widget CSS Classes
|
4 |
+
* Version: 1.5.3
|
5 |
* Description: Add custom, first, last, even, odd, and numbered classes to your widgets.
|
6 |
* Author: C.M. Kendrick
|
7 |
* Author URI: http://cleverness.org
|
27 |
|
28 |
if ( is_admin() ) {
|
29 |
|
30 |
+
if ( ! defined( 'WCSSC_PLUGIN_VERSION' ) ) define( 'WCSSC_PLUGIN_VERSION', '1.5.3' );
|
31 |
if ( ! defined( 'WCSSC_FILE' ) ) define( 'WCSSC_FILE', __FILE__ );
|
32 |
if ( ! defined( 'WCSSC_BASENAME' ) ) define( 'WCSSC_BASENAME', plugin_basename( __FILE__ ) );
|
33 |
if ( ! defined( 'WCSSC_PLUGIN_DIR' ) ) define( 'WCSSC_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
|
61 |
// Add admin notice.
|
62 |
add_action( 'admin_notices', 'widget_css_classes_notice_wp_version' );
|
63 |
// Deactivate.
|
64 |
+
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
65 |
deactivate_plugins( plugin_basename( __FILE__ ) );
|
66 |
return;
|
67 |
}
|
68 |
|
69 |
if ( ! defined( 'WCSSC_BASENAME' ) ) define( 'WCSSC_BASENAME', plugin_basename( __FILE__ ) );
|
70 |
+
if ( ! defined( 'WCSSC_DB_VERSION' ) ) define( 'WCSSC_DB_VERSION', '1.5.3' );
|
71 |
if ( ! defined( 'WCSSC_FILE' ) ) define( 'WCSSC_FILE', __FILE__ );
|
72 |
include_once 'includes/widget-css-classes-library.class.php';
|
73 |
|