Skip to content

Instantly share code, notes, and snippets.

@joshuadavidnelson
Last active August 29, 2018 06:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshuadavidnelson/1aefa78ef7eba90f4de0 to your computer and use it in GitHub Desktop.
Save joshuadavidnelson/1aefa78ef7eba90f4de0 to your computer and use it in GitHub Desktop.
Override Genesis Theme Settings with this handy helper class.
<?php
/**
* Using the Genesis Settings Helper Class
*
* @version 1.0.0
* @author Joshua David Nelson, josh@joshuadnelson.com
* @license GPLv2.0+
*/
// Reference the helper class by uncommenting below and setting it to the path relative to this file
// require_once '/path/to/genesis-settings-override.php';
add_action( 'init', 'jdn_set_theme_options' );
function jdn_set_theme_options() {
if( class_exists( 'JDN_Override_Genesis_Settings' ) ) {
$override = new JDN_Override_Genesis_Settings;
// Override Theme Settings - these are all the defaults
$options = array(
'update' => 1,
'blog_title' => 'text', // or 'image'
'header_right' => 0,
'site_layout' => genesis_get_default_layout(),
'superfish' => 0,
'nav_extras' => '',
'nav_extras_twitter_id' => '',
'nav_extras_twitter_text' => __( 'Follow me on Twitter', 'genesis' ),
'feed_uri' => '',
'comments_feed_uri' => '',
'redirect_feeds' => 0,
'comments_pages' => 0,
'comments_posts' => 1,
'trackbacks_pages' => 0,
'trackbacks_posts' => 1,
'breadcrumb_home' => 0,
'breadcrumb_front_page' => 0,
'breadcrumb_posts_page' => 0,
'breadcrumb_single' => 0,
'breadcrumb_page' => 0,
'breadcrumb_archive' => 0,
'breadcrumb_404' => 0,
'breadcrumb_attachment' => 0,
'content_archive' => 'full', // or 'excerpts'
'content_archive_thumbnail' => 0,
'posts_nav' => 'older-newer', // or 'numeric'
'blog_cat' => '',
'blog_cat_exclude' => '',
'blog_cat_num' => 10,
'header_scripts' => '',
'footer_scripts' => '',
'image_size' => 'full', // or any other registered image size
'image_alignment' => '', // blank, 'alignleft' or 'alignright'
);
$override->set_options( $options );
// Remove Theme Settings Metaboxes
$metaboxes = array( 'breadcrumb', 'feeds', 'header', 'nav', 'breadcrumb', 'comments', 'posts', 'blogpage', 'scripts', 'version' );
$override->remove_metaboxes( $metaboxes );
}
}
<?php
/**
* Override theme settings and remove theme settings metaboxes with this helper class
*
* Requires WordPress v2.6.0 and PHP v5.3.0
*
* @version 2.0.0
* @author Joshua David Nelson, josh@joshuadnelson.com
* @license GPLv2.0+
*
* Copyirght 2015, Joshua David Nelson
*/
class JDN_Override_Genesis_Settings {
// The array of options to set
private $options = array();
// The array of metaboxes to remove
private $metaboxes = array();
// The current option to be set
private $current_option = '';
// The current metabox to be removed
private $current_metabox = '';
// Set Genesis Theme Options with array
public function set_options( $these_options ) {
if( !is_array( $these_options ) )
return;
$this->options = $these_options;
foreach( $this->options as $option => $value ) {
$this->current_option = $option;
add_filter( "genesis_pre_get_option_{$option}", array( $this, $option ), 10, 1 );
}
}
//Override Theme Option with new value using the magic call method
public function __call( $func, $params ) {
if( in_array( $func, $this->options ) ) {
return $this->get_value( $func );
} else {
return $params;
}
}
// Get the option's new value
private function get_value( $option ) {
if( array_key_exists( $option, $this->options ) ) {
return $this->options[ $option ];
} else {
return null;
}
}
// Remove a group of metaboxes
public function remove_metaboxes( $metaboxes ) {
if( !is_array( $metaboxes ) )
return;
// Set metaboxes
$this->metaboxes = $metaboxes;
// Add action
add_action( 'genesis_theme_settings_metaboxes', array( $this, 'remove_genesis_metaboxes' ) );
}
// Remove genesis theme settings metaboxes
public function remove_genesis_metaboxes( $_genesis_theme_settings_pagehook ) {
foreach( $this->metaboxes as $metabox ) {
remove_meta_box( "genesis-theme-settings-{$metabox}", $_genesis_theme_settings_pagehook, 'main' );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment