~dvko/wp-social-sharing

a464990eaa2018c627d03b54109b295399274f21 — Danny van Kooten 1 year, 5 months ago b448a6f
minor php improvements
M includes/class-admin.php => includes/class-admin.php +16 -22
@@ 4,15 4,10 @@ class DVKSS_Admin {

	/**
	* @var int
	*/ 
	*/
	private $code_version = 1;

	/**
	 * @var string
	 */
	private $slug = 'dvk-social-sharing/index.php';
	
	/**
	* @var string
	*/
	private $plugin_file;


@@ 20,35 15,31 @@ class DVKSS_Admin {
	/**
	 * Constructor
	 * @param string $plugin_file
	*/ 
	*/
	public function __construct( $plugin_file ) {
		$this->plugin_file = $plugin_file;	
		$this->plugin_file = $plugin_file;
	}

	public function hook() {
		add_action( 'admin_init', array( $this, 'maybe_run_upgrade_routine' ) );
		add_action( 'admin_init', array( $this, 'register_settings' ) );
		add_action( 'admin_init', array( $this, 'on_admin_init' ) );
		add_action( 'admin_menu', array( $this, 'add_menu_item' ) );
		add_filter( "plugin_action_links_dvk-social-sharing/index.php", array( $this, 'add_settings_link' ) );
		add_action( 'admin_enqueue_scripts', array( $this, 'load_css' ) );
	}

		add_filter( "plugin_action_links_{$this->slug}", array( $this, 'add_settings_link' ) );

		if ( isset( $_GET['page'] ) && $_GET['page'] === 'dvkss' ) {
			// load css
			add_action( 'admin_enqueue_scripts', array( $this, 'load_css' ) );
		}
	public function on_admin_init() {
		$this->maybe_run_upgrade_routine();
		$this->register_settings();
	}

	/**
	 * Upgrade routine
	 *
	 * @return bool
	 */
	public function maybe_run_upgrade_routine() {

		// only run if code version is higher than stored code version
		$db_version = absint( get_option( 'dvkss_code_version', 0  ) );
		if( $this->code_version <= $db_version ) {
			return false;
			return;
		}

		$opts = dvkss_get_options();


@@ 60,13 51,16 @@ class DVKSS_Admin {

		update_option( 'dvk_social_sharing', $opts );
		update_option( 'dvkss_code_version', $this->code_version );
		return true;
	}

	/**
	* Load admin scripts and stylesheets
	*/
	public function load_css() {
		if ( ! isset( $_GET['page'] ) || $_GET['page'] !== 'dvkss' ) {
			return;
		}

		$suffix = ( defined( SCRIPT_DEBUG ) && SCRIPT_DEBUG ) ? '' : '.min';
		wp_enqueue_style( 'dvk-social-sharing', plugins_url( '/assets/css/admin-styles' . $suffix .'.css', $this->plugin_file ) );
		wp_enqueue_script( 'dvk-social-sharing', plugins_url( 'assets/js/admin-script' . $suffix .'.js', $this->plugin_file ), array( 'jquery' ), DVKSS_VERSION , true );


@@ 81,7 75,7 @@ class DVKSS_Admin {

	/**
	* Sanitize settings
	*	
	*
	* @param array $settings
	* @return array $settings
	*/

M includes/class-public.php => includes/class-public.php +5 -7
@@ 3,7 3,7 @@
class DVKSS_Public {

	private $plugin_file;
	

	/**
	 * Constructor
	 *


@@ 22,8 22,7 @@ class DVKSS_Public {
	/**
	* Load plugin stylesheets and scripts
	*/
	public function load_assets() 
	{
	public function load_assets() {
		$opts = dvkss_get_options();
		$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';



@@ 42,8 41,7 @@ class DVKSS_Public {
	 * @param string $content
	 * @return string
	 */
	public function add_links( $content )
	{
	public function add_links( $content ) {
		$opts = dvkss_get_options();
		$show_buttons = false;



@@ 54,8 52,8 @@ class DVKSS_Public {
		// allow custom conditionals
		$show_buttons = apply_filters( 'dvkss_display', $show_buttons );

		if( ! $show_buttons ) { 
			return $content; 
		if( ! $show_buttons ) {
			return $content;
		}

		// add buttons to content

M includes/functions.php => includes/functions.php +5 -5
@@ 5,12 5,12 @@
* @return array Options in array format
*/
function dvkss_get_options()
{	
{
	static $options;

	// load options from database
	if( ! $options ) {
		

		// default options
		$defaults = array(
			'load_icon_css' => 1,


@@ 23,15 23,15 @@ function dvkss_get_options()
		);

		// get options from db
		$db_option = get_option( 'dvk_social_sharing', array() );
		$options = get_option( 'dvk_social_sharing', array() );

		// add option to database if not set, saves a query
		if( ! $db_option ) {
		if( ! $options ) {
			update_option( 'dvk_social_sharing', $defaults );
		}

		// merge with default options to prevent notices
		$options = wp_parse_args( $db_option, $defaults );
		$options = array_merge( $defaults, $options );
	}

	return $options;

M includes/views/settings-page.php => includes/views/settings-page.php +7 -7
@@ 1,4 1,4 @@
<?php 
<?php

if( ! defined("DVKSS_VERSION") ) {
	header( 'Status: 403 Forbidden' );


@@ 22,7 22,7 @@ $networks = array(

		<form id="dvkss_settings" method="post" action="options.php">
			<?php settings_fields( 'dvk_social_sharing' ); ?>
	

			<h2><?php _e('Settings'); ?></h2>

			<table class="form-table">


@@ 51,7 51,7 @@ $networks = array(
							</li>
						<?php } ?>
						</ul>
						

						<small><?php _e('Automatically adds the sharing links to the end of the selected post types.', 'dvk-social-sharing'); ?></small>
					</td>
				</tr>


@@ 80,7 80,7 @@ $networks = array(
						<?php _e('Load icon CSS?', 'dvk-social-sharing'); ?>
					</th>
					<td>
						<label><input type="radio" name="dvk_social_sharing[load_icon_css]" value="1" <?php checked($opts['load_icon_css'], 1); ?> > <?php _e('Yes'); ?></label> &nbsp; 
						<label><input type="radio" name="dvk_social_sharing[load_icon_css]" value="1" <?php checked($opts['load_icon_css'], 1); ?> > <?php _e('Yes'); ?></label> &nbsp;
						<label><input type="radio" name="dvk_social_sharing[load_icon_css]" value="0" <?php checked($opts['load_icon_css'], 0); ?> > <?php _e('No'); ?></label>
						<br>
						<small><?php _e('Adds simple but pretty icons to the sharing links.', 'dvk-social-sharing'); ?></small>


@@ 105,7 105,7 @@ $networks = array(
						<?php _e('Load pop-up JS?', 'dvk-social-sharing'); ?>
					</th>
					<td>
						<label><input type="radio" name="dvk_social_sharing[load_popup_js]" value="1" <?php checked($opts['load_popup_js'], 1); ?> > <?php _e('Yes'); ?></label> &nbsp; 
						<label><input type="radio" name="dvk_social_sharing[load_popup_js]" value="1" <?php checked($opts['load_popup_js'], 1); ?> > <?php _e('Yes'); ?></label> &nbsp;
						<label><input type="radio" name="dvk_social_sharing[load_popup_js]" value="0" <?php checked($opts['load_popup_js'], 0); ?> > <?php _e('No'); ?></label>
						<br>
						<small><?php _e("A small JavaScript file of just 600 bytes so people won't have to leave your website to share.", 'dvk-social-sharing'); ?></small>


@@ 117,8 117,8 @@ $networks = array(
						<label for="dvkss_twitter_username"><?php _e('Twitter username', 'dvk-social-sharing'); ?></label>
					</th>
					<td>
						<input type="text" name="dvk_social_sharing[twitter_username]" id="dvkss_twitter_username" class="widefat" placeholder="DannyvanKooten" value="<?php echo esc_attr($opts['twitter_username']); ?>">
						<small><?php _e('Set this if you want to append "via @yourTwitterUsername" to tweets.', 'dvk-social-sharing'); ?></small>
						<input type="text" name="dvk_social_sharing[twitter_username]" id="dvkss_twitter_username" class="widefat" placeholder="@yourtwitter" value="<?php echo esc_attr($opts['twitter_username']); ?>">
						<small><?php _e('Set this if you want to append "via @yourtwitter" to tweets.', 'dvk-social-sharing'); ?></small>
					</td>
				</tr>


M readme.txt => readme.txt +144 -144
@@ 1,132 1,132 @@
=== Social Sharing (by Danny) ===
Contributors: DvanKooten, ibericode
Donate link: https://dannyvankooten.com/donate/
Tags: social, social sharing, buttons, twitter, googleplus, facebook
Requires at least: 3.7
Tested up to: 5.3
=== Social Sharing (by Danny) ===
Contributors: DvanKooten, ibericode
Donate link: https://www.dannyvankooten.com/donate/
Tags: social, social sharing, buttons, twitter, googleplus, facebook
Requires at least: 3.7
Tested up to: 6.1
Stable tag: 1.3.3
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Adds very simple social sharing buttons for Twitter, Facebook, LinkedIn and Google+ to the end of your posts.

== Description ==

= Social Sharing By Danny =

The simplest sharing links possible for Twitter, Facebook, LinkedIn and Google+.

Most social sharing plugins are too ugly, heavy, complicated or poorly coded for my liking. This plugin aims to be better: simple, lightweight and flexible.

= No script dependencies =

From itself, the buttons are actually plain text links which require <strong>NO external scripts</strong>. It makes no sense to load over 50 kilobytes of scripts and styles for a functionality 95% of your users will not use.

= Simple yet pretty & user-friendly  =

You can have the plugin load two very small files to add icons and a pop-up functionality to the sharing links. This way, users do not have to leave your website after clicking a sharing option. Loading of both files can be disabled so you can craft your own styles.

**Plugin Features**

- Sharing links for Twitter, Facebook, LinkedIn and Google+
- Simple icon styles with a hover effect
- Simple script of just 600 bytes (not jQuery dependent) which will make the links open in a pop-up window.
- A shortcode and a template function to display the buttons anywhere you want.
- An overridable filter to set the condition for when to display the sharing links.
- Translation ready

**Translations**

Is the plugin not translated into your language? You can [contribute your translations using the translation editor here on WordPress.org](https://translate.wordpress.org/projects/wp-plugins/dvk-social-sharing/).

**Other plugins by the same author**

Check out other [WordPress plugins](https://dannyvankooten.com/wordpress-plugins/) by the same author


== Frequently Asked Questions ==

= Can I display the sharing buttons using a shortcode? =

Yes, you can use the following shortcode (eg. inside posts or pages).

`
[dvk_social_sharing]
`

= Can I display the sharing buttons using a template function? =
Yes, you can use the following PHP function from your template files.


`
<?php echo dvk_social_sharing(); ?>
`

= I want more control over when to show the sharing options =

Use the `dvkss_display` filter to show the links in more places.

*Example 1: will add the sharing links to everything possible*

`
add_filter('dvkss_display', '__return_true');
`

*Example 2: will add the sharing links to all single posts, pages and other post types.*

`
function my_display_condition() {
	return is_singular();
}

add_filter('dvkss_display', 'my_display_condition');
`


= Shortcode and function arguments =

**element** (string)

The element to use as the wrapping element. Defaults to `p`, a paragraph element.

**twitter_username** (string)

The Twitter username to add to tweets. This will override the value from the settings page.

**social_options** (comma separated string)

The social media buttons to show. You can also use this to change the order of the buttons. Defaults to `twitter, facebook, googleplus`, which are the only 3 possible values.

**before_text**  (string)

The text to show before the links. This will override the value in the settings page.

**twitter_text** (string)
**facebook_text** (string)
**googleplus_text** (string)
**linkedin_text** (string)

The texts for the different links. Defaults to the string set in the translation file.

== Screenshots ==

1. Simple but beautiful sharing links add the end of your posts.
2. Disable the default plugin CSS to create your own styles.
2. The settings page of the plugin.

== Installation ==

= Installing the plugin =

1. In your WordPress admin panel, go to *Plugins > New Plugin*, search for *Social Sharing by Danny* and click "Install now"
1. Alternatively, download the plugin and upload the contents of `dvk-social-sharing.zip` to your plugins directory, which usually is `/wp-content/plugins/`.
1. Activate the plugin.

= Additional Customization =

Have a look at the [frequently asked questions](https://wordpress.org/plugins/dvk-social-sharing/faq/) section for some examples of additional customization.

== Changelog ==
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Adds very simple social sharing buttons for Twitter, Facebook, LinkedIn and Google+ to the end of your posts.

== Description ==

= Social Sharing By Danny =

The simplest sharing links possible for Twitter, Facebook, LinkedIn and Google+.

Most social sharing plugins are too ugly, heavy, complicated or poorly coded for my liking. This plugin aims to be better: simple, lightweight and flexible.

= No script dependencies =

From itself, the buttons are actually plain text links which require <strong>NO external scripts</strong>. It makes no sense to load over 50 kilobytes of scripts and styles for a functionality 95% of your users will not use.

= Simple yet pretty & user-friendly  =

You can have the plugin load two very small files to add icons and a pop-up functionality to the sharing links. This way, users do not have to leave your website after clicking a sharing option. Loading of both files can be disabled so you can craft your own styles.

**Plugin Features**

- Sharing links for Twitter, Facebook, LinkedIn and Google+
- Simple icon styles with a hover effect
- Simple script of just 600 bytes (not jQuery dependent) which will make the links open in a pop-up window.
- A shortcode and a template function to display the buttons anywhere you want.
- An overridable filter to set the condition for when to display the sharing links.
- Translation ready

**Translations**

Is the plugin not translated into your language? You can [contribute your translations using the translation editor here on WordPress.org](https://translate.wordpress.org/projects/wp-plugins/dvk-social-sharing/).

**Other plugins by the same author**

Check out other [WordPress plugins](https://dannyvankooten.com/wordpress-plugins/) by the same author


== Frequently Asked Questions ==

= Can I display the sharing buttons using a shortcode? =

Yes, you can use the following shortcode (eg. inside posts or pages).

`
[dvk_social_sharing]
`

= Can I display the sharing buttons using a template function? =
Yes, you can use the following PHP function from your template files.


`
<?php echo dvk_social_sharing(); ?>
`

= I want more control over when to show the sharing options =

Use the `dvkss_display` filter to show the links in more places.

*Example 1: will add the sharing links to everything possible*

`
add_filter('dvkss_display', '__return_true');
`

*Example 2: will add the sharing links to all single posts, pages and other post types.*

`
function my_display_condition() {
	return is_singular();
}

add_filter('dvkss_display', 'my_display_condition');
`


= Shortcode and function arguments =

**element** (string)

The element to use as the wrapping element. Defaults to `p`, a paragraph element.

**twitter_username** (string)

The Twitter username to add to tweets. This will override the value from the settings page.

**social_options** (comma separated string)

The social media buttons to show. You can also use this to change the order of the buttons. Defaults to `twitter, facebook, googleplus`, which are the only 3 possible values.

**before_text**  (string)

The text to show before the links. This will override the value in the settings page.

**twitter_text** (string)
**facebook_text** (string)
**googleplus_text** (string)
**linkedin_text** (string)

The texts for the different links. Defaults to the string set in the translation file.

== Screenshots ==

1. Simple but beautiful sharing links add the end of your posts.
2. Disable the default plugin CSS to create your own styles.
2. The settings page of the plugin.

== Installation ==

= Installing the plugin =

1. In your WordPress admin panel, go to *Plugins > New Plugin*, search for *Social Sharing by Danny* and click "Install now"
1. Alternatively, download the plugin and upload the contents of `dvk-social-sharing.zip` to your plugins directory, which usually is `/wp-content/plugins/`.
1. Activate the plugin.

= Additional Customization =

Have a look at the [frequently asked questions](https://wordpress.org/plugins/dvk-social-sharing/faq/) section for some examples of additional customization.

== Changelog ==


#### 1.3.3 - Dec 31, 2019


@@ 167,13 167,13 @@ Misc. textual improvements.
- Added Italian translations, thanks to Alessandro Guidi.


#### 1.2.6 - March 29, 2016 
#### 1.2.6 - March 29, 2016

**Fixes**

- Apostrophes in titles not properly escaped in sharing URL's. Thanks Robin Aldenhoven!

#### 1.2.5 - January 26, 2015 
#### 1.2.5 - January 26, 2015

**Improvements**



@@ 184,27 184,27 @@ Misc. textual improvements.
- Added Finnish (fi_FI) translations, thanks to [Ari-Pekka Koponen](http://versi.fi/)


#### 1.2.4 - November 17, 2014 
#### 1.2.4 - November 17, 2014

**Improvements**

- Wrapped link text in element so it can be hidden using CSS
- Improvements to pop-up JavaScript

#### 1.2.3 - September 4, 2014 
#### 1.2.3 - September 4, 2014

**Improvements**

- Added minified scripts and option to load minified version
- Some textual improvements

#### 1.2.2 - April 30, 2014 
#### 1.2.2 - April 30, 2014

**Fixes**

- Fixed not being able to save all "auto add to .." checkboxes unchecked

#### 1.2.1 - April 29, 2014 
#### 1.2.1 - April 29, 2014
**Additions**

- Added German translations, thanks Andreas Kuhl!


@@ 214,7 214,7 @@ Misc. textual improvements.
- Wrapped non-translatable strings in translation calls.
- Updated Dutch translations

#### 1.2 - March 19, 2014 
#### 1.2 - March 19, 2014
**Additions**

- Added option to automatically add sharing options to all registered post types


@@ 224,43 224,43 @@ Misc. textual improvements.

- Disabled Pop-up JS by default until we figure out a cross-browser compatibility fix.

#### 1.1 - February 19, 2014 
#### 1.1 - February 19, 2014
- Added: Slovenian translations, thanks to [Domen Hrabar, Viking Marketing](http://www.vikingmarketing.si/)
- Improved: direct file access security


#### 1.0.9 - December 30, 2013 
#### 1.0.9 - December 30, 2013
- Added: Danish translation, thanks to [Finn Hoelgaard](http://fhn.dk/)!
- Added: Russian translation, thanks to Nikita!
- Improved: Pop-up script now waits for full page load.

#### 1.0.6 - December 20, 2013 
#### 1.0.6 - December 20, 2013
- Improved: Pop-up JS now used addEventListener to enable multiple event listeners (like a Google Analytics plugin) attaching to the sharing links.

#### 1.0.5 - December 9, 2013 
#### 1.0.5 - December 9, 2013
- Added: French translations, thanks to [Said](http://www.ninapeople.com/)
- Improved: All backend strings are now translatable
- Improved: Prevented direct access or search engine indexing of plugin files
- Improved: Facebook URL sharing parameters

#### 1.0.4 - December 2, 2013 
#### 1.0.4 - December 2, 2013
- Improved: Minified pop-up script to 480 bytes.
- Improved: Removed image attribute from Facebook Share URL. FB will now pick up `og:image` meta tags.

#### 1.0.3 - November 25, 2013 
#### 1.0.3 - November 25, 2013
- Fixed: undefined index notice when saving options.

#### 1.0.2 - November 20, 2013 
#### 1.0.2 - November 20, 2013

- Added: Dutch translation
- Added: Option to change the text that shows before the sharing links.

#### 1.0.1 - November 20, 2013 
#### 1.0.1 - November 20, 2013

- Fixed: Added settings link to plugins overview page
- Fixed: "tweet about" option in admin now tweets about the correct plugin.

#### 1.0 - November 17, 2013 
#### 1.0 - November 17, 2013

- Initial release.