wordPressの風情の続き


wordPress3.0について、以前wordPress3.0の風情 - ミショニポーというエントリを書きました。
それから大分経って、もう少し重箱の隅も気になる今日この頃、とりあえずリストにして、答えの出たところは、ここに書き足そうかなという趣旨で、


いずんなっかわがんねぇげっとも、すこっづつやってみっかなぁーどおもってんのしゃ

誰が あがるいひと いねがなぁーど おもって、いっつも たづねであるぐんだけど、ながながねぇー




やっぱ あちゃらせい だがらねぇ んでもながながDELUXだがらっしゃー、はなさいねんだでば



ところで、wordPress3.0関数検索できます

wordPress2.9.2とwordPress3.0のPHPDocumentor全文検索です。






ところで、3.0になって、新しい hook
WordPress 3.0 - List of all hooks and filters -- Adam Brown, BYU Political Science


この辺り どうなんだろうと思ったところを書き出し。

upload ディレクトリ

ネットワークでは、アップロードディレクトリの設定画面は出ない。
f:id:tenman:20100805150144g:image:w300




ネットワークで複数ブログを作ると

最初のブログは
http://www.example.com/wp/wp-content/uploads/juice-150x150.jpg
にアップロード
2個目のブログは、
http://www.example.com/wp/subdir/wp-content/files/juice-150x150.jpg
が画像リンク先になりますが、実際の画像は、
http://www.example.com/wp/subdir/wp-content/blogs.dir/2/files/juice-150x150.jpg
(2はブログid)





国際化 _ex() を導入

テキストを含んだ翻訳後 echo するため、_e() と _x() のハイブリッドである _ex() を導入
_e
_n __ngettext 単数 複数 の翻訳を持つ
_x 文脈
I18n for WordPress Developers - WordPress Codex 日本語版


get_index_template() を導入

子テーマが親テーマの index.php を上書きできるよう get_index_template() を導入

子テーマで、index.phpがあれば、そのパスを、なければtwentyten(デフォルト設定の)index.phpのパスを返す模様


get_template_part

(ヘッダ・サイドバー・フッタ以外の) 一般的なファイルをインクルードするための

<?php get_template_part( 'loop', 'index' ); ?>

wp-content/themes/twentytenchild/loop-index.php
wp-content/themes/twentytenchild/loop.php
wp-content/themes/twentyten/loop-index.php
wp-content/themes/twentyten/loop.php

子テーマにloop.phpがなければ、親テーマのloop.phpを使う

それぞれひとつのパラメータをもてる
get_header()
get_footer()
get_sidebar()
get_search_form()

応用

<?php
if ( is_home() ) :
  get_header('home');
elseif ( is_404() ) :
  get_header('404');
else :
  get_header();
endif;
?>

home and 404 headers は、header-home.php and header-404.php を呼ぶでしょう

<?php comments_template( '/short-comments.php' ); ?> 

comments_template関数引数を省略すると、comments.phpを呼びます

Function Reference/comments template « WordPress Codex

<?php wp_head(); ?> 

Function Reference/wp head « WordPress Codex

使い方: <?php do_action('wp_head'); ?>
または <?php wp_head(); ?>
<?php wp_footer(); ?> 

Function Reference/wp footer « WordPress Codex


wp_meta
広告スイッチャーやタグクラウドを表示させる。

使い方: <?php do_action('wp_meta'); ?>
または <?php wp_meta(); ?>

comment_form
comments.php および comments-popup.php のコメントフォーム終了タグ () の直前に含める。
プラグインによるフック使用の例: コメントプレビューを表示させる。

使い方: <?php do_action('comment_form', $post->ID); ?>
<?php wp_nav_menu($args); ?> 

テンプレートタグ/wp nav menu - WordPress Codex 日本語版

<?php wp_page_menu('arguments'); ?>

テンプレートタグ/wp page menu - WordPress Codex 日本語版

body_class()
post_class()
comment_class()

Theme Development « WordPress Codex

<?php count_user_posts( $userid ); ?> 

Function Reference/count user posts « WordPress Codex

<?php
$users = array(1, 3, 9, 10);
$counts = count_many_users_posts($users);
echo 'Posts made by user 3: ' . $counts[3];
?>

Function Reference/count many users posts « WordPress Codex

<?php get_the_author_link(); ?> 

Function Reference/get the author link « WordPress Codex




taxonomy が wp_tag_cloud()でも扱えるようになった



wp_tag_cloud( array( 'taxonomy' => 'actor', format => 'list' ) );

taxonomy が 既存の wp_list_categoriesで扱えるようになった

<?php 
//list terms in a given taxonomy using wp_list_categories (also useful as a widget if using a PHP Code plugin)

$taxonomy     = 'actor';
$orderby      = 'name'; 
$show_count   = 0;      // 1 for yes, 0 for no
$pad_counts   = 0;      // 1 for yes, 0 for no
$hierarchical = 1;      // 1 for yes, 0 for no
$title        = '';

$args = array(
  'taxonomy'     => $taxonomy,
  'orderby'      => $orderby,
  'show_count'   => $show_count,
  'pad_counts'   => $pad_counts,
  'hierarchical' => $hierarchical,
  'title_li'     => $title
);
?>




home_url() を導入

schemeが’http’ か ‘https’の場合、is_ssl()は、オーバーライドします。
サイト指定のURLを取得するget_home_url タグを使用します。

  • get_home_url
  • get_site_url
  • edit_tag_link
  • bloginfo
  • edit_comment_link
loopのなかで

Function Reference/the modified date « WordPress Codex
$before、$after、$echo パラメータが追加

update_blog_details() を導入

/**
 * Update the details for a blog. Updates the blogs table for a given blog id.
 *
 * @since 3.0.0
 *
 * @param int $blog_id Blog ID
 * @param array $details Array of details keyed by blogs table field names.
 * @return bool True if update succeeds, false otherwise.
 */
function update_blog_details( $blog_id, $details = array() ) {
	global $wpdb;

	if ( empty($details) )
		return false;

	if ( is_object($details) )
		$details = get_object_vars($details);

	$current_details = get_blog_details($blog_id, false);
	if ( empty($current_details) )
		return false;

	$current_details = get_object_vars($current_details);

	$details = array_merge($current_details, $details);
	$details['last_updated'] = current_time('mysql', true);

	$update_details = array();
	$fields = array( 'site_id', 'domain', 'path', 'registered', 'last_updated', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id');
	foreach ( array_intersect( array_keys( $details ), $fields ) as $field )
		$update_details[$field] = $details[$field];

	$wpdb->update( $wpdb->blogs, $update_details, array('blog_id' => $blog_id) );

	// If spam status changed, issue actions.
	if ( $details[ 'spam' ] != $current_details[ 'spam' ] ) {
		if ( $details[ 'spam' ] == 1 )
			do_action( "make_spam_blog", $blog_id );
		else
			do_action( "make_ham_blog", $blog_id );
	}

	if ( isset($details[ 'public' ]) )
		update_blog_option( $blog_id, 'blog_public', $details[ 'public' ], false );

	refresh_blog_details($blog_id);

	return true;
}
<?php
$post = $wp_query->post;
if ( in_category( '9' ) ) {
    include( TEMPLATEPATH . '/single2.php' );
} else {
    include( TEMPLATEPATH . '/single1.php' );
}
?>

Class Reference/WP Query « WordPress Codex
テンプレートタグ/query posts - WordPress Codex 日本語版



DISALLOW_FILE_MODS

コア、テーマ、プラグインファイルの変更する動作をすべて無効化する





DISALLOW_FILE_EDIT

テーマおよびプラグインエディターの有効化・無効化フラッグとなる

wp-config.php

 define('DISALLOW_FILE_EDIT',true);

f:id:tenman:20100805140856g:image
矢印で示した編集項目が使えなくなる


WP_DEFAULT_THEME

新サイトをインストールする際のデフォルトテーマを設定する

3.01では、twentyten がセットされていました。



comment_form() を追加 (#10910)

テンプレート内で完全なコメントフォームを出力する
テンプレートタグ/comment form - WordPress Codex 日本語版





デフォルト投稿が default_content、default_title、default_excerpt フィルターを通過するように変更。

これで、新規投稿時にだけ、値をセットすることができる。

/**
 * 新規ポストを登校する場合のデフォルト値のセット
 * default_content(記事本文)
 * default_excerpt(デフォルトの記事抜粋)
 * default_title(記事タイトル)
 *
 *
 *
 */


add_filter( 'default_title', 'title_filter' );

function title_filter($text){
	return $text.date("d h:i:s");
}

STYLE_DEBUG 定数を削除。SCRIPT_DEBUG をスクリプト・CSS 両方に対応


圧縮ファイルを読み込むか、通常のファイルを読み込むか選べる模様


???
デフォルトで圧縮 (minified) バージョンのスクリプトを読み込み、define('SCRIPT_DEBUG', true); によって開発バージョンを使うことができるようにする

これにより、wp-includes/js および wp-admin/js ディレクトリの scriptname.dev.js ファイルを編集できます。


<?php
/**
 * WordPress scripts and styles default loader.
 *
 * Most of the functionality that existed here was moved to
 * {@link http://backpress.automattic.com/ BackPress}. WordPress themes and
 * plugins will only be concerned about the filters and actions set in this
 * file.
 *
 * Several constants are used to manage the loading, concatenating and compression of scripts and CSS:
 * define('SCRIPT_DEBUG', true); loads the development (non-minified) versions of all scripts and CSS, and disables compression and concatenation,
 * define('CONCATENATE_SCRIPTS', false); disables compression and concatenation of scripts and CSS,
 * define('COMPRESS_SCRIPTS', false); disables compression of scripts,
 * define('COMPRESS_CSS', false); disables compression of CSS,
 * define('ENFORCE_GZIP', true); forces gzip for compression (default is deflate).
 *
 * The globals $concatenate_scripts, $compress_scripts and $compress_css can be set by plugins
 * to temporarily override the above settings. Also a compression test is run once and the result is saved
 * as option 'can_compress_scripts' (0/1). The test will run again if that option is deleted.
 *
 * @package WordPress
 */

コーディング基準の修正:

変数にキャメルケースを使用しない。変数にはすべて小文字を使用



SUBDOMAIN_INSTALL 定数を導入

page.php を post.php に統合





WP_ALLOW_REPAIR

バージョン 2.9 から自動データベース最適化対応が含まれるようになりました

EMPTY_TRASH_DAYS

define('EMPTY_TRASH_DAYS', 30 ); // 30日
バージョン 2.9 からゴミ箱に入っている期間の設定

WP_MEMORY_LIMIT

バージョン 2.5から、WPHP が消費するメモリの最大値を設定


定数一覧の表示

if(is_admin()){
echo "<pre>";
print_r(@get_defined_constants());
echo "</pre>";	
}

デバッグ


バージョン2.5以降、WP_DEBUG を true にした場合、エラー出力レベル も E_ALL に上げられ、非推奨関数やファイルを使った時に警告を出力します。false の場合は、WordPress はエラー出力レベルを E_ALL ^ E_NOTICE ^ E_USER_NOTICE に設定します。


define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
//seved wp-content/debug.log
define('WP_DEBUG_DISPLAY',true);
define('SCRIPT_DEBUG', true);
define( 'SAVEQUERIES', true );

http://www.andrewnacin.com/2010/04/23/5-ways-to-debug-wordpress/
$queries
You may save all of the queries run on the database and their stop times by setting the SAVEQUERIES constant to TRUE (this constant defaults to FALSE). If SAVEQUERIES is TRUE, your queries will be stored in this variable as an array.

@ini_set('log_errors','On');
@ini_set('display_errors','Off');
@ini_set('error_log','/home/example.com/logs/php_error.log');

wp-config.php の編集 - WordPress Codex 日本語版

add_action( 'all', create_function( '', 'var_dump( current_filter() );' ) );

and ‘shutdown’ hooks

デバッグ定数を試すと、WP_DEBUGはコアファイルのエラーを表示するが、テーマファイルなどのエラーは発見できないことが多い。
この倍は、エラーログの書き出しを行うと、テーマファイル内のパースエラーなどをチェック出来ることが確認できた。


WP_DEBUGだけでは、エラーが表示されないというブーイングが結構あると思うが、併用が肝心と思う。



MagpieRSS を非推奨化し、代わりに Simplepie を使用   Snoopy を非推奨化

WordPress Note - SimplePie : RSSやAtomフィードをパースするクラスライブラリ

備忘

optionsテーブルを表示するショートカットアドレス

http://www.example.com/wp3/sub/wp-admin/options.php
TOP