mwaterous / wp-bitly

This plugin can be used to generate short links for your WordPress posts, pages, or any available custom post type that you would like it to interact with.
https://wordpress.org/plugins/wp-bitly/
GNU General Public License v2.0
3 stars 4 forks source link

Many debug.log php notices #2

Closed jtsternberg closed 6 years ago

jtsternberg commented 6 years ago

With recent release, there are notices in the debug.log on almost every admin page.

[08-Mar-2018 18:42:54 UTC] PHP Notice:  Trying to get property of non-object in /app/public/wp-content/plugins/wp-bitly/includes/functions.php on line 159
[08-Mar-2018 18:42:54 UTC] PHP Stack trace:
[08-Mar-2018 18:42:54 UTC] PHP   1. {main}() /app/public/wp-admin/admin.php:0
[08-Mar-2018 18:42:54 UTC] PHP   2. require_once() /app/public/wp-admin/admin.php:216
[08-Mar-2018 18:42:54 UTC] PHP   3. do_action() /app/public/wp-admin/admin-header.php:219
[08-Mar-2018 18:42:54 UTC] PHP   4. WP_Hook->do_action() /app/public/wp-includes/plugin.php:453
[08-Mar-2018 18:42:54 UTC] PHP   5. WP_Hook->apply_filters() /app/public/wp-includes/class-wp-hook.php:310
[08-Mar-2018 18:42:54 UTC] PHP   6. wp_admin_bar_render() /app/public/wp-includes/class-wp-hook.php:286
[08-Mar-2018 18:42:54 UTC] PHP   7. do_action_ref_array() /app/public/wp-includes/admin-bar.php:83
[08-Mar-2018 18:42:54 UTC] PHP   8. WP_Hook->do_action() /app/public/wp-includes/plugin.php:515
[08-Mar-2018 18:42:54 UTC] PHP   9. WP_Hook->apply_filters() /app/public/wp-includes/class-wp-hook.php:310
[08-Mar-2018 18:42:54 UTC] PHP  10. wp_admin_bar_shortlink_menu() /app/public/wp-includes/class-wp-hook.php:286
[08-Mar-2018 18:42:54 UTC] PHP  11. wp_get_shortlink() /app/public/wp-includes/admin-bar.php:583
[08-Mar-2018 18:42:54 UTC] PHP  12. apply_filters() /app/public/wp-includes/link-template.php:3610
[08-Mar-2018 18:42:54 UTC] PHP  13. WP_Hook->apply_filters() /app/public/wp-includes/plugin.php:203
[08-Mar-2018 18:42:54 UTC] PHP  14. wpbitly_get_shortlink() /app/public/wp-includes/class-wp-hook.php:288

and

[08-Mar-2018 18:43:25 UTC] PHP Notice:  Undefined variable: wp in /app/public/wp-content/plugins/wp-bitly/includes/class.wp-bitly-admin.php on line 271
[08-Mar-2018 18:43:25 UTC] PHP Stack trace:
[08-Mar-2018 18:43:25 UTC] PHP   1. {main}() /app/public/wp-admin/options-writing.php:0
[08-Mar-2018 18:43:25 UTC] PHP   2. do_settings_sections() /app/public/wp-admin/options-writing.php:195
[08-Mar-2018 18:43:25 UTC] PHP   3. do_settings_fields() /app/public/wp-admin/includes/template.php:1337
[08-Mar-2018 18:43:25 UTC] PHP   4. _f_settings_field_authorize() /app/public/wp-admin/includes/template.php:1378

and

[08-Mar-2018 18:43:26 UTC] PHP Notice:  Undefined offset: 1 in /app/public/wp-includes/functions.php on line 823
[08-Mar-2018 18:43:26 UTC] PHP Stack trace:
[08-Mar-2018 18:43:26 UTC] PHP   1. {main}() /app/public/wp-admin/options-writing.php:0
[08-Mar-2018 18:43:26 UTC] PHP   2. do_settings_sections() /app/public/wp-admin/options-writing.php:195
[08-Mar-2018 18:43:26 UTC] PHP   3. do_settings_fields() /app/public/wp-admin/includes/template.php:1337
[08-Mar-2018 18:43:26 UTC] PHP   4. _f_settings_field_authorize() /app/public/wp-admin/includes/template.php:1378
[08-Mar-2018 18:43:26 UTC] PHP   5. add_query_arg() /app/public/wp-content/plugins/wp-bitly/includes/class.wp-bitly-admin.php:271
jtsternberg commented 6 years ago

First one assumes there will always be a post object, which is not the case throughout many parts of the admin. Problem is here: https://github.com/temeritystudios/wp-bitly/blob/master/includes/functions.php#L158-L159

Notice WP's default handling to check if post object exists: https://github.com/WordPress/WordPress/blob/395667f91665f2c12d3a681136b04158ecca07de/wp-includes/link-template.php#L3782-L3785

jtsternberg commented 6 years ago

Second notice is because this file is using the $wp global in several places, but not actually defining the global (e.g. global $wp) before using.

jtsternberg commented 6 years ago

Third notice is because this file is using add_query_arg() and that function expects at least 2 parameters. Not sure why it's being used at all in these instances, but if it is to get the current request, this will work: $current_page = isset( $_SERVER['REQUEST_URI'] ) ? $_SERVER['REQUEST_URI'] : ''; (notice, i'm using isset() because in the case of wp-cli, this may be empty and will throw php notices as well)

jtsternberg commented 6 years ago

Found some more:

[09-Mar-2018 03:48:53 UTC] PHP Stack trace:
[09-Mar-2018 03:48:53 UTC] PHP   1. {main}() /app/public/wp-admin/post.php:0
[09-Mar-2018 03:48:53 UTC] PHP   2. include() /app/public/wp-admin/post.php:174
[09-Mar-2018 03:48:53 UTC] PHP   3. do_meta_boxes() /app/public/wp-admin/edit-form-advanced.php:707
[09-Mar-2018 03:48:53 UTC] PHP   4. WPBitly_Admin->displayMetabox() /app/public/wp-admin/includes/template.php:1063
[09-Mar-2018 03:48:53 UTC] PHP Warning:  array_reverse() expects parameter 1 to be array, null given in /app/public/wp-content/plugins/wp-bitly/includes/class.wp-bitly-admin.php on line 445
[09-Mar-2018 03:48:53 UTC] PHP Stack trace:
[09-Mar-2018 03:48:53 UTC] PHP   1. {main}() /app/public/wp-admin/post.php:0
[09-Mar-2018 03:48:53 UTC] PHP   2. include() /app/public/wp-admin/post.php:174
[09-Mar-2018 03:48:53 UTC] PHP   3. do_meta_boxes() /app/public/wp-admin/edit-form-advanced.php:707
[09-Mar-2018 03:48:53 UTC] PHP   4. WPBitly_Admin->displayMetabox() /app/public/wp-admin/includes/template.php:1063
[09-Mar-2018 03:48:53 UTC] PHP   5. array_reverse() /app/public/wp-content/plugins/wp-bitly/includes/class.wp-bitly-admin.php:445
[09-Mar-2018 03:48:53 UTC] PHP Warning:  Invalid argument supplied for foreach() in /app/public/wp-content/plugins/wp-bitly/includes/class.wp-bitly-admin.php on line 445
[09-Mar-2018 03:48:53 UTC] PHP Stack trace:
[09-Mar-2018 03:48:53 UTC] PHP   1. {main}() /app/public/wp-admin/post.php:0
[09-Mar-2018 03:48:53 UTC] PHP   2. include() /app/public/wp-admin/post.php:174
[09-Mar-2018 03:48:53 UTC] PHP   3. do_meta_boxes() /app/public/wp-admin/edit-form-advanced.php:707
[09-Mar-2018 03:48:53 UTC] PHP   4. WPBitly_Admin->displayMetabox() /app/public/wp-admin/includes/template.php:1063
[09-Mar-2018 03:48:53 UTC] PHP Warning:  max(): Array must contain at least one element in /app/public/wp-content/plugins/wp-bitly/includes/class.wp-bitly-admin.php on line 450
[09-Mar-2018 03:48:53 UTC] PHP Stack trace:
[09-Mar-2018 03:48:53 UTC] PHP   1. {main}() /app/public/wp-admin/post.php:0
[09-Mar-2018 03:48:53 UTC] PHP   2. include() /app/public/wp-admin/post.php:174
[09-Mar-2018 03:48:53 UTC] PHP   3. do_meta_boxes() /app/public/wp-admin/edit-form-advanced.php:707
[09-Mar-2018 03:48:53 UTC] PHP   4. WPBitly_Admin->displayMetabox() /app/public/wp-admin/includes/template.php:1063
[09-Mar-2018 03:48:53 UTC] PHP   5. max() /app/public/wp-content/plugins/wp-bitly/includes/class.wp-bitly-admin.php:450

You can duplicate if you run this plugin locally and disable your internet connection. Basically, there needs to be handling for if/when wpbitly_get() returns an empty response.

mwaterous commented 6 years ago

Look at all the things I could've avoided had I been testing this with WP_DEBUG on during the last updates. No excuses, that's just an easy mistake to avoid.

Thanks for bringing this to my attention, hopefully I can get on top of these in the coming days.