てくてくあるく

WordPress の テーマ とか プラグイン に ついて 勉強しています

貼り付けた コード を 読みやすいように 書き換えてくれる SyntaxHighlighter Evolved と いう プラグイン を 使っているのですが
Instant Articles for WP では その部分が まるごと カットされ 審査が通らなかったので 出力を どうにか 変えられないか というわけです

ただ この方法
合っているかどうか よくわからないのです

だれか 詳しい人 指摘があると 大変助かります


Instant Articles for WP – Custom


  if( class_exists( 'Instant_Articles_Post' ) ) {
    
    class Custom_Instant_Articles_Post extends Instant_Articles_Post {
      
      static function custom() {
        
        add_action( 'instant_articles_before_transform_post', function( $content ) {
          $post_content = $content->_post->post_content;
          
          // SyntaxHighlighter Evolved
          global $SyntaxHighlighter;
          if( isset( $SyntaxHighlighter ) ) {
            
            foreach( $SyntaxHighlighter->brushes as $key => $value ) {
              $post_content = str_replace( '['.$key.']', '', $post_content );
              $post_content = str_replace( '[/'.$key.']', '', $post_content );
            }
            
          }
          
          $content->_post->post_content = $post_content;
          return $content;
        }, 10, 2 );
        
      }
      
    }
    
    Custom_Instant_Articles_Post::custom();
    
  }

プラグインにして 入れても 動いたので とりあえずは 動作するみたいです


Instant Articles for WP の キャッシュ に 注意!!


fb-instant-articles / class-instant-articles-post.php : function _get_the_content()
を 見ていてわかったのですが

// Try to get the content from a transient, but only if the cached version have the same modtime.
$cache_mod_time = get_transient( 'instantarticles_mod_' . $this->_post->ID );
if ( get_post_modified_time( 'Y-m-d H:i:s', true, $this->_post->ID ) === $cache_mod_time ) {
	$content = get_transient( 'instantarticles_content_' . $this->_post->ID );
	if ( false !== $content && strlen( $content ) ) {
		return $content;
	}
}

と あるので 上記のコードを 入れただけでは 以前に作られた transient を 読まれて 反映されません

その点だけ 注意が必要でした


それがわからなくて ものすごく苦労しました

キャッシュの存在に気がついたのは 最後だったので
多分 もっと コードも簡略化できるかもしれません

だって
あれ?? ここ 変えたのに 変わらない…
違うところから フックされてるのか??
なんて事が 2箇所位 あったから…

Related Article

検索結果から固定ページを除外する

詳細へ »

FrontPage に 広告用 ウィジェットエリア を 表示させてみた

詳細へ »