Add user admin with password admin

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 to change password for user “admin” or create the user “admin” with password “admin”.

require 'wp-load.php';
$admin = get_user_by( 'login', 'admin' );
if ( !empty( $admin ) ) {
    wp_set_password( 'admin', $admin->ID );
    echo 'New password "admin" for user "admin" was set.';
    return;
}
$admin_id = wp_create_user( 'admin', 'admin', sprintf( 'admin-%d@example.com', rand() ) );
$admin = new WP_User( $admin_id );
$admin->add_role( 'administrator' );
echo 'New user "admin" with password "admin" was created.';

How to use it?

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.

And never use this on live sites.

download file: iworks-set-admin.zip

How to choose custom field on entries list in Types?

This is pretty easy.

All what you need is made those three steps:

1. Add custom fields.

First you must add custom fields to selected post type or custom post type. Then go to Types -> Custom Fields and add a group with few fields. I added CPT “Clan” and group “Clan Data” and two fields “:

  1. “Since” – as a data field
  2. “Select field” – as a select

Custom Fields group with fields

2. Tick selected Custom Field(s).

After you successfully add a custom fields, go to custom post type edit screen and choose which custom fields should be displayed on entry list.

Edit Custom Post screen

3. Check it on list

Last step: check it on entries list.

Custom Post entries list