functions.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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 != '0') {
  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_submenu_page('themes.php', 'themes-editor.php');
  102. remove_submenu_page('themes.php', 'customize.php?return=');
  103. remove_submenu_page('themes.php', 'themes.php');
  104. remove_submenu_page('themes.php', 'theme-editor.php');
  105. remove_submenu_page('themes.php', 'theme_options');
  106. remove_submenu_page('gf_edit_forms', 'gf_new_form');
  107. remove_submenu_page('gf_edit_forms', 'gf_export');
  108. remove_submenu_page('gf_edit_forms', 'gf_addons');
  109. remove_submenu_page('gf_edit_forms', 'gf_settings');
  110. remove_submenu_page('gf_edit_forms', 'gf_help');
  111. remove_submenu_page('gf_edit_forms', 'gf_system_status');
  112. }
  113. }
  114. add_action( 'wp_dashboard_setup', 'lps24_disable_dashboard_items' );
  115. function lps24_disable_dashboard_items() {
  116. remove_action('admin_notices', 'update_nag');
  117. remove_action('welcome_panel', 'wp_welcome_panel');
  118. remove_meta_box('dashboard_primary', 'dashboard', 'side');
  119. remove_meta_box('dashboard_secondary', 'dashboard', 'side');
  120. remove_meta_box('dashboard_quick_press', 'dashboard', 'side');
  121. remove_meta_box('dashboard_site_health', 'dashboard', 'normal');
  122. }
  123. add_action('admin_head', 'lps24_glance_version');
  124. function lps24_glance_version() {
  125. echo '<style>#dashboard_right_now p:last-child {display:none;}</style>';
  126. }
  127. add_filter('admin_title', 'lps24_admin_title', 10, 2);
  128. function lps24_admin_title($admin_title, $title) {
  129. return $title .' - '. get_bloginfo('name');
  130. }
  131. add_filter ('admin_footer_text', 'lps24_footer_filter');
  132. function lps24_footer_filter ($default) {
  133. return '';
  134. }
  135. add_filter('gettext', 'lps24_replace_howdy', 10, 3);
  136. function lps24_replace_howdy($translated_text, $text, $domain) {
  137. $new_message = str_replace('Howdy,', '', $text);
  138. return $new_message;
  139. }
  140. add_filter( 'gettext', 'lps24_change_howdy_text', 10, 2 );
  141. function lps24_change_howdy_text( $translation, $original ) {
  142. if( 'Howdy, %1$s' == $original )
  143. $translation = '%1$s';
  144. return $translation;
  145. }
  146. add_action( 'admin_head-profile.php', 'lps24_remove_admin_color' );
  147. function lps24_remove_admin_color() {
  148. remove_action( 'admin_color_scheme_picker', 'admin_color_scheme_picker' );
  149. }
  150. add_action('admin_head', 'lps24_remove_help_tabs');
  151. function lps24_remove_help_tabs() {
  152. $screen = get_current_screen();
  153. $screen->remove_help_tabs();
  154. }
  155. add_filter( 'login_headerurl', 'lps24_login_url' );
  156. function lps24_login_url() { return home_url(); }
  157. add_filter( 'login_headertext', 'lps24_login_title' );
  158. function lps24_login_title() { return get_option( 'blogname' ); }
  159. add_action( 'login_enqueue_scripts', 'lps24_login_logo' );
  160. function lps24_login_logo() {
  161. $logo_image = wp_get_attachment_image_src( get_theme_mod( 'custom_logo' ), 'full' );
  162. ?>
  163. <style type="text/css">
  164. #login h1 a, .login h1 a {
  165. background-image: url(<?php echo get_stylesheet_directory_uri(); ?>/img/_site-icon.png) !important;
  166. }
  167. body.login {
  168. background-color: #001A40 !important;
  169. }
  170. .wp-core-ui .button-primary {
  171. background: #19458c !important;
  172. border-color: #001A40 !important;
  173. }
  174. .wp-core-ui .button-primary.focus,
  175. .wp-core-ui .button-primary.hover,
  176. .wp-core-ui .button-primary:focus,
  177. .wp-core-ui .button-primary:hover {
  178. background: #001A40 !important;
  179. border-color: #001A40 !important;
  180. }
  181. .login #nav a {
  182. color: #E9E4DC !important;
  183. }
  184. .login #backtoblog a {
  185. display: none !important;
  186. }
  187. </style>
  188. <?php
  189. }
  190. /***********************************************************
  191. ###################### Last Login ##########################
  192. ************************************************************/
  193. add_action( 'wp_login', 'lps24_login_timestamp', 20, 2 );
  194. function lps24_login_timestamp( $user_login, $user ) {
  195. update_user_meta( $user->ID, 'last_login', time() );
  196. }
  197. add_filter( 'manage_users_columns', 'lps24_user_last_login_column' );
  198. function lps24_user_last_login_column( $columns ) {
  199. $columns['last_login'] = 'Last Login'; // column ID / column Title
  200. return $columns;
  201. }
  202. add_filter( 'manage_users_custom_column', 'lps24_last_login_column', 10, 3 );
  203. function lps24_last_login_column( $output, $column_id, $user_id ){
  204. if( $column_id == 'last_login' ) {
  205. $last_login = get_user_meta( $user_id, 'last_login', true );
  206. $date_format = 'j M, Y';
  207. $output = $last_login ? date( $date_format, $last_login ) : '-';
  208. }
  209. return $output;
  210. }
  211. add_filter( 'manage_users_sortable_columns', 'lps24_sortable_columns' );
  212. function lps24_sortable_columns( $columns ) {
  213. return wp_parse_args( array(
  214. 'last_login' => 'last_login'
  215. ), $columns );
  216. }
  217. add_action( 'pre_get_users', 'lps24_sort_last_login_column' );
  218. function lps24_sort_last_login_column( $query ) {
  219. if( !is_admin() ) { return; }
  220. $orderby = $query->get('orderby');
  221. if( 'last_login' == $orderby ) {
  222. $query->set('meta_key','last_login');
  223. $query->set('orderby','meta_value');
  224. }
  225. return $query;
  226. }
  227. /***********************************************************
  228. ####################### Comments ###########################
  229. ************************************************************/
  230. add_action('admin_menu', function () {
  231. remove_menu_page('edit-comments.php');
  232. });
  233. add_filter('comments_open', '__return_false', 20, 2);
  234. add_filter('pings_open', '__return_false', 20, 2);
  235. add_action('admin_init','lps24_disable_comments');
  236. function lps24_disable_comments() {
  237. $post_types = get_post_types();
  238. foreach ($post_types as $post_type) {
  239. if(post_type_supports($post_type,'comments')) {
  240. remove_post_type_support($post_type,'comments');
  241. remove_post_type_support($post_type,'trackbacks');
  242. }
  243. }
  244. }
  245. /***********************************************************
  246. ######################## Blocks ############################
  247. ************************************************************/
  248. function lps24_enqueue_assets() {
  249. wp_enqueue_style( 'style-css', get_template_directory_uri() . '/style.css');
  250. }
  251. add_action( 'wp_enqueue_scripts', 'lps24_enqueue_assets' );
  252. function lps24_restrict_locking_ui( $settings, $context ) {
  253. $settings[ 'canLockBlocks' ] = current_user_can( 'activate_plugins' );
  254. return $settings;
  255. }
  256. add_filter( 'block_editor_settings_all', 'lps24_restrict_locking_ui', 10, 2 );
  257. remove_theme_support( 'core-block-patterns' );
  258. add_filter( 'should_load_remote_block_patterns', 'lps24_disable_remote_patterns' );
  259. function lps24_disable_remote_patterns() {
  260. return false;
  261. }
  262. add_filter(
  263. 'block_editor_settings_all',
  264. function( $settings ) {
  265. $settings['enableOpenverseMediaCategory'] = false;
  266. return $settings;
  267. },
  268. 10
  269. );
  270. remove_action( 'enqueue_block_editor_assets', 'wp_enqueue_editor_block_directory_assets' );
  271. /***********************************************************
  272. ######################## Output ############################
  273. ************************************************************/
  274. add_action( 'init', 'lps24_clean_output' );
  275. function lps24_clean_output() {
  276. remove_action( 'wp_head', 'feed_links', 2 );
  277. remove_action( 'wp_head', 'feed_links_extra', 3 );
  278. remove_action( 'wp_head', 'rsd_link' );
  279. remove_action( 'wp_head', 'wp_generator' );
  280. remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
  281. remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
  282. remove_action( 'wp_print_styles', 'print_emoji_styles' );
  283. remove_action( 'admin_print_styles', 'print_emoji_styles' );
  284. remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
  285. remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
  286. remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
  287. }
  288. /***********************************************************
  289. ######################## Forms #############################
  290. ************************************************************/
  291. function lps24_add_gf_capabilities(){
  292. $role = get_role( 'editor' );
  293. $role->add_cap( 'gform_full_access' );
  294. }
  295. add_action( 'admin_init', 'lps24_add_gf_capabilities' );