Skip to content

Commit

Permalink
V1.1 - Merge pull request #3 from JoryHogeveen/dev
Browse files Browse the repository at this point in the history
v1.1
  • Loading branch information
JoryHogeveen authored Nov 12, 2016
2 parents 37eb0a4 + b89f348 commit 39413a3
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 16 deletions.
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Widget Subtitles #
Add a customizable subtitle to your widgets

[![WordPress Plugin version](https://img.shields.io/wordpress/plugin/v/widget-subtitles.svg?style=flat)](https://wordpress.org/plugins/widget-subtitles/)
[![WordPress Plugin WP tested version](https://img.shields.io/wordpress/v/widget-subtitles.svg?style=flat)](https://wordpress.org/plugins/widget-subtitles/)
[![WordPress Plugin downloads](https://img.shields.io/wordpress/plugin/dt/widget-subtitles.svg?style=flat)](https://wordpress.org/plugins/widget-subtitles/)
[![WordPress Plugin rating](https://img.shields.io/wordpress/plugin/r/widget-subtitles.svg?style=flat)](https://wordpress.org/plugins/widget-subtitles/)
[![Travis](https://secure.travis-ci.org/JoryHogeveen/widget-subtitles.png?branch=master)](http://travis-ci.org/JoryHogeveen/widget-subtitles)
[![License](https://img.shields.io/badge/license-GPL--2.0%2B-green.svg)](https://github.com/JoryHogeveen/widget-subtitles/blob/master/license.txt)
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](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)

## Description

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.

### Filters

#### `widget_subtitles_element`
Allows you to change the HTML element for the subtitle

* **Default:** span
* **Parameters:**
* string (default)
* string (widget id)
* string (sidebar id)
* array (widget data)

#### `widget_subtitles_classes`
Allows you to change the HTML element for the subtitle

* **Default:** `array( 'widget-subtitle', 'widgetsubtitle', 'subtitle-LOCATION' );` Where LOCATION stands for your selected location
* **Parameters:**
* array (default classes)
* string (widget id)
* string (sidebar id)
* array (widget data)

## Installation

1. Upload `/widget-subtitles` to the `/wp-content/plugins/` directory
2. Activate the plugin through the *Plugins* menu in WordPress
3. Go to *Appearance* > *Widgets* menu and fill out your subtitles
19 changes: 15 additions & 4 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ 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
Tags: widget, widget subtitle, subtitle, subtitles, sub title, sidebar
Requires at least: 3.0
Tested up to: 4.6
Stable tag: 1.0.1
Tested up to: 4.7
Stable tag: 1.1
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand All @@ -18,13 +18,21 @@ This plugin adds a subtitle input field to all your widgets. You can also change
Allows you to change the HTML element for the subtitle

* **Default:** span
* **Parameters:** string (default), int (widget id)
* **Parameters:**
* string (default)
* string (widget id)
* string (sidebar id)
* array (widget data)

= Filter: `widget_subtitles_classes` =
Allows you to change the HTML element for the subtitle

* **Default:** `array( 'widget-subtitle', 'widgetsubtitle', 'subtitle-LOCATION' );` Where LOCATION stands for your selected location
* **Parameters:** array (default classes), int (widget id)
* **Parameters:**
* array (default classes)
* string (widget id)
* string (sidebar id)
* array (widget data)

== Installation ==

Expand All @@ -34,6 +42,9 @@ Allows you to change the HTML element for the subtitle

== Changelog ==

= 1.1 =
* Add extra parameters to the filter hooks

= 1.0.1 =
* Update textdomain hook

Expand Down
54 changes: 42 additions & 12 deletions widget-subtitles.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
/**
* Plugin Name: Widget Subtitles
* Description: Add a customizable subtitle to your widgets
* Plugin URI: http://github.com/JoryHogeveen/widget-subtitles
* Version: 1.0.1
* Author: Jory Hogeveen
* Author URI: http://www.keraweb.nl
* Plugin URI: http://github.com/JoryHogeveen/widget-subtitles
* Version: 1.1
* Author: Jory Hogeveen
* Author URI: http://www.keraweb.nl
* Text Domain: widget-subtitles
* Domain Path: /languages
* License: GNU General Public License v2 or later
* License: GNU General Public License v2 or later
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/

Expand Down Expand Up @@ -111,7 +111,7 @@ function in_widget_form( $widget, $return, $instance ) {

<p>
<label for="<?php echo $widget->get_field_id( 'subtitle_location' ) ?>"><?php _e('Subtitle location', 'widget-subtitles') ?>:</label>
<select name=<?php echo $widget->get_field_name( 'subtitle_location' ); ?>" id="<?php echo $widget->get_field_id( 'subtitle_location' ) ?>">
<select name="<?php echo $widget->get_field_name( 'subtitle_location' ); ?>" id="<?php echo $widget->get_field_id( 'subtitle_location' ) ?>">
<?php
foreach ( $this->locations as $locationKey => $locationName ) {
?>
Expand Down Expand Up @@ -189,7 +189,7 @@ function widget_update_callback( $instance, $new_instance, $old_instance, $widge
*/
function dynamic_sidebar_params( $params ) {

global $wp_registered_widgets;
global $wp_registered_widgets, $_wp_sidebars_widgets;

if ( ! isset( $params[0]['widget_id'] ) ) {
return $params;
Expand All @@ -206,19 +206,38 @@ function dynamic_sidebar_params( $params ) {
// Check if there's an instance of the widget
if ( array_key_exists( $params[1]['number'], $instance ) ) {

$instance = $instance[$params[1]['number']];
$instance = $instance[ $params[1]['number'] ];

// Add the subtitle
if ( ! empty( $instance['subtitle'] ) ) {

$sidebar_id = '';
if ( is_array( $_wp_sidebars_widgets ) ) {
foreach ( $_wp_sidebars_widgets as $key => $widgets ) {
if ( in_array( $widget_id, $widgets ) ) {
$sidebar_id = $key;
break;
}
}
}

$subtitle_location = 'after-inside'; // default
// Get location value if it exists and is valid
if ( ! empty( $instance['subtitle_location'] ) && array_key_exists( $instance['subtitle_location'], $this->locations ) ) {
$subtitle_location = $instance['subtitle_location'];
}

// Filters subtitle element (default: span)
$subtitle_element = apply_filters( 'widget_subtitles_element', 'span', $widget_id );
/**
* Filters subtitle element (default: span)
* @since 1.0
* @since 1.1 Add extra parameters
*
* @param string 'span' The Element
* @param string $widget_id The widget ID (widget name + instance number)
* @param string $sidebar_id The sidebar ID where this widget is located
* @param array $widget All widget data
*/
$subtitle_element = apply_filters( 'widget_subtitles_element', 'span', $widget_id, $sidebar_id, $widget );

// Create subtitle classes
$subtitle_classes = array( 'widget-subtitles', 'widgetsubtitle' );
Expand All @@ -228,8 +247,19 @@ function dynamic_sidebar_params( $params ) {
foreach( $subtitle_location_classes as $location ) {
$subtitle_classes[] = 'subtitle-' . $location;
}
// Allow filter for subtitle classes to overwrite, remove or add classes
$subtitle_classes = apply_filters( 'widget_subtitles_classes', $subtitle_classes, $widget_id );

/**
* Allow filter for subtitle classes to overwrite, remove or add classes
* @since 1.0
* @since 1.1 Add extra parameters
*
* @param array $subtitle_classes The default classes
* @param string $widget_id The widget ID (widget name + instance number)
* @param string $sidebar_id The sidebar ID where this widget is located
* @param array $widget All widget data
*/
$subtitle_classes = apply_filters( 'widget_subtitles_classes', $subtitle_classes, $widget_id, $sidebar_id, $widget );

// Create class string to use
$subtitle_classes = is_array( $subtitle_classes ) ? '' . implode( ' ', $subtitle_classes ) . '' : '';

Expand Down

0 comments on commit 39413a3

Please sign in to comment.