: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
require_once(dirname(__FILE__) . '/wfRESTBaseController.php');
class wfRESTScanController extends wfRESTBaseController {
* @todo Setup routes to modify scan results.
public function registerRoutes() {
register_rest_route('wordfence/v1', '/scan/issues', array(
'methods' => WP_REST_Server::READABLE,
'callback' => array($this, 'getIssuesList'),
'permission_callback' => array($this, 'verifyToken'),
'description' => __('Scan result group or all results.', 'wordfence'),
'description' => __('Offset of scan results to return.', 'wordfence'),
'description' => __('Number of scan results to return.', 'wordfence'),
register_rest_route('wordfence/v1', '/scan', array(
'methods' => WP_REST_Server::CREATABLE,
'callback' => array($this, 'startScan'),
'permission_callback' => array($this, 'verifyToken'),
register_rest_route('wordfence/v1', '/scan', array(
'methods' => WP_REST_Server::DELETABLE,
'callback' => array($this, 'stopScan'),
'permission_callback' => array($this, 'verifyToken'),
register_rest_route('wordfence/v1', '/scan/issue', array(
'methods' => WP_REST_Server::EDITABLE,
'callback' => array($this, 'updateIssue'),
'permission_callback' => array($this, 'verifyToken'),
* @param WP_REST_Request $request
* @return mixed|WP_REST_Response
public function getIssuesList($request) {
$group = $request['group'] ? $request['group'] : 'all';
$offset = absint($request['offset']);
$limit = absint($request['limit']);
$count = wfIssues::shared()->getPendingIssueCount();
$issues = wfIssues::shared()->getPendingIssues($offset, $limit);
default: // Return all issues.
$count = wfIssues::shared()->getIssueCount();
$issues = wfIssues::shared()->getIssues($offset, $limit);
$response = rest_ensure_response(array(
'last-scan-time' => wfConfig::get('scanTime'),
* @param WP_REST_Request $request
* @return mixed|WP_REST_Response
public function startScan($request) {
wordfence::status(1, 'info', sprintf(/* translators: Localized date. */ __('Wordfence scan starting at %s from Wordfence Central', 'wordfence'),
date('l jS \of F Y h:i:s A', current_time('timestamp'))));
wfScanEngine::startScan();
} catch (wfScanEngineTestCallbackFailedException $e) {
wfConfig::set('lastScanCompleted', $e->getMessage());
wfConfig::set('lastScanFailureType', wfIssues::SCAN_FAILED_CALLBACK_TEST_FAILED);
wfUtils::clearScanLock();
$response = rest_ensure_response(array(
'error-code' => $e->getCode(),
'error' => $e->getMessage(),
if ($e->getCode() != wfScanEngine::SCAN_MANUALLY_KILLED) {
wfConfig::set('lastScanCompleted', $e->getMessage());
wfConfig::set('lastScanFailureType', wfIssues::SCAN_FAILED_GENERAL);
$response = rest_ensure_response(array(
'error-code' => $e->getCode(),
'error' => $e->getMessage(),
$response = rest_ensure_response(array(
* @param WP_REST_Request $request
* @return mixed|WP_REST_Response
public function stopScan($request) {
wordfence::status(1, 'info', __('Scan stop request received from Wordfence Central.', 'wordfence'));
wordfence::status(10, 'info', __('SUM_KILLED:A request was received to stop the previous scan from Wordfence Central.', 'wordfence'));
wfUtils::clearScanLock(); //Clear the lock now because there may not be a scan running to pick up the kill request and clear the lock
wfScanEngine::requestKill();
wfConfig::remove('scanStartAttempt');
wfConfig::set('lastScanFailureType', false);
$response = rest_ensure_response(array(
* @param WP_REST_Request $request
* @return mixed|WP_REST_Response
public function updateIssue($request) {
$issue = $request['issue'];
$id = is_array($issue) && array_key_exists('id', $issue) ? $issue['id'] : null;
$status = is_array($issue) && array_key_exists('status', $issue) ? $issue['status'] : null;
$wfdb->queryWrite("update " . wfDB::networkTable('wfIssues') . " set status='%s' where id=%d", $status, $id);
$response = rest_ensure_response(array(
$response = rest_ensure_response(array(
'error' => 'Issue not found.',