Skip to content

Instantly share code, notes, and snippets.

@robincornett
Last active August 8, 2017 17:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robincornett/d7b60bef5004cd8b3dc43dae604ffd66 to your computer and use it in GitHub Desktop.
Save robincornett/d7b60bef5004cd8b3dc43dae604ffd66 to your computer and use it in GitHub Desktop.
Add an SMS button to Scriptless Social Sharing
<?php
add_filter( 'kses_allowed_protocols', 'prefix_allow_sms' );
/**
* Add sms to the list of allowed URL protocols in WordPress.
* @param $protocols
*
* @return array
*/
function prefix_allow_sms( $protocols ) {
$protocols[] = 'sms';
return $protocols;
}
add_filter( 'scriptlesssocialsharing_sms_url', 'prefix_add_sms', 10, 3 );
/**
* Create the URL for the SMS sharing button.
* @param $url
* @param $button
* @param $attributes
*
* @return string
*/
function prefix_add_sms( $url, $button, $attributes ) {
return sprintf( 'sms:?&body=%s %s %s', $attributes['email_subject'], $attributes['title'], $attributes['permalink'] );
}
add_filter( 'scriptlesssocialsharing_networks', 'prefix_scriptless_networks' );
/**
* Add SMS to settings/allowed sharing buttons
* @param $networks
*
* @return mixed
*/
function prefix_scriptless_networks( $networks ) {
$networks['sms'] = array(
'name' => 'sms',
'label' => __( 'SMS', 'scriptless-social-sharing' ),
'icon' => 'f27b',
'color' => '#009933',
);
return $networks;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment