Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // to run this script this user needs to be able to access both databases
- $userName = "root";
- $password = "";
- $hostName = "localhost";
- $database = "db_name";
- $wpPrefix = "wp_"; // wordpress prefix
- // Connect to the Database
- $connection = new mysqli($hostName, $userName, $password, $database);
- if ($mysqli->connect_errno) {
- print(sprintf("error connecting to host %s, by user %s", $hostName, $userName));
- exit();
- }
- $query = '
- SELECT
- ju.id AS user_id,
- REPLACE(TRIM(LOWER(a.username)), \' \', \'_\') AS user_nicename,
- ju.email AS user_email,
- ju.params AS user_params,
- CASE ju.usertype
- WHEN \'Super Administrator\' THEN 10
- WHEN \'Administrator\' THEN 9
- WHEN \'Manager\' THEN 8
- WHEN \'Public Backend\' THEN 7
- WHEN \'Publisher\' THEN 6
- WHEN \'Editor\' THEN 5
- WHEN \'Author\' THEN 4
- WHEN \'Publisher\' THEN 3
- WHEN \'Editor\' THEN 2
- WHEN \'Author\' THEN 1
- ELSE 0
- END AS user_status,
- CASE a.block
- WHEN 1 THEN 2
- ELSE 0
- END AS user_block,
- ju.name AS display_name
- FROM
- db_name.jos_users ju
- ORDER BY
- ju.id
- ';
- $results = $mysqli->query($query);
- while ($row = $mysqli->fetch_assoc($results)) {
- $this_id = $row['user_id'];
- $this_name = $row['user_nicename'];
- $this_email = $row['user_email'];
- $this_status = $row['user_status'];
- $this_block = $row['user_block'];
- $this_params = $row['user_params'];
- $this_dispname = $row['display_name'];
- $wp_capabilities = ($this_status == 10) ? 'a:1:{s:13:\"administrator\";s:1:\"1\";}' : 'a:1:{s:10:\"subscriber\";s:1:\"1\";}';
- $insert_query = sprintf("
- INSERT INTO wp_usermeta
- ( user_id, meta_key, meta_value )
- VALUES
- ( $this_id, 'first_name', '%s' ),
- ( $this_id, 'last_name', '%s' ),
- ( $this_id, 'nickname', '%s' ),
- ( $this_id, 'description', ' ' ),
- ( $this_id, 'rich_editing', true ),
- ( $this_id, 'comment_shortcuts', false ),
- ( $this_id, 'admin_color', 'fresh' ),
- ( $this_id, 'use_ssl', 0 ),
- ( $this_id, 'show_admin_bar_front', true ),
- ( $this_id, 'show_admin_bar_admin', false ),
- ( $this_id, 'aim', ' ' ),
- ( $this_id, 'yim', ' ' ),
- ( $this_id, 'jabber', ' ' ),
- ( $this_id, '%scapabilities', '%s' ),
- ( $this_id, '%suser_level', '%s' );
- ",
- $this_name,
- $this_name,
- $this_name,
- $wpPrefix,
- $wp_capabilities,
- $wpPrefix,
- $this_status
- );
- $insert_result = $mysqli->query($insert_query);
- print_r($insert_result);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement