Generic function/class/define/namespace/option names #3

Open
opened 2026-01-25 13:48:36 +01:00 by vlad · 0 comments
Owner

All plugins must have unique function names, namespaces, defines, class and option names. This prevents your plugin from conflicting with other plugins or themes. We need you to update your plugin to use more unique and distinct names.

A good way to do this is with a prefix. For example, if your plugin is called "Out of Office for Woo" then you could use names like these:

  • function outofoff_save_post(){ ... }
  • class OUTOFOFF_Admin { ... }
  • update_option( 'outofoff_settings', $settings );
  • define( 'OUTOFOFF_PLUGIN_DIR', plugin_dir_path( FILE ) );
  • global $outofoff_options;
  • namespace vladbejenaru\outofofficeforwoo;

Disclaimer: These are just examples that may have been self-generated from your plugin name, we trust you can find better options. If you have a good alternative, please use it instead, this is just an example.

Don't try to use two (2) or three (3) letter prefixes anymore. We host nearly 100-thousand plugins on WordPress.org alone. There are tens of thousands more outside our servers. Believe us, you’re going to run into conflicts.

You also need to avoid the use of __ (double underscores), wp_ , or _ (single underscore) as a prefix. Those are reserved for WordPress itself. You can use them inside your classes, but not as stand-alone function.

Please remember, if you're using _n() or __() for translation, that's fine. We're only talking about functions you've created for your plugin, not the core functions from WordPress. In fact, those core features are why you need to not use those prefixes in your own plugin! You don't want to break WordPress for your users.

Related to this, using if (!function_exists('NAME')) { around all your functions and classes sounds like a great idea until you realize the fatal flaw. If something else has a function with the same name and their code loads first, your plugin will break. Using if-exists should be reserved for shared libraries only.

Remember: Good prefix names are unique and distinct to your plugin. This will help you and the next person in debugging, as well as prevent conflicts.

Analysis result:

# This plugin is using the prefixes "ooo_woo", "ooowoo" for 11 element(s).
# This plugin is using the prefix "out_of" for 17 element(s).

# Looks like there is an element not using common prefixes.
includes/out-of-office-for-woo-options.php:3 function my_sanitize_options

All plugins must have unique function names, namespaces, defines, class and option names. This prevents your plugin from conflicting with other plugins or themes. We need you to update your plugin to use more unique and distinct names. A good way to do this is with a prefix. For example, if your plugin is called "Out of Office for Woo" then you could use names like these: - function outofoff_save_post(){ ... } - class OUTOFOFF_Admin { ... } - update_option( 'outofoff_settings', $settings ); - define( 'OUTOFOFF_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); - global $outofoff_options; - namespace vladbejenaru\outofofficeforwoo; Disclaimer: These are just examples that may have been self-generated from your plugin name, we trust you can find better options. If you have a good alternative, please use it instead, this is just an example. Don't try to use two (2) or three (3) letter prefixes anymore. We host nearly 100-thousand plugins on WordPress.org alone. There are tens of thousands more outside our servers. Believe us, you’re going to run into conflicts. You also need to avoid the use of __ (double underscores), wp_ , or _ (single underscore) as a prefix. Those are reserved for WordPress itself. You can use them inside your classes, but not as stand-alone function. Please remember, if you're using _n() or __() for translation, that's fine. We're only talking about functions you've created for your plugin, not the core functions from WordPress. In fact, those core features are why you need to not use those prefixes in your own plugin! You don't want to break WordPress for your users. Related to this, using if (!function_exists('NAME')) { around all your functions and classes sounds like a great idea until you realize the fatal flaw. If something else has a function with the same name and their code loads first, your plugin will break. Using if-exists should be reserved for shared libraries only. Remember: Good prefix names are unique and distinct to your plugin. This will help you and the next person in debugging, as well as prevent conflicts. **Analysis result:** `# This plugin is using the prefixes "ooo_woo", "ooowoo" for 11 element(s).` `# This plugin is using the prefix "out_of" for 17 element(s).` `# Looks like there is an element not using common prefixes.` `includes/out-of-office-for-woo-options.php:3 function my_sanitize_options`
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
vlad/out-of-office-for-woo#3
No description provided.