Skip to content

Commit

Permalink
v1.2.1 - Merge pull request #12 from JoryHogeveen/dev
Browse files Browse the repository at this point in the history
v1.2.1
  • Loading branch information
JoryHogeveen authored Nov 14, 2019
2 parents c26ef3c + 87fc631 commit dce5b93
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 55 deletions.
11 changes: 9 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ Contributors: keraweb
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: 5.0
Tested up to: 5.3
Requires PHP: 5.2.4
Stable tag: 1.2
Stable tag: 1.2.1
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -42,6 +42,13 @@ Or search for "Widget Subtitles" via your plugins menu.

== Changelog ==

= 1.2.1 =

* **Enhancement:** Improve updating subtitles to reflect WordPress default title.
* **Compatibility:** Tested with WordPress 5.3.

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

= 1.2 =

* **Feature:** New filter: `widget_subtitle` to change the subtitle for a widget. Similar to WP's `widget_title`.
Expand Down
110 changes: 57 additions & 53 deletions widget-subtitles.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
* @author Jory Hogeveen <info@keraweb.nl>
* @package Widget_Subtitles
* @since 0.1.0
* @version 1.2.0
* @version 1.2.1
* @licence GPL-2.0+
* @link https://github.com/JoryHogeveen/widget-subtitles
*
* @wordpress-plugin
* Plugin Name: Widget Subtitles
* Plugin URI: https://wordpress.org/plugins/widget-subtitles/
* Description: Add a customizable subtitle to your widgets
* Version: 1.2
* Version: 1.2.1
* Author: Jory Hogeveen
* Author URI: http://www.keraweb.nl
* Text Domain: widget-subtitles
Expand Down Expand Up @@ -50,7 +50,7 @@
* @author Jory Hogeveen <info@keraweb.nl>
* @package Widget_Subtitles
* @since 0.1.0
* @version 1.2.0
* @version 1.2.1
*/
final class WS_Widget_Subtitles
{
Expand Down Expand Up @@ -167,26 +167,25 @@ public function init() {
* @return string Options: 'after-inside', 'after-outside', 'before-inside', 'before-outside'.
*/
$this->default_location = apply_filters( 'widget_subtitles_default_location', $this->default_location );
$default = explode( '-', $this->default_location );

$default = explode( '-', $this->default_location );
foreach ( $default as $key => $value ) {
if ( isset( $loc[ $value ] ) && 2 === count( $default ) ) {
$default[ $key ] = $loc[ $value ];
}
}

$default = implode( ' - ', $default );

$this->locations = array(
'' => __( 'Default', self::$_domain ) . ' (' . $default . ')',
'' => __( 'Default', self::$_domain ) . ' (' . $default . ')',
// before title, outside title element.
'before-outside' => $loc['before'] . ' - ' . $loc['outside'],
// before title, inside title element
'before-inside' => $loc['before'] . ' - ' . $loc['inside'],
'before-inside' => $loc['before'] . ' - ' . $loc['inside'],
// after title, outside title element
'after-outside' => $loc['after'] . ' - ' . $loc['outside'],
'after-outside' => $loc['after'] . ' - ' . $loc['outside'],
// after title, inside title element
'after-inside' => $loc['after'] . ' - ' . $loc['inside'],
'after-inside' => $loc['after'] . ' - ' . $loc['inside'],
);

add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
Expand Down Expand Up @@ -259,12 +258,12 @@ public function action_in_widget_form( $widget, $return, $instance ) {

<script type="text/javascript">
;( function( $ ) {
var title = '#<?php echo $widget->get_field_id( 'title' ); ?>',
subtitle = '#<?php echo $widget->get_field_id( 'subtitle' ); ?>',
$title = $( title ),
var title = '#<?php echo $widget->get_field_id( 'title' ); ?>',
subtitle = '#<?php echo $widget->get_field_id( 'subtitle' ); ?>',
$title = $( title ),
$subtitle = $( subtitle );
<?php if ( $can_edit_location ) { ?>
var subtitle_location = '#<?php echo $widget->get_field_id( 'subtitle_location' ); ?>',
var subtitle_location = '#<?php echo $widget->get_field_id( 'subtitle_location' ); ?>',
$subtitle_location = $( subtitle_location );

// show/hide subtitle location input.
Expand Down Expand Up @@ -298,6 +297,7 @@ public function action_in_widget_form( $widget, $return, $instance ) {
*
* @since 0.1.0
* @since 1.2.0 Add `filter_` prefix.
* @since 1.2.1 sanitize_text_field() to ensure same validation as default widget title.
* @access public
*
* @param array $instance
Expand All @@ -311,11 +311,11 @@ public function filter_widget_update_callback( $instance, $new_instance ) {
unset( $instance['subtitle_location'] );

if ( ! empty( $new_instance['subtitle'] ) ) {
$instance['subtitle'] = esc_html( strip_tags( $new_instance['subtitle'] ) );
$instance['subtitle'] = sanitize_text_field( $new_instance['subtitle'] );

if ( ! empty( $new_instance['subtitle_location'] ) && is_string( $new_instance['subtitle_location'] ) ) {
//&& array_key_exists( $new_instance['subtitle_location'], $this->locations )
$instance['subtitle_location'] = esc_attr( strip_tags( $new_instance['subtitle_location'] ) );
$instance['subtitle_location'] = esc_attr( wp_strip_all_tags( $new_instance['subtitle_location'] ) );
}
}

Expand Down Expand Up @@ -369,8 +369,9 @@ public function filter_dynamic_sidebar_params( $params ) {

$sidebar_id = $this->get_widget_sidebar_id( $widget_id );

// default.
// Default.
$subtitle_location = $this->default_location;
// Available.
$locations = $this->get_available_subtitle_locations( $widget_obj, $instance, $sidebar_id );

// Get location value if it exists and is valid.
Expand Down Expand Up @@ -519,7 +520,7 @@ public function add_subtitle( $params, $subtitle, $subtitle_location = '', $widg
public function get_widget_sidebar_id( $widget_id ) {
//global $_wp_sidebars_widgets;
$sidebars_widgets = wp_get_sidebars_widgets();
$sidebar_id = '';
$sidebar_id = '';
if ( is_array( $sidebars_widgets ) ) {
foreach ( $sidebars_widgets as $key => $widgets ) {
if ( is_array( $widgets ) && in_array( (string) $widget_id, array_map( 'strval', $widgets ), true ) ) {
Expand All @@ -545,6 +546,7 @@ public function get_subtitle_classes( $location ) {
$subtitle_classes = array( 'widgetsubtitle', 'widget-subtitle' );
// Add subtitle location classes.
$subtitle_classes[] = 'subtitle-' . $location;
// Convert to array.
$location_classes = explode( '-', $location );
// Prevent duplicated classes.
if ( 1 < count( $location_classes ) ) {
Expand Down Expand Up @@ -602,8 +604,10 @@ public function get_available_subtitle_locations( $widget_obj, $instance, $sideb
public function action_plugin_row_meta( $links, $file ) {
if ( self::$_basename === $file ) {
foreach ( $this->get_links() as $id => $link ) {
$icon = '<span class="dashicons ' . $link['icon'] . '" style="font-size: inherit; line-height: inherit; display: inline; vertical-align: text-top;"></span>';
$style = 'font-size: inherit; line-height: inherit; display: inline; vertical-align: text-top;';
$icon = '<span class="dashicons ' . $link['icon'] . '" style="' . $style . '"></span>';
$title = $icon . ' ' . esc_html( $link['title'] );

$links[ $id ] = '<a href="' . esc_url( $link['url'] ) . '" target="_blank">' . $title . '</a>';
}
}
Expand All @@ -623,59 +627,59 @@ public function get_links() {
}

$links = array(
'support' => array(
'title' => __( 'Support', self::$_domain ),
'support' => array(
'title' => __( 'Support', self::$_domain ),
'description' => __( 'Need support?', self::$_domain ),
'icon' => 'dashicons-sos',
'url' => 'https://wordpress.org/support/plugin/widget-subtitles/',
'icon' => 'dashicons-sos',
'url' => 'https://wordpress.org/support/plugin/widget-subtitles/',
),
'slack' => array(
'title' => __( 'Slack', self::$_domain ),
'slack' => array(
'title' => __( 'Slack', self::$_domain ),
'description' => __( 'Quick help via Slack', self::$_domain ),
'icon' => 'dashicons-format-chat',
'url' => 'https://keraweb.slack.com/messages/plugin-ws/',
'icon' => 'dashicons-format-chat',
'url' => 'https://keraweb.slack.com/messages/plugin-ws/',
),
'review' => array(
'title' => __( 'Review', self::$_domain ),
'review' => array(
'title' => __( 'Review', self::$_domain ),
'description' => __( 'Give 5 stars on WordPress.org!', self::$_domain ),
'icon' => 'dashicons-star-filled',
'url' => 'https://wordpress.org/support/plugin/widget-subtitles/reviews/',
'icon' => 'dashicons-star-filled',
'url' => 'https://wordpress.org/support/plugin/widget-subtitles/reviews/',
),
'translate' => array(
'title' => __( 'Translate', self::$_domain ),
'title' => __( 'Translate', self::$_domain ),
'description' => __( 'Help translating this plugin!', self::$_domain ),
'icon' => 'dashicons-translation',
'url' => 'https://translate.wordpress.org/projects/wp-plugins/widget-subtitles',
'icon' => 'dashicons-translation',
'url' => 'https://translate.wordpress.org/projects/wp-plugins/widget-subtitles',
),
'issue' => array(
'title' => __( 'Report issue', self::$_domain ),
'issue' => array(
'title' => __( 'Report issue', self::$_domain ),
'description' => __( 'Have ideas or a bug report?', self::$_domain ),
'icon' => 'dashicons-lightbulb',
'url' => 'https://github.com/JoryHogeveen/widget-subtitles/issues',
'icon' => 'dashicons-lightbulb',
'url' => 'https://github.com/JoryHogeveen/widget-subtitles/issues',
),
'docs' => array(
'title' => __( 'Documentation', self::$_domain ),
'docs' => array(
'title' => __( 'Documentation', self::$_domain ),
'description' => __( 'Documentation', self::$_domain ),
'icon' => 'dashicons-book-alt',
'url' => 'https://github.com/JoryHogeveen/widget-subtitles/', //wiki
'icon' => 'dashicons-book-alt',
'url' => 'https://github.com/JoryHogeveen/widget-subtitles/', //wiki
),
'github' => array(
'title' => __( 'GitHub', self::$_domain ),
'github' => array(
'title' => __( 'GitHub', self::$_domain ),
'description' => __( 'Follow and/or contribute on GitHub', self::$_domain ),
'icon' => 'dashicons-editor-code',
'url' => 'https://github.com/JoryHogeveen/widget-subtitles/tree/dev',
'icon' => 'dashicons-editor-code',
'url' => 'https://github.com/JoryHogeveen/widget-subtitles/tree/dev',
),
'donate' => array(
'title' => __( 'Donate', self::$_domain ),
'donate' => array(
'title' => __( 'Donate', self::$_domain ),
'description' => __( 'Buy me a coffee!', self::$_domain ),
'icon' => 'dashicons-smiley',
'url' => 'https://www.keraweb.nl/donate.php?for=widget-subtitles',
'icon' => 'dashicons-smiley',
'url' => 'https://www.keraweb.nl/donate.php?for=widget-subtitles',
),
'plugins' => array(
'title' => __( 'Plugins', self::$_domain ),
'plugins' => array(
'title' => __( 'Plugins', self::$_domain ),
'description' => __( 'Check out my other WordPress plugins', self::$_domain ),
'icon' => 'dashicons-admin-plugins',
'url' => 'https://profiles.wordpress.org/keraweb/#content-plugins',
'icon' => 'dashicons-admin-plugins',
'url' => 'https://profiles.wordpress.org/keraweb/#content-plugins',
),
);

Expand Down

0 comments on commit dce5b93

Please sign in to comment.