Skip to content

Commit

Permalink
Better naming for multisite compatibility (+ bug fix on THIS_PLUGIN_N…
Browse files Browse the repository at this point in the history
…ETWORK_ACTIVATED)
  • Loading branch information
geoffreycrofte committed May 14, 2017
1 parent 45c40bc commit c05e8e3
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 73 deletions.
45 changes: 23 additions & 22 deletions admin/jsps-admin.inc.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?php

// activation hook
register_activation_hook( JUIZ_SPS_FILE, 'juiz_sps_activation' );
function juiz_sps_activation() {

$juiz_sps_options = juiz_get_option( JUIZ_SPS_SETTING_NAME );
$juiz_sps_options = jsps_get_option();

This comment has been minimized.

Copy link
@geoffreycrofte

geoffreycrofte May 14, 2017

Author Owner

Named jsps_ to avoid conflict with other juiz_ plugins. (yeah I have got several plugins)


if ( ! is_array( $juiz_sps_options ) ) {

Expand Down Expand Up @@ -45,7 +46,7 @@ function juiz_sps_activation() {
)
);

juiz_update_plugin_option( JUIZ_SPS_SETTING_NAME , $default_array );
jsps_update_option( $default_array );
}
else {
// if was version under 1.2.3
Expand All @@ -55,7 +56,7 @@ function juiz_sps_activation() {
);

$updated_array = array_merge( $juiz_sps_options, $new_options );
juiz_update_plugin_option( JUIZ_SPS_SETTING_NAME , $updated_array );
jsps_update_option( $updated_array );
}

// if was version under 1.3.0
Expand All @@ -64,15 +65,15 @@ function juiz_sps_activation() {
$juiz_sps_options['juiz_sps_networks']['vk'] = array( 0, __( 'VKontakte', 'juiz-social-post-sharer' ) );
$juiz_sps_options['juiz_sps_colors'] = array( 'bg_color' => '', 'txt_color' => ''); // for next update

juiz_update_plugin_option( JUIZ_SPS_SETTING_NAME , $juiz_sps_options );
jsps_update_option( $juiz_sps_options );
}

// if was version under 1.3.3.7
if ( ! isset( $juiz_sps_options['juiz_sps_counter_option'] ) ) {

$juiz_sps_options['juiz_sps_counter_option'] = 'both';

juiz_update_plugin_option( JUIZ_SPS_SETTING_NAME , $juiz_sps_options );
jsps_update_option( $juiz_sps_options );
}

// if was version under 1.4.1
Expand All @@ -83,7 +84,7 @@ function juiz_sps_activation() {
$juiz_sps_options['juiz_sps_networks']['delicious'] = array( 0, __( 'Delicious', 'juiz-social-post-sharer' ) );
$juiz_sps_options['juiz_sps_networks']['reddit'] = array( 0, __( 'Reddit', 'juiz-social-post-sharer' ) );

juiz_update_plugin_option( JUIZ_SPS_SETTING_NAME , $juiz_sps_options );
jsps_update_option( $juiz_sps_options );
}

// if was version under 1.4.2
Expand All @@ -93,7 +94,7 @@ function juiz_sps_activation() {
$juiz_sps_options['juiz_sps_networks']['bookmark'] = array( 0, __( 'Bookmark', 'juiz-social-post-sharer' ) );
$juiz_sps_options['juiz_sps_networks']['print'] = array( 0, __( 'Print', 'juiz-social-post-sharer' ) );

juiz_update_plugin_option( JUIZ_SPS_SETTING_NAME , $juiz_sps_options );
jsps_update_option( $juiz_sps_options );
}
}
}
Expand Down Expand Up @@ -144,7 +145,7 @@ function juiz_sps_custom_admin_header() {
add_action( 'add_meta_boxes', 'juiz_sps_metaboxes' );
function juiz_sps_metaboxes(){

$options = juiz_get_option( JUIZ_SPS_SETTING_NAME );
$options = jsps_get_option();
$pts = get_post_types( array( 'public'=> true, 'show_ui' => true, '_builtin' => true ) );
$cpts = get_post_types( array( 'public'=> true, 'show_ui' => true, '_builtin' => false ) );

Expand Down Expand Up @@ -226,7 +227,7 @@ function juiz_sps_sanitize( $options ) {
if ( is_array( $options['juiz_sps_networks'] ) ) {

$temp_array = array( 'facebook' => 0, 'twitter' => 0, 'google' => 0, 'pinterest' => 0, 'viadeo' => 0, 'linkedin' => 0, 'digg' => 0, 'stumbleupon' => 0, 'weibo' => 0, 'mail' => 0, 'vk' => 0 );
$juiz_sps_opt = juiz_get_option( JUIZ_SPS_SETTING_NAME );
$juiz_sps_opt = jsps_get_option();

// new option (1.2.0)
if ( ! in_array( 'weibo', $juiz_sps_opt['juiz_sps_networks'] ) ) {
Expand Down Expand Up @@ -301,7 +302,7 @@ function juiz_sps_section_text() {
if ( ! function_exists( 'juiz_sps_setting_radio_style_choice' ) ) {
function juiz_sps_setting_radio_style_choice() {

$options = juiz_get_option( JUIZ_SPS_SETTING_NAME );
$options = jsps_get_option();
if ( is_array( $options ) ) {
$n1 = $n2 = $n3 = $n4 = $n5 = $n6 = $n7 = $n8 = '';
${'n' . $options['juiz_sps_style']} = ' checked="checked"';
Expand Down Expand Up @@ -347,7 +348,7 @@ function juiz_sps_setting_radio_style_choice() {
if ( ! function_exists( 'juiz_sps_setting_checkbox_network_selection' ) ) {
function juiz_sps_setting_checkbox_network_selection() {
$y = $n = '';
$options = juiz_get_option( JUIZ_SPS_SETTING_NAME );
$options = jsps_get_option();
if ( is_array( $options ) ) {
foreach ( $options['juiz_sps_networks'] as $k => $v ) {

Expand All @@ -369,7 +370,7 @@ function juiz_sps_setting_checkbox_network_selection() {
// input for twitter username
if ( ! function_exists( 'juiz_sps_setting_input_twitter_user' ) ) {
function juiz_sps_setting_input_twitter_user() {
$options = juiz_get_option( JUIZ_SPS_SETTING_NAME );
$options = jsps_get_option();
if ( is_array( $options ) ) {
$username = isset( $options['juiz_sps_twitter_user'] ) ? $options['juiz_sps_twitter_user'] : '';
echo '<p class="juiz_sps_options_p">
Expand All @@ -391,7 +392,7 @@ function juiz_sps_section_text_display() {
function juiz_sps_setting_checkbox_content_type() {
$pts = get_post_types( array( 'public'=> true, 'show_ui' => true, '_builtin' => true ) );
$cpts = get_post_types( array( 'public'=> true, 'show_ui' => true, '_builtin' => false ) );
$options = juiz_get_option( JUIZ_SPS_SETTING_NAME );
$options = jsps_get_option();
$all_lists_icon = '<span class="dashicons-before dashicons-editor-ul"></span>';
$all_lists_selected = '';
if ( is_array( $options['juiz_sps_display_in_types'] ) ) {
Expand Down Expand Up @@ -451,7 +452,7 @@ function juiz_sps_setting_checkbox_content_type() {
if ( ! function_exists( 'juiz_sps_setting_radio_where' ) ) {
function juiz_sps_setting_radio_where() {

$options = juiz_get_option( JUIZ_SPS_SETTING_NAME );
$options = jsps_get_option();

$w_bottom = $w_top = $w_both = $w_nowhere = '';
if ( is_array( $options ) && isset( $options['juiz_sps_display_where'] ) )
Expand Down Expand Up @@ -486,7 +487,7 @@ function juiz_sps_section_text_advanced() {
if ( ! function_exists( 'juiz_sps_setting_radio_hide_social_name' ) ) {
function juiz_sps_setting_radio_hide_social_name() {
$y = $n = '';
$options = juiz_get_option( JUIZ_SPS_SETTING_NAME );
$options = jsps_get_option();

if ( is_array( $options ) )
( isset( $options['juiz_sps_hide_social_name'] ) && $options['juiz_sps_hide_social_name'] == 1 ) ? $y = ' checked="checked"' : $n = ' checked="checked"';
Expand All @@ -505,7 +506,7 @@ function juiz_sps_setting_radio_hide_social_name() {
if ( ! function_exists( 'juiz_sps_setting_radio_target_link' ) ) {
function juiz_sps_setting_radio_target_link() {
$y = $n = '';
$options = juiz_get_option( JUIZ_SPS_SETTING_NAME );
$options = jsps_get_option();

if ( is_array( $options ) )
( isset( $options['juiz_sps_target_link'] ) && $options['juiz_sps_target_link'] == 1 ) ? $y = ' checked="checked"' : $n = ' checked="checked"';
Expand All @@ -522,7 +523,7 @@ function juiz_sps_setting_radio_target_link() {
if ( ! function_exists( 'juiz_sps_setting_radio_force_snif' ) ) {
function juiz_sps_setting_radio_force_snif() {
$y = $n = '';
$options = juiz_get_option( JUIZ_SPS_SETTING_NAME );
$options = jsps_get_option();

if ( is_array( $options ) )
( isset( $options['juiz_sps_force_pinterest_snif'] ) && $options['juiz_sps_force_pinterest_snif'] == 1 ) ? $y = ' checked="checked"' : $n = ' checked="checked"';
Expand All @@ -540,7 +541,7 @@ function juiz_sps_setting_radio_force_snif() {
function juiz_sps_setting_radio_counter() {

$y = $n = '';
$options = juiz_get_option( JUIZ_SPS_SETTING_NAME );
$options = jsps_get_option();

if ( is_array( $options ) )
( isset( $options['juiz_sps_counter'] ) && $options['juiz_sps_counter'] == 1 ) ? $y = ' checked="checked"' : $n = ' checked="checked"';
Expand All @@ -557,7 +558,7 @@ function juiz_sps_setting_radio_counter() {
if ( ! function_exists( 'juiz_sps_setting_radio_counter_option' ) ) {
function juiz_sps_setting_radio_counter_option() {

$options = juiz_get_option( JUIZ_SPS_SETTING_NAME );
$options = jsps_get_option();
if ( is_array( $options ) ) {
$both = ( isset( $options['juiz_sps_counter_option'] ) && $options['juiz_sps_counter_option'] == 'both' ) ? ' checked="checked"' : '';
$total = ( isset( $options['juiz_sps_counter_option'] ) && $options['juiz_sps_counter_option'] == 'total' ) ? ' checked="checked"' : '';
Expand Down Expand Up @@ -585,7 +586,7 @@ function juiz_sps_setting_radio_counter_option() {
if ( ! function_exists( 'juiz_sps_setting_radio_css_in_html' ) ) {
function juiz_sps_setting_radio_css_in_html() {
$y = $n = '';
$options = juiz_get_option( JUIZ_SPS_SETTING_NAME );
$options = jsps_get_option();

if ( is_array( $options ) )
( isset( $options['juiz_sps_write_css_in_html'] ) && $options['juiz_sps_write_css_in_html'] == 1 ) ? $y = ' checked="checked"' : $n = ' checked="checked"';
Expand All @@ -609,15 +610,15 @@ function juiz_sps_section_text_mail() {
}
if ( ! function_exists( 'juiz_sps_setting_input_mail_subject' ) ) {
function juiz_sps_setting_input_mail_subject() {
$options = juiz_get_option( JUIZ_SPS_SETTING_NAME );
$options = jsps_get_option();
if ( isset( $options['juiz_sps_mail_subject'] ) ) {
echo '<input id="juiz_sps_mail_subject" value="' . esc_attr( $options['juiz_sps_mail_subject'] ) . '" name="' . JUIZ_SPS_SETTING_NAME . '[juiz_sps_mail_subject]" type="text">';
}
}
}
if ( ! function_exists( 'juiz_sps_setting_textarea_mail_body' ) ) {
function juiz_sps_setting_textarea_mail_body() {
$options = juiz_get_option( JUIZ_SPS_SETTING_NAME );
$options = jsps_get_option();
if ( isset( $options['juiz_sps_mail_body'] ) ) {
echo '<textarea id="juiz_sps_mail_body" name="' . JUIZ_SPS_SETTING_NAME . '[juiz_sps_mail_body]">' . esc_textarea( $options['juiz_sps_mail_body'] ) . '</textarea>';
}
Expand Down
112 changes: 64 additions & 48 deletions juiz-social-post-sharer.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<?php
/*
Plugin Name: Juiz Social Post Sharer Forked
Plugin Name: Juiz Social Post Sharer
Plugin URI: http://wordpress.org/extend/plugins/juiz-social-post-sharer/
Description: Add buttons after (or before, or both) your posts to allow visitors share your content (includes no JavaScript mode). You can also use <code>juiz_sps($array)</code> template function or <code>[juiz_sps]</code> shortcode. For more informations see the setting page located in <strong>Settings</strong> submenu.
Author: Geoffrey Crofte
Version: 1.4.6
Version: 1.4.7
Author URI: http://geoffrey.crofte.fr
License: GPLv2 or later
Text Domain: juiz-social-post-sharer
Domain Path: /languages
Copyright 2012-2015 Geoffrey Crofte (email : [email protected])
Copyright 2012-2017 Geoffrey Crofte (email : [email protected])
This program is free software; you can redistribute it and/or
Expand All @@ -32,65 +32,81 @@
*/

define( 'JUIZ_SPS_PLUGIN_NAME', 'Juiz Social Post Sharer' );
define( 'JUIZ_SPS_VERSION', '1.4.6' );
define( 'JUIZ_SPS_VERSION', '1.4.7' );
define( 'JUIZ_SPS_FILE', __FILE__ );
define( 'JUIZ_SPS_DIRNAME', basename( dirname( __FILE__ ) ) );
define( 'JUIZ_SPS_PLUGIN_URL', plugin_dir_url( __FILE__ ));
define( 'JUIZ_SPS_SLUG', 'juiz-social-post-sharer' );
define( 'JUIZ_SPS_SETTING_NAME', 'juiz_SPS_settings' );

/**
* MULTISITE COMPATIBILITY
**/
// define a constant to see if site is network activated
if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
// Makes sure the plugin is defined before trying to use it
require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
}
if (is_plugin_active_for_network('juiz-social-post-sharer/juiz-social-post-sharer.php')) { // path to plugin folder and main file
define('JUIZ_NETWORK_ACTIVATED', true);
}
else {
define('JUIZ_NETWORK_ACTIVATED', false);
}
// Checking network activation.
$is_nw_activated = function_exists( 'is_plugin_active_for_network' ) && is_plugin_active_for_network( JUIZ_SPS_SLUG . '/' . JUIZ_SPS_SLUG . '.php' ) ? true : false;

This comment has been minimized.

Copy link
@geoffreycrofte

geoffreycrofte May 14, 2017

Author Owner

More performant way to set a define.


// Wordpress function 'get_site_option' and 'get_option'
function juiz_get_option($option_name) {
define( 'JUIZ_SPS_NETWORK_ACTIVATED', $is_nw_activated );

if(THIS_PLUGIN_NETWORK_ACTIVATED == true) {

// Multilingal.
add_action( 'init', 'make_juiz_sps_multilang' );
function make_juiz_sps_multilang() {
load_plugin_textdomain( 'juiz-social-post-sharer', false, JUIZ_SPS_DIRNAME.'/languages' );
}

// Get network site option
return get_blog_option(get_current_blog_id(), $option_name);
}
else {
/**
* Getting options from the right place.
* Multisite compatibility.
*
* @author Marie Comet, Geoffrey Crofte
* @since 1.4.7
*/
function jsps_get_option( $option_name = '' ) {

// When we want a precise option in a network activated website.
if ( ! empty( $option_name ) && true === JUIZ_SPS_NETWORK_ACTIVATED ) {

This comment has been minimized.

Copy link
@geoffreycrofte

geoffreycrofte May 14, 2017

Author Owner

In case I need to get a precise value. Not used yet.

$options = get_blog_option( get_current_blog_id(), JUIZ_SPS_SETTING_NAME );
return $options[ $option_name ];
}

// Get blog option
return get_option($option_name);
}
}
// Wordpress function 'update_site_option' and 'update_option'
function juiz_update_plugin_option($option_name, $option_value) {
// When we want all options in a network activated website.
else if ( empty( $option_name ) && true === JUIZ_SPS_NETWORK_ACTIVATED ) {
return get_blog_option( get_current_blog_id(), JUIZ_SPS_SETTING_NAME );
}

if(THIS_PLUGIN_NETWORK_ACTIVATED== true) {
// When we want a precise option in a simple website.
else if ( ! empty( $option_name ) && false === JUIZ_SPS_NETWORK_ACTIVATED ) {
$options = get_option( JUIZ_SPS_SETTING_NAME );
return $options[ $option_name ];
}

// Update network site option
return update_blog_option(get_current_blog_id(), $option_name, $option_value);
}
else {
// When we want all options in a simple website.
else {
return get_option( JUIZ_SPS_SETTING_NAME );
}

// Update blog option
return update_option($option_name, $option_value);
}
}

/**
* MULTISITE COMPATIBILITY
**/
* Updating options to the right place.
* Multisite compatibility.
*
* @author Marie Comet, Geoffrey Crofte
* @since 1.4.7
*/
function jsps_update_option( $options ) {

if ( ! is_array( $options ) ) {

This comment has been minimized.

Copy link
@geoffreycrofte

geoffreycrofte May 14, 2017

Author Owner

To be sure we are updating all the "options" at the same time.

die( '$options has to be an array' );
}

// multilingue
// When we want to update options in a network activated website.
if ( true === JUIZ_SPS_NETWORK_ACTIVATED ) {
$options = update_blog_option( get_current_blog_id(), JUIZ_SPS_SETTING_NAME, $options );
return $options;
}

add_action( 'init', 'make_juiz_sps_multilang' );
function make_juiz_sps_multilang() {
load_plugin_textdomain( 'juiz-social-post-sharer', false, JUIZ_SPS_DIRNAME.'/languages' );
// When we want to update options in a simple website.
else {
$options = update_option( JUIZ_SPS_SETTING_NAME, $options );
}
}

if ( is_admin() || ( defined( 'DOING_AJAX' ) && ! DOING_AJAX ) ) {
Expand All @@ -108,7 +124,7 @@ function make_juiz_sps_multilang() {

function juiz_sps_style_and_script() {

$juiz_sps_options = juiz_get_option( JUIZ_SPS_SETTING_NAME );
$juiz_sps_options = jsps_get_option();

if ( is_array( $juiz_sps_options ) ) {

Expand Down Expand Up @@ -219,7 +235,7 @@ function get_juiz_sps( $networks = array(), $counters = 0, $is_current_page_url


// get the plugin options
$juiz_sps_options = juiz_get_option( JUIZ_SPS_SETTING_NAME );
$juiz_sps_options = jsps_get_option();

// classes and attributes options
$juiz_sps_target_link = ( isset( $juiz_sps_options['juiz_sps_target_link'] ) && $juiz_sps_options['juiz_sps_target_link'] == 1 ) ? ' target="_blank"' : '';
Expand Down Expand Up @@ -420,7 +436,7 @@ function juiz_sps( $networks = array(), $counters = 0, $current_page = 0, $is_sh
if ( ! function_exists( 'juiz_sps_print_links' ) ) {
function juiz_sps_print_links( $content ) {

$juiz_sps_options = juiz_get_option( JUIZ_SPS_SETTING_NAME );
$juiz_sps_options = jsps_get_option();

if ( isset( $juiz_sps_options['juiz_sps_display_in_types'] ) ) {

Expand Down
7 changes: 5 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Contributors: CreativeJuiz
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=P39NJPCWVXGDY&lc=FR&item_name=Juiz%20Social%20Post%20Sharer%20%2d%20WP%20Plugin&item_number=%23wp%2djsps&currency_code=EUR&bn=PP%2dDonationsBF%3abtn_donate_SM%2egif%3aNonHosted
Tags: social, twitter, google, facebook, digg, stumbleupon, linkedin, pinterest, viadeo, weibo, vkontakte, post, share
Requires at least: 3.3
Tested up to: 4.6
Stable tag: 1.4.6
Tested up to: 4.7.4
Stable tag: 1.4.7

Add smart designed buttons after/before your posts to allow visitors sharing your content (includes no JavaScript mode & counters)

Expand Down Expand Up @@ -144,6 +144,9 @@ Find my plugins at <a href="http://profiles.wordpress.org/creativejuiz/">http://

== Changelog ==

= 1.4.7 =
* Compatibility on network (multisite) thanks to Marie Comet ([Marie Comet](http://mariecomet.fr/))

= 1.4.6 =
* Tested up to WordPress 4.6
* Facebook counter is back thanks to Jean-Baptiste (from [Whodunit](http://www.whodunit.fr/))
Expand Down
Loading

0 comments on commit c05e8e3

Please sign in to comment.