Overview
social_warfare( [ array $arguments ] )
This function creates and outputs the fully-formatted HTML for a panel of social sharing buttons.
By default, it will output the buttons in accordance with the settings on the Social Warfare options page in the WordPress admin. However, the function accepts an optional array of arguments that can be used to override many of the default settings.
Parameters
arguments: An array of arguments that control the visual and behavioral settings of the buttons panel. The table below outlines the available arguments that can be passed in to the function.
Argument | Description | Accepted Values |
id | (integer) The ID of the post, page, or custom post type that this set of buttons should reflect. | Any valid post ID. Example: 247 |
buttons | (string) A comma separated list of snake_cased social network names. Total Shares: If you pass in the ‘buttons’ argument, the total share counts will not be displayed unless you include the ‘totals’ in the argument. | Core: google_plus, twitter, facebook, pinterest, linkedin, totals Pro: reddit, yummly, hacker_news, flipboard, whatsapp, pocket, tumblr, buffer, email |
network_shares | (bool) Controls whether or not share counts are shown on individual buttons. | true/false |
button_size* | (decimal) This determines the size of the buttons. It accepts a number with 1 decimal place between 0.7 and 1.4. This will override the global setting found on the options page at Styles -> Visual Options -> Button Size | 0.7, 0.8, 0.9, 1, 1.1, 1.2, 1.3, 1.4 |
button_shape* | (string) This determines the shape of the buttons. This will override the global setting found on the options page at Styles -> Visual Options -> Button Shape | flat_fresh, leaf, shift, pill, three_dee, connected |
default_colors* | (string) This is the color set to use on the buttons when they are not being interacted with. This will override the global setting found on the options page at Styles -> Visual Options -> Default Color Set | full_color, light_gray, medium_gray, dark_gray, light_gray_outlines, medium_gray_outlines, dark_gray_outlines, color_outlines |
hover_colors* | (string) This is the color set to use for all of the buttons in the panel when the panel is being hovered. This will override the global setting found on the options page at Styles -> Visual Options -> Hover Color Set | full_color, light_gray, medium_gray, dark_gray, light_gray_outlines, medium_gray_outlines, dark_gray_outlines, color_outlines |
single_colors* | (string) This is the color set to use for the specific button being hovered in the panel. This will override the global setting found on the options page at Styles -> Visual Options -> Single Button Hover | full_color, light_gray, medium_gray, dark_gray, light_gray_outlines, medium_gray_outlines, dark_gray_outlines, color_outlines |
*These attributes are only available if you have Social Warfare – Pro.
Shortcodes
The Social Warfare shortcode works exactly like this function. In fact, all attributes attached to the shortcode get converted into an array of arguments during processing and then passed into this function. This means that any argument you see in the list above can also be used in the shortcode.
For an example of how to use these arguments in a shortcode, just check out the “Code Samples” section below.
Best Practices
Important Note #1: You should always ensure that a function like this exists prior to calling it. This way if you uninstall or deactivate the plugin, and therefore the function goes away, this will prevent it from throwing “call to undefined function” errors in the PHP.
if( function_exists( 'social_warfare' ) ) {
social_warfare();
}
Important Note #2: The team at Social Warfare highly recommend that any changes made to your theme be added in the form of a Child Theme. This will allow you to preserve your edits after updating the parent theme.
Code Samples
If you want a set of buttons without any modifications, simply call the social_warfare() function directly like so:
social_warfare();
If you want to modify the output of the buttons panel using any of the arguments listed above, simply create an array of arguments and pass that into the function like so:
$args = array(
'buttons' => 'google_plus,facebook,twitter,totals',
'id' => 42
);
social_warfare( $args );
And, of course, if you want to use these advanced arguments via the shortcode, it’s as easy as this:
[social_warfare id="42" buttons="twitter,facebook,totals"]