33 * @author Jory Hogeveen <[email protected] > 44 * @package Genesis_Widget_Column_Classes
55 * @since 0.1.0
6- * @version 1.2.4.1
6+ * @version 1.3.0
77 * @licence GPL-2.0+
88 * @link https://github.com/JoryHogeveen/genesis-widget-column-classes
99 *
1010 * @wordpress-plugin
1111 * Plugin Name: Genesis Widget Column Classes
1212 * Plugin URI: https://wordpress.org/plugins/genesis-widget-column-classes/
1313 * Description: Add Genesis (old Bootstrap) column classes to widgets
14- * Version: 1.2.4.1
14+ * Version: 1.3
1515 * Author: Jory Hogeveen
1616 * Author URI: http://www.keraweb.nl
1717 * Text Domain: genesis-widget-column-classes
5050 * @author Jory Hogeveen <[email protected] > 5151 * @package Genesis_Widget_Column_Classes
5252 * @since 0.1.0
53- * @version 1.2.4.1
53+ * @version 1.3.0
5454 */
5555final class WCC_Genesis_Widget_Column_Classes
5656{
@@ -114,6 +114,14 @@ final class WCC_Genesis_Widget_Column_Classes
114114 'five-sixths ' => 'five-sixths ' ,
115115 );
116116
117+ /**
118+ * Allow multiple classes to be selected.
119+ *
120+ * @since 1.3.0
121+ * @var bool
122+ */
123+ private $ select_multiple = false ;
124+
117125 /**
118126 * Current user object.
119127 *
@@ -181,6 +189,16 @@ public function init() {
181189 */
182190 $ this ->cap = apply_filters ( 'genesis_widget_column_classes_capability ' , $ this ->cap );
183191
192+ /**
193+ * Allow multiple classes to be selected.
194+ * Default: false.
195+ *
196+ * @since 1.3.0
197+ * @param bool
198+ * @return bool
199+ */
200+ $ this ->select_multiple = apply_filters ( 'genesis_widget_column_classes_select_multiple ' , false );
201+
184202 // Get the current user.
185203 $ this ->curUser = wp_get_current_user ();
186204
@@ -242,6 +260,7 @@ public function action_ignore_genesis_notice() {
242260 * Add options to the widgets.
243261 *
244262 * @since 0.1.0
263+ * @since 1.3.0 Multi select support.
245264 * @access public
246265 * @param array $instance
247266 * @param \WP_Widget $widget
@@ -252,7 +271,7 @@ public function filter_widget_form_extend( $instance, $widget ) {
252271 $ instance = wp_parse_args (
253272 (array ) $ instance ,
254273 array (
255- 'column-classes ' => '' ,
274+ 'column-classes ' => '' ,
256275 'column-classes-first ' => '' ,
257276 )
258277 );
@@ -265,20 +284,95 @@ public function filter_widget_form_extend( $instance, $widget ) {
265284 return $ instance ;
266285 }
267286
268- $ row = '<p style="border: 1px solid #eee; padding: 5px 10px; background: #f5f5f5;"> ' ;
287+ $ field_name = $ widget ->get_field_name ( 'column-classes ' );
288+ $ field_id = $ widget ->get_field_id ( 'column-classes ' );
289+
290+ $ background = '#f5f5f5 ' ;
291+ $ border = '#eee ' ;
292+ $ background_select = '#fff ' ;
293+ $ border_select = '#ccc ' ;
294+ if ( $ this ->is_using_dark_mode () ) {
295+ $ background = '#191f25 ' ;
296+ $ border = '#000 ' ;
297+ $ background_select = '#000 ' ;
298+ $ border_select = '#32373c ' ;
299+ }
300+
301+ $ row = '<p style="border: 1px solid ' . $ border . '; padding: 5px 10px; background-color: ' . $ background . ';"> ' ;
269302 $ row .= '<label for=" ' . $ widget ->get_field_id ( 'column-classes ' ) . '"> ' . __ ( 'Width ' , self ::$ _domain ) . ': </label> ' ;
270- $ row .= '<select name=" ' . $ widget ->get_field_name ( 'column-classes ' ) . '" id=" ' . $ widget ->get_field_id ( 'column-classes ' ) . '"> ' ;
271303
272- $ row .= '<option value="">- ' . __ ( 'none ' , self ::$ _domain ) . ' -</option> ' ;
304+ $ row_column = '' ;
305+
306+ $ instance ['column-classes ' ] = explode ( ' ' , $ instance ['column-classes ' ] );
307+ $ column_classes = $ this ->get_column_classes ();
308+
309+ if ( $ this ->select_multiple ) {
310+ // Selected first.
311+ $ column_classes = array_replace ( array_flip ( $ instance ['column-classes ' ] ), $ column_classes );
312+ } else {
313+ $ instance ['column-classes ' ] = array ( $ instance ['column-classes ' ][0 ] );
314+ }
273315
274- foreach ( $ this -> get_column_classes () as $ class_name ) {
316+ foreach ( $ column_classes as $ class_name ) {
275317 if ( ! empty ( $ class_name ) ) {
276318 $ class_label = $ class_name ;
277- $ row .= '<option value=" ' . $ class_name . '" ' . selected ( $ instance ['column-classes ' ], $ class_name , false ) . '> ' . $ class_label . '</option> ' ;
319+ $ selected = in_array ( $ class_name , $ instance ['column-classes ' ], true );
320+ if ( $ this ->select_multiple ) {
321+ $ row_column .= '<label><input type="checkbox" name=" ' . $ field_name . '[]" value=" ' . $ class_name . '" ' . checked ( $ selected , true , false ) . '> ' . $ class_label . '</label> ' ;
322+ } else {
323+ $ row_column .= '<option value=" ' . $ class_name . '" ' . selected ( $ selected , true , false ) . '> ' . $ class_label . '</option> ' ;
324+ }
278325 }
279326 }
280327
281- $ row .= '</select> ' ;
328+ if ( $ this ->select_multiple ) {
329+ $ row .= '<span id=" ' . $ field_id . '" class="multiselect"><span> ' ;
330+ $ row .= $ row_column ;
331+ $ row .= '</span></span> ' ;
332+ ?>
333+ <style>
334+ #<?php echo $ field_id ; ?> .multiselect {
335+ position: relative;
336+ height: 26px;
337+ width: 130px;
338+ display: inline-block;
339+ vertical-align: middle;
340+ overflow: visible;
341+ }
342+ #<?php echo $ field_id ; ?> .multiselect label {
343+ display: block;
344+ line-height: 22px;
345+ padding-right: 1em;
346+ white-space: nowrap;
347+ }
348+ #<?php echo $ field_id ; ?> .multiselect span {
349+ position: absolute;
350+ border: 1px solid <?php echo $ border_select ; ?> ;
351+ background: <?php echo $ background_select ; ?> ;
352+ height: 22px;
353+ max-height: 22px;
354+ overflow: hidden;
355+ overflow-y: scroll;
356+ padding: 1px 3px;
357+ width: 120px;
358+ display: inline-block;
359+ transition: max-height .2s;
360+ }
361+ #<?php echo $ field_id ; ?> .multiselect:hover span {
362+ height: auto;
363+ max-height: 200px;
364+ width: auto;
365+ box-shadow: 0 1px 3px rgba(0,0,0,0.1);
366+ }
367+ </style>
368+ <?php
369+ } else {
370+ $ row .= '<select name=" ' . $ field_name . '" id=" ' . $ field_id . '"> ' ;
371+ $ row .= '<option value="">- ' . __ ( 'none ' , self ::$ _domain ) . ' -</option> ' ;
372+ $ row .= $ row_column ;
373+ $ row .= '</select> ' ;
374+ }
375+
282376 $ row .= '<label for=" ' . $ widget ->get_field_id ( 'column-classes-first ' ) . '"> ' . __ ( 'First ' , self ::$ _domain ) . ': </label> ' ;
283377 $ row .= '<input type="checkbox" value="1" name=" ' . $ widget ->get_field_name ( 'column-classes-first ' ) . '" id=" ' . $ widget ->get_field_id ( 'column-classes-first ' ) . '" ' . checked ( $ instance ['column-classes-first ' ], 1 , false ) . '> ' ;
284378 $ row .= '</p> ' ;
@@ -291,7 +385,8 @@ public function filter_widget_form_extend( $instance, $widget ) {
291385 * Add the new fields to the update instance.
292386 *
293387 * @since 0.1.0
294- * @since 0.2.2 Do not save empty data.
388+ * @since 1.2.2 Do not save empty data.
389+ * @since 1.3.0 Multi select support.
295390 * @access public
296391 * @param array $instance
297392 * @param array $new_instance
@@ -302,6 +397,10 @@ public function filter_widget_update_callback( $instance, $new_instance ) {
302397 unset( $ instance ['column-classes-first ' ] );
303398
304399 if ( ! empty ( $ new_instance ['column-classes ' ] ) ) {
400+ if ( is_array ( $ new_instance ['column-classes ' ] ) ) {
401+ $ new_instance ['column-classes ' ] = array_filter ( $ new_instance ['column-classes ' ] );
402+ $ new_instance ['column-classes ' ] = implode ( ' ' , $ new_instance ['column-classes ' ] );
403+ }
305404 $ instance ['column-classes ' ] = esc_attr ( $ new_instance ['column-classes ' ] );
306405 }
307406 if ( ! empty ( $ new_instance ['column-classes-first ' ] ) ) {
@@ -328,7 +427,7 @@ public function filter_dynamic_sidebar_params( $params ) {
328427 if ( empty ( $ params [0 ]['widget_id ' ] ) ) {
329428 return $ params ;
330429 }
331- $ widget_id = $ params [0 ]['widget_id ' ];
430+ $ widget_id = $ params [0 ]['widget_id ' ];
332431
333432 if ( empty ( $ wp_registered_widgets [ $ widget_id ] ) ) {
334433 return $ params ;
@@ -367,6 +466,7 @@ public function filter_dynamic_sidebar_params( $params ) {
367466 }
368467
369468 $ classes = $ this ->get_widget_classes ( $ widget_opt [ $ widget_num ], array () );
469+
370470 $ params [0 ] = $ this ->add_widget_classes ( $ params [0 ], $ classes );
371471 // $params[0]['before_widget'] = str_replace( 'class="', 'class="'.$classes_extra , $params[0]['before_widget'] );
372472
@@ -475,7 +575,7 @@ public function append_to_attribute( $str, $attr, $content_extra, $unique = fals
475575 } else {
476576 $ str = preg_replace (
477577 '/ ' . preg_quote ( $ attr , '/ ' ) . '/ ' ,
478- $ attr . $ content_extra . ' ' ,
578+ $ attr . $ content_extra . ' ' ,
479579 $ str ,
480580 1
481581 );
@@ -543,8 +643,9 @@ public function get_column_classes() {
543643 public function action_plugin_row_meta ( $ links , $ file ) {
544644 if ( self ::$ _basename === $ file ) {
545645 foreach ( $ this ->get_links () as $ id => $ link ) {
546- $ icon = '<span class="dashicons ' . $ link ['icon ' ] . '" style="font-size: inherit; line-height: inherit; display: inline; vertical-align: text-top;"></span> ' ;
646+ $ icon = '<span class="dashicons ' . $ link ['icon ' ] . '" style="font-size: inherit; line-height: inherit; display: inline; vertical-align: text-top;"></span> ' ;
547647 $ title = $ icon . ' ' . esc_html ( $ link ['title ' ] );
648+
548649 $ links [ $ id ] = '<a href=" ' . esc_url ( $ link ['url ' ] ) . '" target="_blank"> ' . $ title . '</a> ' ;
549650 }
550651 }
@@ -564,59 +665,59 @@ public function get_links() {
564665 }
565666
566667 $ links = array (
567- 'support ' => array (
568- 'title ' => __ ( 'Support ' , self ::$ _domain ),
668+ 'support ' => array (
669+ 'title ' => __ ( 'Support ' , self ::$ _domain ),
569670 'description ' => __ ( 'Need support? ' , self ::$ _domain ),
570- 'icon ' => 'dashicons-sos ' ,
571- 'url ' => 'https://wordpress.org/support/plugin/genesis-widget-column-classes/ ' ,
671+ 'icon ' => 'dashicons-sos ' ,
672+ 'url ' => 'https://wordpress.org/support/plugin/genesis-widget-column-classes/ ' ,
572673 ),
573- 'slack ' => array (
574- 'title ' => __ ( 'Slack ' , self ::$ _domain ),
674+ 'slack ' => array (
675+ 'title ' => __ ( 'Slack ' , self ::$ _domain ),
575676 'description ' => __ ( 'Quick help via Slack ' , self ::$ _domain ),
576- 'icon ' => 'dashicons-format-chat ' ,
577- 'url ' => 'https://keraweb.slack.com/messages/plugin-gwcc/ ' ,
677+ 'icon ' => 'dashicons-format-chat ' ,
678+ 'url ' => 'https://keraweb.slack.com/messages/plugin-gwcc/ ' ,
578679 ),
579- 'review ' => array (
580- 'title ' => __ ( 'Review ' , self ::$ _domain ),
680+ 'review ' => array (
681+ 'title ' => __ ( 'Review ' , self ::$ _domain ),
581682 'description ' => __ ( 'Give 5 stars on WordPress.org! ' , self ::$ _domain ),
582- 'icon ' => 'dashicons-star-filled ' ,
583- 'url ' => 'https://wordpress.org/support/plugin/genesis-widget-column-classes/reviews/ ' ,
683+ 'icon ' => 'dashicons-star-filled ' ,
684+ 'url ' => 'https://wordpress.org/support/plugin/genesis-widget-column-classes/reviews/ ' ,
584685 ),
585686 'translate ' => array (
586- 'title ' => __ ( 'Translate ' , self ::$ _domain ),
687+ 'title ' => __ ( 'Translate ' , self ::$ _domain ),
587688 'description ' => __ ( 'Help translating this plugin! ' , self ::$ _domain ),
588- 'icon ' => 'dashicons-translation ' ,
589- 'url ' => 'https://translate.wordpress.org/projects/wp-plugins/genesis-widget-column-classes ' ,
689+ 'icon ' => 'dashicons-translation ' ,
690+ 'url ' => 'https://translate.wordpress.org/projects/wp-plugins/genesis-widget-column-classes ' ,
590691 ),
591- 'issue ' => array (
592- 'title ' => __ ( 'Report issue ' , self ::$ _domain ),
692+ 'issue ' => array (
693+ 'title ' => __ ( 'Report issue ' , self ::$ _domain ),
593694 'description ' => __ ( 'Have ideas or a bug report? ' , self ::$ _domain ),
594- 'icon ' => 'dashicons-lightbulb ' ,
595- 'url ' => 'https://github.com/JoryHogeveen/genesis-widget-column-classes/issues ' ,
695+ 'icon ' => 'dashicons-lightbulb ' ,
696+ 'url ' => 'https://github.com/JoryHogeveen/genesis-widget-column-classes/issues ' ,
596697 ),
597- 'docs ' => array (
598- 'title ' => __ ( 'Documentation ' , self ::$ _domain ),
698+ 'docs ' => array (
699+ 'title ' => __ ( 'Documentation ' , self ::$ _domain ),
599700 'description ' => __ ( 'Documentation ' , self ::$ _domain ),
600- 'icon ' => 'dashicons-book-alt ' ,
601- 'url ' => 'https://github.com/JoryHogeveen/genesis-widget-column-classes/ ' , //wiki
701+ 'icon ' => 'dashicons-book-alt ' ,
702+ 'url ' => 'https://github.com/JoryHogeveen/genesis-widget-column-classes/ ' , //wiki
602703 ),
603- 'github ' => array (
604- 'title ' => __ ( 'GitHub ' , self ::$ _domain ),
704+ 'github ' => array (
705+ 'title ' => __ ( 'GitHub ' , self ::$ _domain ),
605706 'description ' => __ ( 'Follow and/or contribute on GitHub ' , self ::$ _domain ),
606- 'icon ' => 'dashicons-editor-code ' ,
607- 'url ' => 'https://github.com/JoryHogeveen/genesis-widget-column-classes/tree/dev ' ,
707+ 'icon ' => 'dashicons-editor-code ' ,
708+ 'url ' => 'https://github.com/JoryHogeveen/genesis-widget-column-classes/tree/dev ' ,
608709 ),
609- 'donate ' => array (
610- 'title ' => __ ( 'Donate ' , self ::$ _domain ),
710+ 'donate ' => array (
711+ 'title ' => __ ( 'Donate ' , self ::$ _domain ),
611712 'description ' => __ ( 'Buy me a coffee! ' , self ::$ _domain ),
612- 'icon ' => 'dashicons-smiley ' ,
613- 'url ' => 'https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=YGPLMLU7XQ9E8&lc=NL&item_name=Genesis%20Widget%20Column%20Classes&item_number=JWPP%2dGWCC¤cy_code=EUR&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted ' ,
713+ 'icon ' => 'dashicons-smiley ' ,
714+ 'url ' => 'https://www.keraweb.nl/donate.php?for=genesis-widget-column-classes ' ,
614715 ),
615- 'plugins ' => array (
616- 'title ' => __ ( 'Plugins ' , self ::$ _domain ),
716+ 'plugins ' => array (
717+ 'title ' => __ ( 'Plugins ' , self ::$ _domain ),
617718 'description ' => __ ( 'Check out my other WordPress plugins ' , self ::$ _domain ),
618- 'icon ' => 'dashicons-admin-plugins ' ,
619- 'url ' => 'https://profiles.wordpress.org/keraweb/#content-plugins ' ,
719+ 'icon ' => 'dashicons-admin-plugins ' ,
720+ 'url ' => 'https://profiles.wordpress.org/keraweb/#content-plugins ' ,
620721 ),
621722 );
622723
@@ -634,6 +735,20 @@ public function action_load_textdomain() {
634735 load_plugin_textdomain ( self ::$ _domain , false , basename ( dirname ( __FILE__ ) ) . '/languages/ ' );
635736 }
636737
738+ /**
739+ * Compatibility with the Dark Mode plugin.
740+ *
741+ * @since 1.3.0
742+ * @access public
743+ * @return bool
744+ */
745+ public function is_using_dark_mode () {
746+ if ( is_callable ( 'Dark_Mode::is_using_dark_mode ' ) && Dark_Mode::is_using_dark_mode () ) {
747+ return true ;
748+ }
749+ return false ;
750+ }
751+
637752 /**
638753 * Magic method to output a string if trying to use the object as a string.
639754 *
0 commit comments