Created
November 9, 2011 19:38
-
-
Save deckerweb/1352683 to your computer and use it in GitHub Desktop.
Genesis Layout Extras Plugin 1.3-alpha -- For Genesis 1.8 and new Admin Classes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Main plugin file. This plugin for Genesis Theme Framework allows modifying of default layouts for | |
* homepage, singular, archive, attachment, search, 404 and even bbPress 2.x pages via Genesis theme settings. | |
* | |
* @package GenesisLayoutExtras | |
* @author David Decker | |
* @origin Based on the work of @WPChildThemes for original plugin called "Genesis Layout Manager" (C) 2010 | |
* | |
* Plugin Name: Genesis Layout Extras | |
* Plugin URI: http://genesisthemes.de/en/wp-plugins/genesis-layout-extras/ | |
* Description: This plugin for Genesis Theme Framework allows modifying of default layouts for homepage, singular, archive, attachment, search, 404 and even bbPress 2.x pages via Genesis theme settings. | |
* Version: 1.3-alpha | |
* Author: David Decker - DECKERWEB | |
* Author URI: http://deckerweb.de/ | |
* License: GPLv2 | |
* Text Domain: genesis-layout-extras | |
* Domain Path: /languages/ | |
*/ | |
/** | |
* Setting constants | |
* | |
* @since 1.0 | |
*/ | |
define( 'GLE_PLUGIN_DIR', dirname( __FILE__ ) ); | |
define( 'GLE_PLUGIN_BASEDIR', dirname( plugin_basename( __FILE__ ) ) ); | |
define( 'GLE_SETTINGS_FIELD', 'gle-settings' ); | |
/** | |
* The text domain for the plugin | |
* | |
* @since 1.0 | |
*/ | |
define( 'GLE_DOMAIN' , 'genesis-layout-extras' ); | |
/** | |
* Load the text domain for translation of the plugin | |
* | |
* @since 1.0 | |
*/ | |
load_plugin_textdomain( 'genesis-layout-extras', false, 'genesis-layout-extras/languages' ); // Plugin folder | |
load_plugin_textdomain( 'genesis-layout-extras', false, '/../../languages/genesis-layout-extras' ); // WordPress languages folder | |
register_activation_hook( __FILE__, 'ddw_genesis_layout_extras_activation_check' ); | |
/** | |
* Checks for activated Genesis Framework and its minimum version before allowing plugin to activate | |
* | |
* @author Nathan Rice | |
* @uses ddw_genesis_layout_extras_truncate() | |
* @since 0.1 | |
* @version 1.1 | |
*/ | |
function ddw_genesis_layout_extras_activation_check() { | |
$latest = '1.7'; | |
$theme_info = get_theme_data( get_template_directory() . '/style.css' ); | |
if ( basename( get_template_directory() ) != 'genesis' ) { | |
deactivate_plugins( plugin_basename( __FILE__ ) ); // Deactivate ourself | |
wp_die( sprintf( __( 'Sorry, you can’t activate unless you have installed the %1$sGenesis Framework%2$s', GLE_DOMAIN ), '<a href="http://deckerweb.de/go/genesis/" target="_new">', '</a>' ) ); | |
} | |
$version = ddw_genesis_layout_extras_truncate( $theme_info['Version'], 3 ); | |
if ( version_compare( $version, $latest, '<' ) ) { | |
deactivate_plugins( plugin_basename( __FILE__ ) ); // Deactivate ourself | |
wp_die( sprintf( __( 'Sorry, you can’t activate without %1$sGenesis Framework %2$s%3$s or greater', GLE_DOMAIN ), '<a href="http://deckerweb.de/go/genesis/" target="_new">', $latest, '</a>' ) ); | |
} | |
} | |
/** | |
* Used to cutoff a string to a set length if it exceeds the specified length | |
* | |
* @author Nick Croft | |
* @link http://designsbynickthegeek.com/ | |
* | |
* @since 0.1 | |
* @version 0.2 | |
* @param string $str Any string that might need to be shortened | |
* @param string $length Any whole integer | |
* @return string | |
*/ | |
function ddw_genesis_layout_extras_truncate( $str, $length=10 ) { | |
if ( strlen( $str ) > $length ) { | |
return substr( $str, 0, $length ); | |
} else { | |
$res = $str; | |
} | |
return $res; | |
} | |
/** | |
* Registers a new options page for the plugin. | |
* | |
* @package GenesisLayoutExtras | |
* | |
* @since 1.0 | |
* @version 1.3 | |
*/ | |
class Genesis_Layout_Extra_Settings extends Genesis_Admin_Boxes { | |
/** | |
* Create an admin menu item and settings page. | |
* | |
* @since 1.0 | |
* @version 1.3 | |
*/ | |
function __construct() { | |
// Specify a unique page ID. | |
$page_id = 'gle-layout-extras'; | |
// Set it as a submenu to genesis, and define the menu and page titles | |
$menu_ops = array( | |
'submenu' => array( | |
'parent_slug' => 'genesis', | |
'page_title' => __( 'Genesis Layout Extras', GLE_DOMAIN ), | |
'menu_title' => __( 'Layout Extras', GLE_DOMAIN ), | |
) | |
); | |
// Set up page options. | |
$page_ops = array( | |
'screen_icon' => 'themes', | |
// 'save_button_text' => 'Save Settings', | |
// 'reset_button_text' => 'Reset Settings', | |
'save_notice_text' => __( 'The extra layout settings have been saved successfully.', GLE_DOMAIN ), | |
'reset_notice_text' => __( 'ALL extra layout settings were reset to their Genesis default option.', GLE_DOMAIN ), | |
); | |
// Give it a unique settings field. | |
$settings_field = 'gle-settings'; | |
// Set the default values | |
$default_settings = array( | |
'ddw_genesis_layout_home', | |
'ddw_genesis_layout_search', | |
'ddw_genesis_layout_404', | |
'ddw_genesis_layout_post', | |
'ddw_genesis_layout_page', | |
'ddw_genesis_layout_attachment', | |
'ddw_genesis_layout_author', | |
'ddw_genesis_layout_date', | |
'ddw_genesis_layout_date_year', | |
'ddw_genesis_layout_date_month', | |
'ddw_genesis_layout_date_day', | |
'ddw_genesis_layout_category', | |
'ddw_genesis_layout_tag', | |
'ddw_genesis_layout_taxonomy', | |
'ddw_genesis_layout_cpt_apl_listing', | |
'ddw_genesis_layout_bbpress' | |
); | |
// Create the Admin Page | |
$this->create( $page_id, $menu_ops, $page_ops, $settings_field, $default_settings ); | |
// Initialize the Sanitization Filter | |
add_action( 'genesis_settings_sanitizer_init', array( $this, 'sanitization_filters' ) ); | |
} | |
/** | |
* Set up Sanitization Filters - add settings to Genesis sanitization | |
* | |
* @since 1.0 | |
* @version 1.3 | |
*/ | |
function sanitization_filters() { | |
genesis_add_option_filter( 'no_html', $this->settings_field, | |
array( | |
'ddw_genesis_layout_home', | |
'ddw_genesis_layout_search', | |
'ddw_genesis_layout_404', | |
'ddw_genesis_layout_post', | |
'ddw_genesis_layout_page', | |
'ddw_genesis_layout_attachment', | |
'ddw_genesis_layout_author', | |
'ddw_genesis_layout_date', | |
'ddw_genesis_layout_date_year', | |
'ddw_genesis_layout_date_month', | |
'ddw_genesis_layout_date_day', | |
'ddw_genesis_layout_category', | |
'ddw_genesis_layout_tag', | |
'ddw_genesis_layout_taxonomy', | |
'ddw_genesis_layout_cpt_apl_listing', | |
'ddw_genesis_layout_bbpress' | |
) ); | |
} | |
/** | |
* Register meta box to options page | |
* | |
* @since 1.0 | |
* @version 1.3 | |
*/ | |
function metaboxes() { | |
add_meta_box( 'genesis-layout-extras-box', __( 'Genesis Layout Extras', GLE_DOMAIN ), array( $this, 'ddw_genesis_layout_extras_box' ), $this->pagehook, 'main', 'high' ); | |
} | |
/** | |
* Callback for Genesis Layout Extras metabox | |
* Setting up the setting fields & labels | |
* | |
* @since 1.0 | |
* @version 1.3 | |
*/ | |
function ddw_genesis_layout_extras_box() { | |
// Description - user info | |
echo '<p><span class="description">' . sprintf( __( 'Here you can set up a <strong>default</strong> layout option for various extra archive pages and other special pages. %1$sGenesis Default%2$s in the drop-down menus below always means the chosen default layout option in the regular <a href="%3$s">Genesis layout settings</a>.', GLE_DOMAIN ), '<code style="font-style: normal; color: #333;">', '</code>', admin_url( 'admin.php?page=genesis#genesis-theme-settings-layout' ) ) . '</span></p>'; | |
echo '<hr class="div" />'; | |
// Special sections | |
echo '<h4>' . __( 'Special Sections', GLE_DOMAIN ) . '</h4>'; | |
ddw_genesis_layout_extras_option( __( 'Hompage Layout: ', GLE_DOMAIN ), 'ddw_genesis_layout_home' ); | |
echo '<p><span class="description">' . sprintf( __( 'This setting works for homepage templates (file %1$shome.php%2$s is there - %1$sis_home()%2$s) <u>and</u> also for static pages as front page (%1$sis_front_page()%2$s).', GLE_DOMAIN ), '<code style="font-style: normal; color: #333;">', '</code>' ) . '</span></p>'; | |
ddw_genesis_layout_extras_option( __( 'Search Page Layout: ', GLE_DOMAIN ), 'ddw_genesis_layout_search' ); | |
ddw_genesis_layout_extras_option( __( '404 Page Layout: ', GLE_DOMAIN ), 'ddw_genesis_layout_404' ); | |
echo '<hr class="div" />'; | |
// Singular pages | |
echo '<h4>' . __( 'Singular Pages', GLE_DOMAIN ) . '</h4>'; | |
ddw_genesis_layout_extras_option( __( 'Post Page Layout: ', GLE_DOMAIN ), 'ddw_genesis_layout_post' ); | |
ddw_genesis_layout_extras_option( __( 'Page Page Layout: ', GLE_DOMAIN ), 'ddw_genesis_layout_page' ); | |
ddw_genesis_layout_extras_option( __( 'Attachment Page Layout: ', GLE_DOMAIN ), 'ddw_genesis_layout_attachment' ); | |
echo '<hr class="div" />'; | |
// Archive sections | |
echo '<h4>' . __( 'Archive Sections', GLE_DOMAIN ) . '</h4>'; | |
ddw_genesis_layout_extras_option( __( 'Author Page Layout: ', GLE_DOMAIN ), 'ddw_genesis_layout_author' ); | |
ddw_genesis_layout_extras_option( __( 'Date Archive Page Layout: ', GLE_DOMAIN ), 'ddw_genesis_layout_date' ); | |
echo '<p><span class="description">' . sprintf( __( 'This is the general setting for date archives and overwrites the following three settings (Year, Month, Day)! So, if you setup any of the following three settings then let this one here on %1$sGenesis Default%2$s.', GLE_DOMAIN ), '<code style="font-style: normal; color: #333;">', '</code>' ) . '</span></p>'; | |
ddw_genesis_layout_extras_option( '· ' . __( 'Date Archive - Year Page Layout: ', GLE_DOMAIN ), 'ddw_genesis_layout_date_year' ); | |
ddw_genesis_layout_extras_option( '· ' . __( 'Date Archive - Month Page Layout: ', GLE_DOMAIN ), 'ddw_genesis_layout_date_month' ); | |
ddw_genesis_layout_extras_option( '· ' . __( 'Date Archive - Day Page Layout: ', GLE_DOMAIN ), 'ddw_genesis_layout_date_day' ); | |
ddw_genesis_layout_extras_option( __( 'Category Page Layout: ', GLE_DOMAIN ), 'ddw_genesis_layout_category' ); | |
ddw_genesis_layout_extras_option( __( 'Tag Page Layout: ', GLE_DOMAIN ), 'ddw_genesis_layout_tag' ); | |
ddw_genesis_layout_extras_option( __( 'Taxonomy Page Layout: ', GLE_DOMAIN ), 'ddw_genesis_layout_taxonomy' ); | |
echo '<hr class="div" />'; | |
// Special Custom Post Type sections | |
echo '<h4>' . __( 'Special Custom Post Type Sections', GLE_DOMAIN ) . '</h4>'; | |
ddw_genesis_layout_extras_option( __( 'AgentPress Listing Post Type Layout (archive): ', GLE_DOMAIN ), 'ddw_genesis_layout_cpt_apl_listing' ); | |
echo '<p><span class="description">' . sprintf( __( 'For this setting to take any effect the %1$splugin <em>AgentPress Listings</em>%2$s needs to be installed first. — Of course, the plugin (and so the setting here) could be used with the %3$sAgentPress child theme%4$s and also with any other Genesis child theme, so this setting might come in really handy ;-).', GLE_DOMAIN ), '<a href="http://deckerweb.de/go/agentpress-listings/" target="_new" title="Plugin: AgentPress Listings ...">', '</a>', '<a href="http://deckerweb.de/go/genesis-agentpress-child-theme/" target="_new" title="AgentPress Genesis Child Theme ...">', '</a>' ) . '</span></p>'; | |
echo '<hr class="div" />'; | |
// bbPress 2.x Forum section | |
echo '<h4>' . __( 'Plugin: bbPress 2.x Forum Section', GLE_DOMAIN ) . '</h4>'; | |
ddw_genesis_layout_extras_option( __( 'bbPress 2.x Forum Layout (all areas): ', GLE_DOMAIN ), 'ddw_genesis_layout_bbpress' ); | |
echo '<p><span class="description">' . sprintf( __( 'For this setting to take any effect the %1$splugin <em>bbPress 2.0+</em>%2$s needs to be installed first.', GLE_DOMAIN ), '<a href="http://wordpress.org/extend/plugins/bbpress/" target="_new" title="Plugin: bbPress 2.x Forum ...">', '</a>' ) . '</span></p>'; | |
} | |
// Setting up the drop-down menus | |
function ddw_genesis_layout_extras_option( $title, $option ) { ?> | |
<p><?php echo $title; ?> | |
<select name="<?php echo GLE_SETTINGS_FIELD; ?>[<?php echo $option; ?>]"> | |
<option style="padding-right:10px;" value="" <?php selected( '', genesis_get_option( $option, GLE_SETTINGS_FIELD ) ); ?>><?php _e( 'Genesis Default', GLE_DOMAIN ); ?></option> | |
<option style="padding-right: 10px; background-color: #eee;" value="content-sidebar" <?php selected( 'content-sidebar', genesis_get_option( $option, GLE_SETTINGS_FIELD ) ); ?>><?php _e( 'Content-Sidebar', GLE_DOMAIN); ?></option> | |
<option style="padding-right: 10px; background-color: #eee;" value="sidebar-content" <?php selected( 'sidebar-content', genesis_get_option( $option, GLE_SETTINGS_FIELD ) ); ?>><?php _e( 'Sidebar-Content', GLE_DOMAIN ); ?></option> | |
<option style="padding-right: 10px; background-color: #fafafa;" value="content-sidebar-sidebar" <?php selected( 'content-sidebar-sidebar', genesis_get_option( $option, GLE_SETTINGS_FIELD ) ); ?>><?php _e( 'Content-Sidebar-Sidebar', GLE_DOMAIN ); ?></option> | |
<option style="padding-right: 10px; background-color: #fafafa;" value="sidebar-sidebar-content" <?php selected( 'sidebar-sidebar-content', genesis_get_option( $option, GLE_SETTINGS_FIELD ) ); ?>><?php _e( 'Sidebar-Sidebar-Content', GLE_DOMAIN ); ?></option> | |
<option style="padding-right: 10px; background-color: #fafafa;" value="sidebar-content-sidebar" <?php selected( 'sidebar-content-sidebar', genesis_get_option( $option, GLE_SETTINGS_FIELD ) ); ?>><?php _e( 'Sidebar-Content-Sidebar', GLE_DOMAIN ); ?></option> | |
<option style="padding-right: 10px; background-color: #ddd;" value="full-width-content" <?php selected( 'full-width-content', genesis_get_option( $option, GLE_SETTINGS_FIELD ) ); ?>><?php _e( 'Full Width Content', GLE_DOMAIN ); ?></option> | |
</select></p> | |
<?php | |
} | |
} // End of Class | |
add_filter( 'genesis_pre_get_option_site_layout', 'ddw_genesis_layout_extras_filter', 101 ); | |
/** | |
* Manage Genesis layouts for extra sections | |
* | |
* @uses filter: genesis_pre_get_option_site_layout | |
* @since 0.1 | |
* @version 1.1 | |
*/ | |
function ddw_genesis_layout_extras_filter( $opt ) { | |
if ( is_home() || is_front_page() && genesis_get_option( 'ddw_genesis_layout_home', GLE_SETTINGS_FIELD ) ) | |
$opt = genesis_get_option( 'ddw_genesis_layout_home', GLE_SETTINGS_FIELD ); | |
elseif ( is_404() && genesis_get_option( 'ddw_genesis_layout_404', GLE_SETTINGS_FIELD ) ) | |
$opt = genesis_get_option( 'ddw_genesis_layout_404', GLE_SETTINGS_FIELD ); | |
elseif ( is_search() && genesis_get_option('ddw_genesis_layout_search', GLE_SETTINGS_FIELD ) ) | |
$opt = genesis_get_option( 'ddw_genesis_layout_search', GLE_SETTINGS_FIELD ); | |
elseif ( is_date() && genesis_get_option( 'ddw_genesis_layout_date', GLE_SETTINGS_FIELD ) ) | |
$opt = genesis_get_option( 'ddw_genesis_layout_date', GLE_SETTINGS_FIELD ); | |
elseif ( is_year() && genesis_get_option( 'ddw_genesis_layout_date_year', GLE_SETTINGS_FIELD ) ) | |
$opt = genesis_get_option( 'ddw_genesis_layout_date_year', GLE_SETTINGS_FIELD ); | |
elseif ( is_month() && genesis_get_option( 'ddw_genesis_layout_date_month', GLE_SETTINGS_FIELD ) ) | |
$opt = genesis_get_option( 'ddw_genesis_layout_date_month', GLE_SETTINGS_FIELD ); | |
elseif ( is_day() && genesis_get_option( 'ddw_genesis_layout_date_day', GLE_SETTINGS_FIELD ) ) | |
$opt = genesis_get_option( 'ddw_genesis_layout_date_day', GLE_SETTINGS_FIELD ); | |
elseif ( is_author() && genesis_get_option( 'ddw_genesis_layout_author', GLE_SETTINGS_FIELD ) ) | |
$opt = genesis_get_option( 'ddw_genesis_layout_author', GLE_SETTINGS_FIELD ); | |
elseif ( is_category() && genesis_get_option( 'ddw_genesis_layout_category', GLE_SETTINGS_FIELD ) ) | |
$opt = genesis_get_option( 'ddw_genesis_layout_category', GLE_SETTINGS_FIELD ); | |
elseif ( is_tag() && genesis_get_option( 'ddw_genesis_layout_tag', GLE_SETTINGS_FIELD ) ) | |
$opt = genesis_get_option( 'ddw_genesis_layout_tag', GLE_SETTINGS_FIELD ); | |
elseif ( is_tax() && genesis_get_option( 'ddw_genesis_layout_taxonomy', GLE_SETTINGS_FIELD ) ) | |
$opt = genesis_get_option( 'ddw_genesis_layout_taxonomy', GLE_SETTINGS_FIELD ); | |
elseif ( is_single() && genesis_get_option( 'ddw_genesis_layout_post', GLE_SETTINGS_FIELD ) ) | |
$opt = genesis_get_option( 'ddw_genesis_layout_post', GLE_SETTINGS_FIELD ); | |
elseif ( is_page() && genesis_get_option( 'ddw_genesis_layout_page', GLE_SETTINGS_FIELD ) ) | |
$opt = genesis_get_option( 'ddw_genesis_layout_page', GLE_SETTINGS_FIELD ); | |
elseif ( is_attachment() && genesis_get_option( 'ddw_genesis_layout_attachment', GLE_SETTINGS_FIELD ) ) | |
$opt = genesis_get_option( 'ddw_genesis_layout_attachment', GLE_SETTINGS_FIELD ); | |
elseif ( is_post_type_archive( 'listing' ) && genesis_get_option( 'ddw_genesis_layout_cpt_apl_listing', GLE_SETTINGS_FIELD ) ) | |
$opt = genesis_get_option( 'ddw_genesis_layout_cpt_apl_listing', GLE_SETTINGS_FIELD ); | |
return $opt; | |
} | |
add_filter( 'bbp_genesis_force_full_content_width', 'ddw_genesis_layout_extras_bbpress_filter', 101 ); | |
/** | |
* Manage Genesis layouts for bbPress 2.x Forum section (plugin) | |
* | |
* @uses filter: bbp_genesis_force_full_content_width | |
* @since 1.0 | |
*/ | |
function ddw_genesis_layout_extras_bbpress_filter( $opt ) { | |
if ( is_bbpress() && genesis_get_option( 'ddw_genesis_layout_bbpress', GLE_SETTINGS_FIELD ) ) | |
$opt = genesis_get_option( 'ddw_genesis_layout_bbpress', GLE_SETTINGS_FIELD ); | |
return $opt; | |
} | |
/** | |
* Add the Plugin Option Settings Page | |
* | |
* @since 1.3 | |
*/ | |
function ddw_genesis_layout_extras_add_plugin_settings() { | |
global $_gle_plugin_settings; | |
$_gle_plugin_settings = new Genesis_Layout_Extra_Settings; | |
} | |
add_action( 'admin_menu', 'ddw_genesis_layout_extras_add_plugin_settings', 5 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment