functions.php 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. <?php
  2. function uhp24_styles() {
  3. wp_enqueue_style(
  4. 'uhp-style',
  5. get_stylesheet_uri(),
  6. [],
  7. wp_get_theme()->get( 'Version' )
  8. );
  9. }
  10. add_action( 'wp_enqueue_scripts', 'uhp24_styles' );
  11. /***********************************************************
  12. ###################### BrowserSync #########################
  13. ************************************************************/
  14. function add_cors_http_header(){
  15. header('Access-Control-Allow-Origin: https://uhp.ovid:333');
  16. header('Access-Control-Allow-Credentials: true');
  17. header('Access-Control-Allow-Headers: X-WP-Nonce', false );
  18. }
  19. add_action('init','add_cors_http_header');
  20. function uhp24_browsersync_save() {
  21. $args = [
  22. 'blocking' => false,
  23. 'sslverify' => false
  24. ];
  25. $request = wp_remote_get('https://uhp.ovid:333/__browser_sync__?method=reload', $args);
  26. }
  27. add_action('rest_after_insert_page', 'uhp24_browsersync_save', 10, 3);
  28. add_action('rest_after_insert_post', 'uhp24_browsersync_save', 10, 3);
  29. add_action('save_post', 'uhp24_browsersync_save', 10, 3);
  30. add_action('customize_save_after', 'uhp24_browsersync_save', 10, 3);
  31. add_action('wp_update_nav_menu', 'uhp24_browsersync_save', 10, 3);
  32. add_action('updated_option', 'uhp24_browsersync_save', 10, 3);
  33. /***********************************************************
  34. ######################### Admin ############################
  35. ************************************************************/
  36. add_filter( 'show_admin_bar', '__return_false' );
  37. add_action( 'login_enqueue_scripts', 'uhp24_login_logo' );
  38. function uhp24_login_logo() {
  39. $logo_image = wp_get_attachment_image_src( get_theme_mod( 'custom_logo' ), 'full' );
  40. ?>
  41. <style type="text/css">
  42. #login h1 a, .login h1 a {
  43. background-image: url(<?php echo esc_url( $logo_image[0] ); ?>);
  44. background-size:cover;
  45. height:110px;
  46. width:320px;
  47. }
  48. body.login {
  49. background-color: #0F1B44 !important;
  50. }
  51. .login #nav a {
  52. color: #E9E4DC !important;
  53. }
  54. .login #backtoblog a {
  55. display: none !important;
  56. }
  57. </style>
  58. <?php }
  59. add_filter( 'login_headerurl', 'uhp24_login_url' );
  60. function uhp24_login_url() { return home_url(); }
  61. add_filter('admin_title', 'uhp24_admin_title', 10, 2);
  62. function uhp24_admin_title($admin_title, $title) {
  63. return $title .' - '. get_bloginfo('name');
  64. }
  65. add_filter ('update_footer', 'uhp24_footer_ver', 999);
  66. function uhp24_footer_ver ($default) {
  67. return ''. get_bloginfo( 'version' );
  68. }
  69. add_filter ('admin_footer_text', 'uhp24_footer_filter');
  70. function uhp24_footer_filter ($default) {
  71. return '';
  72. }
  73. add_filter('gettext', 'uhp24_change_howdy', 10, 3);
  74. function uhp24_change_howdy($translated, $text, $domain) {
  75. if (false !== strpos($translated, 'Howdy,'))
  76. return str_replace('Howdy,', '', $translated);
  77. return $translated;
  78. }
  79. /* for email */
  80. add_filter( 'gettext', 'uhp24_change_howdy_text', 10, 2 );
  81. function uhp24_change_howdy_text( $translation, $original ) {
  82. if( 'Howdy, %1$s' == $original )
  83. $translation = '%1$s';
  84. return $translation;
  85. }
  86. add_action('admin_head', 'mytheme_remove_help_tabs');
  87. function mytheme_remove_help_tabs() {
  88. $screen = get_current_screen();
  89. $screen->remove_help_tabs();
  90. }
  91. add_action( 'admin_head-profile.php', 'uhp24_remove_admin_color' );
  92. function uhp24_remove_admin_color() {
  93. remove_action( 'admin_color_scheme_picker', 'admin_color_scheme_picker' );
  94. }
  95. add_action( 'admin_bar_menu', 'uhp24_remove_adminbar', 999 );
  96. function uhp24_remove_adminbar( $wp_admin_bar ) {
  97. $wp_admin_bar->remove_node('wp-logo');
  98. $wp_admin_bar->remove_node('updates');
  99. $wp_admin_bar->remove_menu('comments');
  100. $wp_admin_bar->remove_menu('customize');
  101. $wp_admin_bar->remove_menu('new-content');
  102. $wp_admin_bar->remove_menu('edit');
  103. $wp_admin_bar->remove_menu('new-user');
  104. $wp_admin_bar->remove_menu('new-post');
  105. $wp_admin_bar->remove_menu('new-page');
  106. $wp_admin_bar->remove_node('new-media');
  107. $wp_admin_bar->remove_node('view-site');
  108. }
  109. add_action( 'wp_dashboard_setup', 'uhp24_disable_dashboard_items' );
  110. function uhp24_disable_dashboard_items() {
  111. remove_action('admin_notices', 'update_nag');
  112. remove_action('welcome_panel', 'wp_welcome_panel');
  113. remove_meta_box('dashboard_primary', 'dashboard', 'side');
  114. remove_meta_box('dashboard_secondary', 'dashboard', 'side');
  115. remove_meta_box('dashboard_quick_press', 'dashboard', 'side');
  116. remove_meta_box('dashboard_site_health', 'dashboard', 'normal');
  117. }
  118. add_filter( 'screen_options_show_screen', '__return_false' );
  119. add_action('admin_menu', function () {
  120. remove_menu_page('edit-comments.php');
  121. });
  122. add_filter( 'custom_menu_order', 'uhp24_menu_order' );
  123. add_filter( 'menu_order', 'uhp24_menu_order' );
  124. function uhp24_menu_order( $menu_order ) {
  125. if (!$menu_order) return true;
  126. return array(
  127. 'index.php',
  128. 'separator1',
  129. 'edit.php?post_type=page',
  130. 'edit.php',
  131. 'edit-comments.php',
  132. 'separator2',
  133. 'upload.php',
  134. 'theme-settings',
  135. 'themes.php',
  136. 'plugins.php',
  137. 'tools.php',
  138. 'users.php',
  139. 'separator-last'
  140. );
  141. }
  142. add_action( 'admin_menu', 'uhp24_remove_admin_pages', 99 );
  143. function uhp24_remove_admin_pages() {
  144. global $current_user;
  145. $user_id = get_current_user_id();
  146. if($user_id != '0') {
  147. remove_menu_page('plugins.php');
  148. remove_menu_page('tools.php');
  149. remove_menu_page('options-general.php');
  150. remove_menu_page('gutenberg');
  151. remove_menu_page('users.php');
  152. remove_submenu_page('themes.php', 'themes-editor.php');
  153. remove_submenu_page( 'themes.php', 'customize.php?return=' . urlencode($_SERVER['SCRIPT_NAME']));
  154. remove_submenu_page( 'themes.php', 'themes.php' );
  155. remove_submenu_page( 'themes.php', 'theme-editor.php' );
  156. remove_submenu_page( 'themes.php', 'theme_options' );
  157. }
  158. }
  159. add_action( 'init', 'uhp24_admin_post_labels' );
  160. function uhp24_admin_post_labels() {
  161. global $wp_post_types;
  162. $labels = &$wp_post_types['post']->labels;
  163. $labels->name = 'News';
  164. $labels->singular_name = 'News';
  165. $labels->add_new = 'Add News';
  166. $labels->add_new_item = 'Add News';
  167. $labels->edit_item = 'Edit News';
  168. $labels->new_item = 'News';
  169. $labels->view_item = 'View News';
  170. $labels->search_items = 'Search News';
  171. $labels->not_found = 'No News found';
  172. $labels->not_found_in_trash = 'No News found in Trash';
  173. $labels->all_items = 'All News';
  174. $labels->menu_name = 'News';
  175. $labels->name_admin_bar = 'News';
  176. }
  177. /***********************************************************
  178. ###################### Last Login ##########################
  179. ************************************************************/
  180. add_action( 'wp_login', 'uhp24_login_timestamp', 20, 2 );
  181. function uhp24_login_timestamp( $user_login, $user ) {
  182. update_user_meta( $user->ID, 'last_login', time() );
  183. }
  184. add_filter( 'manage_users_columns', 'uhp24_user_last_login_column' );
  185. function uhp24_user_last_login_column( $columns ) {
  186. $columns['last_login'] = 'Last Login'; // column ID / column Title
  187. return $columns;
  188. }
  189. add_filter( 'manage_users_custom_column', 'uhp24_last_login_column', 10, 3 );
  190. function uhp24_last_login_column( $output, $column_id, $user_id ){
  191. if( $column_id == 'last_login' ) {
  192. $last_login = get_user_meta( $user_id, 'last_login', true );
  193. $date_format = 'j M, Y';
  194. $output = $last_login ? date( $date_format, $last_login ) : '-';
  195. }
  196. return $output;
  197. }
  198. add_filter( 'manage_users_sortable_columns', 'uhp24_sortable_columns' );
  199. function uhp24_sortable_columns( $columns ) {
  200. return wp_parse_args( array(
  201. 'last_login' => 'last_login'
  202. ), $columns );
  203. }
  204. add_action( 'pre_get_users', 'uhp24_sort_last_login_column' );
  205. function uhp24_sort_last_login_column( $query ) {
  206. if( !is_admin() ) { return; }
  207. $orderby = $query->get('orderby');
  208. if( 'last_login' == $orderby ) {
  209. $query->set('meta_key','last_login');
  210. $query->set('orderby','meta_value');
  211. }
  212. return $query;
  213. }
  214. /***********************************************************
  215. ######################## Editor ############################
  216. ************************************************************/
  217. add_filter( 'styles_inline_size_limit', '__return_zero' );
  218. add_action( 'enqueue_block_assets', 'uhp24_block_styles', 5 );
  219. function uhp24_block_styles(){
  220. wp_enqueue_style('uhp24-css', get_stylesheet_directory_uri() . '/style.css');
  221. }
  222. //add_action( 'admin_enqueue_scripts', 'uhp24_admin_styles' );
  223. function uhp24_admin_styles() {
  224. wp_enqueue_style( 'style-editor', get_template_directory_uri().'/style-editor.css' );
  225. }
  226. add_filter( 'should_load_remote_block_patterns', 'uhp24_disable_remote_patterns' );
  227. function uhp24_disable_remote_patterns() {
  228. return false;
  229. }
  230. add_action( 'init', 'dwp23_disable_emojis' );
  231. function dwp23_disable_emojis() {
  232. remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
  233. remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
  234. remove_action( 'wp_print_styles', 'print_emoji_styles' );
  235. remove_action( 'admin_print_styles', 'print_emoji_styles' );
  236. remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
  237. remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
  238. remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
  239. add_filter( 'emoji_svg_url', '__return_false' );
  240. }
  241. add_action( 'init', 'uhp24_cleaner_header' );
  242. function uhp24_cleaner_header() {
  243. remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10);
  244. remove_action('wp_head', 'wlwmanifest_link');
  245. remove_action('wp_head', 'rsd_link');
  246. remove_action('wp_head', 'wp_shortlink_wp_head', 10);
  247. remove_action('wp_head', 'wp_generator');
  248. remove_action('wp_head', 'feed_links_extra', 3 );
  249. remove_action('wp_head', 'feed_links', 2 );
  250. }
  251. /***********************************************************
  252. ####################### Comments ###########################
  253. ************************************************************/
  254. add_filter('comments_open', '__return_false', 20, 2);
  255. add_filter('pings_open', '__return_false', 20, 2);
  256. add_action('admin_init','uhp24_disable_comments');
  257. function uhp24_disable_comments() {
  258. $post_types = get_post_types();
  259. foreach ($post_types as $post_type) {
  260. if(post_type_supports($post_type,'comments')) {
  261. remove_post_type_support($post_type,'comments');
  262. remove_post_type_support($post_type,'trackbacks');
  263. }
  264. }
  265. }