I set wp_set_auth_cookie but wp_validate_auth_cookie returns false

If you want the login works without having to reload the page (or redirect to somewhere on the site), then you would want to immediately set both the auth and logged-in cookies, i.e. set them in the superglobal $_COOKIE array. And you can do that via the set_auth_cookie and set_logged_in_cookie hooks: add_action( ‘set_auth_cookie’, function ( … Read more

Create a fullwidth dashboard widget

Here’s perhaps a little hacky way to achieve a full width dashboard widget. Here we force the first (left-most) column to be 100% and to contain our custom widget. Step 1 WP stores the Dashboard widget visibility and order as user specific option. To get the below code working we need to prevent the user’s … Read more

https://mydomain/wp-admin redirects to wp-login.php?redirect_to=https%3A%2F%2Fmydomain%2Fwp-admin%2F&reauth=1

It’s possible to redirect to any page of your site by using the ‘init’ hook. Here’s an example code to show how it can be done. add_action(‘init’, ‘wpse388876_redirect_to_home_page’); function wpse388876_redirect_to_home_page() { global $pagenow; if (‘wp-login.php’ == $pagenow && (!is_user_logged_in() || !is_super_admin() || !is_admin())) { $redirect_to = home_url(); wp_safe_redirect($redirect_to); exit; } } All non-logged in users … Read more

Where are the admin notifications stored?

Where are the admin notifications stored? They aren’t. Admin notices have no storage unless you implement it yourself for your plugin/theme. WordPress provides hooks and styling for displaying admin notices, but that’s it. It might provide styling for dismissible admin notices but it provides no storage or registration mechanisms for persistence. And when a user … Read more

why my menu is not appearing on the admin panel

You are using add_options_page() so this means that you are adding a page menu item under settings section of your WP admin menu. By the sounds of it you dont want to add your page there but you really want it to appear as a sub page of the pages menu. Am I correct in … Read more

Why am I unable to login after converting to www?

You don’t need a rewrite rule in .htaccess to add www back in. Remove the rewrite rule, remove all the defines in wp-config and try to login. If that doesn’t work, delete permalinks in .htaccess to force them back to default. After you’re in, add the www in Dashboard>>Settings and save. Then reset permalinks.

Execute script only on certain admin pages

You can use this in your functions.php : function add_admin_scripts( $hook ) { if ( $hook == ‘post-new.php’ ) { wp_enqueue_script( ‘myscript’, get_bloginfo(‘template_directory’).’/js/myscript.js’ ); } } add_action(‘admin_enqueue_scripts’,’add_admin_scripts’,10,1);