Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Is there some guideline or rationale behind why some WP code functions are prefixed with wp_ ? eg: wp_insert_post() vs. update_post_meta()

share|improve this question
2  
+1 great thing to point out ;) –  Sisir Aug 23 '11 at 19:37
add comment

4 Answers

up vote 7 down vote accepted

This makes not that impressive answer, but - none.

get_ is suffix usually means function returns something, the_ that function echoes something.

wp_ doesn't carry technical meaning and inconsistency in naming is from many developers participating and lack of movement to unify (moving forward is considered more important than major cleanups of older stuff to make it neat).

share|improve this answer
1  
I (somewhat) understand the reasoning for not remedying the current situation; however, I am puzzled by the lack of defining some point in time from which, henceforth, a defined function nomenclature would be enforced. Wishful thinking, I suppose. –  Chip Bennett Aug 24 '11 at 13:03
    
Thanks Rarst. Otto confirmed it. Sigh. I was hoping... I'm with Chip! –  Tom Auger Aug 24 '11 at 19:02
add comment

Wordpress was and is written by a lot of different people. Patches are discussed inside wordpress trac and whoever submits or assigns to a trac ticket can post patches. If the patch gets accepted and moved into core of an upcoming version it's simply in there. So sometimes functions, vars, etc. gets the prefix while other times they don't. It relies on the participating developers.

share|improve this answer
add comment

The wp_ prefix is usually added to avoid naming conflicts with:

  • native PHP functions, such as get_current_user()
  • older/deprecated WP functions, such as get_archives()
  • third-party libraries?
share|improve this answer
add comment

I always assumed the distinction was that - beyond the basic template tags, which generally just have the simplest descriptive name possible:

  1. functions that begin with wp_ are generally high-level public API functions, which are pretty much guaranteed to always be around and retain forwards-compatability.
  2. functions without that prefix are internals, stuff you shouldn't muck around with unless you know what you're doing.

I don't know if this was ever intentional, though. And like the other two answers have said, it doesn't hold up consistently. Your example of update_post_meta is a perfect example of something that seems like it should should have a wp_ prefix if my classification held true. But there's enough deep legacy code in WordPress to throw off any attempt at making sense of any naming convention.

share|improve this answer
    
haha. I actually thought it was exactly the opposite - that wp_ functions were more of the internal (you-can-use-it-but-it's-really-internal) variety while the others were more public. Sad as it sounds though, maybe Rarst et al. are right and there is no rationale. –  Tom Auger Aug 24 '11 at 12:29
2  
For the record the really internal functions start with underscore alone _* But there aren't that many of those and in practice they aren't that absolutely internal-only either. –  Rarst Aug 24 '11 at 13:39
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.