Created
January 30, 2019 20:31
-
-
Save robincornett/ba47e41fa26ae5d44863862666540278 to your computer and use it in GitHub Desktop.
Sample code to add Facebook Messenger as a sharing button to Scriptless Social Sharing.
This file contains hidden or 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_messenger' ); | |
/** | |
* Add Facebook Messenger to the list of allowed URL protocols in WordPress. | |
* | |
* @param $protocols | |
* | |
* @return array | |
*/ | |
function prefix_allow_sms( $protocols ) { | |
$protocols[] = 'fb-messenger'; | |
return $protocols; | |
} | |
add_filter( 'scriptlesssocialsharing_messenger_url', 'prefix_add_fb_messenger', 10, 3 ); | |
/** | |
* Add SMS to settings/allowed sharing buttons | |
* | |
* @param $url | |
* @param $button | |
* @param $attributes | |
* | |
* @return mixed | |
*/ | |
function prefix_add_fb_messenger( $url, $button, $attributes ) { | |
$app_id = ''; // enter your fb app ID here | |
if ( ! $app_id ) { | |
return $url; | |
} | |
$url = add_query_arg( | |
array( | |
'link' => $attributes['permalink'], | |
'app_id' => $app_id, | |
), | |
'fb-messenger://share/' | |
); | |
return $url; | |
} | |
add_filter( 'scriptlesssocialsharing_networks', 'prefix_scriptless_networks' ); | |
/** | |
* Add FB Messenger to settings/allowed sharing buttons | |
* | |
* @param $networks | |
* | |
* @return mixed | |
*/ | |
function prefix_scriptless_networks( $networks ) { | |
$networks['messenger'] = array( | |
'name' => 'messenger', | |
'label' => __( 'Facebook Messenger', 'scriptless-social-sharing' ), | |
'icon' => 'f39f', | |
'color' => '#333', // change this to whatever color you want the button to be | |
); | |
return $networks; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment