Is there some guideline or rationale behind why some WP code functions are prefixed with wp_
? eg: wp_insert_post()
vs. update_post_meta()
Leave a Reply
You must be logged in to post a comment.
Is there some guideline or rationale behind why some WP code functions are prefixed with wp_
? eg: wp_insert_post()
vs. update_post_meta()
You must be logged in to post a comment.
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).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.
The
wp_
prefix is usually added to avoid naming conflicts with:I always assumed the distinction was that – beyond the basic template tags, which generally just have the simplest descriptive name possible:
wp_
are generally high-level public API functions, which are pretty much guaranteed to always be around and retain forwards-compatability.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 awp_
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.