更改短码输出(筛选器?)

时间:2015-06-09 作者:kiarashi

我不熟悉过滤器和操作,我开始发现它们有多有用。然而,我确实需要一些帮助来解决以下问题。

我想从中删除html代码

<?php if ( $atts[\'columns\'] != 0 && $i % $atts[\'columns\'] == 0 ) { ?><div style="clear:both;"></div><?php } ?>
我的函数中的下面一个。php

<?php if ( $atts[\'columns\'] != 0 && $i % $atts[\'columns\'] == 0 ) { ?> <?php } ?>
有人能给我指出正确的方向吗?

完整源代码:

    // Allow the query to be manipulated by other plugins
    $query = apply_filters( \'edd_downloads_query\', $query, $atts );

    $downloads = new WP_Query( $query );
    if ( $downloads->have_posts() ) :
        $i = 1;
        $wrapper_class = \'edd_download_columns_\' . $atts[\'columns\'];
        ob_start(); ?>
        <div class="edd_downloads_list <?php echo apply_filters( \'edd_downloads_list_wrapper_class\', $wrapper_class, $atts ); ?>">
            <?php while ( $downloads->have_posts() ) : $downloads->the_post(); ?>
                <?php $schema = edd_add_schema_microdata() ? \'itemscope itemtype="http://schema.org/Product" \' : \'\'; ?>
                <div <?php echo $schema; ?>class="<?php echo apply_filters( \'edd_download_class\', \'edd_download\', get_the_ID(), $atts, $i ); ?>" id="edd_download_<?php echo get_the_ID(); ?>" style="width: <?php echo $column_width; ?>; float: left;">
                    <div class="edd_download_inner">
                        <?php

                        do_action( \'edd_download_before\' );

                        if ( \'false\' != $atts[\'thumbnails\'] ) :
                            edd_get_template_part( \'shortcode\', \'content-image\' );
                            do_action( \'edd_download_after_thumbnail\' );
                        endif;

                        edd_get_template_part( \'shortcode\', \'content-title\' );
                        do_action( \'edd_download_after_title\' );

                        if ( $atts[\'excerpt\'] == \'yes\' && $atts[\'full_content\'] != \'yes\' ) {
                            edd_get_template_part( \'shortcode\', \'content-excerpt\' );
                            do_action( \'edd_download_after_content\' );
                        } else if ( $atts[\'full_content\'] == \'yes\' ) {
                            edd_get_template_part( \'shortcode\', \'content-full\' );
                            do_action( \'edd_download_after_content\' );
                        }

                        if ( $atts[\'price\'] == \'yes\' ) {
                            edd_get_template_part( \'shortcode\', \'content-price\' );
                            do_action( \'edd_download_after_price\' );
                        }

                        if ( $atts[\'buy_button\'] == \'yes\' )
                            edd_get_template_part( \'shortcode\', \'content-cart-button\' );

                        do_action( \'edd_download_after\' );

                        ?>
                    </div>
                </div>
                <?php if ( $atts[\'columns\'] != 0 && $i % $atts[\'columns\'] == 0 ) { ?><div style="clear:both;"></div><?php } ?>
            <?php $i++; endwhile; ?>

            <div style="clear:both;"></div>

            <?php wp_reset_postdata(); ?>

            <?php
                $pagination = false;

                if ( is_single() ) {
                    $pagination = paginate_links( apply_filters( \'edd_download_pagination_args\', array(
                        \'base\'    => get_permalink() . \'%#%\',
                        \'format\'  => \'?paged=%#%\',
                        \'current\' => max( 1, $query[\'paged\'] ),
                        \'total\'   => $downloads->max_num_pages
                    ), $atts, $downloads, $query ) );
                } else {
                    $big = 999999;
                    $search_for   = array( $big, \'#038;\' );
                    $replace_with = array( \'%#%\', \'&\' );
                    $pagination = paginate_links( apply_filters( \'edd_download_pagination_args\', array(
                        \'base\'    => str_replace( $search_for, $replace_with, get_pagenum_link( $big ) ),
                        \'format\'  => \'?paged=%#%\',
                        \'current\' => max( 1, $query[\'paged\'] ),
                        \'total\'   => $downloads->max_num_pages
                    ), $atts, $downloads, $query ) );
                }
            ?>

            <?php if ( ! empty( $pagination ) ) : ?>
            <div id="edd_download_pagination" class="navigation">
                <?php echo $pagination; ?>
            </div>
            <?php endif; ?>

        </div>
        <?php
        $display = ob_get_clean();
    else:
        $display = sprintf( _x( \'No %s found\', \'download post type name\', \'edd\' ), edd_get_label_plural() );
    endif;

    return apply_filters( \'downloads_shortcode\', $display, $atts, $atts[\'buy_button\'], $atts[\'columns\'], $column_width, $downloads, $atts[\'excerpt\'], $atts[\'full_content\'], $atts[\'price\'], $atts[\'thumbnails\'], $query );
}
add_shortcode( \'downloads\', \'edd_downloads_query\' );

1 个回复
最合适的回答,由SO网友:kiarashi 整理而成

我通过使用str\\u replace解决了这个问题。

function mp_filter_download( $result ) {
        $search         = \'<div style="clear:both;"></div>\';
        $replacewith    = \' \';      
        return str_replace( $search, $replacewith, $result );
}
add_filter( \'downloads_shortcode\', \'mp_filter_download\', 10, 2 );

结束

相关推荐

Shortcodes: Pros and Cons

我们即将开始以插件的形式为特定的客户端工作开发一个相对简单的新小部件,但希望创建一些在未来项目中可用的小部件。该插件允许用户突出显示他们正在编辑的页面中的一行或多行文本,并选择这些文本作为建议内容显示在页面上,以便通过社交网络(如Facebook)共享。以下是实现这一目标的几种可能方法:方法一-短代码添加一个快捷码,用户可以将其希望用于建议共享内容的文本环绕起来。Pros: 短代码是WordPress的内置功能,即使插件被禁用,它们也不会破坏内容</现有内容将始终与共享片段相匹配,因为它们需要存在于