Add MU plugins

This commit is contained in:
Viktor Szépe 2022-12-21 17:51:01 +00:00
parent 71e540afb9
commit 9094aa49bb
36 changed files with 733 additions and 0 deletions

View file

@ -0,0 +1,24 @@
<?php
// Disable admin email confirmation.
add_filter('admin_email_check_interval', '__return_zero', PHP_INT_MAX, 0);
// Hard-code maintainer email address.
/*
add_filter(
'pre_option_admin_email',
static function () {
return 'admin@szepe.net';
},
PHP_INT_MAX,
0
);
add_filter(
'pre_option_new_admin_email',
static function () {
return 'admin@szepe.net';
},
PHP_INT_MAX,
0
);
*/

View file

@ -0,0 +1,15 @@
<?php
// Remove global styles.
add_action(
'wp',
static function () {
remove_action('wp_enqueue_scripts', 'wp_enqueue_global_styles');
remove_action('wp_footer', 'wp_enqueue_global_styles', 1);
remove_action('wp_body_open', 'wp_global_styles_render_svg_filters');
// TODO: Is this part of one of the hooks above?
// remove_filter('render_block', 'wp_render_duotone_support', 10, 2);
},
100,
0
);

View file

@ -0,0 +1,29 @@
<?php
// Prevent activation of themes having a child theme available
add_action( 'after_switch_theme', function ( $oldtheme_name, $old_theme ) {
$error_message = 'Reverted to previous theme as new one has a child theme';
// Child themes are OK
if ( is_child_theme() ) {
return;
}
// Detect child theme
$current_theme = wp_get_theme();
$themes = wp_get_themes();
foreach ( $themes as $theme ) {
// "Theme Name:" header
if ( $current_theme->name !== $theme->parent_theme ) {
continue;
}
// Switch back to the previous theme as this one has a child
switch_theme( $old_theme->stylesheet );
error_log( sprintf( '%s has a child theme, reverting to %s', $current_theme->name, $old_theme->name ) );
add_action( 'admin_notices', function () {
printf( '<div class="notice-error"><p>%s</p></div>', esc_html( $error_message ) );
} );
break;
}
}, 10, 2 );

View file

@ -0,0 +1,37 @@
<?php
// Reset default REST Site Health capability.
array_map(static function ($check) {
add_filter(
'site_health_test_rest_capability_' . $check,
static function () {
return 'view_site_health_checks';
},
PHP_INT_MAX,
0
);
}, [
'background_updates',
'loopback_requests',
'https_status',
'dotorg_communication',
'authorization_header',
'debug_enabled',
]);
// Revoke capability to access Site Health.
add_filter(
'user_has_cap',
static function ($capabilities) {
return array_merge($capabilities, ['view_site_health_checks' => false]);
},
PHP_INT_MAX,
1
);
// No-op WP_Site_Health class.
class WP_Site_Health
{
public function __construct() {}
public static function get_instance() {}
}

View file

@ -0,0 +1,25 @@
<?php
// Disallow core, plugin, theme installation as WordPress is managed by Composer.
add_filter(
'user_has_cap',
static function ($capabilities) {
return array_merge(
$capabilities,
[
'install_plugins' => false,
'install_themes' => false,
// 'switch_themes' => false,
'delete_plugins' => false,
'delete_themes' => false,
'update_core' => false,
'update_plugins' => false,
'update_themes' => false,
'update_languages' => false,
'install_languages' => false,
]
);
},
PHP_INT_MAX,
1
);

40
mu-plugins/_core-http.php Normal file
View file

@ -0,0 +1,40 @@
<?php
/**
* Use these constants to restrict outbound HTTP requests.
*
* define( 'WP_HTTP_BLOCK_EXTERNAL', true );
* define( 'WP_ACCESSIBLE_HOSTS', 'api.wordpress.org' );
*/
// Log failed external HTTP requests.
add_action( 'http_api_debug', function ( $response, $context, $class, $r, $url ) {
if ( 'response' !== $context || 'Requests' !== $class || ! is_wp_error( $response ) ) {
return;
}
error_log(
sprintf(
'WordPress external HTTP request failed with message [%s:%s] %s (%s)',
$response->get_error_code(),
$response->get_error_message(),
$url,
json_encode( $r, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE )
)
);
}, 99, 5 );
// Debug external HTTP requests.
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) :
add_action( 'http_api_debug', function ( $response, $context, $class, $r, $url ) {
if ( 'response' !== $context || 'Requests' !== $class || is_wp_error( $response ) ) {
return;
}
error_log(
sprintf(
'%s: %s (%s)',
'WordPress external HTTP request',
$url,
json_encode( $r, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE )
)
);
}, 100, 5 );
endif;

View file

@ -0,0 +1,12 @@
<?php
// Never enqueue jQuery Migrate before WordPress 5.5
add_action( 'wp_default_scripts', function ( $scripts ) {
if ( is_admin() || empty( $scripts->registered['jquery'] ) ) {
return;
}
$scripts->registered['jquery']->deps = array_diff(
$scripts->registered['jquery']->deps,
['jquery-migrate']
);
}, 10, 1);

22
mu-plugins/_core-mail.php Normal file
View file

@ -0,0 +1,22 @@
<?php
// Remove X-Mailer header from emails.
add_action( 'phpmailer_init', function ( $phpmailer ) {
$phpmailer->XMailer = ' ';
}, 10, 1 );
// Log mail sending errors.
add_action( 'wp_mail_failed', function ( $error ) {
if ( ! is_wp_error( $error ) ) {
error_log( 'WordPress core failure: not an instance of WP_Error in "wp_mail_failed"' );
return;
}
$message = sprintf(
'Mail sending error: [%s] %s',
$error->get_error_code(),
$error->get_error_message()
);
error_log( $message );
openlog( 'php-fpm', LOG_PID, LOG_LOCAL0 );
syslog( LOG_ALERT, $message );
}, -1, 1 );

View file

@ -0,0 +1,19 @@
<?php
// Fix PHP bug #50921: '200 OK' HTTP status despite PHP error
// https://bugs.php.net/bug.php?id=50921
add_action(
'shutdown',
function () {
// display_errors needs to be disabled
if ( '1' === ini_get( 'display_errors' ) ) {
return;
}
$error = error_get_last();
if ( E_ERROR === $error['type'] ) {
header( 'HTTP/1.1 500 Internal Server Error' );
}
},
0,
0
);

View file

@ -0,0 +1,8 @@
<?php
// Disable pingback revealing real IP address behind a firewall or proxy
// https://www.netsparker.com/blog/web-security/xml-rpc-protocol-ip-disclosure-attacks/
add_filter( 'xmlrpc_methods', function ( $methods ) {
unset( $methods['pingback.ping'] );
return $methods;
}, 11, 1 );

View file

@ -0,0 +1,4 @@
<?php
// Disable post-by-email.
add_filter('enable_post_by_email_configuration', '__return_false', PHP_INT_MAX, 0);

View file

@ -0,0 +1,7 @@
<?php
// Disable new user registration email to admin.
remove_action( 'register_new_user', 'wp_send_new_user_notifications' );
add_action( 'register_new_user', function ( $user_id ) {
wp_new_user_notification( $user_id, null, 'user' );
});

View file

@ -0,0 +1,49 @@
<?php
// Enable manual installation of themes with theme/ subdirectory.
function _core_theme_subdir_helper($source)
{
static $themePath;
$screen = get_current_screen();
if (!$screen instanceof \WP_Screen || $screen->id !== 'update') {
return $source;
}
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
if ($action !== 'upload-theme') {
return $source;
}
if (is_wp_error($source)) {
if (
$source->get_error_code() === 'incompatible_archive_theme_no_style'
&& isset($themePath)
&& is_dir($themePath . 'theme')
) {
// Run on priority 11
return $themePath;
}
return $source;
}
// Run on priority 0
$themePath = $source;
return $source;
}
add_filter(
'upgrader_source_selection',
'_core_theme_subdir_helper',
0,
1
);
add_filter(
'upgrader_source_selection',
'_core_theme_subdir_helper',
11,
1
);

View file

@ -0,0 +1,21 @@
<?php
// Log memory usage.
add_action(
'shutdown',
function () {
$peak_usage = memory_get_peak_usage( true );
// Report above 20 MB.
if ( $peak_usage < 20 * 1024 * 1024 ) {
return;
}
$uri = 'CLI';
if ( isset( $_SERVER['REQUEST_URI'] ) ) {
$uri = wp_json_encode( $_SERVER['REQUEST_URI'], JSON_UNESCAPED_SLASHES );
}
// @codingStandardsChangeSetting WordPress.PHP.DevelopmentFunctions exclude error_log
error_log( sprintf( 'Peak memory usage = %s %s', $peak_usage, $uri ) );
},
-1,
0
);

View file

@ -0,0 +1,18 @@
<?php
// Disallow OSZKbot.
add_filter(
'robots_txt',
static function ($output, $public) {
$lines = [
'User-agent: OSZKbot',
'Disallow: /',
];
if ($public) {
return implode("\n", $lines) . "\n\n" . $output;
}
return $output;
},
-1,
2
);

View file

@ -0,0 +1,14 @@
<?php
/**
* Add-ons
*
* - acf-gravityforms-add-on
*
* @see https://awesomeacf.com/
*/
// Hide admin pages
add_filter( 'acf/settings/show_admin', '__return_false', 10, 0 );
// Export fields to .acf/acf-export.json and as code to inc/acf-fields.php

25
mu-plugins/avada.php Normal file
View file

@ -0,0 +1,25 @@
<?php
// Disable Fusion Patcher.
class Fusion_Patcher
{
public function __construct( $array ) {}
public function get_patcher_checker()
{
return new Fusion_Patcher_Checker();
}
}
class Fusion_Patcher_Checker
{
public function get_cache()
{
return [];
}
}
// Disable Fusion Updater.
class Fusion_Updater
{
public function __construct( $object ) {}
}

View file

@ -0,0 +1,11 @@
<?php
// Remove sender domain error.
add_action(
'wpcf7_config_validator_validate',
static function ($configValidator) {
$configValidator->remove_error('mail.sender', WPCF7_ConfigValidator::error_email_not_in_site_domain);
},
10,
1
);

63
mu-plugins/devberry.php Normal file
View file

@ -0,0 +1,63 @@
<?php
add_action(
'wp_footer',
static function () {
$title = sprintf('%s: v%s', wp_get_theme()->Name, \Company\Project\Theme::VERSION);
?>
<style>
.devberry {
position: fixed;
width: 20px;
height: 20px;
margin: 7px;
top: 0;
left: 0;
z-index: 999990;
border-radius: 50%;
/* margin: 10px; */
background: rgba(154, 89, 181, 1);
transform: scale(1);
box-shadow: 0 0 0 0 rgba(154, 89, 181, 1);
animation: devberry-pulse-purple 2s infinite;
}
.devberry-static {
position: fixed;
width: 0;
height: 0;
top: 0;
right: 0;
z-index: 999990;
border-style: solid;
border-width: 16px;
border-top-color: rgba(154, 89, 181, 1);
border-right-color: rgba(154, 89, 181, 1);
border-bottom-color: transparent;
border-left-color: transparent;
}
@keyframes devberry-pulse-purple {
0% {
transform: scale(0.95);
box-shadow: 0 0 0 0 rgba(154, 89, 181, 0.7);
}
70% {
transform: scale(1);
box-shadow: 0 0 0 10px rgba(154, 89, 181, 0);
}
100% {
transform: scale(0.95);
box-shadow: 0 0 0 0 rgba(154, 89, 181, 0);
}
}
</style>
<div class="devberry" title="<?php echo esc_attr($title); ?>"></div>
<!--
<div class="devberry-static" title="<?php echo esc_attr($title); ?>"></div>
-->
<?php
},
10,
0
);

View file

@ -0,0 +1,9 @@
<?php
// Disable Easy Social Share Buttons plugin updates
add_action( 'plugins_loaded', function () {
global $essb_manager;
if ( method_exists( $essb_manager, 'disableUpdater' ) ) {
$essb_manager->disableUpdates( true );
}
}, 10, 0 );

View file

@ -0,0 +1,21 @@
<?php
/**
* Envato Market plugin for ThemeForest updates
*
* wp plugin install https://envato.github.io/wp-envato-market/dist/envato-market.zip --activate
*/
$envato_market_update = <<<'EOF'
#!/bin/bash
WP_CONTENT_DIR="$(wp --no-debug eval 'echo WP_CONTENT_DIR;')"
if [ -n "$WP_CONTENT_DIR" ] && [ -d "$WP_CONTENT_DIR" ]; then
wp --no-debug plugin install "https://github.com/envato/wp-envato-market/archive/master.zip" --force
fi
EOF;
file_put_contents( 'envato-market-update.sh', $envato_market_update );
chmod( 'envato-market-update.sh', 0755 );

6
mu-plugins/flamingo.php Normal file
View file

@ -0,0 +1,6 @@
<?php
// Remove Address Book submenu
add_action( 'admin_menu', function () {
remove_submenu_page( 'flamingo', 'flamingo' );
}, 9, 0 );

View file

@ -0,0 +1,59 @@
<?php
// Disable Gravity Forms plugin updates
define( 'GRAVITY_MANAGER_URL', null );
define( 'GRAVITY_MANAGER_PROXY_URL', null );
add_filter( 'pre_transient_gform_update_info', '__return_true', 10, 0 );
// Disable auto update
// Old solution: add_filter( 'option_gform_enable_background_updates', '__return_false' );
define( 'GFORM_DISABLE_AUTO_UPDATE', true );
// Prevent continuous .htaccess file creation in wp-content/uploads/gravity_form/
add_filter( 'gform_upload_root_htaccess_rules', '__return_empty_string', 10, 0 );
// Hide admin tooltips
add_filter( 'gform_tooltips', '__return_empty_array', 10, 0 );
// Multipart emails
// https://docs.gravityforms.com/gform_notification/#4-change-the-message-format
add_filter( 'gform_notification', function ( $notification ) {
$notification['message_format'] = 'multipart';
return $notification;
}, 10, 1 );
// Add charset attribute to Content-Type headers in multipart messages
add_filter( 'gform_pre_send_email', function ( $email, $message_format ) {
if ( 'multipart' === $message_format ) {
$charset = sprintf( ' charset="%s";', get_option( 'blog_charset' ) );
// '\S+' could be preg_quote( GFCommon::$email_boundary )
$email['message'] = preg_replace(
'/^(--\S+\r?\nContent-Type: text\/(plain|html);)(\r?\n)/m',
'\1' . $charset . '\3',
$email['message']
);
}
return $email;
}, 10, 2 );
// Make honeypot the second field
add_filter( 'gform_pre_render', function ( $form ) {
if ( count( $form['fields'] ) > 1
&& 'honeypot' === RGFormsModel::get_input_type( end( $form['fields'] ) )
&& 'honeypot' !== RGFormsModel::get_input_type( $form['fields'][1] )
) {
$honeypot = end( $form['fields'] );
array_pop( $form['fields'] );
array_splice( $form['fields'], 1, 0, array( $honeypot ) );
}
return $form;
} );
// Delay inline (printed) script execution, jQuery loads in the footer
add_filter( 'gform_init_scripts_footer', '__return_true' );
add_filter( 'gform_cdata_open', function () {
return 'document.addEventListener( "DOMContentLoaded", function () { ';
} );
add_filter( 'gform_cdata_close', function () {
return ' }, false );';
} );

21
mu-plugins/jetpack.php Normal file
View file

@ -0,0 +1,21 @@
<?php
// Enable Jetpack Search only.
add_filter(
'jetpack_get_available_modules',
static function ($modules) {
return array_intersect_key($modules, ['search' => true]);
},
10,
1
);
// Disable Jetpack Backup cron job.
add_action(
'wp_loaded',
static function () {
remove_all_actions('jetpack_backup_cleanup_helper_scripts');
},
100,
0
);

View file

@ -0,0 +1,10 @@
<?php
// Disable WPBakery Visual Composer plugin updates
add_action( 'plugins_loaded', function () {
global $vc_manager;
if ( method_exists( $vc_manager, 'disableUpdater' ) ) {
$vc_manager->disableUpdater( true );
add_filter( 'pre_option_wpb_js_js_composer_purchase_code', '__return_true' );
}
}, 10, 0 );

7
mu-plugins/kernl.php Normal file
View file

@ -0,0 +1,7 @@
<?php
// Disable Kernl - Private WordPress Plugin & Theme Updates
class ThemeUpdateChecker {
public $purchaseCode = false;
}
class PluginUpdateChecker_2_0 {}

View file

@ -0,0 +1,23 @@
<?php
// Log non-WordPress URL query strings.
add_action(
'parse_request',
static function ($wp) {
if (empty($_SERVER['QUERY_STRING'])) {
return;
}
if (strpos($_SERVER['QUERY_STRING'], '+') !== false) {
error_log(sprintf('Non-WordPress query string: plus_encoded_whitespace ("%s")', $_SERVER['QUERY_STRING']));
return;
}
if (preg_match('/%[[:xdigit:]]?[a-f]/', $_SERVER['QUERY_STRING']) === 1) {
error_log(sprintf('Non-WordPress query string: lower_case_hexadecimal_digit ("%s")', $_SERVER['QUERY_STRING']));
return;
}
},
0,
1
);

View file

@ -0,0 +1,17 @@
<?php
// Prevent Redux Framework HTTP requests
$GLOBALS['redux_update_check'] = 1;
add_filter( 'redux/ascend/aURL_filter', '__return_empty_string', 10, 0 );
add_filter( 'get_user_option_' . 'r_tru_u_x', function () {
return array(
'expires' => PHP_INT_MAX,
'id' => '',
);
}, 10, 0 );
add_action( 'after_setup_theme', function () {
remove_all_actions( 'wp_ajax_nopriv_redux_p' );
remove_all_actions( 'wp_ajax_redux_p' );
}, 10, 0 );
// Search for 'opt_name' in the code

15
mu-plugins/revslider.php Normal file
View file

@ -0,0 +1,15 @@
<?php
/**
* Trigger fail2ban on Revolution Slider upload attempt.
*
* revslider/revslider_admin.php:389
*
* case "update_plugin":
*
* // self::updatePlugin(self::DEFAULT_VIEW);
*
* Patched in version 4.2
*/
error_log( 'Break-in attempt detected: ' . 'revslider_update_plugin' );
exit;

View file

@ -0,0 +1,8 @@
<?php
// Disable SOGO Accessability plugin (a11y) license check
add_action( 'wp_ajax_check_license', function () {
add_filter( 'pre_http_request', function ( $status ) {
return new WP_Error( 'sogo_license_check_disabled' );
}, 10, 1 );
}, 10, 0 );

View file

@ -0,0 +1,5 @@
<?php
add_action( 'wp_footer', function () {
echo "\n<!-- Infrastructure, source code management and consulting: Viktor Szépe <viktor@szepe.net> -->\n";
}, PHP_INT_MAX, 0 );

19
mu-plugins/tgmpa.php Normal file
View file

@ -0,0 +1,19 @@
<?php
// Disable TGMPA (procedural)
add_action( 'after_setup_theme', function () {
remove_action( 'admin_init', 'tgmpa_load_bulk_installer' );
// EDIT
remove_action( 'tgmpa_register', 'CUSTOM-FUNCTION' );
}, PHP_INT_MAX, 0 );
// Disable TGMPA (OOP)
add_action( 'after_setup_theme', function () {
// EDIT - example: $wpoEngine
global $wpoEngine;
if ( method_exists( $wpoEngine, 'initRequiredPlugin' ) ) {
remove_action( 'admin_init', 'tgmpa_load_bulk_installer' );
remove_action( 'tgmpa_register', array( $wpoEngine, 'initRequiredPlugin' ) );
}
}, PHP_INT_MAX, 0 );

View file

@ -0,0 +1,28 @@
<?php
/**
* Unity theme
*/
$unity_theme_update = <<<'EOF'
#!/bin/bash
CURRENT="$(dirname "$0")/external-plugin-update.log"
# From wp-content/themes/unity/inc/frontend.php
EXTERNAL_PLUGINS=(
http://www.wpopal.com/thememods/appthemer-crowdfunding.zip
http://www.wpopal.com/thememods/js_composer.zip
http://www.wpopal.com/thememods/revslider.zip
)
for PLUGIN in ${EXTERNAL_PLUGINS[@]}; do
wget -q --spider -S "$PLUGIN" 2>&1 | grep -F 'Last-Modified:'
done | diff "$CURRENT" -
#exit 0
EOF;
file_put_contents( 'unity-plugin-update.sh', $unity_theme_update );
chmod( 'unity-plugin-update.sh', 0755 );

View file

@ -0,0 +1,6 @@
<?php
// Remove WooCommerce guided tour videos
add_action( 'current_screen', function () {
get_current_screen()->remove_help_tab( 'woocommerce_guided_tour_tab' );
}, 51, 0 );

View file

@ -0,0 +1,32 @@
<?php
// Remove JSON for Linking Data
// https://json-ld.org/
// https://developers.google.com/search/docs/guides/intro-structured-data
add_filter( 'wpseo_json_ld_output', '__return_empty_array', 10, 0 );
// Dequeue HelpScout Beacon JavaScript
add_action( 'admin_enqueue_scripts', function () {
wp_dequeue_script( 'yoast-seo-help-scout-beacon' );
}, 99, 0 );
// Hide Premium Upsell metabox and dim sidebar
add_action( 'admin_enqueue_scripts', function ( $hook ) {
if ( false === strpos( $hook, 'wpseo_' ) ) {
return;
}
$style = '.wp-admin .yoast_premium_upsell { display:none !important; }';
$style .= '.wp-admin #sidebar-container { opacity: 0.30; }';
wp_add_inline_style( 'wp-admin', $style );
}, 20, 1 );
// Remove Premium page
add_filter( 'wpseo_submenu_pages', function ( $submenu_pages ) {
foreach ( $submenu_pages as $key => $submenu_page ) {
// Fifth element is $page_slug
if ( in_array( $submenu_page[4], ['wpseo_licenses', 'wpseo_workouts', 'wpseo_redirects'] ) ) {
unset( $submenu_pages[ $key ] );
}
}
return $submenu_pages;
}, 99, 1 );

View file

@ -0,0 +1,4 @@
<?php
// Move Activity menu under Dashboard
add_filter( 'wp_user_activity_menu_humility', '__return_true', 10, 0 );