mirror of
https://github.com/10h30/genesis-simple-sidebars.git
synced 2026-07-11 18:46:05 +09:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 357bc65a70 | |||
| 4e5bfa7caf | |||
| f96e67d4df | |||
| fde95b0dd7 | |||
| 76e5f73e28 | |||
| 5a1b4bec6e | |||
| 2f6eb81ed6 | |||
| 13505bdc2b |
@@ -74,28 +74,25 @@ class Genesis_Simple_Sidebars {
|
||||
*/
|
||||
public function init() {
|
||||
|
||||
register_activation_hook( __FILE__, array( $this, 'activation' ) );
|
||||
|
||||
$this->load_plugin_textdomain();
|
||||
|
||||
add_action( 'admin_notices', array( $this, 'requirements_notice' ) );
|
||||
|
||||
$this->includes();
|
||||
$this->instantiate();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Show admin notice if minimum requirements aren't met.
|
||||
* Plugin activation hook. Runs when plugin is activated.
|
||||
*
|
||||
* @since 2.1.0
|
||||
*/
|
||||
public function requirements_notice() {
|
||||
public function activation() {
|
||||
|
||||
if ( ! defined( 'PARENT_THEME_VERSION' ) || ! version_compare( PARENT_THEME_VERSION, $this->min_genesis_version, '>=' ) ) {
|
||||
|
||||
$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 <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>';
|
||||
deactivate_plugins( plugin_basename( __FILE__ ) );
|
||||
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 ) );
|
||||
|
||||
}
|
||||
|
||||
@@ -107,7 +104,7 @@ class Genesis_Simple_Sidebars {
|
||||
* @since 2.1.0
|
||||
*/
|
||||
public function load_plugin_textdomain() {
|
||||
load_plugin_textdomain( $this->plugin_textdomain, false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
|
||||
load_plugin_textdomain( $this->plugin_textdomain, false, $this->plugin_dir_path . 'languages/' );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -117,8 +114,8 @@ class Genesis_Simple_Sidebars {
|
||||
*/
|
||||
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/functions.php' );
|
||||
//require_once( $this->plugin_dir_path . 'includes/deprecated.php' );
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -223,8 +223,6 @@ class Genesis_Simple_Sidebars_Admin extends Genesis_Admin_Basic {
|
||||
// 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'];
|
||||
@@ -233,16 +231,7 @@ class Genesis_Simple_Sidebars_Admin extends Genesis_Admin_Basic {
|
||||
// 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 ) ? '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 ) );
|
||||
}
|
||||
$db = (array) get_option( $this->settings_field );
|
||||
|
||||
$new = array(
|
||||
$id => array(
|
||||
|
||||
@@ -22,18 +22,8 @@ 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' );
|
||||
add_action( 'get_header', array( $this, 'swap_sidebars' ) );
|
||||
|
||||
}
|
||||
|
||||
@@ -44,7 +34,7 @@ class Genesis_Simple_Sidebars_Core {
|
||||
*/
|
||||
public function register_sidebars() {
|
||||
|
||||
$sidebars = $this->get_sidebars();
|
||||
$sidebars = Genesis_Simple_Sidebars()->core->get_sidebars();
|
||||
|
||||
if ( ! $sidebars ) {
|
||||
return;
|
||||
@@ -69,64 +59,98 @@ class Genesis_Simple_Sidebars_Core {
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the widgets in each widget area.
|
||||
* Remove default sidebars and inject custom sidebars.
|
||||
*
|
||||
* @since 2.1.0
|
||||
*/
|
||||
public function sidebars_widgets_filter( $widgets ) {
|
||||
public function swap_sidebars() {
|
||||
|
||||
$sidebars = array();
|
||||
// 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' ) );
|
||||
}
|
||||
|
||||
if ( is_singular() ) {
|
||||
// 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' ) );
|
||||
|
||||
$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' ),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() ) {
|
||||
|
||||
$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 );
|
||||
|
||||
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 ];
|
||||
if ( $key = get_term_meta( get_queried_object()->term_id, $key, true ) ) {
|
||||
dynamic_sidebar( $key );
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $widgets;
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,8 @@ class Genesis_Simple_Sidebars_Entry {
|
||||
|
||||
require_once( Genesis_Simple_Sidebars()->plugin_dir_path . 'includes/views/entry-metabox-content.php' );
|
||||
|
||||
print_r( get_post_meta( get_the_ID() ) );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+20
-12
@@ -56,20 +56,28 @@ function ss_sidebars_init() {
|
||||
* @since 0.9.0
|
||||
* @deprecated 2.1.0
|
||||
*/
|
||||
function ss_do_one_sidebar( $sidebar_key = '' ) {
|
||||
function ss_do_sidebar() {
|
||||
_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();
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( '_ss_sidebar_alt' == $sidebar_key ) {
|
||||
genesis_do_sidebar_alt();
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* 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' );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
<?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.
|
||||
|
||||
Author: StudioPress
|
||||
Author URI: http://www.studiopress.com/
|
||||
Author: Nathan Rice
|
||||
Author URI: http://www.nathanrice.net/
|
||||
|
||||
Version: 2.1.0
|
||||
|
||||
|
||||
@@ -39,11 +39,6 @@ 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.
|
||||
|
||||
Reference in New Issue
Block a user