functions.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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_filter('admin_title', 'uhp24_admin_title', 10, 2);
  38. function uhp24_admin_title($admin_title, $title) {
  39. return $title .' - '. get_bloginfo('name');
  40. }
  41. add_filter ('update_footer', 'uhp24_footer_ver', 999);
  42. function uhp24_footer_ver ($default) {
  43. return ''. get_bloginfo( 'version' );
  44. }
  45. add_filter ('admin_footer_text', 'uhp24_footer_filter');
  46. function uhp24_footer_filter ($default) {
  47. return '';
  48. }
  49. add_filter( 'admin_bar_menu', 'uhp24_replace_wordpress_howdy', 25 );
  50. function uhp24_replace_wordpress_howdy( $wp_admin_bar ) {
  51. $account = $wp_admin_bar->get_node('my-account');
  52. $newtext = str_replace( 'Howdy,', '', $account->title );
  53. $wp_admin_bar->add_node( array(
  54. 'id' => 'my-account',
  55. 'title' => $newtext,
  56. ));
  57. }
  58. /* for email */
  59. add_filter( 'gettext', 'uhp24_change_howdy_text', 10, 2 );
  60. function uhp24_change_howdy_text( $translation, $original ) {
  61. if( 'Howdy, %1$s' == $original )
  62. $translation = '%1$s';
  63. return $translation;
  64. }
  65. add_action('admin_head', 'mytheme_remove_help_tabs');
  66. function mytheme_remove_help_tabs() {
  67. $screen = get_current_screen();
  68. $screen->remove_help_tabs();
  69. }
  70. add_action( 'admin_head-profile.php', 'uhp24_remove_admin_color' );
  71. function uhp24_remove_admin_color() {
  72. remove_action( 'admin_color_scheme_picker', 'admin_color_scheme_picker' );
  73. }
  74. add_action( 'admin_bar_menu', 'uhp24_remove_adminbar', 999 );
  75. function uhp24_remove_adminbar( $wp_admin_bar ) {
  76. $wp_admin_bar->remove_node('wp-logo');
  77. $wp_admin_bar->remove_node('updates');
  78. $wp_admin_bar->remove_menu('comments');
  79. $wp_admin_bar->remove_menu('customize');
  80. $wp_admin_bar->remove_menu('new-content');
  81. $wp_admin_bar->remove_menu('edit');
  82. $wp_admin_bar->remove_menu('new-user');
  83. $wp_admin_bar->remove_menu('new-post');
  84. $wp_admin_bar->remove_menu('new-page');
  85. $wp_admin_bar->remove_node('new-media');
  86. $wp_admin_bar->remove_node('view-site');
  87. }
  88. add_action( 'wp_dashboard_setup', 'uhp24_disable_dashboard_items' );
  89. function uhp24_disable_dashboard_items() {
  90. remove_action('admin_notices', 'update_nag');
  91. remove_action('welcome_panel', 'wp_welcome_panel');
  92. remove_meta_box('dashboard_primary', 'dashboard', 'side');
  93. remove_meta_box('dashboard_secondary', 'dashboard', 'side');
  94. remove_meta_box('dashboard_quick_press', 'dashboard', 'side');
  95. remove_meta_box('dashboard_site_health', 'dashboard', 'normal');
  96. }
  97. add_filter( 'screen_options_show_screen', '__return_false' );
  98. add_action('admin_menu', function () {
  99. remove_menu_page('edit-comments.php');
  100. });
  101. add_filter( 'custom_menu_order', 'uhp24_menu_order' );
  102. add_filter( 'menu_order', 'uhp24_menu_order' );
  103. function uhp24_menu_order( $menu_order ) {
  104. if (!$menu_order) return true;
  105. return array(
  106. 'index.php',
  107. 'separator1',
  108. 'edit.php?post_type=page',
  109. 'edit.php',
  110. 'edit-comments.php',
  111. 'separator2',
  112. 'upload.php',
  113. 'theme-settings',
  114. 'themes.php',
  115. 'plugins.php',
  116. 'tools.php',
  117. 'users.php',
  118. 'separator-last'
  119. );
  120. }
  121. add_action( 'admin_menu', 'uhp24_remove_admin_pages', 99 );
  122. function uhp24_remove_admin_pages() {
  123. global $current_user;
  124. $user_id = get_current_user_id();
  125. if($user_id != '0') {
  126. remove_menu_page('plugins.php');
  127. remove_menu_page('tools.php');
  128. remove_menu_page('options-general.php');
  129. remove_menu_page('gutenberg');
  130. remove_menu_page('users.php');
  131. remove_submenu_page('themes.php', 'themes-editor.php');
  132. remove_submenu_page( 'themes.php', 'customize.php?return=' . urlencode($_SERVER['SCRIPT_NAME']));
  133. remove_submenu_page( 'themes.php', 'themes.php' );
  134. remove_submenu_page( 'themes.php', 'theme-editor.php' );
  135. remove_submenu_page( 'themes.php', 'theme_options' );
  136. }
  137. }
  138. add_action( 'init', 'uhp24_admin_post_labels' );
  139. function uhp24_admin_post_labels() {
  140. global $wp_post_types;
  141. $labels = &$wp_post_types['post']->labels;
  142. $labels->name = 'News';
  143. $labels->singular_name = 'News';
  144. $labels->add_new = 'Add News';
  145. $labels->add_new_item = 'Add News';
  146. $labels->edit_item = 'Edit News';
  147. $labels->new_item = 'News';
  148. $labels->view_item = 'View News';
  149. $labels->search_items = 'Search News';
  150. $labels->not_found = 'No News found';
  151. $labels->not_found_in_trash = 'No News found in Trash';
  152. $labels->all_items = 'All News';
  153. $labels->menu_name = 'News';
  154. $labels->name_admin_bar = 'News';
  155. }
  156. /***********************************************************
  157. ###################### Last Login ##########################
  158. ************************************************************/
  159. add_action( 'wp_login', 'uhp24_login_timestamp', 20, 2 );
  160. function uhp24_login_timestamp( $user_login, $user ) {
  161. update_user_meta( $user->ID, 'last_login', time() );
  162. }
  163. add_filter( 'manage_users_columns', 'uhp24_user_last_login_column' );
  164. function uhp24_user_last_login_column( $columns ) {
  165. $columns['last_login'] = 'Last Login'; // column ID / column Title
  166. return $columns;
  167. }
  168. add_filter( 'manage_users_custom_column', 'uhp24_last_login_column', 10, 3 );
  169. function uhp24_last_login_column( $output, $column_id, $user_id ){
  170. if( $column_id == 'last_login' ) {
  171. $last_login = get_user_meta( $user_id, 'last_login', true );
  172. $date_format = 'j M, Y';
  173. $output = $last_login ? date( $date_format, $last_login ) : '-';
  174. }
  175. return $output;
  176. }
  177. add_filter( 'manage_users_sortable_columns', 'uhp24_sortable_columns' );
  178. function uhp24_sortable_columns( $columns ) {
  179. return wp_parse_args( array(
  180. 'last_login' => 'last_login'
  181. ), $columns );
  182. }
  183. add_action( 'pre_get_users', 'uhp24_sort_last_login_column' );
  184. function uhp24_sort_last_login_column( $query ) {
  185. if( !is_admin() ) { return; }
  186. $orderby = $query->get('orderby');
  187. if( 'last_login' == $orderby ) {
  188. $query->set('meta_key','last_login');
  189. $query->set('orderby','meta_value');
  190. }
  191. return $query;
  192. }
  193. /***********************************************************
  194. ######################## Editor ############################
  195. ************************************************************/
  196. add_action( 'enqueue_block_assets', 'uhp24_block_styles', 5 );
  197. function uhp24_block_styles(){
  198. wp_enqueue_style('uhp24-css', get_stylesheet_directory_uri() . '/style.css');
  199. }
  200. //add_action( 'admin_enqueue_scripts', 'uhp24_admin_styles' );
  201. function uhp24_admin_styles() {
  202. wp_enqueue_style( 'style-editor', get_template_directory_uri().'/style-editor.css' );
  203. }
  204. add_filter( 'should_load_remote_block_patterns', 'uhp24_disable_remote_patterns' );
  205. function uhp24_disable_remote_patterns() {
  206. return false;
  207. }
  208. /***********************************************************
  209. ####################### Comments ###########################
  210. ************************************************************/
  211. add_filter('comments_open', '__return_false', 20, 2);
  212. add_filter('pings_open', '__return_false', 20, 2);
  213. add_action('admin_init','uhp24_disable_comments');
  214. function uhp24_disable_comments() {
  215. $post_types = get_post_types();
  216. foreach ($post_types as $post_type) {
  217. if(post_type_supports($post_type,'comments')) {
  218. remove_post_type_support($post_type,'comments');
  219. remove_post_type_support($post_type,'trackbacks');
  220. }
  221. }
  222. }