php - 更新后的 Wordpress 'Illegal string offset'

标签 php html wordpress debugging wordpress-theming

我的新客户有一个很长时间没有更新的网站。现在 PHP 版本、wordpress 版本和插件都是最新的,但是 Portifolio 项目现在返回此错误:

截图:

enter image description here

Warning: Illegal string offset 'alt' in /home/elite856/public_html/wp-content/themes/eliteled/functions.php on line 679

Warning: Illegal string offset 'url' in /home/elite856/public_html/wp-content/themes/eliteled/functions.php on line 679

这是第 679 行:

'<img src="'. $ob_img['url'] .'" class="capa" alt="'. $ob_img['alt'] .'" />'.

这是整个函数:

$portfolio = new WP_Query( $args );

if( $portfolio->have_posts() ){
    while ( $portfolio->have_posts() ) { $portfolio->the_post();

        $ob_img     = get_field( 'imagem_de_capa' );
        $allcats    = get_the_category( get_the_ID() );
        $cat        = $allcats[0]->name;
        $arrayData  = array(
                        'id'        => get_the_ID(),
                        'Titulo'    => get_the_title(),
                        'cat'       => $cat
                    );

        //Criando arrayData com as informações do portfolio
        if( have_rows('conteudo_do_portfolio') ){
            while( have_rows('conteudo_do_portfolio') ){ the_row();

                $tipo = get_field( 'tipo' );

                if( $tipo == 'foto' ){

                    if( empty( $arrayData['imgs'] ) ){
                        $arrayData['imgs'][] = array(
                            'full' => $ob_img['original_image']['url'],
                            'thumb' => wp_get_attachment_image_src( $ob_img['id'], 'thumb_portfolio' )[0]
                        );
                    }

                    $idImg      = get_sub_field('foto');

                    $arrayData['imgs'][] = array(
                        'full' => wp_get_attachment_image_src( $idImg, 'full' )[0],
                        'thumb' => wp_get_attachment_image_src( $idImg, 'thumb_portfolio' )[0]
                    );

                }else{

                    $idVideo = youtube_video_id( get_sub_field('video') );

                    $arrayData['imgs'][] = array(
                        'full'  => $idVideo,
                        'thumb' => "http://img.youtube.com/vi/{$idVideo}/0.jpg"
                    );

                }

            }
        }

        //'<li class="'. ( is_home() || is_front_page() ? 'item-home' : '' ) .'">'
        $conteudo .=    '<li>'.
                        '<img src="'. $ob_img['url'] .'" class="capa" alt="'. $ob_img['alt'] .'" />'.
                        '<div class="camada text-center">'.
                            '<a href="#" class="openModalPortfolio" data-tipo="'. get_field( 'tipo' ) .'" data-json=\''. json_encode( $arrayData ) .' \'\ >'.
                                //'<div class="'. ( is_home() || is_front_page() ? 'center-home' : 'center' ) .'">'.
                                '<div class="center">'.
                                    //'<img src="/wp-content/themes/eliteled/images/expand'. ( is_home() || is_front_page() ? '' : '-red' ) .'.png" class="expand" />'.
                                    '<img src="/wp-content/themes/eliteled/images/expand-red.png" class="expand" />'.
                                    '<span class="titulo">'. ( strlen( get_the_title() ) > 60 ? substr( get_the_title(), 0, 60 ) . '...' : get_the_title() ) .'</span>'.
                                    '<span class="cat">'. $cat .'</span>'.
                                '</div>'.
                            '</a>'.
                        '</div>'.
                        '<div class="camada camada-branca"></div>'.
                    '</li>';

    }
}

我读到这个警告在 PHP 5.4 之前不会像 PHP 5.4 之前那样打印,而且它的发生是因为它期待和数组。我的 PHP 技能很少,有人可以告诉我该怎么做吗?

最佳答案

根据转储的数据,我猜测 original_image 的内容是一个附件 ID,所以试试这个:

$img_params = json_decode($ob_img, true); // convert string to associative array
$url = wp_get_attachment_image_url($img_params['original_image']);
if ($url) {
  // we have the image url now so display the image here tag here
}

如果它不起作用,请检查原始主题/插件开发人员是否对该组合来自的插件/主题有新的更新

关于php - 更新后的 Wordpress 'Illegal string offset',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54254790/

相关文章:

angularjs - 在浏览器中下载多个文件/文档

html - 使用CSS强制列表在响应式页面布局中围绕div元素流动

wordpress - 如何从 HTML 中提取 jQuery 代码并执行它?

css - 如何集成两个菜单 Wordpress 插件?

wordpress - WordPress:在url中包含语言变量

javascript - 使用 Javascript 在 Laravel 中重新格式化电话号码

php - CodeIgniter 或 Simple PHP,如何将一个表与另一个表的两列连接起来?

php - 使用 php str_getcsv 函数将 csv 文件数据转换为数组

javascript - 在 css 中为移动 View 调整/禁用 jQuery 代码

php - 在 Centos 中升级 PHP