functions.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <?php
  2. /***********************************************************
  3. #################### Setup WordPress #######################
  4. ************************************************************/
  5. require get_theme_file_path( '/inc/smtp.php' );
  6. //require get_template_directory() . '/inc/smtp.php';
  7. function wpmu_list_sites() {
  8. $subsites = get_sites();
  9. if ( ! empty ( $subsites ) ) {
  10. echo '<ul class="subsites">';
  11. foreach( $subsites as $subsite ) {
  12. $subsite_id = get_object_vars( $subsite )["blog_id"];
  13. $subsite_name = get_blog_details( $subsite_id )->blogname;
  14. $subsite_link = get_blog_details( $subsite_id )->siteurl;
  15. echo '<li class="site-' . $subsite_id . '"><a href="' . $subsite_link . '">' . $subsite_name . '</a></li>';
  16. }
  17. echo '</ul>';
  18. }
  19. }
  20. function hbr_global_menu() {
  21. if (!in_array(get_current_blog_id(), array(2))){ //display on these subsites only
  22. switch_to_blog( '1' );
  23. if (is_nav_menu(8)){
  24. wp_nav_menu( ['menu' => '8', 'menu_class' => 'hbr-global-menu',]);
  25. }
  26. restore_current_blog();
  27. }
  28. }
  29. /*************************************************
  30. // ######### Child Theme (& Editor) ############ //
  31. **************************************************/
  32. function twentytwentyone_styles() {
  33. wp_enqueue_style( 'child-style', get_stylesheet_uri(),
  34. array( 'twenty-twenty-one-style' ), wp_get_theme()->get('Version') );
  35. }
  36. add_action( 'wp_enqueue_scripts', 'twentytwentyone_styles');
  37. function hbr_add_editor_styles() {
  38. add_editor_style( 'style-editor.css' );
  39. }
  40. add_action( 'admin_init', 'hbr_add_editor_styles' );
  41. function hbr_theme_setup() {
  42. add_theme_support( 'align-wide' );
  43. add_theme_support( 'editor-color-palette', array (
  44. array(
  45. 'name' => esc_attr__( 'black', 'hbr' ),
  46. 'slug' => 'black',
  47. 'color' => '#000000',
  48. ),
  49. array(
  50. 'name' => esc_attr__( 'white', 'hbr' ),
  51. 'slug' => 'white',
  52. 'color' => '#ffffff',
  53. ),
  54. array(
  55. 'name' => esc_attr__( 'dark grey', 'hbr' ),
  56. 'slug' => 'darkgrey',
  57. 'color' => '#8F887B',
  58. ),
  59. array(
  60. 'name' => esc_attr__( 'blue grey', 'hbr' ),
  61. 'slug' => 'bluegrey',
  62. 'color' => '#303740',
  63. ),
  64. array(
  65. 'name' => esc_attr__( 'brown grey', 'hbr' ),
  66. 'slug' => 'browngrey',
  67. 'color' => '#3d3d3d',
  68. ),
  69. array(
  70. 'name' => esc_attr__( 'brown', 'hbr' ),
  71. 'slug' => 'brown',
  72. 'color' => '#5C584F',
  73. ),
  74. array(
  75. 'name' => esc_attr__( 'dark brown', 'hbr' ),
  76. 'slug' => 'darkbrown',
  77. 'color' => '#4F4E4C',
  78. ),
  79. array(
  80. 'name' => esc_attr__( 'paper', 'hbr' ),
  81. 'slug' => 'paper',
  82. 'color' => '#DBD8D3',
  83. ),
  84. array(
  85. 'name' => esc_attr__( 'tan', 'hbr' ),
  86. 'slug' => 'tan',
  87. 'color' => '#BDB3A2',
  88. ),
  89. array(
  90. 'name' => esc_attr__( 'med grey', 'hbr' ),
  91. 'slug' => 'medgrey',
  92. 'color' => '#7A7A7A',
  93. ),
  94. array(
  95. 'name' => esc_attr__( 'light blue', 'hbr' ),
  96. 'slug' => 'lightblue',
  97. 'color' => '#6D7F8F',
  98. ),
  99. array(
  100. 'name' => esc_attr__( 'grey', 'hbr' ),
  101. 'slug' => 'grey',
  102. 'color' => '#B8BCBF',
  103. ),
  104. ));
  105. }
  106. add_action( 'after_setup_theme', 'hbr_theme_setup', 30 );
  107. /*************************************************
  108. // ############### wp_head ################## //
  109. **************************************************/
  110. remove_action('wp_head', 'index_rel_link' );
  111. remove_action('wp_head', 'rel_canonical');
  112. remove_action('wp_head', 'start_post_rel_link', 10);
  113. remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10);
  114. remove_action('wp_head', 'wp_shortlink_wp_head', 10);
  115. remove_action('wp_head', 'parent_post_rel_link', 10);
  116. remove_action('wp_head', 'rsd_link');
  117. remove_action('wp_head', 'wlwmanifest_link');
  118. remove_action('wp_head', 'wp_generator');
  119. remove_action('wp_head', 'feed_links_extra', 3 );
  120. remove_action('wp_head', 'feed_links', 2 );
  121. //remove_action('wp_head', 'wp_oembed_add_discovery_links', 10);
  122. //remove_action('wp_head', 'wp_oembed_add_host_js', 10);
  123. //remove_action('wp_head', 'rest_output_link_wp_head', 10);
  124. //remove_action('template_redirect', 'rest_output_link_header', 11, 0);
  125. add_filter( 'style_loader_src', 'hbr_remove_wp_ver_css_js', 9999 );
  126. function hbr_remove_wp_ver_css_js( $src ) {
  127. if ( strpos( $src, 'ver=' ) )
  128. $src = remove_query_arg( 'ver', $src );
  129. return $src;
  130. }
  131. add_filter( 'xmlrpc_enabled', '__return_false' );
  132. add_filter( 'wp_headers', 'hbr_disable_x_pingback' );
  133. function hbr_disable_x_pingback( $headers ) {
  134. unset( $headers['X-Pingback'] );
  135. return $headers;
  136. }
  137. /*************************************************
  138. // ############ Dashboard items ################ //
  139. **************************************************/
  140. remove_action('welcome_panel', 'wp_welcome_panel');
  141. //add_filter('screen_options_show_screen', '__return_false');
  142. add_action('admin_head', 'hbr_remove_help_tabs');
  143. function hbr_remove_help_tabs() {
  144. $screen = get_current_screen();
  145. $screen->remove_help_tabs();
  146. }
  147. add_action( 'admin_init', 'hbr_remove_dashboard_meta' );
  148. function hbr_remove_dashboard_meta() {
  149. remove_meta_box( 'wp_mail_smtp_reports_widget_lite', 'dashboard', 'normal' );
  150. remove_meta_box( 'dashboard_site_health', 'dashboard', 'normal' );
  151. remove_meta_box( 'dashboard_incoming_links', 'dashboard', 'normal' );
  152. remove_meta_box( 'dashboard_plugins', 'dashboard', 'normal' );
  153. remove_meta_box( 'dashboard_primary', 'dashboard', 'normal' );
  154. remove_meta_box( 'dashboard_secondary', 'dashboard', 'normal' );
  155. remove_meta_box( 'dashboard_incoming_links', 'dashboard', 'normal' );
  156. remove_meta_box( 'dashboard_quick_press', 'dashboard', 'side' );
  157. }
  158. /*************************************************
  159. // ############## Admin pages ################ //
  160. **************************************************/
  161. add_action( 'admin_menu', 'hbr_remove_admin_pages', 99 );
  162. function hbr_remove_admin_pages() {
  163. remove_menu_page( 'edit-comments.php' );
  164. //remove_submenu_page('edit.php', 'edit-tags.php?taxonomy=post_tag');
  165. //remove_menu_page( 'themes.php' );
  166. //remove_menu_page( 'plugins.php' );
  167. //remove_menu_page( 'tools.php' );
  168. //remove_menu_page( 'options-general.php' );
  169. //remove_menu_page( 'wp-mail-smtp' );
  170. }
  171. /*************************************************
  172. // ############# Admin Bar ################## //
  173. **************************************************/
  174. add_filter('show_admin_bar', '__return_false');
  175. add_filter('show_recent_comments_widget_style', function() { return false; });
  176. add_action( 'admin_bar_menu', 'hbr_remove_adminbar', 999 );
  177. function hbr_remove_adminbar( $wp_admin_bar ) {
  178. $wp_admin_bar->remove_node( 'wp-logo' );
  179. $wp_admin_bar->remove_node( 'updates' );
  180. $wp_admin_bar->remove_menu( 'comments' );
  181. $wp_admin_bar->remove_menu( 'customize' );
  182. $wp_admin_bar->remove_menu( 'new-content' );
  183. $wp_admin_bar->remove_menu( 'edit' );
  184. $wp_admin_bar->remove_menu( 'new-user' );
  185. $wp_admin_bar->remove_menu( 'new-post' );
  186. $wp_admin_bar->remove_menu( 'new-page' );
  187. $wp_admin_bar->remove_node( 'new-media' );
  188. $wp_admin_bar->remove_menu( 'comments' );
  189. $wp_admin_bar->remove_node( 'view-site' );
  190. $wp_admin_bar->remove_menu( 'edit-profile' );
  191. }
  192. /*************************************************
  193. // ############ Admin footer ############## //
  194. **************************************************/
  195. add_filter('admin_footer_text', '__return_empty_string', 1000);
  196. add_filter('update_footer', '__return_empty_string', 1000);
  197. /*************************************************
  198. // ########## Howdy email/adminbar ############# //
  199. **************************************************/
  200. add_filter( 'gettext', 'hbr_change_howdy_text', 10, 2 );
  201. function hbr_change_howdy_text( $translation, $original ) {
  202. if( 'Howdy, %1$s' == $original )
  203. $translation = '%1$s';
  204. return $translation;
  205. }
  206. add_filter( 'admin_bar_menu', 'hbr_replace_howdy', 25 );
  207. function hbr_replace_howdy( $wp_admin_bar ) {
  208. $my_account = $wp_admin_bar->get_node('my-account');
  209. $newtext = str_replace( 'Howdy,', '', $my_account->title );
  210. $wp_admin_bar->add_node( array(
  211. 'id' => 'my-account',
  212. 'title' => $newtext,
  213. ) );
  214. }
  215. /***********************************************************
  216. ###################### Last Login ##########################
  217. ************************************************************/
  218. add_action( 'wp_login', 'hbr_login_timestamp', 20, 2 );
  219. function hbr_login_timestamp( $user_login, $user ) {
  220. update_user_meta( $user->ID, 'last_login', time() );
  221. }
  222. add_filter( 'manage_users_columns', 'hbr_user_last_login_column' );
  223. function hbr_user_last_login_column( $columns ) {
  224. $columns['last_login'] = 'Last Login'; // column ID / column Title
  225. return $columns;
  226. }
  227. add_filter( 'manage_users_custom_column', 'hbr_last_login_column', 10, 3 );
  228. function hbr_last_login_column( $output, $column_id, $user_id ){
  229. if( $column_id == 'last_login' ) {
  230. $last_login = get_user_meta( $user_id, 'last_login', true );
  231. $date_format = 'j M, Y';
  232. $output = $last_login ? date( $date_format, $last_login ) : '-';
  233. }
  234. return $output;
  235. }
  236. add_filter( 'manage_users_sortable_columns', 'hbr_sortable_columns' );
  237. function hbr_sortable_columns( $columns ) {
  238. return wp_parse_args( array(
  239. 'last_login' => 'last_login'
  240. ), $columns );
  241. }
  242. add_action( 'pre_get_users', 'hbr_sort_last_login_column' );
  243. function hbr_sort_last_login_column( $query ) {
  244. if( !is_admin() ) { return; }
  245. $orderby = $query->get('orderby');
  246. if( 'last_login' == $orderby ) {
  247. $query->set('meta_key','last_login');
  248. $query->set('orderby','meta_value');
  249. }
  250. return $query;
  251. }
  252. add_filter( 'wpmu_users_columns', 'hbr_user_last_login_column' );