Skip to content

Commit

Permalink
v1.2 - Merge pull request #11 from JoryHogeveen/dev
Browse files Browse the repository at this point in the history
v1.2
  • Loading branch information
JoryHogeveen authored Aug 2, 2018
2 parents d2a2cd4 + 713a1d6 commit 9edd687
Show file tree
Hide file tree
Showing 3 changed files with 172 additions and 121 deletions.
75 changes: 20 additions & 55 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
=== Widget Subtitles ===
Contributors: keraweb
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=YGPLMLU7XQ9E8&lc=NL&item_name=Widget%20Subtitles&item_number=JWPP%2dWS&currency_code=EUR&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHostedGuest
Donate link: https://www.keraweb.nl/donate.php?for=widget-subtitles
Tags: widget, widget subtitle, subtitle, subtitles, sub title, sidebar
Requires at least: 3.0
Tested up to: 4.9
Requires PHP: 5.2.4
Stable tag: 1.1.4.1
Stable tag: 1.2
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand All @@ -15,59 +15,14 @@ Add a customizable subtitle to your widgets

This plugin adds a subtitle input field to all your widgets. You can also change the location of the subtitle and even use filters to change the subtitle output.

= Filter: `widget_subtitles_element` =
Allows you to change the HTML element for the subtitle.
Since 1.0

* **Default:** `span`
* **Parameters:**
* `string` Default element.
* `string` Widget ID, widget name + instance number.
* `string` Sidebar ID where this widget is located. (since 1.1)
* `array` All widget data. (since 1.1)
* `WP_Widget` The widget type class. (since 1.1.3)
* **Return:** `string` A valid HTML element.

= Filter: `widget_subtitles_classes` =
Allow filter for subtitle classes to overwrite, remove or add classes.
Since 1.0

* **Default:** `array( 'widget-subtitle', 'widgetsubtitle', 'subtitle-{LOCATION}' );` *Where {LOCATION} stands for your selected location*.
* **Parameters:**
* `string` Default element.
* `string` Widget ID, widget name + instance number.
* `string` Sidebar ID where this widget is located. (since 1.1)
* `array` All widget data. (since 1.1)
* `WP_Widget` The widget type class. (since 1.1.3)
* **Return:** `array` An array of CSS classes.

= Filter: `widget_subtitles_default_location` =
Sets the default location for subtitles.
Since 1.1.2

* **Default:** `after-inside`
* **Parameters:** `string` The default subtitle location.
* **Return:** `string` Options: `after-inside`, `after-outside`, `before-inside`, `before-outside`.

= Filter: `widget_subtitles_edit_location_capability` =
Change the capability required to modify subtitle locations.
Since 1.1.2

* **Default:** `edit_theme_options`
* **Parameters:** `string` The default capability.
* **Return:** `string` The new capability.

= Filter: `widget_subtitles_available_locations` =
Overwrites the available locations for a widget.
NOTE: You can currently only remove locations. New locations are not possible (yet).
Since 1.1.3

* **Default:** `after-inside`, `after-outside`, `before-inside`, `before-outside`.
* **Parameters:**
* `array` The array of available locations.
* `WP_Widget` The widget type class.
* `array` The widget instance.
* **Return:** `array` Filtered list of available locations for this widget.
= Filters =
* [`widget_subtitles_element`](https://github.com/JoryHogeveen/widget-subtitles/wiki#filter-widget_subtitles_element)
* [`widget_subtitles_classes`](https://github.com/JoryHogeveen/widget-subtitles/wiki#filter-widget_subtitles_classes)
* [`widget_subtitles_default_location`](https://github.com/JoryHogeveen/widget-subtitles/wiki#filter-widget_subtitles_default_location)
* [`widget_subtitles_edit_location_capability`](https://github.com/JoryHogeveen/widget-subtitles/wiki#filter-widget_subtitles_edit_location_capability)
* [`widget_subtitles_available_locations`](https://github.com/JoryHogeveen/widget-subtitles/wiki#filter-widget_subtitles_available_locations)
* [`widget_subtitles_add_subtitle`](https://github.com/JoryHogeveen/widget-subtitles/wiki#filter-widget_subtitles_add_subtitle)
* [`widget_subtitle`](https://github.com/JoryHogeveen/widget-subtitles/wiki#filter-widget_subtitle)

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

Expand All @@ -87,6 +42,16 @@ Or search for "Widget Subtitles" via your plugins menu.

== Changelog ==

= 1.2 =

* **Feature:** New filter: `widget_subtitle` to change the subtitle for a widget. Similar to WP's `widget_title`.
* **Feature:** New filter: `widget_subtitles_add_subtitle` to allow custom subtitle location handlers.
* **Enhancement:** Extended filter: `widget_subtitles_available_locations` now allows custom locations.
* **Enhancement:** Make use of `wp_get_sidebars_widgets()` instead of a global to get the related sidebar ID from a widget instance.
* **Documentation:** Created a wiki on GitHub.

Detailed info: [PR on GitHub](https://github.com/JoryHogeveen/widget-subtitles/pull/11)

= 1.1.4.1 =

* **Fix:** PHP notice.
Expand Down
72 changes: 59 additions & 13 deletions tests/test-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ function test_plugin_activated() {

// Check for PHP errors
function test_general() {
$ws = ws_widget_subtitles();
$ws->get_links();
ws_widget_subtitles()->get_links();
}

// Check add_subtitle() method.
function test_add_subtitle() {
$ws = ws_widget_subtitles();

$tests = array(
array(
Expand Down Expand Up @@ -118,28 +116,73 @@ function test_add_subtitle() {
),
'location' => 'after-outside', // default
),
array(
'start' => array(
'after_title' => '</div>',
'before_title' => '<div class="title">',
),
'data' => '<div>SUBTITLE</div>',
'result' => array(
'after_title' => '</div>',
'before_title' => '<div class="title"><div>SUBTITLE</div> test ',
),
'location' => 'custom', // default
),
);

add_filter( 'widget_subtitles_add_subtitle', array( $this, 'filter_widget_subtitles_add_subtitle' ), 10, 3 );

foreach ( $tests as $test ) {
$this->assertEquals( $test['result'], $ws->add_subtitle( $test['start'], $test['data'], $test['location'] ) );
$this->assertEquals(
$test['result'],
ws_widget_subtitles()->add_subtitle( $test['start'], $test['data'], $test['location'] )
);
}
}

// Check widget_update_callback() method
function test_widget_update_callback() {
$ws = ws_widget_subtitles();
function filter_widget_subtitles_add_subtitle( $params, $subtitle, $subtitle_location ) {
if ( 'custom' === $subtitle_location ) {
$params['before_title'] = $params['before_title'] . $subtitle . ' test ';
}
return $params;
}

// Check get_subtitle_classes() method.
function test_get_subtitle_classes() {

$tests = array(
array(
'start' => array(),
'data' => array(
'subtitle' => 'test',
'subtitle_location' => '1', // Not valid.
'result' => array(
'widgetsubtitle',
'widget-subtitle',
'subtitle-after-outside',
'subtitle-after',
'subtitle-outside',
),
'location' => 'after-outside', // default
),
array(
'result' => array(
'subtitle' => 'test',
'widgetsubtitle',
'widget-subtitle',
'subtitle-custom',
),
'location' => 'custom', // default
),
);

foreach ( $tests as $test ) {
$this->assertEquals(
$test['result'],
ws_widget_subtitles()->get_subtitle_classes( $test['location'] )
);
}
}

// Check filter_widget_update_callback() method
function test_widget_update_callback() {

$tests = array(
array(
'start' => array(),
'data' => array(
Expand Down Expand Up @@ -201,7 +244,10 @@ function test_widget_update_callback() {

// Run tests
foreach ( $tests as $test ) {
$this->assertEquals( $test['result'], $ws->widget_update_callback( $test['start'], $test['data'] ) );
$this->assertEquals(
$test['result'],
ws_widget_subtitles()->filter_widget_update_callback( $test['start'], $test['data'] )
);
}
}
}
Loading

0 comments on commit 9edd687

Please sign in to comment.