WordPress: Pluginの修正WordPress: Topics for plugin modification

WordPress Mobile Pack Issue

WordPress Mobile pack プラグインをインストールした際、次のようなエラーメッセージが表示されることがあります。これはPHP5以降ではis_executableがPHPセーフモードでは正しい値を返さないことから来ている問題のようです。

Critical WordPress Mobile Pack Plugin Issue Not able to cache images to /var/www/htdocs/blog/wp-content/plugins/wordpress-mobile-pack/plugins/wpmp_transcoder/c. That directory is not executable. Please ensure that the web server has write- and execute-access to it. Not able to install theme files to /var/www/htdocs/blog/wp-content/themes. That directory is not executable. Please ensure that the web server has write- and execute-access to it.

対処法としては、wordpress-mobile- pack.php内を、次のように変更します。

is_executable( $cache_dir ) → @file_exists( $cache_dir . '/.' )
is_executable( $theme_dir ) → @file_exists( $theme_dir . '/.' )
is_executable( $destination_dir ) → @file_exists( $destination_dir . '/.' )

その後プラグインを無効化→有効化します。場合によっては、/wp-content/plugins/wordpress-mobile-pack /themes/以下にあるテーマフォルダを、全て/wp-content/themes/にコピーする必要があるかもしれません。

Specific CSS/JS プラグイン(v1.0)をカスタム投稿タイプでも使う

個別の「ページ」と「ポスト(投稿)」にJavascript, CSSを追加するプラグインで有名なものに、Specific CSS/JS for post and pagesというものがあります。このVer. 1.0はカスタム投稿タイプには対応していませんが、次のように変更を加えることで、カスタム投稿タイプでも使えるようになります。 tt-specific-cssjs.phpは3箇所を変えます。 1.オリジナル:

if( ($post->post_type == 'post' && get_option('ttscj_enable_on_posts') != '')
 || ($post->post_type == 'page' && get_option('ttscj_enable_on_pages') != '') )

1.変更後:

if( ($post->post_type == 'post' && get_option('ttscj_enable_on_posts') != '') 
 || ($post->post_type == 'page' && get_option('ttscj_enable_on_pages') != '') 
 || ($post->post_type == 'cpst' && get_option('ttscj_enable_on_custom') != '')) {

2.オリジナル:

if( (get_option('ttscj_enable_on_posts') != '' && $post_type == 'post')
 || (get_option('ttscj_enable_on_pages') != '' &&  $post_type == 'page') ) {

2.変更後:

if( (get_option('ttscj_enable_on_posts') != '' && $post_type == 'post')
 || (get_option('ttscj_enable_on_pages') != '' &&  $post_type == 'page')
 || (get_option('ttscj_enable_on_custom') != '' &&  $post_type == 'cpst') ) {

どちらも’cpst’には、カスタム投稿タイプの名前を入れます。 カスタム投稿タイプが複数ある場合は同様に追加します。 3.オリジナル:

// Check permissions
if ( $_POST['post_type'] == 'page' ) {
	if ( !current_user_can( 'edit_page', $post_id ) )
	  return $post_id;
} else {
	if ( !current_user_can( 'edit_post', $post_id ) )
	  return $post_id;
}

3.変更後:

// Check permissions
if ( $_POST['post_type'] == 'page' ) {
	if ( !current_user_can( 'edit_page', $post_id ) )
	  return $post_id;
} elseif( $_POST['post_type'] == 'post' ) {
	if ( !current_user_can( 'edit_post', $post_id ) )
	  return $post_id;
}else{
	if ( !current_user_can( 'edit_post', $post_id ) )
	  return $post_id;
}

投稿の編集権限で、カスタム投稿タイプの編集権限を代用しています。 includes/settings.phpは1箇所を変えます。 1.オリジナル:

array(	"name" => __('Specific CSS/JS on pages', 'ttscj'),
		"desc" => __('Enable specific CSS/JS on pages', 'ttscj'),
		"id" => "ttscj_enable_on_pages",
		"default" => true,
		"type" => "checkbox"),

1.変更後:

array(	"name" => __('Specific CSS/JS on pages', 'ttscj'),
		"desc" => __('Enable specific CSS/JS on pages', 'ttscj'),
		"id" => "ttscj_enable_on_pages",
		"default" => true,
		"type" => "checkbox"),

array(	"name" => __('Specific CSS/JS on custom post type', 'ttscj'),
		"desc" => __('Enable specific CSS/JS on custom post type', 'ttscj'),
		"id" => "ttscj_enable_on_custom",
		"default" => true,
		"type" => "checkbox"),

tinyMCEでカスタム属性が削除されてしまう場合の対処

TinyCMEは、登録されていないタグの属性は削除するという仕様になっています。例えば、HTML5の独自データ属性:data-*も、デフォルトでは登録されていないので、TinyCMEのモードをHTML→ビジュアル→HTMLとすると、これらのデータ属性は勝手に削除されてしまいます。また、WP SyntaxHighlighterプラグインを使用している場合も、preタグにclass=”brush:php”などのカスタム属性を記載。これを回避するには、以下のようにフックをかけます。 例:TinyCMEで、spanタグにdata-time属性を登録する場合:

add_filter('tiny_mce_before_init', create_function( '$init_array',
     '$init_array["extended_valid_elements"] = "span[data-time|align<center?justify?left?right|class|dir
なお、全てのXHTML仕様の属性は次のサイトに網羅されていますので、こちらから必要なものを選択して登録すると良いでしょう。
<a href="http://sie-cs.com/inc/tinymce/docs/option_valid_elements.html">http://sie-cs.com/inc/tinymce/docs/option_valid_elements.html</a>

BuddyPressを使用している際に、登録画面をデフォルトに戻す方法

BuddyPressを入れると、登録画面が特別なものに変更されてしまいます。Wordpressデフォルトの登録画面を使いたいときは、現在使用中のテーマフォルダにあるregistrationフォルダの名前を変更すればOKです。

BuddyPressの要修正部分

  • global.jsのjQuery Easing Pluginの行を、jQuery(document).ready(function() {…..});にて括る

CubePointの要修正部分

これもすぐに直されるでしょうけれども。 CubePoint ver. 3.1 で”wp_register_script was called incorrectly.”というエラーが出る。これについてはcp_admin.phpで次のように修正すればオッケイ。

add_action('admin_enqueue_scripts', 'cp_datatables_register' );
function cp_datatables_register() {
	wp_register_script('datatables',
	       CP_PATH . 'assets/datatables/js/jquery.dataTables.min.js',
	       array('jquery'),
	       '1.7.4' );
	wp_register_style('datatables', CP_PATH . 'assets/datatables/css/style.css');

	/** Register autocomplete script and stylesheet for admin pages */
	wp_register_script('autocomplete',
	       CP_PATH . 'assets/autocomplete/jquery.autocomplete.js',
	       array('jquery'),
	       '3.2.2' );
	wp_register_style('autocomplete', CP_PATH . 'assets/autocomplete/jquery.autocomplete.css');
}

datatablesとautocompleteのwp_register_style, wp_register_scriptは少し離れた場所にあります。これらを上のようにadmin_enqueue_scriptsフックで呼び出すように変更すればOK。

cubepoints-buddypress-integrationの要修正部分

これもすぐに修正がかけられるでしょうけれども。 cubepoints-buddypress-integration ver. 0.1.9.8 で言語ファイルの読み込みができないことについて。 bp-cubepoint-core.phpで、次の部分を修正する。

load_textdomain( 'bp-cubepoint', dirname( __FILE__ ) . '/languages/bp-cubepoint-' . get_locale() . '.mo' );

load_textdomain( 'cp_buddypress', dirname( __FILE__ ) . '/languages/bp-cubepoint-' . get_locale() . '.mo' );

これはすぐに修正がかけられるでしょう。

theme-my-loginの日本語修正

承認が登録されたことを知らせるメールのタイトル: “[%s] Registration Approved”の日本語訳が、「[%s]登録を承認だ」なんて元気な表現になっていました。POファイルを編集しましょう。気づきにくいところです。

buddypressカスタム投稿タイプへのcommentをactivity streamに出力する方法

デフォルトではカスタム投稿タイプへのコメントはactivitystreamに出力されません。たとえばカスタム投稿タイプtype1, type2, type3へのコメントもactivity streamに反映したい場合は、次のようにフィルタをかけます。

add_filter( 'bp_blogs_record_comment_post_types', 'my_filter' );
function my_filter() {
	$post_types = func_get_args();
	array_push( $post_types, 'type1', 'type2', 'type3' );
	return $post_types;
}

(2012.06.04)

buddypress-activity-plusのアイコンをトップ画面にも表示する方法

buddypress-activity-plusは、フックではなくjavascriptのDOM操作によってアイコンを表示しています。js/bpfb_interface.jsの以下の部分。

function init () {
    $form = $("#whats-new-form");
    $text = $form.find('textarea[name="whats-new"]');
    $textContainer = $form.find('#whats-new-textarea');
    createMarkup();

  つまり、whats-new-formのwhats-new-textareaがあればその下にアイコンを追加しているわけです。任意のページでアイコンを表示するには、このjavascriptファイルの読み込みが行われる必要があり、 buddypress-activity-plus/lib/class_bpfb_binder.phpの以下を編集する必要があります。

function _add_js_css_hooks () {
  global $bp;

  if (
      // Load the scripts on Activity pages
      (defined('BP_ACTIVITY_SLUG') && bp_is_activity_component())
      ||
      // Load the scripts when Activity page is the Home page
      (defined('BP_ACTIVITY_SLUG') && 'page' == get_option('show_on_front') && is_front_page() && BP_ACTIVITY_SLUG == get_option('page_on_front'))
      ||
      // Load the script on Group home page
      (defined('BP_GROUPS_SLUG') && bp_is_groups_component() && 'home' == $bp->current_action)
  ) {
      // Step1: Load JS/CSS requirements
      add_action('wp_print_scripts', array($this, 'js_plugin_url'));
      add_action('wp_print_scripts', array($this, 'js_load_scripts'));
      add_action('wp_print_styles', array($this, 'css_load_styles'));

      do_action('bpfb_add_cssjs_hooks');
  }
}

このif文中に、新しい条件をORで入れればOK。たとえばindex.phpのトップページで表示するには

        if (
  // Load the scripts on Activity pages
  (defined('BP_ACTIVITY_SLUG') && bp_is_activity_component())
  ||
  // Load the scripts when Activity page is the Home page
  (defined('BP_ACTIVITY_SLUG') && 'page' == get_option('show_on_front') && is_front_page() && BP_ACTIVITY_SLUG == get_option('page_on_front'))
  ||
  // Load the script on Group home page
  (defined('BP_GROUPS_SLUG') && bp_is_groups_component() && 'home' == $bp->current_action)
  ||
  in_array( $GLOBALS['pagenow'], array('index.php') )
) {

とします。

BuddyPressダイジェストメールの文字化け

BuddyPress Group Email Subscriptionの日刊ダイジェスト、週刊ダイジェストで、WP Multibyte Patchを使っているとメール本文が文字化けすることがあります。その場合、WP Multibyte Patchの設定ファイルwpmp-config.php(ない場合はwpmp-config-sample-ja.phpをリネームして作成)で設定を見直しましょう。

$wpmp_conf['mail_mode'] = 'auto';

WordPress Mobile Pack Issue

If you have errors like following:

Critical WordPress Mobile Pack Issue Not able to cache images to /var/www/htdocs/blog/wp-content/plugins/wordpress-mobile-pack/plugins/wpmp_transcoder/c. That directory is not executable. Please ensure that the web server has write- and execute-access to it. Not able to install theme files to /var/www/htdocs/blog/wp-content/themes. That directory is not executable. Please ensure that the web server has write- and execute-access to it.

you simply need to change the code in wordpress-mobile-pack.php like:

is_executable($cache_dir) → @file_exists($cache_dir . '/.')
is_executable($theme_dir) → @file_exists($theme_dir . '/.')
is_executable($destination_dir) → @file_exists($destination_dir . '/.')

Maybe you have to copy files under /wp-content/plugins/wordpress-mobile-pack/themes/ and paste them into /wp-content/themes/ folder. then deactivate and re-activate the plugin. This problem may be caused by is_executable() command, which seems not work properly when safe mode is ON. If this info helps you, feel free to link this site to your own!:)