mirror of
https://github.com/10h30/genesis-simple-sidebars.git
synced 2026-07-12 02:56:12 +09:00
Compare commits
26 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f83f625c84 | |||
| 42315b2944 | |||
| 6f8b1a2069 | |||
| 7b439c95a7 | |||
| 775ece1a8b | |||
| a3dc69479a | |||
| f2280a3fae | |||
| 991b354175 | |||
| 491a2b74fc | |||
| e5afd4f9ef | |||
| 7d10d3c408 | |||
| 1509276708 | |||
| e5c3b527f1 | |||
| 6afb3213f7 | |||
| dffb99c57b | |||
| 49d5cfce79 | |||
| febb5ede11 | |||
| c7fdc4387e | |||
| eff4992b6c | |||
| 97fac5c57b | |||
| 36553a6557 | |||
| 4d09f1c1ac | |||
| 93a304aa06 | |||
| 4106eb6c68 | |||
| be896fd123 | |||
| e63975e620 |
@@ -74,25 +74,28 @@ class Genesis_Simple_Sidebars {
|
|||||||
*/
|
*/
|
||||||
public function init() {
|
public function init() {
|
||||||
|
|
||||||
register_activation_hook( __FILE__, array( $this, 'activation' ) );
|
|
||||||
|
|
||||||
$this->load_plugin_textdomain();
|
$this->load_plugin_textdomain();
|
||||||
|
|
||||||
|
add_action( 'admin_notices', array( $this, 'requirements_notice' ) );
|
||||||
|
|
||||||
$this->includes();
|
$this->includes();
|
||||||
$this->instantiate();
|
$this->instantiate();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plugin activation hook. Runs when plugin is activated.
|
* Show admin notice if minimum requirements aren't met.
|
||||||
*
|
*
|
||||||
* @since 2.1.0
|
* @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, '>=' ) ) {
|
if ( ! defined( 'PARENT_THEME_VERSION' ) || ! version_compare( PARENT_THEME_VERSION, $this->min_genesis_version, '>=' ) ) {
|
||||||
|
|
||||||
deactivate_plugins( plugin_basename( __FILE__ ) );
|
$action = defined( 'PARENT_THEME_VERSION' ) ? __( 'upgrade to', 'genesis-simple-sidebars' ) : __( 'install and activate', 'genesis-simple-sidebars' );
|
||||||
wp_die( sprintf( __( 'Sorry, you cannot run Genesis Simple Sidebars without WordPress %s and <a href="%s">Genesis %s</a>, 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 %s the latest version of <a href="%s" target="_blank">Genesis</a> to use this plugin.', 'genesis-simple-sidebars' ), $this->min_wp_version, $this->min_genesis_version, $action, 'http://my.studiopress.com/?download_id=91046d629e74d525b3f2978e404e7ffa' );
|
||||||
|
echo '<div class="notice notice-warning"><p>' . $message . '</p></div>';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,7 +107,7 @@ class Genesis_Simple_Sidebars {
|
|||||||
* @since 2.1.0
|
* @since 2.1.0
|
||||||
*/
|
*/
|
||||||
public function load_plugin_textdomain() {
|
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/' );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -114,8 +117,8 @@ class Genesis_Simple_Sidebars {
|
|||||||
*/
|
*/
|
||||||
public function includes() {
|
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' );
|
require_once( $this->plugin_dir_path . 'includes/deprecated.php' );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -223,6 +223,8 @@ class Genesis_Simple_Sidebars_Admin extends Genesis_Admin_Basic {
|
|||||||
// nonce verification
|
// nonce verification
|
||||||
check_admin_referer( 'simple-sidebars-action_create-sidebar' );
|
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.
|
// Change empty or numeric IDs to the name, lowercased and separated by dashes.
|
||||||
if ( empty( $args['id'] ) || is_numeric( $args['id'] ) ) {
|
if ( empty( $args['id'] ) || is_numeric( $args['id'] ) ) {
|
||||||
$args['id'] = $args['name'];
|
$args['id'] = $args['name'];
|
||||||
@@ -231,7 +233,16 @@ class Genesis_Simple_Sidebars_Admin extends Genesis_Admin_Basic {
|
|||||||
// Strip all but alphanumeric, sanitize with dashes.
|
// Strip all but alphanumeric, sanitize with dashes.
|
||||||
$id = preg_replace( "/[^a-zA-Z0-9 -]+/", "", sanitize_title_with_dashes( $args['id'] ) );
|
$id = preg_replace( "/[^a-zA-Z0-9 -]+/", "", sanitize_title_with_dashes( $args['id'] ) );
|
||||||
|
|
||||||
$db = (array) get_option( $this->settings_field );
|
// Preface numeric IDs with 'sidebar-'.
|
||||||
|
$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(
|
$new = array(
|
||||||
$id => array(
|
$id => array(
|
||||||
|
|||||||
@@ -22,8 +22,18 @@ class Genesis_Simple_Sidebars_Core {
|
|||||||
*/
|
*/
|
||||||
public function init() {
|
public function init() {
|
||||||
|
|
||||||
|
add_action( 'after_setup_theme', array( $this, 'backward_compatibility' ) );
|
||||||
add_action( 'widgets_init', array( $this, 'register_sidebars' ) );
|
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' ) );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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' );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,7 +44,7 @@ class Genesis_Simple_Sidebars_Core {
|
|||||||
*/
|
*/
|
||||||
public function register_sidebars() {
|
public function register_sidebars() {
|
||||||
|
|
||||||
$sidebars = Genesis_Simple_Sidebars()->core->get_sidebars();
|
$sidebars = $this->get_sidebars();
|
||||||
|
|
||||||
if ( ! $sidebars ) {
|
if ( ! $sidebars ) {
|
||||||
return;
|
return;
|
||||||
@@ -59,98 +69,64 @@ class Genesis_Simple_Sidebars_Core {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove default sidebars and inject custom sidebars.
|
* Filter the widgets in each widget area.
|
||||||
*
|
*
|
||||||
* @since 2.1.0
|
* @since 2.1.0
|
||||||
*/
|
*/
|
||||||
public function swap_sidebars() {
|
public function sidebars_widgets_filter( $widgets ) {
|
||||||
|
|
||||||
// Header
|
$sidebars = array();
|
||||||
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
|
if ( is_singular() ) {
|
||||||
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' ) );
|
|
||||||
|
|
||||||
}
|
$sidebars = array(
|
||||||
|
'sidebar' => genesis_get_custom_field( '_ss_sidebar' ),
|
||||||
/**
|
'sidebar-alt' => genesis_get_custom_field( '_ss_sidebar_alt' ),
|
||||||
* Output custom header widget area, if one is set. Otherwise output default.
|
'header-right' => genesis_get_custom_field( '_ss_header' ),
|
||||||
*
|
);
|
||||||
* @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 ( is_tax() || is_category() || is_tag() ) {
|
||||||
|
|
||||||
if ( $key = get_term_meta( get_queried_object()->term_id, $key, true ) ) {
|
$sidebars = array(
|
||||||
dynamic_sidebar( $key );
|
'sidebar' => get_term_meta( get_queried_object()->term_id, '_ss_sidebar', true ),
|
||||||
return 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 );
|
||||||
|
|
||||||
|
return $widgets;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 swap_widgets( $widgets, $sidebars ) {
|
||||||
|
|
||||||
|
if ( is_admin() ) {
|
||||||
|
return $widgets;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ( (array) $sidebars as $old_sidebar => $new_sidebar ) {
|
||||||
|
|
||||||
|
if ( ! is_registered_sidebar( $old_sidebar ) ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $new_sidebar && ! empty( $widgets[ $new_sidebar ] ) ) {
|
||||||
|
$widgets[ $old_sidebar ] = $widgets[ $new_sidebar ];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return $widgets;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,8 +35,6 @@ class Genesis_Simple_Sidebars_Entry {
|
|||||||
|
|
||||||
require_once( Genesis_Simple_Sidebars()->plugin_dir_path . 'includes/views/entry-metabox-content.php' );
|
require_once( Genesis_Simple_Sidebars()->plugin_dir_path . 'includes/views/entry-metabox-content.php' );
|
||||||
|
|
||||||
print_r( get_post_meta( get_the_ID() ) );
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+12
-20
@@ -56,28 +56,20 @@ function ss_sidebars_init() {
|
|||||||
* @since 0.9.0
|
* @since 0.9.0
|
||||||
* @deprecated 2.1.0
|
* @deprecated 2.1.0
|
||||||
*/
|
*/
|
||||||
function ss_do_sidebar() {
|
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' ) );
|
||||||
* Deprecated.
|
|
||||||
*
|
if ( '_ss_sidebar' == $sidebar_key ) {
|
||||||
* @since 0.9.0
|
genesis_do_sidebar();
|
||||||
* @deprecated 2.1.0
|
return true;
|
||||||
*/
|
}
|
||||||
function ss_do_sidebar_alt() {
|
|
||||||
_deprecated_function( __FUNCTION__, '2.1.0' );
|
if ( '_ss_sidebar_alt' == $sidebar_key ) {
|
||||||
}
|
genesis_do_sidebar_alt();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Deprecated.
|
|
||||||
*
|
|
||||||
* @since 0.9.0
|
|
||||||
* @deprecated 2.1.0
|
|
||||||
*/
|
|
||||||
function ss_do_one_sidebar() {
|
|
||||||
_deprecated_function( __FUNCTION__, '2.1.0' );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dummy function for backward compatibility. Outputs the primary sidebar.
|
||||||
|
*
|
||||||
|
* @since 0.9.0
|
||||||
|
*/
|
||||||
|
function ss_do_sidebar() {
|
||||||
|
genesis_do_sidebar();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dummy function for backward compatibility. Outputs the secondary sidebar.
|
||||||
|
*
|
||||||
|
* @since 0.9.0
|
||||||
|
*/
|
||||||
|
function ss_do_sidebar_alt() {
|
||||||
|
genesis_do_sidebar_alt();
|
||||||
|
}
|
||||||
+2
-2
@@ -5,8 +5,8 @@ Plugin URI: http://www.studiopress.com/plugins/simple-sidebars
|
|||||||
|
|
||||||
Description: Genesis Simple Sidebars allows you to easily create and use new sidebar widget areas.
|
Description: Genesis Simple Sidebars allows you to easily create and use new sidebar widget areas.
|
||||||
|
|
||||||
Author: Nathan Rice
|
Author: StudioPress
|
||||||
Author URI: http://www.nathanrice.net/
|
Author URI: http://www.studiopress.com/
|
||||||
|
|
||||||
Version: 2.1.0
|
Version: 2.1.0
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,11 @@ Not in the way you're probably thinking. The markup surrounding the widget area
|
|||||||
|
|
||||||
= 2.1.0 =
|
= 2.1.0 =
|
||||||
* Rewrite based on new plugin boilerplate.
|
* 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 =
|
= 2.0.3 =
|
||||||
* Fix warnings and notices.
|
* Fix warnings and notices.
|
||||||
|
|||||||
Reference in New Issue
Block a user