WordPress / WordPress/WordPress-Coding-Standards

Should setup_postdata trigger an error for overriding WP global?

Open
#842 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
2.8k
Forks
521
Avg merge
5d 20h
Merged PRs (30d)
1

Description

While preparing to merge the WP Globals check for the WordPress-Theme ruleset I found a place when setup_postdata() is used an error is triggered.

Should the following code trigger an error?

global $post;
$post = get_post( '10' );
setup_postdata( $post );
wp_reset_postdata();

This is also used in Twenty Seventeen https://github.com/WordPress/WordPress/blob/master/wp-content/themes/twentyseventeen/inc/template-tags.php#L142

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

Start with the WP Globals check for the WordPress-Theme ruleset and trace how setup_postdata() is handled in the reported example. Compare that behavior with the Twenty Seventeen template-tags.php usage; done means the expected error behavior is decided and the ruleset reflects that decision.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
tooling
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.