I have this blog in iPage and it used WorldPress. In 2018 I had a period of getting Internal Service Error all the time and made a simple patch, which worked fine at that time. Later there came new updates of WorldPress and I did not need to patch the code. But yesterday I again started getting this error. So I looked at what is the reason this time. It is not the same, but I explain what you can do to locate the error. However, before you waste time reading this, I just got in to my blog, updated to the latest version of WP and at the moment it workd. So I will not do anything right now, but if you in some future have this problem, so you can indeed debug the login script and pinpoint where the problem is. This is why I wrote this post. (Update, seems to be Internal Service Error every now and then. I will debug more when I again have time. It is a transient problem this time.)
In iPage you can access the blog code through ftp. I downloaded the free WinSCP and will explain how to check the code using it. Firstly you start WinSCP and select FTP. If your blog is at the address www.example.com, then the ftp server address is ftp.example.com.
It requires a user name and a password. In iPage they are the name and password to the Control Panel. That is, not the name and password you use when accessing the blog. WinSCP shows the names of all files in the remote site. There is a file wp-login.php. I suggest you save the version there now is under some name before doing changes to the code. WinSCP has a nice editor, so clicking the file name it opens. Rather close to the end you find the following code (or in a newer version it may be a bit changed, but it is essentially the same)
if ( ( empty( $redirect_to ) || $redirect_to == ‘wp-admin/’ || $redirect_to == admin_url() ) ) {
// If the user doesn’t belong to a blog, send them
to user admin. If the user can’t edit posts,
send them to their profile.
if ( is_multisite() && !get_active_blog_for_user($user->ID) &&
!is_super_admin( $user->ID ) ) $redirect_to = user_admin_url();
elseif ( is_multisite() && !$user->has_cap(‘read’) )
$redirect_to = get_dashboard_url( $user->ID );
elseif ( !$user->has_cap(‘edit_posts’) )
$redirect_to = $user->has_cap( ‘read’ ) ?
admin_url( ‘profile.php’ ) : home_url();
wp_redirect( $redirect_to );
exit();
}
This is where is should come when doing login. It makes the login at we_redirect($redirect_to); command.
If you look at the code in wp-login.php there is the case login. It comes to this case twice. First time it is before you give the username and password and it does not come to the code above. It continues further and comes to the following code:
* Fires following the ‘Password’ field in the login form.
*
* @since 2.1.0
*/
do_action( ‘login_form’ );
This is quite close to the end of the code. Insert to the code after do_action(‘login_form’); the lines
printf(“hello”);
exit();
and try to log to your blog. You see that do_action makes the login box and you see hello written in the lower part of it. You can give the username and password, but there is no login button. This is because if has to run another time and come to the code above. So, remove these printf and exit and put them infront of we_redirect($redirect_to); Then try to login. Now you should have the login form with the login button. When you give the username and password and press the button, there should appear in the upper left corner hello. Then nothing happens as you did exit(); That is, there should not be Internal Service Error. If it works like this, then your problem is wp_redirect($redirect_to); You can print what $redirect_to is, so remove the printf(“hello”); and replace it with printf($redirect_to); and try to login. It should write to the left upper corner
Back in 2018 there was an error. wp_redirect($redirect_to); expected that $redirect_to is ‘http://www.example.com/wp-admin/index.php’, so I made a fix by calling directly wp_redirect(‘http://www.example.com/wp-admin/index.php’);
Not to mess uo any more than needed, I inserted an if-case
if ( is_multisite() && !get_active_blog_for_user($user->ID) &&
!is_super_admin( $user->ID ) ) $redirect_to = user_admin_url();
elseif ( is_multisite() && !$user->has_cap(‘read’) )
$redirect_to = get_dashboard_url( $user->ID );
elseif ( !$user->has_cap(‘edit_posts’) )
$redirect_to = $user->has_cap( ‘read’ ) ?
admin_url( ‘profile.php’ ) : home_url();
else {
wp_redirect(‘http://www.example.com/wp-admin/index.php’);
exit();
}
wp_redirect( $redirect_to );
exit();
It worked at that time. Today WP code writers have modified wp_redirect. It gives and error if you try to set $redirect_to to a different value or try to call wp_redirect with an address as I do above. But the code is fixed and it should work with $redirect_to set to ‘http://www.example.com/wp-admin/’. Therefore, the problem was not here.
I did not do any change and the program started working yesterday evening. Today morning I again got Internal Service Error. When I got this error, execution went to do_action(‘login_form’); but it never come to the wp_redirect($redirect_to);. So, it was something between these two.
At the very end of the file you find
<?php
login_footer();
break;
} // end action switch
This is the place where it puts the login button. It never comes out of login_footer(); Going to login_footer() we find that the execution prints hello12 and hello13 but not hello14. But is is because it is in another division. We should put exit after hello14.
function login_footer($input_id = ”) {
global $interim_login;
// Don’t allow interim logins to navigate away from the page.
if ( ! $interim_login ): ?>
<p id=”backtoblog”><a href=”<?php echo esc_url( home_url( ‘/’ ) );
?>”><?php
/* translators: %s: site title */
printf( _x( ‘← Back to %s’, ‘site’ ), get_bloginfo( ‘title’,
‘display’ ) );
?></a></p>
<?php the_privacy_policy_link( ‘<div class=”privacy-policy-page-link”>’,
‘</div>’ ); ?>
printf(“hello12”);
<?php endif; ?>
printf(“hello13”);
</div>
printf(“hello14”);
<?php if ( !empty($input_id) ) : ?>
So here we have the problem this time. The <?php endif; ?> must be an end for some if. There is only if ( ! $interim_login ): ?>.
It looks like it should not go to this part at all. So, we can replace this if with
if (0 /** ! $interim_login */): ?>.
Now it goes through the routine and exists login_footer(). Then we have to see if it comes to the part where wp_redirect is.
We should have $interim_login=false as it is true only if a session expired. Thus, we should go in login_footer() to the if(! $interim_login). The it writes <-Back to your site.
Then comes a new part that was not before.
<?php the_privacy_policy_link( ‘<div class=”privacy-policy-page-link”>’, ‘</div>’ ); ?>
But removing this part does not help and it goes pass this part.
But now when I logged in it went through. So, I updated to the latest version and made all updates, and it seems to work now.
What I want to say in this post is that you can easily debug the script if you have the problem. The command printf(“hello”) works fine if it is in the code part and not in php and that is all that is needed to debug this script. The other thing is that you sometimes probably have to debug WP login since they give faulty (automatic) updates.