Skip to content

Commit

Permalink
remove duplicate and unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
timelsass committed Mar 20, 2019
1 parent e66a6ee commit 16675ca
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 193 deletions.
82 changes: 4 additions & 78 deletions src/includes/class-boldgrid-framework-activate.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,52 +39,18 @@ class Boldgrid_Framework_Activate {
*/
public function __construct( $configs ) {
$this->configs = $configs;
$this->widgets = new Boldgrid_Framework_Widgets( $this->configs );
$this->menus = new Boldgrid_Framework_Menu( $this->configs );
$this->scss = new Boldgrid_Framework_SCSS( $this->configs );
$this->color = new Boldgrid_Framework_Customizer_Colors( $this->configs );
}

/**
* Reset The Boldgrid Theme Framework
* Removing any menu locations and widget locations
*
* @since 1.0.0
*/
public function reset() {
$this->menus->reset_nav_locations();

// Delete Option indicating that the framework needs to be setup.
delete_option( 'boldgrid_framework_init' );

// Do action for 3rd party.
do_action( 'boldgrid_theme_reset' );
}

/**
* Activate Boldgrid theme framework
*
* @since 1.0.0
*/
public function do_activate() {
if ( $this->menus->is_user_child() ) {
return;
}

// Before running the activation, run deactivate just to be sure.
$this->reset();

$this->widgets->empty_widget_areas();

// Then update the menu_check option to make sure this code only runs once.
update_option( 'boldgrid_framework_init', true );

// Set Color Palettes.
$option = 'theme_mods_' . get_stylesheet();
$this->set_palette( $option );

// Do action for 3rd party.
do_action( 'boldgrid_theme_activate' );
}

/**
Expand Down Expand Up @@ -191,7 +157,8 @@ public function tgm_override( $configs ) {
* @return array $configs BGTFW Configs.
*/
public function remove_recommended_plugin( $configs, $disabled_plugin_name ) {
$plugins = array();
$plugins = [];

foreach ( $configs['tgm']['plugins'] as $plugin ) {
if ( $disabled_plugin_name !== $plugin['slug'] ) {
$plugins[] = $plugin;
Expand All @@ -206,50 +173,9 @@ public function remove_recommended_plugin( $configs, $disabled_plugin_name ) {
/**
* Register the required plugins for this theme.
*
* In this example, we register five plugins:
* - one included with the TGMPA library
* - two from an external source, one from an arbitrary source, one from a GitHub repository
* - two from the .org repo, where one demonstrates the use of the `is_callable` argument
*
* The variables passed to the `tgmpa()` function should be:
* - an array of plugin arrays;
* - optionally a configuration array.
* If you are not changing anything in the configuration array, you can remove the array and remove the
* variable from the function call: `tgmpa( $plugins );`.
* In that case, the TGMPA default settings will be used.
*
* This function is hooked into `tgmpa_register`, which is fired on the WP `init` action on priority 10.
* @since 1.5.4
*/
public function register_required_plugins() {

/**
* Whether or not to register our configured tgmpa plugins.
*
* The theme may configure a set of base plugins (in tgm.config.php), and our starter content
* may configure an additional set of plugins (specific to that starter content).
*
* The main purpose of this filter is to prevent issues in which the theme and the starter
* content both configure the same plugins.
*
* For example, if the theme is requiring p&pb(version 1.7, stable, from the repo), yet the
* starter cotnent is requiring p&pb(version 1.8, rc, from external URL), the plugins from
* the starter content should take precedence from the plugins reuqired for the theme only.
*
* @since 2.0.0
*/
$register = apply_filters( 'bgtfw_register_tgmpa', true );

if ( $register ) {
tgmpa( $this->configs['tgm']['plugins'], $this->configs['tgm']['configs'] );
}
}

/**
* Perform tasks on deactivation.
*
* @since 1.5.10
*/
public function do_deactivate() {
delete_site_transient( 'bg_license_data' );
tgmpa( $this->configs['tgm']['plugins'], $this->configs['tgm']['configs'] );
}
}
57 changes: 8 additions & 49 deletions src/includes/class-boldgrid-framework-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,12 @@ public function title_container( $classes ) {
* @return array $classes Filter classes on .main element.
*/
public function title_content_container( $classes ) {
$class = 'container';
if ( 'above' === get_theme_mod( 'bgtfw_global_title_position' ) && 'full-width' === get_theme_mod( 'bgtfw_global_title_background_container' ) ) {
$classes[] = get_theme_mod( 'bgtfw_global_title_content_container' );
} else {
$classes[] = 'container';
$class = get_theme_mod( 'bgtfw_global_title_content_container' );
}

return $classes;
return array_merge( $classes, $class );
}

/**
Expand Down Expand Up @@ -245,12 +244,13 @@ public function print_tagline() {
// Retrieve blog tagline.
$blog_info = get_bloginfo( 'description' );
$display = get_theme_mod( 'bgtfw_tagline_display' ) === 'hide' ? ' screen-reader-text' : '';
$classes = 'site-description invisible';

if ( $blog_info ) {
printf( wp_kses_post( $this->configs['template']['tagline'] ), esc_attr( $this->configs['template']['tagline-classes'] . $display ), esc_html( $blog_info ) );
} else {
printf( wp_kses_post( $this->configs['template']['tagline'] ), 'site-description invisible', esc_html( $blog_info ) );
$classes = $this->configs['template']['tagline-classes'] . $display;
}

printf( wp_kses_post( $this->configs['template']['tagline'] ), esc_attr( $classes ), esc_html( $blog_info ) );
}

/**
Expand All @@ -270,31 +270,6 @@ public function print_title_tagline() {
<?php
}

/**
* Print the site's primary navigation using the Bootstrap navwalker.
*
* @since 1.0.0
*/
public function print_primary_navigation() {
if ( has_nav_menu( 'primary' ) ) { ?>
<nav id="site-navigation" class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#primary-navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div><!-- .navbar-header -->
<?php do_action( 'boldgrid_menu_primary' ); ?>
<?php if ( true === $this->configs['template']['navbar-search-form'] ) : ?>
<?php get_template_part( 'templates/header/search' ); ?>
<?php endif; ?>
</nav><!-- #site-navigation -->
<?php
}
}

/**
* Print the site's primary navigation using the native WordPress navwalker.
*
Expand All @@ -306,7 +281,7 @@ public function print_menu() {
<!-- Mobile toggle -->
<input id="main-menu-state" type="checkbox" />
<label class="main-menu-btn" for="main-menu-state">
<span class="main-menu-btn-icon"></span><span class="sr-only">Toggle main menu visibility</span>
<span class="main-menu-btn-icon"></span><span class="sr-only"><?php esc_html_e( 'Toggle main menu visibility', 'bgtfw' ); ?></span>
</label>
<?php wp_nav_menu( array( 'theme_location' => 'primary', 'container' => 'false', 'menu_id' => 'main-menu', 'menu_class' => 'sm bgtfw-menu main-menu' ) ); ?>
</div>
Expand Down Expand Up @@ -351,22 +326,6 @@ public function navi_classes( $classes ) {
return $classes;
}

/**
* Adds custom classes to the array of inner header classes.
*
* @since 2.0.0
*
* @return array $classes array of classes to be applied to the #masthead element.
*/
public function inner_header_classes( $classes ) {
$classes = array_merge(
$classes,
$this->get_background_color( 'bgtfw_header_color' )
);

return $classes;
}

/**
* Adds custom classes to the array of footer classes.
*
Expand Down
33 changes: 0 additions & 33 deletions src/includes/class-boldgrid-framework-menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,6 @@ public function __construct( $configs ) {
$this->configs = $configs;
}

/**
* Reset Menu Locations.
*
* @since 1.0.0
*/
public function reset_nav_locations() {
$locations = get_theme_mod( 'nav_menu_locations', array() );
foreach ( $locations as $location_name => $menu_id ) {
if ( 'primary' !== $location_name ) {
$locations[ $location_name ] = 0;
}
}
set_theme_mod( 'nav_menu_locations', $locations );
}

/**
* Disable Advanced Nav Options.
*
Expand Down Expand Up @@ -391,22 +376,4 @@ public function is_user_child() {
$is_user_child = is_child_theme() && $parent_stylesheet_name !== $parent_name;
return $is_user_child;
}

/**
* Copy over menu locations to child theme
*
* @param array $old Old menus in theme.
* @param string $new New menus in theme.
* @since 1.0.0
*/
public function transfer_menus( $old, $new = null ) {
if ( $this->is_user_child() && $new ) {
$old_theme_mods = get_option( 'theme_mods_' . $new->get_stylesheet() );
$old_locations = ! empty( $old_theme_mods['nav_menu_locations'] ) ? $old_theme_mods['nav_menu_locations'] : null;

if ( $old_locations ) {
set_theme_mod( 'nav_menu_locations', $old_locations );
}
}
}
}
29 changes: 0 additions & 29 deletions src/includes/class-boldgrid-framework-widgets.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,41 +44,12 @@ public function __construct( $configs ) {
$this->configs = $configs;
}

/**
* Clear all Widget areas
*
* @since 1.0.0
*/
public function empty_widget_areas() {
$auto_created = $this->configs['widget']['sidebars'];
$all_widgets = get_option( 'sidebars_widgets' );

foreach ( $all_widgets as $key => $widget ) {
if ( ! empty( $auto_created[ $key ] ) ) {
$all_widgets[ $key ] = array();
}
}

/**
* The call to update_option returns true / false based on the success of the update.
* The call will fail if:
* 1. The first parameter, 'sidebars_widgets', is empty (which will never be).
* 2. The old value == the new value.
* 3. The SQL failed to update the database.
* In an obscure bug, the call below is failing because of scenario #2 above.
* Below, we'll try to fix this by emptying the value before setting it.
*/
update_option( 'sidebars_widgets', array() );
update_option( 'sidebars_widgets', $all_widgets );
}

/**
* Create sidebars based on config file
*
* @since 1.0.0
*/
public function create_config_widgets() {

foreach ( $this->configs['widget']['sidebars'] as $config ) {
register_sidebar( $config );
}
Expand Down
5 changes: 1 addition & 4 deletions src/includes/class-boldgrid-framework.php
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,8 @@ private function define_theme_hooks() {

$this->loader->add_filter( 'bgtfw_entry_header_classes', $boldgrid_theme, 'entry_header_classes' );
$this->loader->add_filter( 'bgtfw_header_classes', $boldgrid_theme, 'header_classes' );
$this->loader->add_filter( 'bgtfw_navi_wrap_classes', $boldgrid_theme, 'header_classes' );
$this->loader->add_filter( 'bgtfw_footer_classes', $boldgrid_theme, 'footer_classes' );
$this->loader->add_filter( 'bgtfw_navi_wrap_classes', $boldgrid_theme, 'inner_header_classes' );
$this->loader->add_filter( 'bgtfw_navi_classes', $boldgrid_theme, 'navi_classes' );
$this->loader->add_filter( 'bgtfw_footer_content_classes', $boldgrid_theme, 'inner_footer_classes' );
$this->loader->add_filter( 'bgtfw_main_wrapper_classes', $boldgrid_theme, 'blog_container' );
Expand All @@ -417,7 +417,6 @@ private function define_theme_hooks() {
$this->loader->add_filter( 'boldgrid_print_tagline', $boldgrid_theme, 'print_tagline' );
$this->loader->add_filter( 'boldgrid_site_title', $boldgrid_theme, 'site_title' );
$this->loader->add_filter( 'boldgrid_site_identity', $boldgrid_theme, 'print_title_tagline' );
$this->loader->add_filter( 'boldgrid_primary_navigation', $boldgrid_theme, 'print_primary_navigation' );
$this->loader->add_filter( 'boldgrid_print_menu', $boldgrid_theme, 'print_menu' );

// Sticky Header
Expand Down Expand Up @@ -474,7 +473,6 @@ private function setup_menus() {

if ( ! $this->doing_cron ) {
$this->loader->add_action( 'after_switch_theme', $menu, 'disable_advanced_nav_options' );
$this->loader->add_action( 'after_switch_theme', $menu, 'transfer_menus', 10, 2 );
}
}

Expand Down Expand Up @@ -526,7 +524,6 @@ private function define_admin_hooks() {

if ( ! $this->doing_cron ) {
$this->loader->add_action( 'after_switch_theme', $activate, 'do_activate' );
$this->loader->add_action( 'switch_theme', $activate, 'do_deactivate' );
}

// Stop WordPress from assigning widgets to our areas.
Expand Down

0 comments on commit 16675ca

Please sign in to comment.