当サイト、Codex 日本語版は今後積極的な更新は行わない予定です。後継となる新ユーザーマニュアルは、https://ja.wordpress.org/support/ にあります。
万が一、当サイトで重大な問題を発見した際などは、フォーラムWordSlack #docs チャンネルでお知らせください。</p>

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

提供: WordPress Codex 日本語版
< プラグインとテーマの移行
2008年11月12日 (水) 00:10時点におけるBono (トーク | 投稿記録)による版 (en:Migrating Plugins and Themes to 2.7 23:16, November 10, 2008 ChrisThomson 版を翻訳用にコピー、言語間リンク・差分リンク挿入)

(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
移動先: 案内検索
このページ「プラグインとテーマの移行/2.7」はまだ書きかけで、情報が不足しています。続きを書いて WordPress を手助けしましょう.


Introduction

When a new major version of WordPress is released, such as WordPress 2.1 or 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 is part of a series on Migrating Plugins and Themes. It covers changes between WordPress Version 2.6 and Version 2.7, and what you need to do to Plugins and Themes to get them working in Version 2.7.

If the Theme or Plugin you are using was developed by someone else, there are several places to look for information:

If you are the author of your Theme or Plugin, or if you have modified or customized your Theme, then this article will help you upgrade your Theme/Plugin for 2.6. If your Theme or Plugin is distributed publicly, after getting it working you may want to add it to the Compatibility lists above, so your users will know it is working and which version they should be running.

Fixing Up Your Theme or Plugin

The following sections describe changes to WordPress that might affect your theme or plugin.

Themes

Enhanced Comment Display - Threading, Paging, etc.

Comments have many new features in WordPress 2.7, such as threading, nesting, paging, etc. They are built in, assuming that your theme supports them. As of this writing, the exact feature list is in flux, but this article on Otto's blog is keeping up with the changes, and describes how to update your theme to take advantage of the new features.

Post Classes

WordPress 2.7 includes a new function for post classes, which will help theme authors perform simpler styling. The function is, appropriately enough, called post_class().

To use this function in a theme, you will simply add it to the Loop in a place that makes sense. Most themes encapsulate every post within a DIV of some sort. That DIV usually has a class="post" or something similar. Instead of that class, just add a call to post_class instead. Like so:

<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

The post_class() outputs the class="whatever" piece for that div. This includes several different classes of value: post, hentry (for hAtom microformat pages), category-X (where X is the slug of every category the post is in), and tag-X (similar, but with tags). It also adds "sticky" for posts marked as sticky posts. These make it easy to style different parts of the theme in different ways.

For special cases where you want to add your own classes, post_class supports that too:

<?php post_class('special'); ?>

This will add "special" to the class list. You can either give it a space separated list of classes, or an array of strings with one class each, if your code is more complex and that is more useful.

For displaying posts outside the Loop or in an alternate Loop, the second parameter to the post_class function can be the post ID. Classes will then be determined from that post.

<?php post_class('',$post_id); ?>

Logout from Site

The Template Tag,wp_logout_url, was added in Version 2.7 to provide a nonced URL for logout purposes. If a theme uses a construct such as /wp-login.php?action=logout to offer the user a logout link that code should be updated to use the wp_logout_url. A good example of the usage of wp_logout_url can be seen in the WordPress Default and Classic themes comments.php and comments-popup.php Templates.

Users will experience a You are attempting to log out of yourdomain.tld. Please try again. message if the theme does not use wp_logout_url for the logout URL.

Excluding Sticky Posts from Custom Queries

The ability to designate a post as a sticky was added in Version 2.7. If you use a query posts loop, those sticky posts will be returned in your custom queries. But, to prevent the sticky posts from being included, just add caller_get_posts=1 to your query string.

Plugins

Uninstall Plugin API

There is a new plugin uninstall in WordPress 2.7 that allows a plugin to uninstall itself, when the user deletes the plugin. There are two uninstall methods that the plugin can implement. One is by creating a file in the base plugin directory named uninstall.php and storing the uninstall code there. The second method is by creating a hook that will execute the uninstall routines and using register_uninstall_hook() function to register the hook with WordPress.

Administrative Hooks Added and Removed

The administration menus in WordPress were redesigned again for 2.7, and correspondingly, some plugin hooks (actions and filters) were added and removed. Here is a list (which may be incomplete):

Add to Settings pages

WordPress 2.7 is going to have an API for adding additional sections to the manage or settings administration panels. This means directly in those pages and not as a new page. The functions add_settings_section(), add_settings_field(), register_setting(), unregister_setting() implement this feature. The functions are found in wp-admin/includes/plugin.php (also see the section below on registering options).

Admin Header

The "sidemenu" action has been removed, since the section of the admin page header that used to add items to is no longer there.

There is a new "favorites" menu, using the 'favorite_actions' filter (see wp-admin/includes/template.php, function favorite_actions() near the bottom, to figure out how to use it).

Plugins List Page

There are two filters that let plugins add items to their display on the Plugins page:

  • plugin_action_links_{$plugin} filter -- lets you add a new action to the Actions column for your plugin. Example:
$plugin = plugin_basename(__FILE__); 
add_filter("plugin_action_links_$plugin", 'my_plugin_actlinks' ); 
function my_plugin_actlinks( $links ) { 
 // Add a link to this plugin's settings page
 $settings_link = '<a href="whatevertheurlis">Settings</a>'; 
 array_unshift( $links, $settings_link ); 
 return $links; 
}
  • after_plugin_row_{$plugin_file} filter - this allows you to add something to the end of the row of information displayed for your plugin - like the existing after_plugin_row filter, but specific to your plugin, so it only runs once instead of after each row of the plugin display

Plugins need to Register their Options

In a near-future version of WordPress (and in the current version of WordPress MU), plugins will need to register their options. In WordPress, the functions register_setting() and unregister_setting() can be used to do this; these are simple wrappers for the functions that exist now in WPMU, add_option_update_handler() and remove_option_update_handler() (the new aliases will be added soon to WPMU as well). While using these functions is not required for 2.7, it will be required soon for any plugin that uses options.php as its post handler for optoin updates, so it is a good idea to modify your plugin now.

These functions have several purposes:

  • Whitelist options
  • Register sanitization callbacks
  • In WPMU, prevent admins (who are not necessarily trusted on a WPMU setup that allows anyone to create a blog) from tinkering with private options such as rewrite_rules or active_plugins.

Here's how to use them (you may also want to read the function documentation in wp-admin/includes/plugin.php):

  • Define a group name for your options, such as 'some-options'
  • Do something like the following in an admin_init action for each setting you want to update:
register_setting('some-options', 'option-1', 'intval');
  • Do this in your option update form:
settings_fields('some-options');

settings_fields() outputs all of the hidden fields that options.php will check, including the nonce. You no longer need to setup the page_options hidden field if you use the new API.


This page is a stub... more will be added shortly (I hope).



最新英語版: WordPress Codex » Migrating Plugins and Themes to 2.7最新版との差分