From e63975e6209e6f2617118f42e96c958404ae1502 Mon Sep 17 00:00:00 2001 From: Nathan Rice Date: Tue, 29 Sep 2015 17:34:15 -0400 Subject: [PATCH 01/25] Update grunt tasks. --- Gruntfile.js | 12 ++++-------- package.json | 4 ++-- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index e965fb1..38f6c2a 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -27,14 +27,10 @@ module.exports = function(grunt) { options: { updateDomains: true }, - target: { - files: { - src: [ - '*.php', - 'lib/**/*.php' - ] - } - } + src: [ + '*.php', + 'lib/**/*.php' + ] } }, diff --git a/package.json b/package.json index 2b7a6f7..eea18fa 100644 --- a/package.json +++ b/package.json @@ -20,8 +20,8 @@ "grunt-jsvalidate": "^0.2.2", "grunt-phplint": "0.0.5", "grunt-styledocco": "^0.1.4", - "grunt-wp-i18n": "^0.4.7", - "load-grunt-tasks": "^0.6.0" + "grunt-wp-i18n": "^0.5.3", + "load-grunt-tasks": "^3.3.0" }, "plugin": { "name": "Genesis Simple Sidebars", From be896fd1230463fb7d3f868d957ce05920e0ec84 Mon Sep 17 00:00:00 2001 From: Nathan Rice Date: Mon, 12 Oct 2015 16:04:42 -0400 Subject: [PATCH 02/25] Update grunt dependencies. --- package.json | 30 +++++++++++++++--------------- plugin.php | 2 +- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index eea18fa..60f2b1b 100644 --- a/package.json +++ b/package.json @@ -7,21 +7,21 @@ }, "dependencies": {}, "devDependencies": { - "grunt": "^0.4.5", - "grunt-autoprefixer": "^0.8.1", - "grunt-checktextdomain": "^0.1.1", - "grunt-contrib-cssmin": "^0.10.0", - "grunt-contrib-imagemin": "^0.7.1", - "grunt-contrib-jshint": "^0.10.0", - "grunt-contrib-uglify": "^0.5.0", - "grunt-contrib-watch": "^0.6.1", - "grunt-csscomb": "~2.0.1", - "grunt-jsbeautifier": "^0.2.7", - "grunt-jsvalidate": "^0.2.2", - "grunt-phplint": "0.0.5", - "grunt-styledocco": "^0.1.4", - "grunt-wp-i18n": "^0.5.3", - "load-grunt-tasks": "^3.3.0" + "grunt": "*", + "grunt-autoprefixer": "*", + "grunt-checktextdomain": "*", + "grunt-contrib-cssmin": "*", + "grunt-contrib-imagemin": "*", + "grunt-contrib-jshint": "*", + "grunt-contrib-uglify": "*", + "grunt-contrib-watch": "*", + "grunt-csscomb": "*", + "grunt-jsbeautifier": "*", + "grunt-jsvalidate": "*", + "grunt-phplint": "*", + "grunt-styledocco": "*", + "grunt-wp-i18n": "*", + "load-grunt-tasks": "*" }, "plugin": { "name": "Genesis Simple Sidebars", diff --git a/plugin.php b/plugin.php index 13f5e46..c1e1391 100644 --- a/plugin.php +++ b/plugin.php @@ -7,7 +7,7 @@ Author URI: http://www.nathanrice.net/ Text Domain: genesis-simple-sidebars -Domain Path: /languages/ +Domain Path: /languages Version: 2.0.2 From 4106eb6c68a3ad82c8199fe289c61ee746672fbf Mon Sep 17 00:00:00 2001 From: Lauren Mancke Date: Mon, 25 Jan 2016 14:11:33 -0500 Subject: [PATCH 03/25] Add StudioPress --- readme.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.txt b/readme.txt index 0b65502..571f738 100644 --- a/readme.txt +++ b/readme.txt @@ -1,5 +1,5 @@ === Plugin Name === -Contributors: nathanrice, wpmuguru +Contributors: nathanrice, wpmuguru, studiopress Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=5553118 Tags: hooks, genesis, genesiswp, studiopress Requires at least: 3.6 From 93a304aa06cb2c609fd1116e49aad9440d442ba6 Mon Sep 17 00:00:00 2001 From: Nathan Rice Date: Wed, 24 Feb 2016 14:48:19 -0500 Subject: [PATCH 04/25] Update for new term meta handling. --- includes/term.php | 4 ++-- plugin.php | 42 ++++++++++++------------------------------ 2 files changed, 14 insertions(+), 32 deletions(-) diff --git a/includes/term.php b/includes/term.php index 74d08b6..562f50a 100644 --- a/includes/term.php +++ b/includes/term.php @@ -37,7 +37,7 @@ function ss_term_sidebar($tag, $taxonomy) { $info ) { - printf( '', esc_html( $id ), selected( $id, $tag->meta['_ss_sidebar'] , false), esc_html( $info['name'] ) ); + printf( '', esc_html( $id ), selected( $id, get_term_meta( $tag->term_id, '_ss_sidebar', true ), false), esc_html( $info['name'] ) ); } ?> @@ -54,7 +54,7 @@ function ss_term_sidebar($tag, $taxonomy) { $info ) { - printf( '', esc_html( $id ), selected( $id, $tag->meta['_ss_sidebar_alt'] , false), esc_html( $info['name'] ) ); + printf( '', esc_html( $id ), selected( $id, get_term_meta( $tag->term_id, '_ss_sidebar_alt', true ), false), esc_html( $info['name'] ) ); } ?> diff --git a/plugin.php b/plugin.php index c1e1391..742a985 100644 --- a/plugin.php +++ b/plugin.php @@ -9,7 +9,7 @@ Text Domain: genesis-simple-sidebars Domain Path: /languages -Version: 2.0.2 +Version: 2.0.3 License: GNU General Public License v2.0 (or later) License URI: http://www.opensource.org/licenses/gpl-license.php @@ -30,8 +30,8 @@ */ function ss_activation_check() { - if ( ! defined( 'PARENT_THEME_VERSION' ) || ! version_compare( PARENT_THEME_VERSION, '2.0.0', '>=' ) ) - ss_deactivate( '2.0.0', '3.6' ); + if ( ! defined( 'PARENT_THEME_VERSION' ) || ! version_compare( PARENT_THEME_VERSION, '2.2.7', '>=' ) ) + ss_deactivate( '2.2.7', '4.4.2' ); } @@ -42,7 +42,7 @@ function ss_activation_check() { * * @since 1.0.0 */ -function ss_deactivate( $genesis_version = '1.8.0', $wp_version = '3.3' ) { +function ss_deactivate( $genesis_version = '2.2.7', $wp_version = '4.4.2' ) { deactivate_plugins( plugin_basename( __FILE__ ) ); wp_die( sprintf( __( 'Sorry, you cannot run Simple Sidebars without WordPress %s and Genesis %s, or greater.', 'genesis-simple-sidebars' ), $wp_version, 'http://my.studiopress.com/?download_id=91046d629e74d525b3f2978e404e7ffa', $genesis_version ) ); @@ -169,37 +169,19 @@ function ss_do_sidebar_alt() { */ function ss_do_one_sidebar( $sidebar_key = '_ss_sidebar' ) { - static $taxonomies = null; - if ( is_singular() && $sidebar_key = genesis_get_custom_field( $sidebar_key ) ) { - if ( dynamic_sidebar( $sidebar_key ) ) return true; - } - - if ( is_category() ) { - $term = get_term( get_query_var( 'cat' ), 'category' ); - if ( isset( $term->meta[$sidebar_key] ) && dynamic_sidebar( $term->meta[$sidebar_key] ) ) return true; - } - - if ( is_tag() ) { - $term = get_term( get_query_var( 'tag_id' ), 'post_tag' ); - if ( isset( $term->meta[$sidebar_key] ) && dynamic_sidebar( $term->meta[$sidebar_key] ) ) return true; + if ( dynamic_sidebar( $sidebar_key ) ) { + return true; + } } - if ( is_tax() ) { - if ( null === $taxonomies ) - $taxonomies = ss_get_taxonomies(); + if ( is_tax() || is_category() || is_tag() ) { - foreach ( $taxonomies as $tax ) { - if ( 'post_tag' == $tax || 'category' == $tax ) - continue; - - if ( is_tax( $tax ) ) { - $obj = get_queried_object(); - $term = get_term( $obj->term_id, $tax ); - if ( isset( $term->meta[$sidebar_key] ) && dynamic_sidebar( $term->meta[$sidebar_key] ) ) return true; - break; - } + if ( $sidebar_key = get_term_meta( get_queried_object()->term_id, $sidebar_key, true ) ) { + dynamic_sidebar( $sidebar_key ); + return true; } + } return false; From 4d09f1c1ac8cf0baa5232263e52e0eb8ed41fa54 Mon Sep 17 00:00:00 2001 From: Nathan Rice Date: Wed, 24 Feb 2016 14:51:29 -0500 Subject: [PATCH 05/25] Update POT. --- Gruntfile.js | 12 ++++++------ languages/genesis-simple-sidebars.pot | 10 +++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 38f6c2a..230ed93 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -20,7 +20,7 @@ module.exports = function(grunt) { // I18n - + // Add text domain as last argument of i18n functions addtextdomain: { php: { @@ -43,15 +43,15 @@ module.exports = function(grunt) { '_e:1,2d', '_x:1,2c,3d', '_ex:1,2c,3d', - '_n:1,2,4d', + '_n:1,2,4d', '_nx:1,2,4c,5d', '_n_noop:1,2,3d', '_nx_noop:1,2,3c,4d', - 'esc_attr__:1,2d', + 'esc_attr__:1,2d', 'esc_html__:1,2d', - 'esc_attr_e:1,2d', + 'esc_attr_e:1,2d', 'esc_html_e:1,2d', - 'esc_attr_x:1,2c,3d', + 'esc_attr_x:1,2c,3d', 'esc_html_x:1,2c,3d' ] }, @@ -75,7 +75,7 @@ module.exports = function(grunt) { pot.headers['last-translator'] = 'StudioPress '; pot.headers['language-team'] = 'English '; pot.headers['plural-forms'] = 'nplurals=2; plural=n != 1;'; - pot.headers['x-generator'] = 'grunt-wp-i18n 0.4.4'; + pot.headers['x-generator'] = 'grunt-wp-i18n'; pot.headers['x-poedit-basepath'] = '.'; pot.headers['x-poedit-language'] = 'English'; pot.headers['x-poedit-country'] = 'UNITED STATES'; diff --git a/languages/genesis-simple-sidebars.pot b/languages/genesis-simple-sidebars.pot index 1c55ce6..16e7420 100644 --- a/languages/genesis-simple-sidebars.pot +++ b/languages/genesis-simple-sidebars.pot @@ -1,17 +1,17 @@ -# Copyright (C) 2015 Nathan Rice +# Copyright (C) 2016 Nathan Rice # This file is distributed under the GNU General Public License v2.0 (or later). msgid "" msgstr "" -"Project-Id-Version: Genesis Simple Sidebars 2.0.2\n" +"Project-Id-Version: Genesis Simple Sidebars 2.0.3\n" "Report-Msgid-Bugs-To: StudioPress \n" -"POT-Creation-Date: 2015-09-29 20:53:32+00:00\n" +"POT-Creation-Date: 2016-02-24 19:51:21+00:00\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" -"PO-Revision-Date: 2015-MO-DA HO:MI+ZONE\n" +"PO-Revision-Date: 2016-MO-DA HO:MI+ZONE\n" "Last-Translator: StudioPress \n" "Language-Team: English \n" -"X-Generator: grunt-wp-i18n 0.4.4\n" +"X-Generator: grunt-wp-i18n\n" "Plural-Forms: nplurals=2; plural=n != 1;\n" "X-Poedit-Basepath: .\n" "X-Poedit-Language: English\n" From 36553a655757024bf85df901fd92624aafd5590d Mon Sep 17 00:00:00 2001 From: Nathan Rice Date: Wed, 24 Feb 2016 14:54:21 -0500 Subject: [PATCH 06/25] Bump version, update Readme.txt. --- package.json | 2 +- readme.txt | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 60f2b1b..ed80923 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "description": "Genesis Simple Sidebars allows you to easily create and use new sidebar widget areas.", "author": "StudioPress", "authoruri": "http://www.studiopress.com/", - "version": "2.0.2", + "version": "2.0.3", "license": "GPL-2.0+", "licenseuri": "http://www.gnu.org/licenses/gpl-2.0.html", "textdomain": "genesis-simple-sidebars" diff --git a/readme.txt b/readme.txt index 571f738..2caec34 100644 --- a/readme.txt +++ b/readme.txt @@ -2,9 +2,9 @@ Contributors: nathanrice, wpmuguru, studiopress Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=5553118 Tags: hooks, genesis, genesiswp, studiopress -Requires at least: 3.6 -Tested up to: 4.3.1 -Stable tag: 2.0.2 +Requires at least: 4.4.2 +Tested up to: 4.4.2 +Stable tag: 2.0.3 This plugin allows you to create multiple, dynamic widget areas, and assign those widget areas to sidebar locations within the Genesis Framework on a per post, per page, or per tag/category archive basis. @@ -37,6 +37,10 @@ Not in the way you're probably thinking. The markup surrounding the widget area == Changelog == += 2.0.3 = +* Update for WordPress 4.4+ and Genesis 2.2.7+ +* DO NOT upgrade to 2.0.3 unless you are running WordPress 4.4+ AND Genesis 2.2.7+ + = 2.0.2 = * Change text domain, update POT file. From 97fac5c57b94f741b61504cf2bb1818f4f060c59 Mon Sep 17 00:00:00 2001 From: Nathan Rice Date: Thu, 21 Apr 2016 11:32:39 -0400 Subject: [PATCH 07/25] Fix errors associated with variables not being set. see #8, #17. --- includes/inpost.php | 4 ++-- plugin.php | 4 ++++ readme.txt | 9 ++++++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/includes/inpost.php b/includes/inpost.php index 9f75364..7b99b68 100644 --- a/includes/inpost.php +++ b/includes/inpost.php @@ -80,8 +80,8 @@ function ss_inpost_metabox_save( $post_id, $post ) { return $post->ID; $_sidebars = array( - '_ss_sidebar' => $_POST['_ss_sidebar'], - '_ss_sidebar_alt' => $_POST['_ss_sidebar_alt'], + '_ss_sidebar' => isset( $_POST['_ss_sidebar'] ) ? $_POST['_ss_sidebar'] : '', + '_ss_sidebar_alt' => isset( $_POST['_ss_sidebar_alt'] ) ? $_POST['_ss_sidebar_alt'] : '', ); //* store the custom fields diff --git a/plugin.php b/plugin.php index 742a985..b884246 100644 --- a/plugin.php +++ b/plugin.php @@ -101,6 +101,10 @@ function ss_register_sidebars() { //* Cycle through created sidebars, register them as widget areas foreach ( (array) $_sidebars as $id => $info ) { + if ( ! isset( $info['name'] ) || ! isset( $info['description'] ) ) { + continue; + } + genesis_register_sidebar( array( 'name' => esc_html( $info['name'] ), 'id' => $id, diff --git a/readme.txt b/readme.txt index 2caec34..179cb19 100644 --- a/readme.txt +++ b/readme.txt @@ -2,8 +2,8 @@ Contributors: nathanrice, wpmuguru, studiopress Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=5553118 Tags: hooks, genesis, genesiswp, studiopress -Requires at least: 4.4.2 -Tested up to: 4.4.2 +Requires at least: 3.6 +Tested up to: 4.5 Stable tag: 2.0.3 This plugin allows you to create multiple, dynamic widget areas, and assign those widget areas to sidebar locations within the Genesis Framework on a per post, per page, or per tag/category archive basis. @@ -37,10 +37,13 @@ Not in the way you're probably thinking. The markup surrounding the widget area == Changelog == -= 2.0.3 = += 2.0.4 = * Update for WordPress 4.4+ and Genesis 2.2.7+ * DO NOT upgrade to 2.0.3 unless you are running WordPress 4.4+ AND Genesis 2.2.7+ += 2.0.3 = +* Fix warnings and notices + = 2.0.2 = * Change text domain, update POT file. From eff4992b6c21484aa706c26f4eaf04f4cbbba63c Mon Sep 17 00:00:00 2001 From: Tiago Hillebrandt Date: Mon, 13 Jun 2016 14:20:36 -0500 Subject: [PATCH 08/25] ping gitbot --- README.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ + From c7fdc4387e28d50ad7b73d9c166d7475963de249 Mon Sep 17 00:00:00 2001 From: Nathan Rice Date: Fri, 17 Jun 2016 17:04:30 -0400 Subject: [PATCH 09/25] Bump version. --- package.json | 2 +- plugin.php | 8 ++++---- readme.txt | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index ed80923..88cc5cc 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "description": "Genesis Simple Sidebars allows you to easily create and use new sidebar widget areas.", "author": "StudioPress", "authoruri": "http://www.studiopress.com/", - "version": "2.0.3", + "version": "2.0.4", "license": "GPL-2.0+", "licenseuri": "http://www.gnu.org/licenses/gpl-2.0.html", "textdomain": "genesis-simple-sidebars" diff --git a/plugin.php b/plugin.php index b884246..401ae36 100644 --- a/plugin.php +++ b/plugin.php @@ -9,7 +9,7 @@ Text Domain: genesis-simple-sidebars Domain Path: /languages -Version: 2.0.3 +Version: 2.0.4 License: GNU General Public License v2.0 (or later) License URI: http://www.opensource.org/licenses/gpl-license.php @@ -30,8 +30,8 @@ */ function ss_activation_check() { - if ( ! defined( 'PARENT_THEME_VERSION' ) || ! version_compare( PARENT_THEME_VERSION, '2.2.7', '>=' ) ) - ss_deactivate( '2.2.7', '4.4.2' ); + if ( ! defined( 'PARENT_THEME_VERSION' ) || ! version_compare( PARENT_THEME_VERSION, '2.3.0', '>=' ) ) + ss_deactivate( '2.3.0', '4.4.2' ); } @@ -42,7 +42,7 @@ function ss_activation_check() { * * @since 1.0.0 */ -function ss_deactivate( $genesis_version = '2.2.7', $wp_version = '4.4.2' ) { +function ss_deactivate( $genesis_version = '2.3.0', $wp_version = '4.4.2' ) { deactivate_plugins( plugin_basename( __FILE__ ) ); wp_die( sprintf( __( 'Sorry, you cannot run Simple Sidebars without WordPress %s and Genesis %s, or greater.', 'genesis-simple-sidebars' ), $wp_version, 'http://my.studiopress.com/?download_id=91046d629e74d525b3f2978e404e7ffa', $genesis_version ) ); diff --git a/readme.txt b/readme.txt index 179cb19..274d64d 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i Tags: hooks, genesis, genesiswp, studiopress Requires at least: 3.6 Tested up to: 4.5 -Stable tag: 2.0.3 +Stable tag: 2.0.4 This plugin allows you to create multiple, dynamic widget areas, and assign those widget areas to sidebar locations within the Genesis Framework on a per post, per page, or per tag/category archive basis. @@ -38,8 +38,8 @@ Not in the way you're probably thinking. The markup surrounding the widget area == Changelog == = 2.0.4 = -* Update for WordPress 4.4+ and Genesis 2.2.7+ -* DO NOT upgrade to 2.0.3 unless you are running WordPress 4.4+ AND Genesis 2.2.7+ +* Update for WordPress 4.4+ and Genesis 2.3.0+ +* DO NOT upgrade to 2.0.4 unless you are running WordPress 4.4+ AND Genesis 2.3.0+ = 2.0.3 = * Fix warnings and notices From febb5ede11f23fa1f27f7040d6c8e533f08bb2cf Mon Sep 17 00:00:00 2001 From: Nathan Rice Date: Wed, 1 Mar 2017 19:51:34 -0500 Subject: [PATCH 10/25] Rewrite based on new plugin boilerplate. --- Gruntfile.js | 24 +- README.md | 1 - genesis-simple-sidebars.php | 187 +++++++++++++++ ...> class-genesis-simple-sidebars-admin.php} | 110 +++++---- .../class-genesis-simple-sidebars-core.php | 223 ++++++++++++++++++ .../class-genesis-simple-sidebars-entry.php | 63 +++++ .../class-genesis-simple-sidebars-term.php | 31 +++ includes/deprecated.php | 161 +++++++++++++ includes/inpost.php | 102 -------- includes/term.php | 69 ------ includes/views/{edit.php => admin-edit.php} | 17 +- includes/views/{main.php => admin-main.php} | 5 +- includes/views/entry-metabox-content.php | 46 ++++ includes/views/term-edit-sidebar-form.php | 51 ++++ languages/genesis-simple-sidebars.pot | 10 +- package.json | 32 +-- plugin.php | 217 +---------------- readme.txt | 47 ++-- 18 files changed, 895 insertions(+), 501 deletions(-) delete mode 100644 README.md create mode 100644 genesis-simple-sidebars.php rename includes/{admin.php => class-genesis-simple-sidebars-admin.php} (78%) create mode 100644 includes/class-genesis-simple-sidebars-core.php create mode 100644 includes/class-genesis-simple-sidebars-entry.php create mode 100644 includes/class-genesis-simple-sidebars-term.php create mode 100644 includes/deprecated.php delete mode 100644 includes/inpost.php delete mode 100644 includes/term.php rename includes/views/{edit.php => admin-edit.php} (79%) rename includes/views/{main.php => admin-main.php} (94%) create mode 100644 includes/views/entry-metabox-content.php create mode 100644 includes/views/term-edit-sidebar-form.php diff --git a/Gruntfile.js b/Gruntfile.js index 230ed93..e965fb1 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -20,17 +20,21 @@ module.exports = function(grunt) { // I18n - + // Add text domain as last argument of i18n functions addtextdomain: { php: { options: { updateDomains: true }, - src: [ - '*.php', - 'lib/**/*.php' - ] + target: { + files: { + src: [ + '*.php', + 'lib/**/*.php' + ] + } + } } }, @@ -43,15 +47,15 @@ module.exports = function(grunt) { '_e:1,2d', '_x:1,2c,3d', '_ex:1,2c,3d', - '_n:1,2,4d', + '_n:1,2,4d', '_nx:1,2,4c,5d', '_n_noop:1,2,3d', '_nx_noop:1,2,3c,4d', - 'esc_attr__:1,2d', + 'esc_attr__:1,2d', 'esc_html__:1,2d', - 'esc_attr_e:1,2d', + 'esc_attr_e:1,2d', 'esc_html_e:1,2d', - 'esc_attr_x:1,2c,3d', + 'esc_attr_x:1,2c,3d', 'esc_html_x:1,2c,3d' ] }, @@ -75,7 +79,7 @@ module.exports = function(grunt) { pot.headers['last-translator'] = 'StudioPress '; pot.headers['language-team'] = 'English '; pot.headers['plural-forms'] = 'nplurals=2; plural=n != 1;'; - pot.headers['x-generator'] = 'grunt-wp-i18n'; + pot.headers['x-generator'] = 'grunt-wp-i18n 0.4.4'; pot.headers['x-poedit-basepath'] = '.'; pot.headers['x-poedit-language'] = 'English'; pot.headers['x-poedit-country'] = 'UNITED STATES'; diff --git a/README.md b/README.md deleted file mode 100644 index 8b13789..0000000 --- a/README.md +++ /dev/null @@ -1 +0,0 @@ - diff --git a/genesis-simple-sidebars.php b/genesis-simple-sidebars.php new file mode 100644 index 0000000..622bc3d --- /dev/null +++ b/genesis-simple-sidebars.php @@ -0,0 +1,187 @@ +plugin_dir_url = plugin_dir_url( __FILE__ ); + $this->plugin_dir_path = plugin_dir_path( __FILE__ ); + + // For backward compatibility + define( 'SS_PLUGIN_DIR', $this->plugin_dir_path ); + + } + + /** + * Initialize. + * + * @since 2.1.0 + */ + public function init() { + + register_activation_hook( __FILE__, array( $this, 'activation' ) ); + + $this->load_plugin_textdomain(); + $this->includes(); + $this->instantiate(); + + } + + /** + * Plugin activation hook. Runs when plugin is activated. + * + * @since 2.1.0 + */ + public function activation() { + + if ( ! defined( 'PARENT_THEME_VERSION' ) || ! version_compare( PARENT_THEME_VERSION, $this->min_genesis_version, '>=' ) ) { + + deactivate_plugins( plugin_basename( __FILE__ ) ); + wp_die( sprintf( __( 'Sorry, you cannot run Genesis Simple Sidebars without WordPress %s and Genesis %s, or greater.', 'genesis-simple-sidebars' ), $this->min_wp_version, 'http://my.studiopress.com/?download_id=91046d629e74d525b3f2978e404e7ffa', $this->min_genesis_version ) ); + + } + + } + + /** + * Load the plugin textdomain, for translation. + * + * @since 2.1.0 + */ + public function load_plugin_textdomain() { + load_plugin_textdomain( $this->plugin_textdomain, false, $this->plugin_dir_path . 'languages/' ); + } + + /** + * All general includes. + * + * @since 2.1.0 + */ + public function includes() { + + //require_once( $this->plugin_dir_path . 'includes/functions.php' ); + //require_once( $this->plugin_dir_path . 'includes/deprecated.php' ); + + } + + /** + * Include the class file, instantiate the classes, create objects. + * + * @since 2.1.0 + */ + public function instantiate() { + + add_action( 'genesis_setup', array( $this, 'genesis_dependencies' ) ); + + } + + /** + * Load and instantiate any Genesis dependencies. + * + * @since 2.1.0 + */ + public function genesis_dependencies() { + + require_once( $this->plugin_dir_path . 'includes/class-genesis-simple-sidebars-core.php' ); + $this->core = new Genesis_Simple_Sidebars_Core; + $this->core->init(); + + // Anything beyond this point should only be loaded if in the admin. + if ( ! is_admin() ) { + return; + } + + require_once( $this->plugin_dir_path . 'includes/class-genesis-simple-sidebars-entry.php' ); + $this->entry = new Genesis_Simple_Sidebars_Entry; + $this->entry->init(); + + require_once( $this->plugin_dir_path . 'includes/class-genesis-simple-sidebars-term.php' ); + $this->term = new Genesis_Simple_Sidebars_Term; + $this->term->init(); + + require_once( $this->plugin_dir_path . 'includes/class-genesis-simple-sidebars-admin.php' ); + $this->admin = new Genesis_Simple_Sidebars_Admin; + $this->admin->admin_menu(); + + // For backward compatibility + global $_genesis_simple_sidebars; + $_genesis_simple_sidebars = $this->admin; + + } + +} + +/** + * Helper function to retrieve the static object without using globals. + * + * @since 2.1.0 + */ +function Genesis_Simple_Sidebars() { + + static $object; + + if ( null == $object ) { + $object = new Genesis_Simple_Sidebars; + } + + return $object; +} +/** + * Initialize the object on `plugins_loaded`. + */ +add_action( 'plugins_loaded', array( Genesis_Simple_Sidebars(), 'init' ) ); diff --git a/includes/admin.php b/includes/class-genesis-simple-sidebars-admin.php similarity index 78% rename from includes/admin.php rename to includes/class-genesis-simple-sidebars-admin.php index f045e32..fb9c1f8 100644 --- a/includes/admin.php +++ b/includes/class-genesis-simple-sidebars-admin.php @@ -13,6 +13,25 @@ */ class Genesis_Simple_Sidebars_Admin extends Genesis_Admin_Basic { + /** + * Settings field. + * + * @since 2.1.0 + */ + public $settings_field; + + /** + * Constructor. + */ + public function __construct() { + + $this->settings_field = Genesis_Simple_Sidebars()->settings_field; + + // For backward compatibility + define( 'SS_SETTINGS_FIELD', $this->settings_field ); + + } + /** * Create an admin menu item and settings page. * @@ -22,7 +41,7 @@ class Genesis_Simple_Sidebars_Admin extends Genesis_Admin_Basic { * * @see Genesis_Admin_Import_Export::actions() Handle creating, editing, and deleting sidebars. */ - public function __construct() { + public function admin_menu() { $page_id = 'simple-sidebars'; @@ -34,14 +53,12 @@ public function __construct() { ) ); - //* Empty, as we'll be building the page manually + // Empty, as we'll be building the page manually $page_ops = array(); - $settings_field = SS_SETTINGS_FIELD; - - $this->create( $page_id, $menu_ops, $page_ops, $settings_field ); + $this->create( $page_id, $menu_ops, $page_ops, $this->settings_field ); - //* Simpe Sidebar actions (create, edit, or delete) + // Simpe Sidebar actions (create, edit, or delete) add_action( 'admin_init', array( $this, 'actions' ) ); } @@ -56,14 +73,14 @@ public function __construct() { */ public function admin() { - $_sidebars = get_option( $this->settings_field ); - echo '
'; - if ( isset( $_REQUEST['action'] ) && 'edit' == $_REQUEST['action'] ) - require_once( SS_PLUGIN_DIR . '/includes/views/edit.php' ); - else - require_once( SS_PLUGIN_DIR . '/includes/views/main.php' ); + if ( isset( $_REQUEST['action'] ) && 'edit' == $_REQUEST['action'] ) { + require_once( Genesis_Simple_Sidebars()->plugin_dir_path . '/includes/views/admin-edit.php' ); + } + else { + require_once( Genesis_Simple_Sidebars()->plugin_dir_path . '/includes/views/admin-main.php' ); + } echo '
'; @@ -129,8 +146,9 @@ public function table_rows() { */ public function actions() { - if ( ! genesis_is_menu_page( 'simple-sidebars' ) ) + if ( ! genesis_is_menu_page( 'simple-sidebars' ) ) { return; + } /** * This section handles the data if a new sidebar is created @@ -164,8 +182,9 @@ public function actions() { */ public function notices() { - if ( ! genesis_is_menu_page( 'simple-sidebars' ) ) + if ( ! genesis_is_menu_page( 'simple-sidebars' ) ) { return; + } $pattern = '

%s

'; @@ -196,34 +215,39 @@ public function notices() { */ protected function create_sidebar( $args = array() ) { - if ( empty( $args['name'] ) || empty( $args['id'] ) ) { + if ( empty( $args['name'] ) ) { wp_die( $this->error( 1 ) ); exit; } - //* nonce verification + // nonce verification check_admin_referer( 'simple-sidebars-action_create-sidebar' ); - //* WP changes a numeric sidebar id to sidebar-id which makes it inaccessible to the user - if ( is_numeric( $args['id'] ) ) - $args['id'] = sanitize_title_with_dashes( $args['name'] ); + // Change empty or numeric IDs to the name, lowercased and separated by dashes. + if ( empty( $args['id'] ) || is_numeric( $args['id'] ) ) { + $args['id'] = $args['name']; + } + + // Strip all but alphanumeric, sanitize with dashes. + $id = preg_replace( "/[^a-zA-Z0-9 -]+/", "", sanitize_title_with_dashes( $args['id'] ) ); + + $db = (array) get_option( $this->settings_field ); - $db = (array) get_option( SS_SETTINGS_FIELD ); $new = array( - sanitize_title_with_dashes( $args['id'] ) => array( - 'name' => esc_html( $args['name'] ), + $id => array( + 'name' => esc_html( $args['name'] ), 'description' => esc_html( $args['description'] ) - ) + ), ); - if ( array_key_exists( $args['id'], $db ) ) { + if ( array_key_exists( $id, $db ) ) { wp_die( $this->error( 2 ) ); exit; } $_sidebars = wp_parse_args( $new, $db ); - update_option( SS_SETTINGS_FIELD, $_sidebars ); + update_option( $this->settings_field, $_sidebars ); wp_redirect( admin_url( 'admin.php?page=simple-sidebars&created=true' ) ); exit; @@ -242,17 +266,13 @@ protected function edit_sidebar( $args = array() ) { exit; } - //* nonce verification + // nonce verification check_admin_referer( 'simple-sidebars-action_edit-sidebar' ); - //* WP changes a numeric sidebar id to sidebar-id which makes it inaccessible to the user - if ( is_numeric( $args['id'] ) ) - $args['id'] = sanitize_title_with_dashes( $args['name'] ); - - $db = (array) get_option( SS_SETTINGS_FIELD ); + $db = (array) get_option( $this->settings_field ); $new = array( - sanitize_title_with_dashes( $args['id'] ) => array( - 'name' => esc_html( $args['name'] ), + $args['id'] => array( + 'name' => esc_html( $args['name'] ), 'description' => esc_html( $args['description'] ) ) ); @@ -264,7 +284,7 @@ protected function edit_sidebar( $args = array() ) { $_sidebars = wp_parse_args( $new, $db ); - update_option( SS_SETTINGS_FIELD, $_sidebars ); + update_option( $this->settings_field, $_sidebars ); wp_redirect( admin_url( 'admin.php?page=simple-sidebars&edited=true' ) ); exit; @@ -283,10 +303,10 @@ protected function delete_sidebar( $id = '' ) { exit; } - //* nonce verification + // nonce verification check_admin_referer( 'simple-sidebars-action_delete-sidebar' ); - $_sidebars = (array) get_option( SS_SETTINGS_FIELD ); + $_sidebars = (array) get_option( $this->settings_field ); if ( ! isset( $_sidebars[$id] ) ) { wp_die( $this->error( 4 ) ); @@ -295,7 +315,7 @@ protected function delete_sidebar( $id = '' ) { unset( $_sidebars[$id] ); - update_option( SS_SETTINGS_FIELD, $_sidebars ); + update_option( $this->settings_field, $_sidebars ); wp_redirect( admin_url( 'admin.php?page=simple-sidebars&deleted=true' ) ); exit; @@ -316,7 +336,7 @@ protected function error( $error = false ) { switch( (int) $error ) { case 1: - return __( 'Oops! Please choose a valid Name and ID for this sidebar', 'genesis-simple-sidebars' ); + return __( 'Oops! Please choose a valid Name for this sidebar', 'genesis-simple-sidebars' ); break; case 2: return __( 'Oops! That sidebar ID already exists', 'genesis-simple-sidebars' ); @@ -335,17 +355,3 @@ protected function error( $error = false ) { } } - -add_action( 'genesis_admin_menu', 'simplesidebars_settings_menu' ); -/** - * Instantiate the class to create the menu. - * - * @since 1.0.0 - */ -function simplesidebars_settings_menu() { - - global $_genesis_simple_sidebars_admin; - - $_genesis_simple_sidebars_admin = new Genesis_Simple_Sidebars_Admin; - -} diff --git a/includes/class-genesis-simple-sidebars-core.php b/includes/class-genesis-simple-sidebars-core.php new file mode 100644 index 0000000..1fb525c --- /dev/null +++ b/includes/class-genesis-simple-sidebars-core.php @@ -0,0 +1,223 @@ +core->get_sidebars(); + + if ( ! $sidebars ) { + return; + } + + // Cycle through created sidebars, register them as widget areas + foreach ( (array) $sidebars as $id => $info ) { + + if ( ! isset( $info['name'] ) || ! isset( $info['description'] ) ) { + continue; + } + + genesis_register_sidebar( array( + 'name' => esc_html( $info['name'] ), + 'id' => $id, + 'description' => esc_html( $info['description'] ), + 'editable' => 1, + ) ); + + } + + } + + /** + * Remove default sidebars and inject custom sidebars. + * + * @since 2.1.0 + */ + public function swap_sidebars() { + + // Header + if ( is_registered_sidebar( 'header-right' ) ) { + global $wp_registered_sidebars; + $wp_registered_sidebars['ss-header-right-temp'] = $wp_registered_sidebars['header-right']; + unset( $wp_registered_sidebars['header-right'] ); + add_action( 'genesis_header_right', array( $this, 'do_header_right' ) ); + } + + // Sidebars + remove_action( 'genesis_sidebar', 'genesis_do_sidebar' ); + remove_action( 'genesis_sidebar_alt', 'genesis_do_sidebar_alt' ); + add_action( 'genesis_sidebar', array( $this, 'do_primary_sidebar' ) ); + add_action( 'genesis_sidebar_alt', array( $this, 'do_secondary_sidebar' ) ); + + } + + /** + * Output custom header widget area, if one is set. Otherwise output default. + * + * @since 2.1.0 + */ + public function do_header_right() { + + global $wp_registered_sidebars; + + if ( ! $this->do_sidebar( '_ss_header' ) ) { + $wp_registered_sidebars['header-right'] = $wp_registered_sidebars['ss-header-right-temp']; + } + + unset( $wp_registered_sidebars['ss-header-right-temp'] ); + + } + + /** + * Output custom primary sidebar, if one is set. Otherwise output default. + * + * @since 2.1.0 + */ + public function do_primary_sidebar() { + + if ( ! $this->do_sidebar( '_ss_sidebar' ) ) { + genesis_do_sidebar(); + } + + } + + /** + * Output custom secondary sidebar, if one is set. Otherwise output default. + * + * @since 2.1.0 + */ + public function do_secondary_sidebar() { + + if ( ! $this->do_sidebar( '_ss_sidebar_alt' ) ) { + genesis_do_sidebar_alt(); + } + + } + + /** + * Show widgets in a particular sidebar. + * + * @param string $key sidebar id you wish to output. + * + * @since 2.1.0 + */ + public function do_sidebar( $key ) { + + if ( is_singular() && $key = genesis_get_custom_field( $key ) ) { + + if ( dynamic_sidebar( $key ) ) { + return true; + } + + } + + if ( is_tax() || is_category() || is_tag() ) { + + if ( $key = get_term_meta( get_queried_object()->term_id, $key, true ) ) { + dynamic_sidebar( $key ); + return true; + } + + } + + return false; + + } + + /** + * Get all custom registered sidebars. + * + * @since 2.1.0 + */ + public function get_sidebars( $cache = true ) { + + if ( ! $cache ) { + return stripslashes_deep( get_option( Genesis_Simple_Sidebars()->settings_field ) ); + } + + if ( is_null( $this->sidebars ) ) { + $this->sidebars = stripslashes_deep( get_option( Genesis_Simple_Sidebars()->settings_field ) ); + } + + return $this->sidebars; + + } + + /** + * Return taxonomy ids. + * + * Helper function to return the array keys from a taxonomy query. + * + * @since 2.1.0 + */ + public function get_public_taxonomies() { + + if ( is_null( $this->public_taxonomies ) ) { + $this->public_taxonomies = get_taxonomies( array( + 'show_ui' => true, + 'public' => true, + ) ); + } + + $this->public_taxonomies = apply_filters( 'genesis_simple_sidebars_taxonomies', array_keys( $this->public_taxonomies ) ); + + return $this->public_taxonomies; + + } + + /** + * Determines if this site has disabled 3 column layouts or not. + * + * @since 2.1.0 + */ + public function has_3_column_layout() { + + $layouts = genesis_get_layouts(); + + $three_column_layouts = array( + 'content-sidebar-sidebar', + 'sidebar-content-sidebar', + 'sidebar-sidebar-content', + ); + + foreach ( $three_column_layouts as $layout ) { + if ( array_key_exists( $layout, $layouts ) ) { + return true; + } + } + + return false; + + } + +} diff --git a/includes/class-genesis-simple-sidebars-entry.php b/includes/class-genesis-simple-sidebars-entry.php new file mode 100644 index 0000000..5c05e3c --- /dev/null +++ b/includes/class-genesis-simple-sidebars-entry.php @@ -0,0 +1,63 @@ + true ) ) as $type ) { + + if ( post_type_supports( $type, 'genesis-simple-sidebars' ) || $type == 'post' || $type == 'page' ) { + add_meta_box( 'ss_inpost_metabox', __( 'Sidebar Selection', 'genesis-simple-sidebars' ), array( $this, 'metabox_content' ), $type, 'side', 'low' ); + } + + } + + } + + /** + * Include the metabox content. + * + * @since 2.1.0 + */ + public function metabox_content() { + + require_once( Genesis_Simple_Sidebars()->plugin_dir_path . 'includes/views/entry-metabox-content.php' ); + + print_r( get_post_meta( get_the_ID() ) ); + + } + + /** + * Save the metabox fields when the entry is saved. + * + * @since 2.1.0 + */ + public function metabox_save( $post_id, $post ) { + + if ( ! isset( $_POST['genesis_simple_sidebars'] ) ) { + return; + } + + $data = wp_parse_args( $_POST['genesis_simple_sidebars'], array( + '_ss_header' => '', + '_ss_sidebar' => '', + '_ss_sidebar_alt' => '', + ) ); + + genesis_save_custom_fields( $data, 'genesis-simple-sidebars-save-entry', 'genesis-simple-sidebars-save-entry-nonce', $post ); + + } + +} diff --git a/includes/class-genesis-simple-sidebars-term.php b/includes/class-genesis-simple-sidebars-term.php new file mode 100644 index 0000000..af9f64b --- /dev/null +++ b/includes/class-genesis-simple-sidebars-term.php @@ -0,0 +1,31 @@ +core->get_public_taxonomies(); + + if ( ! empty( $taxonomies ) && is_admin() && is_array( $taxonomies ) ) { + + foreach ( $taxonomies as $tax ) { + add_action( "{$tax}_edit_form", array( $this, 'term_sidebar_form' ), 9, 2 ); + } + + } + + } + + public function term_sidebar_form( $tag, $taxonomy ) { + + require_once( Genesis_Simple_Sidebars()->plugin_dir_path . 'includes/views/term-edit-sidebar-form.php' ); + + } + +} diff --git a/includes/deprecated.php b/includes/deprecated.php new file mode 100644 index 0000000..ab4cbf4 --- /dev/null +++ b/includes/deprecated.php @@ -0,0 +1,161 @@ + true ) ) as $type ) { - - if ( post_type_supports( $type, 'genesis-simple-sidebars' ) || $type == 'post' || $type == 'page' ) { - add_meta_box( 'ss_inpost_metabox', __( 'Sidebar Selection', 'genesis-simple-sidebars' ), 'ss_inpost_metabox', $type, 'side', 'low' ); - } - - } - -} - -function ss_inpost_metabox() { - - $_sidebars = stripslashes_deep( get_option( SS_SETTINGS_FIELD ) ); - global $wp_registered_sidebars; - -?> - - - - - -

- - -

- -

- - -

- -ID; - - //* don't try to save the data under autosave, ajax, or future post. - if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return; - if ( defined('DOING_AJAX') && DOING_AJAX ) return; - if ( defined('DOING_CRON') && DOING_CRON ) return; - - //* is the user allowed to edit the post or page? - if ( ( 'page' == $_POST['post_type'] && ! current_user_can( 'edit_page', $post->ID ) ) || ! current_user_can( 'edit_post', $post->ID ) ) - return $post->ID; - - $_sidebars = array( - '_ss_sidebar' => isset( $_POST['_ss_sidebar'] ) ? $_POST['_ss_sidebar'] : '', - '_ss_sidebar_alt' => isset( $_POST['_ss_sidebar_alt'] ) ? $_POST['_ss_sidebar_alt'] : '', - ); - - //* store the custom fields - foreach ( $_sidebars as $key => $value ) { - - //* don't try to store data during revision save - if ( 'revision' === $post->post_type ) - return; - - if ( $value ) { - update_post_meta($post->ID, $key, $value); - } else { - delete_post_meta($post->ID, $key); - } - - } - -} diff --git a/includes/term.php b/includes/term.php deleted file mode 100644 index 562f50a..0000000 --- a/includes/term.php +++ /dev/null @@ -1,69 +0,0 @@ -meta = wp_parse_args( $tag->meta, array( '_ss_sidebar' => '', '_ss_sidebar_alt' => '' ) ); - - //* Pull custom sidebars - $_sidebars = stripslashes_deep( get_option( SS_SETTINGS_FIELD ) ); - -?> - -

- - - - - - - - - - - - -
- -
- -
- -core->get_sidebars(); + +if ( array_key_exists( $_REQUEST['id'], (array) $sidebars ) ) { + $sidebar = stripslashes_deep( $sidebars[ $_REQUEST['id'] ] ); } else { wp_die( __( 'Nice try, partner. But that sidebar doesn\'t exist. Click back and try again.', 'genesis-simple-sidebars' ) ); } - -screen_icon( 'themes' ); ?> -

+?> +

@@ -15,21 +16,21 @@ - +

- +

- + diff --git a/includes/views/main.php b/includes/views/admin-main.php similarity index 94% rename from includes/views/main.php rename to includes/views/admin-main.php index eedd871..2542455 100644 --- a/includes/views/main.php +++ b/includes/views/admin-main.php @@ -1,5 +1,4 @@ - -

+

@@ -67,4 +66,4 @@
- \ No newline at end of file + diff --git a/includes/views/entry-metabox-content.php b/includes/views/entry-metabox-content.php new file mode 100644 index 0000000..f728049 --- /dev/null +++ b/includes/views/entry-metabox-content.php @@ -0,0 +1,46 @@ +core->get_sidebars(); +global $wp_registered_sidebars; +wp_nonce_field( 'genesis-simple-sidebars-save-entry', 'genesis-simple-sidebars-save-entry-nonce' ); + +if ( is_registered_sidebar( 'header-right' ) ) : ?> +

+ + +

+ +

+ + +

+ +

+ + +

+core->get_sidebars(); ?> + +

+ + + + + + + + + + + + + + +core->has_3_column_layout() ) : ?> + + + + + +
+ +
+ +
+ +
diff --git a/languages/genesis-simple-sidebars.pot b/languages/genesis-simple-sidebars.pot index 16e7420..1c55ce6 100644 --- a/languages/genesis-simple-sidebars.pot +++ b/languages/genesis-simple-sidebars.pot @@ -1,17 +1,17 @@ -# Copyright (C) 2016 Nathan Rice +# Copyright (C) 2015 Nathan Rice # This file is distributed under the GNU General Public License v2.0 (or later). msgid "" msgstr "" -"Project-Id-Version: Genesis Simple Sidebars 2.0.3\n" +"Project-Id-Version: Genesis Simple Sidebars 2.0.2\n" "Report-Msgid-Bugs-To: StudioPress \n" -"POT-Creation-Date: 2016-02-24 19:51:21+00:00\n" +"POT-Creation-Date: 2015-09-29 20:53:32+00:00\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" -"PO-Revision-Date: 2016-MO-DA HO:MI+ZONE\n" +"PO-Revision-Date: 2015-MO-DA HO:MI+ZONE\n" "Last-Translator: StudioPress \n" "Language-Team: English \n" -"X-Generator: grunt-wp-i18n\n" +"X-Generator: grunt-wp-i18n 0.4.4\n" "Plural-Forms: nplurals=2; plural=n != 1;\n" "X-Poedit-Basepath: .\n" "X-Poedit-Language: English\n" diff --git a/package.json b/package.json index 88cc5cc..2b7a6f7 100644 --- a/package.json +++ b/package.json @@ -7,21 +7,21 @@ }, "dependencies": {}, "devDependencies": { - "grunt": "*", - "grunt-autoprefixer": "*", - "grunt-checktextdomain": "*", - "grunt-contrib-cssmin": "*", - "grunt-contrib-imagemin": "*", - "grunt-contrib-jshint": "*", - "grunt-contrib-uglify": "*", - "grunt-contrib-watch": "*", - "grunt-csscomb": "*", - "grunt-jsbeautifier": "*", - "grunt-jsvalidate": "*", - "grunt-phplint": "*", - "grunt-styledocco": "*", - "grunt-wp-i18n": "*", - "load-grunt-tasks": "*" + "grunt": "^0.4.5", + "grunt-autoprefixer": "^0.8.1", + "grunt-checktextdomain": "^0.1.1", + "grunt-contrib-cssmin": "^0.10.0", + "grunt-contrib-imagemin": "^0.7.1", + "grunt-contrib-jshint": "^0.10.0", + "grunt-contrib-uglify": "^0.5.0", + "grunt-contrib-watch": "^0.6.1", + "grunt-csscomb": "~2.0.1", + "grunt-jsbeautifier": "^0.2.7", + "grunt-jsvalidate": "^0.2.2", + "grunt-phplint": "0.0.5", + "grunt-styledocco": "^0.1.4", + "grunt-wp-i18n": "^0.4.7", + "load-grunt-tasks": "^0.6.0" }, "plugin": { "name": "Genesis Simple Sidebars", @@ -29,7 +29,7 @@ "description": "Genesis Simple Sidebars allows you to easily create and use new sidebar widget areas.", "author": "StudioPress", "authoruri": "http://www.studiopress.com/", - "version": "2.0.4", + "version": "2.0.2", "license": "GPL-2.0+", "licenseuri": "http://www.gnu.org/licenses/gpl-2.0.html", "textdomain": "genesis-simple-sidebars" diff --git a/plugin.php b/plugin.php index 401ae36..75613e0 100644 --- a/plugin.php +++ b/plugin.php @@ -2,224 +2,19 @@ /* Plugin Name: Genesis Simple Sidebars Plugin URI: http://www.studiopress.com/plugins/simple-sidebars + Description: Genesis Simple Sidebars allows you to easily create and use new sidebar widget areas. + Author: Nathan Rice Author URI: http://www.nathanrice.net/ -Text Domain: genesis-simple-sidebars -Domain Path: /languages +Version: 2.1.0 -Version: 2.0.4 +Text Domain: genesis-simple-sidebars +Domain Path: /languages/ License: GNU General Public License v2.0 (or later) License URI: http://www.opensource.org/licenses/gpl-license.php */ -/** Define our constants */ -define( 'SS_SETTINGS_FIELD', 'ss-settings' ); -define( 'SS_PLUGIN_DIR', dirname( __FILE__ ) ); - -register_activation_hook( __FILE__, 'ss_activation_check' ); -/** - * Activation hook callback. - * - * This functions runs when the plugin is activated. It checks to make sure the user is running - * a minimum Genesis version, so there are no conflicts or fatal errors. - * - * @since 0.9.0 - */ -function ss_activation_check() { - - if ( ! defined( 'PARENT_THEME_VERSION' ) || ! version_compare( PARENT_THEME_VERSION, '2.3.0', '>=' ) ) - ss_deactivate( '2.3.0', '4.4.2' ); - -} - -/** - * Deactivate Simple Sidebars. - * - * This function deactivates Simple Sidebars. - * - * @since 1.0.0 - */ -function ss_deactivate( $genesis_version = '2.3.0', $wp_version = '4.4.2' ) { - - deactivate_plugins( plugin_basename( __FILE__ ) ); - wp_die( sprintf( __( 'Sorry, you cannot run Simple Sidebars without WordPress %s and Genesis %s, or greater.', 'genesis-simple-sidebars' ), $wp_version, 'http://my.studiopress.com/?download_id=91046d629e74d525b3f2978e404e7ffa', $genesis_version ) ); - -} - -add_action( 'genesis_init', 'ss_genesis_init', 12 ); -/** - * Plugin initialization. - * - * Initialize the plugin, set the constants, hook callbacks to actions, and include the plugin library. - * - * @since 0.9.0 - */ -function ss_genesis_init() { - - //* Deactivate if not running Genesis 1.8.0 or greater - if ( ! class_exists( 'Genesis_Admin_Boxes' ) ) - add_action( 'admin_init', 'ss_deactivate', 10, 0 ); - - //* Load translations - load_plugin_textdomain( 'genesis-simple-sidebars', false, 'genesis-simple-sidebars/languages' ); - - //* required hooks - add_action( 'get_header', 'ss_sidebars_init' ); - add_action( 'widgets_init', 'ss_register_sidebars' ); - - //* The rest is admin stuff, so load only if we're in the admin area - if ( ! is_admin() ) - return; - - //* Include admin files - require_once( SS_PLUGIN_DIR . '/includes/admin.php' ); - require_once( SS_PLUGIN_DIR . '/includes/inpost.php' ); - require_once( SS_PLUGIN_DIR . '/includes/term.php' ); - - //* let the child theme hook the genesis_simple_sidebars_taxonomies filter before hooking term edit - add_action( 'init', 'ss_term_edit_init' ); - -} -/** - * Register widget areas. - * - * This function registers the created sidebars as widget areas - * - * @since 0.9.0 - */ -function ss_register_sidebars() { - - $_sidebars = stripslashes_deep( get_option( SS_SETTINGS_FIELD ) ); - - //* If no sidebars have been created, do nothing - if ( ! $_sidebars ) - return; - - //* Cycle through created sidebars, register them as widget areas - foreach ( (array) $_sidebars as $id => $info ) { - - if ( ! isset( $info['name'] ) || ! isset( $info['description'] ) ) { - continue; - } - - genesis_register_sidebar( array( - 'name' => esc_html( $info['name'] ), - 'id' => $id, - 'description' => esc_html( $info['description'] ), - 'editable' => 1, - ) ); - - } - -} - -/** - * Use custom sidebars. - * - * Remove the default sidebars, run some conditional logic, - * use alternate sidebars if necessary, else fallback on default sidebars. - * - * @since 0.9.0 - */ -function ss_sidebars_init() { - - remove_action( 'genesis_sidebar', 'genesis_do_sidebar' ); - remove_action( 'genesis_sidebar_alt', 'genesis_do_sidebar_alt' ); - add_action( 'genesis_sidebar', 'ss_do_sidebar' ); - add_action( 'genesis_sidebar_alt', 'ss_do_sidebar_alt' ); - -} - -/** - * Display primary sidebar. - * - * Display custom sidebar if one exists, else display default primary sidebar. - * - * @since 0.9.0 - */ -function ss_do_sidebar() { - - if ( ! ss_do_one_sidebar( '_ss_sidebar' ) ) - genesis_do_sidebar(); - -} - -/** - * Display secondary sidebar. - * - * Display custom sidebar if one exists, else display default secondary sidebar. - * - * @since 0.9.0 - */ -function ss_do_sidebar_alt() { - - if ( ! ss_do_one_sidebar( '_ss_sidebar_alt' ) ) - genesis_do_sidebar_alt(); - -} - -/** - * Sidebar widget area output. - * - * Helper function to show widgets in a particular sidebar. - * - * @param string $sidebar_key sidebar id you wish to output. - * - * @since 0.9.0 - * - */ -function ss_do_one_sidebar( $sidebar_key = '_ss_sidebar' ) { - - if ( is_singular() && $sidebar_key = genesis_get_custom_field( $sidebar_key ) ) { - if ( dynamic_sidebar( $sidebar_key ) ) { - return true; - } - } - - if ( is_tax() || is_category() || is_tag() ) { - - if ( $sidebar_key = get_term_meta( get_queried_object()->term_id, $sidebar_key, true ) ) { - dynamic_sidebar( $sidebar_key ); - return true; - } - - } - - return false; - -} - -/** - * Return taxonomy ids. - * - * Helper function to return the array keys from a taxonomy query. - * - * @since 0.9.0 - */ -function ss_get_taxonomies() { - - $taxonomies = get_taxonomies( array( 'show_ui' => true, 'public' => true ) ); - return apply_filters( 'genesis_simple_sidebars_taxonomies', array_keys( $taxonomies ) ); - -} - -/** - * Does this Genesis install have the 3 column layouts deactivated? - * - * This function checks to see if the Genesis install still has active 3 column layouts. Since - * child themes and plugins can deregister layouts, we need to know if they have deregistered the 3 column layouts. - * - * @since 0.9.2 - */ -function ss_has_3_column_layouts() { - - $_layouts = (array) genesis_get_layouts(); - $_layouts = array_keys( $_layouts ); - $_3_column = array_intersect( $_layouts, array( 'content-sidebar-sidebar', 'sidebar-content-sidebar', 'sidebar-sidebar-content' ) ); - - return ! empty( $_3_column ); - -} +require_once( plugin_dir_path( __FILE__ ) . 'genesis-simple-sidebars.php' ); diff --git a/readme.txt b/readme.txt index 274d64d..606fa31 100644 --- a/readme.txt +++ b/readme.txt @@ -1,10 +1,10 @@ === Plugin Name === -Contributors: nathanrice, wpmuguru, studiopress +Contributors: nathanrice, wpmuguru Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=5553118 Tags: hooks, genesis, genesiswp, studiopress Requires at least: 3.6 Tested up to: 4.5 -Stable tag: 2.0.4 +Stable tag: 2.1.0 This plugin allows you to create multiple, dynamic widget areas, and assign those widget areas to sidebar locations within the Genesis Framework on a per post, per page, or per tag/category archive basis. @@ -37,49 +37,48 @@ Not in the way you're probably thinking. The markup surrounding the widget area == Changelog == -= 2.0.4 = -* Update for WordPress 4.4+ and Genesis 2.3.0+ -* DO NOT upgrade to 2.0.4 unless you are running WordPress 4.4+ AND Genesis 2.3.0+ += 2.1.0 = +* Rewrite based on new plugin boilerplate. = 2.0.3 = -* Fix warnings and notices +* Fix warnings and notices. = 2.0.2 = * Change text domain, update POT file. = 2.0.1 = -* Genesis 2.0.1 compatibility with term meta keys -* Use actual sidebar name, instead of hard coded names -* Fix incorrect textdomain +* Genesis 2.0.1 compatibility with term meta keys. +* Use actual sidebar name, instead of hard coded names. +* Fix incorrect textdomain. = 2.0.0 = -* Compatibility with Genesis 2.0 -* Standards +* Compatibility with Genesis 2.0.0. +* Standards. = 1.0.0 = -* Reorganize theme files +* Reorganize theme files. * Standards = 0.9.2.1 = -* Restore default tag/category support -* Default custom taxonomy support to on for public taxonomies -* Remove secondary selection when no 3 column layouts are enabled +* Restore default tag/category support. +* Default custom taxonomy support to on for public taxonomies. +* Remove secondary selection when no 3 column layouts are enabled. = 0.9.2 = -* Added support for custom taxonomies -* Added translation support -* bug fix to prevent invalid sidebar creation +* Added support for custom taxonomies. +* Added translation support. +* bug fix to prevent invalid sidebar creation. = 0.9.1 = -* Added support for custom post types +* Added support for custom post types. = 0.9 = -* Fixed "is not array" errors reported by users -* Added nonce verification for security purposes -* Added error and success messages -* Bump to pre-release 0.9 branch +* Fixed "is not array" errors reported by users. +* Added nonce verification for security purposes. +* Added error and success messages. +* Bump to pre-release 0.9 branch. = 0.1 = -* Initial Alpha Release +* Initial Alpha Release. From 49d5cfce79cd0a640a51a9364e43bda87767474f Mon Sep 17 00:00:00 2001 From: Nathan Rice Date: Wed, 1 Mar 2017 20:01:43 -0500 Subject: [PATCH 11/25] Include deprecated.php, update readme.txt. --- genesis-simple-sidebars.php | 2 +- readme.txt | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/genesis-simple-sidebars.php b/genesis-simple-sidebars.php index 622bc3d..5904afb 100644 --- a/genesis-simple-sidebars.php +++ b/genesis-simple-sidebars.php @@ -115,7 +115,7 @@ public function load_plugin_textdomain() { public function includes() { //require_once( $this->plugin_dir_path . 'includes/functions.php' ); - //require_once( $this->plugin_dir_path . 'includes/deprecated.php' ); + require_once( $this->plugin_dir_path . 'includes/deprecated.php' ); } diff --git a/readme.txt b/readme.txt index 606fa31..7ca7aa3 100644 --- a/readme.txt +++ b/readme.txt @@ -39,6 +39,11 @@ Not in the way you're probably thinking. The markup surrounding the widget area = 2.1.0 = * Rewrite based on new plugin boilerplate. +* Make ID field readonly, rather than disabled. +* Add header widget area support. +* Allow for empty ID (auto-generate ID from name). +* Allow for only alphanumeric characters in ID. +* Use WordPress native term meta functions. = 2.0.3 = * Fix warnings and notices. From dffb99c57b3de93b6136d0843bf70e49d269aa25 Mon Sep 17 00:00:00 2001 From: Nathan Rice Date: Fri, 3 Mar 2017 10:44:09 -0500 Subject: [PATCH 12/25] Remove debugging code. --- includes/class-genesis-simple-sidebars-entry.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/includes/class-genesis-simple-sidebars-entry.php b/includes/class-genesis-simple-sidebars-entry.php index 5c05e3c..f89c8b5 100644 --- a/includes/class-genesis-simple-sidebars-entry.php +++ b/includes/class-genesis-simple-sidebars-entry.php @@ -35,8 +35,6 @@ public function metabox_content() { require_once( Genesis_Simple_Sidebars()->plugin_dir_path . 'includes/views/entry-metabox-content.php' ); - print_r( get_post_meta( get_the_ID() ) ); - } /** From 6afb3213f7e983d0848c9691173ee72e91993e9f Mon Sep 17 00:00:00 2001 From: Nathan Rice Date: Fri, 3 Mar 2017 10:50:52 -0500 Subject: [PATCH 13/25] Account for numeric sidebars. --- includes/class-genesis-simple-sidebars-admin.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/includes/class-genesis-simple-sidebars-admin.php b/includes/class-genesis-simple-sidebars-admin.php index fb9c1f8..88517c9 100644 --- a/includes/class-genesis-simple-sidebars-admin.php +++ b/includes/class-genesis-simple-sidebars-admin.php @@ -231,6 +231,9 @@ protected function create_sidebar( $args = array() ) { // Strip all but alphanumeric, sanitize with dashes. $id = preg_replace( "/[^a-zA-Z0-9 -]+/", "", sanitize_title_with_dashes( $args['id'] ) ); + // Preface numeric IDs with 'sidebar-'. + $id = is_numeric( $id ) ? 'sidebar-' . $id : $id; + $db = (array) get_option( $this->settings_field ); $new = array( From e5c3b527f1444501cc0bcb62bb1262b15acfc761 Mon Sep 17 00:00:00 2001 From: Nathan Rice Date: Fri, 3 Mar 2017 13:09:34 -0500 Subject: [PATCH 14/25] Account for net result empty sidebar ID. --- includes/class-genesis-simple-sidebars-admin.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/includes/class-genesis-simple-sidebars-admin.php b/includes/class-genesis-simple-sidebars-admin.php index 88517c9..d2a572a 100644 --- a/includes/class-genesis-simple-sidebars-admin.php +++ b/includes/class-genesis-simple-sidebars-admin.php @@ -223,6 +223,8 @@ protected function create_sidebar( $args = array() ) { // nonce verification check_admin_referer( 'simple-sidebars-action_create-sidebar' ); + $db = (array) get_option( $this->settings_field ); + // Change empty or numeric IDs to the name, lowercased and separated by dashes. if ( empty( $args['id'] ) || is_numeric( $args['id'] ) ) { $args['id'] = $args['name']; @@ -232,9 +234,15 @@ protected function create_sidebar( $args = array() ) { $id = preg_replace( "/[^a-zA-Z0-9 -]+/", "", sanitize_title_with_dashes( $args['id'] ) ); // Preface numeric IDs with 'sidebar-'. - $id = is_numeric( $id ) ? 'sidebar-' . $id : $id; - - $db = (array) get_option( $this->settings_field ); + $id = is_numeric( $id ) ? 'gss-sidebar-' . $id : $id; + + // If empty after all the sanitizing ... + if ( ! $id || is_registered_sidebar( $id ) ) { + $n = count( $db ) + 1; + do { + $id = 'gss-sidebar-' . $n++; + } while ( is_registered_sidebar( $id ) ); + } $new = array( $id => array( From 1509276708ebc3a5d88202b2cde58e0090c171cf Mon Sep 17 00:00:00 2001 From: Nathan Rice Date: Mon, 6 Mar 2017 11:01:36 -0500 Subject: [PATCH 15/25] Change activation hook to admin notice. see #19. --- genesis-simple-sidebars.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/genesis-simple-sidebars.php b/genesis-simple-sidebars.php index 5904afb..baa4477 100644 --- a/genesis-simple-sidebars.php +++ b/genesis-simple-sidebars.php @@ -74,7 +74,7 @@ public function __construct() { */ public function init() { - register_activation_hook( __FILE__, array( $this, 'activation' ) ); + add_action( 'admin_notices', array( $this, 'requirements_notice' ) ); $this->load_plugin_textdomain(); $this->includes(); @@ -83,16 +83,16 @@ public function init() { } /** - * Plugin activation hook. Runs when plugin is activated. + * Show admin notice if minimum requirements aren't met. * * @since 2.1.0 */ - public function activation() { + public function requirements_notice() { if ( ! defined( 'PARENT_THEME_VERSION' ) || ! version_compare( PARENT_THEME_VERSION, $this->min_genesis_version, '>=' ) ) { - deactivate_plugins( plugin_basename( __FILE__ ) ); - wp_die( sprintf( __( 'Sorry, you cannot run Genesis Simple Sidebars without WordPress %s and Genesis %s, or greater.', 'genesis-simple-sidebars' ), $this->min_wp_version, 'http://my.studiopress.com/?download_id=91046d629e74d525b3f2978e404e7ffa', $this->min_genesis_version ) ); + $message = sprintf( __( 'Genesis Simple Sidebars requires WordPress %s and Genesis %s, or greater. Please upgrade or deactivate this plugin.', 'genesis-simple-sidebars' ), $this->min_wp_version, 'http://my.studiopress.com/?download_id=91046d629e74d525b3f2978e404e7ffa', $this->min_genesis_version ); + echo '

' . $message . '

'; } From 7d10d3c40807211a30fa5c4af133d2c880ac0e8a Mon Sep 17 00:00:00 2001 From: Nathan Rice Date: Mon, 6 Mar 2017 11:36:53 -0500 Subject: [PATCH 16/25] Fix translations issues. see #20. --- genesis-simple-sidebars.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/genesis-simple-sidebars.php b/genesis-simple-sidebars.php index baa4477..724a618 100644 --- a/genesis-simple-sidebars.php +++ b/genesis-simple-sidebars.php @@ -76,7 +76,8 @@ public function init() { add_action( 'admin_notices', array( $this, 'requirements_notice' ) ); - $this->load_plugin_textdomain(); + add_action( 'init', array( $this, 'load_plugin_textdomain' ) ); + $this->includes(); $this->instantiate(); @@ -104,7 +105,7 @@ public function requirements_notice() { * @since 2.1.0 */ public function load_plugin_textdomain() { - load_plugin_textdomain( $this->plugin_textdomain, false, $this->plugin_dir_path . 'languages/' ); + load_plugin_textdomain( $this->plugin_textdomain, false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); } /** From e5afd4f9ef8100bdeb297b88e8b3f3304e8114ec Mon Sep 17 00:00:00 2001 From: Nathan Rice Date: Mon, 6 Mar 2017 12:29:22 -0500 Subject: [PATCH 17/25] Better wording for admin notice. --- genesis-simple-sidebars.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/genesis-simple-sidebars.php b/genesis-simple-sidebars.php index 724a618..c8856cd 100644 --- a/genesis-simple-sidebars.php +++ b/genesis-simple-sidebars.php @@ -92,7 +92,9 @@ public function requirements_notice() { if ( ! defined( 'PARENT_THEME_VERSION' ) || ! version_compare( PARENT_THEME_VERSION, $this->min_genesis_version, '>=' ) ) { - $message = sprintf( __( 'Genesis Simple Sidebars requires WordPress %s and Genesis %s, or greater. Please upgrade or deactivate this plugin.', 'genesis-simple-sidebars' ), $this->min_wp_version, 'http://my.studiopress.com/?download_id=91046d629e74d525b3f2978e404e7ffa', $this->min_genesis_version ); + $action = defined( 'PARENT_THEME_VERSION' ) ? __( 'upgrade to', 'genesis-simple-sidebars' ) : __( 'install and activate', 'genesis-simple-sidebars' ); + + $message = sprintf( __( 'Genesis Simple Hooks requires WordPress %s and Genesis %s, or greater. Please %s the latest version of Genesis to use this plugin.', 'genesis-simple-sidebars' ), $this->min_wp_version, 'http://my.studiopress.com/?download_id=91046d629e74d525b3f2978e404e7ffa', $this->min_genesis_version, $action ); echo '

' . $message . '

'; } From 491a2b74fc69e585346b1cc5b00acc587952bb83 Mon Sep 17 00:00:00 2001 From: Nathan Rice Date: Mon, 6 Mar 2017 12:32:21 -0500 Subject: [PATCH 18/25] Better wording for admin notice. --- genesis-simple-sidebars.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/genesis-simple-sidebars.php b/genesis-simple-sidebars.php index c8856cd..a772bd8 100644 --- a/genesis-simple-sidebars.php +++ b/genesis-simple-sidebars.php @@ -94,7 +94,7 @@ public function requirements_notice() { $action = defined( 'PARENT_THEME_VERSION' ) ? __( 'upgrade to', 'genesis-simple-sidebars' ) : __( 'install and activate', 'genesis-simple-sidebars' ); - $message = sprintf( __( 'Genesis Simple Hooks requires WordPress %s and Genesis %s, or greater. Please %s the latest version of Genesis to use this plugin.', 'genesis-simple-sidebars' ), $this->min_wp_version, 'http://my.studiopress.com/?download_id=91046d629e74d525b3f2978e404e7ffa', $this->min_genesis_version, $action ); + $message = sprintf( __( 'Genesis Simple Hooks requires WordPress %s and Genesis %s, or greater. Please %s the latest version of Genesis to use this plugin.', 'genesis-simple-sidebars' ), $this->min_wp_version, 'http://my.studiopress.com/?download_id=91046d629e74d525b3f2978e404e7ffa', $this->min_genesis_version, $action ); echo '

' . $message . '

'; } From 991b3541757772f2d172935b31cf8183a2248f22 Mon Sep 17 00:00:00 2001 From: Nathan Rice Date: Mon, 6 Mar 2017 13:32:33 -0500 Subject: [PATCH 19/25] Fix typo. --- genesis-simple-sidebars.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/genesis-simple-sidebars.php b/genesis-simple-sidebars.php index a772bd8..2ef71d4 100644 --- a/genesis-simple-sidebars.php +++ b/genesis-simple-sidebars.php @@ -94,7 +94,7 @@ public function requirements_notice() { $action = defined( 'PARENT_THEME_VERSION' ) ? __( 'upgrade to', 'genesis-simple-sidebars' ) : __( 'install and activate', 'genesis-simple-sidebars' ); - $message = sprintf( __( 'Genesis Simple Hooks requires WordPress %s and Genesis %s, or greater. Please %s the latest version of Genesis to use this plugin.', 'genesis-simple-sidebars' ), $this->min_wp_version, 'http://my.studiopress.com/?download_id=91046d629e74d525b3f2978e404e7ffa', $this->min_genesis_version, $action ); + $message = sprintf( __( 'Genesis Simple Sidebars requires WordPress %s and Genesis %s, or greater. Please %s the latest version of Genesis to use this plugin.', 'genesis-simple-sidebars' ), $this->min_wp_version, 'http://my.studiopress.com/?download_id=91046d629e74d525b3f2978e404e7ffa', $this->min_genesis_version, $action ); echo '

' . $message . '

'; } From f2280a3faecd371604049cd519f9585439913e8e Mon Sep 17 00:00:00 2001 From: Nathan Rice Date: Mon, 6 Mar 2017 15:41:58 -0500 Subject: [PATCH 20/25] Change minimum requirement message. --- genesis-simple-sidebars.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/genesis-simple-sidebars.php b/genesis-simple-sidebars.php index 2ef71d4..4fb16ec 100644 --- a/genesis-simple-sidebars.php +++ b/genesis-simple-sidebars.php @@ -86,7 +86,7 @@ public function init() { /** * Show admin notice if minimum requirements aren't met. * - * @since 2.1.0 + * @since 2.2.0 */ public function requirements_notice() { @@ -94,7 +94,7 @@ public function requirements_notice() { $action = defined( 'PARENT_THEME_VERSION' ) ? __( 'upgrade to', 'genesis-simple-sidebars' ) : __( 'install and activate', 'genesis-simple-sidebars' ); - $message = sprintf( __( 'Genesis Simple Sidebars requires WordPress %s and Genesis %s, or greater. Please %s the latest version of Genesis to use this plugin.', 'genesis-simple-sidebars' ), $this->min_wp_version, 'http://my.studiopress.com/?download_id=91046d629e74d525b3f2978e404e7ffa', $this->min_genesis_version, $action ); + $message = sprintf( __( 'Genesis Simple Sidebars requires WordPress %s and Genesis %s, or greater. Please %s the latest version of Genesis to use this plugin.', 'genesis-simple-sidebars' ), $this->min_wp_version, $this->min_genesis_version, $action, 'http://my.studiopress.com/?download_id=91046d629e74d525b3f2978e404e7ffa' ); echo '

' . $message . '

'; } From a3dc69479ab18fca2ce0020f6844e11bff77eb0a Mon Sep 17 00:00:00 2001 From: Nathan Rice Date: Tue, 7 Mar 2017 15:18:28 -0500 Subject: [PATCH 21/25] Load textdomain first thing. --- genesis-simple-sidebars.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/genesis-simple-sidebars.php b/genesis-simple-sidebars.php index 4fb16ec..9f06a16 100644 --- a/genesis-simple-sidebars.php +++ b/genesis-simple-sidebars.php @@ -74,9 +74,9 @@ public function __construct() { */ public function init() { - add_action( 'admin_notices', array( $this, 'requirements_notice' ) ); + $this->load_plugin_textdomain(); - add_action( 'init', array( $this, 'load_plugin_textdomain' ) ); + add_action( 'admin_notices', array( $this, 'requirements_notice' ) ); $this->includes(); $this->instantiate(); From 775ece1a8b62254950ee0b8a787deddd15a26b6f Mon Sep 17 00:00:00 2001 From: Nathan Rice Date: Tue, 7 Mar 2017 15:21:21 -0500 Subject: [PATCH 22/25] Forgot to change version after copy/paste. --- genesis-simple-sidebars.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/genesis-simple-sidebars.php b/genesis-simple-sidebars.php index 9f06a16..8e3f574 100644 --- a/genesis-simple-sidebars.php +++ b/genesis-simple-sidebars.php @@ -86,7 +86,7 @@ public function init() { /** * Show admin notice if minimum requirements aren't met. * - * @since 2.2.0 + * @since 2.1.0 */ public function requirements_notice() { From 7b439c95a717f3bf8b9196f323f10b790e076a65 Mon Sep 17 00:00:00 2001 From: Nathan Rice Date: Wed, 8 Mar 2017 22:42:02 -0500 Subject: [PATCH 23/25] Use more reliable method for switching sidebars. should eliminate issues moving sidebars in #22. --- .../class-genesis-simple-sidebars-core.php | 106 +++++++----------- 1 file changed, 42 insertions(+), 64 deletions(-) diff --git a/includes/class-genesis-simple-sidebars-core.php b/includes/class-genesis-simple-sidebars-core.php index 1fb525c..5fda384 100644 --- a/includes/class-genesis-simple-sidebars-core.php +++ b/includes/class-genesis-simple-sidebars-core.php @@ -23,7 +23,7 @@ class Genesis_Simple_Sidebars_Core { public function init() { add_action( 'widgets_init', array( $this, 'register_sidebars' ) ); - add_action( 'get_header', array( $this, 'swap_sidebars' ) ); + add_filter( 'sidebars_widgets', array( $this, 'sidebars_widgets_filter' ) ); } @@ -34,7 +34,7 @@ public function init() { */ public function register_sidebars() { - $sidebars = Genesis_Simple_Sidebars()->core->get_sidebars(); + $sidebars = $this->get_sidebars(); if ( ! $sidebars ) { return; @@ -59,98 +59,76 @@ public function register_sidebars() { } /** - * Remove default sidebars and inject custom sidebars. + * Filter the widgets in each widget area. * * @since 2.1.0 */ - public function swap_sidebars() { - - // Header - if ( is_registered_sidebar( 'header-right' ) ) { - global $wp_registered_sidebars; - $wp_registered_sidebars['ss-header-right-temp'] = $wp_registered_sidebars['header-right']; - unset( $wp_registered_sidebars['header-right'] ); - add_action( 'genesis_header_right', array( $this, 'do_header_right' ) ); - } - - // Sidebars - remove_action( 'genesis_sidebar', 'genesis_do_sidebar' ); - remove_action( 'genesis_sidebar_alt', 'genesis_do_sidebar_alt' ); - add_action( 'genesis_sidebar', array( $this, 'do_primary_sidebar' ) ); - add_action( 'genesis_sidebar_alt', array( $this, 'do_secondary_sidebar' ) ); - - } + public function sidebars_widgets_filter( $widgets ) { - /** - * Output custom header widget area, if one is set. Otherwise output default. - * - * @since 2.1.0 - */ - public function do_header_right() { + $sidebars = array( + 'sidebar' => '_ss_sidebar', + 'sidebar-alt' => '_ss_sidebar_alt', + 'header-right' => '_ss_header', + ); - global $wp_registered_sidebars; + /** + * Swappable widget areas. + * + * An array of original widget area => GSS key for new sidebar. Can be used to add or remove widget areas from being + * swappable in the Genesis Simple Sidebars admin. + * + * @since 2.1.0 + * + * @param array $sidebars Array of widget areas that can be swapped, with the keys used to find the ID of the new widget area to swap in. + */ + $sidebars = apply_filters( 'genesis_simple_sidebars_widget_areas', $sidebars ); - if ( ! $this->do_sidebar( '_ss_header' ) ) { - $wp_registered_sidebars['header-right'] = $wp_registered_sidebars['ss-header-right-temp']; - } + $widgets = $this->swap_widgets( $widgets, $sidebars ); - unset( $wp_registered_sidebars['ss-header-right-temp'] ); + return $widgets; } /** - * Output custom primary sidebar, if one is set. Otherwise output default. + * Take the $widgets array and swap the contents of each widget area with a custom widget area, if specified. * * @since 2.1.0 */ - public function do_primary_sidebar() { + public function swap_widgets( $widgets, $sidebars ) { - if ( ! $this->do_sidebar( '_ss_sidebar' ) ) { - genesis_do_sidebar(); + if ( is_admin() ) { + return $widgets; } - } - - /** - * Output custom secondary sidebar, if one is set. Otherwise output default. - * - * @since 2.1.0 - */ - public function do_secondary_sidebar() { + foreach ( (array) $sidebars as $old_sidebar => $new_sidebar_key ) { - if ( ! $this->do_sidebar( '_ss_sidebar_alt' ) ) { - genesis_do_sidebar_alt(); - } + if ( ! is_registered_sidebar( $old_sidebar ) ) { + continue; + } - } + if ( is_singular() ) { - /** - * Show widgets in a particular sidebar. - * - * @param string $key sidebar id you wish to output. - * - * @since 2.1.0 - */ - public function do_sidebar( $key ) { + $new_sidebar = genesis_get_custom_field( $new_sidebar_key ); - if ( is_singular() && $key = genesis_get_custom_field( $key ) ) { + if ( $new_sidebar && ! empty( $widgets[ $new_sidebar ] ) ) { + $widgets[ $old_sidebar ] = $widgets[ $new_sidebar ]; + } - if ( dynamic_sidebar( $key ) ) { - return true; } - } + if ( is_tax() || is_category() || is_tag() ) { - if ( is_tax() || is_category() || is_tag() ) { + $new_sidebar = get_term_meta( get_queried_object()->term_id, $new_sidebar_key, true ); + + if ( $new_sidebar && ! empty( $widgets[ $new_sidebar ] ) ) { + $widgets[ $old_sidebar ] = $widgets[ $new_sidebar ]; + } - if ( $key = get_term_meta( get_queried_object()->term_id, $key, true ) ) { - dynamic_sidebar( $key ); - return true; } } - return false; + return $widgets; } From 6f8b1a2069c242d1c8b0e2702938bd8f66831e5d Mon Sep 17 00:00:00 2001 From: Nathan Rice Date: Fri, 10 Mar 2017 14:27:11 -0500 Subject: [PATCH 24/25] Modify deprecated functions for backward compatibility. see #22. --- genesis-simple-sidebars.php | 2 +- .../class-genesis-simple-sidebars-core.php | 68 +++++++++---------- includes/deprecated.php | 30 +++----- includes/functions.php | 19 ++++++ plugin.php | 4 +- 5 files changed, 66 insertions(+), 57 deletions(-) create mode 100644 includes/functions.php diff --git a/genesis-simple-sidebars.php b/genesis-simple-sidebars.php index 8e3f574..962ba45 100644 --- a/genesis-simple-sidebars.php +++ b/genesis-simple-sidebars.php @@ -117,7 +117,7 @@ public function load_plugin_textdomain() { */ public function includes() { - //require_once( $this->plugin_dir_path . 'includes/functions.php' ); + require_once( $this->plugin_dir_path . 'includes/functions.php' ); require_once( $this->plugin_dir_path . 'includes/deprecated.php' ); } diff --git a/includes/class-genesis-simple-sidebars-core.php b/includes/class-genesis-simple-sidebars-core.php index 5fda384..72766b9 100644 --- a/includes/class-genesis-simple-sidebars-core.php +++ b/includes/class-genesis-simple-sidebars-core.php @@ -22,11 +22,21 @@ class Genesis_Simple_Sidebars_Core { */ public function init() { + add_action( 'after_setup_theme', array( $this, 'backward_compatibility' ) ); add_action( 'widgets_init', array( $this, 'register_sidebars' ) ); add_filter( 'sidebars_widgets', array( $this, 'sidebars_widgets_filter' ) ); } + public function backward_compatibility() { + + remove_action( 'genesis_sidebar', 'genesis_do_sidebar' ); + add_action( 'genesis_sidebar', 'ss_do_sidebar' ); + remove_action( 'genesis_sidebar_alt', 'genesis_do_sidebar_alt' ); + add_action( 'genesis_sidebar_alt', 'ss_do_sidebar_alt' ); + + } + /** * Take created sidebars and register them with WordPress. * @@ -65,23 +75,27 @@ public function register_sidebars() { */ public function sidebars_widgets_filter( $widgets ) { - $sidebars = array( - 'sidebar' => '_ss_sidebar', - 'sidebar-alt' => '_ss_sidebar_alt', - 'header-right' => '_ss_header', - ); + $sidebars = array(); + + if ( is_singular() ) { + + $sidebars = array( + 'sidebar' => genesis_get_custom_field( '_ss_sidebar' ), + 'sidebar-alt' => genesis_get_custom_field( '_ss_sidebar_alt' ), + 'header-right' => genesis_get_custom_field( '_ss_header' ), + ); + + } + + if ( is_tax() || is_category() || is_tag() ) { - /** - * Swappable widget areas. - * - * An array of original widget area => GSS key for new sidebar. Can be used to add or remove widget areas from being - * swappable in the Genesis Simple Sidebars admin. - * - * @since 2.1.0 - * - * @param array $sidebars Array of widget areas that can be swapped, with the keys used to find the ID of the new widget area to swap in. - */ - $sidebars = apply_filters( 'genesis_simple_sidebars_widget_areas', $sidebars ); + $sidebars = array( + 'sidebar' => get_term_meta( get_queried_object()->term_id, '_ss_sidebar', true ), + 'sidebar-alt' => get_term_meta( get_queried_object()->term_id, '_ss_sidebar_alt', true ), + 'header-right' => get_term_meta( get_queried_object()->term_id, '_ss_header', true ), + ); + + } $widgets = $this->swap_widgets( $widgets, $sidebars ); @@ -100,30 +114,14 @@ public function swap_widgets( $widgets, $sidebars ) { return $widgets; } - foreach ( (array) $sidebars as $old_sidebar => $new_sidebar_key ) { + foreach ( (array) $sidebars as $old_sidebar => $new_sidebar ) { if ( ! is_registered_sidebar( $old_sidebar ) ) { continue; } - if ( is_singular() ) { - - $new_sidebar = genesis_get_custom_field( $new_sidebar_key ); - - if ( $new_sidebar && ! empty( $widgets[ $new_sidebar ] ) ) { - $widgets[ $old_sidebar ] = $widgets[ $new_sidebar ]; - } - - } - - if ( is_tax() || is_category() || is_tag() ) { - - $new_sidebar = get_term_meta( get_queried_object()->term_id, $new_sidebar_key, true ); - - if ( $new_sidebar && ! empty( $widgets[ $new_sidebar ] ) ) { - $widgets[ $old_sidebar ] = $widgets[ $new_sidebar ]; - } - + if ( $new_sidebar && ! empty( $widgets[ $new_sidebar ] ) ) { + $widgets[ $old_sidebar ] = $widgets[ $new_sidebar ]; } } diff --git a/includes/deprecated.php b/includes/deprecated.php index ab4cbf4..805e8c8 100644 --- a/includes/deprecated.php +++ b/includes/deprecated.php @@ -56,28 +56,20 @@ function ss_sidebars_init() { * @since 0.9.0 * @deprecated 2.1.0 */ -function ss_do_sidebar() { - _deprecated_function( __FUNCTION__, '2.1.0' ); -} +function ss_do_one_sidebar( $sidebar_key = '' ) { -/** - * Deprecated. - * - * @since 0.9.0 - * @deprecated 2.1.0 - */ -function ss_do_sidebar_alt() { _deprecated_function( __FUNCTION__, '2.1.0' ); -} -/** - * Deprecated. - * - * @since 0.9.0 - * @deprecated 2.1.0 - */ -function ss_do_one_sidebar() { - _deprecated_function( __FUNCTION__, '2.1.0' ); + if ( '_ss_sidebar' == $sidebar_key ) { + genesis_do_sidebar(); + return true; + } + + if ( '_ss_sidebar_alt' == $sidebar_key ) { + genesis_do_sidebar_alt(); + return true; + } + } /** diff --git a/includes/functions.php b/includes/functions.php new file mode 100644 index 0000000..8112009 --- /dev/null +++ b/includes/functions.php @@ -0,0 +1,19 @@ + Date: Fri, 10 Mar 2017 17:18:33 -0500 Subject: [PATCH 25/25] Indicate replacement for ss_do_one_sidebar(). see #22. --- includes/deprecated.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/deprecated.php b/includes/deprecated.php index 805e8c8..ae3aedc 100644 --- a/includes/deprecated.php +++ b/includes/deprecated.php @@ -58,7 +58,7 @@ function ss_sidebars_init() { */ function ss_do_one_sidebar( $sidebar_key = '' ) { - _deprecated_function( __FUNCTION__, '2.1.0' ); + _deprecated_function( __FUNCTION__, '2.1.0', __( 'dynamic_sidebar() with sidebars_widget filter', 'genesis-simple-sidebars' ) ); if ( '_ss_sidebar' == $sidebar_key ) { genesis_do_sidebar();