Available Actions/Filters

Actions

socialize_settings_tabs - Called after admin tabs are generated

Filters

socialize_settings_tabs_array - Add new tabs to the Socialize settings page

Example:

  
    function new_tab($tabs) {
        $tabs['my-new-tab'] = array(
            'title' => 'My New tab',
            'function' => 'my_new_tab_callback'
        );
        return $tabs;
    }

socialize-sort_buttons_array – Modify services array before sorting

socialize-footerjs – Modify services javascript array before passing to wp_print_scripts()

socialize-short_url –  Modify short_url returned by get_short_url()

socialize-get_bitly_short_url – Modify bitly url returned by get_bitly_short_url()

socialize-get_services – Modify services array used throughout Socialize

socialize-get_button_array – Modify services array returned by get_button_array()

socialize-{service_name} – Modify output of specific service

Adding New Buttons

add_filter('socialize-get_services', 'my_socialize_button');

function my_socialize_button($socialize_array){
    $new_button = array(
        'My Button' => array(
                'inline' => 100,
                'action' => 101, 
                'callback' => 'createMyButton'
            )
    );
    $socialize_array = array_merge($socialize_array, $new_button);
    return $socialize_array;
}

function createMyButton(){
    return 'This is my custom button code';
}

Note: The inline and action numbers are arbitrary however cannot clash with built in number. It’s safest to use number greater than 100.

Modifying Existing Buttons

The following code replaces the default Socialize buttons with their asynchronous alternatives

// Add custom javascript
add_action('wp', 'socialize_custom');

function socialize_custom(){
    add_action('wp_footer', 'socialize_custom_js');
}

// Add asynchronous loading code
function socialize_custom_js() {
    ?>
    
    Tweet';
    return $buttonContent;
}

// Replace Facebook button
add_filter('socialize-facebook', 'filter_socialize_facebook');

function filter_socialize_facebook($content) {
    $socialize_settings = array();
    $socialize_settings = get_option('socialize_settings10');
    $buttonContent = '
'; return $buttonContent; } // Remove default Socialize javascript add_filter('socialize-footerjs', 'remove_footerjs'); function remove_footerjs($content) { return array(); }
0saves
Leave a comment below and continue the conversation, or subscribe to my RSS feed to get articles like this delivered automatically to your feed reader.

  • http://twitter.com/jordantrizz Jordan

    I’ve tried using the example code to replace the twitter button. And all the buttons are affected, instead of just twitter.

    I’m using shortcodes.

  • http://www.markflint.net Mark Flint


    // function to add a default image for Pinterests where no thumbnail/featured image exists
    function addDefaultPinterestImage($socialize_array) {
    // $socialize_array in this case is actually a string
    $str = $socialize_array;
    $scheme = ( !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? 'https://' : 'http://';
    $media = '&media=' . urlencode($scheme . $_SERVER['SERVER_NAME'] . '/wp-content/themes/cbc/images/logo.png');
    $href_onward = substr($str,strpos($str,'href="')+6);
    $href = substr($href_onward,0,strpos($href_onward,'"'));
    return str_replace($href,$href.$media,$str);
    }
    add_filter('socialize-pinterest','addDefaultPinterestImage');

    • http://twitter.com/NoahsDadDotCom Noah’s Dad

      Mark, thanks for sharing this. Is there any way to set this up where you can share on pintrest and scroll through the various images in a post and someone can share the ones they want?

    • Mark Flint

      This function is meant for specifying a fixed path to an image to be used as the default in case no suitable image was found. I suppose you could use this function by offer a modal window (triggered off the pinterest button) with thumbnails to the user and overwrite the file (ajax) at the fixed location with their choice. Not simply adding an extra line of code :-)

    • http://twitter.com/NoahsDadDotCom Noah’s Dad

      @d4c2da403776a75749d471aa31652bc6:disqus Mark, thanks for sharing this. Is there any way to set this up where you can share on pintrest and scroll through the various images in a post and someone can share the ones they want?