【问题标题】:wordpress. lightbox plugin error on apply_filterWordPress的。 apply_filter 上的灯箱插件错误
【发布时间】:2014-09-18 12:50:17
【问题描述】:

我使用插件https://wordpress.org/plugins/show-post-in-lightbox/ 来显示页面上每个帖子的所有 fautered 图像。每当点击其中一张图片时,就会出现一个灯箱,显示帖子内容。

这一切正常,但显示内容的原始代码使用:

if($_REQUEST['popup']!=''){
$postObj = get_post( $_REQUEST['pid'] );
echo $postObj->post_content;
exit;
}

这很好用,因为它不是很需要,因为 wordpress 无法格式化 html。 wordpress 也不会识别简码。所以我决定试试这个脚本以确保它运行良好并且我可以使用简码:

if($_REQUEST['popup']!=''){

$postObj = $_POST['pid'];
$content_post = get_post($$postObj);
$content = $content_post->post_content;
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
echo $content;
exit;
}

但这给了我错误:打开灯箱时加载灯箱时出错。当我删除 APPLT_FILTERS 行时它不会出错(但因为我需要该行它也不会显示任何内容)

但我认为它可以节省

$content = apply_filters('the_content', $content);

是灯箱崩溃的那个。 这段代码都在插件文件中。有谁知道为什么上面的代码会生成和 500 崩溃?

希望有人能帮帮我!

整个代码:

 if($_REQUEST['popup']!=''){

$postObj = $_POST['pid'];
$content_post = get_post($$postObj);
$content = $content_post->post_content;
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
echo $content;
}

class spbc_showPostsWidget extends WP_Widget{

function spbc_showPostsWidget() {
            $options = array('description' => 'Show posts from selected categories.');
            parent::WP_Widget(false, $name = 'Show Posts By Category', $options);
}
/*-----------------------------------------------------------*/
function widget($args, $instance) {
            extract($args, EXTR_SKIP);

            $ost_title              = empty($instance['ost_title']) ? ' ' :     apply_filters('widget_title', $instance['ost_title']);
            $ost_limit              = (is_numeric($instance['ost_limit'])) ? $instance['ost_limit'] : 5;
            $ost_orderby            = ($instance['ost_orderby']) ? $instance['ost_orderby'] : 'date';
            $ost_order              = ($instance['ost_order']) ? $instance['ost_order'] : 'desc';
            $ost_exclude            = ($instance['ost_exclude'] != '') ? $instance['ost_exclude'] : 0;
            $ost_excludeposts       = ($instance['ost_excludeposts'] != '') ? $instance['ost_excludeposts'] : 0;
            $ost_category_id        = $instance['ost_categoryid'];
            $ost_showdate           = ($instance['ost_show_date'] == 'on') ? 'yes' : 'no';
            $ost_thumbnail          = ($instance['ost_thumbnail'] == 'on') ? 'yes' : 'no';
            $ost_thumbnail_size     = ($instance['ost_thumbnail_size']) ? $instance['ost_thumbnail_size'] : 'thumbnail';

            echo $before_widget;

            $this->spbc_showWidget($instance);
            echo $after_widget;
}
/*-----------------------------------------------------------*/
public static function get_UrlFromText($content,$url='Y'){

    if($url=='Y'){
        $imgpattern = '/src=[\'"]?([^\'" >]+)[\'" >]/';
        preg_match($imgpattern, $content, $article_image);
    }else{
        preg_match_all('/<img[^>]+>/i',$content, $article_image); 
    }
    return $article_image;
}

/*-----------------------------------------------------------*/
function spbc_showWidget($instance){
            global $post;
            $query    = array(
                'posts_per_page' => $instance['ost_limit'],
                'cat' => $instance['ost_categoryid'],
                'orderby' => $instance['ost_orderby'],
                'order' => $instance['ost_order'],
                'category__not_in' => array($instance['ost_exclude']),
                'post__not_in' => array($instance['ost_excludeposts'])
            );

            $wp_query = new WP_Query($query);

             if ($wp_query->have_posts()):

                     echo '
                        <div class="list-posts-by-category">                                   
                            <ul>';
                                while ($wp_query->have_posts()):
                                    $wp_query->the_post();
                                    $image_id = get_post_thumbnail_id();


                                    if(!empty($instance['ost_thumbnail'])){
                                        if ( in_array($instance['ost_thumbnail_size'],array('thumbnail', 'medium', 'large', 'full'))) {
                                            $ost_thumb_size = $instance['ost_thumbnail_size'];
                                        }elseif ($instance['ost_thumbnail_size']){
                                            $ost_thumb_size = array($instance['ost_thumbnail_size']);
                                        }else {
                                            $ost_thumb_size = 'thumbnail';
                                        }
                                        $ost_thumbnail = get_the_post_thumbnail($post->ID, $ost_thumb_size);
                                    }else{
                                        $ost_thumbnail = "";
                                    }
                                ?>

                                <li>
                               <a class="ostlightbox"  href="<?php echo get_site_url().'/index.php?pid='.$post->ID.'&popup=Y'; ?>" title="<?php echo the_title_attribute(); ?>">
                                <?php echo '<div class="ostoverlay"></div>'; ?>
                                    <?php echo '<div class="titleconthidden"><p class="osttitle">'.$post->post_title.'</p></div>'; ?>
                                    <?php echo '<div class="titlecont"></div>'; ?>


                                    <?php 

                                    echo $ost_thumbnail;

                                    ?>
                                    </a>
                                    <?php if(!empty($instance['ost_show_date'])){ ?><span><?php      echo get_the_time('F jS, Y'); ?></span><?php } ?>
                                  </li><?php
                                endwhile;
                                echo '
                            </ul>
                        </div>';
             endif;
}

【问题讨论】:

    标签: php wordpress lightbox


    【解决方案1】:

    您是否检查过 Apache/PHP 错误日志文件?这对于调试很重要:)

    我注意到您的代码存在 2 个问题 - 但更正它们实际上可能无法修复 500。

    这几行没有达到你的预期:

    $postObj = $_POST['pid'];
    $content_post = get_post($$postObj);
    

    将$_POST['pid'] 更改为$_REQUEST['pid']。 pid 查询变量未发布。

    将$$postObj 更改为$postObj。想象一下$_REQUEST['pid'] 返回了123(一个示例帖子 ID)。调用$$postObj 实际上会尝试调用$123;该变量将不存在且无效,因为它以数字开头。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-11
      • 1970-01-01
      • 2019-12-16
      • 1970-01-01
      相关资源
      最近更新 更多