Skip to content

Commit

Permalink
Merge pull request #10 from MarieComet/master
Browse files Browse the repository at this point in the history
Add Multisite compatibility
  • Loading branch information
geoffreycrofte authored May 14, 2017
2 parents 113d0b3 + f2a2049 commit 45c40bc
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 28 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Contributors
* Geoffrey Crofte ([WP Media](http://wp-media.me))
* *Contributors*
* Jean-Baptiste Audras ([Whodunit](http://www.whodunit.fr/))
* Marie Comet ([Marie Comet](http://mariecomet.fr/))
* *Translators*
* [Dennis Schmitz](http://compcardinmotion.de)
* [半月 Hangetsu](http://wp.fruit-frappe.net/)
Expand Down
45 changes: 22 additions & 23 deletions admin/jsps-admin.inc.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<?php

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

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

if ( ! is_array( $juiz_sps_options ) ) {

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

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

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

// if was version under 1.3.0
Expand All @@ -65,15 +64,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

update_option( JUIZ_SPS_SETTING_NAME , $juiz_sps_options );
juiz_update_plugin_option( JUIZ_SPS_SETTING_NAME , $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';

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

// if was version under 1.4.1
Expand All @@ -84,7 +83,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' ) );

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

// if was version under 1.4.2
Expand All @@ -94,7 +93,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' ) );

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

$options = get_option( JUIZ_SPS_SETTING_NAME );
$options = juiz_get_option( JUIZ_SPS_SETTING_NAME );
$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 @@ -227,7 +226,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 = get_option ( JUIZ_SPS_SETTING_NAME );
$juiz_sps_opt = juiz_get_option( JUIZ_SPS_SETTING_NAME );

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

$options = get_option( JUIZ_SPS_SETTING_NAME );
$options = juiz_get_option( JUIZ_SPS_SETTING_NAME );
if ( is_array( $options ) ) {
$n1 = $n2 = $n3 = $n4 = $n5 = $n6 = $n7 = $n8 = '';
${'n' . $options['juiz_sps_style']} = ' checked="checked"';
Expand Down Expand Up @@ -348,7 +347,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 = get_option( JUIZ_SPS_SETTING_NAME );
$options = juiz_get_option( JUIZ_SPS_SETTING_NAME );
if ( is_array( $options ) ) {
foreach ( $options['juiz_sps_networks'] as $k => $v ) {

Expand All @@ -370,7 +369,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 = get_option( JUIZ_SPS_SETTING_NAME );
$options = juiz_get_option( JUIZ_SPS_SETTING_NAME );
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 @@ -392,7 +391,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 = get_option( JUIZ_SPS_SETTING_NAME );
$options = juiz_get_option( JUIZ_SPS_SETTING_NAME );
$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 @@ -452,7 +451,7 @@ function juiz_sps_setting_checkbox_content_type() {
if ( ! function_exists( 'juiz_sps_setting_radio_where' ) ) {
function juiz_sps_setting_radio_where() {

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

$w_bottom = $w_top = $w_both = $w_nowhere = '';
if ( is_array( $options ) && isset( $options['juiz_sps_display_where'] ) )
Expand Down Expand Up @@ -487,7 +486,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 = get_option( JUIZ_SPS_SETTING_NAME );
$options = juiz_get_option( JUIZ_SPS_SETTING_NAME );

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 @@ -506,7 +505,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 = get_option( JUIZ_SPS_SETTING_NAME );
$options = juiz_get_option( JUIZ_SPS_SETTING_NAME );

if ( is_array( $options ) )
( isset( $options['juiz_sps_target_link'] ) && $options['juiz_sps_target_link'] == 1 ) ? $y = ' checked="checked"' : $n = ' checked="checked"';
Expand All @@ -523,7 +522,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 = get_option( JUIZ_SPS_SETTING_NAME );
$options = juiz_get_option( JUIZ_SPS_SETTING_NAME );

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 @@ -541,7 +540,7 @@ function juiz_sps_setting_radio_force_snif() {
function juiz_sps_setting_radio_counter() {

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

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

$options = get_option( JUIZ_SPS_SETTING_NAME );
$options = juiz_get_option( JUIZ_SPS_SETTING_NAME );
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 @@ -586,7 +585,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 = get_option( JUIZ_SPS_SETTING_NAME );
$options = juiz_get_option( JUIZ_SPS_SETTING_NAME );

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 @@ -610,15 +609,15 @@ function juiz_sps_section_text_mail() {
}
if ( ! function_exists( 'juiz_sps_setting_input_mail_subject' ) ) {
function juiz_sps_setting_input_mail_subject() {
$options = get_option( JUIZ_SPS_SETTING_NAME );
$options = juiz_get_option( JUIZ_SPS_SETTING_NAME );
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 = get_option( JUIZ_SPS_SETTING_NAME );
$options = juiz_get_option( JUIZ_SPS_SETTING_NAME );
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
56 changes: 51 additions & 5 deletions juiz-social-post-sharer.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
Plugin Name: Juiz Social Post Sharer
Plugin Name: Juiz Social Post Sharer Forked
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
Expand Down Expand Up @@ -39,7 +39,53 @@
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);
}

// Wordpress function 'get_site_option' and 'get_option'
function juiz_get_option($option_name) {

if(THIS_PLUGIN_NETWORK_ACTIVATED == true) {

// Get network site option
return get_blog_option(get_current_blog_id(), $option_name);
}
else {

// 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) {

if(THIS_PLUGIN_NETWORK_ACTIVATED== true) {

// Update network site option
return update_blog_option(get_current_blog_id(), $option_name, $option_value);
}
else {

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

// multilingue

add_action( 'init', 'make_juiz_sps_multilang' );
Expand All @@ -62,7 +108,7 @@ function make_juiz_sps_multilang() {

function juiz_sps_style_and_script() {

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

if ( is_array( $juiz_sps_options ) ) {

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


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

// 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 @@ -374,7 +420,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 = get_option( JUIZ_SPS_SETTING_NAME );
$juiz_sps_options = juiz_get_option( JUIZ_SPS_SETTING_NAME );

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

Expand Down

0 comments on commit 45c40bc

Please sign in to comment.