|
1 | 1 | <?php |
2 | 2 | /* |
3 | 3 | Snippet Name: Create a user from hardcoded data and log in to WordPress. |
4 | | -Snippet URI: https://github.com/szepeviktor/wordpress-plugin-construction |
| 4 | +Version: 0.2.3 |
5 | 5 | Description: Unzip WordPress instead of uploading it file-by-file |
6 | | -Version: 0.2.2 |
| 6 | +Snippet URI: https://github.com/szepeviktor/wordpress-plugin-construction |
7 | 7 | License: The MIT License (MIT) |
8 | 8 | Author: Viktor Szépe |
9 | 9 | */ |
10 | 10 |
|
11 | 11 | /** |
12 | 12 | * Usage |
13 | 13 | * |
14 | | - * 1. Fill in your user details below. |
| 14 | + * 1. Fill in your user details below |
15 | 15 | * 2. Set a strong password! (user_pass) |
16 | | - * 3. Upload this file to your WordPress directory. |
17 | | - * 4. Load it in your browser: <YOURSITE.NET/WP-DIR>/wp-create-user.php |
| 16 | + * 3. Upload this file to your WordPress directory |
| 17 | + * 4. Load it in your browser: https://www.example.com/wordpress/wp-create-user.php |
18 | 18 | */ |
19 | 19 |
|
20 | | -$wcu_userdata = (object)array( |
21 | | - 'user_login' => "viktor", |
22 | | - 'nickname' => "v", |
23 | | - 'role' => "administrator", |
24 | | - 'user_email' => "viktor@szepe.net", |
25 | | - 'user_url' => "http://www.online1.hu/", |
26 | | - 'first_name' => "Viktor", |
27 | | - 'last_name' => "Szépe", |
28 | | - 'comment_shortcuts' => "", |
| 20 | +$wcu_userdata = (object) array( |
| 21 | + 'user_login' => 'viktor', |
| 22 | + 'nickname' => 'v', |
| 23 | + 'role' => 'administrator', |
| 24 | + 'user_email' => 'viktor@szepe.net', |
| 25 | + 'user_url' => 'https://github.com/szepeviktor', |
| 26 | + 'first_name' => 'Viktor', |
| 27 | + 'last_name' => 'Szépe', |
| 28 | + 'comment_shortcuts' => '', |
29 | 29 | 'use_ssl' => 0, |
30 | | - 'user_pass' => "12345" |
| 30 | + 'user_pass' => '12345', |
31 | 31 | ); |
32 | 32 |
|
| 33 | +@ini_set( 'display_errors', 1 ); |
| 34 | +@error_reporting( E_ALL ); |
| 35 | + |
33 | 36 | $wcu_html = '<!DOCTYPE html> |
34 | 37 | <html> |
35 | 38 | <meta charset="UTF-8"> |
|
39 | 42 | </body> |
40 | 43 | </html> |
41 | 44 | '; |
| 45 | + |
42 | 46 | $wcu_html_ok = ' |
43 | 47 | New user ID = %s |
44 | 48 | <script type="text/javascript">setTimeout(function () { window.location.href="%s"; }, 3000);</script> |
45 | 49 | '; |
46 | 50 |
|
47 | | -@ini_set( 'display_errors', 1 ); |
48 | | -@error_reporting( E_ALL ); |
49 | | - |
50 | 51 | $wcu_wpload_path = dirname( __FILE__ ) . '/wp-load.php'; |
51 | 52 |
|
52 | | -if ( ! file_exists( $wcu_wpload_path ) ) |
53 | | - return 'wp-load not found: ' . $wcu_wpload_path; |
| 53 | +if ( ! file_exists( $wcu_wpload_path ) ) { |
| 54 | + exit( 'wp-load not found: ' . $wcu_wpload_path ); |
| 55 | +} |
54 | 56 |
|
55 | 57 | define( 'WP_USE_THEMES', false ); |
56 | | -require_once( $wcu_wpload_path ); |
| 58 | +require_once $wcu_wpload_path; |
57 | 59 |
|
58 | 60 | $wcu_userid = wp_insert_user( $wcu_userdata ); |
59 | 61 |
|
60 | 62 | if ( is_wp_error( $wcu_userid ) ) { |
61 | | - printf( $wcu_html, 'Insert user failed: ' . $wcu_userid->get_error_message() ); |
62 | | -} else { |
63 | | - // Delete self |
64 | | - unlink( __FILE__ ); |
65 | | - // Log in |
66 | | - wp_set_auth_cookie( $wcu_userid ); |
67 | | - // Redirect to Dashboard |
68 | | - printf( sprintf( $wcu_html, $wcu_html_ok ), |
69 | | - $wcu_userid, |
70 | | - admin_url( 'profile.php#pass1' ) |
71 | | - ); |
| 63 | + exit( sprintf( $wcu_html, 'Insert user failed: ' . $wcu_userid->get_error_message() ) ); |
72 | 64 | } |
73 | 65 |
|
74 | | -exit; |
| 66 | +// Delete self |
| 67 | +unlink( __FILE__ ); |
| 68 | +// Log in |
| 69 | +wp_set_auth_cookie( $wcu_userid ); |
| 70 | +// Redirect to Dashboard |
| 71 | +exit( sprintf( sprintf( $wcu_html, $wcu_html_ok ), |
| 72 | + $wcu_userid, |
| 73 | + admin_url( 'profile.php#pass1' ) |
| 74 | +) ); |
0 commit comments