Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter fabio84

    (@fabio84)

    @roterdam909 No, I’m just Italian and we love long sentences, and I’m trying to explain technical issues in a language that I don’t know very well 😀

    @otto: Ok, at a first try, I wasn’t able to reproduce the issue in a vanilla WordPress with only a test plugin and Simple Facebook Connect. In fact I had the issue on a WordPress installation with many plugins. On this installation, I tried enabling and disabling Simple Facebook Connect, and my fix described in the second post seemed to resolve the issue.

    I have another hypothesis: maybe another plugin disables wptexturize and replaces it with another function (or gives to it another priority with the third optional parameter), so you don’t actually disable wptexturize (because another plugin already disabled it) and you add it, break something. I’ll investigate further….

    Thread Starter fabio84

    (@fabio84)

    I think you didn’t understand my point: I got that sfc_base_make_excerpt is basically a function that strips the html to create a textual excerpt, and it’s ok if it strips javascript for its purpose. I got also that for some reason you don’t want to apply wptexturize during apply_filters(‘the_content’, $text) in the context of sfc_base_make_excerpt.

    It seems you think that if you remove filter wptexturize and add back again is ok, but it’s not, because the order of filters is important. wptexturize is one of the first functions added to the_content filter queue at default priority (10), if you add it back it becomes the last filter.

    As sfc_base_make_excerpt is called in the header, the change of behavior of the_content filters breaks the javascript code in the_content later in the main content. If you still think this is not an issue, I may provide a simple case with a simple plugin so you can do your tests.

    Thread Starter fabio84

    (@fabio84)

    As a quick and dirty solution, I have added the function _sfc_apply_filters in sfc-base.php. This function is the copy of apply_filter as in WordPress 3.5.1, but I added a condition so it executes all the filter functions except wptexturize. In sfc_base_make_excerpt I have removed the remove_filter and add_filter calls and I use _sfc_apply_filters instead of apply_filters

    function _sfc_apply_filters($tag, $value) {
    	global $wp_filter, $merged_filters, $wp_current_filter;
    
    	$args = array();
    
    	// Do 'all' actions first
    	if ( isset($wp_filter['all']) ) {
    		$wp_current_filter[] = $tag;
    		$args = func_get_args();
    		_wp_call_all_hook($args);
    	}
    
    	if ( !isset($wp_filter[$tag]) ) {
    		if ( isset($wp_filter['all']) )
    			array_pop($wp_current_filter);
    		return $value;
    	}
    
    	if ( !isset($wp_filter['all']) )
    		$wp_current_filter[] = $tag;
    
    	// Sort
    	if ( !isset( $merged_filters[ $tag ] ) ) {
    		ksort($wp_filter[$tag]);
    		$merged_filters[ $tag ] = true;
    	}
    
    	reset( $wp_filter[ $tag ] );
    
    	if ( empty($args) )
    		$args = func_get_args();
    
    	do {
    		foreach( (array) current($wp_filter[$tag]) as $the_ )
    			if ( !(is_null($the_['function']) || $the_['function'] == 'wptexturize' ) ){
    				$args[1] = $value;
    				$value = call_user_func_array($the_['function'], array_slice($args, 1, (int) $the_['accepted_args']));
    			}
    
    	} while ( next($wp_filter[$tag]) !== false );
    
    	array_pop( $wp_current_filter );
    
    	return $value;
    }
    
    // code to create a pretty excerpt given a post object
    function sfc_base_make_excerpt($post) { 
    
    	if ( !empty($post->post_excerpt) )
    		$text = $post->post_excerpt;
    	else
    		$text = $post->post_content;
    
    	$text = strip_shortcodes( $text );
    
    	// filter the excerpt or content, but without texturizing
    	if ( empty($post->post_excerpt) ) {
    		$text = _sfc_apply_filters('the_content', $text);
    	} else {
    		$text = _sfc_apply_filters('the_excerpt', $text);
    	}

    I hope you could rethink about the way excerpt text is generated: it seems over-complex to me at a first sight, maybe this could be done in a simpler way, but I had no time to study it and maybe all this is necessary.
    Neither my fix is optimal, because _sfc_apply_filters works only with WordPress 3.5.1 and in versions with the same code for apply_filters, and may not work with other versions. So if you use a fix like mine you have to check if apply_filters changes in future WordPress versions.

Viewing 3 replies - 1 through 3 (of 3 total)