Skip to content

Instantly share code, notes, and snippets.

@tenman
Last active December 17, 2015 03:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tenman/5545822 to your computer and use it in GitHub Desktop.
Save tenman/5545822 to your computer and use it in GitHub Desktop.
Quick Fix Raindrops Theme for ver 1.113
/**
* Management of uninstall and install.
*
*
*
* ver 1.114 Theme data automatic change is supported at the time of site change.
*/
if ( ! function_exists( "raindrops_install_navigation" ) ) {
function raindrops_install_navigation( ) {
$install = get_option( 'raindrops_theme_settings' );
$upload_dir = wp_upload_dir();
if ( $install == false or !array_key_exists( 'install', $install ) ) {
$install['current_stylesheet_dir_url'] = get_stylesheet_directory_uri();
$install['current_upload_base_url'] = $upload_dir['baseurl'];
//add_action( 'admin_notices', create_function(null, 'echo raindrops_first_only_msg( 1 );' ) );
$install['install'] = true;
update_option( 'raindrops_theme_settings', $install );
} else {
if( isset( $install['current_stylesheet_dir_url'] ) and get_stylesheet_directory_uri() !== $install['current_stylesheet_dir_url'] ){
$install['_raindrops_indv_css'] = str_replace( $install['current_stylesheet_dir_url'],
get_stylesheet_directory_uri(),
$install['_raindrops_indv_css']
);
$install['old_stylesheet_dir_url'] = $install['current_stylesheet_dir_url'];
$install['current_stylesheet_dir_url'] = get_stylesheet_directory_uri();
update_option( 'raindrops_theme_settings', $install );
}elseif( ! isset( $install['current_stylesheet_dir_url'] ) ){
$install['current_stylesheet_dir_url'] = get_stylesheet_directory_uri();
update_option( 'raindrops_theme_settings', $install );
}
if( isset( $install['current_upload_base_url'] ) and $upload_dir !== $install['current_upload_base_url'] ){
$install['_raindrops_indv_css'] = str_replace( $install['current_upload_base_url'],
$upload_dir['baseurl'],
$install['_raindrops_indv_css']
);
$install['old_upload_base_url'] = $install['current_upload_base_url'];
$install['current_upload_base_url'] = $upload_dir['baseurl'];
update_option( 'raindrops_theme_settings', $install );
}elseif( ! isset( $install['current_upload_base_url'] ) ){
$install['current_upload_base_url'] = $upload_dir['baseurl'];
update_option( 'raindrops_theme_settings', $install );
}
add_action( 'switch_theme', create_function(null, 'delete_option( "raindrops_theme_settings" );' ) );
}
}
}
@tenman
Copy link
Author

tenman commented May 9, 2013

問題点

WordPress Theme Raindrops ver 1.113 を利用して、WEBサイトの変更を行った場合、移転前のテーマオプションの設定が引き継がれない。

サイトの移転に関して、一般的に行われるURL等の文字列置換を行った場合のRaindropsの挙動

テーマデータは、シリアライズして保存されているため、URL等文字列置換を行った場合、データが壊れ、結果としてデフォルトデザインでインストールされる事があります

対応

ユーザーが、このような問題を考慮して、適切な対応をとる事は、困難で、Raindrops で適切な処理が必要と判断します。

Raindropsのインストールの時点で、インストールされたサイトのテーマディレクトリURLとアップロードディレクトリのURLをテーマで使用するデータベーステーブルに格納し、サイトの移転を行った場合に、保存されているサイトのテーマディレクトリURLと、比較して、異なる場合は、テーマが自動的に、スタイルシート内のURLを書き換えるように、変更しました。

このコードの使い方

functions.php の、raindrops_install_navigation関数を上記のものと置き換えて、Raindropsを再インストールしてください。

なを、この変更は、Raindropsの次回のアップデートに含まれる予定です。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment