How to fix a "globals" issue to avoid a soft rejected theme?

wordpress

#1

Hi,
I submit a WordPress theme for Themeforest and one of the reasons for rejection was as follows:

Globals should always be within a function or a class and should be used restrictively & only if theme really needs to. It’s highly recommended not to use them at all just to keep things out of the global namespace, they’re poor coding practice.

Im using Smof Option Framework for ttheme options and here is a sample code from one of my theme files:

global $smof_data;
$td_header_manager_wide = $smof_data['td_header_blocks']['enabled'];

if ( $td_header_manager_wide ) {

        foreach ( $td_header_manager_wide as $key=>$value ) {

            switch( $key ) {

                case 'block_main_menu_wide': // wide menu
                echo '<div id="td-sticky" class="wide-menu ' . $td_sticky . '">';
                echo '<div id="wide-menu">';
                include( get_template_directory() . '/parts/menu-header-logo.php');
                echo '</div>';
                echo '</div>';
                break;
  }
}

It seems that global $smof_data; should be within a function but I’m really lost here how to accomplish this task to avoid include global $smof_data; in all of my theme files where I need it.

Any help will be greatly appreciated.
Thanks.


#2

I’ve this issue. If you have solution please tell me. thanks


#3

Did anyone found the solution? changing this throughout the theme means re-writing the whole theme… how come it is allowed in most popular themes today…