Skip to content

Instantly share code, notes, and snippets.

@ashleyfae
Last active May 6, 2022 11:41
Show Gist options
  • Save ashleyfae/73e950885fdbbecb20fe to your computer and use it in GitHub Desktop.
Save ashleyfae/73e950885fdbbecb20fe to your computer and use it in GitHub Desktop.
<?php
/**
* Plugin Name: Naked Social Share Add-On
* Plugin URI: https://www.nosegraze.com
* Description: Demonstrates how to add an extra social site to Naked Social Share.
* Version: 1.2
* Author: Nose Graze
* Author URI: https://www.nosegraze.com
* License: GPL2
*
* @package nss-addon
* @copyright Copyright (c) 2022, Nose Graze Ltd.
* @license GPL2+
*/
/**
* Add 'Email' as a new social media site.
*
* @param array $sites Available sites.
*
* @return array
*/
function nss_addon_add_email( $sites ) {
$sites['email'] = __( 'Email' );
return $sites;
}
add_filter( 'naked-social-share/available-sites', 'nss_addon_add_email' );
/**
* Display the Email Button
*
* If you want to display a share counter, you need to code the function for
* fetching the share count.
*
* @param string $site_name Array key of the site being displayed.
* @param array $share_numbers Array of share numbers for all social sites.
* @param WP_Post $post Object for current post.
* @param bool $disable_counters
*
* @return void
*/
function nss_addon_display_email( $site_name, $share_numbers, $post, $disable_counters ) {
// Bail if the site name isn't 'email'.
if ( $site_name != 'email' ) {
return;
}
?>
<li class="nss-email">
<a href="mailto:?subject=<?php echo esc_attr( urlencode( $post->post_title ) ); ?>&body=<?php echo esc_url( get_permalink( $post ) ); ?>" target="_blank">
<i class="fa fa-envelope"></i>
<span class="nss-site-name"><?php _e( 'Email' ); ?></span>
<?php if ( $disable_counters == false ) : ?>
<span class="nss-site-count"><!-- Share count here --></span>
<?php endif; ?>
</a>
</li>
<?php
}
add_action( 'naked_social_share_display_buttons', 'nss_addon_display_email', 10, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment