How to fix a “globals” issue to avoid a rejected theme?

If you’re dealing with framework that holds values in a global variable then there isn’t much you can do about it. Here is an example of wrapping the variable in a static getter.

if ( ! class_exists( 'SMOFData' ) ):

    class SMOFData {

        static public function is( $key, $compare ) {
            $value = static::get( $key );
            return $value === $compare;
        }

        static public function not( $key, $compare ) {
            $value = static::get( $key );
            return $value !== $compare;
        }

        static public function has( $key ) {
            $value = static::get( $key );
            return ! empty( $value );
        }

        static public function get( $key ) {

            global $smof_data;

            if ( ! isset( $smof_data ) ) {
                return null;
            }

            return isset( $smof_data[ $key ] ) ? $smof_data[ $key ] : null;
        }

    }

endif; // SMOFData

To access the data just use

echo SMOFData::get('td_header_blocks')['enabled'];

function matilda_customize_styles() { 
    $css="<style type="text/css" media="screen">";
    $td_body_font_family = SMOFData::get( 'td_body_font_family' ); 
    if ( ! empty( $td_body_font_family ) && $td_body_font_family != 'none' ) {
        $css .= 'body{font-family:' . esc_html( $td_body_font_family ) . ';}';
    } 
}

function matilda_customize_styles() { 
    $css="<style type="text/css" media="screen">";
    if ( SMOFData::has( 'td_body_font_family' ) && SMOFData::not( 'td_body_font_family', 'none' ) ) {
            $css .= 'body{font-family:' . esc_html( SMOFData::get( 'td_body_font_family' ) ) . ';}';
    }
}

If you just want you’re own globals you can wrap that in a class as well.

if ( ! class_exists( 'ThemeData' ) ):

    class ThemeData {
        private static $_values = array ();

        static public function get( $key ) {
            return isset( static::$_values[ $key ] ) ? static::$_values[ $key ] : null;
        }

        static public function set( $key, $value ) {
            static::$_values[ $key ] = $value;
            return $value;
        }
    }
endif; // ThemeData


// setter
ThemeData::set('foo', 'bar');

// getter
echo ThemeData::get('foo');