Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. <?php
  2. // to run this script this user needs to be able to access both databases
  3. $userName = "root";
  4. $password = "";
  5. $hostName = "localhost";
  6. $database = "db_name";
  7. $wpPrefix = "wp_"; // wordpress prefix
  8.  
  9. // Connect to the Database
  10. $connection = new mysqli($hostName, $userName, $password, $database);
  11.  
  12. if ($mysqli->connect_errno) {
  13. print(sprintf("error connecting to host %s, by user %s", $hostName, $userName));
  14. exit();
  15. }
  16.  
  17. $query = '
  18. SELECT
  19. ju.id AS user_id,
  20. REPLACE(TRIM(LOWER(a.username)), \' \', \'_\') AS user_nicename,
  21. ju.email AS user_email,
  22. ju.params AS user_params,
  23. CASE ju.usertype
  24. WHEN \'Super Administrator\' THEN 10
  25. WHEN \'Administrator\' THEN 9
  26. WHEN \'Manager\' THEN 8
  27. WHEN \'Public Backend\' THEN 7
  28. WHEN \'Publisher\' THEN 6
  29. WHEN \'Editor\' THEN 5
  30. WHEN \'Author\' THEN 4
  31. WHEN \'Publisher\' THEN 3
  32. WHEN \'Editor\' THEN 2
  33. WHEN \'Author\' THEN 1
  34. ELSE 0
  35. END AS user_status,
  36. CASE a.block
  37. WHEN 1 THEN 2
  38. ELSE 0
  39. END AS user_block,
  40. ju.name AS display_name
  41. FROM
  42. db_name.jos_users ju
  43. ORDER BY
  44. ju.id
  45. ';
  46.  
  47. $results = $mysqli->query($query);
  48. while ($row = $mysqli->fetch_assoc($results)) {
  49. $this_id = $row['user_id'];
  50. $this_name = $row['user_nicename'];
  51. $this_email = $row['user_email'];
  52. $this_status = $row['user_status'];
  53. $this_block = $row['user_block'];
  54. $this_params = $row['user_params'];
  55. $this_dispname = $row['display_name'];
  56.  
  57. $wp_capabilities = ($this_status == 10) ? 'a:1:{s:13:\"administrator\";s:1:\"1\";}' : 'a:1:{s:10:\"subscriber\";s:1:\"1\";}';
  58.  
  59. $insert_query = sprintf("
  60. INSERT INTO wp_usermeta
  61. ( user_id, meta_key, meta_value )
  62. VALUES
  63. ( $this_id, 'first_name', '%s' ),
  64. ( $this_id, 'last_name', '%s' ),
  65. ( $this_id, 'nickname', '%s' ),
  66. ( $this_id, 'description', ' ' ),
  67. ( $this_id, 'rich_editing', true ),
  68. ( $this_id, 'comment_shortcuts', false ),
  69. ( $this_id, 'admin_color', 'fresh' ),
  70. ( $this_id, 'use_ssl', 0 ),
  71. ( $this_id, 'show_admin_bar_front', true ),
  72. ( $this_id, 'show_admin_bar_admin', false ),
  73. ( $this_id, 'aim', ' ' ),
  74. ( $this_id, 'yim', ' ' ),
  75. ( $this_id, 'jabber', ' ' ),
  76. ( $this_id, '%scapabilities', '%s' ),
  77. ( $this_id, '%suser_level', '%s' );
  78. ",
  79. $this_name,
  80. $this_name,
  81. $this_name,
  82. $wpPrefix,
  83. $wp_capabilities,
  84. $wpPrefix,
  85. $this_status
  86. );
  87.  
  88. $insert_result = $mysqli->query($insert_query);
  89. print_r($insert_result);
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement