functions.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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_content_width() {
  76. $GLOBALS['content_width'] = apply_filters( 'hp_content_width', 1170 );
  77. }
  78. add_action( 'after_setup_theme', 'hp_content_width', 0 );
  79. function hp_widgets_init() {
  80. register_sidebar( array(
  81. 'name' => esc_html__( 'Sidebar', 'hp-theme' ),
  82. 'id' => 'sidebar-1',
  83. 'description' => esc_html__( 'Add widgets here.', 'hp-theme' ),
  84. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  85. 'after_widget' => '</section>',
  86. 'before_title' => '<h3 class="widget-title">',
  87. 'after_title' => '</h3>',
  88. ) );
  89. register_sidebar( array(
  90. 'name' => esc_html__( 'Footer 1', 'hp-theme' ),
  91. 'id' => 'footer-1',
  92. 'description' => esc_html__( 'Add widgets here.', 'hp-theme' ),
  93. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  94. 'after_widget' => '</section>',
  95. 'before_title' => '<h3 class="widget-title">',
  96. 'after_title' => '</h3>',
  97. ) );
  98. register_sidebar( array(
  99. 'name' => esc_html__( 'Footer 2', 'hp-theme' ),
  100. 'id' => 'footer-2',
  101. 'description' => esc_html__( 'Add widgets here.', 'hp-theme' ),
  102. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  103. 'after_widget' => '</section>',
  104. 'before_title' => '<h3 class="widget-title">',
  105. 'after_title' => '</h3>',
  106. ) );
  107. register_sidebar( array(
  108. 'name' => esc_html__( 'Footer 3', 'hp-theme' ),
  109. 'id' => 'footer-3',
  110. 'description' => esc_html__( 'Add widgets here.', 'hp-theme' ),
  111. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  112. 'after_widget' => '</section>',
  113. 'before_title' => '<h3 class="widget-title">',
  114. 'after_title' => '</h3>',
  115. ) );
  116. }
  117. add_action( 'widgets_init', 'hp_widgets_init' );
  118. /**********************************
  119. ######## Gutenberg Editor #########
  120. ***********************************/
  121. function hp_add_editor_styles() {
  122. add_editor_style([
  123. 'css/custom.css',
  124. 'style.css'
  125. ] );
  126. }
  127. add_action( 'admin_init', 'hp_add_editor_styles' );
  128. function hp_gutenberg_scripts() {
  129. 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 );
  130. }
  131. add_action( 'enqueue_block_editor_assets', 'hp_gutenberg_scripts' );
  132. function hp_gutenberg_style() {
  133. 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>';
  134. }
  135. add_action('admin_head', 'hp_gutenberg_style');
  136. add_filter( 'render_block', function( $block_content, $block ) {
  137. $block_content = str_replace(
  138. 'wp-block-button__link',
  139. 'wp-block-button__link btn',
  140. $block_content
  141. );
  142. return $block_content;
  143. }, 5, 2 );
  144. /**********************************
  145. ###### Seamless Donations #########
  146. ***********************************/
  147. function hp_seamless_style() {
  148. if ( !is_page('donate') ) {
  149. wp_deregister_style('seamless_donations_css');
  150. }
  151. }
  152. add_action('wp_print_styles', 'hp_seamless_style', 100);
  153. function hp_seamless_scripts() {
  154. if ( !is_page('donate') ) {
  155. wp_dequeue_script( 'seamless_javascript_code' );
  156. wp_deregister_script( 'seamless_javascript_code' );
  157. wp_dequeue_script( 'seamless_javascript_uuid' );
  158. wp_deregister_script( 'seamless_javascript_uuid' );
  159. }
  160. }
  161. add_action( 'wp_enqueue_scripts', 'hp_seamless_scripts', 100);
  162. function hp_seamless_script() {
  163. if ( is_page(200) ) { ?>
  164. <script type="text/javascript">
  165. document.getElementById("dgx-donate-designated").checked = true;
  166. jQuery(document).ready(function($){
  167. $('.specific-fund').show();
  168. });
  169. </script>
  170. <div data-reveal='.specific-fund'></div>
  171. <?php }
  172. }
  173. add_action('wp_footer', 'hp_seamless_script', 0);
  174. function hp_seamless_redirect() {
  175. if ( is_singular(['donor','donation','funds'])) {
  176. wp_redirect( 'donate', 301 );
  177. exit;
  178. }
  179. }
  180. add_action( 'template_redirect', 'hp_seamless_redirect' );