如何删除业务摘要短码致命错误

时间:2016-12-30 作者:Shubham

致命错误:无法在/opt/lampp/htdocs/news/WP content/plugins/iron\\u elements/vc\\u extend/shortcode/wwn\\u business\\u feed中将WP\\u error类型的对象用作数组。php第13行

<?php
if ( !function_exists(\'wwn_currency_updates\')):
    function wwn_currency_updates($atts) {
        ob_start();
        $attr = shortcode_atts(array(\'currency\' => esc_html__(\'USD\', \'worldwidenews\'),
            \'css\' => esc_html__(\'\', \'worldwidenews\'),
        ), $atts);
        $css_class = apply_filters(VC_SHORTCODE_CUSTOM_CSS_FILTER_TAG, vc_shortcode_custom_css_class($attr[\'css\'], \' \'), \'wwn_currency_updates\', $atts);
        $currency_base = $attr[\'currency\'];
        $current_ping = "http://api.fixer.io/latest?base=" . $currency_base;
        $currency = wp_remote_get($current_ping);
        if ($currency) {
            $currency_data = json_decode($currency[\'body\']); ?>
            <div class="<?php echo esc_attr($css_class); ?>">
                <div class="wwn-currency-update-wrapper">
                    <div class="sub-heading-sec">
                        <h6><?php esc_html_e(\'Currency Rates\', \'worldwidenews\'); ?></h6>
                    </div><!--sub-heading-sec-->
                    <div class="wwn-currency-rates-sec">
                        <ul class="wwn-currency-rates-info">
                            <li>
                                <span class="wwn-currency wwn-left-float">
                                    <?php esc_html_e(\'GBP (Sterling) - AUD (Australian Dollars)\', \'worldwidenews\'); ?>
                                </span>
                                <span class="wwn-currency-rates wwn-right-float">
                                    <?php echo isset($currency_data->rates->AUD) ? esc_html($currency_data->rates->AUD) : 0; ?>
                                </span>
                            </li>
                            <li>
                                <span class="wwn-currency wwn-left-float">
                                    <?php esc_html_e(\'GBP (Sterling) - CAD (Canadian Dollar)\', \'worldwidenews\'); ?>
                                </span>
                                <span class="wwn-currency-rates wwn-right-float">
                                    <?php echo isset($currency_data->rates->CAD) ? esc_html($currency_data->rates->CAD) : 0; ?>
                                </span>
                            </li>
                            <li>
                                <span class="wwn-currency wwn-left-float">
                                    <?php esc_html_e(\'GBP (Sterling) - EUR (Euro)\', \'worldwidenews\'); ?>
                                </span>
                                <span class="wwn-currency-rates wwn-right-float">
                                    <?php echo isset($currency_data->rates->EUR) ? esc_html($currency_data->rates->EUR) : 0; ?>
                                </span>
                            </li>
                            <li>
                                <span class="wwn-currency wwn-left-float">
                                    <?php esc_html_e(\'GBP (Sterling) - NZD (New Zealand Dollar)\', \'worldwidenews\'); ?>
                                </span>
                                <span class="wwn-currency-rates wwn-right-float">
                                    <?php echo isset($currency_data->rates->NZD) ? esc_html($currency_data->rates->NZD) : 0; ?>
                                </span>
                            </li>
                            <li>
                                <span class="wwn-currency wwn-left-float">
                                    <?php esc_html_e(\'GBP (Sterling) - INR (Indian Rupees)\', \'worldwidenews\'); ?>
                                </span>
                                <span class="wwn-currency-rates wwn-right-float">
                                    <?php echo isset($currency_data->rates->INR) ? esc_html($currency_data->rates->INR) : 0; ?>
                                </span>
                            </li>
                            <li>
                                <span class="wwn-currency wwn-left-float">
                                    <?php esc_html_e(\'GBP (Sterling) - SGD (Singapore Dollar)\', \'worldwidenews\'); ?>
                                </span>
                                <span class="wwn-currency-rates wwn-right-float">
                                    <?php echo isset($currency_data->rates->SGD) ? esc_html($currency_data->rates->SGD) : 0; ?>
                                </span>
                            </li>
                            <li>
                                <span class="wwn-currency wwn-left-float">
                                    <?php esc_html_e(\'GBP (Sterling) - BGN (Bulgarian Lev)\', \'worldwidenews\'); ?>
                                </span>
                                <span class="wwn-currency-rates wwn-right-float">
                                    <?php echo isset($currency_data->rates->BGN) ? esc_html($currency_data->rates->BGN) : 0; ?>
                                </span>
                            </li>
                            <li>
                                <span class="wwn-currency wwn-left-float">
                                    <?php esc_html_e(\'GBP (Sterling) - RON (Romanian)\', \'worldwidenews\'); ?>
                                </span>
                                <span class="wwn-currency-rates wwn-right-float">
                                    <?php echo isset($currency_data->rates->RON) ? esc_html($currency_data->rates->RON) : 0; ?>
                                </span>
                            </li>
                            <li>
                                <span class="wwn-currency wwn-left-float">
                                    <?php esc_html_e(\'GBP (Sterling) - CHF (Swiss Franc)\', \'worldwidenews\'); ?>
                                </span>
                                <span class="wwn-currency-rates wwn-right-float">
                                    <?php echo isset($currency_data->rates->CHF) ? esc_html($currency_data->rates->CHF) : 0; ?>
                                </span>
                            </li>
                        </ul>
                    </div><!--wwn-currency-rates-sec-->
                </div><!--currency-update-wrapper-->
            </div>
        <?php }
        $currency_updates = ob_get_clean();
        return $currency_updates;
    }

    add_shortcode(\'wwn_currency_updates\', \'wwn_currency_updates\');
endif;

1 个回复
SO网友:Milo

这可能就是问题所在:

$currency = wp_remote_get($current_ping);
if($currency){
$currency 要么是WP_Error 对象或array. 正在检查if($currency) 在这两种情况下都是如此。

相反,您应该检查它是否是数组而不是错误对象:

if ( is_array( $currency ) && ! is_wp_error( $currency ) ) {
当然,这并不能解决这样一个事实wp_remote_get 返回错误。。。

相关推荐

SHORTCODE_ATTS()中的$ATTS参数是什么?

这个WordPress developers reference page for shortcode_atts() 国家:$atts(array)(必选)用户在shortcode标记中定义的属性。但我不理解这个定义。例如,在WP Frontend Profile 插件:$atts = shortcode_atts( [ \'role\' => \'\', ], $atts ); 据我所知,shortcode\