functions.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. <?php
  2. /***********************************************************
  3. ###################### BrowserSync #########################
  4. ************************************************************/
  5. function add_cors_http_header(){
  6. header('Access-Control-Allow-Origin: https://lps.ovid:333');
  7. header('Access-Control-Allow-Credentials: true');
  8. header('Access-Control-Allow-Headers: X-WP-Nonce', false );
  9. }
  10. add_action('init','add_cors_http_header');
  11. function lps24_browsersync_save() {
  12. $args = [
  13. 'blocking' => false,
  14. 'sslverify' => false
  15. ];
  16. $request = wp_remote_get('https://lps.ovid:333/__browser_sync__?method=reload', $args);
  17. }
  18. add_action('rest_after_insert_page', 'lps24_browsersync_save', 10, 3);
  19. add_action('rest_after_insert_post', 'lps24_browsersync_save', 10, 3);
  20. add_action('save_post', 'lps24_browsersync_save', 10, 3);
  21. add_action('customize_save_after', 'lps24_browsersync_save', 10, 3);
  22. add_action('wp_update_nav_menu', 'lps24_browsersync_save', 10, 3);
  23. add_action('updated_option', 'lps24_browsersync_save', 10, 3);
  24. /***********************************************************
  25. ######################## Sucurity ##########################
  26. ************************************************************/
  27. /* disabled xmlrpc and edit .htaccess
  28. <Files xmlrpc.php>
  29. order allow,deny
  30. deny from all
  31. </Files>
  32. */
  33. add_filter( 'xmlrpc_enabled', '__return_false' );
  34. add_filter( 'wp_headers', 'lps24_disable_x_pingback' );
  35. function lps24_disable_x_pingback( $headers ) {
  36. unset( $headers['X-Pingback'] );
  37. return $headers;
  38. }
  39. /* change login url and edit .htaccess
  40. RewriteBase /
  41. RewriteRule ^SRH$ wp-login.php
  42. */
  43. //add_filter('site_url', 'lps24_wplogin_filter', 10, 3);
  44. function lps24_wplogin_filter( $url, $path, $orig_scheme ) {
  45. $old = array( "/(wp-login\.php)/");
  46. $new = array( "SRH");
  47. return preg_replace( $old, $new, $url, 1);
  48. }
  49. /***********************************************************
  50. ######################### Admin ############################
  51. ************************************************************/
  52. add_filter( 'show_admin_bar', '__return_false' );
  53. add_action( 'admin_enqueue_scripts', 'lps24_admin_styles' );
  54. function lps24_admin_styles() {
  55. wp_enqueue_style( 'style-editor', get_template_directory_uri().'/style-editor.css' );
  56. }
  57. add_action( 'admin_bar_menu', 'lps24_remove_adminbar', 999 );
  58. function lps24_remove_adminbar( $wp_admin_bar ) {
  59. $wp_admin_bar->remove_node('wp-logo');
  60. $wp_admin_bar->remove_node('updates');
  61. $wp_admin_bar->remove_menu('comments');
  62. $wp_admin_bar->remove_menu('customize');
  63. $wp_admin_bar->remove_menu('new-content');
  64. $wp_admin_bar->remove_menu('edit');
  65. $wp_admin_bar->remove_menu('new-user');
  66. $wp_admin_bar->remove_menu('new-post');
  67. $wp_admin_bar->remove_menu('new-page');
  68. $wp_admin_bar->remove_node('new-media');
  69. $wp_admin_bar->remove_node('view-site');
  70. }
  71. add_filter( 'custom_menu_order', 'lps24_menu_order' );
  72. add_filter( 'menu_order', 'lps24_menu_order' );
  73. function lps24_menu_order( $menu_order ) {
  74. if (!$menu_order) return true;
  75. return array(
  76. 'index.php',
  77. 'separator1',
  78. 'edit.php?post_type=page',
  79. 'edit.php',
  80. 'edit-comments.php',
  81. 'separator2',
  82. 'upload.php',
  83. 'theme-settings',
  84. 'themes.php',
  85. 'plugins.php',
  86. 'tools.php',
  87. 'users.php',
  88. 'separator-last'
  89. );
  90. }
  91. add_action( 'admin_menu', 'lps24_remove_admin_pages', 99 );
  92. function lps24_remove_admin_pages() {
  93. global $current_user;
  94. $user_id = get_current_user_id();
  95. if($user_id != '1') {
  96. remove_menu_page('plugins.php');
  97. remove_menu_page('tools.php');
  98. remove_menu_page('options-general.php');
  99. remove_menu_page('gutenberg');
  100. remove_menu_page('users.php');
  101. remove_menu_page('gf_edit_forms');
  102. remove_menu_page('activity-log-page');
  103. remove_submenu_page('themes.php', 'themes-editor.php');
  104. remove_submenu_page('themes.php', 'customize.php?return=');
  105. remove_submenu_page('themes.php', 'themes.php');
  106. remove_submenu_page('themes.php', 'theme-editor.php');
  107. remove_submenu_page('themes.php', 'theme_options');
  108. remove_submenu_page('gf_edit_forms', 'gf_edit_forms');
  109. remove_submenu_page('gf_edit_forms', 'gf_new_form');
  110. remove_submenu_page('gf_edit_forms', 'gf_export');
  111. remove_submenu_page('gf_edit_forms', 'gf_addons');
  112. remove_submenu_page('gf_edit_forms', 'gf_settings');
  113. remove_submenu_page('gf_edit_forms', 'gf_help');
  114. remove_submenu_page('gf_edit_forms', 'gf_system_status');
  115. }
  116. }
  117. add_action( 'wp_dashboard_setup', 'lps24_disable_dashboard_items' );
  118. function lps24_disable_dashboard_items() {
  119. remove_action('admin_notices', 'update_nag');
  120. remove_action('welcome_panel', 'wp_welcome_panel');
  121. remove_meta_box('dashboard_primary', 'dashboard', 'side');
  122. remove_meta_box('dashboard_secondary', 'dashboard', 'side');
  123. remove_meta_box('dashboard_quick_press', 'dashboard', 'side');
  124. remove_meta_box('dashboard_site_health', 'dashboard', 'normal');
  125. }
  126. add_action('admin_head', 'lps24_glance_version');
  127. function lps24_glance_version() {
  128. echo '<style>#dashboard_right_now p:last-child {display:none;}</style>';
  129. }
  130. add_filter('admin_title', 'lps24_admin_title', 10, 2);
  131. function lps24_admin_title($admin_title, $title) {
  132. return $title .' - '. get_bloginfo('name');
  133. }
  134. add_filter ('admin_footer_text', 'lps24_footer_filter');
  135. function lps24_footer_filter ($default) {
  136. return '';
  137. }
  138. add_filter('gettext', 'lps24_replace_howdy', 10, 3);
  139. function lps24_replace_howdy($translated_text, $text, $domain) {
  140. $new_message = str_replace('Howdy,', '', $text);
  141. return $new_message;
  142. }
  143. add_filter( 'gettext', 'lps24_change_howdy_text', 10, 2 );
  144. function lps24_change_howdy_text( $translation, $original ) {
  145. if( 'Howdy, %1$s' == $original )
  146. $translation = '%1$s';
  147. return $translation;
  148. }
  149. add_action( 'admin_head-profile.php', 'lps24_remove_admin_color' );
  150. function lps24_remove_admin_color() {
  151. remove_action( 'admin_color_scheme_picker', 'admin_color_scheme_picker' );
  152. }
  153. add_action('admin_head', 'lps24_remove_help_tabs');
  154. function lps24_remove_help_tabs() {
  155. $screen = get_current_screen();
  156. $screen->remove_help_tabs();
  157. }
  158. add_filter( 'login_headerurl', 'lps24_login_url' );
  159. function lps24_login_url() { return home_url(); }
  160. add_filter( 'login_headertext', 'lps24_login_title' );
  161. function lps24_login_title() { return get_option( 'blogname' ); }
  162. add_action( 'login_enqueue_scripts', 'lps24_login_logo' );
  163. function lps24_login_logo() {
  164. $logo_image = wp_get_attachment_image_src( get_theme_mod( 'custom_logo' ), 'full' );
  165. ?>
  166. <style type="text/css">
  167. #login h1 a, .login h1 a {
  168. background-image: url(<?php echo get_stylesheet_directory_uri(); ?>/img/_site-icon.png) !important;
  169. }
  170. body.login {
  171. background-color: #001A40 !important;
  172. }
  173. .wp-core-ui .button-primary {
  174. background: #19458c !important;
  175. border-color: #001A40 !important;
  176. }
  177. .wp-core-ui .button-primary.focus,
  178. .wp-core-ui .button-primary.hover,
  179. .wp-core-ui .button-primary:focus,
  180. .wp-core-ui .button-primary:hover {
  181. background: #001A40 !important;
  182. border-color: #001A40 !important;
  183. }
  184. .login #nav a {
  185. color: #E9E4DC !important;
  186. }
  187. .login #backtoblog a {
  188. display: none !important;
  189. }
  190. </style>
  191. <?php
  192. }
  193. /***********************************************************
  194. ###################### Last Login ##########################
  195. ************************************************************/
  196. add_action( 'wp_login', 'lps24_login_timestamp', 20, 2 );
  197. function lps24_login_timestamp( $user_login, $user ) {
  198. update_user_meta( $user->ID, 'last_login', time() );
  199. }
  200. add_filter( 'manage_users_columns', 'lps24_user_last_login_column' );
  201. function lps24_user_last_login_column( $columns ) {
  202. $columns['last_login'] = 'Last Login'; // column ID / column Title
  203. return $columns;
  204. }
  205. add_filter( 'manage_users_custom_column', 'lps24_last_login_column', 10, 3 );
  206. function lps24_last_login_column( $output, $column_id, $user_id ){
  207. if( $column_id == 'last_login' ) {
  208. $last_login = get_user_meta( $user_id, 'last_login', true );
  209. $date_format = 'j M, Y';
  210. $output = $last_login ? date( $date_format, $last_login ) : '-';
  211. }
  212. return $output;
  213. }
  214. add_filter( 'manage_users_sortable_columns', 'lps24_sortable_columns' );
  215. function lps24_sortable_columns( $columns ) {
  216. return wp_parse_args( array(
  217. 'last_login' => 'last_login'
  218. ), $columns );
  219. }
  220. add_action( 'pre_get_users', 'lps24_sort_last_login_column' );
  221. function lps24_sort_last_login_column( $query ) {
  222. if( !is_admin() ) { return; }
  223. $orderby = $query->get('orderby');
  224. if( 'last_login' == $orderby ) {
  225. $query->set('meta_key','last_login');
  226. $query->set('orderby','meta_value');
  227. }
  228. return $query;
  229. }
  230. /***********************************************************
  231. ####################### Comments ###########################
  232. ************************************************************/
  233. add_action('admin_menu', function () {
  234. remove_menu_page('edit-comments.php');
  235. });
  236. add_filter('comments_open', '__return_false', 20, 2);
  237. add_filter('pings_open', '__return_false', 20, 2);
  238. add_action('admin_init','lps24_disable_comments');
  239. function lps24_disable_comments() {
  240. $post_types = get_post_types();
  241. foreach ($post_types as $post_type) {
  242. if(post_type_supports($post_type,'comments')) {
  243. remove_post_type_support($post_type,'comments');
  244. remove_post_type_support($post_type,'trackbacks');
  245. }
  246. }
  247. }
  248. /***********************************************************
  249. ######################## Blocks ############################
  250. ************************************************************/
  251. function lps24_enqueue_assets() {
  252. wp_enqueue_style( 'style-css', get_template_directory_uri() . '/style.css');
  253. }
  254. add_action( 'wp_enqueue_scripts', 'lps24_enqueue_assets' );
  255. function lps24_restrict_locking_ui( $settings, $context ) {
  256. $settings[ 'canLockBlocks' ] = current_user_can( 'activate_plugins' );
  257. return $settings;
  258. }
  259. add_filter( 'block_editor_settings_all', 'lps24_restrict_locking_ui', 10, 2 );
  260. remove_theme_support( 'core-block-patterns' );
  261. add_filter( 'should_load_remote_block_patterns', 'lps24_disable_remote_patterns' );
  262. function lps24_disable_remote_patterns() {
  263. return false;
  264. }
  265. add_filter(
  266. 'block_editor_settings_all',
  267. function( $settings ) {
  268. $settings['enableOpenverseMediaCategory'] = false;
  269. return $settings;
  270. },
  271. 10
  272. );
  273. remove_action( 'enqueue_block_editor_assets', 'wp_enqueue_editor_block_directory_assets' );
  274. /***********************************************************
  275. ######################## Output ############################
  276. ************************************************************/
  277. add_action( 'init', 'lps24_clean_output' );
  278. function lps24_clean_output() {
  279. remove_action( 'wp_head', 'feed_links', 2 );
  280. remove_action( 'wp_head', 'feed_links_extra', 3 );
  281. remove_action( 'wp_head', 'rsd_link' );
  282. remove_action( 'wp_head', 'wp_generator' );
  283. remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
  284. remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
  285. remove_action( 'wp_print_styles', 'print_emoji_styles' );
  286. remove_action( 'admin_print_styles', 'print_emoji_styles' );
  287. remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
  288. remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
  289. remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
  290. }
  291. /***********************************************************
  292. ######################## Forms #############################
  293. ************************************************************/
  294. function lps24_add_gf_capabilities(){
  295. $role = get_role( 'editor' );
  296. $role->add_cap( 'gform_full_access' );
  297. }
  298. add_action( 'admin_init', 'lps24_add_gf_capabilities' );