{"id":3491,"date":"2016-02-25T09:34:38","date_gmt":"2016-02-25T08:34:38","guid":{"rendered":"http:\/\/iworks.pl\/en\/?p=3491"},"modified":"2016-02-25T16:28:18","modified_gmt":"2016-02-25T15:28:18","slug":"add-user-admin-with-password-admin","status":"publish","type":"post","link":"http:\/\/iworks.pl\/en\/2016\/02\/25\/add-user-admin-with-password-admin\/","title":{"rendered":"Add user admin with password admin"},"content":{"rendered":"<p>When I test client sites I need to re-create this site on my local machine. I often use Duplicator plugin to get full backup of client site with files and database dump. I need a login to WordPress too. Sometimes client create a login for me, but sometimes not.<\/p>\n<p>This is a code which allow to change password for user &#8220;admin&#8221; or create the user &#8220;admin&#8221; with password &#8220;admin&#8221;.<\/p>\n<pre lang=\"php\" escaped=\"true\">require 'wp-load.php';\r\n$admin = get_user_by( 'login', 'admin' );\r\nif ( !empty( $admin ) ) {\r\n    wp_set_password( 'admin', $admin-&gt;ID );\r\n    echo 'New password \"admin\" for user \"admin\" was set.';\r\n    return;\r\n}\r\n$admin_id = wp_create_user( 'admin', 'admin', sprintf( 'admin-%d@example.com', rand() ) );\r\n$admin = new WP_User( $admin_id );\r\n$admin-&gt;add_role( 'administrator' );\r\necho 'New user \"admin\" with password \"admin\" was created.';\r\n<\/pre>\n<h2>How to use it?<\/h2>\n<p>Copy this file to root directory of your WordPress and enter URL in to browser. Remember to delete this file after you create a user.<\/p>\n<p>And <strong>never<\/strong> use this on live sites.<\/p>\n[zip href=\"http:\/\/iworks.pl\/wp-content\/uploads\/2016\/02\/iworks-set-admin.zip\" lang=\"en\"]iworks-set-admin.zip[\/zip]\n","protected":false},"excerpt":{"rendered":"<p>When I test client sites I need to re-create this site on my local machine. I often use Duplicator plugin to get full backup of client site with files and database dump. I need a login to WordPress too. Sometimes client create a login for me, but sometimes not. This is a code which allow [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3499,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_links_to":"","_links_to_target":""},"categories":[131],"tags":[839,860],"class_list":["post-3491","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-wordpress","tag-admin","tag-cli","has-thumbnail"],"_links":{"self":[{"href":"http:\/\/iworks.pl\/en\/wp-json\/wp\/v2\/posts\/3491","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/iworks.pl\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/iworks.pl\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/iworks.pl\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/iworks.pl\/en\/wp-json\/wp\/v2\/comments?post=3491"}],"version-history":[{"count":0,"href":"http:\/\/iworks.pl\/en\/wp-json\/wp\/v2\/posts\/3491\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/iworks.pl\/en\/wp-json\/wp\/v2\/media\/3499"}],"wp:attachment":[{"href":"http:\/\/iworks.pl\/en\/wp-json\/wp\/v2\/media?parent=3491"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/iworks.pl\/en\/wp-json\/wp\/v2\/categories?post=3491"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/iworks.pl\/en\/wp-json\/wp\/v2\/tags?post=3491"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}