Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#11624 closed enhancement (fixed)

Stop using $id global

Reported by: scribu Owned by:
Priority: normal Milestone: 3.1
Component: General Version:
Severity: normal Keywords: has-patch commit
Cc: scribu@…, mpretty@…

Description

We already have the $post global which has the ID field.

So the $id global can be replaced with $post->ID everywhere.

Attachments (2)

11624.diff (1.4 KB) - added by scribu 3 years ago.
Remove $id global from the_ID(), get_the_ID() and get_the_content()
11624.2.diff (7.3 KB) - added by scribu 3 years ago.
Replace all instances

Download all attachments as: .zip

Change History (18)

scribu3 years ago

Remove $id global from the_ID(), get_the_ID() and get_the_content()

  • Cc scribu@… added

that's a big change which might potentially break a lot of themes and plugins.

comment:3 follow-up: ↓ 5   scribu3 years ago

Such as?

Themes and plugins should be using get_the_ID() anyway.

comment:5 in reply to: ↑ 3   Denis-de-Bernardy3 years ago

Replying to scribu:

Such as?

Subscribe to comments comes to mind. Or at least it did in prior versions. I'm sure we'd find a few by looking.

  • Keywords tested added

This shouldn't affect plugins that still use global $id since it will be still be set in setup_post_content(). Core functions will just stop using it. Its at least a small step in getting rid of all the globals.

  • Keywords commit added

This looks good.

  • Keywords tested commit removed

I would commit this, but we use $id in a lot more places than post.php. It's not a bad idea to reduce our dependence on globals even by one, but we might as well do it across the board if we are to do it.

comment:9 follow-up: ↓ 10   xibe3 years ago

Should we create a ticket with the grand project of getting rid of all globals for 3.1?

comment:10 in reply to: ↑ 9 ; follow-up: ↓ 11   nacin3 years ago

Replying to xibe:

Should we create a ticket with the grand project of getting rid of all globals for 3.1?

Heh, yea, that's not going to happen so easily. :)

comment:11 in reply to: ↑ 10   xibe3 years ago

Replying to nacin:

Heh, yea, that's not going to happen so easily. :)

I guess so :)
But that would most certainly appease a lot of developers who like to snark at the "code is poetry" motto.

  • Milestone changed from 3.0 to Future Release

Moving out of 3.0 for now.

  • Cc mpretty@… added

related #10471

scribu3 years ago

Replace all instances

  • Keywords commit added
  • Milestone changed from Future Release to 3.1

Updated patch removes all instances of $id that I could find.

  • Resolution set to fixed
  • Status changed from new to closed

(In [15549]) Don't use the global anymore. Fixes #11624

(In [15563]) Adjustments to [15549]. See #11624.

Note: See TracTickets for help on using tickets.