• 赤色のリンクは、まだ日本語Codexに存在しないページ・画像です。英語版と併せてご覧ください。(詳細

このWikiはいつでも誰でも編集できます

プラグインとテーマの移行

提供: WordPress Codex 日本語版
2008年2月19日 (火) 22:04時点におけるBono (トーク | 投稿記録)による版 (en:Migrating Plugins and Themes 2008年2月16日 (土) 01:30 Jeremyclarke 版/著者: JHodgdon, Jeremyclarke)

(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
移動先: 案内検索

Introduction

When you upgrade WordPress from one major version to another, such as from 2.1 to 2.2, you may find that your Themes and Plugins no longer work the way you are used to. It could be that they are completely broken, because something in WordPress that was fundamental to them changed, but it's also possible that you can get them working again by updating some settings, or maybe just a small edit.

This article has some hints on how to upgrade plugins and themes from one version to another, below. There is also a special article on Migrating Plugins and Themes to 2.1, which covers changes between WordPress 2.0 and WordPress 2.1, as well as a much older article, Upgrade 1.2 to 1.5, which covers how to convert a really old Theme to the current theming system.

Migrating from 2.1 to 2.2

The main change of importance to Plugins and Themes in Version 2.2 was the introduction of WordPress Widgets as part of the core of WordPress. (Widgets are small pieces of WordPress output, such as category lists, archive lists, and search forms, which you can put into the sidebar(s) of your blog.)

If you want to use Widgets in a Theme that was developed prior to WordPress 2.2, you can find out how to fix your theme in this article on Widgetizing Themes.

If you want some output that your Plugin generates to be displayed in a sidebar Widget, you can find out how in this article on Widgetizing Plugins, and you may also find the Widgets API article useful.

Migrating from 2.2 to 2.3

Categories and Tags

The main change of importance to Plugins and Themes in Version 2.3 was the introduction of tagging as a core WordPress functionality.

If you want to add tags to your theme (e.g. to display the tags used on a post, or put a tag cloud into your sidebar), you will be interested in new the_tags and wp_tag_cloud template tag functions.

There were also quite a few new tag-related functions for use in plugins introduced in WordPress 2.3.

Also, as a side effect of introducing tags to WordPress, the underlying database table structure, in regards to storage of categories, was changed considerably. So, any plugins that ran queries using the category-related tables in the WordPress database will likely be broken; the queries will have to be completely rewritten. Plugins and Themes that used WordPress functions to access categories should be OK.

Canonical URLs

Another change in 2.3 that affects some plugins is the introduction of "canonical" URLs. The canonical URL system basically rewrites all URLs used in WordPress into "canonical" form, so that there is only one URL that points to a given display, and other URLs that could also point to that display are redirected to the "canonical" URL. Most plugins will not be affected by this change, but a plugin that adds suffixes to URLs could find that some of the URLs it generates are broken. Notably, a URL with a page number in it, such as example.com/page/2/ (to access the second page of older posts) must have the page section at the end of the URL. Prior versions of WordPress would have allowed example.com/page/2/suffix/ to work, but in WordPress 2.3, the URL must be generated as example.com/suffix/page/2 in order to function correctly.

Note that if you use a non-standard url/permalink structure that is necessary for the functioning of your site, the "canonical url" functionality can be turned off by adding the following to a plugin file or the functions.php file in your template folder:

remove_filter('template_redirect', 'redirect_canonical');

WordPress 2.5 will make a further filter available for choosing which canonical redirects are denied rather than forcing them to be all on or all off.

Migrating from 2.3 to 2.5

(Note: There was no WordPress version 2.4 - it was skipped.)

Themes are unlikely to be affected hugely by Version 2.5.

The main change affecting plugins in the (at time of writing) upcoming WordPress version 2.5 is the complete overhaul of the administration screens and menus of WordPress. This change will affect some plugins that add pages to the menus, or sections to screens, in the administration sections of WordPress.

First, menus: The menus have been reorganized slightly; most plugins will probably still function correctly, if they used the standard methods of Adding Administration Menus.

Second, screens: Any plugin that had added a section to the post editing screen, or other administration screen, will probably find that the formatting and markup changes on the administration screens in WordPress 2.5 have made their section so that it no longer "blends in" and looks like it belongs with the built-in WordPress sections on the screen. So, plugin authors will either need to release a new version of their plugins for WordPress 2.5, or (preferably) put some decision logic into their plugin that will detect the version and use the right formatting. A good way to do that is to detect whether the new formatting functions have been defined. For example:

if (function_exists('add_meta_box')) {
 // 2.5 style
} else {
 // 2.3
} 

Another change that might affect some plugins is that in WordPress 2.5, the Activation hooks for plugins are run in non-global scope within a function (they used to be run in the global scope). This means that if your plugin has an activation hook, and the function it calls relies on global variables that are defined within your plugin file, you may find that they are not working properly. All you need to do is, at the global scope level in your plugin, add a "global" declaration for those variables, and you should be OK. For instance:

global $my_plugin_variable;
$my_plugin_variable = 3;

function my_plugin_activation_function() {
   global $my_plugin_variable;

   // rest of activation function
}

最新英語版: WordPress Codex » Migrating Plugins and Themes