Skip to content

Instantly share code, notes, and snippets.

@bmakowski
Created October 25, 2016 11:31
Show Gist options
  • Save bmakowski/832edba8da837c86ee6936af6a91fec8 to your computer and use it in GitHub Desktop.
Save bmakowski/832edba8da837c86ee6936af6a91fec8 to your computer and use it in GitHub Desktop.
WPAllimport
<?php
/*
WP All Import DB Fix for showing incorrect users number
on WP Dashboard
Author: Bartek Makowski
*/
//inside main wordpress folder
/*
$table_name - usermeta table name
$capabilities_name - name of your site capabilities {site prefix}_capabilities
IMPORTANT - make full db backup before executing this
Script deletes all users capabilities except
admin user id = 1 (filtered with NOT IN(1))
*/
require_once('wp-config.php');
require_once('wp-settings.php');
global $wpdb;
$table_name = 'mgt_usermeta';
$capabilities_name = 'mgt_capabilities';
$all_capabilities_delete = $wpdb->get_results(
"
delete
FROM $table_name
WHERE meta_key = '$capabilities_name' and user_id NOT IN(1)
"
);
echo 'deleted all capabilities except for user_id = 1 <br/>';
$user_ids = $wpdb->get_results( "SELECT ID FROM $wpdb->users where ID NOT IN(1)" );
foreach($user_ids as $user){
echo $user->ID . ' added <br/>';
$wpdb->insert(
$table_name,
array(
'user_id' => $user->ID,
'meta_key' => $capabilities_name,
'meta_value' => 'a:1:{s:8:"customer";b:1;}'
),
array(
'%d',
'%s',
'%s'
)
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment