Unable to use add_filter on network_the_content

There's a slight typo in the functions.php which means that you can't do add_filter(network_the_content

The problem is that the network_get_the_content function ends:

return $output;

when it should end:

return apply_filters('network_the_content', $output);

if you make this change other plugins can then apply their own filters on your function.

  • Jack Kitterhing

    Hi there @Steve Atty,

    Hope you're well today and thanks for pointing that out, much appreciated! :slight_smile:

    We'll get that fixed up in the next version, though in the mean time you can make that change and you should be good on the plugin update :slight_smile:

    If you need any assistance making the change please don't hesitate to ask, I've notified the lead developer of this :slight_smile:

    Thank you!

    Kind Regards

  • Eugene Manuilov

    Hi @Steve Atty

    Those functions (in the functions.php file) have been written as a copy of standard WordPress functions, but with scope of network index stuff. It means that if you investigate standard get_the_content function, then you won't find 'the_content' filter inside. But if you look at the_content function, you will see this filter. The same is in network functions. Look at network_the_content function, there is 'network_the_content' filter.

    So we won't add this filter to network_get_the_content function.


  • Eugene Manuilov

    Hi @Steve Atty

    I have implemented an ability to override template for search results in the Global Site Search plugin. Could you please test it out on your end? Please install the beta version from the attached archive. The go to your theme, create a folder global-site-search and cope following file into it:


    After it you should be able to modify template as you need. Please, let me know if it works for you and you can use your custom templates.


  • Steve Atty

    Sorry? Over ride the template? The problem is that it is not possible to use apply_filters on the output of the Global Search. I have a plugin that needs to apply filters to handle code in the text returned when the Global Search returns its results. I can't go round asking everyone who uses my plugin to go round editing their themes.

    My code uses:

    add_filter('the_content',  'canal_stats');
    	add_filter('the_content',  'canal_trip_maps');
    	add_filter('the_content',  'canal_trip_stats');
    	add_filter('the_content',  'canal_route_maps');
    	add_filter('the_content',  'canal_place_maps');
    	add_filter('the_content',  'canal_link_maps');
    	add_filter('the_content',  'canal_linkify');
    	add_filter('the_content',  'canal_blogroute_insert');
            add_filter('the_excerpt',  'canal_stats');
    	add_filter('the_excerpt',  'canal_trip_maps');
    	add_filter('the_excerpt',  'canal_trip_stats');
    	add_filter('the_excerpt',  'canal_route_maps');
    	add_filter('the_excerpt',  'canal_place_maps');
    	add_filter('the_excerpt',  'canal_link_maps');
    	add_filter('the_excerpt',  'canal_linkify');
    	add_filter('the_excerpt',  'canal_blogroute_insert');

    to manipulate the output - the problem is that the global search does this:

    $the_content = preg_replace( "~(?:\[/?)[^/\]]+/?\]~s", '', network_get_the_content() );
    $content .= $substr( strip_tags( $the_content ), 0, 250 ) . ' (<a href="' . network_get_permalink() . '">' . __( 'More', 'globalsitesearch' ) . '</a>)';

    which I can't apply filters to because network_get_the_content never applies any filters even though other network_get_the functions do ....

    function network_get_the_excerpt() {
    	global $network_post, $post;
    	$output = $network_post->post_excerpt;
    	// back up post as we need it later
    	$oldpost = $post;
    	// set the post to our network post
    	$post = $network_post;
    	// get the excerpt
    	$excerpt = apply_filters('get_the_excerpt', $output);
    	// reset the post variable in case it's needed elsewhere
    	$post = $oldpost;
    	// return the excerpt
    	return $excerpt;

    as does :

    function network_get_post_time( $d = 'U', $gmt = false, $post = null, $translate = false ) { // returns timestamp
    	global $network_post;
    	$post = &network_get_post( $network_post->BLOG_ID, $network_post->ID );
    	if ( $gmt )
    		$time = $post->post_date_gmt;
    		$time = $post->post_date;
    	$time = mysql2date($d, $time, $translate);
    	return apply_filters('network_get_post_time', $time, $d, $gmt);

    Or Global Site Search needs to be changed so that it does:

    $the_content = preg_replace( "~(?:\[/?)[^/\]]+/?\]~s", '', apply_filters('network_the_content', network_get_the_content()));

    Which to be honest would be the better way to do it - or it could use the existing network_get_the_excerpt function rather than implemeting its own version of an excerpt

  • Steve Atty

    I've just made the filter change to the output in the global site search and its now working..

    If you look at:


    You see posts like :

    Mintball wrote: The long push south
    From Dutton Wharf Bridge No 212 to Barbridge Junction, a distance of 22 miles and 8 locks. For various reasons, which this blog is not going in to, Kathy and I were still on the boat when we should have got off at Wigan, this of course meant that we (More)

    The "From Dutton Wharf Bridge No 212 to Barbridge Junction, a distance of 22 miles and 8 locks" is generated on the fly from my plugin which is why I need to be able to apply the filters.

  • Steve Atty

    The problem is that the global post search does not allow you to apply filters to its output - which means that plugins that manipulate the post using apply_filters don't work with Global search.

    So either the post indexer needs changing to allow filtering on the function being used... which you say is wrong. OR the global search output needs changing to apply the filters before it creates its excerpt... or it could use the already crafted network_excerpt function which works with filters.

    Changing themes with over-rides is NOT an option as that means anyone using my plugin has to make changes to their theme.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.