15

Reference file in current path or deeper nested To reference the current path plugin_dir_path( __FILE__ )."further/nesting/here.css"; which works in Plugins and Themes. Reference URl/URi in a plugin To point to a plugin or theme file, use plugins_url( "path/to/file", __FILE__ ); which works only in plugins Reference URl/URi in wp-admin folder ...


6

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')...


4

Use plugin_dir_url( __FILE__ ); for the URL and plugin_dir_path( __FILE__ ); for the path. Pass the plugin’s main file to both functions to get similar results. Besides that, ADMIN_PATH and ADMIN_DIR are really poor names for custom code. They might result in collisions with other code in the future. Try to use better names, something with a unique prefix.


4

This returns the current plugin's directory's server path: plugin_dir_path(__FILE__) // example: /home/myserver/public_html/wordpress_install/wp-content/plugins/exampleplugin/ Ref: https://codex.wordpress.org/Function_Reference/plugin_dir_path Not to be confused with: plugins_dir_path(__FILE__) (Notice the plural "plugins" on that.) Since you don't ...


3

TEMPLATEPATH and STYLESHEETPATH will be deprecated in the near future. It is not safe to rely on these constants. Use get_template_directory() and get_stylesheet_directory() instead. And wait until the init hook (or after_setup_theme before you use them to be sure all needed files are loaded. Example for a plugin: add_action( 'after_setup_theme', '...


3

The value you pass to wp_enqueue_script should be the URL of the script, not the local file path. wp_enqueue_script('my-script', get_template_directory_uri() . '/my-scripts/my-script.js');


3

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, a form of some kind update_option('...


3

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 hooked into this so you can have ...


3

From the PHP manual on defining namespaces: Namespaces are declared using the namespace keyword. A file containing a namespace must declare the namespace at the top of the file before any other code - with one exception: the declare keyword. To fix the issue, simply make sure that your namespace declaration comes before the other code: namespace JSR;...


3

You should not put any defines in the end of the wp_config.php it is actually explicitly stated in it ;) Every define you add should be above the line saying /* That's all, stop editing! Happy blogging. */ Anything after that will have impact only after wordpress had finished to process the request


2

While calling get_stylesheet_directory_uri multiple times does consume some extra resources versus setting a constant, I doubt you could reliably measure the overall impact it would have on your code. You would also lose the filter applied to the output of get_stylesheet_directory_uri, if it was changed depending on context, and make your code slightly less ...


2

The basic syntax for define() is: define ( $name, $value ) In the above definition, the value is: ( 0755 & ~ umask() ) The '&' (ampersand) is the 'And' bitwise operator, the '~' (tilde) is the 'Not' bitwise operator, and the umask() function returns the current umask. To answer your question in short (if your are interested in learning bitwise ...


2

Once you have same db, you will have same users, so offcouse the password for the user 'admin' (please do not use 'admin' as username) will be the one setted in database, and of course is the same for the 2 sites, once they shared the db. However you can create users that can login only in one site and users that can login in the other. To do that, add a ...


1

I don’t think you should define constants in your plugin. It will be very hard to debug later on. IMHO using wp_revisions_to_keep filter will be much nicer solution. So your code could look like this: add_filter( 'wp_revisions_to_keep', 'my_revisions_to_keep_based_on_settings', 10, 2 ); function my_revisions_to_keep_based_on_settings( $num, $post ) { ...


1

I think this is happening because Constants cannot be redefined later. Once they are set, they are fixed. http://php.net/manual/en/language.constants.php I'm not exactly sure how WP language constructs work, but part of me thinks that they are defined, then changed later on the fly when plugins/themes use them. I don't have a reference for this but it seems ...


1

I have some modifications that I make in wp-config.php that allow for WordPress to work with my version control process. I think with some adjustments the modifications could work for your purpose as well. 1) Make URLs relative instead of absolute. This is useful because WordPress likes to write absolute URLS to the database, but since you're serving the ...


1

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/...


1

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 core might receive ...


1

I usually split my theme's functions into several files as well, and include those in my functions.php, like so: // load helper functions require_once get_stylesheet_directory().'/inc/helper-functions.php'; // load admin functions if (is_admin()) require_once get_stylesheet_directory().'/inc/admin-functions.php'; // load theme functions require_once ...


1

I have created a wordpress plugin that uses custom css/js code, in order to include these resources locally add a line like this one: wp_enqueue_style( 'wp-aa-style', plugin_dir_url( __FILE__ ) . 'css/wp-aa-style.css',false,'1.1','all'); wp-aa-style is the element id make sure to define a css folder and a wp-aa-style.css file inside your WordPress plugin's ...


1

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, languages ...


1

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 introducing it when ...


1

I guess you're talking about a site specific wp-config.php file that resides in your themes folder. At the point where you're loading the wp-config.php file, WP isn't fully loaded, so you ain't got any constants or filesystem API or other basic API functions available. Here's how I approach this: Structure # Dir structure ~/ROOT ├── config ├── wp-content ...


1

Try taking a look at this answer over at StackOverflow: https://stackoverflow.com/a/2356526/1077363 - it looks similar to the method I used once before but don't have that code to hand right now. The theory behind it is that you are usually only 2 or 3 directories below the root directory, so checking for the existence of wp-config.php (which is most of the ...


1

I guess what you are saying is that it then 'exports' the wrong system's xml (I'm not familiar with the plugin) ? Ideally the plugin itself should be including/using the code rather in such a way so that it still knows the context/system in which it is being used irrespective of where the code is stored. Have you tried seeing if the plugin author can ...


1

Windows does support both styles of slashes in path. I am not sure if ABSPATH definition is safe to edit: pro it's in wp-config.php con it's says to not edit following above it Myself I just use it as is, or replace slashes to make them uniform when putting path together. If that doesn't work for you please provide specific examples where this causes ...


Only top voted, non community-wiki answers of a minimum length are eligible