-
Notifications
You must be signed in to change notification settings - Fork 1
Description
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 "PayButton" then you could use names like these:
function paybut_save_post(){ ... }
class PAYBUT_Admin { ... }
update_option( 'paybut_settings', $settings );
define( 'PAYBUT_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
global $paybut_options;
namespace klakurka\paybutton;
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 prefix "paybutton" for 35 element(s).
Looks like there are elements not using common prefixes.
includes/class-paybutton-activator.php:31 update_option('pb_paywall_admin_wallet_address', $old_value);
includes/class-paybutton-admin.php:257 update_option('pb_paywall_admin_wallet_address', $address);
includes/class-paybutton-admin.php:277 update_option('unlocked_indicator_bg_color', $unlocked_indicator_bg_color ?: '#007bff');
includes/class-paybutton-admin.php:278 update_option('unlocked_indicator_text_color', $unlocked_indicator_text_color ?: '#ffffff');
Note: Options and Transients must be prefixed.
This is really important because the options are stored in a shared location and under the name you have set. If two plugins use the same name for options, they will find an interesting conflict when trying to read information introduced by the other plugin.
Also, once your plugin has active users, changing the name of an option is going to be really tricky, so let's make it robust from the very beginning.
Example(s) from your plugin:
includes/class-paybutton-admin.php:257 update_option('pb_paywall_admin_wallet_address', $address);
includes/class-paybutton-admin.php:278 update_option('unlocked_indicator_text_color', $unlocked_indicator_text_color ?: '#ffffff');
includes/class-paybutton-admin.php:277 update_option('unlocked_indicator_bg_color', $unlocked_indicator_bg_color ?: '#007bff');
includes/class-paybutton-activator.php:31 update_option('pb_paywall_admin_wallet_address', $old_value);