functions.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <?php
  2. /**********************************
  3. ######### Setup WordPress #########
  4. ***********************************/
  5. require get_template_directory() . '/inc/hp-cleaner.php';
  6. require get_template_directory() . '/inc/hp-nav-walker.php';
  7. require get_template_directory() . '/inc/hp-templates.php';
  8. function hp_scripts() {
  9. wp_enqueue_style( 'icons', get_template_directory_uri() . '/css/bootstrap-icons.css' );
  10. wp_enqueue_style( 'sass', get_template_directory_uri() . '/css/custom.css' );
  11. wp_enqueue_style( 'style', get_stylesheet_uri() );
  12. wp_enqueue_script('jquery');
  13. wp_enqueue_script('script', get_template_directory_uri() . '/js/script.min.js', array(), '', true );
  14. wp_enqueue_script('init', get_template_directory_uri() . '/js/init.js', array(), '', true );
  15. if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  16. wp_enqueue_script( 'comment-reply' );
  17. }
  18. }
  19. add_action( 'wp_enqueue_scripts', 'hp_scripts' );
  20. if ( ! function_exists( 'hp_setup' ) ) :
  21. function hp_setup() {
  22. add_theme_support( 'automatic-feed-links' );
  23. add_theme_support( 'title-tag' );
  24. add_theme_support( 'post-thumbnails' );
  25. add_theme_support( 'nav-menus' );
  26. register_nav_menus( array(
  27. 'primary' => __( 'Primary' ),
  28. 'bottom' =>__( 'Bottom' ),
  29. 'top' =>__( 'Top' )
  30. ));
  31. add_theme_support( 'html5', array(
  32. 'search-form',
  33. 'comment-form',
  34. 'comment-list',
  35. 'caption',
  36. ));
  37. add_theme_support( 'customize-selective-refresh-widgets' );
  38. add_theme_support( 'editor-styles' );
  39. add_theme_support( 'disable-custom-colors' );
  40. add_theme_support( 'editor-color-palette', array(
  41. array(
  42. 'name' => __( 'Green' ),
  43. 'slug' => 'green',
  44. 'color' => '#325363',
  45. ),
  46. array(
  47. 'name' => __( 'Purple' ),
  48. 'slug' => 'purple',
  49. 'color' => '#343C70',
  50. ),
  51. array(
  52. 'name' => __( 'Blue' ),
  53. 'slug' => 'blue',
  54. 'color' => '#5177B0',
  55. ),
  56. array(
  57. 'name' => __( 'Red' ),
  58. 'slug' => 'red',
  59. 'color' => '#CC7C84',
  60. ),
  61. array(
  62. 'name' => __( 'Yellow' ),
  63. 'slug' => 'yellow',
  64. 'color' => '#E0DC67',
  65. ),
  66. array(
  67. 'name' => __( 'Teal' ),
  68. 'slug' => 'teal',
  69. 'color' => '#50A7AD',
  70. ),
  71. ));
  72. }
  73. endif;
  74. add_action( 'after_setup_theme', 'hp_setup' );
  75. function hp_widgets_init() {
  76. register_sidebar( array(
  77. 'name' => esc_html__( 'Sidebar', 'hp-theme' ),
  78. 'id' => 'sidebar-1',
  79. 'description' => esc_html__( 'Add widgets here.', 'hp-theme' ),
  80. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  81. 'after_widget' => '</section>',
  82. 'before_title' => '<h3 class="widget-title">',
  83. 'after_title' => '</h3>',
  84. ) );
  85. register_sidebar( array(
  86. 'name' => esc_html__( 'Footer 1', 'hp-theme' ),
  87. 'id' => 'footer-1',
  88. 'description' => esc_html__( 'Add widgets here.', 'hp-theme' ),
  89. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  90. 'after_widget' => '</section>',
  91. 'before_title' => '<h3 class="widget-title">',
  92. 'after_title' => '</h3>',
  93. ) );
  94. register_sidebar( array(
  95. 'name' => esc_html__( 'Footer 2', 'hp-theme' ),
  96. 'id' => 'footer-2',
  97. 'description' => esc_html__( 'Add widgets here.', 'hp-theme' ),
  98. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  99. 'after_widget' => '</section>',
  100. 'before_title' => '<h3 class="widget-title">',
  101. 'after_title' => '</h3>',
  102. ) );
  103. register_sidebar( array(
  104. 'name' => esc_html__( 'Footer 3', 'hp-theme' ),
  105. 'id' => 'footer-3',
  106. 'description' => esc_html__( 'Add widgets here.', 'hp-theme' ),
  107. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  108. 'after_widget' => '</section>',
  109. 'before_title' => '<h3 class="widget-title">',
  110. 'after_title' => '</h3>',
  111. ) );
  112. }
  113. add_action( 'widgets_init', 'hp_widgets_init' );
  114. /**********************************
  115. ######## Gutenberg Editor #########
  116. ***********************************/
  117. function hp_add_editor_styles() {
  118. add_editor_style([
  119. 'css/custom.css',
  120. 'style.css'
  121. ] );
  122. }
  123. add_action( 'admin_init', 'hp_add_editor_styles' );
  124. function hp_gutenberg_scripts() {
  125. wp_enqueue_script( 'hp-editor', get_stylesheet_directory_uri() . '/js/editor.js', array( 'wp-blocks', 'wp-dom' ), filemtime( get_stylesheet_directory() . '/js/editor.js' ), true );
  126. }
  127. add_action( 'enqueue_block_editor_assets', 'hp_gutenberg_scripts' );
  128. function hp_gutenberg_style() {
  129. echo '<style>.wp-block{max-width:992px;}.wp-block[data-align="wide"]{}.wp-block[data-align="full"]{max-width:none;}.editor-post-title__block .editor-post-title__input,.edit-post-visual-editor, .edit-post-visual-editor p{font-family: Helvetica, Arial, sans-serif;}</style>';
  130. }
  131. add_action('admin_head', 'hp_gutenberg_style');
  132. add_filter( 'render_block', function( $block_content, $block ) {
  133. $block_content = str_replace(
  134. 'wp-block-button__link',
  135. 'wp-block-button__link btn',
  136. $block_content
  137. );
  138. return $block_content;
  139. }, 5, 2 );
  140. /**********************************
  141. ###### Seamless Donations #########
  142. ***********************************/
  143. function hp_seamless_style() {
  144. if ( !is_page('donate') ) {
  145. wp_deregister_style('seamless_donations_css');
  146. }
  147. }
  148. add_action('wp_print_styles', 'hp_seamless_style', 100);
  149. function hp_seamless_scripts() {
  150. if ( !is_page('donate') ) {
  151. wp_dequeue_script( 'seamless_javascript_code' );
  152. wp_deregister_script( 'seamless_javascript_code' );
  153. wp_dequeue_script( 'seamless_javascript_uuid' );
  154. wp_deregister_script( 'seamless_javascript_uuid' );
  155. }
  156. }
  157. add_action( 'wp_enqueue_scripts', 'hp_seamless_scripts', 100);
  158. function hp_seamless_script() {
  159. if ( is_page(200) ) { ?>
  160. <script type="text/javascript">
  161. document.getElementById("dgx-donate-designated").checked = true;
  162. jQuery(document).ready(function($){
  163. $('.specific-fund').show();
  164. });
  165. </script>
  166. <div data-reveal='.specific-fund'></div>
  167. <?php }
  168. }
  169. add_action('wp_footer', 'hp_seamless_script', 0);
  170. function hp_seamless_redirect() {
  171. if ( is_singular(['donor','donation','funds'])) {
  172. wp_redirect( 'donate', 301 );
  173. exit;
  174. }
  175. }
  176. add_action( 'template_redirect', 'hp_seamless_redirect' );
  177. function hp_exclude_seamless_post_type($query) {
  178. if(is_admin() || !$query->is_main_query()) return;
  179. if($query->is_search()) {
  180. $post_type_to_remove = 'funds';
  181. $searchable = get_post_types(array('exclude_from_search' => false));
  182. if(is_array($searchable) && in_array($post_type_to_remove, $searchable)){
  183. $query->set('post_type', $searchable);
  184. }
  185. }
  186. }
  187. add_action('pre_get_posts', 'hp_exclude_seamless_post_type', 99 );
  188. function hp_remove_fund_custom_type() {
  189. global $wp_post_types;
  190. $wp_post_types['funds']->exclude_from_search = true;
  191. }
  192. add_action( 'init', 'hp_remove_fund_custom_type', 99 );
  193. function hp_remove_donor_custom_type() {
  194. global $wp_post_types;
  195. $wp_post_types['donor']->exclude_from_search = true;
  196. }
  197. add_action( 'init', 'hp_remove_donor_custom_type', 99 );