Skip to content

Commit 48b59f0

Browse files
authored
Merge pull request #1 from JoryHogeveen/dev
v 1.1.4
2 parents 9429b6b + aae01b0 commit 48b59f0

File tree

2 files changed

+94
-59
lines changed

2 files changed

+94
-59
lines changed

genesis-widget-column-classes.php

Lines changed: 85 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
* @package Genesis
44
* @author Jory Hogeveen
55
*
6-
* Plugin Name: Genesis Widget Column Classes
7-
* Description: Add Genesis (old Bootstrap) column classes to widgets
8-
* Plugin URI: https://wordpress.org/plugins/genesis-widget-column-classes/
9-
* Version: 1.1.4-dev
10-
* Author: Jory Hogeveen
11-
* Author URI: http://www.keraweb.nl
12-
* Text Domain: genesis-widget-column-classes
13-
* Domain Path: /languages/
14-
* License: GPLv2
6+
* Plugin Name: Genesis Widget Column Classes
7+
* Description: Add Genesis (old Bootstrap) column classes to widgets
8+
* Plugin URI: https://wordpress.org/plugins/genesis-widget-column-classes/
9+
* Version: 1.1.4
10+
* Author: Jory Hogeveen
11+
* Author URI: http://www.keraweb.nl
12+
* Text Domain: genesis-widget-column-classes
13+
* Domain Path: /languages/
14+
* License: GPLv2
1515
*/
1616

1717
/*
@@ -44,8 +44,8 @@ final class WCC_Genesis_Widget_Column_Classes
4444
/**
4545
* The single instance of the class.
4646
*
47-
* @since 1.1.3
48-
* @var WCC_Genesis_Widget_Column_Classes
47+
* @since 1.1.3
48+
* @var WCC_Genesis_Widget_Column_Classes
4949
*/
5050
private static $_instance = null;
5151

@@ -70,7 +70,7 @@ final class WCC_Genesis_Widget_Column_Classes
7070
*
7171
* @since 1.1.4
7272
* @var array
73-
*/
73+
*/
7474
private $column_classes = array(
7575
'one-half',
7676
'one-third',
@@ -90,15 +90,15 @@ final class WCC_Genesis_Widget_Column_Classes
9090
*
9191
* @since 1.1
9292
* @var object
93-
*/
93+
*/
9494
private $curUser = false;
9595

9696
/**
9797
* Init function to register plugin hook
9898
*
9999
* @since 1.1
100-
* @access private
101-
* @return void
100+
* @access private
101+
* @return void
102102
*/
103103
private function __construct() {
104104
self::$_instance = $this;
@@ -112,11 +112,11 @@ private function __construct() {
112112
*
113113
* Ensures only one instance of Genesis Widget Column Classes is loaded or can be loaded.
114114
*
115-
* @since 1.1.3
116-
* @access public
115+
* @since 1.1.3
116+
* @access public
117117
* @static
118-
* @see Genesis_Widget_Column_Classes()
119-
* @return Genesis Widget Column Classes - Main instance.
118+
* @see Genesis_Widget_Column_Classes()
119+
* @return Genesis Widget Column Classes - Main instance.
120120
*/
121121
public static function get_instance() {
122122
if ( is_null( self::$_instance ) ) {
@@ -129,22 +129,30 @@ public static function get_instance() {
129129
* Init function/action and register all used hooks
130130
*
131131
* @since 1.1
132-
* @access public
133-
* @return void
132+
* @access public
133+
* @return void
134134
*/
135135
public function init() {
136136

137137
// Get the current user
138138
$this->curUser = wp_get_current_user();
139139

140+
/**
141+
* Change the default column classes
142+
*
143+
* @since 1.1.4
144+
* @param array The column classes
145+
*/
146+
$this->column_classes = apply_filters( 'genesis_widget_column_classes', $this->column_classes );
147+
140148
if ( isset( $this->curUser->ID ) ) {
141149
add_action( 'admin_notices', array( $this, 'genesis_notice' ) );
142150
add_action( 'wp_ajax_'.$this->noticeKey, array( $this, 'ignore_genesis_notice' ) );
143151
}
144152
// widget_form_callback instead of in_widget_form because we want these fields to show BEFORE the other fields
145153
add_filter( 'widget_form_callback', array( $this, 'widget_form_extend' ), 10, 2 );
146154
add_filter( 'widget_update_callback', array( $this, 'widget_update' ), 10, 2 );
147-
add_filter( 'dynamic_sidebar_params', array( $this, 'sidebar_params' ) );
155+
add_filter( 'dynamic_sidebar_params', array( $this, 'sidebar_params' ), 99999 ); // Make sure to be the last one
148156
add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
149157

150158
}
@@ -154,8 +162,8 @@ public function init() {
154162
* Checks for version in the notice ignore meta value. If the version is the same (user has clicked ignore), then hide it
155163
*
156164
* @since 0.1
157-
* @access public
158-
* @return void
165+
* @access public
166+
* @return void
159167
*/
160168
public function genesis_notice() {
161169
if ( get_template() != 'genesis' ) {
@@ -177,8 +185,8 @@ public function genesis_notice() {
177185
* Store format: Boolean
178186
*
179187
* @since 1.1
180-
* @access public
181-
* @return String
188+
* @access public
189+
* @return string
182190
*/
183191
public function ignore_genesis_notice() {
184192
update_user_meta( $this->curUser->ID, $this->noticeKey, $this->version );
@@ -189,10 +197,10 @@ public function ignore_genesis_notice() {
189197
* Add options to the widgets
190198
*
191199
* @since 0.1
192-
* @access public
193-
* @param array $instance
194-
* @param object $widget
195-
* @return Array $instance
200+
* @access public
201+
* @param array $instance
202+
* @param object $widget
203+
* @return array $instance
196204
*/
197205
public function widget_form_extend( $instance, $widget ) {
198206

@@ -229,10 +237,10 @@ public function widget_form_extend( $instance, $widget ) {
229237
* Add the new fields to the update instance
230238
*
231239
* @since 0.1
232-
* @access public
233-
* @param array $instance
234-
* @param array $new_instance
235-
* @return Array $instance
240+
* @access public
241+
* @param array $instance
242+
* @param array $new_instance
243+
* @return array $instance
236244
*/
237245
public function widget_update( $instance, $new_instance ) {
238246

@@ -251,19 +259,39 @@ public function widget_update( $instance, $new_instance ) {
251259
* Add classes to the widget
252260
*
253261
* @since 0.1
254-
* @access public
255-
* @param array $params
256-
* @return Array $params
262+
* @access public
263+
* @param array $params
264+
* @return array $params
257265
*/
258266
public function sidebar_params( $params ) {
259267
global $wp_registered_widgets;
260-
$widget_id = $params[0]['widget_id'];
261-
$widget_obj = $wp_registered_widgets[ $widget_id ];
262-
$widget_opt = get_option( $widget_obj['callback'][0]->option_name );
263-
$widget_num = $widget_obj['params'][0]['number'];
268+
269+
if ( empty( $params[0] ) ) {
270+
return $params;
271+
}
272+
$widget_id = $params[0]['widget_id'];
273+
274+
if ( empty( $wp_registered_widgets[ $widget_id ] ) ) {
275+
return $params;
276+
}
277+
$widget_obj = $wp_registered_widgets[ $widget_id ];
278+
279+
if ( empty( $widget_obj['callback'][0] ) || empty( $widget_obj['callback'][0]->option_name ) ) {
280+
return $params;
281+
}
282+
$widget_opt = get_option( $widget_obj['callback'][0]->option_name );
283+
284+
if ( empty( $widget_obj['params'][0]['number'] ) ) {
285+
return $params;
286+
}
287+
$widget_num = $widget_obj['params'][0]['number'];
288+
289+
if ( empty( $widget_opt[ $widget_num ] ) ) {
290+
return $params;
291+
}
264292

265293
$widget_extra_classes = '';
266-
if ( isset( $widget_opt[ $widget_num ]['column-classes'] ) && ! empty( $widget_opt[ $widget_num ]['column-classes'] ) ) {
294+
if ( ! empty( $widget_opt[ $widget_num ]['column-classes'] ) ) {
267295
$widget_extra_classes .= $widget_opt[ $widget_num ]['column-classes'].' ';
268296
}
269297
if ( isset( $widget_opt[ $widget_num ]['column-classes-first'] ) && 1 == $widget_opt[ $widget_num ]['column-classes-first'] ) {
@@ -278,9 +306,9 @@ public function sidebar_params( $params ) {
278306
/**
279307
* Load plugin textdomain.
280308
*
281-
* @since 1.1.3
282-
* @access public
283-
* @return void
309+
* @since 1.1.3
310+
* @access public
311+
* @return void
284312
*/
285313
public function load_textdomain() {
286314
load_plugin_textdomain( 'genesis-widget-column-classes', false, basename( dirname( __FILE__ ) ) . '/languages/' );
@@ -289,9 +317,9 @@ public function load_textdomain() {
289317
/**
290318
* Magic method to output a string if trying to use the object as a string.
291319
*
292-
* @since 1.1.3
293-
* @access public
294-
* @return void
320+
* @since 1.1.3
321+
* @access public
322+
* @return void
295323
*/
296324
public function __toString() {
297325
return get_class( $this );
@@ -300,9 +328,9 @@ public function __toString() {
300328
/**
301329
* Magic method to keep the object from being cloned.
302330
*
303-
* @since 1.1.3
304-
* @access public
305-
* @return void
331+
* @since 1.1.3
332+
* @access public
333+
* @return void
306334
*/
307335
public function __clone() {
308336
_doing_it_wrong( __FUNCTION__, esc_html__( 'Whoah, partner!', 'genesis-widget-column-classes' ), '1.0.0' );
@@ -311,9 +339,9 @@ public function __clone() {
311339
/**
312340
* Magic method to keep the object from being unserialized.
313341
*
314-
* @since 1.1.3
315-
* @access public
316-
* @return void
342+
* @since 1.1.3
343+
* @access public
344+
* @return void
317345
*/
318346
public function __wakeup() {
319347
_doing_it_wrong( __FUNCTION__, esc_html__( 'Whoah, partner!', 'genesis-widget-column-classes' ), '1.0.0' );
@@ -322,9 +350,9 @@ public function __wakeup() {
322350
/**
323351
* Magic method to prevent a fatal error when calling a method that doesn't exist.
324352
*
325-
* @since 1.1.3
326-
* @access public
327-
* @return null
353+
* @since 1.1.3
354+
* @access public
355+
* @return null
328356
*/
329357
public function __call( $method = '', $args = array() ) {
330358
_doing_it_wrong( get_class( $this ) . "::{$method}", esc_html__( 'Method does not exist.', 'genesis-widget-column-classes' ), '1.0.0' );

readme.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ Contributors: keraweb
33
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=YGPLMLU7XQ9E8&lc=NL&item_name=Genesis%20Widget%20Column%20Classes&item_number=JWPP%2dGWCC&currency_code=EUR&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted
44
Tags: genesis, bootstrap, column, widget, dynamik
55
Requires at least: 3.1
6-
Tested up to: 4.5
7-
Stable tag: 1.1.3
6+
Tested up to: 4.6
7+
Stable tag: 1.1.4
88

99
Adds Genesis column classes to widgets.
1010

@@ -14,6 +14,11 @@ As easy as it gets. Add column classes to widgets with a select box, check wethe
1414

1515
I've built this plugin for the Genesis Framework, though it will work with any theme that uses the (old) Bootstrap column classes.
1616

17+
= Filter: `genesis_widget_column_classes` =
18+
Allows you to change the available column classes
19+
20+
* **Parameters:** array (default column classes)
21+
1722
== Installation ==
1823

1924
Installation of this plugin works like any other plugin out there. Either:
@@ -32,6 +37,8 @@ Or search for "Genesis Widget Column Classes" via your plugins menu.
3237
= 1.1.4 =
3338

3439
* Usage of the WP_Widget object for generating input names and ID's
40+
* Add filter `genesis_widget_column_classes` to add/modify available column classes
41+
* Tested with WordPress 4.6
3542

3643
= 1.1.3 =
3744

0 commit comments

Comments
 (0)