WP最新版対応して欲しいプラグインの非推奨対応など

昔から重宝して使い続けているプラグインでも、更新されなくなったり、いつの間にか公式プラグインから消えていたりして、ブルーになるこの頃。めげずに、とりあえずソースに手を加えてしのぎます!

非推奨メッセージは、
・本体バージョンアップによって、非推奨となるWordPress関数を使用している
・サーバーのPHPバージョンアップにより、非推奨となるものを記述している
といった場合に、PHPエラーログへ出力されます。

プラグインSubscribe2

subscribe2\admin\your_subscriptions.php
line 12あたり

phpglobal $user_ID, $s2nonce;

if ( isset($_GET['email']) ) {
global $wpdb;
$user_ID = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->users WHERE user_email = %s", $_GET['email']));
} else {
// get_currentuserinfo();/*変更前*/
$user_ID = get_current_user_id();/*変更後*/
}

フロントエンドで使用している場合は、他にもdeprecatedがある様子。

プラグインWordPress HTTPS

SSLが安価になる前はCloudFlareとセットでよく使っていたプラグイン。

wordpress-https/lib/WordPressHTTPS/Module/Core.php
line 280あたり

phppublic function secure_login( $force_ssl, $post_id = 0, $url = '' ) {
if ( $url != '' && $this->getPlugin()->isUrlLocal($url) ) {
// if ( force_ssl_login() && preg_match('/wp-login\.php$/', $url) === 1 ) {/*変更前*/
if ( force_ssl_admin() && preg_match('/wp-login\.php$/', $url) === 1 ) {/*変更後*/
$force_ssl = true;
}
}
return $force_ssl;
}

プラグインWordPress FAQ Manager

FAQが多い時や、ユーザーさん自身で編集するときに重宝します。

1. preg_replace の /e 修飾子

php5.5で非推奨、php7でサポートしなくなりました。
かわりに preg_replace_callback() を使いましょう。のPHP Warning がでます。

FAQ Topics や FAQ Tags 別に表示している場合、php7にupすると全件表示されてしまいますのでご注意を!

wordpress-faq-manager/faq-manager.php 637,638行目あたり

faq-manager.php// clean up text(636行目)

/* 変更前(637-638行目) */
// $faq_topic = preg_replace('~&#x0*([0-9a-f]+);~i', 'chr(hexdec("\\1"))', $faq_topic);
// $faq_tag = preg_replace('~&#x0*([0-9a-f]+);~i', 'chr(hexdec("\\1"))', $faq_tag);

/* 変更後(637-638行目) */
$faq_topic = preg_replace_callback('~&#x0*([0-9a-f]+);~i', function($m){return chr(hexdec($m[1]));}, $faq_topic);
$faq_tag = preg_replace_callback('~&#x0*([0-9a-f]+);~i', function($m){return chr(hexdec($m[1]));}, $faq_tag);

2. コンストラクタ

wordpress-faq-manager/faq-widgets.php
5つあるclassのコンストラクタの部分

faq-widgets.php// function search_FAQ_Widget() {/*変更前*/
function __construct() {/*変更後*/
$widget_ops = array( 'classname' => 'faq-search-widget widget_search', 'description' => 'Puts a search box for just FAQs' );
// $this->WP_Widget( 'faq_search', 'FAQ Widget - Search', $widget_ops );/*変更前*/
parent::__construct( 'faq_search', 'FAQ Widget - Search', $widget_ops );/*変更後*/
}
faq-widgets.phpclass random_FAQ_Widget extends WP_Widget {
// function random_FAQ_Widget() {/*変更前*/
function __construct() {/*変更後*/
$widget_ops = array( 'classname' => 'faq-random-widget', 'description' => 'Lists a single random FAQ on the sidebar' );
// $this->WP_Widget( 'faq_random', 'FAQ Widget - Random', $widget_ops );/*変更前*/
parent::__construct( 'faq_random', 'FAQ Widget - Random', $widget_ops );/*変更後*/
}
faq-widgets.phpclass recent_FAQ_Widget extends WP_Widget {
// function recent_FAQ_Widget() {/*変更前*/
function __construct() {/*変更後*/
$widget_ops = array( 'classname' => 'recent-questions-widget', 'description' => 'List recent questions' );
// $this->WP_Widget( 'recent_questions', 'FAQ Widget - Recent', $widget_ops );/*変更前*/
parent::__construct( 'recent_questions', 'FAQ Widget - Recent', $widget_ops );/*変更後*/
}
faq-widgets.phpclass topics_FAQ_Widget extends WP_Widget {
// function topics_FAQ_Widget() {/*変更前*/
function __construct() {/*変更後*/
$widget_ops = array( 'classname' => 'recent-faqtax-widget', 'description' => 'List FAQ topics or tags' );
// $this->WP_Widget( 'recent_faqtax', 'FAQ Widget - Taxonomies', $widget_ops );/*変更前*/
parent::__construct( 'recent_faqtax', 'FAQ Widget - Taxonomies', $widget_ops );/*変更後*/
}
faq-widgets.php// function cloud_FAQ_Widget() {/*変更前*/
function __construct() {/*変更後*/
$widget_ops = array( 'classname' => 'faq-cloud-widget', 'description' => 'A tag cloud of FAQ topics and tags' );
// $this->WP_Widget( 'faq_cloud', 'FAQ Widget - Cloud', $widget_ops );/*変更前*/
parent::__construct( 'faq_cloud', 'FAQ Widget - Cloud', $widget_ops );/*変更後*/
}
faq-widgets.php// (405-409行目)
/*変更前*/
add_action( 'widgets_init', create_function( '', "register_widget('search_FAQ_Widget');" ) );
add_action( 'widgets_init', create_function( '', "register_widget('random_FAQ_Widget');" ) );
add_action( 'widgets_init', create_function( '', "register_widget('recent_FAQ_Widget');" ) );
add_action( 'widgets_init', create_function( '', "register_widget('topics_FAQ_Widget');" ) );
add_action( 'widgets_init', create_function( '', "register_widget('cloud_FAQ_Widget');" ) );

/*変更後*/
add_action( 'widgets_init', function(){
register_widget( 'search_FAQ_Widget' );
register_widget( 'random_FAQ_Widget' );
register_widget( 'recent_FAQ_Widget' );
register_widget( 'topics_FAQ_Widget' );
register_widget( 'cloud_FAQ_Widget' );
} );

ウィジェット作成しているテーマやプラグインでphp7にupするなどでdeprecatedがでるのは、この大抵パターンでいけます。
次のCrazy Boneも。

プラグインCrazy Bone

バージョン0.6.0

1. コンストラクタ

crazy-bone/includes/ip2c/ip2c.php
class ip2country のコンストラクタの部分...20行目あたり

php// function ip2country($bin_file = './ip-to-country.bin', $caching = false) /*変更前*/
function __construct($bin_file = './ip-to-country.bin', $caching = false) /*変更後*/
{

2. get_userdatabylogin

非推奨get_userdatabyloginをget_user_byに変更します。

crazy-bone/plugin.php...240 ~ 250行目public function cookie_expired_log($cookie_elements) {
/*@@@ deprecated @@@
if ( function_exists('get_userdatabylogin') ) {
$user = get_userdatabylogin($cookie_elements['username']);
$this->logging($user->ID, 'cookie_expired');
}
*/
$user = get_user_by( 'login', $cookie_elements['username'] );
$this->logging( $user->ID, 'cookie_expired' );
}

public function cookie_bad_hash_log($cookie_elements) {
/*@@@ deprecated @@@
if ( function_exists('get_userdatabylogin') ) {
$user = get_userdatabylogin($cookie_elements['username']);
$this->logging($user->ID, 'cookie_bad_hash');
}
*/
$user = get_user_by( 'login',$cookie_elements['username'] );
$this->logging( $user->ID, 'cookie_bad_hash' );
}

ちなみに、ログイン有効期間はフィルターフックできます。テストにでも!、

code//@TEST@ 5min
add_filter('auth_cookie_expiration', function( $expiration, $user_id, $remember ){
$expiration = 300; //60x5
return $expiration;
} , 10, 3 );

また思い出し次第、追加します!

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です