Get variable value based on string constant

You can do that, but you shouldn’t: Keep the global namespace clean. Each name in the global namespace is a collision candidate. Making a variable global, a constant or a function increases the likelihood of a collision, no matter how good your prefixes are. Constants are the slowest global types. Yes, that’s micro-optimization, but why … Read more

Get WP Install Directory

The WordPress directory path is available in the constant ABSPATH. Be aware this is not related to the wp-content directory. The constant WP_CONTENT_DIR could be set to exactly the same value. Or another directory on the same level where WP_CONTENT_URL is another domain name. There doesn’t even have to be a wp-content equivalent: themes, plugins, … Read more

Constant for ‘barebones’ update of WordPress

So in the old days when WordPress updated you got the whole shebang and deleting Akismet after every time was deadly boring. Things had slightly improved since then (partially driven by minimizing traffic it takes to serve update to everyone), but process also got more complicated. Now there are multiple versions of update archive that … Read more

Update the value of a constant

You can’t alter a constant once it is defined. That is how PHP works. Don’t fight it. The good news is that you should not be using a constant at all. Use options. // get your value // the second parameter is the default $enable_paypal = get_option(‘enable_paypal’,true); // set your value based on, I assume, … Read more

is there a benefit in using a constant over get_stylesheet_directory_uri?

You can read up the source code of theme.php where get_stylesheet_directory_uri() is defined, inside you’ll see a str_replace() wich is consuming additional resources on each request. The best way to avoid this is to define a variable or constant that contains the path. In that case it is only called once. https://core.trac.wordpress.org/browser/tags/4.3.1/src/wp-includes/theme.php#L0

How to define constant before plugin [duplicate]

Defining constants on the global scope instead of using WordPress hooks, the first plugin loaded (See answer linked by Kero) will get the chance to define the constant. However, you could use some of the API hooks in your plugin, the earliest one possible is plugins_loaded, and then you can set priorities for the callbacks … Read more

Checking for existence of constants before defining them

These are not PHP global variables, they are constants that cannot be modified(hence the name). Trying to redefine them, using a define() will trigger a notice since they are already defined(and consequently keep the initial value assigned). To stay away from notices, you should check if they have been defined() before. Example: define(‘VARIABLE’, ‘hello’); define(‘VARIABLE’, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)