aggregator icon indicating copy to clipboard operation
aggregator copied to clipboard

$aggregator not in global scope causing fatal error in class-aggregate.php

Open mikeselander opened this issue 8 years ago • 0 comments

Whenever the save_post action is triggered we end up with a fatal 500 error, caught by Query Monitor that results from attempting to pull a non-global variable as global. This is 500ing on our local installs and causing posts not to update if an aggregator job is triggering.

The issue comes from using $aggregator as a global in class-aggregate.php line 40. The variable is not available within global scope which leads to class variable resolving as null when called.

I'd recommend either calling the Aggregator class anew when loading the Aggregate class or using a static instance of the class and not relying on globals because globals kinda suck.

Error and Trace:

Xdebug: Fatal error: Uncaught Error: Call to a member function get_portals() on null in /srv/www/thesun/wp-content/plugins/aggregator/class-aggregate.php:992 
Stack trace: 
#0 /srv/www/thesun/wp-includes/plugin.php(524): Aggregate->save_post(1373719, Object(WP_Post)) 
#1 /srv/www/thesun/wp-includes/post.php(3409): do_action('save_post', 1373719, Object(WP_Post), true) 
#2 /srv/www/thesun/wp-includes/post.php(3482): wp_insert_post(Array, false) 
#3 /srv/www/thesun/wp-admin/includes/post.php(376): wp_update_post(Array) 
#4 /srv/www/thesun/wp-admin/post.php(193): edit_post() 
#5 {main} thrown in /srv/www/thesun/wp-content/plugins/aggregator/class-aggregate.php on line 992. 
Output triggered in /srv/www/thesun/wp-content/mu-plugins/query-monitor/collectors/php_errors.php on line 143

mikeselander avatar Oct 12 '16 16:10 mikeselander