WordPress.org

Ready to get started?Download WordPress

Forums

Custom Post Widget
incompatility with bj-lazy-load and solution. (2 posts)

  1. Nikoya
    Member
    Posted 6 months ago #

    Hello,

    It seems that CPW break partially bj-lazy-load plugin.
    (I've post on the bg-lazy-load forum too (http://wordpress.org/support/topic/incompatibility-with-certain-plugin-caused-by-filter-priority-200?replies=1).
    But after trying lot of things i think the problem can be solve in the CPW.

    The issue seems to be caused by using apply_filters( 'the_content'.
    I don't know exactly why, maybe cause add_shortcode start too late ...

    But i've found a solution here : http://www.viper007bond.com/2009/11/22/wordpress-code-earlier-shortcodes/

    So, finally i proposed this code wich seems to do the job without breaking anything.

    Replace :

    // Add the ability to display the content block in a reqular post using a shortcode
    function custom_post_widget_shortcode( $atts ) {
    	extract( shortcode_atts( array(
    		'id' => '',
    		'class' => 'content_block'
    	), $atts ) );
    
    	$content = "";
    
    	if( $id != "" ) {
    		$args = array(
    			'post__in' => array( $id ),
    			'post_type' => 'content_block',
    		);
    
    		$content_post = get_posts( $args );
    
    		foreach( $content_post as $post ) :
    			$content .= '<div class="'. esc_attr($class) .'" id="custom_post_widget-' . $id . '">';
    			$content .= apply_filters( 'the_content', $post->post_content);
    			$content .= '</div>';
    		endforeach;
    	}
    
    	return $content;
    }
    add_shortcode( 'content_block', 'custom_post_widget_shortcode' );

    BY :

    // Add the ability to display the content block in a reqular post using a shortcode
    function custom_post_widget_shortcode( $atts ) {
    	extract( shortcode_atts( array(
    		'id' => '',
    		'class' => 'content_block'
    	), $atts ) );
    
    	$content = "";
    
    	if( $id != "" ) {
    		$args = array(
    			'post__in' => array( $id ),
    			'post_type' => 'content_block',
    		);
    
    		$content_post = get_posts( $args );
    
    		foreach( $content_post as $post ) :
    			$content .= '<div class="'. esc_attr($class) .'" id="custom_post_widget-' . $id . '">';
    			//$content .= apply_filters( 'the_content', $post->post_content);
    			$content .= $post->post_content;
    			$content .= '</div>';
    		endforeach;
    	}
    
    	return $content;
    }
    //add_shortcode( 'content_block', 'custom_post_widget_shortcode' );
    
    /*******************************
    *http://www.viper007bond.com/2009/11/22/wordpress-code-earlier-shortcodes/
    *******************************/
    // This will do nothing but will allow the shortcode to be stripped
    //add_shortcode( 'content_block', '__return_false' );
    
    // Actual processing of the shortcode happens here
    function custom_post_widget_add_shortcode( $content ) {
       // global $shortcode_tags;
    
        // Backup current registered shortcodes and clear them all out
        //$orig_shortcode_tags = $shortcode_tags;
        //remove_all_shortcodes();
    
    		add_shortcode( 'content_block', 'custom_post_widget_shortcode' );
        // Do the shortcode (only the one above is registered)
        $content = do_shortcode( $content );
    
        // Put the original shortcodes back
        //$shortcode_tags = $orig_shortcode_tags;
    
        return $content;
    }
    add_filter( 'the_content', 'custom_post_widget_add_shortcode', 7 );

    what you think about this ? Can it be used in the next released ?

    https://wordpress.org/plugins/custom-post-widget/

  2. Nikoya
    Member
    Posted 6 months ago #

    Oops this code is in the file 'post-widget.php' line 188 ;)

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.