2016-07-21 7 views
0

私のプラグインに問題があります。Wordpressのクッキー法情報プラグインのエラー

ログファイルは言った:

PHP警告:にstripslashes()/に指定された配列/ MNT/web008/C1/57250724分の24/htdocsに/ WordPress_01/WP-コンテンツ、パラメータ1が文字列であることを期待プラグイン/ cookie-law-info/php/shortcodes.php on line 125

与えられた文字列があると思われますが、文字列が必要ですか?私はこれをどのように修正できるかわかりません。

/** Returns HTML for a standard (green, medium sized) 'Accept' button */ 
function cookielawinfo_shortcode_accept_button($atts) { 
    extract(shortcode_atts(array(
     'colour' => 'green' 
    ), $atts)); 

    // Fixing button translate text bug 
    // 18/05/2015 by RA 
    $defaults = array(
     'button_1_text' => '' 
    ); 
    $settings = wp_parse_args(cookielawinfo_get_admin_settings(), $defaults); 

    /*This is line 125:*/ return '<a href="#" id="cookie_action_close_header" class="medium cli-plugin-button">' . stripslashes($settings) . '</a>'; 
} 
+0

$設定は配列なので、stripslashesはエラーとなるためです。 –

答えて

0

まあ、エラー自体はかなり自明です。

関数stripslashesは、そのパラメータが文字列であると想定しています。 Wordpressのドキュメントを簡単に見てはwp_parse_argsの戻り値が$settings変数が配列でない文字列であるため、stripslashesに引数として渡すことはあなたのエラーが発生するという意味、配列であることを示唆しています。

stripslashesはアレイ上で使用できますが、もう少し作業が必要です。 PHPのドキュメントにある例を示します。

<?php 
function stripslashes_deep($value) { 
    $value = is_array($value) ? 
       array_map('stripslashes_deep', $value) : 
       stripslashes($value); 

    return $value; 
} 

// Example 
$array = array("f\\'oo", "b\\'ar", array("fo\\'o", "b\\'ar")); 
$array = stripslashes_deep($array); 

// Output 
print_r($array); 
?> 

https://developer.wordpress.org/reference/functions/wp_parse_args/ http://php.net/manual/en/function.stripslashes.php

EDIT:それはおそらくstripslashes_deepが配列を返すことは注目に値します。これが目的の出力でない場合は、implode関数を使用してstripslashes_deep関数をラップして文字列に変換します。

implode(stripslashes_deep($settings)) 
関連する問題