I am creating a product in wordpress and here i am installing the custom theme and plugins during wp installation.
No problem until here. But the admin wants to login automatically during the installation ends without prompting for log in and want to redirect to the page what i wish to give.
Any help?
I tried to put this code after the wp_install() in wp-admin/install.php
$creds = array();
$creds['user_login'] = $_POST['user_name'];
$creds['user_password'] = $_POST['admin_password'];
$creds['remember'] = true;
$user = wp_signon( $creds, false );
if ( is_wp_error($user) )
echo $user->get_error_message();
wp_redirect(home_url('products'));exit;
Your problem seems to be that you hook in too early (aside from the problem that you’re editing a core file), so let’s take a look at
wp-admin/install.php
:No hooks at all, but at the end of the page when everything was properly rendered, there’s a call for
wp_print_scripts( 'user-profile' )
. And gladly there we’ll find a number of hooks. One that directly sits inside that function on top of it and is named after the function itself:wp_print_scripts
. And other insideWP_Scripts
.So let’s give this a try (untested) with a small custom plugin:
I’m not sure if
admin_password
is the properform
fieldid
/name
. Normally/IIRC WP usesuser_password
. Second, the user won’t get logged in withhome_url( "products" )
. You’ll need to useadmin_url()
for that.Last Note: NEVER EVER edit a core file. You’ll loose all the changes during any upgrade. If it would be just about installing (and not upgrading) your way of doing it would somehow even be valid (if you want to maintain a WP fork), but not if you want to upgrade.
First, instead of editing the core file, notice the following:
wp-admin/install.php
includes thewp-admin/includes/upgrade.php
file, right at the top.wp-content/install.php
file and includes it if there. So, your custom install.php file gets included in the install process. This is important because,wp_install()
function is wrapped in anif ( !function_exists() )
type of check. Meaning that thewp_install()
function itself is “pluggable”.In other words, if you define your own
wp_install()
function in thewp-content/install.php
, then yours gets used instead, letting you customize the whole function all you like, without editing core.So, step 1: Copy the existing
wp_install()
function, as is, into yourwp-content/install.php
file. You will modify this function instead of editing the core code.As for step two, you want to auto-log the resulting user in and redirect. Fortunately, all you really have to do is to set a cookie and then redirect and exit. Easily done. Instead of the
return array
bit at the end of the function, do something more like this:Note: Untested. Haven’t tried it yet. But it should work. You may need to add error handling and such as well.