コード例 #1
0
/**
 * 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'))));
}
コード例 #2
0
 public static function tearDownAfterClass()
 {
     $emails = get_posts(array('fields' => 'ids', 'post_status' => 'any', 'post_type' => bp_get_email_post_type(), 'posts_per_page' => 200, 'suppress_filters' => false));
     if ($emails) {
         foreach ($emails as $email_id) {
             wp_delete_post($email_id, true);
         }
     }
     parent::tearDownAfterClass();
 }
コード例 #3
0
/**
 * In emails editor, add notice linking to token documentation on Codex.
 *
 * @since 2.5.0
 */
function bp_admin_email_add_codex_notice()
{
    if (get_current_screen()->post_type !== bp_get_email_post_type()) {
        return;
    }
    bp_core_add_admin_notice(sprintf(__('Phrases wrapped in braces <code>{{ }}</code> are email tokens. <a href="%s">Learn about tokens on the BuddyPress Codex</a>.', 'buddypress'), esc_url('https://codex.buddypress.org/emails/email-tokens/')), 'error');
}
コード例 #4
0
ファイル: functions.php プロジェクト: dcavins/buddypress-svn
 /**
  * @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);
     }
 }
コード例 #5
0
/**
 * 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');
}
コード例 #6
0
 /**
  * Add Emails menu item to custom menus array.
  *
  * Several BuddyPress components have top-level menu items in the Dashboard,
  * which all appear together in the middle of the Dashboard menu. This function
  * adds the Emails screen to the array of these menu items.
  *
  * @since 2.4.0
  *
  * @param array $custom_menus The list of top-level BP menu items.
  * @return array $custom_menus List of top-level BP menu items, with Emails added.
  */
 public function emails_admin_menu_order($custom_menus = array())
 {
     array_push($custom_menus, 'edit.php?post_type=' . bp_get_email_post_type());
     if (is_network_admin() && bp_is_network_activated()) {
         array_push($custom_menus, get_admin_url(bp_get_root_blog_id(), 'edit.php?post_type=' . bp_get_email_post_type()));
     }
     return $custom_menus;
 }
コード例 #7
0
/**
 * 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'));
}
コード例 #8
0
/**
 * Find and render the template for Email posts (the Customizer and admin previews).
 *
 * Misuses the `template_include` filter which expects a string, but as we need to replace
 * the `{{{content}}}` token with the post's content, we use object buffering to load the
 * template, replace the token, and render it.
 *
 * The function returns an empty string to prevent WordPress rendering another template.
 *
 * @since 2.5.0
 *
 * @param string $template Path to template (probably single.php).
 * @return string
 */
function bp_core_render_email_template($template)
{
    if (get_post_type() !== bp_get_email_post_type() || !is_single()) {
        return $template;
    }
    /**
     * Filter template used to display Email posts.
     *
     * @since 2.5.0
     *
     * @param string $template Path to current template (probably single.php).
     */
    $email_template = apply_filters('bp_core_render_email_template', bp_locate_template(bp_email_get_template(get_queried_object()), false), $template);
    if (!$email_template) {
        return $template;
    }
    ob_start();
    include $email_template;
    $template = ob_get_contents();
    ob_end_clean();
    // Make sure we add a <title> tag so WP Customizer picks it up.
    $template = str_replace('<head>', '<head><title>' . esc_html_x('BuddyPress Emails', 'screen heading', 'buddypress') . '</title>', $template);
    echo str_replace('{{{content}}}', nl2br(get_post()->post_content), $template);
    /*
     * Link colours are applied directly in the email template before sending, so we
     * need to add an extra style here to set the colour for the Customizer or preview.
     */
    $settings = bp_email_get_appearance_settings();
    printf('<style>a { color: %s; }</style>', esc_attr($settings['highlight_color']));
    return '';
}
コード例 #9
0
/**
 * 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;
}
コード例 #10
0
/**
 * Implements a JS redirect to the Customizer, previewing a randomly selected email.
 *
 * @since 2.5.0
 */
function bp_email_redirect_to_customizer()
{
    $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;
    }
    $email = get_posts(array('fields' => 'ids', 'orderby' => 'rand', 'post_status' => 'publish', 'post_type' => bp_get_email_post_type(), 'posts_per_page' => 1, 'suppress_filters' => false));
    $preview_url = admin_url();
    if ($email) {
        $preview_url = get_post_permalink($email[0]) . '&bp_customizer=email';
    }
    $redirect_url = add_query_arg(array('autofocus[panel]' => 'bp_mailtpl', 'bp_customizer' => 'email', 'return' => rawurlencode(admin_url()), 'url' => rawurlencode($preview_url)), admin_url('customize.php'));
    if ($switched) {
        restore_current_blog();
    }
    printf('<script type="text/javascript">window.location = "%s";</script>', esc_url_raw($redirect_url));
    exit;
}
コード例 #11
0
 /**
  * Set up post types.
  *
  * @since BuddyPress (2.4.0)
  */
 public function register_post_types()
 {
     // Emails
     if (bp_is_root_blog() && !is_network_admin()) {
         register_post_type(bp_get_email_post_type(), apply_filters('bp_register_email_post_type', array('description' => _x('BuddyPress emails', 'email post type description', 'buddypress'), 'labels' => bp_get_email_post_type_labels(), 'menu_icon' => 'dashicons-email', 'public' => false, 'publicly_queryable' => bp_current_user_can('bp_moderate'), 'query_var' => false, 'rewrite' => false, 'show_in_admin_bar' => false, 'show_ui' => bp_current_user_can('bp_moderate'), 'supports' => bp_get_email_post_type_supports())));
     }
     parent::register_post_types();
 }
コード例 #12
0
/**
 * 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>&quot;{{usermessage}}&quot;</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>&quot;{{usermessage}}&quot;</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>&quot;{{usermessage}}&quot;</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>&quot;{{usermessage}}&quot;</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 &quot;<a href=\"{{{group.url}}}\">{{group.name}}</a>&quot; were updated:\n<blockquote>{{changed_text}}</blockquote>", 'buddypress'), 'post_excerpt' => __("Group details for the group &quot;{{group.name}}&quot; 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: &quot;{{group.name}}&quot;.\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: &quot;{{group.name}}&quot;.\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 &quot;<a href=\"{{{group.url}}}\">{{group.name}}</a>&quot;.", 'buddypress'), 'post_excerpt' => __("You have been promoted to {{promoted_to}} in the group: &quot;{{group.name}}&quot;.\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 &quot;{{group.name}}&quot;. 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 &quot;{{group.name}}&quot;. 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: &quot;{{usersubject}}&quot;\n\n<blockquote>&quot;{{usermessage}}&quot;</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: &quot;{{usersubject}}&quot;\n\n&quot;{{usermessage}}&quot;\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 &quot;<a href=\"{{{group.url}}}\">{{group.name}}</a>&quot; has been accepted.", 'buddypress'), 'post_excerpt' => __("Your membership request for the group &quot;{{group.name}}&quot; 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 &quot;<a href=\"{{{group.url}}}\">{{group.name}}</a>&quot; has been rejected.", 'buddypress'), 'post_excerpt' => __("Your membership request for the group &quot;{{group.name}}&quot; 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');
}