Tag Info

Hot answers tagged

20

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


12

you can use single_template filter hook /* Filter the single_template with our custom function*/ add_filter('single_template', 'my_custom_template'); function my_custom_template($single) { global $wp_query, $post; /* Checks for single template by post type */ if ($post->post_type == "POST TYPE NAME"){ if(file_exists(PLUGIN_PATH. ...


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


12

The WordPress PHP Coding Standards Handbook states that filenames should be all lowercase and hyphen-separated. As Squish points out, various routines in the WordPress Template Hierarchy rely on this convention in order to auto-load templates for certain situations. All of that said, you will not break Linux or Apache by using underscores instead of hyphens ...


11

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


9

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


9

I'm assuming that you put WordPress in your site root and the external directories are also in your site root. The reason this is happening is that .htaccess files follow a hierarchy. Whatever directives are in the top-level .htaccess file flow down and apply to all directories below it. If this is the case, you can do one of several things: Move your ...


9

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


9

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


8

This depends on how the theme was developed from the beginning. Theoretically, if everything was coded to standards you can rename the folder and nothing bad will happen. When renaming the folder you are at risk of breaking code that asks specifically for files from the theme directory by name. WordPress offers a number of functions to help decouple the ...


7

This has worked for me in the past for a similar situation : Put this on top of .htaccess ErrorDocument 401 default


6

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


6

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


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.


5

The PHP files in the wp-includes directory will do nothing when accessed directly. They are designed to be include()'d in an existing PHP script, such as on the front-end or in the dashboard. Your Options -Indexes entry in the .htaccess file simply prevents a list of the files in a directory when no index.php is present. It's good practice to use this on a ...


5

You need to reference your WordPress template directory when you register the script. Change this: wp_enqueue_script('my_javascript_file', '/javascripts/app.js', array('jquery')); ...to this: wp_enqueue_script('my_javascript_file', get_template_directory_uri() . '/javascripts/app.js', array('jquery')); Codex reference: get_template_directory_uri()


4

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


4

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


4

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


4

@kureikain's answer looks great, and it probably works really well in a wide variety of circumstances. But for author URLs specifically, there's a simpler way. Change the author_base, like so: global $wp_rewrite; $wp_rewrite->author_base = "people"; $wp_rewrite->flush_rules(); You should only need to run this once, perhaps on a plugin activation. ...


4

A great starting point would be Mike's answer to the question about cloning CrunchBase. You'll want to do something similar with custom post types for entries in your directory. If you want to allow visitors to submit sites, you could perhaps use the TDO Mini Forms plugin to allow visitors to create a new listing, and adjust the settings so that any new ...


4

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


4

It might be best not to think of it as "folders" since it all runs off of index.php. The rest of the URL structure does not represent the file structure (eg Folders) but the permalink rewriting structure. (And thus make sure you have Permalinks enabled.) To create example.com/miami, you would create a Page within WordPress and set its URL to miami. You can ...


4

Files named "core" are created when some OS process crashes. In your case it was likely a crash of the php interpreter. These files being memory dumps are used to debug the process "postmortem" - e.g. to check in which function did it fail, so it is perfectly safe to delete them if you are not going to debug the issue. In fact, on many systems there is a ...


4

You can use PHP5 RecursiveDirectoryIterator with RecursiveIteratorIterator $directory = '/project_root/wp-content/plugins/your-plugin'; //Your plugin dir $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)); while ($it->valid()) { //Check the file exist if (!$it->isDot()) { //if not parent ".." or current "." ...


4

You can do this by adding some code to wp-config.php $request_uri = $_SERVER['REQUEST_URI']; $debug_dirs = array ('/debug-dir1/','/debug-dir2/'); // list of directories to turn on debugging foreach ($debug_dirs as $debug_dir) { if (!strncmp($request_uri,$debug_dir,strlen($debug_dir))) { define('WP_DEBUG', true); } } define('WP_DEBUG', ...


3

Edit file wp-config.php in root & define site url and home url: define('WP_HOME','http://example.com'); define('WP_SITEURL','http://example.com'); And go to admin dashboard and update permalink (Settings => Permalinks => Update).


3

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; } } ...


3

All my plugins follow this structure, which seems to be very similar to what most other devs are doing: plugin-folder/ admin/ css/ images/ js/ core/ css/ images/ js/ languages/ library/ templates/ plugin-folder.php readme.txt changelog.txt license.txt plugin-folder.php is then ...


3

If you're manually installing a plugin, you need to disable and delete the old version. However, WordPress does allow you to update your plugin programatically. If your plugin is hosted on the WordPress.org repository, it will prompt the users to install updates for you. You've likely seen this with Akismet and other plugins already. If your plugin isn't ...



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