Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
cornerstone/inc/reg-sidebars.php
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
161 lines (142 sloc)
5.89 KB
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 | |
/** | |
* Register widget area. | |
* | |
* @link http://codex.wordpress.org/Function_Reference/register_sidebar | |
*/ | |
if ( function_exists('register_sidebar') ) { | |
$sidebars = get_option( 'uc_sidebars' ); | |
if(!isset($sidebars['mega-footer'])){ | |
$sidebars['mega-footer'] = array( | |
'name' => __( 'Mega Footer', 'theme_text_domain' ), | |
'description' => 'Limited to 6 widgets. Will appear at the bottom of every page in the site.', | |
'before_widget' => '<aside class=""><div id="%1$s" class="%2$s widget">', | |
'after_widget' => ' </div></aside>', | |
'before_title' => '<div class="widget-head"><h2 class="widget-title">', | |
'after_title' => '</h2></div>', | |
'pages' => array(), | |
'children' => 'off', | |
'force' => true | |
); | |
update_option('uc_sidebars',$sidebars); | |
$sidebars['mega-footer']['id'] = 'mega-footer'; | |
register_sidebar($sidebars['mega-footer']); | |
} | |
if(!isset($sidebars['sidebar'])){ | |
$sidebars['sidebar'] = array( | |
'name' => __( 'Default Sidebar', 'theme_text_domain' ), | |
'description' => 'Appears with Archives, Search Results, the Blog page template, and when viewing single posts.', | |
'class' => 'sidebar', | |
'before_widget' => '<aside id="%1$s" class="widget %2$s">', | |
'after_widget' => '</aside>', | |
'before_title' => '<div class="widget-head"><h2 class="widget-title">', | |
'after_title' => '</h2></div>', | |
'pages' => array(), | |
'children' => 'off', | |
'force' => true | |
); | |
update_option('uc_sidebars',$sidebars); | |
$sidebars['sidebar']['id'] = 'sidebar'; | |
register_sidebar($sidebars['sidebar']); | |
} | |
register_sidebar(array( | |
'name' => __( 'Header Content', 'theme_text_domain' ), | |
'id' => 'header-widget-area', | |
'description' => 'Widget area for header, limited to 2 widgets. Max height: 76px. For more information view our header widget area guide', | |
'class' => 'sidebar', | |
'before_widget' => '<aside id="%1$s" class="widget %2$s">', | |
'after_widget' => '</aside>', | |
'before_title' => '<div class="widget-head"><h2 class="widget-title">', | |
'after_title' => '</h2></div>' | |
)); | |
/*register_sidebar( array( | |
'name' => __( 'Mega Footer' ), | |
'id' => 'mega-footer', | |
'description' => 'Limited to 6 widgets. Will appear at the bottom of every page in the site.', | |
'before_widget' => '<aside id="%1$s" class="widget %2$s">', | |
'after_widget' => '</aside>', | |
'before_title' => '<div class="widget-head"><h2 class="widget-title">', | |
'after_title' => '</h2></div>' | |
) );*/ | |
for($i=1; $i<=30; $i++){ | |
$sidebars['home'.$i] = array( | |
'name' => __( 'Home '.$i, 'theme_text_domain' ), | |
'class' => 'sidebar', | |
'before_widget' => '<aside id="%1$s" class="widget %2$s">', | |
'after_widget' => '</aside>', | |
'before_title' => '<div class="widget-head"><h2 class="widget-title">', | |
'after_title' => '</h2></div>', | |
'pages' => array(), | |
'children' => 'off', | |
'force' => true | |
); | |
update_option('uc_sidebars',$sidebars); | |
$sidebars['home'.$i]['id'] = 'home'.$i; | |
register_sidebar($sidebars['home'.$i]); | |
} | |
} | |
/** | |
* Add the options page to the "Appearance" admin menu | |
* | |
* @since Unique Page Sidebars 0.1 | |
*/ | |
function uc_options_add_page() { | |
add_theme_page( 'Manage Sidebars', 'Manage Sidebars', 'edit_theme_options', 'uc_sidebars', 'uc_sidebars_do_page' ); | |
//remove_submenu_page( 'themes.php', 'widgets.php' ); | |
} | |
add_action( 'admin_menu', 'uc_options_add_page' ); | |
function remove_wp_widgets( $wp_admin_bar ) { | |
$wp_admin_bar->remove_node( 'widgets' ); | |
} | |
add_action( 'admin_bar_menu', 'remove_wp_widgets', 999 ); | |
// if no title then add widget content wrapper to before widget | |
function check_sidebar_params( $params ) { | |
global $wp_registered_widgets; | |
$settings_getter = $wp_registered_widgets[ $params[0]['widget_id'] ]['callback'][0]; | |
$settings = $settings_getter->get_settings(); | |
$settings = $settings[ $params[1]['number'] ]; | |
if ( $params[0][ 'after_widget' ] == '</div></aside>' && isset( $settings[ 'title' ] ) && empty( $settings[ 'title' ] ) ){ | |
$params[0][ 'before_widget' ] .= '<div class="widget-content ccc">'; | |
} | |
#Counts widgets in mega footer and adds column class accordingly | |
if( $params[0]['id'] == 'mega-footer' ){ | |
$sidebars = get_option('sidebars_widgets'); | |
$widgets = $sidebars['mega-footer']; | |
$count = count($widgets); | |
if( $count > 6 ){ | |
$cols = 2; | |
} else { | |
$cols = floor(12 / $count); | |
} | |
$params[0]['before_widget'] = str_replace('aside class="', 'aside class="col-sm-' . $cols . ' ', $params[0]['before_widget']); | |
} | |
return $params; | |
} | |
add_filter( 'dynamic_sidebar_params', 'check_sidebar_params' ); | |
function mf_remove_extra( $sidebars_widgets ){ | |
$widgets = $sidebars_widgets['mega-footer']; | |
if( is_array($sidebars_widgets['mega-footer']) ){ | |
foreach ($sidebars_widgets['mega-footer'] as $i => $widget) { | |
if( $i > 5 ){ | |
unset($sidebars_widgets['mega-footer'][$i]); | |
} | |
} | |
} | |
return $sidebars_widgets; | |
} | |
add_filter( 'sidebars_widgets', 'mf_remove_extra' ); | |
function custom_searchform($form){ | |
global $search_counter; | |
if( !$search_counter ){ | |
$search_counter = 0; | |
} | |
$search_counter++; | |
$form = '<div class="searchform"><form action="'.home_url( '/' ).'" method="get" class="form-inline" role="form"><div class="form-group"><fieldset><legend class="sr-only">Search this Site</legend>'; | |
$form .= '<label for="searchfield-'.$search_counter.'" class="sr-only">Search in '.home_url( '/' ).'></label>'; | |
$form .= '<input type="text" name="s" id="searchfield-'.$search_counter.'" value="'.get_search_query().'" class="form-control search" title="Search this site... " placeholder="Search this site... " />'; | |
$form .= '<button type="submit" class="btn btn-default" title="Search"><i class="glyphicon glyphicon-search"></i><span class="sr-only">Search</span></button>'; | |
$form .= '</fieldset></div></form></div>'; | |
return $form; | |
} | |
add_filter('get_search_form', 'custom_searchform'); | |
?> |