function bp_groupblog_blog_defaults($blog_id)
{
global $bp, $wp_rewrite;
// only apply defaults to groupblog blogs
if (bp_is_groups_component()) {
switch_to_blog($blog_id);
// get the site options
$options = get_site_option('bp_groupblog_blog_defaults_options');
foreach ((array) $options as $key => $value) {
update_option($key, $value);
}
// override default themes
if (!empty($options['theme'])) {
// we want something other than the default theme
$values = explode("|", $options['theme']);
switch_theme($values[0], $values[1]);
}
// groupblog bonus options
if (strlen($options['default_cat_name']) > 0) {
global $wpdb;
$cat = $options['default_cat_name'];
$slug = str_replace(' ', '-', strtolower($cat));
$results = $wpdb->query($wpdb->prepare("UPDATE {$wpdb->terms} SET name = %s, slug = %s WHERE term_id = 1", $cat, $slug));
}
if (strlen($options['default_link_cat']) > 0) {
global $wpdb;
$cat = $options['default_link_cat'];
$slug = str_replace(' ', '-', strtolower($cat));
$results = $wpdb->query($wpdb->prepare("UPDATE {$wpdb->terms} SET name = %s, slug = %s WHERE term_id = 2", $cat, $slug));
}
if (isset($options['delete_first_post']) && $options['delete_first_post'] == 1) {
global $wpdb;
$statement = "UPDATE {$wpdb->posts} SET post_status = 'draft' WHERE id = 1";
$results = $wpdb->query($statement);
}
if (isset($options['delete_first_comment']) && $options['delete_first_comment'] == 1) {
wp_delete_comment(1);
}
if ($options['delete_blogroll_links'] == 1) {
wp_delete_link(1);
//delete Wordpress.com blogroll link
wp_delete_link(2);
//delete Wordpress.org blogroll link
}
if ($options['redirectblog'] == 2) {
$blog_page = array('comment_status' => 'closed', 'ping_status' => 'closed', 'post_status' => 'publish', 'post_name' => $options['pageslug'], 'post_title' => $options['pagetitle'], 'post_type' => 'page', 'post_content' => __('<p><strong>This page has been created automatically by the BuddyPress GroupBlog plugin.</strong></p><p>Please contact the site admin if you see this message instead of your blog posts. Possible solution: please advise your site admin to create the <a href="http://codex.wordpress.org/Pages#Creating_Your_Own_Page_Templates">page template</a> needed for the BuddyPress GroupBlog plugin.<p>', 'groupblog'));
$blog_page_id = wp_insert_post($blog_page);
if ($blog_page_id) {
add_post_meta($blog_page_id, '_wp_page_template', 'blog.php');
}
add_post_meta($blog_page_id, 'created_by_groupblog_dont_change', '1');
// Set the Blog Reading Settings to load the template page as front page
if ($options['deep_group_integration'] == 1) {
update_option('show_on_front', 'page');
update_option('page_on_front', $blog_page_id);
}
}
restore_current_blog();
}
}
/**
* Delete the bookmark corresponding to this container.
* Also removes the synch. record of the container and removes all associated instances.
*
* @return bool|WP_error
*/
function delete_wrapped_object()
{
if (wp_delete_link($this->container_id)) {
//Note that there is no need to explicitly delete the synch. record and instances
//associated with this link - wp_delete_link() will execute the 'delete_link' action,
//which will be noticed by blcBookmarkManager, which will then delete anything that needs
//to be deleted.
//But in case the (undocumented) behaviour of wp_delete_link() changes in a later WP version,
//add a call to $this->delete() here.
return true;
} else {
$bookmark = $this->get_wrapped_object();
if (is_null($bookmark)) {
$link_name = "[nonexistent]";
} else {
$link_name = sanitize_bookmark_field('link_name', $bookmark->link_name, $this->container_id, 'display');
}
$msg = sprintf(__('Failed to delete blogroll link "%s" (%d)', 'broken-link-checker'), $link_name, $this->container_id);
return new WP_Error('delete_failed', $msg);
}
}
/**
* Remove user and optionally reassign posts and links to another user.
*
* If the $reassign parameter is not assigned to an User ID, then all posts will
* be deleted of that user. The action 'delete_user' that is passed the User ID
* being deleted will be run after the posts are either reassigned or deleted.
* The user meta will also be deleted that are for that User ID.
*
* @since unknown
*
* @param int $id User ID.
* @param int $reassign Optional. Reassign posts and links to new User ID.
* @return bool True when finished.
*/
function wp_delete_user($id, $reassign = 'novalue') {
global $wpdb;
$id = (int) $id;
$user = new WP_User($id);
// allow for transaction statement
do_action('delete_user', $id);
if ($reassign == 'novalue') {
$post_ids = $wpdb->get_col( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_author = %d", $id) );
if ($post_ids) {
foreach ($post_ids as $post_id)
wp_delete_post($post_id);
}
// Clean links
$link_ids = $wpdb->get_col( $wpdb->prepare("SELECT link_id FROM $wpdb->links WHERE link_owner = %d", $id) );
if ( $link_ids ) {
foreach ( $link_ids as $link_id )
wp_delete_link($link_id);
}
} else {
$reassign = (int) $reassign;
$wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_author = %d WHERE post_author = %d", $reassign, $id) );
$wpdb->query( $wpdb->prepare("UPDATE $wpdb->links SET link_owner = %d WHERE link_owner = %d", $reassign, $id) );
}
// FINALLY, delete user
$wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->usermeta WHERE user_id = %d", $id) );
$wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->users WHERE ID = %d", $id) );
wp_cache_delete($id, 'users');
wp_cache_delete($user->user_login, 'userlogins');
wp_cache_delete($user->user_email, 'useremail');
wp_cache_delete($user->user_nicename, 'userslugs');
// allow for commit transaction
do_action('deleted_user', $id);
return true;
}
/**
* Remove user and optionally reassign posts and links to another user.
*
* If the $reassign parameter is not assigned to an User ID, then all posts will
* be deleted of that user. The action 'delete_user' that is passed the User ID
* being deleted will be run after the posts are either reassigned or deleted.
* The user meta will also be deleted that are for that User ID.
*
* @since 2.0.0
*
* @param int $id User ID.
* @param int $reassign Optional. Reassign posts and links to new User ID.
* @return bool True when finished.
*/
function wp_delete_user($id, $reassign = 'novalue')
{
global $wpdb;
$id = (int) $id;
$user = new WP_User($id);
// allow for transaction statement
do_action('delete_user', $id);
if ('novalue' === $reassign || null === $reassign) {
$post_types_to_delete = array();
foreach (get_post_types(array(), 'objects') as $post_type) {
if ($post_type->delete_with_user) {
$post_types_to_delete[] = $post_type->name;
} elseif (null === $post_type->delete_with_user && post_type_supports($post_type->name, 'author')) {
$post_types_to_delete[] = $post_type->name;
}
}
$post_types_to_delete = apply_filters('post_types_to_delete_with_user', $post_types_to_delete, $id);
$post_types_to_delete = implode("', '", $post_types_to_delete);
$post_ids = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_author = %d AND post_type IN ('{$post_types_to_delete}')", $id));
if ($post_ids) {
foreach ($post_ids as $post_id) {
wp_delete_post($post_id);
}
}
// Clean links
$link_ids = $wpdb->get_col($wpdb->prepare("SELECT link_id FROM {$wpdb->links} WHERE link_owner = %d", $id));
if ($link_ids) {
foreach ($link_ids as $link_id) {
wp_delete_link($link_id);
}
}
} else {
$reassign = (int) $reassign;
$wpdb->update($wpdb->posts, array('post_author' => $reassign), array('post_author' => $id));
$wpdb->update($wpdb->links, array('link_owner' => $reassign), array('link_owner' => $id));
}
// FINALLY, delete user
if (is_multisite()) {
remove_user_from_blog($id, get_current_blog_id());
} else {
$meta = $wpdb->get_col($wpdb->prepare("SELECT umeta_id FROM {$wpdb->usermeta} WHERE user_id = %d", $id));
foreach ($meta as $mid) {
delete_metadata_by_mid('user', $mid);
}
$wpdb->delete($wpdb->users, array('ID' => $id));
}
clean_user_cache($user);
// allow for commit transaction
do_action('deleted_user', $id);
return true;
}
/**
* Remove user and optionally reassign posts and links to another user.
*
* If the $reassign parameter is not assigned to an User ID, then all posts will
* be deleted of that user. The action 'delete_user' that is passed the User ID
* being deleted will be run after the posts are either reassigned or deleted.
* The user meta will also be deleted that are for that User ID.
*
* @since unknown
*
* @param int $id User ID.
* @param int $reassign Optional. Reassign posts and links to new User ID.
* @return bool True when finished.
*/
function wp_delete_user($id, $reassign = 'novalue')
{
global $wpdb;
$id = (int) $id;
// allow for transaction statement
do_action('delete_user', $id);
if ('novalue' === $reassign || null === $reassign) {
$post_ids = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_author = %d", $id));
if ($post_ids) {
foreach ($post_ids as $post_id) {
wp_delete_post($post_id);
}
}
// Clean links
$link_ids = $wpdb->get_col($wpdb->prepare("SELECT link_id FROM {$wpdb->links} WHERE link_owner = %d", $id));
if ($link_ids) {
foreach ($link_ids as $link_id) {
wp_delete_link($link_id);
}
}
} else {
$reassign = (int) $reassign;
$wpdb->update($wpdb->posts, array('post_author' => $reassign), array('post_author' => $id));
$wpdb->update($wpdb->links, array('link_owner' => $reassign), array('link_owner' => $id));
}
clean_user_cache($id);
// FINALLY, delete user
if (!is_multisite()) {
$wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->usermeta} WHERE user_id = %d", $id));
$wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->users} WHERE ID = %d", $id));
} else {
$level_key = $wpdb->get_blog_prefix() . 'capabilities';
// wpmu site admins don't have user_levels
$wpdb->query("DELETE FROM {$wpdb->usermeta} WHERE user_id = {$id} AND meta_key = '{$level_key}'");
}
// allow for commit transaction
do_action('deleted_user', $id);
return true;
}
function set_blog_defaults($blog_id, $user_id)
{
global $wp_rewrite, $wpdb, $current_site;
switch_to_blog($blog_id);
// get the site options
$options = get_site_option('cets_blog_defaults_options');
// check for the blogname_flag and if it's 0, then delete the blogname option
if ($options['blogname_flag'] == 0 && isset($options['blogname'])) {
unset($options['blogname']);
}
// check for the blog_public setting and if it's blank, delete it
if (strlen($options['blog_public']) == 0) {
unset($options['blog_public']);
}
// bonus options - set these first and then unset each one so they don't clutter the database
// Add User to Blog
if ($options['add_user_to_blog'] == 1) {
if(strlen($options['add_user_to_blog_id']) == 1) {
add_user_to_blog( $options['add_user_to_blog_id'], $user_id, $options['add_user_to_blog_role'] );
}
elseif (strlen($options['add_user_to_blog_id']) > 1) {
$blogs = explode(',', $options['add_user_to_blog_id']);
foreach ($blogs as $blog){
add_user_to_blog( $blog, $user_id, $options['add_user_to_blog_role'] );
}
}
}
unset($options['add_user_to_blog']);
unset($options['add_user_to_blog_role']);
unset($options['add_user_to_blog_id']);
// Delete Links
if ($options['delete_blogroll_links'] == 1) {
wp_delete_link(1); // documentation
wp_delete_link(2); // wordpress blog
wp_delete_link(3); //delete suggest ideas
wp_delete_link(4); //delete support forum
wp_delete_link(5); //delete plugins
wp_delete_link(6); //delete themes
wp_delete_link(7); //delete wp planet
}
unset($options['delete_blogroll_links']);
// Default Category Name
if (strlen($options['default_cat_name']) > 0){
global $wpdb;
$cat = $options['default_cat_name'];
$slug = str_replace(' ', '-', strtolower($cat));
$results = $wpdb->query( $wpdb->prepare("UPDATE $wpdb->terms SET name = %s, slug = %s WHERE term_id = 1", $cat, $slug ) );
}
unset($options['default_cat_name']);
// Default Link Category
if (strlen($options['default_link_cat']) > 0){
global $wpdb;
$cat = $options['default_link_cat'];
$slug = str_replace(' ', '-', strtolower($cat));
$results = $wpdb->query( $wpdb->prepare("UPDATE $wpdb->terms SET name = %s, slug = %s WHERE term_id = 2", $cat, $slug ) );
}
unset($options['default_link_cat']);
//Delete First Comment
if (isset($options['delete_first_comment']) && $options['delete_first_comment'] == 1){
wp_delete_comment( 1 );
}
unset($options['delete_first_comment']);
// Close Comments on Hello World
if (isset($options['close_comments_on_hello_world']) && $options['close_comments_on_hello_world'] == 1){
global $wpdb;
$statement = "UPDATE $wpdb->posts SET comment_status = 'closed' WHERE id = 1";
$results = $wpdb->query( $statement );
}
unset($options['close_comments_on_hello_world']);
// Close Comments on About Page
if (isset($options['close_comments_on_about_page']) && $options['close_comments_on_about_page'] == 1){
global $wpdb;
$statement = "UPDATE $wpdb->posts SET comment_status = 'closed' WHERE id = 2";
//.........这里部分代码省略.........
/**
* Delete a user from the network and remove from all sites.
*
* @since 3.0.0
*
* @todo Merge with wp_delete_user() ?
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param int $id The user ID.
* @return bool True if the user was deleted, otherwise false.
*/
function wpmu_delete_user($id)
{
global $wpdb;
if (!is_numeric($id)) {
return false;
}
$id = (int) $id;
$user = new WP_User($id);
if (!$user->exists()) {
return false;
}
// Global super-administrators are protected, and cannot be deleted.
$_super_admins = get_super_admins();
if (in_array($user->user_login, $_super_admins, true)) {
return false;
}
/**
* Fires before a user is deleted from the network.
*
* @since MU
*
* @param int $id ID of the user about to be deleted from the network.
*/
do_action('wpmu_delete_user', $id);
$blogs = get_blogs_of_user($id);
if (!empty($blogs)) {
foreach ($blogs as $blog) {
switch_to_blog($blog->userblog_id);
remove_user_from_blog($id, $blog->userblog_id);
$post_ids = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_author = %d", $id));
foreach ((array) $post_ids as $post_id) {
wp_delete_post($post_id);
}
// Clean links
$link_ids = $wpdb->get_col($wpdb->prepare("SELECT link_id FROM {$wpdb->links} WHERE link_owner = %d", $id));
if ($link_ids) {
foreach ($link_ids as $link_id) {
wp_delete_link($link_id);
}
}
restore_current_blog();
}
}
$meta = $wpdb->get_col($wpdb->prepare("SELECT umeta_id FROM {$wpdb->usermeta} WHERE user_id = %d", $id));
foreach ($meta as $mid) {
delete_metadata_by_mid('user', $mid);
}
$wpdb->delete($wpdb->users, array('ID' => $id));
clean_user_cache($user);
/** This action is documented in wp-admin/includes/user.php */
do_action('deleted_user', $id);
return true;
}
/**
* Remove user and optionally reassign posts and links to another user.
*
* If the $reassign parameter is not assigned to an User ID, then all posts will
* be deleted of that user. The action 'delete_user' that is passed the User ID
* being deleted will be run after the posts are either reassigned or deleted.
* The user meta will also be deleted that are for that User ID.
*
* @since 2.0.0
*
* @param int $id User ID.
* @param int $reassign Optional. Reassign posts and links to new User ID.
* @return bool True when finished.
*/
function wp_delete_user($id, $reassign = 'novalue')
{
global $wpdb;
$id = (int) $id;
$user = new WP_User($id);
// allow for transaction statement
do_action('delete_user', $id);
if ('novalue' === $reassign || null === $reassign) {
$post_ids = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_author = %d", $id));
if ($post_ids) {
foreach ($post_ids as $post_id) {
wp_delete_post($post_id);
}
}
// Clean links
$link_ids = $wpdb->get_col($wpdb->prepare("SELECT link_id FROM {$wpdb->links} WHERE link_owner = %d", $id));
if ($link_ids) {
foreach ($link_ids as $link_id) {
wp_delete_link($link_id);
}
}
} else {
$reassign = (int) $reassign;
$wpdb->update($wpdb->posts, array('post_author' => $reassign), array('post_author' => $id));
$wpdb->update($wpdb->links, array('link_owner' => $reassign), array('link_owner' => $id));
}
// FINALLY, delete user
if (is_multisite()) {
remove_user_from_blog($id, get_current_blog_id());
} else {
$meta = $wpdb->get_col($wpdb->prepare("SELECT umeta_id FROM {$wpdb->usermeta} WHERE user_id = %d", $id));
foreach ($meta as $mid) {
delete_metadata_by_mid('user', $mid);
}
$wpdb->delete($wpdb->users, array('ID' => $id));
}
clean_user_cache($user);
// allow for commit transaction
do_action('deleted_user', $id);
return true;
}
/**
* Remove user and optionally reassign posts and links to another user.
*
* If the $reassign parameter is not assigned to an User ID, then all posts will
* be deleted of that user. The action 'delete_user' that is passed the User ID
* being deleted will be run after the posts are either reassigned or deleted.
* The user meta will also be deleted that are for that User ID.
*
* @since 2.0.0
*
* @param int $id User ID.
* @param int $reassign Optional. Reassign posts and links to new User ID.
* @return bool True when finished.
*/
function wp_delete_user($id, $reassign = 'novalue')
{
global $wpdb;
$id = (int) $id;
$user = new WP_User($id);
if (!$user->exists()) {
return false;
}
// allow for transaction statement
do_action('delete_user', $id);
if ('novalue' === $reassign || null === $reassign) {
$post_types_to_delete = array();
foreach (get_post_types(array(), 'objects') as $post_type) {
if ($post_type->delete_with_user) {
$post_types_to_delete[] = $post_type->name;
} elseif (null === $post_type->delete_with_user && post_type_supports($post_type->name, 'author')) {
$post_types_to_delete[] = $post_type->name;
}
}
$post_types_to_delete = apply_filters('post_types_to_delete_with_user', $post_types_to_delete, $id);
$post_types_to_delete = implode("', '", $post_types_to_delete);
$post_ids = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_author = %d AND post_type IN ('{$post_types_to_delete}')", $id));
if ($post_ids) {
foreach ($post_ids as $post_id) {
wp_delete_post($post_id);
}
}
// Clean links
$link_ids = $wpdb->get_col($wpdb->prepare("SELECT link_id FROM {$wpdb->links} WHERE link_owner = %d", $id));
if ($link_ids) {
foreach ($link_ids as $link_id) {
wp_delete_link($link_id);
}
}
} else {
$reassign = (int) $reassign;
$post_ids = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_author = %d", $id));
$wpdb->update($wpdb->posts, array('post_author' => $reassign), array('post_author' => $id));
if (!empty($post_ids)) {
foreach ($post_ids as $post_id) {
clean_post_cache($post_id);
}
}
$link_ids = $wpdb->get_col($wpdb->prepare("SELECT link_id FROM {$wpdb->links} WHERE link_owner = %d", $id));
$wpdb->update($wpdb->links, array('link_owner' => $reassign), array('link_owner' => $id));
if (!empty($link_ids)) {
foreach ($link_ids as $link_id) {
clean_bookmark_cache($link_id);
}
}
}
// FINALLY, delete user
if (is_multisite()) {
remove_user_from_blog($id, get_current_blog_id());
} else {
$meta = $wpdb->get_col($wpdb->prepare("SELECT umeta_id FROM {$wpdb->usermeta} WHERE user_id = %d", $id));
$group_user = $_POST['users'];
//print_r($group_user);
//exit();
foreach ($meta as $mid) {
delete_metadata_by_mid('user', $mid);
}
$direct = ABSPATH;
require_once $direct . '/User.php';
require_once $direct . '/course.php';
$user_course = new User();
$course = new Course();
foreach ($group_user as $gid) {
$get_lmsid = "select user_lms from wp_users where ID=" . $gid;
$getlms = $wpdb->get_row($get_lmsid);
$res = $user_course->delete_user(1, $getlms->user_lms);
}
//echo "hiiiiiiiiiii".$id;
//exit();
$wpdb->delete($wpdb->users, array('ID' => $id));
}
clean_user_cache($user);
// allow for commit transaction
do_action('deleted_user', $id);
return true;
}
请发表评论