Support » Plugin: Simple Twitter Connect » [Plugin: Simple Twitter Connect] Unable to override defaults & admin setting with function args

  • Resolved thomtels


    Using v0.15 of simple-twitter-connect. It appears imposible to use the function arguments to setup a custom twitter button if there are admin settings for the ‘source’, ‘style’ and ‘related’ options. get_stc_tweetbutton will always use the options in the admin rather than any arguments passed in via the function.

    • reproduce:
      • In the admin settings:
        • Tweet Button Position: “Manually”
        • Tweet Button Style: “Vertical”
      • In a theme template:
        • <?php stc_tweetbutton(array('style'=>'horizontal')); ?>
    • expected result:
      • A horizontally oriented tweet button
    • actual result:
      • A vertically oriented tweet button

    Below is a potential fix. I just adjusted the order of operations for the parsing of arguments such that the arguments passed in via the function args take the highest priority (assumption being that someone using this method is going to be most knowledgeable and expecting full control). The tweetbutton options start with the class default, then add in anything setup in the admin config followed finally by the function args.

    diff --git a/wp-content/plugins/simple-twitter-connect/stc-tweetbutton.php b/wp-content/plugins/simple-twitter-connect/stc-tweetbutton.php
    index 7f3addc..ede35a2 100644
    --- a/wp-content/plugins/simple-twitter-connect/stc-tweetbutton.php
    +++ b/wp-content/plugins/simple-twitter-connect/stc-tweetbutton.php
    @@ -53,16 +53,23 @@ $stc_tweetbutton_defaults = array(
     function get_stc_tweetbutton($args='') {
            global $stc_tweetbutton_defaults;
    -       $args = wp_parse_args($args, $stc_tweetbutton_defaults);
    -       extract($args);
            // fix for missing ID in some cases (some shortlink plugins don't work well with ID = zero)
            if (!$id) $id = get_the_ID();
    +       // load admin config options
            $options = get_option('stc_options');
    -       if ($options['tweetbutton_source']) $source = $options['tweetbutton_source'];
    -       if ($options['tweetbutton_style']) $style = $options['tweetbutton_style'];
    -       if ($options['tweetbutton_related']) $related = $options['tweetbutton_related'];
    +       $option_args = array();
    +       if ($options['tweetbutton_source']) $option_args['source'] = $options['tweetbutton_source'];
    +       if ($options['tweetbutton_style']) $option_args['style'] = $options['tweetbutton_style'];
    +       if ($options['tweetbutton_related']) $option_args['related'] = $options['tweetbutton_related'];
    +       // supplant defaults with admin config options
    +       $option_args = wp_parse_args($option_args, $stc_tweetbutton_defaults);
    +       // finally use any options passed in via function args
    +       $args = wp_parse_args($args, $option_args);
    +       extract($args);
            $url = wp_get_shortlink($id);
            $counturl = get_permalink($id);
            $post = get_post($id);

Viewing 1 replies (of 1 total)
  • Plugin Author Samuel Wood (Otto)

    (@otto42) Admin

    Edit: Never mind, I see the issue. I’ll put in a fix, but a slightly different one than yours. Defaults should be what’s in the admin, overriding the built in defaults.

    Thanks for the heads up! 🙂

Viewing 1 replies (of 1 total)
  • The topic ‘[Plugin: Simple Twitter Connect] Unable to override defaults & admin setting with function args’ is closed to new replies.