From 5a4bf1195d10ae92a2f726e19839a84cfcdf9f6a Mon Sep 17 00:00:00 2001 From: yannbug Date: Wed, 21 Aug 2013 03:17:57 -0700 Subject: [PATCH] Proposed improvements for actual initialization of default settings for forum subscription. --- ...ctivity-subscription-forum-notif-inits.php | 52 +++++++++++++++++++ bp-activity-subscription-main.php | 7 +++ bp-activity-subscription.php | 10 ++-- readme.txt | 4 ++ 4 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 bp-activity-subscription-forum-notif-inits.php diff --git a/bp-activity-subscription-forum-notif-inits.php b/bp-activity-subscription-forum-notif-inits.php new file mode 100644 index 0000000..7ac484a --- /dev/null +++ b/bp-activity-subscription-forum-notif-inits.php @@ -0,0 +1,52 @@ +notifications page + * for all existing users upon plugin installation + * only add the following options if BP's bundled forums are installed... + * + * @see bp-activity-subscription-functions.php line 2014, function ass_group_subscription_notification_settings() + * called by bp-activity-subscription.php line 77 during plugin activation + * + * @return true if success, false if failure (not used) + */ +function ass_forum_notif_activation_init() { + + require_once( WP_PLUGIN_DIR.'/buddypress-group-email-subscription/bp-activity-subscription-functions.php' ); + + // get forum type + $forums = ass_get_forum_type(); + + // no forums installed? stop now! + if ( ! $forums ) { + return false; + } + + if ( $forums == 'buddypress' ) : + + $all_existing_users = get_users( array( 'fields'=>'ID' ) ); + //trigger_error( 'debug:' . serialize( $all_existing_users ) ); //debug YD + + if( count( $all_existing_users ) > 1000 ) + return false; //we risk performance issue, so just don't try + + foreach( $all_existing_users as $user ) { + add_user_meta( $user, 'ass_replies_to_my_topic', 'yes', true); + add_user_meta( $user, 'ass_replies_after_me_topic', 'yes', true); + } + + endif; + return true; +} + +/** + * Initializes forum notification options in the users settings->notifications page + * for a newly registered user, after plugin has been installed + * + * called by the user_register hook + * @see bp-activity-subscription-main.php line 66 in the plugin's main class constructor function + */ +function ass_forum_notif_new_user_init( $user_id ) { + add_user_meta( $user_id, 'ass_replies_to_my_topic', 'yes', true); + add_user_meta( $user_id, 'ass_replies_after_me_topic', 'yes', true); +} +?> \ No newline at end of file diff --git a/bp-activity-subscription-main.php b/bp-activity-subscription-main.php index b196018..d2c021a 100644 --- a/bp-activity-subscription-main.php +++ b/bp-activity-subscription-main.php @@ -58,6 +58,13 @@ function group_activity_subscription() { // hook in the css and js add_action( 'wp_print_styles', array( &$this , 'add_settings_stylesheet' ) ); add_action( 'wp_enqueue_scripts', array( &$this , 'ass_add_javascript' ),1 ); + + // hook in the new user forum notification default settings initialization + $forums = ass_get_forum_type(); + if( $forums == 'buddypress' ) { + require_once( WP_PLUGIN_DIR.'/buddypress-group-email-subscription/bp-activity-subscription-forum-notif-inits.php' ); + add_action('user_register', 'ass_forum_notif_new_user_init'); + } } public function add_settings_stylesheet() { diff --git a/bp-activity-subscription.php b/bp-activity-subscription.php index 97243ea..483fa09 100644 --- a/bp-activity-subscription.php +++ b/bp-activity-subscription.php @@ -3,9 +3,9 @@ Plugin Name: BuddyPress Group Email Subscription Plugin URI: http://wordpress.org/extend/plugins/buddypress-group-email-subscription/ Description: Allows group members to receive email notifications for group activity and forum posts instantly or as daily digest or weekly summary. -Author: Deryk Wenaus, boonebgorges, r-a-y -Revision Date: July 24, 2013 -Version: 3.4-alpha +Author: Deryk Wenaus, boonebgorges, r-a-y, ydubois +Revision Date: August 21, 2013 +Version: 3.5-yd */ /** @@ -71,6 +71,10 @@ function activitysub_setup_digest_defaults() { require_once( WP_PLUGIN_DIR.'/buddypress-group-email-subscription/bp-activity-subscription-digest.php' ); ass_set_daily_digest_time( '05', '00' ); ass_set_weekly_digest_time( '4' ); + + /** forum default email notification settings initializations **/ + require_once( WP_PLUGIN_DIR.'/buddypress-group-email-subscription/bp-activity-subscription-forum-notif-inits.php' ); + ass_forum_notif_activation_init(); } register_activation_hook( __FILE__, 'activitysub_setup_digest_defaults' ); diff --git a/readme.txt b/readme.txt index 4a85b8f..55f360c 100644 --- a/readme.txt +++ b/readme.txt @@ -88,6 +88,10 @@ For bug reports or to add patches or translation files, please visit the [GES Gi == Changelog == += 3.5 = +* Initializes forum subscription default settings of existing users upon plugin installation +* Initializes forum subscription default settings of new registered users after plugin installation + = 3.4 = * Reinstate bbPress "Subscribe" option in forum threads for group members not subscribed to "All Mail" * Performance improvements in daily and weekly digests