0

I'm new to filters and actions and I'm starting to see how useful they are. However I do need a bit of help with the following problem.

I'd like to remove the html code from this

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

to the one below inside my functions.php

<?php if ( $atts['columns'] != 0 && $i % $atts['columns'] == 0 ) { ?> <?php } ?>

Can anyone put me in the right direction?

Full source code:

    // 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' );
0

I was able to solve this by using str_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 );
  • If you accept your answer then the question will be marked as resolved. Thanks. – Andy Macaulay-Brook Jul 22 '16 at 16:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.