theme.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <?php
  2. /*************************************************
  3. // ######### cleanup migration ################ //
  4. **************************************************/
  5. add_action('set_current_user', 'hp_hide_admin_bar');
  6. function hp_hide_admin_bar() {
  7. show_admin_bar(false);
  8. }
  9. function hp_remove_comment_support() {
  10. remove_post_type_support( 'post', 'comments' );
  11. remove_post_type_support( 'page', 'comments' );
  12. }
  13. add_action('init', 'hp_remove_comment_support', 100);
  14. function hp_filter_media_comment_status( $open, $post_id ) {
  15. $post = get_post( $post_id );
  16. if( $post->post_type == 'attachment' ) {
  17. return false;
  18. }
  19. return $open;
  20. }
  21. add_filter( 'comments_open', 'hp_filter_media_comment_status', 10 , 2 );
  22. function hp_remove_default_img_sizes( $sizes ) {
  23. $targets = ['medium_large', '1536x1536', '2048x2048'];
  24. foreach($sizes as $size_index=>$size) {
  25. if(in_array($size, $targets)) {
  26. unset($sizes[$size_index]);
  27. }
  28. }
  29. return $sizes;
  30. }
  31. add_filter( 'intermediate_image_sizes', 'hp_remove_default_img_sizes', 10, 1);
  32. /****************************************
  33. // ########## Theme Setup ############ //
  34. *****************************************/
  35. function hp_theme_setup() {
  36. add_theme_support( 'disable-custom-colors' );
  37. add_theme_support( 'editor-color-palette', array(
  38. array(
  39. 'name' => __( 'Green' ),
  40. 'slug' => 'green',
  41. 'color' => '#325363',
  42. ),
  43. array(
  44. 'name' => __( 'Purple' ),
  45. 'slug' => 'purple',
  46. 'color' => '#343C70',
  47. ),
  48. array(
  49. 'name' => __( 'Blue' ),
  50. 'slug' => 'blue',
  51. 'color' => '#5177B0',
  52. ),
  53. array(
  54. 'name' => __( 'Red' ),
  55. 'slug' => 'red',
  56. 'color' => '#CC7C84',
  57. ),
  58. array(
  59. 'name' => __( 'Yellow' ),
  60. 'slug' => 'yellow',
  61. 'color' => '#E0DC67',
  62. ),
  63. array(
  64. 'name' => __( 'Teal' ),
  65. 'slug' => 'teal',
  66. 'color' => '#50A7AD',
  67. )
  68. ));
  69. }
  70. add_action( 'after_setup_theme', 'hp_theme_setup' );
  71. /*******************************************
  72. // ######### Recent News Widget ######### //
  73. *******************************************/
  74. class HP_News_Widget extends WP_Widget {
  75. public function __construct() {
  76. $options = array(
  77. 'classname' => 'news-widget',
  78. 'description' => 'News Widget',
  79. 'customize_selective_refresh' => true,
  80. );
  81. parent::__construct(
  82. 'news-widget', 'News Widget', $options
  83. );
  84. }
  85. public function widget( $args, $instance ) {
  86. $q_args = array(
  87. 'post_type' => 'post',
  88. 'posts_per_page' => '2'
  89. );
  90. $query = new WP_Query( $q_args );
  91. while ($query->have_posts()) {
  92. $query->the_post();
  93. echo $args['before_widget'];
  94. echo $args['before_title'] . apply_filters( 'widget_title', 'News' ) . $args['after_title'];
  95. the_title();
  96. echo get_the_excerpt();
  97. echo $args['after_widget'];
  98. }
  99. wp_reset_postdata();
  100. }
  101. }
  102. function hp_register_news_widget() {
  103. register_widget( 'HP_News_Widget' );
  104. }
  105. add_action( 'widgets_init', 'hp_register_news_widget' );
  106. /*******************************************
  107. // ######### Donation Menu Item ######### //
  108. *******************************************/
  109. function hp_donate_nav_item( $items, $args ) {
  110. if( $args->theme_location == 'primary' ) {
  111. $items = $items .'<li id="donate-button" class="menu-item nav-item ps-lg-3">'."\n".'<a class="btn btn-outline-light" href="'.home_url().'/get-involved/donate" role="button">Donate <i class="bi bi-suit-heart-fill p-1 text-danger"></i></a></li>';
  112. }
  113. return $items;
  114. }
  115. add_filter('wp_nav_menu_items','hp_donate_nav_item',10,2);
  116. /*************************************
  117. ######### Seamless Donations #########
  118. **************************************/
  119. function hp_seamless_style() {
  120. if ( !is_page('donate') ) {
  121. wp_deregister_style('seamless_donations_css');
  122. }
  123. }
  124. add_action('wp_print_styles', 'hp_seamless_style', 100);
  125. function hp_seamless_scripts() {
  126. if ( !is_page('donate') ) {
  127. wp_dequeue_script( 'seamless_javascript_code' );
  128. wp_deregister_script( 'seamless_javascript_code' );
  129. wp_dequeue_script( 'seamless_javascript_uuid' );
  130. wp_deregister_script( 'seamless_javascript_uuid' );
  131. }
  132. }
  133. add_action( 'wp_enqueue_scripts', 'hp_seamless_scripts', 100);
  134. function hp_seamless_script() {
  135. if ( is_page(200) ) { ?>
  136. <script type="text/javascript">
  137. document.getElementById("dgx-donate-designated").checked = true;
  138. jQuery(document).ready(function($){
  139. $('.specific-fund').show();
  140. });
  141. </script>
  142. <div data-reveal='.specific-fund'></div>
  143. <?php }
  144. }
  145. add_action('wp_footer', 'hp_seamless_script', 0);
  146. function hp_seamless_redirect() {
  147. if ( is_singular(['donor','donation','funds'])) {
  148. wp_redirect( 'donate', 301 );
  149. exit;
  150. }
  151. }
  152. add_action( 'template_redirect', 'hp_seamless_redirect' );
  153. function hp_exclude_seamless_post_type($query) {
  154. if(is_admin() || !$query->is_main_query()) return;
  155. if($query->is_search()) {
  156. $post_type_to_remove = 'funds';
  157. $searchable = get_post_types(array('exclude_from_search' => false));
  158. if(is_array($searchable) && in_array($post_type_to_remove, $searchable)){
  159. $query->set('post_type', $searchable);
  160. }
  161. }
  162. }
  163. add_action('pre_get_posts', 'hp_exclude_seamless_post_type', 99 );
  164. function hp_remove_fund_custom_type() {
  165. global $wp_post_types;
  166. $wp_post_types['funds']->exclude_from_search = true;
  167. }
  168. add_action( 'init', 'hp_remove_fund_custom_type', 99 );
  169. function hp_remove_donor_custom_type() {
  170. global $wp_post_types;
  171. $wp_post_types['donor']->exclude_from_search = true;
  172. }
  173. add_action( 'init', 'hp_remove_donor_custom_type', 99 );