heartbeat_command = true; foreach ($data as $uid => $command) { if (!$this->is_wpo_heartbeat($uid)) { continue; } if (is_string($command)) { if (apply_filters('wp_optimize_is_heartbeat_valid_ajax_command', $command)) { $response['callbacks'][$uid] = apply_filters('wp_optimize_heartbeat_ajax', $command); } } else { $command_name = key($command); if ('updraft_smush_ajax' == $command_name) { $command_data = current($command); $command_data_param = null; if (isset($command_data['data'])) { $command_data_param = $command_data['data']; } $_REQUEST['subaction'] = $command_data['subaction']; $_REQUEST['data'] = $command_data_param; ob_start(); if (!is_callable(array($commands, $command_data['subaction']))) { continue; } $method = new ReflectionMethod($commands, $command_data['subaction']); $command_response = $method->invokeArgs($commands, array($command_data_param)); if (is_array($command_response)) { $response['callbacks'][$uid] = $command_response; ob_end_clean(); } else { $response['callbacks'][$uid] = ob_get_clean(); } if (is_wp_error($command_response)) { $response['callbacks'][$uid] = array( 'status' => true, 'result' => false, 'error_code' => $command_response->get_error_code(), 'error_message' => $command_response->get_error_message(), 'error_data' => $command_response->get_error_data(), 'skip_notice' => !empty($command_data_param['skip_notice']), ); } } } } if (true === $commands->background_command) { $response['server_time'] = time(); $response['wp-auth-check'] = true; $commands->final_response = $response; die(); } else { return $response; } } /** * Check if the received heartbeat action was triggered by WPO's heartbeat.js layer * * @param string $uid The task unique id * @return bool */ private function is_wpo_heartbeat($uid) { return 0 === strpos($uid, 'wpo-heartbeat-'); } } endif;