• Resolved dberdal

    (@dberdal)


    Hi Robin, thanks for a great plugin! I use wordpress multisite, and although your default settings are pretty close to what I’d want, there are a few settings that I’d like to modify across my network.

    add_filter('scriptlesssocialsharing_get_setting','scriptless_custom_settings',20,2);
    function scriptless_custom_settings($key){
    	if( array_key_exists('button_style',$key)){
    
    		$key['button_style'] = 0;
    		$key['heading'] = 'updated heading';
    
    		return $key;
    	}
    
    }

    The filter does appear to change the settings, including updating the header, however for some reason when I use the filter the SVG icons stop working.

    Here is the HTML from one of the buttons

    <a class="button linkedin" target="_blank" href="...removed..." rel="noopener noreferrer nofollow"><svg class="scriptlesssocialsharing__icon linkedin" role="img" aria-hidden="true"> <use href="#linkedin" xlink:href="#linkedin"></use> </svg><span class="screen-reader-text">LinkedIn</span></a>

    Any ideas why that filter might stop SVG output? Is there a different filter I should be using?

    • This topic was modified 4 years, 4 months ago by dberdal.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Robin Cornett

    (@littlerchicken)

    Your filter is not always returning a value, which is one issue (the return statement is inside the conditional). You’ve also told the code you are passing two parameters, but there is only one.

    I think if you update your code like this:

    
    add_filter( 'scriptlesssocialsharing_get_setting', 'scriptless_custom_settings', 20 );
    function scriptless_custom_settings( $key ) {
    	if ( is_array( $key ) && array_key_exists( 'button_style', $key ) ) {
    		$key['button_style'] = 0;
    		$key['heading']      = 'updated heading';
    	}
    
    	return $key;
    }
    

    It should work (it is working locally for me, but you will want to test). The code will always return something, even if it hasn’t been modified, and it adds a check to make sure that the variable is an array before checking for the array key. Hope that helps get you started!

    Thread Starter dberdal

    (@dberdal)

    Hi Robin,

    Thank you so much – yes those two errors of mine were enough to cause problems, and your adjusted code above worked perfectly.

    Do you have a donate link anywhere?

    P.S. for any future people, here is the array of plugin settings included in $key for version 3.1.5

    [styles] => Array
            (
                [plugin] => 1
                [font] => 0
            )
    
        [icons] => svg
        [heading] => Share this post:
        [buttons] => Array
            (
                [twitter] => 1
                [facebook] => 1
                [pinterest] => 1
                [linkedin] => 1
                [email] => 1
                [reddit] => 0
                [whatsapp] => 0
                [pocket] => 0
                [telegram] => 0
                [sms] => 0
            )
    
        [twitter_handle] => 
        [email_subject] => A post worth sharing:
        [email_body] => I read this post and wanted to share it with you. Here's the link:
        [post_types] => Array
            (
                [post] => Array
                    (
                        [before] => 0
                        [after] => 1
                        [manual] => 0
                    )
    
                [page] => Array
                    (
                        [before] => 0
                        [after] => 0
                        [manual] => 0
                    )
    
                [popup] => Array
                    (
                        [before] => 0
                        [after] => 0
                        [manual] => 0
                    )
    
                [product] => Array
                    (
                        [before] => 0
                        [after] => 0
                        [manual] => 0
                    )
    
            )
    
        [location] => 
        [button_style] => 1
        [button_padding] => 12
        [table_width] => full
        [order] => Array
            (
                [twitter] => 1
                [facebook] => 2
                [pinterest] => 3
                [linkedin] => 4
                [email] => 5
            )
    
        [genesis] => 0
        [css_style] => flex
        [disable_block] => 0
    )
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Using filter for all plugin settings’ is closed to new replies.