/** * Register our default taxonomies. * * @since 2.2.0 */ function bp_register_default_taxonomies() { // Member Type. register_taxonomy(bp_get_member_type_tax_name(), 'user', array('public' => false)); // Email type. register_taxonomy(bp_get_email_tax_type(), bp_get_email_post_type(), apply_filters('bp_register_email_tax_type', array('description' => _x('BuddyPress email types', 'email type taxonomy description', 'buddypress'), 'labels' => bp_get_email_tax_type_labels(), 'meta_box_cb' => 'bp_email_tax_type_metabox', 'public' => false, 'query_var' => false, 'rewrite' => false, 'show_in_menu' => false, 'show_tagcloud' => false, 'show_ui' => bp_is_root_blog() && bp_current_user_can('bp_moderate')))); }
/** * Display metabox for email taxonomy type. * * Shows the term description in a list, rather than the term name itself. * * @since 2.5.0 * * @param WP_Post $post Post object. * @param array $box { * Tags meta box arguments. * * @type string $id Meta box ID. * @type string $title Meta box title. * @type callable $callback Meta box display callback. * } */ function bp_email_tax_type_metabox($post, $box) { $r = array('taxonomy' => bp_get_email_tax_type()); $tax_name = esc_attr($r['taxonomy']); $taxonomy = get_taxonomy($r['taxonomy']); ?> <div id="taxonomy-<?php echo $tax_name; ?> " class="categorydiv"> <div id="<?php echo $tax_name; ?> -all" class="tabs-panel"> <?php $name = $tax_name == 'category' ? 'post_category' : 'tax_input[' . $tax_name . ']'; echo "<input type='hidden' name='{$name}[]' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks. ?> <ul id="<?php echo $tax_name; ?> checklist" data-wp-lists="list:<?php echo $tax_name; ?> " class="categorychecklist form-no-clear"> <?php wp_terms_checklist($post->ID, array('taxonomy' => $tax_name, 'walker' => new BP_Walker_Category_Checklist())); ?> </ul> </div> <p><?php esc_html_e('Choose when this email will be sent.', 'buddypress'); ?> </p> </div> <?php }
/** * @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); } }
/** * 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'); }
/** * Delete emails and restore from defaults. * * @since 2.5.0 * * @return array */ function bp_admin_reinstall_emails() { $switched = false; // Switch to the root blog, where the email posts live. if (!bp_is_root_blog()) { switch_to_blog(bp_get_root_blog_id()); bp_register_taxonomies(); $switched = true; } $emails = get_posts(array('fields' => 'ids', 'post_status' => 'publish', 'post_type' => bp_get_email_post_type(), 'posts_per_page' => 200, 'suppress_filters' => false)); if ($emails) { foreach ($emails as $email_id) { wp_trash_post($email_id); } } // Make sure we have no orphaned email type terms. $email_types = get_terms(bp_get_email_tax_type(), array('fields' => 'ids', 'hide_empty' => false, 'update_term_meta_cache' => false)); if ($email_types) { foreach ($email_types as $term_id) { wp_delete_term((int) $term_id, bp_get_email_tax_type()); } } require_once buddypress()->plugin_dir . '/bp-core/admin/bp-core-admin-schema.php'; bp_core_install_emails(); if ($switched) { restore_current_blog(); } return array(0, __('Emails have been successfully reinstalled.', 'buddypress')); }
/** * Output column data for our custom 'Situations' column. * * @since 2.6.0 * * @param string $column Current column name. * @param int $post_id Current post ID. */ public function emails_display_situation_column_data($column = '', $post_id = 0) { if ('situation' !== $column) { return; } // Grab email situations for the current post. $situations = wp_list_pluck(get_the_terms($post_id, bp_get_email_tax_type()), 'description'); // Output each situation as a list item. echo '<ul><li>'; echo implode('</li><li>', $situations); echo '</li></ul>'; }
/** * Get an BP_Email object for the specified email type. * * This function pre-populates the object with the subject, content, and template from the appropriate * email post type item. It does not replace placeholder tokens in the content with real values. * * @since 2.5.0 * * @param string $email_type Unique identifier for a particular type of email. * @return BP_Email|WP_Error BP_Email object, or WP_Error if there was a problem. */ function bp_get_email($email_type) { $switched = false; // Switch to the root blog, where the email posts live. if (!bp_is_root_blog()) { switch_to_blog(bp_get_root_blog_id()); $switched = true; } $args = array('no_found_rows' => true, 'numberposts' => 1, 'post_status' => 'publish', 'post_type' => bp_get_email_post_type(), 'suppress_filters' => false, 'tax_query' => array(array('field' => 'slug', 'taxonomy' => bp_get_email_tax_type(), 'terms' => $email_type))); /** * Filters arguments used to find an email post type object. * * @since 2.5.0 * * @param array $args Arguments for get_posts() used to fetch a post object. * @param string $email_type Unique identifier for a particular type of email. */ $args = apply_filters('bp_get_email_args', $args, $email_type); $post = get_posts($args); if (!$post) { if ($switched) { restore_current_blog(); } return new WP_Error('missing_email', __FUNCTION__, array($email_type, $args)); } /** * Filters arguments used to create the BP_Email object. * * @since 2.5.0 * * @param WP_Post $post Post object containing the contents of the email. * @param string $email_type Unique identifier for a particular type of email. * @param array $args Arguments used with get_posts() to fetch a post object. * @param WP_Post $post All posts retrieved by get_posts( $args ). May only contain $post. */ $post = apply_filters('bp_get_email_post', $post[0], $email_type, $args, $post); $email = new BP_Email($email_type); /* * Set some email properties for convenience. */ // Post object (sets subject, content, template). $email->set_post_object($post); /** * Filters the BP_Email object returned by bp_get_email(). * * @since 2.5.0 * * @param BP_Email $email An object representing a single email, ready for mailing. * @param string $email_type Unique identifier for a particular type of email. * @param array $args Arguments used with get_posts() to fetch a post object. * @param WP_Post $post All posts retrieved by get_posts( $args ). May only contain $post. */ $retval = apply_filters('bp_get_email', $email, $email_type, $args, $post); if ($switched) { restore_current_blog(); } return $retval; }
/** * 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 = array('activity-comment' => array('post_title' => __('[{{{site.name}}}] {{poster.name}} replied to one of your updates', 'buddypress'), 'post_content' => __("{{poster.name}} replied to one of your updates:\n\n<blockquote>"{{usermessage}}"</blockquote>\n\n<a href=\"{{{thread.url}}}\">Go to the discussion</a> to reply or catch up on the conversation.", 'buddypress'), 'post_excerpt' => __("{{poster.name}} replied to one of your updates:\n\n\"{{usermessage}}\"\n\nGo to the discussion to reply or catch up on the conversation: {{{thread.url}}}", 'buddypress')), 'activity-comment-author' => array('post_title' => __('[{{{site.name}}}] {{poster.name}} replied to one of your comments', 'buddypress'), 'post_content' => __("{{poster.name}} replied to one of your comments:\n\n<blockquote>"{{usermessage}}"</blockquote>\n\n<a href=\"{{{thread.url}}}\">Go to the discussion</a> to reply or catch up on the conversation.", 'buddypress'), 'post_excerpt' => __("{{poster.name}} replied to one of your comments:\n\n\"{{usermessage}}\"\n\nGo to the discussion to reply or catch up on the conversation: {{{thread.url}}}", 'buddypress')), 'activity-at-message' => array('post_title' => __('[{{{site.name}}}] {{poster.name}} mentioned you in a status update', 'buddypress'), 'post_content' => __("{{poster.name}} mentioned you in a status update:\n\n<blockquote>"{{usermessage}}"</blockquote>\n\n<a href=\"{{{mentioned.url}}}\">Go to the discussion</a> to reply or catch up on the conversation.", 'buddypress'), 'post_excerpt' => __("{{poster.name}} mentioned you in a status update:\n\n\"{{usermessage}}\"\n\nGo to the discussion to reply or catch up on the conversation: {{{mentioned.url}}}", 'buddypress')), 'groups-at-message' => array('post_title' => __('[{{{site.name}}}] {{poster.name}} mentioned you in an update', 'buddypress'), 'post_content' => __("{{poster.name}} mentioned you in the group \"{{group.name}}\":\n\n<blockquote>"{{usermessage}}"</blockquote>\n\n<a href=\"{{{mentioned.url}}}\">Go to the discussion</a> to reply or catch up on the conversation.", 'buddypress'), 'post_excerpt' => __("{{poster.name}} mentioned you in the group \"{{group.name}}\":\n\n\"{{usermessage}}\"\n\nGo to the discussion to reply or catch up on the conversation: {{{mentioned.url}}}", 'buddypress')), 'core-user-registration' => array('post_title' => __('[{{{site.name}}}] Activate your account', 'buddypress'), 'post_content' => __("Thanks for registering!\n\nTo complete the activation of your account, go to the following link: <a href=\"{{{activate.url}}}\">{{{activate.url}}}</a>", 'buddypress'), 'post_excerpt' => __("Thanks for registering!\n\nTo complete the activation of your account, go to the following link: {{{activate.url}}}", 'buddypress')), 'core-user-registration-with-blog' => array('post_title' => __('[{{{site.name}}}] Activate {{{user-site.url}}}', 'buddypress'), 'post_content' => __("Thanks for registering!\n\nTo complete the activation of your account and site, go to the following link: <a href=\"{{{activate-site.url}}}\">{{{activate-site.url}}}</a>.\n\nAfter you activate, you can visit your site at <a href=\"{{{user-site.url}}}\">{{{user-site.url}}}</a>.", 'buddypress'), 'post_excerpt' => __("Thanks for registering!\n\nTo complete the activation of your account and site, go to the following link: {{{activate-site.url}}}\n\nAfter you activate, you can visit your site at {{{user-site.url}}}.", 'buddypress')), 'friends-request' => array('post_title' => __('[{{{site.name}}}] New friendship request from {{initiator.name}}', 'buddypress'), 'post_content' => __("<a href=\"{{{initiator.url}}}\">{{initiator.name}}</a> wants to add you as a friend.\n\nTo accept this request and manage all of your pending requests, visit: <a href=\"{{{friend-requests.url}}}\">{{{friend-requests.url}}}</a>", 'buddypress'), 'post_excerpt' => __("{{initiator.name}} wants to add you as a friend.\n\nTo accept this request and manage all of your pending requests, visit: {{{friend-requests.url}}}\n\nTo view {{initiator.name}}'s profile, visit: {{{initiator.url}}}", 'buddypress')), 'friends-request-accepted' => array('post_title' => __('[{{{site.name}}}] {{friend.name}} accepted your friendship request', 'buddypress'), 'post_content' => __("<a href=\"{{{friendship.url}}}\">{{friend.name}}</a> accepted your friend request.", 'buddypress'), 'post_excerpt' => __("{{friend.name}} accepted your friend request.\n\nTo learn more about them, visit their profile: {{{friendship.url}}}", 'buddypress')), 'groups-details-updated' => array('post_title' => __('[{{{site.name}}}] Group details updated', 'buddypress'), 'post_content' => __("Group details for the group "<a href=\"{{{group.url}}}\">{{group.name}}</a>" were updated:\n<blockquote>{{changed_text}}</blockquote>", 'buddypress'), 'post_excerpt' => __("Group details for the group "{{group.name}}" were updated:\n\n{{changed_text}}\n\nTo view the group, visit: {{{group.url}}}", 'buddypress')), 'groups-invitation' => array('post_title' => __('[{{{site.name}}}] You have an invitation to the group: "{{group.name}}"', 'buddypress'), 'post_content' => __("<a href=\"{{{inviter.url}}}\">{{inviter.name}}</a> has invited you to join the group: "{{group.name}}".\n<a href=\"{{{invites.url}}}\">Go here to accept your invitation</a> or <a href=\"{{{group.url}}}\">visit the group</a> to learn more.", 'buddypress'), 'post_excerpt' => __("{{inviter.name}} has invited you to join the group: "{{group.name}}".\n\nTo accept your invitation, visit: {{{invites.url}}}\n\nTo learn more about the group, visit {{{group.url}}}.\nTo view {{inviter.name}}'s profile, visit: {{{inviter.url}}}", 'buddypress')), 'groups-member-promoted' => array('post_title' => __('[{{{site.name}}}] You have been promoted in the group: "{{group.name}}"', 'buddypress'), 'post_content' => __("You have been promoted to <b>{{promoted_to}}</b> in the group "<a href=\"{{{group.url}}}\">{{group.name}}</a>".", 'buddypress'), 'post_excerpt' => __("You have been promoted to {{promoted_to}} in the group: "{{group.name}}".\n\nTo visit the group, go to: {{{group.url}}}", 'buddypress')), 'groups-membership-request' => array('post_title' => __('[{{{site.name}}}] Membership request for group: {{group.name}}', 'buddypress'), 'post_content' => __("<a href=\"{{{profile.url}}}\">{{requesting-user.name}}</a> wants to join the group "{{group.name}}". As you are an administrator of this group, you must either accept or reject the membership request.\n\n<a href=\"{{{group-requests.url}}}\">Go here to manage this</a> and all other pending requests.", 'buddypress'), 'post_excerpt' => __("{{requesting-user.name}} wants to join the group "{{group.name}}". As you are the administrator of this group, you must either accept or reject the membership request.\n\nTo manage this and all other pending requests, visit: {{{group-requests.url}}}\n\nTo view {{requesting-user.name}}'s profile, visit: {{{profile.url}}}", 'buddypress')), 'messages-unread' => array('post_title' => __('[{{{site.name}}}] New message from {{sender.name}}', 'buddypress'), 'post_content' => __("{{sender.name}} sent you a new message: "{{usersubject}}"\n\n<blockquote>"{{usermessage}}"</blockquote>\n\n<a href=\"{{{message.url}}}\">Go to the discussion</a> to reply or catch up on the conversation.", 'buddypress'), 'post_excerpt' => __("{{sender.name}} sent you a new message: "{{usersubject}}"\n\n"{{usermessage}}"\n\nGo to the discussion to reply or catch up on the conversation: {{{message.url}}}", 'buddypress')), 'settings-verify-email-change' => array('post_title' => __('[{{{site.name}}}] Verify your new email address', 'buddypress'), 'post_content' => __("You recently changed the email address associated with your account on {{site.name}}. If this is correct, <a href=\"{{{verify.url}}}\">go here to confirm the change</a>.\n\nOtherwise, you can safely ignore and delete this email if you have changed your mind, or if you think you have received this email in error.", 'buddypress'), 'post_excerpt' => __("You recently changed the email address associated with your account on {{site.name}}. If this is correct, go to the following link to confirm the change: {{{verify.url}}}\n\nOtherwise, you can safely ignore and delete this email if you have changed your mind, or if you think you have received this email in error.", 'buddypress')), 'groups-membership-request-accepted' => array('post_title' => __('[{{{site.name}}}] Membership request for group "{{group.name}}" accepted', 'buddypress'), 'post_content' => __("Your membership request for the group "<a href=\"{{{group.url}}}\">{{group.name}}</a>" has been accepted.", 'buddypress'), 'post_excerpt' => __("Your membership request for the group "{{group.name}}" has been accepted.\n\nTo view the group, visit: {{{group.url}}}", 'buddypress')), 'groups-membership-request-rejected' => array('post_title' => __('[{{{site.name}}}] Membership request for group "{{group.name}}" rejected', 'buddypress'), 'post_content' => __("Your membership request for the group "<a href=\"{{{group.url}}}\">{{group.name}}</a>" has been rejected.", 'buddypress'), 'post_excerpt' => __("Your membership request for the group "{{group.name}}" has been rejected.\n\nTo request membership again, visit: {{{group.url}}}", 'buddypress'))); $descriptions = array('activity-comment' => __('A member has replied to an activity update that the recipient posted.', 'buddypress'), 'activity-comment-author' => __('A member has replied to a comment on an activity update that the recipient posted.', 'buddypress'), 'activity-at-message' => __('Recipient was mentioned in an activity update.', 'buddypress'), 'groups-at-message' => __('Recipient was mentioned in a group activity update.', 'buddypress'), 'core-user-registration' => __('Recipient has registered for an account.', 'buddypress'), 'core-user-registration-with-blog' => __('Recipient has registered for an account and site.', 'buddypress'), 'friends-request' => __('A member has sent a friend request to the recipient.', 'buddypress'), 'friends-request-accepted' => __('Recipient has had a friend request accepted by a member.', 'buddypress'), 'groups-details-updated' => __("A group's details were updated.", 'buddypress'), 'groups-invitation' => __('A member has sent a group invitation to the recipient.', 'buddypress'), 'groups-member-promoted' => __("Recipient's status within a group has changed.", 'buddypress'), 'groups-membership-request' => __('A member has requested permission to join a group.', 'buddypress'), 'messages-unread' => __('Recipient has received a private message.', 'buddypress'), 'settings-verify-email-change' => __('Recipient has changed their email address.', 'buddypress'), 'groups-membership-request-accepted' => __('Recipient had requested to join a group, which was accepted.', 'buddypress'), 'groups-membership-request-rejected' => __('Recipient had requested to join a group, which was rejected.', 'buddypress')); // 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; } $term_ids = wp_set_post_terms($post_id, $id, bp_get_email_tax_type()); foreach ($term_ids as $term_id) { wp_update_term((int) $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'); }
/** * For non-RBE emails, we now add a line above each message denoting that the * email is not one you can reply to. * * However, there are instances where we do not want to add this line. * * This method disables this line when: * - An email is sent from the admin area * - An activation email is sent * * @since 1.0-RC2 * * @param bool $retval Should we disable the non-RBE notice? * @param array $args Email args passed by the 'wp_mail' filter * @return bool */ public function disable_non_rbe_notice($retval, $args) { // if explicitly showing non-rbe notice, return true if (isset($this->show_non_rbe_notice)) { unset($this->show_non_rbe_notice); return true; } // don't do this in the admin area if (is_admin()) { return false; } // do not add the notice to activation emails // check the subject line and look for the activation subject text if (strpos($args['subject'], __('Activate Your Account', 'buddypress')) !== false || strpos($args['subject'], __('Activate %s', 'buddypress')) !== false) { return false; } // BP post type version check for activation emails. if (isset($args['post']) && $args['post'] instanceof WP_Post) { $terms = get_the_terms($args['post'], bp_get_email_tax_type()); if (!empty($terms[0]) && false !== strpos($terms[0]->slug, 'core-user-registration')) { return false; } } return $retval; }