';
@@ -129,8 +146,9 @@ class Genesis_Simple_Sidebars_Admin extends Genesis_Admin_Basic {
*/
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 @@ class Genesis_Simple_Sidebars_Admin extends Genesis_Admin_Basic {
*/
public function notices() {
- if ( ! genesis_is_menu_page( 'simple-sidebars' ) )
+ if ( ! genesis_is_menu_page( 'simple-sidebars' ) ) {
return;
+ }
$pattern = '
%s
';
@@ -201,17 +220,19 @@ class Genesis_Simple_Sidebars_Admin extends Genesis_Admin_Basic {
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'] ) )
+ // 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( $this->settings_field );
- $db = (array) get_option( SS_SETTINGS_FIELD );
$new = array(
sanitize_title_with_dashes( $args['id'] ) => array(
- 'name' => esc_html( $args['name'] ),
+ 'name' => esc_html( $args['name'] ),
'description' => esc_html( $args['description'] )
)
);
@@ -223,7 +244,7 @@ class Genesis_Simple_Sidebars_Admin extends Genesis_Admin_Basic {
$_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,14 +263,15 @@ class Genesis_Simple_Sidebars_Admin extends Genesis_Admin_Basic {
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'] ) )
+ // 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'] ),
@@ -264,7 +286,7 @@ class Genesis_Simple_Sidebars_Admin extends Genesis_Admin_Basic {
$_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 +305,10 @@ class Genesis_Simple_Sidebars_Admin extends Genesis_Admin_Basic {
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 +317,7 @@ class Genesis_Simple_Sidebars_Admin extends Genesis_Admin_Basic {
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;
@@ -335,17 +357,3 @@ class Genesis_Simple_Sidebars_Admin extends Genesis_Admin_Basic {
}
}
-
-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..ee22349
--- /dev/null
+++ b/includes/class-genesis-simple-sidebars-core.php
@@ -0,0 +1,197 @@
+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() {
+
+ 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 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..d89e91e
--- /dev/null
+++ b/includes/class-genesis-simple-sidebars-entry.php
@@ -0,0 +1,62 @@
+ 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_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 74d08b6..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 ) );
-
-?>
-
-
-