51

I think you have to be a little careful because it depends on what you are trying to do. If you are using a child theme get_template_directory(); will still go to the parent theme. However get_stylesheet_directory(); will go to the current theme, child or parent. Also, both these functions return absolute server paths. If you wanted a fully formed URI, ...


28

Okay, I'll take a stab at this. Some limitations I encountered along the way: There are not a lot of filters in subclasses of WP_List_Table, at least no where we need them to be. Due to that lack of filters, we can't really maintain an accurate list of plugin types at the top. We also have to use some awesome (read: dirty) JavaScript hacks to display ...


24

Updated answer Cleaner and shorter version. function load_movie_template( $template ) { global $post; if ( 'movie' === $post->post_type && locate_template( array( 'single-movie.php' ) ) !== $template ) { /* * This is a 'movie' post * AND a 'single movie template' is not found on * theme or child theme ...


21

Try to visit through the folder structure of your site from the browser: http://example.com/wp-content/ You will see a blank page. That's actually is the index.php, and its content is very simple - a commented out PHP comment: <?php // Silence is golden. Remove the file and visit the URL again. You will see the file structure completely. So your file ...


17

Following Justice Is Cheap lead, I ended adapting the functions from this plugin: http://wordpress.org/extend/plugins/custom-upload-dir/ <?php /* * Change upload directory for PDF files * Only works in WordPress 3.3+ */ add_filter('wp_handle_upload_prefilter', 'wpse47415_pre_upload'); add_filter('wp_handle_upload', 'wpse47415_post_upload'); ...


17

Note that plugins are all "controllers" by WP standards. It depends on what the plugin is supposed to do, but in all cases I would try to separate the screen output from the PHP code as much as possible. Here's one way to do that easily - first, define a function that loads the template: function my_plugin_load_template(array $_vars){ // you cannot let ...


17

To make a long story short: get_bloginfo( 'template_directory' ) and get_bloginfo( 'template_url' ) simply return get_template_directory_uri(). So, you can shortcut that second call simply by referring directly to the latter template tag. Refer to source for get_bloginfo(). A few others: 'url' => home_url() 'wpurl' => site_url() 'stylesheet_url' => ...


17

In short, there is no well defined convention for naming a theme's directory, and all of the following are valid (among others): my_wordpress_theme my-wordpress-theme (empirically the most popular option within the ecosystem) MyWordPressTheme mywordpresstheme (what the default themes use) Details The WordPress PHP Coding Standards Handbook states that ...


12

How does Wordpress determine "the main plugin file" ? It is the file in your plugin that contains the plugin header comment /** * Plugin Name: A fresh example * Plugin URI: http://example.com * Description: Foo makes a bar * Version: 2012-06-14.1426 * Author: John Doe * Author URI: http://example.com * TextDomain: your_textdomain * ...


11

How Page Templates are loaded: According to the default WordPress Template Hierarchy, a page request loads a template based on the priority and naming as stated below: Custom Page Template: if defined in the page editor. page-{slug}.php page-{url-encoded-slug}.php: only for multi-byte characters. page-{id}.php page.php singular.php index.php Among these, ...


10

once up a time i did a client project where i had to have archives by first letter. thinking back i'm wondering if shouldn't have just created a hidden taxonomy and then saved the first letter as a term in that taxonomy. anyway, here's what i actually did: /* * Function Create Array of Letters that have post titles (for archive) */ /* When the post ...


10

You can just register another stylesheet instead of style.css: add_action( 'wp_enqueue_scripts', 'enqueue_theme_css' ); function enqueue_theme_css() { wp_enqueue_style( 'default', get_template_directory_uri() . '/css/default.css' ); } This is, in my opinion, better than using style.css.


9

My best guess would be: if ( ! is_file( $dir = WPMU_PLUGIN_DIR . '/pluginb/pluginb.php' ) ) { if ( ! is_file( $dir = WP_PLUGIN_DIR . '/pluginb/pluginb.php' ) ) $dir = null; } return $dir; However, the danger here is still the assumption of the plugin's "basename" - a well written plugin will still function even when its directory and/or main ...


9

Best place is the uploads directory - it'll be writable by the server, and it's the defacto directory for storing any user-generated/uploaded files: $dirs = wp_upload_dir(); $path = $dirs['basedir']; // /path/to/wordpress/wp-content/uploads


8

Updated plugin version available at GitHub. I first saw your Question at [wp-hackers] list, and, after implementing the solution, was about to publish a Q&A for that. Well, it's already here, and has a bounty put on it :) As Daniel Bachhuber points out in the thread: WordPress.com puts themes inside of subdirectories /wp-content/themes/public /...


8

If the plugin structure is: plugins/ some-plugin/ some-plugin.php data/ GeoIP.dat then for PHP 5.3.0+, you could try the magic constant __DIR__ __DIR__ The directory of the file. If used inside an include, the directory of the included file is returned. This is equivalent to dirname(__FILE__). This directory name does not ...


7

get_template_directory(); http://codex.wordpress.org/Function_Reference/get_template_directory


7

I know it's old but I fixed it! i installed WP MU in a subfolder. htaccess: RewriteEngine On RewriteBase /YOUR_SUBFOLDER RewriteRule ^index\.php$ - [L] # add a trailing slash to /wp-admin RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L] RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^ - [L] RewriteRule ...


7

You cannot use bloginfo() while your are outputting using echo because bloginfo it self also out puts string using echo. Below will work for you, you also have extra double quote which i have removed.... <?php $attch_id_1 = pn_get_attachment_id_from_url(get_post_meta($post->ID, 'img1', true)); $image_attributes_1 = ...


7

This file is just there if the server (Apache, Nginx, Lighttp, etc.) is not properly set up and allowing this kind of file system access for guests. To properly set up your Apache for e.g., just add the following to your .htaccess Options –Indexes which will lead to a Forbidden|403 for everyone trying to access your directory structure (prevents directory ...


7

Within the plugin's main PHP file: $plugin_data = get_plugin_data( __FILE__ ); $plugin_name = $plugin_data['Name'];


6

It depends on the plugin. This is my basic structure for nearly every plugin: my-plugin/ inc/ Any additional plugin-specific PHP files go here lib/ Library classes, css, js, and other files that I use with many plugins go here css/ js/ images/ lang/ Translation files my-plugin.php readme.txt ...


6

IMHO, the easiest, most powerful, and most maintainable route is to use an MVC structure, and WP MVC is designed to make writing MVC plugins very easy (I'm a little biased, though...). With WP MVC, you simply make the models, views, and controllers, and everything else is handled behind the scenes for you. Separate controllers and views can be made for the ...


6

After these years I hope this will still answer your question... I think I've got the situation working you want. Allthough I don't have the Wordpress installation in '/subfolder/', but I've a installation 'in subdirectory' per language, and on the same level: my-domain.com/nl/ -> this is primary installation, site id = 1 my-domain.com/en/ -> this ...


6

The procedure is thoroughly documented in Codex under Moving a Root install to its own directory. You misunderstand the point about changing URLs in it, and yes the terminology sucks. The only URLs that will change are those that are based on the "WP address". That would be WordPress core, essentially the admin area. All content URLs are based on "Site ...


6

As @MarkKaplun suggests, it would be preferable to store this non-WordPress file in a different area of the filesystem altogether and rewrite the URL in .htaccess. Instead of mimicking the WordPress URL in the physical directory structure - which will likely only cause you (more) problems (not least that you would need to override the WordPress front-...


5

I came up with this solution. This function checks in each directory level starting from the directory of the current file for the file wp-config.php. <?php function find_wp_config_path() { $dir = dirname(__FILE__); do { if( file_exists($dir."/wp-config.php") ) { return $dir; } } while(...


5

We're using a mix of all methods. First of all, we're using the Zend Framework 1.11 in our plugins and therefore we had to use a similar structure for the class files because of the autoload mechanic. The structure of our core plugin (which is used by all our plugins as a base) looks similar to this: webeo-core/ css/ images/ js/ languages/ ...


5

Like many here already answered It really depends on what the plugin is supposed to do, but here is my base structure: my-plugin/ admin/ holds all back-end administrative files js/ holds all back-end JavaScript files css/ holds all back-end CSS files images/ holds ...


5

The forward slash works on every operating system supported by PHP. Yes, on Windows too. It is also more readable and easier to type, so there is no need to use the constant. See the tickets #20849 and #15598 for related discussion on Trac.


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