bp_admin_reinstall_emails()

Delete emails and restore from defaults.

Description

Return

(array)

Source

File: bp-core/admin/bp-core-admin-tools.php

909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
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.', 'buddyboss' ) );
}

Changelog

Changelog
Version Description
BuddyPress 2.5.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.