Problem with wp_redirect()
-
Using latest nightly. Sometime in the past few weeks code that has worked, and works in 4.3.1 now throws a fatal.
//wp_redirect('https://test.dev/wp-admin/network/settings.php?page=github-updater&updated=true'); wp_redirect( add_query_arg( array( 'page' => 'github-updater', 'updated' => 'true', 'tab' => $_GET['tab'], ), network_admin_url( 'settings.php' ) ) ); exit;
Interestingly, the commented code works and the
add_query_arg
generates the same $location but fatals.The error is ‘Trying to property of non-object’ and ‘headers already sent’.
Any ideas?
-
I wonder if it’s from changes to network_admin_url. Do other URLs work?
Is network_admin_url spitting out the right information?
Hey Mika!
network_admin_url is producing the correct URL. It produced the URL that is commented and works above.
It seems to be more of an issue of wp_redirect not liking a variable vs a string. Very strange. I’ll have to see if I can trace it back further when I have more time.
Andy, I’m unable to reproduce this problem with a fresh install of WordPress trunk running Multisite.
* Can you confirm that
network_admin_url()
is the cause of the error? If you swapnetwork_admin_url( 'settings.php' )
forhttps://test.dev/wp-admin/network/settings.php
, does the problem persist?
* Can you paste the exact error messages (including file name, line number, etc) you’re seeing please?
* Which version of PHP are you using?
* Does the problem persist on a fresh install with no other plugins active? (For example, just by placing this code into its own plugin).Thanks in advance.
Hey John,
I believe the issue is with wp_redirect not network_admin_url.
Swapping in
network_admin_url( 'settings.php' )
gives the same error.Here’s the exact error.
Backtrace from warning 'Trying to get property of non-object' at /Users/afragen/Documents/Websites/wp-content/plugins/query-monitor/output/headers/php_errors.php 45: /Users/afragen/Documents/Websites/wp-content/plugins/query-monitor/output/Headers.php 23 calling get_output() /Users/afragen/Documents/Websites/wp-content/plugins/query-monitor/dispatchers/Redirect.php 43 calling output() calling filter_wp_redirect() /Users/afragen/Documents/Websites/test.dev/wp-includes/plugin.php 235 calling call_user_func_array() /Users/afragen/Documents/Websites/test.dev/wp-includes/pluggable.php 1208 calling apply_filters() /Users/afragen/Documents/github/github-updater/src/GitHub_Updater/Settings.php 659 calling wp_redirect() calling update_network_setting() /Users/afragen/Documents/Websites/test.dev/wp-includes/plugin.php 525 calling call_user_func_array() /Users/afragen/Documents/Websites/test.dev/wp-admin/network/edit.php 39 calling do_action() Backtrace from warning 'Cannot modify header information - headers already sent' at /Users/afragen/Documents/Websites/wp-content/plugins/query-monitor/output/Headers.php 25: /Users/afragen/Documents/Websites/wp-content/plugins/query-monitor/output/Headers.php 25 calling header() /Users/afragen/Documents/Websites/wp-content/plugins/query-monitor/dispatchers/Redirect.php 43 calling output() calling filter_wp_redirect() /Users/afragen/Documents/Websites/test.dev/wp-includes/plugin.php 235 calling call_user_func_array() /Users/afragen/Documents/Websites/test.dev/wp-includes/pluggable.php 1208 calling apply_filters() /Users/afragen/Documents/github/github-updater/src/GitHub_Updater/Settings.php 659 calling wp_redirect() calling update_network_setting() /Users/afragen/Documents/Websites/test.dev/wp-includes/plugin.php 525 calling call_user_func_array() /Users/afragen/Documents/Websites/test.dev/wp-admin/network/edit.php 39 calling do_action() Backtrace from warning 'Cannot modify header information - headers already sent' at /Users/afragen/Documents/Websites/wp-content/plugins/query-monitor/output/Headers.php 25: /Users/afragen/Documents/Websites/wp-content/plugins/query-monitor/output/Headers.php 25 calling header() /Users/afragen/Documents/Websites/wp-content/plugins/query-monitor/dispatchers/Redirect.php 43 calling output() calling filter_wp_redirect() /Users/afragen/Documents/Websites/test.dev/wp-includes/plugin.php 235 calling call_user_func_array() /Users/afragen/Documents/Websites/test.dev/wp-includes/pluggable.php 1208 calling apply_filters() /Users/afragen/Documents/github/github-updater/src/GitHub_Updater/Settings.php 659 calling wp_redirect() calling update_network_setting() /Users/afragen/Documents/Websites/test.dev/wp-includes/plugin.php 525 calling call_user_func_array() /Users/afragen/Documents/Websites/test.dev/wp-admin/network/edit.php 39 calling do_action() Backtrace from warning 'Cannot modify header information - headers already sent' at /Users/afragen/Documents/Websites/wp-content/plugins/query-monitor/output/Headers.php 25: /Users/afragen/Documents/Websites/wp-content/plugins/query-monitor/output/Headers.php 25 calling header() /Users/afragen/Documents/Websites/wp-content/plugins/query-monitor/dispatchers/Redirect.php 43 calling output() calling filter_wp_redirect() /Users/afragen/Documents/Websites/test.dev/wp-includes/plugin.php 235 calling call_user_func_array() /Users/afragen/Documents/Websites/test.dev/wp-includes/pluggable.php 1208 calling apply_filters() /Users/afragen/Documents/github/github-updater/src/GitHub_Updater/Settings.php 659 calling wp_redirect() calling update_network_setting() /Users/afragen/Documents/Websites/test.dev/wp-includes/plugin.php 525 calling call_user_func_array() /Users/afragen/Documents/Websites/test.dev/wp-admin/network/edit.php 39 calling do_action() Backtrace from warning 'Cannot modify header information - headers already sent' at /Users/afragen/Documents/Websites/test.dev/wp-includes/pluggable.php 1228: /Users/afragen/Documents/Websites/test.dev/wp-includes/pluggable.php 1228 calling header() /Users/afragen/Documents/github/github-updater/src/GitHub_Updater/Settings.php 659 calling wp_redirect() calling update_network_setting() /Users/afragen/Documents/Websites/test.dev/wp-includes/plugin.php 525 calling call_user_func_array() /Users/afragen/Documents/Websites/test.dev/wp-admin/network/edit.php 39 calling do_action()
On localhost PHP 5.5.24, on server PHP 5.6.10
I’m calling the code from the following hook, just in case that helps.
add_action( 'network_admin_edit_github-updater', array( $this, 'update_network_setting' ) );
I’ll have some time tomorrow to spin up a clean install and test in it’s own plugin.
Thank you!
This looks like it’s being caused by Query Monitor (which, coincidentally, is my plugin). Can you try disabling QM and see if the error disappears?
Query Monitor disabled and now a different error to track down.
The error is mine and I’m fixing but odd how it never showed itself until recently.
If I have anything more I’ll post back. I’ll close if nothing further. Deactivating Query Monitor was very helpful, only in this case. ??
Query Monitor just hid my error. The real error was
$_GET['tab']
not being defined.I fixed by getting the value from elsewhere.
Thanks John, thanks Mika!
- The topic ‘Problem with wp_redirect()’ is closed to new replies.