| @@ -64,9 +64,9 @@ | ||
| 64 | 64 | * @return array|void |
| 65 | 65 | */ |
| 66 | 66 | public function receive_heartbeat($response, $data) { |
| 67 | 67 | $allowed_smush_commands = Updraft_Smush_Manager_Commands::get_allowed_ajax_commands(); |
| 68 | - $capability_required = current_user_can(WP_Optimize()->capability_required()); | |
| 68 | + $user_can = WP_Optimize()->current_user_can(); | |
| 69 | 69 | $commands = new Updraft_Smush_Manager_Commands(Updraft_Smush_Manager::instance()); |
| 70 | 70 | $commands->heartbeat_command = true; |
| 71 | 71 | |
| 72 | 72 | foreach ($data as $uid => $command) { |
| @@ -81,9 +81,9 @@ | ||
| 81 | 81 | } else { |
| 82 | 82 | $command_name = key($command); |
| 83 | 83 | if ('updraft_smush_ajax' === $command_name) { |
| 84 | 84 | |
| 85 | - if (!$capability_required) { | |
| 85 | + if (!$user_can) { | |
| 86 | 86 | continue; |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | $command_data = current($command); |
| @@ -111,9 +111,13 @@ | ||
| 111 | 111 | ob_start(); |
| 112 | 112 | |
| 113 | 113 | $method = new ReflectionMethod($commands, $command_data['subaction']); |
| 114 | 114 | |
| 115 | - $command_response = $method->invokeArgs($commands, array($command_data_param)); | |
| 115 | + try { | |
| 116 | + $command_response = $method->invokeArgs($commands, array($command_data_param)); | |
| 117 | + } catch (Exception $e) { | |
| 118 | + $command_response = new WP_Error($e->getCode() ? $e->getCode() : 1, $e->getMessage()); | |
| 119 | + } | |
| 116 | 120 | |
| 117 | 121 | if (is_array($command_response)) { |
| 118 | 122 | $response['callbacks'][$uid] = $command_response; |
| 119 | 123 | ob_end_clean(); |