/** * Add default emails. * * @since 2.5.0 */ function bp_core_install_emails() { $defaults = array('post_status' => 'publish', 'post_type' => bp_get_email_post_type()); $emails = bp_email_get_schema(); $descriptions = bp_email_get_type_schema(); // Add these emails to the database. foreach ($emails as $id => $email) { $post_id = wp_insert_post(bp_parse_args($email, $defaults, 'install_email_' . $id)); if (!$post_id) { continue; } $tt_ids = wp_set_object_terms($post_id, $id, bp_get_email_tax_type()); foreach ($tt_ids as $tt_id) { $term = get_term_by('term_taxonomy_id', (int) $tt_id, bp_get_email_tax_type()); wp_update_term((int) $term->term_id, bp_get_email_tax_type(), array('description' => $descriptions[$id])); } } /** * Fires after BuddyPress adds the posts for its emails. * * @since 2.5.0 */ do_action('bp_core_install_emails'); }
/** * @ticket BP6936 */ public function test_email_type_descriptions_should_match_when_split_terms_exist() { global $wpdb; // Delete all existing email types and descriptions. $emails = get_posts(array('fields' => 'ids', 'post_type' => bp_get_email_post_type())); foreach ($emails as $email) { wp_delete_post($email, true); } $descriptions = get_terms(bp_get_email_tax_type(), array('fields' => 'ids', 'hide_empty' => false)); foreach ($descriptions as $description) { wp_delete_term((int) $description, bp_get_email_tax_type()); } // Fake the existence of split terms by offsetting the term_taxonomy table. $wpdb->insert($wpdb->term_taxonomy, array('term_id' => 9999, 'taxonomy' => 'post_tag', 'description' => 'foo description', 'parent' => 0, 'count' => 0)); require_once BP_PLUGIN_DIR . '/bp-core/admin/bp-core-admin-schema.php'; bp_core_install_emails(); $d_terms = get_terms(bp_get_email_tax_type(), array('hide_empty' => false)); $correct_descriptions = bp_email_get_type_schema(); foreach ($d_terms as $d_term) { $correct_description = $correct_descriptions[$d_term->slug]; $this->assertSame($correct_description, $d_term->description); } }
/** * Creates unsubscribe link for notification emails. * * @since 2.7.0 * * @param string $redirect_to The URL to which the unsubscribe query string is appended. * @param array $args { * Used to build unsubscribe query string. * * @type string $notification_type Which notification type is being sent. * @type string $user_id The ID of the user to whom the notification is sent. * @type string $redirect_to Optional. The url to which the user will be redirected. Default is the activity directory. * } * @return string The unsubscribe link. */ function bp_email_get_unsubscribe_link($args) { $emails = bp_email_get_type_schema('all'); if (empty($args['notification_type']) || !array_key_exists($args['notification_type'], $emails)) { return site_url('wp-login.php'); } $email_type = $args['notification_type']; $redirect_to = !empty($args['redirect_to']) ? $args['redirect_to'] : site_url(); $user_id = (int) $args['user_id']; // Bail out if the activity type is not un-unsubscribable. if (empty($emails[$email_type]['unsubscribe'])) { return ''; } $link = add_query_arg(array('action' => 'unsubscribe', 'nh' => hash_hmac('sha1', "{$email_type}:{$user_id}", bp_email_get_salt()), 'nt' => $args['notification_type'], 'uid' => $user_id), $redirect_to); /** * Filters the unsubscribe link. * * @since 2.7.0 */ return apply_filters('bp_email_get_link', $link, $redirect_to, $args); }