PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/functions.php

https://gitlab.com/kishikeisuke/estatesale
PHP | 183 lines | 123 code | 17 blank | 43 comment | 28 complexity | cf37a1d5b830487cba522b87c794f18a MD5 | raw file
  1. <?php
  2. /**
  3. * WpTHK WordPress Theme - free/libre wordpress platform
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * @copyright Copyright (C) 2015 Thought is free.
  11. * @license http://www.gnu.org/licenses/gpl-2.0.html GPL v2 or later
  12. * @author LunaNuko
  13. * @link http://thk.kanzae.net/
  14. * @translators rakeem( http://rakeem.jp/ )
  15. */
  16. // WordPress の例の定数を使うとチェックで怒られるので再定義
  17. define( 'TPATH', get_template_directory() );
  18. define( 'SPATH', get_stylesheet_directory() );
  19. define( 'DSEP' , DIRECTORY_SEPARATOR );
  20. define( 'INC' , TPATH . DSEP . 'inc' . DSEP );
  21. /*---------------------------------------------------------------------------
  22. * WpTHK Theme only works in PHP 5.3 or later.
  23. * WpTHK Theme only works in WordPress 4.4 or later.
  24. *---------------------------------------------------------------------------*/
  25. if(
  26. version_compare( PHP_VERSION, '5.3', '<' ) === true ||
  27. version_compare( $GLOBALS['wp_version'], '4.4-alpha', '<' ) === true
  28. ) {
  29. require( INC . 'back-compat.php' );
  30. }
  31. /*---------------------------------------------------------------------------
  32. * global
  33. *---------------------------------------------------------------------------*/
  34. $wpthk = array();
  35. if( is_admin() === true && current_user_can( 'edit_posts' ) === true ) {
  36. load_theme_textdomain( 'wpthk', TPATH . DSEP . 'languages' . DSEP . 'admin' );
  37. }
  38. else {
  39. load_theme_textdomain( 'wpthk', TPATH . DSEP . 'languages' . DSEP . 'site' );
  40. }
  41. require( INC . 'wpfunc.php' );
  42. require( INC . 'widget.php' );
  43. require( INC . 'stinger.php' );
  44. require( INC . 'sns-cache.php' );
  45. if( is_customize_preview() === true ) {
  46. require( INC . 'custom.php' );
  47. require( INC . 'custom-css.php' );
  48. require( INC . 'compress.php' );
  49. }
  50. elseif( is_admin() === true ) {
  51. if( current_user_can( 'edit_theme_options' ) === true ) {
  52. require( INC . 'admin-func.php' );
  53. $referer = wp_get_raw_referer();
  54. if( stripos( (string)$referer, 'wp-admin/widgets.php' ) !== false ) {
  55. if( stripos( $_SERVER['REQUEST_URI'], 'wp-admin/admin-ajax.php' ) !== false ) {
  56. thk_options_modify();
  57. }
  58. }
  59. }
  60. if( current_user_can( 'edit_posts' ) === true ) {
  61. require( INC . 'og-img-admin.php' );
  62. require( INC . 'post-update-level.php');
  63. add_editor_style( array( 'css/bootstrap.min.css', 'editor-style.css' ) );
  64. }
  65. }
  66. /*---------------------------------------------------------------------------
  67. * initialization
  68. *---------------------------------------------------------------------------*/
  69. add_action( 'init', function() {
  70. add_theme_support( 'title-tag' );
  71. add_theme_support( 'post-thumbnails' );
  72. add_theme_support( 'automatic-feed-links' );
  73. add_theme_support( 'editor-style' );
  74. register_nav_menus( array('global-nav' => __( 'Header Nav (Global Nav)', 'wpthk' ) ) );
  75. register_nav_menus( array('head-band' => __( 'Header Band Menu', 'wpthk' ) ) );
  76. } );
  77. /*---------------------------------------------------------------------------
  78. * pre get posts
  79. *---------------------------------------------------------------------------*/
  80. add_action( 'pre_get_posts', function() {
  81. global $wpthk;
  82. if( is_search() === true ) {
  83. get_template_part( 'inc/search-func' );
  84. thk_search_extend();
  85. }
  86. } );
  87. /*---------------------------------------------------------------------------
  88. * wp
  89. *---------------------------------------------------------------------------*/
  90. add_action( 'wp', function() {
  91. global $wpthk;
  92. if( is_admin() === false ) require_once( INC . 'const.php' );
  93. if( is_singular() === true ) wp_enqueue_script( 'comment-reply' );
  94. if( isset( $wpthk['sns_count_cache_enable'] ) && is_preview() === false && is_customize_preview() === false ) {
  95. if(
  96. ( is_singular() === true &&
  97. ( isset( $wpthk['sns_count_cache_force'] ) || (
  98. ( isset( $wpthk['sns_tops_enable'] ) && isset( $wpthk['sns_tops_count'] ) ) ||
  99. ( isset( $wpthk['sns_bottoms_enable'] ) && isset( $wpthk['sns_bottoms_count'] ) ) ) ) ) ||
  100. ( is_home() === true &&
  101. ( isset( $wpthk['sns_count_cache_force'] ) || (
  102. ( isset( $wpthk['sns_toppage_view'] ) && isset( $wpthk['sns_bottoms_count'] ) ) ) ) )
  103. ) {
  104. add_filter( 'template_redirect', 'touch_sns_count_cache', 10 );
  105. add_filter( 'shutdown', 'set_transient_sns_count_cache', 90 );
  106. add_filter( 'shutdown', 'set_transient_sns_count_cache_weekly_cleanup', 95 );
  107. if(
  108. isset( $wpthk['sns_count_cache_force'] ) ||
  109. isset( $wpthk['feedly_share_tops_button'] ) || isset( $wpthk['feedly_share_bottoms_button'] )
  110. ) {
  111. add_filter( 'template_redirect', 'touch_feedly_cache', 10 );
  112. add_filter( 'shutdown', 'transient_register_feedly_cache', 90 );
  113. }
  114. }
  115. }
  116. } );
  117. /*---------------------------------------------------------------------------
  118. * template redirect
  119. *---------------------------------------------------------------------------*/
  120. add_action( 'template_redirect', function() {
  121. if( is_feed() === true ) return;
  122. if(
  123. is_home() === true ||
  124. is_singular() === true ||
  125. is_archive() === true ||
  126. is_search() === true ||
  127. is_404() === true
  128. ) {
  129. require( INC . 'load_styles.php' );
  130. require( INC . 'description.php' );
  131. require( INC . 'load-header.php' );
  132. }
  133. }, 99 );
  134. /*---------------------------------------------------------------------------
  135. * 指定年からの経過年を返す:追加
  136. *---------------------------------------------------------------------------*/
  137. function get_progress_date($atts) {
  138. extract(shortcode_atts(array(
  139. 'year' => 0,
  140. ), $atts));
  141. return date("Y") - $year;
  142. }
  143. add_shortcode('get_progress_date', 'get_progress_date');
  144. /*---------------------------------------------------------------------------
  145. * 投稿ページ以外ではhentryクラスを削除:追加
  146. *---------------------------------------------------------------------------*/
  147. function remove_hentry( $classes ) {
  148. if ( !is_single() ) {
  149. $classes = array_diff($classes, array('hentry'));
  150. }
  151. //これらのクラスが含まれたページではhentryを削除する
  152. $ng_classes = array('type-forum', 'type-topic');//ここに追加していく
  153. $is_include = false;
  154. foreach ($ng_classes as $ng_class) {
  155. //NGのクラス名が含まれていないか調べる
  156. if ( in_array($ng_class, $classes) ) {
  157. $is_include = true;
  158. }
  159. }
  160. //含まれていたらhentryを削除する
  161. if ($is_include) {
  162. $classes = array_diff($classes, array('hentry'));
  163. }
  164. return $classes;
  165. }
  166. add_filter('post_class', 'remove_hentry');