functions.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <?php
  2. function lnr24_enqueue_assets() {
  3. wp_enqueue_style( 'style-css', get_template_directory_uri() . '/style.css');
  4. }
  5. add_action( 'wp_enqueue_scripts', 'lnr24_enqueue_assets' );
  6. function lnr24_theme_setup() {
  7. add_theme_support( 'editor-styles' );
  8. add_editor_style( 'style-editor.css' );
  9. }
  10. add_action( 'after_setup_theme', 'lnr24_theme_setup' );
  11. /***********************************************************
  12. ###################### BrowserSync #########################
  13. ************************************************************/
  14. function add_cors_http_header(){
  15. header('Access-Control-Allow-Origin: https://lnr.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 lnr24_browsersync_save() {
  21. $args = [
  22. 'blocking' => false,
  23. 'sslverify' => false
  24. ];
  25. $request = wp_remote_get('https://lnr.ovid:333/__browser_sync__?method=reload', $args);
  26. }
  27. add_action('rest_after_insert_page', 'lnr24_browsersync_save', 10, 3);
  28. add_action('rest_after_insert_post', 'lnr24_browsersync_save', 10, 3);
  29. add_action('save_post', 'lnr24_browsersync_save', 10, 3);
  30. add_action('customize_save_after', 'lnr24_browsersync_save', 10, 3);
  31. add_action('wp_update_nav_menu', 'lnr24_browsersync_save', 10, 3);
  32. add_action('updated_option', 'lnr24_browsersync_save', 10, 3);
  33. /***********************************************************
  34. ######################### Admin ############################
  35. ************************************************************/
  36. add_filter( 'show_admin_bar', '__return_false' );
  37. add_action( 'admin_bar_menu', 'lnr24_remove_adminbar', 999 );
  38. function lnr24_remove_adminbar( $wp_admin_bar ) {
  39. $wp_admin_bar->remove_node('wp-logo');
  40. $wp_admin_bar->remove_node('updates');
  41. $wp_admin_bar->remove_menu('comments');
  42. $wp_admin_bar->remove_menu('customize');
  43. $wp_admin_bar->remove_menu('new-content');
  44. $wp_admin_bar->remove_menu('edit');
  45. $wp_admin_bar->remove_menu('new-user');
  46. $wp_admin_bar->remove_menu('new-post');
  47. $wp_admin_bar->remove_menu('new-page');
  48. $wp_admin_bar->remove_node('new-media');
  49. $wp_admin_bar->remove_node('view-site');
  50. }
  51. add_filter( 'custom_menu_order', 'lnr24_menu_order' );
  52. add_filter( 'menu_order', 'lnr24_menu_order' );
  53. function lnr24_menu_order( $menu_order ) {
  54. if (!$menu_order) return true;
  55. return array(
  56. 'index.php',
  57. 'separator1',
  58. 'edit.php?post_type=page',
  59. 'edit.php',
  60. 'edit-comments.php',
  61. 'separator2',
  62. 'upload.php',
  63. 'theme-settings',
  64. 'themes.php',
  65. 'plugins.php',
  66. 'tools.php',
  67. 'users.php',
  68. 'separator-last'
  69. );
  70. }
  71. add_action( 'admin_menu', 'lnr24_remove_admin_pages', 99 );
  72. function lnr24_remove_admin_pages() {
  73. global $current_user;
  74. $user_id = get_current_user_id();
  75. if($user_id != '0') {
  76. remove_menu_page('plugins.php');
  77. remove_menu_page('tools.php');
  78. remove_menu_page('options-general.php');
  79. remove_menu_page('gutenberg');
  80. remove_menu_page('users.php');
  81. remove_submenu_page('themes.php', 'themes-editor.php');
  82. remove_submenu_page( 'themes.php', 'customize.php?return=' . urlencode($_SERVER['SCRIPT_NAME']));
  83. remove_submenu_page( 'themes.php', 'themes.php' );
  84. remove_submenu_page( 'themes.php', 'theme-editor.php' );
  85. remove_submenu_page( 'themes.php', 'theme_options' );
  86. remove_submenu_page('gf_edit_forms', 'gf_new_form');
  87. remove_submenu_page('gf_edit_forms', 'gf_export');
  88. remove_submenu_page('gf_edit_forms', 'gf_addons');
  89. remove_submenu_page('gf_edit_forms', 'gf_settings');
  90. remove_submenu_page('gf_edit_forms', 'gf_help');
  91. remove_submenu_page('gf_edit_forms', 'gf_system_status');
  92. }
  93. }
  94. add_action( 'wp_dashboard_setup', 'lnr24_disable_dashboard_items' );
  95. function lnr24_disable_dashboard_items() {
  96. remove_action('admin_notices', 'update_nag');
  97. remove_action('welcome_panel', 'wp_welcome_panel');
  98. remove_meta_box('dashboard_primary', 'dashboard', 'side');
  99. remove_meta_box('dashboard_secondary', 'dashboard', 'side');
  100. remove_meta_box('dashboard_quick_press', 'dashboard', 'side');
  101. remove_meta_box('dashboard_site_health', 'dashboard', 'normal');
  102. }
  103. add_filter('admin_title', 'lnr24_admin_title', 10, 2);
  104. function lnr24_admin_title($admin_title, $title) {
  105. return $title .' - '. get_bloginfo('name');
  106. }
  107. add_filter ('admin_footer_text', 'lnr24_footer_filter');
  108. function lnr24_footer_filter ($default) {
  109. return '';
  110. }
  111. add_filter( 'admin_bar_menu', 'lnr24_replace_wordpress_howdy', 25 );
  112. function lnr24_replace_wordpress_howdy( $wp_admin_bar ) {
  113. $account = $wp_admin_bar->get_node('my-account');
  114. $newtext = str_replace( 'Howdy,', '', $account->title );
  115. $wp_admin_bar->add_node( array(
  116. 'id' => 'my-account',
  117. 'title' => $newtext,
  118. ));
  119. }
  120. add_filter( 'gettext', 'lnr24_change_howdy_text', 10, 2 );
  121. function lnr24_change_howdy_text( $translation, $original ) {
  122. if( 'Howdy, %1$s' == $original )
  123. $translation = '%1$s';
  124. return $translation;
  125. }
  126. add_action( 'admin_head-profile.php', 'lnr24_remove_admin_color' );
  127. function lnr24_remove_admin_color() {
  128. remove_action( 'admin_color_scheme_picker', 'admin_color_scheme_picker' );
  129. }
  130. add_action('admin_head', 'lnr24_remove_help_tabs');
  131. function lnr24_remove_help_tabs() {
  132. $screen = get_current_screen();
  133. $screen->remove_help_tabs();
  134. }
  135. /***********************************************************
  136. ####################### Comments ###########################
  137. ************************************************************/
  138. add_action('admin_menu', function () {
  139. remove_menu_page('edit-comments.php');
  140. });
  141. add_filter('comments_open', '__return_false', 20, 2);
  142. add_filter('pings_open', '__return_false', 20, 2);
  143. add_action('admin_init','lnr24_disable_comments');
  144. function lnr24_disable_comments() {
  145. $post_types = get_post_types();
  146. foreach ($post_types as $post_type) {
  147. if(post_type_supports($post_type,'comments')) {
  148. remove_post_type_support($post_type,'comments');
  149. remove_post_type_support($post_type,'trackbacks');
  150. }
  151. }
  152. }
  153. /***********************************************************
  154. ###################### Last Login ##########################
  155. ************************************************************/
  156. add_action( 'wp_login', 'lnr24_login_timestamp', 20, 2 );
  157. function lnr24_login_timestamp( $user_login, $user ) {
  158. update_user_meta( $user->ID, 'last_login', time() );
  159. }
  160. add_filter( 'manage_users_columns', 'lnr24_user_last_login_column' );
  161. function lnr24_user_last_login_column( $columns ) {
  162. $columns['last_login'] = 'Last Login'; // column ID / column Title
  163. return $columns;
  164. }
  165. add_filter( 'manage_users_custom_column', 'lnr24_last_login_column', 10, 3 );
  166. function lnr24_last_login_column( $output, $column_id, $user_id ){
  167. if( $column_id == 'last_login' ) {
  168. $last_login = get_user_meta( $user_id, 'last_login', true );
  169. $date_format = 'j M, Y';
  170. $output = $last_login ? date( $date_format, $last_login ) : '-';
  171. }
  172. return $output;
  173. }
  174. add_filter( 'manage_users_sortable_columns', 'lnr24_sortable_columns' );
  175. function lnr24_sortable_columns( $columns ) {
  176. return wp_parse_args( array(
  177. 'last_login' => 'last_login'
  178. ), $columns );
  179. }
  180. add_action( 'pre_get_users', 'lnr24_sort_last_login_column' );
  181. function lnr24_sort_last_login_column( $query ) {
  182. if( !is_admin() ) { return; }
  183. $orderby = $query->get('orderby');
  184. if( 'last_login' == $orderby ) {
  185. $query->set('meta_key','last_login');
  186. $query->set('orderby','meta_value');
  187. }
  188. return $query;
  189. }
  190. /***********************************************************
  191. ######################## Blocks ############################
  192. ************************************************************/
  193. function lnr24_restrict_locking_ui( $settings, $context ) {
  194. $settings[ 'canLockBlocks' ] = current_user_can( 'activate_plugins' );
  195. return $settings;
  196. }
  197. add_filter( 'block_editor_settings_all', 'lnr24_restrict_locking_ui', 10, 2 );
  198. remove_theme_support( 'core-block-patterns' );
  199. add_filter( 'should_load_remote_block_patterns', 'lnr24_disable_remote_patterns' );
  200. function lnr24_disable_remote_patterns() {
  201. return false;
  202. }
  203. add_filter(
  204. 'block_editor_settings_all',
  205. function( $settings ) {
  206. $settings['enableOpenverseMediaCategory'] = false;
  207. return $settings;
  208. },
  209. 10
  210. );