Passing User Messages to Another Page

A standard approach is to add a query parameter to the location header (redirect), for example: $redirect = add_query_arg( ‘my-form’, ‘success’, $redirect ); wp_redirect( $redirect ); exit; Then on the redirected-to page, you can conditionally display a message: <?php if ( filter_input( INPUT_GET, ‘my-form’ ) === ‘success’ ) : ?> Congrats! <?php endif ?>

Login to wp-admin “redirect_to” points to wrong URL after migration

I had the same issue. To fix it I had to make some changes to the database. Use phpMyAdmin or just log directly into the database and look at your wp_options table. Check the following two fields: siteurl and home. SELECT * FROM wp_options WHERE option_name IN (‘siteurl’, ‘home’); Make sure these fields hold the … Read more

How to hide/redirect the author page

You can do this at an earlier moment by hooking into the right action, like template_redirect, which fires right before the template will be displayed. add_action( ‘template_redirect’, ‘wpse14047_template_redirect’ ); function wpse14047_template_redirect() { if ( is_author() ) { $id = get_query_var( ‘author’ ); // get_usernumposts() is deprecated since 3.0 $post_count = count_user_posts( $id ); if ( … Read more

Force users to complete their profile after they register? How to

You should hook into the user_register action. I did something similar on a recent site (not involving having to fill out profile fields, but involving having to renew a membership). I will propose a multi-part solution (let me know if any of it is confusing, it’s been a long day and I might not explain … Read more

How to redirect a specific user after log-in?

You need to use the login_redirect filter returning the redirect location: add_filter( ‘login_redirect’, ‘redirect_to_home’, 10, 3 ); function redirect_to_home( $redirect_to, $request, $user ) { if( $user->ID == 6 ) { //If user ID is 6, redirect to home return get_home_url(); } else { //If user ID is not 6, leave WordPress handle the redirection as … Read more

Using a Theme inside a Plugin directory

Hi @Hamza: I think what you are looking to do is for your plugin to hook ‘template_include’ to tell it to load a file from your plugin directory. Here’s starter code for your plugin: <?php /* Plugin Name: Mobile View Plugin */ if (is_mobile_user()) // YOU NEED TO DEFINE THIS FUNCTION class MobileViewPlugin { static … Read more

Redirect after deleting post and keep track of pagination

You can use $_SERVER[‘HTTP_REFERER’] to get the URL the user came from. The following code will find the paged GET variable of the previous URL to determine which page the user was on, then count how many posts are left of that particiular post type (only published) and how many pages are needed to display … Read more