function cfgp_install()
{
    /* Make domain a subdomain to example.com so there's
     * 	no possible way to navigate to it from admin or
     * 	front-end */
    $domain = CFGP_SITE_DOMAIN;
    $path = '/';
    if (!domain_exists($domain, $path, $site)) {
        $new_blog_id = create_empty_blog($domain, $path, 'CF Global Posts Blog', CFGP_SITE_ID);
        /* Make the blog private */
        update_blog_status($new_blog_id, 'public', 0);
    } else {
        error_log('Domain Already Exists');
    }
}
 /**
  * Add new option when registering a site (back and front end)
  *
  * URI: http://stackoverflow.com/a/10372861/1287812
  */
 public function add_new_blog_field($blog_id, $user_id, $domain, $path, $site_id, $meta)
 {
     $new_field_value = '';
     # Site added in the back end
     if (!empty($_POST['blog']['input_site_cat'])) {
         switch_to_blog($blog_id);
         $cat_id = $_POST['blog']['input_site_cat'];
         # TODO: if Sign-up is to be enabled, change this to a method
         $val = B5F_Multisite_Categories::get_instance()->do_mature_to_name($cat_id);
         update_blog_option($blog_id, 'site_category', $val);
         update_blog_status($blog_id, 'mature', $cat_id);
         get_blog_status($blog_id, 'mature');
         restore_current_blog();
     } elseif (!empty($meta['input_site_cat'])) {
         $new_field_value = $meta['input_site_cat'];
         update_option('site_category', $new_field_value);
     }
 }
     break;
 case 'unmatureblog':
     check_admin_referer('unmatureblog');
     if (!current_user_can('manage_sites')) {
         wp_die(__('You do not have permission to access this page.'));
     }
     update_blog_status($id, 'mature', '0');
     wp_safe_redirect(add_query_arg(array('updated' => 'true', 'action' => 'unmature'), wp_get_referer()));
     exit;
     break;
 case 'matureblog':
     check_admin_referer('matureblog');
     if (!current_user_can('manage_sites')) {
         wp_die(__('You do not have permission to access this page.'));
     }
     update_blog_status($id, 'mature', '1');
     wp_safe_redirect(add_query_arg(array('updated' => 'true', 'action' => 'mature'), wp_get_referer()));
     exit;
     break;
     // Common
 // Common
 case 'confirm':
     check_admin_referer('confirm');
     if (!headers_sent()) {
         nocache_headers();
         header('Content-Type: text/html; charset=utf-8');
     }
     if ($current_site->blog_id == $id) {
         wp_die(__('You are not allowed to change the current site.'));
     }
     ?>
Beispiel #4
0
/**
 * Update the 'archived' status of a particular blog.
 *
 * @since MU
 *
 * @param int $id The blog id
 * @param string $archived The new status
 * @return string $archived
 */
function update_archived($id, $archived)
{
    update_blog_status($id, 'archived', $archived);
    return $archived;
}
Beispiel #5
0
/**
 * Update this blog's 'public' setting in the global blogs table.
 *
 * Public blogs have a setting of 1, private blogs are 0.
 *
 * @since MU
 *
 * @param int $old_value
 * @param int $value     The new public value
 */
function update_blog_public($old_value, $value)
{
    update_blog_status(get_current_blog_id(), 'public', (int) $value);
}
Beispiel #6
0
             * Fires before a network site is deactivated.
             *
             * @since MU
             *
             * @param string $id The ID of the site being deactivated.
             */
            do_action('deactivate_blog', $id);
            update_blog_status($id, 'deleted', '1');
            break;
        case 'unspamblog':
        case 'spamblog':
            update_blog_status($id, 'spam', 'spamblog' === $_GET['action'] ? '1' : '0');
            break;
        case 'unmatureblog':
        case 'matureblog':
            update_blog_status($id, 'mature', 'matureblog' === $_GET['action'] ? '1' : '0');
            break;
    }
    if (empty($updated_action) && array_key_exists($_GET['action'], $manage_actions)) {
        $updated_action = $_GET['action'];
    }
    if (!empty($updated_action)) {
        wp_safe_redirect(add_query_arg(array('updated' => $updated_action), wp_get_referer()));
        exit;
    }
}
$msg = '';
if (isset($_GET['updated'])) {
    switch ($_GET['updated']) {
        case 'all_notspam':
            $msg = __('Sites removed from spam.');
/**
 * Delete a site.
 *
 * @since 3.0.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param int  $blog_id Site ID.
 * @param bool $drop    True if site's database tables should be dropped. Default is false.
 */
function wpmu_delete_blog($blog_id, $drop = false)
{
    global $wpdb;
    $switch = false;
    if (get_current_blog_id() != $blog_id) {
        $switch = true;
        switch_to_blog($blog_id);
    }
    $blog = get_blog_details($blog_id);
    /**
     * Fires before a site is deleted.
     *
     * @since MU
     *
     * @param int  $blog_id The site ID.
     * @param bool $drop    True if site's table should be dropped. Default is false.
     */
    do_action('delete_blog', $blog_id, $drop);
    $users = get_users(array('blog_id' => $blog_id, 'fields' => 'ids'));
    // Remove users from this blog.
    if (!empty($users)) {
        foreach ($users as $user_id) {
            remove_user_from_blog($user_id, $blog_id);
        }
    }
    update_blog_status($blog_id, 'deleted', 1);
    $current_site = get_current_site();
    // If a full blog object is not available, do not destroy anything.
    if ($drop && !$blog) {
        $drop = false;
    }
    // Don't destroy the initial, main, or root blog.
    if ($drop && (1 == $blog_id || is_main_site($blog_id) || $blog->path == $current_site->path && $blog->domain == $current_site->domain)) {
        $drop = false;
    }
    $upload_path = trim(get_option('upload_path'));
    // If ms_files_rewriting is enabled and upload_path is empty, wp_upload_dir is not reliable.
    if ($drop && get_site_option('ms_files_rewriting') && empty($upload_path)) {
        $drop = false;
    }
    if ($drop) {
        $uploads = wp_get_upload_dir();
        $tables = $wpdb->tables('blog');
        /**
         * Filters the tables to drop when the site is deleted.
         *
         * @since MU
         *
         * @param array $tables  The site tables to be dropped.
         * @param int   $blog_id The ID of the site to drop tables for.
         */
        $drop_tables = apply_filters('wpmu_drop_tables', $tables, $blog_id);
        foreach ((array) $drop_tables as $table) {
            $wpdb->query("DROP TABLE IF EXISTS `{$table}`");
        }
        $wpdb->delete($wpdb->blogs, array('blog_id' => $blog_id));
        /**
         * Filters the upload base directory to delete when the site is deleted.
         *
         * @since MU
         *
         * @param string $uploads['basedir'] Uploads path without subdirectory. @see wp_upload_dir()
         * @param int    $blog_id            The site ID.
         */
        $dir = apply_filters('wpmu_delete_blog_upload_dir', $uploads['basedir'], $blog_id);
        $dir = rtrim($dir, DIRECTORY_SEPARATOR);
        $top_dir = $dir;
        $stack = array($dir);
        $index = 0;
        while ($index < count($stack)) {
            // Get indexed directory from stack
            $dir = $stack[$index];
            $dh = @opendir($dir);
            if ($dh) {
                while (($file = @readdir($dh)) !== false) {
                    if ($file == '.' || $file == '..') {
                        continue;
                    }
                    if (@is_dir($dir . DIRECTORY_SEPARATOR . $file)) {
                        $stack[] = $dir . DIRECTORY_SEPARATOR . $file;
                    } elseif (@is_file($dir . DIRECTORY_SEPARATOR . $file)) {
                        @unlink($dir . DIRECTORY_SEPARATOR . $file);
                    }
                }
                @closedir($dh);
            }
            $index++;
        }
        $stack = array_reverse($stack);
        // Last added dirs are deepest
        foreach ((array) $stack as $dir) {
            if ($dir != $top_dir) {
                @rmdir($dir);
            }
        }
        clean_blog_cache($blog);
    }
    if ($switch) {
        restore_current_blog();
    }
}
/**
 * Process a spammed or unspammed user.
 *
 * This function is called from three places:
 *
 * - in bp_settings_action_capabilities() (from the front-end)
 * - by bp_core_mark_user_spam_admin()    (from wp-admin)
 * - bp_core_mark_user_ham_admin()        (from wp-admin)
 *
 * @since 1.6.0
 *
 * @param int    $user_id       The ID of the user being spammed/hammed.
 * @param string $status        'spam' if being marked as spam, 'ham' otherwise.
 * @param bool   $do_wp_cleanup True to force the cleanup of WordPress content
 *                              and status, otherwise false. Generally, this should
 *                              only be false if WordPress is expected to have
 *                              performed this cleanup independently, as when hooked
 *                              to 'make_spam_user'.
 * @return bool True on success, false on failure.
 */
function bp_core_process_spammer_status($user_id, $status, $do_wp_cleanup = true)
{
    global $wpdb;
    // Bail if no user ID.
    if (empty($user_id)) {
        return;
    }
    // Bail if user ID is super admin.
    if (is_super_admin($user_id)) {
        return;
    }
    // Get the functions file.
    if (is_multisite()) {
        require_once ABSPATH . 'wp-admin/includes/ms.php';
    }
    $is_spam = 'spam' == $status;
    // Only you can prevent infinite loops.
    remove_action('make_spam_user', 'bp_core_mark_user_spam_admin');
    remove_action('make_ham_user', 'bp_core_mark_user_ham_admin');
    // Force the cleanup of WordPress content and status for multisite configs.
    if ($do_wp_cleanup) {
        // Get the blogs for the user.
        $blogs = get_blogs_of_user($user_id, true);
        foreach ((array) array_values($blogs) as $details) {
            // Do not mark the main or current root blog as spam.
            if (1 == $details->userblog_id || bp_get_root_blog_id() == $details->userblog_id) {
                continue;
            }
            // Update the blog status.
            update_blog_status($details->userblog_id, 'spam', $is_spam);
        }
        // Finally, mark this user as a spammer.
        if (is_multisite()) {
            update_user_status($user_id, 'spam', $is_spam);
        }
    }
    // Update the user status.
    $wpdb->update($wpdb->users, array('user_status' => $is_spam), array('ID' => $user_id));
    // Clean user cache.
    clean_user_cache($user_id);
    if (!is_multisite()) {
        // Call multisite actions in single site mode for good measure.
        if (true === $is_spam) {
            /**
             * Fires at end of processing spammer in Dashboard if not multisite and user is spam.
             *
             * @since 1.5.0
             *
             * @param int $value user ID.
             */
            do_action('make_spam_user', $user_id);
        } else {
            /**
             * Fires at end of processing spammer in Dashboard if not multisite and user is not spam.
             *
             * @since 1.5.0
             *
             * @param int $value user ID.
             */
            do_action('make_ham_user', $user_id);
        }
    }
    // Hide this user's activity.
    if (true === $is_spam && bp_is_active('activity')) {
        bp_activity_hide_user_activity($user_id);
    }
    // We need a special hook for is_spam so that components can delete data at spam time.
    if (true === $is_spam) {
        /**
         * Fires at the end of the process spammer process if the user is spam.
         *
         * @since 1.5.0
         *
         * @param int $value Displayed user ID.
         */
        do_action('bp_make_spam_user', $user_id);
    } else {
        /**
         * Fires at the end of the process spammer process if the user is not spam.
         *
         * @since 1.5.0
         *
         * @param int $value Displayed user ID.
         */
        do_action('bp_make_ham_user', $user_id);
    }
    /**
     * Fires at the end of the process for hanlding spammer status.
     *
     * @since 1.5.5
     *
     * @param int  $user_id ID of the processed user.
     * @param bool $is_spam The determined spam status of processed user.
     */
    do_action('bp_core_process_spammer_status', $user_id, $is_spam);
    // Put things back how we found them.
    add_action('make_spam_user', 'bp_core_mark_user_spam_admin');
    add_action('make_ham_user', 'bp_core_mark_user_ham_admin');
    return true;
}
Beispiel #9
0
/**
 * Process a spammed or unspammed user.
 *
 * This function is called from three places:
 *
 * - in bp_settings_action_capabilities() (from the front-end)
 * - by bp_core_mark_user_spam_admin()    (from wp-admin)
 * - bp_core_mark_user_ham_admin()        (from wp-admin)
 *
 * @since BuddyPress (1.6.0)
 *
 * @param int $user_id The ID of the user being spammed/hammed.
 * @param string $status 'spam' if being marked as spam, 'ham' otherwise.
 * @param bool $do_wp_cleanup True to force the cleanup of WordPress content
 *        and status, otherwise false. Generally, this should only be false if
 *        WordPress is expected to have performed this cleanup independently,
 *        as when hooked to 'make_spam_user'.
 * @return bool True on success, false on failure.
 */
function bp_core_process_spammer_status($user_id, $status, $do_wp_cleanup = true)
{
    global $wpdb;
    // Bail if no user ID
    if (empty($user_id)) {
        return;
    }
    // Bail if user ID is super admin
    if (is_super_admin($user_id)) {
        return;
    }
    // Get the functions file
    if (is_multisite()) {
        require_once ABSPATH . 'wp-admin/includes/ms.php';
    }
    $is_spam = 'spam' == $status;
    // Only you can prevent infinite loops
    remove_action('make_spam_user', 'bp_core_mark_user_spam_admin');
    remove_action('make_ham_user', 'bp_core_mark_user_ham_admin');
    // Determine if we are on an admin page
    $is_admin = is_admin();
    if ($is_admin && !defined('DOING_AJAX')) {
        $is_admin = (bool) (buddypress()->members->admin->user_page !== get_current_screen()->id);
    }
    // When marking as spam in the Dashboard, these actions are handled by WordPress
    if ($do_wp_cleanup) {
        // Get the blogs for the user
        $blogs = get_blogs_of_user($user_id, true);
        foreach ((array) array_values($blogs) as $details) {
            // Do not mark the main or current root blog as spam
            if (1 == $details->userblog_id || bp_get_root_blog_id() == $details->userblog_id) {
                continue;
            }
            // Update the blog status
            update_blog_status($details->userblog_id, 'spam', $is_spam);
        }
        // Finally, mark this user as a spammer
        if (is_multisite()) {
            update_user_status($user_id, 'spam', $is_spam);
        }
        // Always set single site status
        $wpdb->update($wpdb->users, array('user_status' => $is_spam), array('ID' => $user_id));
        // Call multisite actions in single site mode for good measure
        if (!is_multisite()) {
            $wp_action = true === $is_spam ? 'make_spam_user' : 'make_ham_user';
            do_action($wp_action, bp_displayed_user_id());
        }
    }
    // Hide this user's activity
    if (true === $is_spam && bp_is_active('activity')) {
        bp_activity_hide_user_activity($user_id);
    }
    // We need a special hook for is_spam so that components can delete data at spam time
    $bp_action = true === $is_spam ? 'bp_make_spam_user' : 'bp_make_ham_user';
    do_action($bp_action, $user_id);
    // Allow plugins to do neat things
    do_action('bp_core_process_spammer_status', $user_id, $is_spam);
    // Put things back how we found them
    add_action('make_spam_user', 'bp_core_mark_user_spam_admin');
    add_action('make_ham_user', 'bp_core_mark_user_ham_admin');
    return true;
}
/**
 * Display a noindex meta tag if required by the blog configuration.
 *
 * If a blog is marked as not being public then the noindex meta tag will be
 * output to tell web robots not to index the page content. Add this to the wp_head action.
 * Typical usage is as a wp_head callback. add_action( 'wp_head', 'noindex' );
 *
 * @see wp_no_robots
 *
 * @since 2.1.0
 */
function noindex()
{
    $public = get_option('blog_public');
    if (is_multisite()) {
        // Compare local and global and override with the local setting if they
        // don't match.
        global $current_blog;
        if ('' != $public && $public != $current_blog->public) {
            update_blog_status(get_current_blog_id(), 'public', $public);
            $current_blog->public = $public;
        }
    }
    // If the blog is not public, tell robots to go away.
    if ('0' == $public) {
        wp_no_robots();
    }
}
Beispiel #11
0
function wpmu_create_blog($domain, $path, $title, $user_id, $meta = '', $site_id = 1)
{
    $domain = preg_replace("/\\s+/", '', sanitize_user($domain, true));
    if (constant('VHOST') == 'yes') {
        $domain = str_replace('@', '', $domain);
    }
    $title = strip_tags($title);
    $user_id = (int) $user_id;
    if (empty($path)) {
        $path = '/';
    }
    // Check if the domain has been used already. We should return an error message.
    if (domain_exists($domain, $path, $site_id)) {
        return new WP_Error('blog_taken', __('Blog already exists.'));
    }
    if (!defined("WP_INSTALLING")) {
        define("WP_INSTALLING", true);
    }
    if (!($blog_id = insert_blog($domain, $path, $site_id))) {
        return new WP_Error('insert_blog', __('Could not create blog.'));
    }
    switch_to_blog($blog_id);
    install_blog($blog_id, $title);
    install_blog_defaults($blog_id, $user_id);
    add_user_to_blog($blog_id, $user_id, 'administrator');
    if (is_array($meta)) {
        foreach ($meta as $key => $value) {
            if ($key == 'public' || $key == 'archived' || $key == 'mature' || $key == 'spam' || $key == 'deleted' || $key == 'lang_id') {
                update_blog_status($blog_id, $key, $value);
            } else {
                update_option($key, $value);
            }
        }
    }
    add_option('WPLANG', get_site_option('WPLANG'));
    update_option('blog_public', $meta['public']);
    if (get_usermeta($user_id, 'primary_blog') == 1) {
        update_usermeta($user_id, 'primary_blog', $blog_id);
    }
    restore_current_blog();
    do_action('wpmu_new_blog', $blog_id, $user_id);
    return $blog_id;
}
function wangguard_delete_user_and_blogs($userid)
{
    global $wpdb;
    if (function_exists("get_blogs_of_user") && function_exists("update_blog_status") && method_exists($wpdb, 'get_blog_prefix')) {
        $blogs = get_blogs_of_user($userid, true);
        if (is_array($blogs)) {
            foreach ((array) $blogs as $key => $details) {
                $isMainBlog = false;
                if (isset($current_site)) {
                    $isMainBlog = $details->userblog_id != $current_site->blog_id;
                    // main blog not a spam !
                } elseif (defined("BP_ROOT_BLOG")) {
                    $isMainBlog = 1 == $details->userblog_id || BP_ROOT_BLOG == $details->userblog_id;
                } else {
                    $isMainBlog = $details->userblog_id == 1;
                }
                $userIsAuthor = false;
                if (!$isMainBlog) {
                    //Only works on WP 3+
                    $blog_prefix = $wpdb->get_blog_prefix($details->userblog_id);
                    $authorcaps = $wpdb->get_var(sprintf("SELECT meta_value as caps FROM {$wpdb->users} u, {$wpdb->usermeta} um WHERE u.ID = %d and u.ID = um.user_id AND meta_key = '{$blog_prefix}capabilities'", $userid));
                    $caps = maybe_unserialize($authorcaps);
                    $userIsAuthor = isset($caps['administrator']);
                }
                //Update blog to spam if the user is the author and its not the main blog
                if (!$isMainBlog && $userIsAuthor) {
                    @update_blog_status($details->userblog_id, 'spam', '1');
                    //remove blog from queue
                    $table_name = $wpdb->base_prefix . "wangguardreportqueue";
                    $wpdb->query($wpdb->prepare("delete from {$table_name} where blog_id = '%d'", $details->userblog_id));
                }
            }
        }
    }
    if (wangguard_is_multisite()) {
        if (function_exists('bp_core_mark_user_spam_admin')) {
            @(include_once ABSPATH . 'wp-admin/includes/ms.php');
            bp_core_mark_user_spam_admin($userid);
            wpmu_delete_user($userid);
        } else {
            @(include_once ABSPATH . 'wp-admin/includes/ms.php');
            wpmu_delete_user($userid);
        }
    } else {
        if (function_exists('wp_delete_user') && function_exists('bp_core_mark_user_spam_admin')) {
            @(include_once ABSPATH . 'wp-admin/includes/user.php');
            bp_core_mark_user_spam_admin($userid);
            wp_delete_user($userid);
        } else {
            @(include_once ABSPATH . 'wp-admin/includes/user.php');
            wp_delete_user($userid);
        }
    }
}
 function update_options()
 {
     global $wpdb, $current_site, $wp_version;
     if (!isset($_POST['tags_blog_enabled']) || !$_POST['tags_blog_enabled']) {
         if (isset($_POST['tags_blog_enabled']) && $this->get('tags_blog_enabled') != $_POST['tags_blog_enabled']) {
             $this->update('tags_blog_enabled', 0, true);
         }
         wp_redirect(esc_url_raw(add_query_arg(array('updated' => '1'))));
         exit;
     }
     $this->update('tags_blog_enabled', 1);
     if ((isset($_POST['tags_blog']) || isset($_POST['tags_blog_main_blog'])) && isset($_POST['tags_blog_public'])) {
         if (isset($_POST['tags_blog_main_blog']) && 1 == $_POST['tags_blog_main_blog']) {
             if ($current_site->blog_id) {
                 $id = $current_site->blog_id;
             } else {
                 $id = $wpdb->get_var("SELECT blog_id FROM {$wpdb->blogs} WHERE domain = '{$current_site->domain}' AND path = '{$current_site->path}'");
             }
             if ($id) {
                 $this->update('tags_blog_id', $id);
                 $this->update('tags_blog_main_blog', 1);
             } else {
                 $this->update('tags_blog_main_blog', 0);
             }
         } else {
             $this->update('tags_blog_main_blog', 0);
             $aggregate_blog = sanitize_title($_POST['tags_blog']);
             $this->update('tags_blog', $aggregate_blog);
             if (constant('VHOST') == 'yes') {
                 $domain = $aggregate_blog . '.' . $current_site->domain;
                 $path = $current_site->path;
             } else {
                 $domain = $current_site->domain;
                 $path = trailingslashit($current_site->path . $aggregate_blog);
             }
             $aggregate_blog_id = $wpdb->get_var("SELECT blog_id FROM {$wpdb->blogs} WHERE domain = '{$domain}' AND path = '{$path}'");
             if ($aggregate_blog_id) {
                 $this->update('tags_blog_id', $aggregate_blog_id);
             } else {
                 $wpdb->hide_errors();
                 $id = wpmu_create_blog($domain, $path, __('Network Posts', 'wds-multisite-aggregate'), get_current_user_id(), array('public' => $_POST['tags_blog_public']), $current_site->id);
                 $this->update('tags_blog_id', $id);
                 $wpdb->show_errors();
             }
         }
         $aggregate_blog_public = (int) $_POST['tags_blog_public'];
         $this->update('tags_blog_public', $aggregate_blog_public);
         update_blog_option($aggregate_blog_id, 'blog_public', $aggregate_blog_public);
         update_blog_status($aggregate_blog_id, 'public', $aggregate_blog_public);
     }
     $options_as_integers = array('tags_max_posts');
     foreach ($options_as_integers as $option_key) {
         if ($set = $this->make_integer_from_request($option_key)) {
             $this->update($option_key, $set);
         }
     }
     $options_as_integers_maybe_set = array('tags_blog_thumbs', 'tags_blog_pages', 'populate_all_blogs');
     foreach ($options_as_integers_maybe_set as $option_key) {
         $set = $this->make_integer_from_request($option_key);
         if ($set != $this->get($option_key)) {
             $this->update($option_key, $set);
         }
     }
     if (($set = $this->make_integer_from_request('tags_blog_pub_check')) && $set != $this->get('tags_blog_pub_check')) {
         $set = $aggregate_blog_public == 0 ? $set : 0;
         $this->update('tags_blog_pub_check', $set);
     }
     if (isset($_POST['tags_blog_postmeta']) && '' != $_POST['tags_blog_postmeta']) {
         $meta_keys = explode("\n", strip_tags(stripslashes($_POST['tags_blog_postmeta'])));
         $this->update('tags_blog_postmeta', array_map('trim', $meta_keys));
     } else {
         $this->update('tags_blog_postmeta', '');
     }
     $blogs_to_import = $this->comma_delimited_to_array_from_request('blogs_to_import');
     $this->update('blogs_to_import', $blogs_to_import);
     // force write if changes saved
     $this->update(true);
     wp_redirect(esc_url_raw(add_query_arg(array('updated' => '1'))));
     exit;
 }
Beispiel #14
0
 /**
  * Tests deletion of index when a blog is marked as archived
  * @group 392
  * @link https://github.com/10up/ElasticPress/issues/392
  */
 public function testArchivedSite()
 {
     $index_count = ep_count_indexes();
     $count_indexes = $index_count['total_indexes'];
     $last_blog_id = $index_count['last_blog_id_with_index'];
     update_blog_status($last_blog_id, 'archived', '1');
     $post_delete_count = ep_count_indexes();
     $post_count_indexes = $post_delete_count['total_indexes'];
     $this->assertNotEquals($count_indexes, $post_count_indexes);
 }
/**
 * When a site admin selects "Mark as Spammer/Not Spammer" from the admin menu
 * this action will fire and mark or unmark the user and their blogs as spam.
 * Must be a site admin for this function to run.
 *
 * @package BuddyPress Core
 * @param int $user_id Optional user ID to mark as spam
 * @global object $wpdb Global WordPress Database object
 */
function bp_core_action_set_spammer_status($user_id = 0)
{
    global $wpdb;
    // Only super admins can currently spam users
    if (!is_super_admin() || bp_is_my_profile()) {
        return;
    }
    // Use displayed user if it's not yourself
    if (empty($user_id) && bp_is_user()) {
        $user_id = bp_displayed_user_id();
    }
    // Bail if no user ID
    if (empty($user_id)) {
        return;
    }
    // Bail if user ID is super admin
    if (is_super_admin($user_id)) {
        return;
    }
    if (bp_is_current_component('admin') && in_array(bp_current_action(), array('mark-spammer', 'unmark-spammer'))) {
        // Check the nonce
        check_admin_referer('mark-unmark-spammer');
        // Get the functions file
        if (is_multisite()) {
            require ABSPATH . 'wp-admin/includes/ms.php';
        }
        // To spam or not to spam
        $is_spam = bp_is_current_action('mark-spammer') ? 1 : 0;
        // Get the blogs for the user
        $blogs = get_blogs_of_user($user_id, true);
        foreach ((array) $blogs as $key => $details) {
            // Do not mark the main or current root blog as spam
            if (1 == $details->userblog_id || bp_get_root_blog_id() == $details->userblog_id) {
                continue;
            }
            // Update the blog status
            update_blog_status($details->userblog_id, 'spam', $is_spam);
        }
        // Finally, mark this user as a spammer
        if (is_multisite()) {
            update_user_status($user_id, 'spam', $is_spam);
        }
        // Always set single site status
        $wpdb->update($wpdb->users, array('user_status' => $is_spam), array('ID' => $user_id));
        // Add feedback message
        if ($is_spam) {
            bp_core_add_message(__('User marked as spammer. Spam users are visible only to site admins.', 'buddypress'));
        } else {
            bp_core_add_message(__('User removed as spammer.', 'buddypress'));
        }
        // Hide this user's activity
        if ($is_spam && bp_is_active('activity')) {
            bp_activity_hide_user_activity($user_id);
        }
        // We need a special hook for is_spam so that components can delete data at spam time
        $bp_action = $is_spam ? 'bp_make_spam_user' : 'bp_make_ham_user';
        do_action($bp_action, bp_displayed_user_id());
        // Call multisite actions in single site mode for good measure
        if (!is_multisite()) {
            $wp_action = $is_spam ? 'make_spam_user' : 'make_ham_user';
            do_action($wp_action, bp_displayed_user_id());
        }
        // Allow plugins to do neat things
        do_action('bp_core_action_set_spammer_status', bp_displayed_user_id(), $is_spam);
        // Redirect back to where we came from
        bp_core_redirect(wp_get_referer());
    }
}
Beispiel #16
0
 private function update_site_status($ids, $pref, $value)
 {
     if ($pref == 'archived' && $value == 1) {
         $action = 'archived';
     } else {
         if ($pref == 'archived' && $value == 0) {
             $action = 'unarchived';
         } else {
             if ($pref == 'deleted' && $value == 1) {
                 $action = 'deactivated';
             } else {
                 if ($pref == 'deleted' && $value == 0) {
                     $action = 'activated';
                 } else {
                     if ($pref == 'spam' && $value == 1) {
                         $action = 'marked as spam';
                     } else {
                         if ($pref == 'spam' && $value == 0) {
                             $action = 'removed from spam';
                         }
                     }
                 }
             }
         }
     }
     foreach ($ids as $site_id) {
         $site = $this->fetcher->get_check($site_id);
         if (is_main_site($site->blog_id)) {
             WP_CLI::warning("You are not allowed to change the main site.");
             continue;
         }
         $old_value = get_blog_status($site->blog_id, $pref);
         if ($value == $old_value) {
             WP_CLI::warning("Site {$site->blog_id} already {$action}.");
             continue;
         }
         update_blog_status($site->blog_id, $pref, $value);
         WP_CLI::success("Site {$site->blog_id} {$action}.");
     }
 }
Beispiel #17
0
/**
 * Delete a blog
 *
 * @since 3.0.0
 *
 * @param int $blog_id Blog ID
 * @param bool $drop True if blog's table should be dropped.  Default is false.
 * @return void
 */
function wpmu_delete_blog($blog_id, $drop = false)
{
    global $wpdb;
    $switch = false;
    if ($blog_id != $wpdb->blogid) {
        $switch = true;
        switch_to_blog($blog_id);
    }
    $blog_prefix = $wpdb->get_blog_prefix($blog_id);
    do_action('delete_blog', $blog_id, $drop);
    $users = get_users_of_blog($blog_id);
    // Remove users from this blog.
    if (!empty($users)) {
        foreach ($users as $user) {
            remove_user_from_blog($user->user_id, $blog_id);
        }
    }
    update_blog_status($blog_id, 'deleted', 1);
    if ($drop) {
        if (substr($blog_prefix, -1) == '_') {
            $blog_prefix = substr($blog_prefix, 0, -1) . '\\_';
        }
        $drop_tables = $wpdb->get_results("SHOW TABLES LIKE '{$blog_prefix}%'", ARRAY_A);
        $drop_tables = apply_filters('wpmu_drop_tables', $drop_tables);
        reset($drop_tables);
        foreach ((array) $drop_tables as $drop_table) {
            $wpdb->query("DROP TABLE IF EXISTS " . current($drop_table) . "");
        }
        $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->blogs} WHERE blog_id = %d", $blog_id));
        $dir = apply_filters('wpmu_delete_blog_upload_dir', WP_CONTENT_DIR . "/blogs.dir/{$blog_id}/files/", $blog_id);
        $dir = rtrim($dir, DIRECTORY_SEPARATOR);
        $top_dir = $dir;
        $stack = array($dir);
        $index = 0;
        while ($index < count($stack)) {
            # Get indexed directory from stack
            $dir = $stack[$index];
            $dh = @opendir($dir);
            if ($dh) {
                while (($file = @readdir($dh)) !== false) {
                    if ($file == '.' || $file == '..') {
                        continue;
                    }
                    if (@is_dir($dir . DIRECTORY_SEPARATOR . $file)) {
                        $stack[] = $dir . DIRECTORY_SEPARATOR . $file;
                    } else {
                        if (@is_file($dir . DIRECTORY_SEPARATOR . $file)) {
                            @unlink($dir . DIRECTORY_SEPARATOR . $file);
                        }
                    }
                }
            }
            $index++;
        }
        $stack = array_reverse($stack);
        // Last added dirs are deepest
        foreach ((array) $stack as $dir) {
            if ($dir != $top_dir) {
                @rmdir($dir);
            }
        }
    }
    $wpdb->query("DELETE FROM {$wpdb->usermeta} WHERE meta_key = '{$blog_prefix}autosave_draft_ids'");
    $blogs = get_site_option('blog_list');
    if (is_array($blogs)) {
        foreach ($blogs as $n => $blog) {
            if ($blog['blog_id'] == $blog_id) {
                unset($blogs[$n]);
            }
        }
        update_site_option('blog_list', $blogs);
    }
    if ($switch === true) {
        restore_current_blog();
    }
}
Beispiel #18
0
<?php

update_blog_status(get_current_blog_id(), 'deleted', '1');
Beispiel #19
0
/**
 * Delete a blog
 *
 * @since 3.0.0
 *
 * @param int $blog_id Blog ID
 * @param bool $drop True if blog's table should be dropped. Default is false.
 * @return void
 */
function wpmu_delete_blog($blog_id, $drop = false)
{
    global $wpdb, $current_site;
    $switch = false;
    if (get_current_blog_id() != $blog_id) {
        $switch = true;
        switch_to_blog($blog_id);
    }
    $blog = get_blog_details($blog_id);
    do_action('delete_blog', $blog_id, $drop);
    $users = get_users(array('blog_id' => $blog_id, 'fields' => 'ids'));
    // Remove users from this blog.
    if (!empty($users)) {
        foreach ($users as $user_id) {
            remove_user_from_blog($user_id, $blog_id);
        }
    }
    update_blog_status($blog_id, 'deleted', 1);
    // Don't destroy the initial, main, or root blog.
    if ($drop && (1 == $blog_id || is_main_site($blog_id) || $blog->path == $current_site->path && $blog->domain == $current_site->domain)) {
        $drop = false;
    }
    if ($drop) {
        $drop_tables = apply_filters('wpmu_drop_tables', $wpdb->tables('blog'));
        foreach ((array) $drop_tables as $table) {
            $wpdb->query("DROP TABLE IF EXISTS `{$table}`");
        }
        $wpdb->delete($wpdb->blogs, array('blog_id' => $blog_id));
        $uploads = wp_upload_dir();
        $dir = apply_filters('wpmu_delete_blog_upload_dir', $uploads['basedir'], $blog_id);
        $dir = rtrim($dir, DIRECTORY_SEPARATOR);
        $top_dir = $dir;
        $stack = array($dir);
        $index = 0;
        while ($index < count($stack)) {
            # Get indexed directory from stack
            $dir = $stack[$index];
            $dh = @opendir($dir);
            if ($dh) {
                while (($file = @readdir($dh)) !== false) {
                    if ($file == '.' || $file == '..') {
                        continue;
                    }
                    if (@is_dir($dir . DIRECTORY_SEPARATOR . $file)) {
                        $stack[] = $dir . DIRECTORY_SEPARATOR . $file;
                    } else {
                        if (@is_file($dir . DIRECTORY_SEPARATOR . $file)) {
                            @unlink($dir . DIRECTORY_SEPARATOR . $file);
                        }
                    }
                }
                @closedir($dh);
            }
            $index++;
        }
        $stack = array_reverse($stack);
        // Last added dirs are deepest
        foreach ((array) $stack as $dir) {
            if ($dir != $top_dir) {
                @rmdir($dir);
            }
        }
        clean_blog_cache($blog);
    }
    if ($switch) {
        restore_current_blog();
    }
}
 /**
  * set spammeer status
  *
  * @param <int|array> $user_ids member ids
  * @param <bool> $is_spam mark spammer (true) or unmark (false)
  * @param <callback> $end_callback function to execute after marking/unmarking, after this bpcore will redirect back & die
  */
 function set_spammer_status($user_ids, $is_spam, $end_callback)
 {
     global $wpdb;
     $user_ids = (array) $user_ids;
     $successes = array();
     foreach ($user_ids as $user_id) {
         // Bail if user ID is super admin
         if (is_super_admin($user_id)) {
             continue;
         }
         // Get the blogs for the user
         $blogs = get_blogs_of_user($user_id, true);
         foreach ((array) $blogs as $key => $details) {
             // Do not mark the main or current root blog as spam
             if (1 == $details->userblog_id || bp_get_root_blog_id() == $details->userblog_id) {
                 continue;
             }
             // Update the blog status
             update_blog_status($details->userblog_id, 'spam', $is_spam);
         }
         // Finally, mark this user as a spammer
         if (is_multisite()) {
             update_user_status($user_id, 'spam', $is_spam);
         }
         // Always set single site status
         $wpdb->update($wpdb->users, array('user_status' => (int) $is_spam), array('ID' => $user_id));
         // Hide this user's activity
         if ($is_spam && bp_is_active('activity')) {
             bp_activity_hide_user_activity($user_id);
         }
         // We need a special hook for is_spam so that components can delete data at spam time
         $bp_action = $is_spam ? 'bp_make_spam_user' : 'bp_make_ham_user';
         do_action($bp_action, $user_id);
         // Call multisite actions in single site mode for good measure
         if (!is_multisite()) {
             $wp_action = $is_spam ? 'make_spam_user' : 'make_ham_user';
             do_action($wp_action, $user_id);
         }
         // Allow plugins to do neat things
         do_action('bp_core_action_set_spammer_status', $user_id, $is_spam);
         $successes[] = $user_id;
     }
     $errors = array_diff($user_ids, $successes);
     call_user_func($end_callback, $successes, $errors, $is_spam);
 }
	function test_update_blog_status() {
		global $test_action_counter;

		$user_id = $this->factory->user->create( array( 'role' => 'administrator' ) );
		$blog_id = $this->factory->blog->create( array( 'user_id' => $user_id, 'path' => '/test_blogpath', 'title' => 'Test Title' ) );
		$this->assertInternalType( 'int', $blog_id );

		$test_action_counter = 0;
		$count = 1;

		add_action( 'make_ham_blog', array( $this, '_action_counter_cb' ), 10, 1 );
		$result = update_blog_status( $blog_id, 'spam', 0 );
		$this->assertEquals( 0, $result );
		$blog = get_blog_details( $blog_id );
		$this->assertEquals( '0', $blog->spam );
		$this->assertEquals( $count, $test_action_counter );

		// Same again
		$count++;
		$result = update_blog_status( $blog_id, 'spam', 0 );
		$this->assertEquals( 0, $result );
		$blog = get_blog_details( $blog_id );
		$this->assertEquals( '0', $blog->spam );
		$this->assertEquals( $count, $test_action_counter );
		remove_action( 'make_ham_blog', array( $this, '_action_counter_cb' ), 10, 1 );

		$count++;
		add_action( 'make_spam_blog', array( $this, '_action_counter_cb' ), 10, 1 );
		$result = update_blog_status( $blog_id, 'spam', 1 );
		$this->assertEquals( 1, $result );
		$blog = get_blog_details( $blog_id );
		$this->assertEquals( '1', $blog->spam );
		$this->assertEquals( $count, $test_action_counter );

		// Same again
		$count++;
		$result = update_blog_status( $blog_id, 'spam', 1 );
		$this->assertEquals( 1, $result );
		$blog = get_blog_details( $blog_id );
		$this->assertEquals( '1', $blog->spam );
		$this->assertEquals( $count, $test_action_counter );
		remove_action( 'make_spam_blog', array( $this, '_action_counter_cb' ), 10, 1 );

		add_action( 'archive_blog', array( $this, '_action_counter_cb' ), 10, 1 );
		$count++;
		$result = update_blog_status( $blog_id, 'archived', 1 );
		$this->assertEquals( 1, $result );
		$blog = get_blog_details( $blog_id );
		$this->assertEquals( '1', $blog->archived );
		$this->assertEquals( $count, $test_action_counter );

		// Same again
		$count++;
		$result = update_blog_status( $blog_id, 'archived', 1 );
		$this->assertEquals( 1, $result );
		$blog = get_blog_details( $blog_id );
		$this->assertEquals( '1', $blog->archived );
		$this->assertEquals( $count, $test_action_counter );
		remove_action( 'archive_blog', array( $this, '_action_counter_cb' ), 10, 1 );

		add_action( 'unarchive_blog', array( $this, '_action_counter_cb' ), 10, 1 );
		$count++;
		$result = update_blog_status( $blog_id, 'archived', 0 );
		$this->assertEquals( 0, $result );
		$blog = get_blog_details( $blog_id );
		$this->assertEquals( '0', $blog->archived );
		$this->assertEquals( $count, $test_action_counter );

		// Same again
		$result = update_blog_status( $blog_id, 'archived', 0 );
		$count++;
		$this->assertEquals( 0, $result );
		$blog = get_blog_details( $blog_id );
		$this->assertEquals( '0', $blog->archived );
		$this->assertEquals( $count, $test_action_counter );
		remove_action( 'unarchive_blog', array( $this, '_action_counter_cb' ), 10, 1 );

		add_action( 'make_delete_blog', array( $this, '_action_counter_cb' ), 10, 1 );
		$count++;
		$result = update_blog_status( $blog_id, 'deleted', 1 );
		$this->assertEquals( 1, $result );
		$blog = get_blog_details( $blog_id );
		$this->assertEquals( '1', $blog->deleted );
		$this->assertEquals( $count, $test_action_counter );

		// Same again
		$count++;
		$result = update_blog_status( $blog_id, 'deleted', 1 );
		$this->assertEquals( 1, $result );
		$blog = get_blog_details( $blog_id );
		$this->assertEquals( '1', $blog->deleted );
		$this->assertEquals( $count, $test_action_counter );
		remove_action( 'make_delete_blog', array( $this, '_action_counter_cb' ), 10, 1 );

		add_action( 'make_undelete_blog', array( $this, '_action_counter_cb' ), 10, 1 );
		$count++;
		$result = update_blog_status( $blog_id, 'deleted', 0 );
		$this->assertEquals( 0, $result );
		$blog = get_blog_details( $blog_id );
		$this->assertEquals( '0', $blog->deleted );
		$this->assertEquals( $count, $test_action_counter );

		// Same again
		$count++;
		$result = update_blog_status( $blog_id, 'deleted', 0 );
		$this->assertEquals( 0, $result );
		$blog = get_blog_details( $blog_id );
		$this->assertEquals( '0', $blog->deleted );
		$this->assertEquals( $count, $test_action_counter );
		remove_action( 'make_undelete_blog', array( $this, '_action_counter_cb' ), 10, 1 );

		add_action( 'mature_blog', array( $this, '_action_counter_cb' ), 10, 1 );
		$count++;
		$result = update_blog_status( $blog_id, 'mature', 1 );
		$this->assertEquals( 1, $result );
		$blog = get_blog_details( $blog_id );
		$this->assertEquals( '1', $blog->mature );
		$this->assertEquals( $count, $test_action_counter );

		// Same again
		$count++;
		$result = update_blog_status( $blog_id, 'mature', 1 );
		$this->assertEquals( 1, $result );
		$blog = get_blog_details( $blog_id );
		$this->assertEquals( '1', $blog->mature );
		$this->assertEquals( $count, $test_action_counter );
		remove_action( 'mature_blog', array( $this, '_action_counter_cb' ), 10, 1 );

		add_action( 'unmature_blog', array( $this, '_action_counter_cb' ), 10, 1 );
		$count++;
		$result = update_blog_status( $blog_id, 'mature', 0 );
		$this->assertEquals( 0, $result );
		$blog = get_blog_details( $blog_id );
		$this->assertEquals( '0', $blog->mature );
		$this->assertEquals( $count, $test_action_counter );

		// Same again
		$count++;
		$result = update_blog_status( $blog_id, 'mature', 0 );
		$this->assertEquals( 0, $result );
		$blog = get_blog_details( $blog_id );
		$this->assertEquals( '0', $blog->mature );
		$this->assertEquals( $count, $test_action_counter );
		remove_action( 'unmature_blog', array( $this, '_action_counter_cb' ), 10, 1 );

		add_action( 'update_blog_public', array( $this, '_action_counter_cb' ), 10, 1 );
		$count++;
		$result = update_blog_status( $blog_id, 'public', 0 );
		$this->assertEquals( 0, $result );
		$blog = get_blog_details( $blog_id );
		$this->assertEquals( '0', $blog->public );
		$this->assertEquals( $count, $test_action_counter );

		// Same again
		$count++;
		$result = update_blog_status( $blog_id, 'public', 0 );
		$this->assertEquals( 0, $result );
		$blog = get_blog_details( $blog_id );
		$this->assertEquals( '0', $blog->public );
		$this->assertEquals( $count, $test_action_counter );
		remove_action( 'update_blog_public', array( $this, '_action_counter_cb' ), 10, 1 );

		add_action( 'update_blog_public', array( $this, '_action_counter_cb' ), 10, 1 );
		$count++;
		$result = update_blog_status( $blog_id, 'public', 1 );
		$this->assertEquals( 1, $result );
		$blog = get_blog_details( $blog_id );
		$this->assertEquals( '1', $blog->public );
		$this->assertEquals( $count, $test_action_counter );

		// Same again
		$count++;
		$result = update_blog_status( $blog_id, 'public', 1 );
		$this->assertEquals( 1, $result );
		$blog = get_blog_details( $blog_id );
		$this->assertEquals( '1', $blog->public );
		$this->assertEquals( $count, $test_action_counter );
		remove_action( 'update_blog_public', array( $this, '_action_counter_cb' ), 10, 1 );

		// Updating a dummy field returns the value passed. Go fig.
		$result = update_blog_status( $blog_id, 'doesnotexist', 1 );
		$this->assertEquals( 1, $result );
	}
Beispiel #22
0
                     $userfunction = 'all_spam';
                     $blogs = get_blogs_of_user($val, true);
                     foreach ((array) $blogs as $key => $details) {
                         if ($details->userblog_id == 1) {
                             continue;
                         }
                         // main blog not a spam !
                         update_blog_status($details->userblog_id, "spam", '1');
                         do_action("make_spam_blog", $details->userblog_id);
                     }
                     update_user_status($val, "spam", '1', 1);
                 } elseif (isset($_POST['alluser_notspam'])) {
                     $userfunction = 'all_notspam';
                     $blogs = get_blogs_of_user($val, true);
                     foreach ((array) $blogs as $key => $details) {
                         update_blog_status($details->userblog_id, "spam", '0');
                     }
                     update_user_status($val, "spam", '0', 1);
                 }
             }
         }
         wp_redirect(add_query_arg(array('updated' => 'true', 'action' => $userfunction), $_SERVER['HTTP_REFERER']));
     }
     exit;
     break;
 case "adduser":
     check_admin_referer('add-user');
     $user = $_POST['user'];
     if (empty($user['username']) && empty($user['email'])) {
         wp_die(__('Missing username and email.'));
     } elseif (empty($user['username'])) {
Beispiel #23
0
 public static function downgrade_paypal_site($entry, $config)
 {
     global $current_site;
     $action = $config['meta']['update_site_action'];
     if (!$action) {
         return;
     }
     $site_id = GFUserData::get_site_by_entry_id($entry['id']);
     if (!$site_id) {
         return;
     }
     switch ($action) {
         case 'deactivate':
             do_action('deactivate_blog', $site_id);
             update_blog_status($site_id, 'deleted', '1');
             break;
         case 'delete':
             require_once ABSPATH . 'wp-admin/includes/ms.php';
             if ($site_id != '0' && $site_id != $current_site->blog_id) {
                 wpmu_delete_blog($site_id, true);
             }
             break;
     }
 }
/**
 * Processes a spammed or unspammed user
 *
 * This function is called in three ways:
 *  - in bp_settings_action_capabilities() (from the front-end)
 *  - by bp_core_mark_user_spam_admin()    (from wp-admin)
 *  - bp_core_mark_user_ham_admin()        (from wp-admin)
 *
 * @since BuddyPress (1.6)
 *
 * @param int $user_id The user being spammed/hammed
 * @param string $status 'spam' if being marked as spam, 'ham' otherwise
 */
function bp_core_process_spammer_status($user_id, $status)
{
    global $wpdb;
    // Only super admins can currently spam users
    if (!is_super_admin() || bp_is_my_profile()) {
        return;
    }
    // Bail if no user ID
    if (empty($user_id)) {
        return;
    }
    // Bail if user ID is super admin
    if (is_super_admin($user_id)) {
        return;
    }
    // Get the functions file
    if (is_multisite()) {
        require_once ABSPATH . 'wp-admin/includes/ms.php';
    }
    $is_spam = 'spam' == $status;
    // Only you can prevent infinite loops
    remove_action('make_spam_user', 'bp_core_mark_user_spam_admin');
    remove_action('make_ham_user', 'bp_core_mark_user_ham_admin');
    // When marking as spam in the Dashboard, these actions are handled by WordPress
    if (!is_admin()) {
        // Get the blogs for the user
        $blogs = get_blogs_of_user($user_id, true);
        foreach ((array) $blogs as $key => $details) {
            // Do not mark the main or current root blog as spam
            if (1 == $details->userblog_id || bp_get_root_blog_id() == $details->userblog_id) {
                continue;
            }
            // Update the blog status
            update_blog_status($details->userblog_id, 'spam', $is_spam);
        }
        // Finally, mark this user as a spammer
        if (is_multisite()) {
            update_user_status($user_id, 'spam', $is_spam);
        }
        // Always set single site status
        $wpdb->update($wpdb->users, array('user_status' => $is_spam), array('ID' => $user_id));
        // Call multisite actions in single site mode for good measure
        if (!is_multisite()) {
            $wp_action = true === $is_spam ? 'make_spam_user' : 'make_ham_user';
            do_action($wp_action, bp_displayed_user_id());
        }
    }
    // Hide this user's activity
    if (true === $is_spam && bp_is_active('activity')) {
        bp_activity_hide_user_activity($user_id);
    }
    // We need a special hook for is_spam so that components can delete data at spam time
    $bp_action = true === $is_spam ? 'bp_make_spam_user' : 'bp_make_ham_user';
    do_action($bp_action, $user_id);
    // Allow plugins to do neat things
    do_action('bp_core_process_spammer_status', $user_id, $is_spam);
    return true;
}
Beispiel #25
0
                     }
                     $userfunction = 'all_spam';
                     $blogs = get_blogs_of_user($val, true);
                     foreach ((array) $blogs as $key => $details) {
                         if ($details->userblog_id != $current_site->blog_id) {
                             // main blog not a spam !
                             update_blog_status($details->userblog_id, 'spam', '1');
                         }
                     }
                     update_user_status($val, 'spam', '1');
                     break;
                 case 'notspam':
                     $userfunction = 'all_notspam';
                     $blogs = get_blogs_of_user($val, true);
                     foreach ((array) $blogs as $key => $details) {
                         update_blog_status($details->userblog_id, 'spam', '0');
                     }
                     update_user_status($val, 'spam', '0');
                     break;
             }
         }
     }
     wp_redirect(add_query_arg(array('updated' => 'true', 'action' => $userfunction), wp_get_referer()));
 } else {
     $location = network_admin_url('users.php');
     if (!empty($_REQUEST['paged'])) {
         $location = add_query_arg('paged', (int) $_REQUEST['paged'], $location);
     }
     wp_redirect($location);
 }
 exit;
Beispiel #26
0
 function test_update_blog_status_update_blog_public_action()
 {
     global $test_action_counter;
     $test_action_counter = 0;
     $blog_id = self::factory()->blog->create();
     add_action('update_blog_public', array($this, '_action_counter_cb'), 10);
     update_blog_status($blog_id, 'public', 0);
     $blog = get_blog_details($blog_id);
     $this->assertEquals('0', $blog->public);
     $this->assertEquals(1, $test_action_counter);
     // The action should fire if the status of 'mature' stays the same.
     update_blog_status($blog_id, 'public', 0);
     $blog = get_blog_details($blog_id);
     $this->assertEquals('0', $blog->public);
     $this->assertEquals(2, $test_action_counter);
     remove_action('update_blog_public', array($this, '_action_counter_cb'), 10);
 }
/**
 * Delete a blog
 *
 * @since 3.0.0
 *
 * @param int $blog_id Blog ID
 * @param bool $drop True if blog's table should be dropped.  Default is false.
 * @return void
 */
function wpmu_delete_blog( $blog_id, $drop = false ) {
	global $wpdb, $current_site;

	$switch = false;
	if ( $blog_id != $wpdb->blogid ) {
		$switch = true;
		switch_to_blog( $blog_id );
		$blog = get_blog_details( $blog_id );
	} else {
		$blog = $GLOBALS['current_blog'];
	}

	do_action( 'delete_blog', $blog_id, $drop );

	$users = get_users( array( 'blog_id' => $blog_id, 'fields' => 'ids' ) );

	// Remove users from this blog.
	if ( ! empty( $users ) ) {
		foreach ( $users as $user_id ) {
			remove_user_from_blog( $user_id, $blog_id );
		}
	}

	update_blog_status( $blog_id, 'deleted', 1 );

	// Don't destroy the initial, main, or root blog.
	if ( $drop && ( 1 == $blog_id || is_main_site( $blog_id ) || ( $blog->path == $current_site->path && $blog->domain == $current_site->domain ) ) )
		$drop = false;

	if ( $drop ) {

		$drop_tables = apply_filters( 'wpmu_drop_tables', $wpdb->tables( 'blog' ) );

		foreach ( (array) $drop_tables as $table ) {
			$wpdb->query( "DROP TABLE IF EXISTS `$table`" );
		}

		$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->blogs WHERE blog_id = %d", $blog_id ) );
		$dir = apply_filters( 'wpmu_delete_blog_upload_dir', WP_CONTENT_DIR . "/blogs.dir/{$blog_id}/files/", $blog_id );
		$dir = rtrim( $dir, DIRECTORY_SEPARATOR );
		$top_dir = $dir;
		$stack = array($dir);
		$index = 0;

		while ( $index < count( $stack ) ) {
			# Get indexed directory from stack
			$dir = $stack[$index];

			$dh = @opendir( $dir );
			if ( $dh ) {
				while ( ( $file = @readdir( $dh ) ) !== false ) {
					if ( $file == '.' || $file == '..' )
						continue;

					if ( @is_dir( $dir . DIRECTORY_SEPARATOR . $file ) )
						$stack[] = $dir . DIRECTORY_SEPARATOR . $file;
					else if ( @is_file( $dir . DIRECTORY_SEPARATOR . $file ) )
						@unlink( $dir . DIRECTORY_SEPARATOR . $file );
				}
			}
			$index++;
		}

		$stack = array_reverse( $stack );  // Last added dirs are deepest
		foreach( (array) $stack as $dir ) {
			if ( $dir != $top_dir)
			@rmdir( $dir );
		}
	}

	if ( $switch )
		restore_current_blog();
}
Beispiel #28
0
function wpmu_delete_blog($blog_id, $drop = false)
{
    global $wpdb;
    if ($blog_id != $wpdb->blogid) {
        $switch = true;
        switch_to_blog($blog_id);
    }
    do_action('delete_blog', $blog_id, $drop);
    $users = get_users_of_blog($blog_id);
    // Remove users from this blog.
    if (!empty($users)) {
        foreach ($users as $user) {
            remove_user_from_blog($user->user_id, $blog_id);
        }
    }
    update_blog_status($blog_id, 'deleted', 1);
    if ($drop) {
        $drop_tables = $wpdb->get_results("show tables LIKE '" . $wpdb->base_prefix . $blog_id . "\\_%'", ARRAY_A);
        $drop_tables = apply_filters('wpmu_drop_tables', $drop_tables);
        reset($drop_tables);
        foreach ((array) $drop_tables as $drop_table) {
            $wpdb->query("DROP TABLE IF EXISTS " . current($drop_table) . "");
        }
        $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->blogs} WHERE blog_id = %d", $blog_id));
        $dir = apply_filters('wpmu_delete_blog_upload_dir', constant("ABSPATH") . "wp-content/blogs.dir/{$blog_id}/files/", $blog_id);
        $dir = rtrim($dir, DIRECTORY_SEPARATOR);
        $top_dir = $dir;
        $stack = array($dir);
        $index = 0;
        while ($index < count($stack)) {
            # Get indexed directory from stack
            $dir = $stack[$index];
            $dh = @opendir($dir);
            if ($dh) {
                while (($file = @readdir($dh)) !== false) {
                    if ($file == '.' or $file == '..') {
                        continue;
                    }
                    if (@is_dir($dir . DIRECTORY_SEPARATOR . $file)) {
                        $stack[] = $dir . DIRECTORY_SEPARATOR . $file;
                    } else {
                        if (@is_file($dir . DIRECTORY_SEPARATOR . $file)) {
                            @unlink($dir . DIRECTORY_SEPARATOR . $file);
                        }
                    }
                }
            }
            $index++;
        }
        $stack = array_reverse($stack);
        // Last added dirs are deepest
        foreach ((array) $stack as $dir) {
            if ($dir != $top_dir) {
                @rmdir($dir);
            }
        }
    }
    $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->usermeta} WHERE meta_key = %s", 'wp_{$blog_id}_autosave_draft_ids'));
    if ($switch === true) {
        restore_current_blog();
    }
}
Beispiel #29
0
/**
 * Update this blog's 'public' setting in the global blogs table.
 *
 * Public blogs have a setting of 1, private blogs are 0.
 *
 * @since MU
 * @uses update_blog_status()
 *
 * @param int $old_value
 * @param int $value The new public value
 * @return bool
 */
function update_blog_public($old_value, $value)
{
    global $wpdb;
    do_action('update_blog_public');
    update_blog_status($wpdb->blogid, 'public', (int) $value);
}
Beispiel #30
0
function sitewide_tags_update_options()
{
    global $wpdb, $current_site, $current_user;
    if (!$_POST['tags_blog_enabled']) {
        if (get_sitewide_tags_option('tags_blog_enabled') != $_POST['tags_blog_enabled']) {
            update_sitewide_tags_option('tags_blog_enabled', 0, true);
        }
        return;
    }
    update_sitewide_tags_option('tags_blog_enabled', 1);
    if ((isset($_POST['tags_blog']) || isset($_POST['tags_blog_main_blog'])) && isset($_POST['tags_blog_public'])) {
        if ($_POST['tags_blog_main_blog'] == 1) {
            if ($current_site->blog_id) {
                $id = $current_site->blog_id;
            } else {
                $id = $wpdb->get_var("SELECT blog_id FROM {$wpdb->blogs} WHERE domain = '{$current_site->domain}' AND path = '{$current_site->path}'");
            }
            if ($id) {
                update_sitewide_tags_option('tags_blog_id', $id);
                update_sitewide_tags_option('tags_blog_main_blog', 1);
            } else {
                update_sitewide_tags_option('tags_blog_main_blog', 0);
            }
        } else {
            update_sitewide_tags_option('tags_blog_main_blog', 0);
            $tags_blog = $_POST['tags_blog'];
            update_sitewide_tags_option('tags_blog', $tags_blog);
            if (constant('VHOST') == 'yes') {
                $domain = $tags_blog . '.' . $current_site->domain;
                $path = $current_site->path;
            } else {
                $domain = $current_site->domain;
                $path = trailingslashit($current_site->path . $tags_blog);
            }
            $tags_blog_id = $wpdb->get_var("SELECT blog_id FROM {$wpdb->blogs} WHERE domain = '{$domain}' AND path = '{$path}'");
            if ($tags_blog_id) {
                update_sitewide_tags_option('tags_blog_id', $tags_blog_id);
            } else {
                $wpdb->hide_errors();
                $id = wpmu_create_blog($domain, $path, __('Global Posts', 'wpmu-sitewide-tags'), $current_user->id, array("public" => $_POST['tags_blog_public']), $current_site->id);
                update_sitewide_tags_option('tags_blog_id', $id);
                $wpdb->show_errors();
            }
        }
        $tags_blog_public = (int) $_POST['tags_blog_public'];
        update_sitewide_tags_option('tags_blog_public', $tags_blog_public);
        update_blog_option($tags_blog_id, 'blog_public', $tags_blog_public);
        update_blog_status($tags_blog_id, 'public', $tags_blog_public);
    }
    if (isset($_POST['tags_max_posts'])) {
        update_sitewide_tags_option('tags_max_posts', (int) $_POST['tags_max_posts']);
    }
    if (get_sitewide_tags_option('tags_blog_pages') != $_POST['tags_blog_pages']) {
        update_sitewide_tags_option('tags_blog_pages', (int) $_POST['tags_blog_pages']);
    }
    if (get_sitewide_tags_option('tags_blog_pub_check') != $_POST['tags_blog_pub_check']) {
        if ($tags_blog_public == 0) {
            update_sitewide_tags_option('tags_blog_pub_check', (int) $_POST['tags_blog_pub_check']);
        } else {
            update_sitewide_tags_option('tags_blog_pub_check', 0);
        }
    }
    if ($_POST['tags_blog_postmeta'] != '') {
        $meta_keys = split("\n", stripslashes($_POST['tags_blog_postmeta']));
        foreach ((array) $meta_keys as $key) {
            $keys[] = trim($key);
        }
        update_sitewide_tags_option("tags_blog_postmeta", $keys);
    } else {
        update_sitewide_tags_option("tags_blog_postmeta", '');
    }
    // force write if changes saved
    update_sitewide_tags_option(true);
}