WordPress.org

Make WordPress Core

Opened 8 years ago

Closed 7 years ago

Last modified 7 years ago

#11624 closed enhancement (fixed)

Stop using $id global

Reported by: scribu Owned by:
Milestone: 3.1 Priority: normal
Severity: normal Version:
Component: General Keywords: has-patch commit
Focuses: Cc:

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 8 years ago.
Remove $id global from the_ID(), get_the_ID() and get_the_content()
11624.2.diff (7.3 KB) - added by scribu 7 years ago.
Replace all instances

Download all attachments as: .zip

Change History (18)

@scribu
8 years ago

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

#1 @scribu
8 years ago

  • Cc scribu@… added

#2 @Denis-de-Bernardy
8 years ago

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

#3 follow-up: @scribu
8 years ago

Such as?

#4 @scribu
8 years ago

Themes and plugins should be using get_the_ID() anyway.

#5 in reply to: ↑ 3 @Denis-de-Bernardy
8 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.

#6 @prettyboymp
8 years ago

  • 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.

#7 @nacin
8 years ago

  • Keywords commit added

This looks good.

#8 @nacin
7 years ago

  • 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.

#9 follow-up: @xibe
7 years ago

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

#10 in reply to: ↑ 9 ; follow-up: @nacin
7 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. :)

#11 in reply to: ↑ 10 @xibe
7 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.

#12 @nacin
7 years ago

  • Milestone changed from 3.0 to Future Release

Moving out of 3.0 for now.

#13 @prettyboymp
7 years ago

  • Cc mpretty@… added

related #10471

@scribu
7 years ago

Replace all instances

#14 @scribu
7 years ago

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

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

#15 @scribu
7 years ago

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

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

#16 @nacin
7 years ago

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

Note: See TracTickets for help on using tickets.