Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?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.1
* Author: Nose Graze
* Author URI: https://www.nosegraze.com
* License: GPL2
*
* @package nss-addon
* @copyright Copyright (c) 2016, 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' );
/**
* OLD FUNCTION
* @deprecated 1.3.0
*
* This was the old method before version 1.3.0 Please see the new method above.
*/
/*function nss_addon_add_email() {
$nss_settings = get_option( 'naked_ss__settings' );
$social_sites = $nss_settings['social_sites'];
if ( ! is_array( $social_sites ) || ! array_key_exists( 'enabled', $social_sites ) || ! array_key_exists( 'disabled', $social_sites ) ) {
return;
}
// Only add your new site if it doesn't already exist.
if ( ! array_key_exists( 'email', $social_sites['enabled'] ) && ! array_key_exists( 'email', $social_sites['disabled'] ) ) {
// Add email as an option.
$social_sites['enabled']['email'] = array( 'name' => __( 'Email' ) );
// Update the settings again.
$nss_settings['social_sites'] = $social_sites;
update_option( 'naked_ss__settings', $nss_settings );
}
}
add_action( 'init', '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
You can’t perform that action at this time.