Php Wordpress do_短代码奇怪的行为

Php Wordpress do_短代码奇怪的行为,php,wordpress,shortcode,Php,Wordpress,Shortcode,我正在开发一个WP插件,它可以处理短代码并显示amazon条目数据来代替它们。除了有点奇怪的行为外,插件工作正常。你可以看到我的测试运行在 如果在该页上向下滚动,可以看到内容中附加了4个1。在该页面中,短代码被处理4次,每次WP向输出中添加不希望的1。我不明白为什么会这样。在我的html文件中没有1,在帖子内容中也没有。我所有的函数都只返回要替换的内容来代替短代码。有人能给我解释一下,让我知道如何删除这些吗?提前谢谢 我的代码如下: add_shortcode('zon_product', 'z

我正在开发一个WP插件,它可以处理短代码并显示amazon条目数据来代替它们。除了有点奇怪的行为外,插件工作正常。你可以看到我的测试运行在

如果在该页上向下滚动,可以看到内容中附加了4个1。在该页面中,短代码被处理4次,每次WP向输出中添加不希望的1。我不明白为什么会这样。在我的html文件中没有1,在帖子内容中也没有。我所有的函数都只返回要替换的内容来代替短代码。有人能给我解释一下,让我知道如何删除这些吗?提前谢谢

我的代码如下:

add_shortcode('zon_product', 'zon_process_shortcode');

// Zon Shortcode processor
function zon_process_shortcode($attributes, $content = null) {
    global $zon_html_path;

    // default options for shortcode
    $options = array('asin' => '', 'style' => 'compact', 'loc' => 'com');
    extract(shortcode_atts($options, $attributes));

    $asin = $attributes['asin'];

    // first find asin in local zon_data table
    $zdb = ZonDbHandler::instance();
    $product = $zdb->findASIN($asin);

    if ($product) {
        // if product exists in db, render template
        return zon_display_product($product, $attributes);
    } else {
        // product does not exist in database, get data through amazon api worflow
        $product = ZonLibrary::getAmazonProduct($asin, $attributes['loc']);
        if ($product) {
            // product data has been successfully retrieved and saved, render template
            return zon_display_product($product, $attributes);
        } else {
            // error in fetching product data, check amazon access key id and api secret
            $content = include($zon_html_path . 'html' . DIRECTORY_SEPARATOR . 'api_error.php');
            return $content;
        }
    }
}

// Renders selected template with product data
function zon_display_product(ZonProduct $product, $attributes) {
    global $zon_html_path;
    global $zon_path;

    // process other shortcode options
    $view_vars = array();
    $view_vars['style'] = (isset($attributes['style'])) ? $attributes['style'] : "default";
    $view_vars['show_price'] = (isset($attributes['show_price']) && $attributes['show_price'] == 0) ? false : true;
    $view_vars['price_updates'] = (isset($attributes['price_updates']) && $attributes['price_updates'] == 0) ? false : true;
    $view_vars['hide_unavailable'] = (isset($attributes['hide_unavailable']) && $attributes['hide_unavailable'] == 1) ? true : false;
    $view_vars['show_desc'] = (isset($attributes['show_desc']) && $attributes['show_desc'] == 0) ? false : true;

    // check if template file exists
    if (!is_file($zon_html_path . 'html' . DIRECTORY_SEPARATOR . $view_vars['style'] . '.php')) {
        $content = 'ERROR! Zon Template not found. Please check you are using a correct value for the "style" parameter.';
        return $content;
    } else {
        // get product array
        $product = $product->getArray();

        // if product is unavailable and hide_unavailable is true, return unavailable template
        if ($view_vars['hide_unavailable']) {
            if ((strpos($product['availability'], "Usually") === false) && strpos($product['availability'], "ships") === false) {
                $content = include($zon_html_path . 'html' . DIRECTORY_SEPARATOR . 'unavailable.php');
                return $content;
            }
        }

        // render chosen template file
        $content = include($zon_html_path . 'html' . DIRECTORY_SEPARATOR . $view_vars['style'] . '.php');
        return $content;
    }
}

我猜“1”字符的出现是由其他原因造成的。如果查看源代码,实际生成的是

1

。我不认为Wordpress会自己产生这样的结果。在插件和/或主题文件夹中搜索该样式字符串应该可以找到罪魁祸首。。让我快速地做一个grep,看看我是否找到了。我在我的wp内容文件夹中做了一个“grep-rn 141412.”,它只能找到这些:./themes/twentyrety/css/editor style.css:36:color:141412/themes/Twenty13/style.css:110:color:141412/themes/Twenty13/style.css:576:color:141412/themes/Twenty13/style.css:819:color:141412/themes/Twenty13/style.css:872:color:141412/themes/Twenty13/style.css:1037:color:141412/themes/Twenty13/style.css:2888:color:141412/主题/Twenty13/style.css:2895:color:141412;它不在我的插件中。生成的1的数量等于我的帖子内容中的短代码的数量。。当我使用3个短代码时,有3个1s等。我看不到你在这里发布的内容会生成1个字符。你的短码在帖子里是什么样子的?