public/wordpress/wp-content/plugins/backupbuddy/classes/backup.php
/*	ms_copy_users_table()
	 *	
	 *  Step 7
	 *	Used by Multisite Exporting.
	 *	Copies over users to a temp table for this site for inclusion into the backup for creating a standalone backup from a subsite.
	 *	Authored by Ron H. Modified by Dustin B.
	 *	
	 *	@return		boolean			Currently only returns true.
	 */


Step 7
Used by Multisite Exporting.
Copies over users to a temp table for this site for inclusion into the backup for creating a standalone backup from a subsite.
Authored by Ron H. Modified by Dustin B.

@return         boolean                 Currently only returns true.
Step 7 Used by Multisite Exporting . Copies over users to a temp table for this site for inclusion into the backup for creating a standalone backup from a subsite . Authored by Ron H . Modified by Dustin B . @return boolean Currently only returns true .
public function ms_copy_users_table() {
		pb_backupbuddy::status( 'message', 'Copying temporary users table for users in this blog.' );
		global $wpdb, $current_blog;
		$new_user_tablename = $wpdb->prefix . 'users';
		$new_usermeta_tablename = $wpdb->prefix . 'usermeta';
		if ( $new_user_tablename == $wpdb->users ) {
			pb_backupbuddy::status( 'message', 'Temporary users table would match existing users table. Skipping creation of this temporary users & usermeta tables.' );
			return true;
		}
		pb_backupbuddy::status( 'message', 'Created new table `' . $new_user_tablename . '` like `' . $wpdb->users . '`.' );
		$wpdb->query( "CREATE TABLE `{$new_user_tablename}` LIKE `{$wpdb->users}`" );
		$wpdb->query( "INSERT `{$new_user_tablename}` SELECT * FROM `{$wpdb->users}`" );
		pb_backupbuddy::status( 'message', 'Created new table `' . $new_usermeta_tablename . '` like `' . $wpdb->usermeta . '`.' );
		$wpdb->query( "CREATE TABLE `{$new_usermeta_tablename}` LIKE `{$wpdb->usermeta}`" );
		$wpdb->query( "INSERT `{$new_usermeta_tablename}` SELECT * FROM `{$wpdb->usermeta}`" );
		$users_to_capture = array();
		$user_args = array(
			'blog_id' => $current_blog->blog_id
		);
		$users = get_users( $user_args );
		if ( $users ) {
			foreach ( $users as $user ) {
				array_push( $users_to_capture, $user->ID );
			}
		}
		$users_to_capture = implode( ',', $users_to_capture );
		pb_backupbuddy::status( 'details', 'User IDs to capture (' . count( $users_to_capture ) . ' total): ' . print_r( $users_to_capture, true ) );
		$wpdb->query( "DELETE from `{$new_user_tablename}` WHERE ID NOT IN( {$users_to_capture} )" );
		$wpdb->query( "DELETE from `{$new_usermeta_tablename}` WHERE user_id NOT IN( {$users_to_capture} )" );
		pb_backupbuddy::status( 'message', 'Copied temporary users table for users in this blog.' );
		return true;
	}
public function ms_copy_users_table ( ) { pb_backupbuddy :: status ( 'message' , 'Copying temporary users table for users in this blog.' ) ; global $ wpdb , $ current_blog ; $ new_user_tablename = $ wpdb -> prefix . 'users' ; $ new_usermeta_tablename = $ wpdb -> prefix . 'usermeta' ; if ( $ new_user_tablename == $ wpdb -> users ) { pb_backupbuddy :: status ( 'message' , 'Temporary users table would match existing users table. Skipping creation of this temporary users & usermeta tables.' ) ; return true ; } pb_backupbuddy :: status ( 'message' , 'Created new table `' . $ new_user_tablename . '` like `' . $ wpdb -> users . '`.' ) ; $ wpdb -> query ( " CREATE TABLE ` { $ new_user_tablename } ` LIKE ` { $ wpdb -> users } ` " ) ; $ wpdb -> query ( " INSERT ` { $ new_user_tablename } ` SELECT * FROM ` { $ wpdb -> users } ` " ) ; pb_backupbuddy :: status ( 'message' , 'Created new table `' . $ new_usermeta_tablename . '` like `' . $ wpdb -> usermeta . '`.' ) ; $ wpdb -> query ( " CREATE TABLE ` { $ new_usermeta_tablename } ` LIKE ` { $ wpdb -> usermeta } ` " ) ; $ wpdb -> query ( " INSERT ` { $ new_usermeta_tablename } ` SELECT * FROM ` { $ wpdb -> usermeta } ` " ) ; $ users_to_capture = array ( ) ; $ user_args = array ( 'blog_id' => $ current_blog -> blog_id ) ; $ users = get_users ( $ user_args ) ; if ( $ users ) { foreach ( $ users as $ user ) { array_push ( $ users_to_capture , $ user -> ID ) ; } } $ users_to_capture = implode ( ',' , $ users_to_capture ) ; pb_backupbuddy :: status ( 'details' , 'User IDs to capture (' . count ( $ users_to_capture ) . ' total): ' . print_r ( $ users_to_capture , true ) ) ; $ wpdb -> query ( " DELETE from ` { $ new_user_tablename } ` WHERE ID NOT IN(  { $ users_to_capture }  ) " ) ; $ wpdb -> query ( " DELETE from ` { $ new_usermeta_tablename } ` WHERE user_id NOT IN(  { $ users_to_capture }  ) " ) ; pb_backupbuddy :: status ( 'message' , 'Copied temporary users table for users in this blog.' ) ; return true ; }
ms_copy_users_table()
ms_copy_users_table ()
// Copy over users table to temporary table. // Copy over usermeta table to temporary table. // Get list of users associated with this site. // Remove users from temporary table that arent associated with this site.