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 theme 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.
Update code using @jgraup method:
function matilda_customize_styles() {
$css = '<style type="text/css" media="screen">';
if ( ! empty( SMOFData::get( 'td_body_font_family' ) )
&& SMOFData::get( 'td_body_font_family' ) != 'none' )
{
$css .= 'body{font-family:' . esc_html( SMOFData::get( 'td_body_font_family' ) ) . ';}';
}
}
Any help will be greatly appreciated. Thanks.