I have noticed that many people around the site, when writing PHP functions as part of an answer, prefix it with something like wpse_101042. I assume that this is to prevent duplicate function name errors.

Is this a widely accepted standard on WP SE, or simply a commonly used practice?

In an answer, is the number the question ID or the actual post (answer) ID?

share
    
I tend to use wpa_XXXX...where wpa stands for WordPress Answers –  Joseph Jan 7 '13 at 4:17

2 Answers 2

up vote 13 down vote accepted

This is usually just a personal preference. As Bainternet states, it is always a good practice to prefix function names in WordPress. And while it's not required on this site, consider the sheer number of people who just copy and paste code into their projects.

Using a wpse_XXX prefix does a couple of things:

  1. It prevents sites that contain copy-pasted code from breaking with duplicate function names
  2. It helps identify which copy-pasted code came from this site.

Number 2 is merely a fun, unintended result of the practice. But the number of client sites I've seen with wpse_XXX littered around their themes and plugins is entertaining and, to me at least, proves just how much the code snippets we post are used.

So to answer your specific questions:

Is this a widely accepted standard on WP SE, or simply a commonly used practice?

Just a commonly used practice based on a widely accepted best practice.

In an answer, is the number the question ID or the actual post (answer) ID?

Usually the question ID since, typically, you don't know your answer's ID until after you've posted it.

share

Its Always a good practice to prefix you function names when it comes to WordPress.

When i use it i simple put the id of the question but lately I started to postfix the function names so the function has the meaning full name first and the a unique ID (wpse_XXXX) which makes more sense to me and its easier to understand when I go back and read over the code.

But to answer your question (question/answer id) or even use wpse_XXXX is not a must but it is becoming an accepted standard by those who want to follow it.

Bottom line: Do what ever feels right for you.

share
3  
Postfixing makes a lot of sense, much easier to read, I'll buy it! –  brasofilo Jan 4 '13 at 21:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .