functions.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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( 'admin_bar_menu', 'uhp24_replace_wordpress_howdy', 25 );
  74. function uhp24_replace_wordpress_howdy( $wp_admin_bar ) {
  75. $account = $wp_admin_bar->get_node('my-account');
  76. $newtext = str_replace( 'Howdy,', '', $account->title );
  77. $wp_admin_bar->add_node( array(
  78. 'id' => 'my-account',
  79. 'title' => $newtext,
  80. ));
  81. }
  82. /* for email */
  83. add_filter( 'gettext', 'uhp24_change_howdy_text', 10, 2 );
  84. function uhp24_change_howdy_text( $translation, $original ) {
  85. if( 'Howdy, %1$s' == $original )
  86. $translation = '%1$s';
  87. return $translation;
  88. }
  89. add_action('admin_head', 'mytheme_remove_help_tabs');
  90. function mytheme_remove_help_tabs() {
  91. $screen = get_current_screen();
  92. $screen->remove_help_tabs();
  93. }
  94. add_action( 'admin_head-profile.php', 'uhp24_remove_admin_color' );
  95. function uhp24_remove_admin_color() {
  96. remove_action( 'admin_color_scheme_picker', 'admin_color_scheme_picker' );
  97. }
  98. add_action( 'admin_bar_menu', 'uhp24_remove_adminbar', 999 );
  99. function uhp24_remove_adminbar( $wp_admin_bar ) {
  100. $wp_admin_bar->remove_node('wp-logo');
  101. $wp_admin_bar->remove_node('updates');
  102. $wp_admin_bar->remove_menu('comments');
  103. $wp_admin_bar->remove_menu('customize');
  104. $wp_admin_bar->remove_menu('new-content');
  105. $wp_admin_bar->remove_menu('edit');
  106. $wp_admin_bar->remove_menu('new-user');
  107. $wp_admin_bar->remove_menu('new-post');
  108. $wp_admin_bar->remove_menu('new-page');
  109. $wp_admin_bar->remove_node('new-media');
  110. $wp_admin_bar->remove_node('view-site');
  111. }
  112. add_action( 'wp_dashboard_setup', 'uhp24_disable_dashboard_items' );
  113. function uhp24_disable_dashboard_items() {
  114. remove_action('admin_notices', 'update_nag');
  115. remove_action('welcome_panel', 'wp_welcome_panel');
  116. remove_meta_box('dashboard_primary', 'dashboard', 'side');
  117. remove_meta_box('dashboard_secondary', 'dashboard', 'side');
  118. remove_meta_box('dashboard_quick_press', 'dashboard', 'side');
  119. remove_meta_box('dashboard_site_health', 'dashboard', 'normal');
  120. }
  121. add_filter( 'screen_options_show_screen', '__return_false' );
  122. add_action('admin_menu', function () {
  123. remove_menu_page('edit-comments.php');
  124. });
  125. add_filter( 'custom_menu_order', 'uhp24_menu_order' );
  126. add_filter( 'menu_order', 'uhp24_menu_order' );
  127. function uhp24_menu_order( $menu_order ) {
  128. if (!$menu_order) return true;
  129. return array(
  130. 'index.php',
  131. 'separator1',
  132. 'edit.php?post_type=page',
  133. 'edit.php',
  134. 'edit-comments.php',
  135. 'separator2',
  136. 'upload.php',
  137. 'theme-settings',
  138. 'themes.php',
  139. 'plugins.php',
  140. 'tools.php',
  141. 'users.php',
  142. 'separator-last'
  143. );
  144. }
  145. add_action( 'admin_menu', 'uhp24_remove_admin_pages', 99 );
  146. function uhp24_remove_admin_pages() {
  147. global $current_user;
  148. $user_id = get_current_user_id();
  149. if($user_id != '0') {
  150. remove_menu_page('plugins.php');
  151. remove_menu_page('tools.php');
  152. remove_menu_page('options-general.php');
  153. remove_menu_page('gutenberg');
  154. remove_menu_page('users.php');
  155. remove_submenu_page('themes.php', 'themes-editor.php');
  156. remove_submenu_page( 'themes.php', 'customize.php?return=' . urlencode($_SERVER['SCRIPT_NAME']));
  157. remove_submenu_page( 'themes.php', 'themes.php' );
  158. remove_submenu_page( 'themes.php', 'theme-editor.php' );
  159. remove_submenu_page( 'themes.php', 'theme_options' );
  160. }
  161. }
  162. add_action( 'init', 'uhp24_admin_post_labels' );
  163. function uhp24_admin_post_labels() {
  164. global $wp_post_types;
  165. $labels = &$wp_post_types['post']->labels;
  166. $labels->name = 'News';
  167. $labels->singular_name = 'News';
  168. $labels->add_new = 'Add News';
  169. $labels->add_new_item = 'Add News';
  170. $labels->edit_item = 'Edit News';
  171. $labels->new_item = 'News';
  172. $labels->view_item = 'View News';
  173. $labels->search_items = 'Search News';
  174. $labels->not_found = 'No News found';
  175. $labels->not_found_in_trash = 'No News found in Trash';
  176. $labels->all_items = 'All News';
  177. $labels->menu_name = 'News';
  178. $labels->name_admin_bar = 'News';
  179. }
  180. /***********************************************************
  181. ###################### Last Login ##########################
  182. ************************************************************/
  183. add_action( 'wp_login', 'uhp24_login_timestamp', 20, 2 );
  184. function uhp24_login_timestamp( $user_login, $user ) {
  185. update_user_meta( $user->ID, 'last_login', time() );
  186. }
  187. add_filter( 'manage_users_columns', 'uhp24_user_last_login_column' );
  188. function uhp24_user_last_login_column( $columns ) {
  189. $columns['last_login'] = 'Last Login'; // column ID / column Title
  190. return $columns;
  191. }
  192. add_filter( 'manage_users_custom_column', 'uhp24_last_login_column', 10, 3 );
  193. function uhp24_last_login_column( $output, $column_id, $user_id ){
  194. if( $column_id == 'last_login' ) {
  195. $last_login = get_user_meta( $user_id, 'last_login', true );
  196. $date_format = 'j M, Y';
  197. $output = $last_login ? date( $date_format, $last_login ) : '-';
  198. }
  199. return $output;
  200. }
  201. add_filter( 'manage_users_sortable_columns', 'uhp24_sortable_columns' );
  202. function uhp24_sortable_columns( $columns ) {
  203. return wp_parse_args( array(
  204. 'last_login' => 'last_login'
  205. ), $columns );
  206. }
  207. add_action( 'pre_get_users', 'uhp24_sort_last_login_column' );
  208. function uhp24_sort_last_login_column( $query ) {
  209. if( !is_admin() ) { return; }
  210. $orderby = $query->get('orderby');
  211. if( 'last_login' == $orderby ) {
  212. $query->set('meta_key','last_login');
  213. $query->set('orderby','meta_value');
  214. }
  215. return $query;
  216. }
  217. /***********************************************************
  218. ######################## Editor ############################
  219. ************************************************************/
  220. add_filter( 'styles_inline_size_limit', '__return_zero' );
  221. add_action( 'enqueue_block_assets', 'uhp24_block_styles', 5 );
  222. function uhp24_block_styles(){
  223. wp_enqueue_style('uhp24-css', get_stylesheet_directory_uri() . '/style.css');
  224. }
  225. //add_action( 'admin_enqueue_scripts', 'uhp24_admin_styles' );
  226. function uhp24_admin_styles() {
  227. wp_enqueue_style( 'style-editor', get_template_directory_uri().'/style-editor.css' );
  228. }
  229. add_filter( 'should_load_remote_block_patterns', 'uhp24_disable_remote_patterns' );
  230. function uhp24_disable_remote_patterns() {
  231. return false;
  232. }
  233. add_action( 'init', 'dwp23_disable_emojis' );
  234. function dwp23_disable_emojis() {
  235. remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
  236. remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
  237. remove_action( 'wp_print_styles', 'print_emoji_styles' );
  238. remove_action( 'admin_print_styles', 'print_emoji_styles' );
  239. remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
  240. remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
  241. remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
  242. add_filter( 'emoji_svg_url', '__return_false' );
  243. }
  244. add_action( 'init', 'uhp24_cleaner_header' );
  245. function uhp24_cleaner_header() {
  246. remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10);
  247. remove_action('wp_head', 'wlwmanifest_link');
  248. remove_action('wp_head', 'rsd_link');
  249. remove_action('wp_head', 'wp_shortlink_wp_head', 10);
  250. remove_action('wp_head', 'wp_generator');
  251. remove_action('wp_head', 'feed_links_extra', 3 );
  252. remove_action('wp_head', 'feed_links', 2 );
  253. }
  254. /***********************************************************
  255. ####################### Comments ###########################
  256. ************************************************************/
  257. add_filter('comments_open', '__return_false', 20, 2);
  258. add_filter('pings_open', '__return_false', 20, 2);
  259. add_action('admin_init','uhp24_disable_comments');
  260. function uhp24_disable_comments() {
  261. $post_types = get_post_types();
  262. foreach ($post_types as $post_type) {
  263. if(post_type_supports($post_type,'comments')) {
  264. remove_post_type_support($post_type,'comments');
  265. remove_post_type_support($post_type,'trackbacks');
  266. }
  267. }
  268. }