Skip to content

Instantly share code, notes, and snippets.

@mdawaffe
Created December 13, 2012 03:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdawaffe/4273702 to your computer and use it in GitHub Desktop.
Save mdawaffe/4273702 to your computer and use it in GitHub Desktop.
PowerPress Compatibility with Jetpack: Improve the_excerpt/the_content gymnastics
Index: powerpress.php
===================================================================
--- powerpress.php (revision 638166)
+++ powerpress.php (working copy)
@@ -101,8 +101,12 @@
function powerpress_content($content)
{
- global $post, $g_powerpress_excerpt_post_id;
-
+ global $post, $wp_current_filter;
+
+ // Problem: If the_excerpt is used instead of the_content, both the_exerpt and the_content will be called here.
+ if( in_array('get_the_excerpt', (array) $wp_current_filter) )
+ return $content;
+
if( defined('PODPRESS_VERSION') || isset($GLOBALS['podcasting_player_id']) || isset($GLOBALS['podcast_channel_active']) || defined('PODCASTING_VERSION') )
return $content;
@@ -132,32 +136,13 @@
if( !empty($GLOBALS['fb_ver']) && version_compare($GLOBALS['fb_ver'], '1.0', '<=') ) {
$GeneralSettings['player_aggressive'] = true;
}
- if( defined('JETPACK__VERSION') && version_compare(JETPACK__VERSION, '2.0', '>=') ) {
- $GeneralSettings['player_aggressive'] = true;
- }
if( !empty($GeneralSettings['player_aggressive']) )
{
if( strstr($content, '<!--powerpress_player-->') !== false )
return $content; // The players were already added to the content
-
- if( $g_powerpress_excerpt_post_id > 0 )
- $g_powerpress_excerpt_post_id = 0; // Hack, set this to zero so it always goes past...
}
- // Problem: If the_excerpt is used instead of the_content, both the_exerpt and the_content will be called here.
- // Important to note, get_the_excerpt will be called before the_content is called, so we add a simple little hack
- if( current_filter() == 'get_the_excerpt' )
- {
- $g_powerpress_excerpt_post_id = $post->ID;
- return $content; // We don't want to do anything to this content yet...
- }
- else if( current_filter() == 'the_content' && $g_powerpress_excerpt_post_id == $post->ID )
- {
- return $content; // We don't want to do anything to this excerpt content in this call either...
- }
-
-
if( !isset($GeneralSettings['custom_feeds']) )
$GeneralSettings['custom_feeds'] = array('podcast'=>'Default Podcast Feed');
@@ -289,7 +274,6 @@
return $content;
}//end function
-add_filter('get_the_excerpt', 'powerpress_content', (POWERPRESS_CONTENT_ACTION_PRIORITY - 1) );
add_filter('the_content', 'powerpress_content', POWERPRESS_CONTENT_ACTION_PRIORITY);
add_filter('the_excerpt', 'powerpress_content', POWERPRESS_CONTENT_ACTION_PRIORITY);
@@ -2435,4 +2419,4 @@
register_activation_hook( __FILE__, 'powerpress_admin_activate' );
}
-?>
\ No newline at end of file
+?>
@amandato
Copy link

This removes the ability to add a player and download links to excerpt only pages. It also is a problem for when get_the_excerpt() is called and there's actually and excerpt for the post/page, in that case the_content is never called.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment