Skip to content

Commit 93da52f

Browse files
committed
New filter genesis_widget_column_classes_capability
Change the capability required to modify column classes.
1 parent def7f10 commit 93da52f

File tree

3 files changed

+49
-5
lines changed

3 files changed

+49
-5
lines changed

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,16 @@ I've built this plugin for the Genesis Framework, though it will work with any t
2121
#### `genesis_widget_column_classes`
2222
Allows you to change the available column classes
2323

24-
**Parameters:** `array` Default column classes.
25-
**Return:** `array` Array of column classes.
24+
**Parameters:** `array` Default column classes.
25+
**Return:** `array` Array of column classes.
26+
27+
#### `genesis_widget_column_classes_capability`
28+
Change the capability required to modify column classes.
29+
Since 1.2.2
30+
31+
* **Default:** `edit_theme_options`
32+
* **Parameters:** `string` The default capability.
33+
* **Return:** `string` The new capability.
2634

2735
You can use these filters inside your theme functions.php file or in a plugin.
2836

genesis-widget-column-classes.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,14 @@ final class WCC_Genesis_Widget_Column_Classes
107107
*/
108108
private $curUser = null;
109109

110+
/**
111+
* Capability required to use this plugin.
112+
*
113+
* @since 1.2.2
114+
* @var string
115+
*/
116+
private $cap = 'edit_theme_options';
117+
110118
/**
111119
* Init function to register plugin hook
112120
*
@@ -147,6 +155,16 @@ public static function get_instance() {
147155
*/
148156
public function init() {
149157

158+
/**
159+
* Change the capability required to use this plugin.
160+
* Default: `edit_theme_options`.
161+
*
162+
* @since 1.2.2
163+
* @param string $cap The capability.
164+
* @return string
165+
*/
166+
$this->cap = apply_filters( 'genesis_widget_column_classes_capability', $this->cap );
167+
150168
// Get the current user.
151169
$this->curUser = wp_get_current_user();
152170

@@ -212,13 +230,22 @@ public function ignore_genesis_notice() {
212230
*/
213231
public function widget_form_extend( $instance, $widget ) {
214232

215-
$instance = wp_parse_args( (array) $instance,
233+
$instance = wp_parse_args(
234+
(array) $instance,
216235
array(
217236
'column-classes' => '',
218237
'column-classes-first' => '',
219238
)
220239
);
221240

241+
if ( ! current_user_can( $this->cap ) ) {
242+
?>
243+
<input type="hidden" name="<?php echo $widget->get_field_name( 'column-classes' ) ?>" value="<?php echo $instance['column-classes'] ?>"/>
244+
<input type="hidden" name="<?php echo $widget->get_field_name( 'column-classes-first' ) ?>" value="<?php echo $instance['column-classes-first'] ?>"/>
245+
<?php
246+
return $instance;
247+
}
248+
222249
$row = '<p style="border: 1px solid #eee; padding: 5px; background: #f5f5f5;">';
223250
$row .= '<label for="' . $widget->get_field_id( 'column-classes' ) . '">' . __( 'Width', 'genesis-widget-column-classes' ) . ':</label> ';
224251
$row .= '<select name="' . $widget->get_field_name( 'column-classes' ) . '" id="' . $widget->get_field_id( 'column-classes' ) . '">';

readme.txt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
=== Genesis Widget Column Classes ===
22
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
4-
Tags: genesis, bootstrap, column, grid, widget, dynamik
4+
Tags: genesis, bootstrap, column, grid, widget, sidebar, dynamik
55
Requires at least: 3.1
66
Tested up to: 4.8
77
Stable tag: 1.2.2
@@ -10,7 +10,7 @@ Adds Genesis column classes to widgets.
1010

1111
== Description ==
1212

13-
As easy as it gets. Add column classes to widgets with a select box, check wether the widget is the first, and save!
13+
As easy as it gets. Add column classes to widgets with a select box, check whether the widget is the first, and save!
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

@@ -20,6 +20,14 @@ Allows you to change the available column classes
2020
**Parameters:** `array` Default column classes.
2121
**Return:** `array` Array of column classes.
2222

23+
= Filter: `genesis_widget_column_classes_capability` =
24+
Change the capability required to modify column classes.
25+
Since 1.2.2
26+
27+
* **Default:** `edit_theme_options`
28+
* **Parameters:** `string` The default capability.
29+
* **Return:** `string` The new capability.
30+
2331
You can use these filters inside your theme functions.php file or in a plugin.
2432

2533
== Installation ==
@@ -40,6 +48,7 @@ Or search for "Genesis Widget Column Classes" via your plugins menu.
4048

4149
= 1.2.2 =
4250

51+
* Feature: new filter `genesis_widget_column_classes_capability`. Change the capability required to modify column classes.
4352
* Enhancement: Helper method to get the available column classes.
4453
* Enhancement: Fix CodeClimate coding standards issues.
4554

0 commit comments

Comments
 (0)