WordPressで作ったサイトで使っているPHPのバージョンを7.4.33→8.0.25に変更したところ、
functions.phpに記述しているコードに対して、以下のエラーが表示されています。
バージョンを元に戻すとエラーメッセージが表示されなくなるので、バージョンの違いによるエラーなのは明白です。
Warning: Undefined variable $tag in /[ファイルのディレクトリ]/functions.php on line 55 Warning: Undefined variable $tag in /[ファイルのディレクトリ]/functions.php on line 33
ソースコードは以下のとおりです。
PHP
1//timelineショートコードコンテンツ内に余計な改行や文字列が入らないように除外 2if ( !function_exists( 'remove_wrap_shortcode_wpautop' ) ): 3function remove_wrap_shortcode_wpautop($shortcode, $content) { 4 //tiショートコードのみを抽出 5 $pattern = '/\['.$shortcode.'.*?\].*?\[\/'.$shortcode.'\]/is'; 6 if (preg_match_all($pattern, $content, $m)) { 7 $all = null; 8 foreach ($m[0] as $code) { 9 $all .= $code; 10 } 11 return $all; 12 } 13} 14endif; 15//タイムラインショートコード 16add_shortcode('ptimeline', 'tl_shortcode'); 17if ( !function_exists( 'tl_shortcode' ) ): 18function tl_shortcode( $atts, $content = null ) { 19extract( shortcode_atts( array( 20 'color' => null, 21 'marker' => null, 22 'icon' => null, 23 ), $atts ) ); 24 $content = remove_wrap_shortcode_wpautop('ti', $content); 25 $content = do_shortcode( shortcode_unautop( $content ) ); 26 if ( $icon ): 27 $tag .= '<style type="text/css">.ptimeline-wrap .'.$icon.' .ptimeline-item .ptimeline-marker:before{ content:"\\'.$icon.'";}</style>'; 28 endif; 29 $tag .= '<div class="ptimeline-wrap">'. 30 '<ul class="ptimeline '.$color.' '.$marker.' '.$icon.'">'. 31 $content. 32 '</ul>'. 33 '</div>'; 34 return apply_filters('timeline_tag', $tag); 35} 36endif; 37// タイムラインショートコード中身 38add_shortcode('ti', 'tl_item_shortcode'); 39if ( !function_exists( 'tl_item_shortcode' ) ): 40function tl_item_shortcode( $atts, $content = null ) { 41 extract( shortcode_atts( array( 42 'title' => null, 43 'label' => null, 44 'icon_item' => null, 45 ), $atts ) ); 46 $content = do_shortcode( shortcode_unautop( $content ) ); 47 if ($icon_item): 48 $tag .= '<style type="text/css">.ptimeline-wrap .ptimeline-item .'.$icon_item.':before{ content:"\\'.$icon_item.'" !important;}</style>'; 49 endif; 50 $tag .= '<li class="ptimeline-item">'. 51 '<div class="ptimeline-label">'.$label.'</div>'. 52 '<div class="ptimeline-title">'.$title.'</div>'. 53 '<div class="ptimeline-main">'.$content.'</div>'. 54 '<div class="ptimeline-marker '.$icon_item.'"></div>'. 55 '</li>'; 56 return apply_filters('timeline_item_tag', $tag); 57} 58endif;
なお、上記のコード自体は以下の記事などで紹介されているものをそのまま使用しています。
https://aofireawayblog.com/wordpress-timeline-howto/
エラーメッセージのとおりだと、単純に変数が定義されてないということですが、コード上は定義しているはずです。
PHPのバージョン変更に伴う関数などの仕様変更が原因なのだと思いますが、具体的にどうしたらいいか分かりません。
私自身、ゴリゴリのエンジニアではないので、お知恵のある方の力を貸していただけますと幸いです。
回答1件
あなたの回答
tips
プレビュー