-
-
Save robincornett/d7b60bef5004cd8b3dc43dae604ffd66 to your computer and use it in GitHub Desktop.
Add an SMS button to Scriptless Social Sharing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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