Permalink
Browse files

change Subscribe button to Follow button

  • Loading branch information...
1 parent 7464246 commit 95998b5cfdeab8c4b904fe345a4b2eb412b14b41 @niallkennedy niallkennedy committed Dec 15, 2012
@@ -76,8 +76,8 @@ public static function migrate() {
self::migrate_send_button( $old_options['send'] );
if ( isset( $old_options['social_publisher'] ) )
self::migrate_social_publisher( $old_options['social_publisher'] );
- if ( isset( $old_options['subscribe'] ) )
- self::migrate_subscribe_button( $old_options['subscribe'] );
+ if ( isset( $old_options['follow'] ) )
+ self::migrate_follow_button( $old_options['follow'] );
}
/**
@@ -211,23 +211,23 @@ public static function migrate_social_publisher( $options ) {
}
/**
- * Migrate subscribe button settings
+ * Migrate follow button settings
*
* @since 1.1
* @param array $options existing settings
* @return result of update_option, if run
*/
- public static function migrate_subscribe_button( $options ) {
+ public static function migrate_follow_button( $options ) {
if ( ! is_array( $options ) || empty( $options ) )
return;
$options = self::show_on( $options );
- if ( ! class_exists( 'Facebook_Subscribe_Button_Settings' ) )
- require_once( dirname(__FILE__) . '/settings-subscribe-button.php' );
- $options = Facebook_Subscribe_Button_Settings::sanitize_options( $options );
+ if ( ! class_exists( 'Facebook_Follow_Button_Settings' ) )
+ require_once( dirname(__FILE__) . '/settings-follow-button.php' );
+ $options = Facebook_Follow_Button_Settings::sanitize_options( $options );
if ( ! empty( $options ) )
- return update_option( Facebook_Subscribe_Button_Settings::OPTION_NAME, $options );
+ return update_option( Facebook_Follow_Button_Settings::OPTION_NAME, $options );
}
}
?>
@@ -31,7 +31,7 @@ public static function comments_settings() {
$comments_options = get_option( Facebook_Comments_Settings::OPTION_NAME );
if ( ! is_array( $comments_options ) )
$comments_options = array();
- $comments_options['show_on'] = Facebook_Comments_Settings::get_display_conditionals_by_feature( 'comments', 'posts' );
+ $comments_options['show_on'] = array_keys( Facebook_Comments_Settings::get_display_conditionals_by_feature( 'comments', 'posts' ) );
update_option( Facebook_Comments_Settings::OPTION_NAME, Facebook_Comments_Settings::sanitize_options( $comments_options ) );
}
@@ -0,0 +1,102 @@
+<?php
+/**
+ * Change Subscribe Button to Follow Button
+ *
+ * @since 1.1.9
+ */
+class Facebook_Migrate_Options_118 {
+
+ /**
+ * Store subscribe button options as follow button options
+ *
+ * @since 1.1.9
+ */
+ public static function update_option() {
+ $options = get_option( 'facebook_subscribe_button' );
+ if ( ! is_array( $options ) )
+ return false;
+
+ update_option( 'facebook_follow_button', $options );
+ }
+
+ /**
+ * Iterate through possible view types for subscribe button
+ * Change subscribe to follow if found
+ *
+ * @since 1.1.9
+ */
+ public static function update_views() {
+ if ( ! class_exists( 'Facebook_Follow_Button_Settings' ) )
+ require_once( dirname(__FILE__) . '/settings-follow-button.php' );
+
+ // archives + post types
+ $all_possible_display_types = Facebook_Social_Plugin_Settings::get_show_on_choices( 'all' );
+ // archives + post types supporting authorship
+ $follow_display_types = Facebook_Follow_Button_Settings::get_show_on_choices();
+ // iterate through all display types, looking for our feature in each
+ foreach ( $all_possible_display_types as $display_type ) {
+ $option_name = "facebook_{$display_type}_features";
+ $display_preferences = get_option( $option_name );
+ if ( ! is_array( $display_preferences ) )
+ continue;
+
+ if ( isset( $display_preferences['subscribe'] ) ) {
+ unset( $display_preferences['subscribe'] );
+
+ // remove any post types not supporting authorship
+ if ( in_array( $display_type, $follow_display_types, true ) )
+ $display_preferences['follow'] = true;
+
+ // save new values
+ update_option( $option_name, $display_preferences );
+ }
+
+ unset( $option_name );
+ unset( $display_preferences );
+ }
+ }
+
+ /**
+ * Update subscribe widget instances to follow widget instances
+ *
+ * @since 1.1.9
+ */
+ public static function update_widgets() {
+ $sidebars = wp_get_sidebars_widgets();
+ if ( ! is_array( $sidebars ) )
+ return;
+
+ $found_widgets = false;
+
+ foreach ( $sidebars as $sidebar => $widgets ) {
+ foreach ( $widgets as $position => $widget_id ) {
+ if ( substr_compare( $widget_id, 'facebook-subscribe', 0, 18 ) === 0 ) {
+ $sidebars[$sidebar][$position] = 'facebook-follow' . substr( $widget_id, strrpos( $widget_id, '-' ) );
+ $found_widgets = true;
+ }
+ }
+ }
+
+ if ( $found_widgets ) {
+ $existing_instances = get_option( 'widget_facebook-subscribe' );
+ if ( is_array( $existing_instances ) )
+ update_option( 'widget_facebook-follow', $existing_instances );
+ if ( $existing_instances !== false )
+ delete_option( 'widget_facebook-subscribe' );
+ unset( $existing_instances );
+ wp_set_sidebars_widgets( $sidebars );
+ }
+ }
+
+ /**
+ * Migrate subscribe to follow
+ *
+ * @since 1.1.9
+ */
+ public static function migrate() {
+ self::update_option();
+ self::update_views();
+ self::update_widgets();
+ }
+}
+?>
View
@@ -296,9 +296,9 @@ public static function enabled_features_by_view_type() {
'name' => __( 'Send Button', 'facebook' ),
'url' => 'https://developers.facebook.com/docs/reference/plugins/send/'
),
- 'subscribe' => array(
- 'name' => __( 'Subscribe Button', 'facebook' ),
- 'url' => 'https://developers.facebook.com/docs/reference/plugins/subscribe/'
+ 'follow' => array(
+ 'name' => __( 'Follow Button', 'facebook' ),
+ 'url' => 'https://developers.facebook.com/docs/reference/plugins/follow/'
),
'recommendations_bar' => array(
'name' => __( 'Recommendations Bar', 'facebook' ),
@@ -374,9 +374,9 @@ public static function widgets_section() {
'name' => __( 'Send Button', 'facebook' ),
'url' => 'https://developers.facebook.com/docs/reference/plugins/send/'
),
- 'subscribe' => array(
- 'name' => __( 'Subscribe Button', 'facebook' ),
- 'url' => 'https://developers.facebook.com/docs/reference/plugins/subscribe/'
+ 'follow' => array(
+ 'name' => __( 'Follow Button', 'facebook' ),
+ 'url' => 'https://developers.facebook.com/docs/reference/plugins/follow/'
)
);
Oops, something went wrong.

0 comments on commit 95998b5

Please sign in to comment.