WordPress / WordPress/WordPress-Coding-Standards

$wpdb->(insert|update|delete|replace)() return value shouldn't be used in boolean comparisons

Open
#674 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Focus: Code analysis Type: Enhancement
Dominant language
PHP
Stars
2.8k
Forks
521
Avg merge
5d 20h
Merged PRs (30d)
1

Description

The return value will be an integer, and -1 can indicate an error as well as 0. So comparing to a boolean value will mean that errors won't be detected in all cases, since -1 == true.

An integer greater than zero indicates the number of rows affected or retrieved. Zero indicates that no records were updated for an UPDATE statement, no rows matched the WHERE clause in the query or that no query has yet been executed. -1 indicates that the query returned an error. 1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No file or test is identified in the issue. Start by locating the rules that inspect $wpdb->insert(), update(), delete(), and replace() calls, then determine how boolean comparisons are detected. Done means comparisons that can hide a -1 error are reported, with tests covering affected-row values and error handling.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.