サポート » その他 » strpos()非推奨について

  • 解決済 ysaito

    (@ysaito)


    PHP5.6で動いていたWordPressをPHP7.4の環境へ引っ越した際に、

    strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior

    という非推奨のメッセージが出ていたので、下記URLを参考にして
    https://detail.chiebukuro.yahoo.co.jp/qa/question_detail/q11213191486

    該当の場所wp-content/plugins/admin-menu-editor/includes/shadow_plugin_framework.php:310


    return (strpos( realpath($filename), realpath(WPMU_PLUGIN_DIR) ) !== false);

    return (strpos( realpath($filename), strval(realpath(WPMU_PLUGIN_DIR)) ) !== false);

    としてstrval()で文字列に変換してみたのですが、変換後、

    strpos(): Empty needle
    という警告がでてしまいました。

    恐らくrealpath(WPMU_PLUGIN_DIR)が0でstrvalで文字列化すると空白になったのでEmptyのエラーが出たと思われるのですが、空白部分をnullやfalseとなればエラーは回避できると、下記URLで見ました。
    https://akamist.com/blog/archives/426

    どう変更すればよいのでしょうか。

    該当箇所の一連のコードは下記です。

    function is_in_wpmu_plugin_dir( $filename = ” ){
    if ( !defined(‘WPMU_PLUGIN_DIR’) ) return false;

    if ( empty($filename) ){
    $filename = $this->plugin_file;
    }

    return (strpos( realpath($filename), strval(realpath(WPMU_PLUGIN_DIR)) ) !== false);
    }

1件の返信を表示中 - 1 - 1件目 (全1件中)
  • トピック投稿者 ysaito

    (@ysaito)

    すみません。プラグインをアップデートしたら解決しました。お騒がせしました。

1件の返信を表示中 - 1 - 1件目 (全1件中)
  • トピック「strpos()非推奨について」には新たに返信することはできません。