ショートコードで 注意文を出す
この記事は 2015年 3月 10日 に書かれた記事です。
この記事は WordPress Version 4.1.1 の時の記事です。
WordPressの記事が古かったり WordPressのバージョンが異なっていた場合
注意文を出すようにしました
テキストエディタに ショートカットボタンも追加したので
使いやすいかと
I referred to かちびと.net.
http://kachibito.net/wp-code/notify-of-old-post-in-front-end
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | <?php //--------------------------------------------------------------------------- // テキストエディタへ ショートカットボタン追加 //--------------------------------------------------------------------------- add_action( 'admin_print_footer_scripts' , function () { if ( wp_script_is( 'quicktags' ) ) { ?> <script> // WordPress Version Alert QTags.addButton( 'post_date' , 'Post Date' , '[[jr_post_date]]' ); // WordPress Version Alert QTags.addButton( 'wp_version' , 'Version' , '[[jr_wp_version version=""]]' ); </script> <?php } } ); //--------------------------------------------------------------------------- // Post Date Alert //--------------------------------------------------------------------------- add_shortcode( 'post_date' , function () { if ( date ( 'U' ) - get_the_time( 'U' ) > 60*60*24*365*2 ) { if ( date ( 'U' ) - get_the_modified_date( 'U' ) > 60*60*24*180 ) { $return = '<div class="alert alert-danger" role="alert">この記事は ' . get_the_time( 'Y年 n月 j日' ) . ' に書かれた記事です。</div>' . PHP_EOL; } else { $return = '<div class="alert alert-warning" role="alert">この記事は ' . get_the_time( 'Y年 n月 j日' ) . ' に書かれた記事です。<br>しかし、180日以内に修正が加えられています。</div>' . PHP_EOL; } } return $return ; } ); //--------------------------------------------------------------------------- // WordPress Version Alert //--------------------------------------------------------------------------- add_shortcode( 'wp_version' , function ( $atts ) { extract( shortcode_atts( array ( 'version' => '1.0' , ), $atts ) ); if ( version_compare( $GLOBALS [ 'wp_version' ], $version , '>' ) ) { $return = '<div class="alert alert-warning" role="alert">この記事は WordPress バージョン ' . $version . ' の時の記事です。</div>' . PHP_EOL; } return $return ; } ); |