WordPress的. apply_filter上的灯箱插件错误 [英] wordpress. lightbox plugin error on apply_filter

查看:108
本文介绍了WordPress的. apply_filter上的灯箱插件错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了插件 https://wordpress.org/plugins/show-post -in-lightbox/在页面上显示每个帖子的所有精选图片.每当这些图片之一被点击时,都会出现一个灯箱,显示帖子内容.

I use the plugin https://wordpress.org/plugins/show-post-in-lightbox/ to display all feautered image of every post on a page. whenver one of these images get clicked on a lightbox will appear showing the post content.

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

This all works fine but the original code that display the content uses:

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

这不是很好,因为wordpress无法格式化html,因此效果很好. Wordpress也不会识别简码.因此,我决定尝试使用脚本来确保其正常运行,并可以使用简码:

This works fine besides the fact that its not very need because wordpress cant format the html. also wordpress wont recognize shortcodes. So I decided to chance the script to make sure it works good and I can use shortcodes:

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行时,它不会出错(但是因为我需要该行,所以它也不会显示任何内容)

But this gives me the error: error loading lightbox on opening the lightbox. When i delete the APPLT_FILTERS line it doesnt error (but because I need that line it doesnt diplay anything aswell)

但是我认为保存

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

是灯箱崩溃的那个. 这段代码全部在插件文件中.有谁知道为什么上面的代码会生成并导致500次崩溃?

is the one that the lightbox crashes on. This code is all inside the plugin files. Does anyone know why the above code generates and 500 crash?

希望有人可以帮助我!

整个代码:

 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;
}

推荐答案

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

Have you checked the Apache/PHP error log file? It's essential for debugging :)

我注意到您的代码有2个问题-但更正它们实际上并不能解决500个问题.

I noticed 2 issues with your code - but correcting them might not actually fix the 500.

以下几行没有达到您的预期目的:

These few lines aren't doing what you intend:

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

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

Change $_POST['pid'] to $_REQUEST['pid']. The pid query variable isn't being POSTed.

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

Change $$postObj to $postObj. Imagine $_REQUEST['pid'] returned 123 (a sample post ID). Calling $$postObj would actually try to call $123; that variable would be both non-existent and invalid because it starts with a numeral.

这篇关于WordPress的. apply_filter上的灯箱插件错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆