Files
genesis-simple-sidebars/plugin.php
T

162 lines
4.7 KiB
PHP
Raw Normal View History

2013-08-09 13:05:55 -04:00
<?php
/*
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.
2013-08-09 13:09:21 -04:00
Version: 0.9.2.1
2013-08-09 13:05:55 -04:00
Author: Nathan Rice
Author URI: http://www.nathanrice.net/
2013-08-09 13:07:35 -04:00
Text Domain: ss
Domain Path: /languages/
2013-08-09 13:05:55 -04:00
*/
// require Genesis 1.2 upon activation
register_activation_hook(__FILE__, 'ss_activation_check');
function ss_activation_check() {
2013-08-09 13:07:35 -04:00
$latest = '1.2';
2013-08-09 13:05:55 -04:00
2013-08-09 13:07:35 -04:00
$theme_info = get_theme_data(TEMPLATEPATH.'/style.css');
2013-08-09 13:05:55 -04:00
if( basename(TEMPLATEPATH) != 'genesis' ) {
2013-08-09 13:07:35 -04:00
load_plugin_textdomain( 'ss', false, 'genesis-simple-sidebars/languages' );
2013-08-09 13:05:55 -04:00
deactivate_plugins(plugin_basename(__FILE__)); // Deactivate ourself
wp_die( sprintf( __('Sorry, you can\'t activate unless you have installed <a href="%s">Genesis</a>', 'ss'), 'http://www.studiopress.com/themes/genesis' ) );
}
if( version_compare( $theme_info['Version'], $latest, '<' ) ) {
deactivate_plugins(plugin_basename(__FILE__)); // Deactivate ourself
wp_die( sprintf( __('Sorry, you cannot activate without <a href="%s">Genesis %s</a> or greater', 'ss'), 'http://www.studiopress.com/support/showthread.php?t=19576', $latest ) );
}
}
2013-08-09 13:07:35 -04:00
/**
* Hook into Genesis
*/
add_action( 'genesis_init', 'ss_genesis_init', 12 );
function ss_genesis_init() {
// Define our constants
define( 'SS_SETTINGS_FIELD', 'ss-settings' );
define( 'SS_PLUGIN_DIR', dirname( __FILE__ ) );
2013-08-09 13:05:55 -04:00
2013-08-09 13:07:35 -04:00
// required hooks
add_action( 'get_header', 'ss_sidebars_init' );
add_action( 'widgets_init', 'ss_register_sidebars' );
if ( !is_admin() )
return;
2013-08-09 13:05:55 -04:00
2013-08-09 13:07:35 -04:00
// Include admin files
load_plugin_textdomain( 'ss', false, 'genesis-simple-sidebars/languages' );
require_once( SS_PLUGIN_DIR . '/admin.php' );
require_once( SS_PLUGIN_DIR . '/functions.php' );
require_once( SS_PLUGIN_DIR . '/inpost.php' );
require_once( SS_PLUGIN_DIR . '/term.php' );
// let the child theme hook the genesis_simple_sidebars_taxonomies filter before hooking term edit
add_action( 'init', 'ss_term_edit_init' );
}
2013-08-09 13:05:55 -04:00
/**
* This function registers the created sidebars
*/
function ss_register_sidebars() {
$_sidebars = stripslashes_deep( get_option( SS_SETTINGS_FIELD ) );
if ( !$_sidebars ) return;
foreach ( (array)$_sidebars as $id => $info ) {
register_sidebar(array(
'name' => esc_html( $info['name'] ),
'id' => $id,
'description' => esc_html( $info['description'] ),
'editable' => 1,
'before_widget' => '<div id="%1$s" class="widget %2$s"><div class="widget-wrap">',
'after_widget' => "</div></div>\n",
'before_title' => '<h4 class="widgettitle">',
'after_title' => "</h4>\n"
));
}
}
/**
* Remove the default sidebars, run some conditional logic,
* use alternate sidebars if necessary, else fallback on default sidebars.
*/
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');
}
function ss_do_sidebar() {
2013-08-09 13:07:35 -04:00
if ( ! ss_do_one_sidebar( '_ss_sidebar' ) )
genesis_do_sidebar();
2013-08-09 13:05:55 -04:00
}
function ss_do_sidebar_alt() {
2013-08-09 13:07:35 -04:00
if ( ! ss_do_one_sidebar( '_ss_sidebar_alt' ) )
genesis_do_sidebar_alt();
}
function ss_do_one_sidebar( $bar = '_ss_sidebar' ) {
static $taxonomies = null;
2013-08-09 13:05:55 -04:00
2013-08-09 13:07:35 -04:00
if ( is_singular() && $_bar = genesis_get_custom_field( $bar ) ) {
if ( dynamic_sidebar( $_bar ) ) return true;
2013-08-09 13:05:55 -04:00
}
if ( is_category() ) {
$term = get_term( get_query_var('cat'), 'category' );
2013-08-09 13:07:35 -04:00
if( isset( $term->meta[$bar] ) && dynamic_sidebar( $term->meta[$bar] ) ) return true;
2013-08-09 13:05:55 -04:00
}
if ( is_tag() ) {
$term = get_term( get_query_var('tag_id'), 'post_tag' );
2013-08-09 13:07:35 -04:00
if( isset( $term->meta[$bar] ) && dynamic_sidebar( $term->meta[$bar] ) ) return true;
}
if ( is_tax() ) {
if( $taxonomies === null )
2013-08-09 13:09:21 -04:00
$taxonomies = ss_get_taxonomies();
2013-08-09 13:07:35 -04:00
foreach( $taxonomies as $tax ) {
if( $tax == 'post_tag' || $tax == 'category' )
continue;
if( is_tax( $tax ) ) {
$obj = get_queried_object();
$term = get_term( $obj->term_id, $tax );
if( isset( $term->meta[$bar] ) && dynamic_sidebar( $term->meta[$bar] ) ) return true;
break;
}
}
2013-08-09 13:05:55 -04:00
}
2013-08-09 13:07:35 -04:00
return false;
2013-08-09 13:05:55 -04:00
2013-08-09 13:07:35 -04:00
}
2013-08-09 13:09:21 -04:00
function ss_get_taxonomies() {
$taxonomies = get_taxonomies( array( 'show_ui' => true, 'public' => true ) );
return apply_filters( 'genesis_simple_sidebars_taxonomies', array_keys( $taxonomies ) );
}
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 );
}