mirror of
https://github.com/10h30/genesis-simple-sidebars.git
synced 2026-06-05 15:08:34 +09:00
sweep.
This commit is contained in:
@@ -1,349 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Controls the creation, deletion, and editing of Simple Sidebar.
|
||||
*
|
||||
* @author StudioPress
|
||||
*/
|
||||
|
||||
/**
|
||||
* Registers a new admin page, providing content and corresponding menu item
|
||||
* for the Genesis Simple Sidebars plugin.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Genesis_Simple_Sidebars_Admin extends Genesis_Admin_Basic {
|
||||
|
||||
/**
|
||||
* Create an admin menu item and settings page.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @uses Genesis_Admin::create() Register the admin page
|
||||
*
|
||||
* @see Genesis_Admin_Import_Export::actions() Handle creating, editing, and deleting sidebars.
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
$page_id = 'simple-sidebars';
|
||||
|
||||
$menu_ops = array(
|
||||
'submenu' => array(
|
||||
'parent_slug' => 'genesis',
|
||||
'page_title' => __( 'Genesis - Simple Sidebars', 'ss' ),
|
||||
'menu_title' => __( 'Simple Sidebars', 'ss' )
|
||||
)
|
||||
);
|
||||
|
||||
//* 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 );
|
||||
|
||||
//* Simpe Sidebar actions (create, edit, or delete)
|
||||
add_action( 'admin_init', array( $this, 'actions' ) );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for displaying the Simple Sidebars admin page.
|
||||
*
|
||||
* Echoes out HTML.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
*/
|
||||
public function admin() {
|
||||
|
||||
$_sidebars = get_option( $this->settings_field );
|
||||
|
||||
echo '<div class="wrap">';
|
||||
|
||||
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' );
|
||||
|
||||
echo '</div>';
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Display sidebar table rows.
|
||||
*
|
||||
* Displays table rows of sidebars for viewing and editing on the main admin page.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
*/
|
||||
public function table_rows() {
|
||||
|
||||
global $wp_registered_sidebars;
|
||||
|
||||
$_sidebars = $wp_registered_sidebars;
|
||||
|
||||
$alt = true;
|
||||
|
||||
foreach ( (array) $_sidebars as $id => $info ) :
|
||||
|
||||
$is_editable = isset( $info['editable'] ) && $info['editable'] ? true : false;
|
||||
|
||||
?>
|
||||
|
||||
<tr <?php if ( $alt ) { echo 'class="alternate"'; $alt = false; } else { $alt = true; } ?>>
|
||||
<td class="name column-name">
|
||||
<?php
|
||||
if ( $is_editable ) {
|
||||
printf( '<a class="row-title" href="%s" title="Edit %s">%s</a>', admin_url('admin.php?page=simple-sidebars&action=edit&id=' . esc_html( $id ) ), esc_html( $info['name'] ), esc_html( $info['name'] ) );
|
||||
} else {
|
||||
printf( '<strong class="row-title">%s</strong>', esc_html( $info['name'] ) );
|
||||
}
|
||||
?>
|
||||
|
||||
<?php if ( $is_editable ) : ?>
|
||||
<br />
|
||||
<div class="row-actions">
|
||||
<span class="edit"><a href="<?php echo admin_url('admin.php?page=simple-sidebars&action=edit&id=' . esc_html( $id ) ); ?>"><?php _e('Edit', 'ss'); ?></a> | </span>
|
||||
<span class="delete"><a class="delete-tag" href="<?php echo wp_nonce_url( admin_url( 'admin.php?page=simple-sidebars&action=delete&id=' . esc_html( $id ) ), 'simple-sidebars-action_delete-sidebar' ); ?>"><?php _e('Delete', 'ss'); ?></a></span>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
</td>
|
||||
<td class="slug column-slug"><?php echo esc_html( $id ); ?></td>
|
||||
<td class="description column-description"><?php echo esc_html( $info['description'] )?></td>
|
||||
</tr>
|
||||
|
||||
<?php
|
||||
endforeach;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Action handler.
|
||||
*
|
||||
* Depending on what action was intended by the user, this method calls the appropriate action method.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
*/
|
||||
public function actions() {
|
||||
|
||||
if ( ! genesis_is_menu_page( 'simple-sidebars' ) )
|
||||
return;
|
||||
|
||||
/**
|
||||
* This section handles the data if a new sidebar is created
|
||||
*/
|
||||
if ( isset( $_REQUEST['action'] ) && 'create' == $_REQUEST['action'] ) {
|
||||
$this->create_sidebar( $_POST['new_sidebar'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* This section will handle the data if a sidebar is deleted
|
||||
*/
|
||||
if ( isset( $_REQUEST['action'] ) && 'delete' == $_REQUEST['action'] && isset( $_REQUEST['id'] ) ) {
|
||||
$this->delete_sidebar( $_REQUEST['id'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* This section will handle the data if a sidebar is to be modified
|
||||
*/
|
||||
if ( isset( $_REQUEST['action'] ) && 'edit' == $_REQUEST['action'] && ! isset( $_REQUEST['id'] ) ) {
|
||||
$this->edit_sidebar( $_POST['edit_sidebar'] );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add custom notices that display when you successfully create, edit, or delete a sidebar.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return null Returns null if not on the correct admin page.
|
||||
*/
|
||||
public function notices() {
|
||||
|
||||
if ( ! genesis_is_menu_page( 'simple-sidebars' ) )
|
||||
return;
|
||||
|
||||
$pattern = '<div id="message" class="updated"><p><strong>%s</strong></p></div>';
|
||||
|
||||
if ( isset( $_REQUEST['created'] ) && 'true' === $_REQUEST['created'] ) {
|
||||
printf( $pattern, __( 'New sidebar successfully created!', 'ss' ) );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( isset( $_REQUEST['edited'] ) && 'true' === $_REQUEST['edited'] ) {
|
||||
printf( $pattern, __( 'Sidebar successfully edited!', 'ss' ) );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( isset( $_REQUEST['deleted'] ) && 'true' === $_REQUEST['deleted'] ) {
|
||||
printf( $pattern, __( 'Sidebar successfully deleted.', 'ss' ) );
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a sidebar.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
*/
|
||||
protected function create_sidebar( $args = array() ) {
|
||||
|
||||
if ( empty( $args['name'] ) || empty( $args['id'] ) ) {
|
||||
wp_die( $this->error( 1 ) );
|
||||
exit;
|
||||
}
|
||||
|
||||
//* 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'] );
|
||||
|
||||
$db = (array) get_option( SS_SETTINGS_FIELD );
|
||||
$new = array(
|
||||
sanitize_title_with_dashes( $args['id'] ) => array(
|
||||
'name' => esc_html( $args['name'] ),
|
||||
'description' => esc_html( $args['description'] )
|
||||
)
|
||||
);
|
||||
|
||||
if ( array_key_exists( $args['id'], $db ) ) {
|
||||
wp_die( $this->error( 2 ) );
|
||||
exit;
|
||||
}
|
||||
|
||||
$_sidebars = wp_parse_args( $new, $db );
|
||||
|
||||
update_option( SS_SETTINGS_FIELD, $_sidebars );
|
||||
wp_redirect( admin_url( 'admin.php?page=simple-sidebars&created=true' ) );
|
||||
exit;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit a sidebar.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
*/
|
||||
protected function edit_sidebar( $args = array() ) {
|
||||
|
||||
if ( empty( $args['name'] ) || empty( $args['id'] ) ) {
|
||||
wp_die( $this->error( 3 ) );
|
||||
exit;
|
||||
}
|
||||
|
||||
//* 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 );
|
||||
$new = array(
|
||||
sanitize_title_with_dashes( $args['id'] ) => array(
|
||||
'name' => esc_html( $args['name'] ),
|
||||
'description' => esc_html( $args['description'] )
|
||||
)
|
||||
);
|
||||
|
||||
if ( ! array_key_exists( $args['id'], $db ) ) {
|
||||
wp_die( $this->error( 3 ) );
|
||||
exit;
|
||||
}
|
||||
|
||||
$_sidebars = wp_parse_args( $new, $db );
|
||||
|
||||
update_option( SS_SETTINGS_FIELD, $_sidebars );
|
||||
wp_redirect( admin_url( 'admin.php?page=simple-sidebars&edited=true' ) );
|
||||
exit;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a sidebar.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
*/
|
||||
protected function delete_sidebar( $id = '' ) {
|
||||
|
||||
if ( empty( $id ) ) {
|
||||
wp_die( $this->error( 4 ) );
|
||||
exit;
|
||||
}
|
||||
|
||||
//* nonce verification
|
||||
check_admin_referer( 'simple-sidebars-action_delete-sidebar' );
|
||||
|
||||
$_sidebars = (array) get_option( SS_SETTINGS_FIELD );
|
||||
|
||||
if ( ! isset( $_sidebars[$id] ) ) {
|
||||
wp_die( $this->error( 4 ) );
|
||||
exit;
|
||||
}
|
||||
|
||||
unset( $_sidebars[$id] );
|
||||
|
||||
update_option( SS_SETTINGS_FIELD, $_sidebars );
|
||||
wp_redirect( admin_url( 'admin.php?page=simple-sidebars&deleted=true' ) );
|
||||
exit;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an error message by ID.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return string Returns an error string based on an error ID.
|
||||
*/
|
||||
protected function error( $error = false ) {
|
||||
|
||||
if ( ! $error )
|
||||
return false;
|
||||
|
||||
switch( (int) $error ) {
|
||||
|
||||
case 1:
|
||||
return __( 'Oops! Please choose a valid Name and ID for this sidebar', 'ss' );
|
||||
break;
|
||||
case 2:
|
||||
return __( 'Oops! That sidebar ID already exists', 'ss' );
|
||||
break;
|
||||
case 3:
|
||||
return __( 'Oops! You are trying to edit a sidebar that does not exist, or is not editable', 'ss' );
|
||||
break;
|
||||
case 4:
|
||||
return __( 'Oops! You are trying to delete a sidebar that does not exist, or cannot be deleted', 'ss' );
|
||||
break;
|
||||
default:
|
||||
return __( 'Oops! Something went wrong. Try again.', 'ss' );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
add_action( 'genesis_admin_menu', 'simplesidebars_settings_menu' );
|
||||
/**
|
||||
* Instantiate the class to create the menu.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
function simplesidebars_settings_menu() {
|
||||
|
||||
new Genesis_Simple_Sidebars_Admin;
|
||||
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
<?php
|
||||
add_action('admin_menu', 'ss_add_inpost_metabox');
|
||||
/**
|
||||
* This bit of code registers the meta box on posts/pages,
|
||||
* so that users can choose what sidebar to use.
|
||||
*/
|
||||
function ss_add_inpost_metabox() {
|
||||
|
||||
foreach ( (array) get_post_types( array( 'public' => true ) ) as $type ) {
|
||||
|
||||
if ( post_type_supports( $type, 'genesis-simple-sidebars' ) || $type == 'post' || $type == 'page' ) {
|
||||
add_meta_box( 'ss_inpost_metabox', __( 'Sidebar Selection', 'ss' ), 'ss_inpost_metabox', $type, 'side', 'low' );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function ss_inpost_metabox() {
|
||||
|
||||
$_sidebars = stripslashes_deep( get_option( SS_SETTINGS_FIELD ) );
|
||||
global $wp_registered_sidebars;
|
||||
|
||||
?>
|
||||
|
||||
<input type="hidden" name="ss_inpost_nonce" value="<?php echo wp_create_nonce( plugin_basename( __FILE__ ) ); ?>" />
|
||||
|
||||
<?php
|
||||
if( isset( $wp_registered_sidebars['sidebar'] ) ) {
|
||||
?>
|
||||
|
||||
<p>
|
||||
<label class="howto" for="_ss_sidebar"><span><?php echo esc_attr( $wp_registered_sidebars['sidebar']['name'] ); ?><span></label>
|
||||
<select name="_ss_sidebar" id="_ss_sidebar" style="width: 99%">
|
||||
<option value=""><?php _e( 'Default', 'ss' ); ?></option>
|
||||
<?php
|
||||
foreach ( (array) $_sidebars as $id => $info ) {
|
||||
printf( '<option value="%s" %s>%s</option>', esc_html( $id ), selected( $id, genesis_get_custom_field( '_ss_sidebar' ), false), esc_html( $info['name'] ) );
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
if( isset( $wp_registered_sidebars['sidebar-alt'] ) ) {
|
||||
?>
|
||||
<p>
|
||||
<label class="howto" for="_ss_sidebar_alt"><span><?php echo esc_attr( $wp_registered_sidebars['sidebar-alt']['name'] ); ?><span></label>
|
||||
<select name="_ss_sidebar_alt" id="_ss_sidebar_alt" style="width: 99%">
|
||||
<option value=""><?php _e( 'Default', 'ss' ); ?></option>
|
||||
<?php
|
||||
foreach ( (array) $_sidebars as $id => $info ) {
|
||||
printf( '<option value="%s" %s>%s</option>', esc_html( $id ), selected( $id, genesis_get_custom_field( '_ss_sidebar_alt' ), false ), esc_html( $info['name'] ) );
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</p>
|
||||
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
add_action( 'save_post', 'ss_inpost_metabox_save', 1, 2 );
|
||||
/**
|
||||
* This bit of code saves the sidebars chosen as post meta.
|
||||
*/
|
||||
function ss_inpost_metabox_save( $post_id, $post ) {
|
||||
|
||||
//* verify the nonce
|
||||
if ( !isset($_POST['ss_inpost_nonce']) || !wp_verify_nonce( $_POST['ss_inpost_nonce'], plugin_basename(__FILE__) ) )
|
||||
return $post->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' => $_POST['_ss_sidebar'],
|
||||
'_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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* This function, hooked to display on the category/tag edit forms,
|
||||
* adds new fields to select a sidebar. The variables $tag and $taxonomy
|
||||
* are passed via the hook so that we can use them.
|
||||
*/
|
||||
function ss_term_edit_init() {
|
||||
|
||||
$taxonomies = ss_get_taxonomies();
|
||||
|
||||
if ( ! empty( $taxonomies ) && is_admin() && is_array( $taxonomies ) ) {
|
||||
|
||||
foreach( $taxonomies as $tax )
|
||||
add_action( "{$tax}_edit_form", 'ss_term_sidebar', 9, 2 );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function ss_term_sidebar($tag, $taxonomy) {
|
||||
|
||||
// Merge Defaults to prevent notices
|
||||
$tag->meta = wp_parse_args( $tag->meta, array( '_ss_sidebar' => '', '_ss_sidebar_alt' => '' ) );
|
||||
|
||||
// Pull custom sidebars
|
||||
$_sidebars = stripslashes_deep( get_option( SS_SETTINGS_FIELD ) );
|
||||
|
||||
?>
|
||||
|
||||
<h3><?php _e( 'Sidebar Options', 'ss' ); ?></h3>
|
||||
<table class="form-table">
|
||||
|
||||
<tr class="form-field">
|
||||
<th scope="row" valign="top"><label for="genesis-meta[_ss_sidebar]"><?php _e( 'Primary Sidebar', 'ss' ); ?></label></th>
|
||||
<td>
|
||||
<select name="genesis-meta[_ss_sidebar]" id="genesis-meta[_ss_sidebar]" style="padding-right: 10px;">
|
||||
<option value=""><?php _e( 'Default', 'ss' ); ?></option>
|
||||
<?php
|
||||
foreach ( (array) $_sidebars as $id => $info ) {
|
||||
printf( '<option value="%s" %s>%s</option>', esc_html( $id ), selected( $id, $tag->meta['_ss_sidebar'] , false), esc_html( $info['name'] ) );
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
// don't show the option if there are no 3 column layouts registered
|
||||
if ( ss_has_3_column_layouts() ) {
|
||||
?>
|
||||
<tr class="form-field">
|
||||
<th scope="row" valign="top"><label for="genesis-meta[_ss_sidebar_alt]"><?php _e( 'Secondary Sidebar', 'ss' ); ?></label></th>
|
||||
<td>
|
||||
<select name="genesis-meta[_ss_sidebar_alt]" id="genesis-meta[_ss_sidebar_alt]" style="padding-right: 10px;">
|
||||
<option value=""><?php _e( 'Default', 'ss' ); ?></option>
|
||||
<?php
|
||||
foreach ( (array) $_sidebars as $id => $info ) {
|
||||
printf( '<option value="%s" %s>%s</option>', esc_html( $id ), selected( $id, $tag->meta['_ss_sidebar_alt'] , false), esc_html( $info['name'] ) );
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
|
||||
<?php
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
<?php
|
||||
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.', 'ss' ) );
|
||||
}
|
||||
|
||||
screen_icon( 'themes' ); ?>
|
||||
<h2><?php _e( 'Edit Sidebar', 'ss' ); ?></h2>
|
||||
|
||||
<form method="post" action="<?php echo admin_url( 'admin.php?page=simple-sidebars&action=edit' ); ?>">
|
||||
<?php wp_nonce_field( 'simple-sidebars-action_edit-sidebar' ); ?>
|
||||
|
||||
<table class="form-table">
|
||||
|
||||
<tr class="form-field">
|
||||
<th scope="row" valign="top"><label for="edit_sidebar[name]"><?php _e( 'Name', 'ss' ); ?></label></th>
|
||||
<td><input name="edit_sidebar[name]" id="edit_sidebar[name]" type="text" value="<?php echo esc_html( $_sidebar['name'] ); ?>" size="40" />
|
||||
<p class="description"><?php _e( 'A recognizable name for your new sidebar widget area', 'ss' ); ?></p></td>
|
||||
</tr>
|
||||
|
||||
<tr class="form-field">
|
||||
<th scope="row" valign="top"><label for="edit_sidebar[id]"><?php _e( 'ID', 'ss' ); ?></label></th>
|
||||
<td>
|
||||
<input type="text" value="<?php echo esc_html( $_REQUEST['id'] ); ?>" size="40" disabled="disabled" />
|
||||
<input name="edit_sidebar[id]" id="edit_sidebar[id]" type="hidden" value="<?php echo esc_html( $_REQUEST['id'] ); ?>" size="40" />
|
||||
<p class="description"><?php _e( 'The unique ID is used to register the sidebar widget area (cannot be changed)', 'ss' ); ?></p></td>
|
||||
</tr>
|
||||
|
||||
<tr class="form-field">
|
||||
<th scope="row" valign="top"><label for="edit_sidebar[description]"><?php _e( 'Description', 'ss' ); ?></label></th>
|
||||
<td><textarea name="edit_sidebar[description]" id="edit_sidebar[description]" rows="3" cols="50" style="width: 97%;"><?php echo esc_html( $_sidebar['description'] ); ?></textarea></td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
|
||||
<p class="submit"><input type="submit" class="button-primary" name="submit" value="<?php _e( 'Update', 'ss' ); ?>" /></p>
|
||||
|
||||
</form>
|
||||
@@ -1,70 +0,0 @@
|
||||
<?php screen_icon( 'themes' ); ?>
|
||||
<h2><?php _e( 'Genesis - Simple Sidebars', 'ss' ); ?></h2>
|
||||
|
||||
<div id="col-container">
|
||||
|
||||
<div id="col-right">
|
||||
<div class="col-wrap">
|
||||
|
||||
<h3><?php _e( 'Current Sidebars', 'ss' ); ?></h3>
|
||||
<table class="widefat tag fixed" cellspacing="0">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col" id="name" class="manage-column column-name"><?php _e( 'Name', 'ss' ); ?></th>
|
||||
<th scope="col" class="manage-column column-slug"><?php _e( 'ID', 'ss' ); ?></th>
|
||||
<th scope="col" id="description" class="manage-column column-description"><?php _e( 'Description', 'ss' ); ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tfoot>
|
||||
<tr>
|
||||
<th scope="col" class="manage-column column-name"><?php _e( 'Name', 'ss' ); ?></th>
|
||||
<th scope="col" class="manage-column column-slug"><?php _e( 'ID', 'ss' ); ?></th>
|
||||
<th scope="col" class="manage-column column-description"><?php _e( 'Description', 'ss' ); ?></th>
|
||||
</tr>
|
||||
</tfoot>
|
||||
|
||||
<tbody id="the-list" class="list:tag">
|
||||
|
||||
<?php $this->table_rows(); ?>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
</div>
|
||||
</div><!-- /col-right -->
|
||||
|
||||
<div id="col-left">
|
||||
<div class="col-wrap">
|
||||
|
||||
|
||||
<div class="form-wrap">
|
||||
<h3><?php _e( 'Add New Sidebar', 'ss' ); ?></h3>
|
||||
|
||||
<form method="post" action="<?php echo admin_url( 'admin.php?page=simple-sidebars&action=create' ); ?>">
|
||||
<?php wp_nonce_field( 'simple-sidebars-action_create-sidebar' ); ?>
|
||||
|
||||
<div class="form-field form-required">
|
||||
<label for="sidebar-name"><?php _e( 'Name', 'ss' ); ?></label>
|
||||
<input name="new_sidebar[name]" id="sidebar-name" type="text" value="" size="40" aria-required="true" />
|
||||
<p><?php _e( 'A recognizable name for your new sidebar widget area', 'ss' ); ?></p>
|
||||
</div>
|
||||
|
||||
<div class="form-field">
|
||||
<label for="sidebar-id"><?php _e( 'ID', 'ss' ); ?></label>
|
||||
<input name="new_sidebar[id]" id="sidebar-id" type="text" value="" size="40" />
|
||||
<p><?php _e( 'The unique ID is used to register the sidebar widget area', 'ss' ); ?></p>
|
||||
</div>
|
||||
|
||||
<div class="form-field">
|
||||
<label for="sidebar-description"><?php _e( 'Description', 'ss' ); ?></label>
|
||||
<textarea name="new_sidebar[description]" id="sidebar-description" rows="5" cols="40"></textarea>
|
||||
</div>
|
||||
|
||||
<p class="submit"><input type="submit" class="button" name="submit" id="submit" value="<?php _e( 'Add New Sidebar', 'ss' ); ?>" /></p>
|
||||
</form></div>
|
||||
|
||||
</div>
|
||||
</div><!-- /col-left -->
|
||||
|
||||
</div><!-- /col-container -->
|
||||
-239
@@ -1,239 +0,0 @@
|
||||
<?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.
|
||||
Author: Nathan Rice
|
||||
Author URI: http://www.nathanrice.net/
|
||||
|
||||
Text Domain: ss
|
||||
Domain Path: /languages/
|
||||
|
||||
Version: 2.0.1
|
||||
|
||||
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.0.0', '>=' ) )
|
||||
ss_deactivate( '2.0.0', '3.6' );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Deactivate Simple Sidebars.
|
||||
*
|
||||
* This function deactivates Simple Sidebars.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
function ss_deactivate( $genesis_version = '1.8.0', $wp_version = '3.3' ) {
|
||||
|
||||
deactivate_plugins( plugin_basename( __FILE__ ) );
|
||||
wp_die( sprintf( __( 'Sorry, you cannot run Simple Sidebars without WordPress %s and <a href="%s">Genesis %s</a>, or greater.', 'ss' ), $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( 'ss', 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 ) {
|
||||
|
||||
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' ) {
|
||||
|
||||
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 ( is_tax() ) {
|
||||
if ( null === $taxonomies )
|
||||
$taxonomies = ss_get_taxonomies();
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 );
|
||||
|
||||
}
|
||||
-73
@@ -1,73 +0,0 @@
|
||||
=== Plugin Name ===
|
||||
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: 3.6
|
||||
Stable tag: 2.0.1
|
||||
|
||||
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.
|
||||
|
||||
== Description ==
|
||||
|
||||
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.
|
||||
|
||||
Creating widget areas programmatically, then using conditional logic to properly assign them to sidebar locations can be a complex task for a beginner. This plugin allows you to do all this from a simple administration menu, and assign widget areas to sidebar locations with simple drop-down menus within the post/page edit screens, or when editing a tag or category.
|
||||
|
||||
== Installation ==
|
||||
|
||||
1. Upload the entire `genesis-simple-sidebars` folder to the `/wp-content/plugins/` directory
|
||||
1. DO NOT change the name of the `genesis-simple-sidebars` folder
|
||||
1. Activate the plugin through the 'Plugins' menu in WordPress
|
||||
1. Navigate to the `Genesis > Simple Sidebars` menu
|
||||
1. Create as many new sidebar widget areas as you need
|
||||
1. Choose the widget area you want to display by choosing it from the drop-down menu in the post/page or category/tag edit screen.
|
||||
|
||||
== Frequently Asked Questions ==
|
||||
|
||||
= Can I assign widget areas to locations other than the sidebars? =
|
||||
|
||||
No. You can only assign them to the primary and secondary sidebars, using the plugin.
|
||||
|
||||
However, once a widget area has been created, you can use hooks to programmatically display those widget areas throughout the theme. But if you're going to do that, it's very unlikely that you would want to use the plugin to create the widget areas. You might as well just create the widget areas programmatically too.
|
||||
|
||||
= Does this plugin give me the option of creating an entirely NEW sidebar? =
|
||||
|
||||
Not in the way you're probably thinking. The markup surrounding the widget area never changes. The only thing that changes is the dynamic content that displays within the pre-existing sidebar locations.
|
||||
|
||||
== Changelog ==
|
||||
|
||||
= 0.1 =
|
||||
* Initial Alpha Release
|
||||
|
||||
= 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
|
||||
|
||||
= 0.9.1 =
|
||||
* Added support for custom post types
|
||||
|
||||
= 0.9.2 =
|
||||
* Added support for custom taxonomies
|
||||
* Added translation support
|
||||
* bug fix to prevent invalid sidebar creation
|
||||
|
||||
= 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
|
||||
|
||||
= 1.0.0 =
|
||||
* Reorganize theme files
|
||||
* Standards
|
||||
|
||||
= 2.0.0 =
|
||||
* Compatibility with Genesis 2.0
|
||||
* Standards
|
||||
|
||||
= 2.0.1 =
|
||||
* Genesis 2.0.1 compatibility with term meta keys
|
||||
* Use actual sidebar name, instead of hard coded names
|
||||
* Fix incorrect textdomain
|
||||
Reference in New Issue
Block a user