From f0c6d71171a16cf7ffc1e7e03354bacac22ba8fd Mon Sep 17 00:00:00 2001 From: marie_comet Date: Wed, 15 Feb 2017 18:46:01 +0100 Subject: [PATCH 1/4] add Multisite compatibility --- admin/jsps-admin.inc.php | 45 +++++++++++++++-------------- juiz-social-post-sharer.php | 56 +++++++++++++++++++++++++++++++++---- readme.txt | 2 +- 3 files changed, 74 insertions(+), 29 deletions(-) diff --git a/admin/jsps-admin.inc.php b/admin/jsps-admin.inc.php index db0bc3d..69dfb8f 100644 --- a/admin/jsps-admin.inc.php +++ b/admin/jsps-admin.inc.php @@ -1,10 +1,9 @@ '', '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 @@ -73,7 +72,7 @@ function juiz_sps_activation() { $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 @@ -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 @@ -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 ); } } } @@ -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 ) ); @@ -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'] ) ) { @@ -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"'; @@ -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 ) { @@ -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 '

@@ -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 = ''; $all_lists_selected = ''; if ( is_array( $options['juiz_sps_display_in_types'] ) ) { @@ -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'] ) ) @@ -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"'; @@ -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"'; @@ -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"'; @@ -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"'; @@ -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"' : ''; @@ -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"'; @@ -610,7 +609,7 @@ 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 ''; } @@ -618,7 +617,7 @@ function juiz_sps_setting_input_mail_subject() { } 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 ''; } diff --git a/juiz-social-post-sharer.php b/juiz-social-post-sharer.php index 61e7cfe..f244ef7 100644 --- a/juiz-social-post-sharer.php +++ b/juiz-social-post-sharer.php @@ -1,6 +1,6 @@ juiz_sps($array) template function or [juiz_sps] shortcode. For more informations see the setting page located in Settings submenu. Author: Geoffrey Crofte @@ -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' ); @@ -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 ) ) { @@ -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"' : ''; @@ -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'] ) ) { diff --git a/readme.txt b/readme.txt index 2a2d88f..320ef34 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=P39NJ 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 +Stable tag: 1.4.5 Add smart designed buttons after/before your posts to allow visitors sharing your content (includes no JavaScript mode & counters) From 6d97bde56d0314be511c15acbb3136dfc33e27a4 Mon Sep 17 00:00:00 2001 From: marie_comet Date: Wed, 15 Feb 2017 19:24:41 +0100 Subject: [PATCH 2/4] Readme update --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index b2eef48..71465c4 100644 --- a/README.md +++ b/README.md @@ -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/) From f2a20492f6f39e2ea31ae30b76e6ac009521511a Mon Sep 17 00:00:00 2001 From: marie_comet Date: Wed, 15 Feb 2017 19:29:33 +0100 Subject: [PATCH 3/4] Readme.txt update --- readme.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.txt b/readme.txt index 320ef34..2a2d88f 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=P39NJ 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.5 +Stable tag: 1.4.6 Add smart designed buttons after/before your posts to allow visitors sharing your content (includes no JavaScript mode & counters) From c05e8e35751909484bedd2e4a082e6459284e49c Mon Sep 17 00:00:00 2001 From: Geoffrey Crofte Date: Sun, 14 May 2017 16:44:53 +0200 Subject: [PATCH 4/4] Better naming for multisite compatibility (+ bug fix on THIS_PLUGIN_NETWORK_ACTIVATED) --- admin/jsps-admin.inc.php | 45 ++++++++------- juiz-social-post-sharer.php | 112 ++++++++++++++++++++---------------- readme.txt | 7 ++- uninstall.php | 3 +- 4 files changed, 94 insertions(+), 73 deletions(-) diff --git a/admin/jsps-admin.inc.php b/admin/jsps-admin.inc.php index 69dfb8f..b0afab7 100644 --- a/admin/jsps-admin.inc.php +++ b/admin/jsps-admin.inc.php @@ -1,9 +1,10 @@ '', '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 @@ -72,7 +73,7 @@ function juiz_sps_activation() { $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 @@ -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 @@ -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 ); } } } @@ -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 ) ); @@ -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'] ) ) { @@ -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"'; @@ -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 ) { @@ -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 '

@@ -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 = ''; $all_lists_selected = ''; if ( is_array( $options['juiz_sps_display_in_types'] ) ) { @@ -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'] ) ) @@ -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"'; @@ -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"'; @@ -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"'; @@ -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"'; @@ -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"' : ''; @@ -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"'; @@ -609,7 +610,7 @@ 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 ''; } @@ -617,7 +618,7 @@ function juiz_sps_setting_input_mail_subject() { } 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 ''; } diff --git a/juiz-social-post-sharer.php b/juiz-social-post-sharer.php index f244ef7..53db248 100644 --- a/juiz-social-post-sharer.php +++ b/juiz-social-post-sharer.php @@ -1,10 +1,10 @@ juiz_sps($array) template function or [juiz_sps] shortcode. For more informations see the setting page located in Settings 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 @@ -12,7 +12,7 @@ -Copyright 2012-2015 Geoffrey Crofte (email : support@creativejuiz.com) +Copyright 2012-2017 Geoffrey Crofte (email : support@creativejuiz.com) This program is free software; you can redistribute it and/or @@ -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; -// 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 ) { + $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 ) ) { + 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 ) ) { @@ -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 ) ) { @@ -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"' : ''; @@ -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'] ) ) { diff --git a/readme.txt b/readme.txt index 2a2d88f..5eeb8d9 100644 --- a/readme.txt +++ b/readme.txt @@ -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¤cy_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) @@ -144,6 +144,9 @@ Find my plugins at 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/)) diff --git a/uninstall.php b/uninstall.php index 9bc1c37..cfa011c 100644 --- a/uninstall.php +++ b/uninstall.php @@ -3,4 +3,5 @@ exit(); } -delete_option( 'juiz_SPS_settings' ); \ No newline at end of file +delete_option( 'juiz_SPS_settings' ); +delete_site_option( 'juiz_SPS_settings' ); \ No newline at end of file