开发者 | jrf |
---|---|
更新时间 | 2018年1月22日 19:21 |
捐献地址: | 去捐款 |
PHP版本: | 5.2.4 及以上 |
WordPress版本: | 4.9 |
版权: | GPLv2 |
/wp-content/plugins/
directory. Alternatively, you can install directly from the Plugin directory within your WordPress Install.PLEASE DON'T! Amongst the defined constants are your database credentials, so you really do not want to do this. This plugin is only meant to be used for development purposes.
A constant is an identifier (name) for a simple value. As the name suggests, that value cannot change during the execution of the script. A constant is case-sensitive by default. By convention, constant identifiers are always uppercase. Like super globals, the scope of a constant is global. You can access constants anywhere in your script without regard to scope. For more information on scope, read the manual section on variable scope.
Congratulations! Sounds like you're practicing lean programming (or something is going wrong... ;-) ). The constants you see are the ones available in the current request. If you define constants in a conditionally included file - for instance you only include the file when on a certain page -, these constants will not be available if the conditions have not been met.
See the previous question.
It is possible to define constant values on a per-class basis remaining the same and unchangeable. Constants differ from normal variables in that you don't use the $ symbol to declare or use them. The value must be a constant expression, not (for example) a variable, a property, a result of a mathematical operation, or a function call.
It's good coding practice to avoid littering the global namespace with your own variables and constants. This is a good way to avoid this.
If your plugin/theme interacts with other plugins and/or themes, you may want to use their constants.
Example: A plugin might have their version number saved as a class constant (good practice!). On your part, your plugin may have been set up to only work if the related plugin has been upgraded to version x. In that case, you may want to check other plugins version number before your plugin interacts with it.
Don't forget to always check whether the class constant exists before you use it! It may not be available on all pages and surely not on all WP installs.
if( defined( 'class_name::constant_name' ) ) { // Your code here }
Easy: It's bad practise to name your class the same as one of the PHP native/extension classes. In general, when you're developing a plugin/theme, you are developing for an unknown group of other people with unknown server configurations - including which extensions are(n't) installed -, so you should always make sure that your class will not interfere with any of the PHP native/extension classes.
I've tried to exclude all PHP classes from this list, however, I might have missed some. Also some new extensions and/or classes may have been introduced in PHP since the last version of this plugin was released. Please let me know which one(s) you found and I'll add it/them to the exclusion list.
Have you read what it says in the beautifully red bar at the top of your plugins page ? As it says there, the Debug Bar plugin needs to be active for this plugin to work. If the Debug Bar plugin is not active, this plugin will automatically de-activate itself.
must-use
plugins directory.