• alvaro05

    (@alvaro05)


    I want to set the Default values in my theme for the different fonts.
    After investigating very much and thanks to the help Sunny provided I came up with:

    function aaa_egf_default_controls($options) {
    
    	// Here's how to remove some default controls
    	unset($options['tt_default_body']);
    	unset($options['tt_default_heading_1']);
    	unset($options['tt_default_heading_2']);
    	unset($options['tt_default_heading_3']);
    	unset($options['tt_default_heading_4']);
    	unset($options['tt_default_heading_5']);
    	unset($options['tt_default_heading_6']);
    
    	$options['post_text_full'] = array(
    		'name' => 'post_text_full',
    		'title' => __('Post content', 'easy-google-fonts'),
    		'description' => __("Edit Font", 'easy-google-fonts'),
    		'tab' => 'full',// I created a section for this
    		'properties' => array(
    			'selector' => 'body',
    		),
    		'default' => array(
    			'subset' => 'latin,all',
    			'font_id' => 'roboto',
    			'font_name' => 'Roboto',
    			'font_color' => '#333333',
    			'font_weight' => '300',
    			'font_style' => '',
    			// 'font_weight_style'   => '',
    			'background_color' => '',
    			'stylesheet_url' => 'https://fonts.googleapis.com/css?family=Roboto',
    			// 'text_decoration'     => '',
    			'text_transform' => 'none',
    			'line_height' => '1.4',
    			'font_size' => array(
    				'amount' => '15',
    				'unit' => 'px',
    			),
    		),
    	);	return $options;
    }
    add_filter('tt_font_get_option_parameters', 'aaa_egf_default_controls');

    I realized although this set the theme default value, when returning values, most of them were empty. So after searching within the files of the plugin I found out
    validate_settings() function has a $whitelist array that removes the mentioned values.

    How can I overpass this array from outside of the plugin so my Default values dont dissapear?

    https://www.ads-software.com/plugins/easy-google-fonts/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Sunny Johal

    (@sunny_johal)

    Hi Alvaro,
    It’s not a good idea to try to bypass that function as it sanitises the values before saving them to the database for security.

    Can you describe exactly what you are trying to do (every detail e.g. The selector, font, font weight etc) and I’ll give you a hand when I get a moment. Cheers

    Sunny

    Thread Starter alvaro05

    (@alvaro05)

    Thanks Sunny, I would really appreciate some help here as Im becoming a little bit crazy with this.

    function aaa_egf_default_controls($options) {
    
    	unset($options['tt_default_body']);
    	unset($options['tt_default_heading_1']);
    	unset($options['tt_default_heading_2']);
    	unset($options['tt_default_heading_3']);
    	unset($options['tt_default_heading_4']);
    	unset($options['tt_default_heading_5']);
    	unset($options['tt_default_heading_6']);
    
    	$options['example'] = array(
    		'name' => 'example',
    		'title' => __('Post content', 'easy-google-fonts'),
    		'description' => __("Edit Font", 'easy-google-fonts'),
    		'properties' => array(
    			'selector' => 'body',
    		),
    		'default' => array(
    			'subset' => 'latin,all',
    			'font_id' => 'lobster',
    			'font_name' => 'Lobster',
    			'font_color' => '#333333',
    			'font_weight' => '300',
    			'font_style' => '',
    			'font_weight_style'   => '',
    			'background_color' => '',
    			'stylesheet_url' => 'https://fonts.googleapis.com/css?family=Lobster',
    			'text_decoration'     => '',
    			'text_transform' => 'none',
    			'line_height' => '1.4',
    			'font_size' => array(
    				'amount' => '15',
    				'unit' => 'px',
    			),
    		),
    	);	return $options;
    }
    add_filter('tt_font_get_option_parameters', 'aaa_egf_default_controls');

    I want to add default settings to my theme so:
    1.When the user activates the theme and then the plugin, those default settings apply.
    2.When the user goes to the theme customizer and selects Theme Default as font, those default values apply.

    Right now, when I add the code mentioned above,
    1. This works perfect.
    2.Maybe I am missunderstanding the scope of this snippet I added. I expected this default settings would apply (the same way as in 1.) when I selected “Theme Default” setting as font. However when selecting it, nothing is happening, the fonts is not loading and the selector is not applying.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Theme Default settings not saving’ is closed to new replies.