+ ADD CI/CD

This commit is contained in:
felegy
2025-08-29 11:44:13 +00:00
parent 696fb9b22c
commit cc84f76490
7 changed files with 352 additions and 153 deletions

View File

@@ -15,69 +15,72 @@
* Author URI: https://github.com/felegy
*/
defined( 'ABSPATH' ) || die('Restricted Area');
namespace App;
defined('ABSPATH') || die('Restricted Area');
class AppMuPlugin
{
public function __construct()
{
// Define constants
$this->define_constants();
$this->defineConstants();
if (defined('ERROR_LOG_TO_STDOUT')) {
if (ERROR_LOG_TO_STDOUT) {
// WP error log to stdout
$this->error_log_to_stdout();
$this->errorLogToStdout();
}
}
if (defined('S3_UPLOADS_ENDPOINT')) {
// Filter S3 Uploads params.
$this->s3_uploads_endpoint();
$this->s3UploadsEndpoint();
}
if (defined('SMTP_ENABLED') && SMTP_ENABLED) {
// If SMTP is enabled, setup PHPMailer
if (defined('SMTP_SERVER') && defined('SMTP_PORT')) {
$this->setup_phpmailer();
$this->setupPhpMailer();
}
}
$this->header_security();
$this->no_wordpress_errors();
$this->sanitize_file_name();
$this->remove_wp_version();
$this->cc_mime_types();
$this->two_factor_default();
$this->on_logout_redirect();
$this->headerSecurity();
$this->noWordpressErrors();
$this->sanitizeFileName();
$this->removeWpVersion();
$this->ccMimeTypes();
$this->twoFactorDefault();
$this->onLogoutRedirect();
}
private function define_constants() {
private function defineConstants()
{
if ( ! defined( 'SMTP_SERVER') ) {
define( 'SMTP_SERVER', '127.0.0.1' );
if (!defined('SMTP_SERVER')) {
define('SMTP_SERVER', '127.0.0.1');
}
if ( ! defined( 'SMTP_PORT') ) {
define( 'SMTP_PORT', 1025 );
if (!defined('SMTP_PORT')) {
define('SMTP_PORT', 1025);
}
if ( ! defined( 'BLOG_SLUG') ) {
define( 'BLOG_SLUG', 'wp' );
if (!defined('BLOG_SLUG')) {
define('BLOG_SLUG', 'wp');
}
}
private function error_log_to_stdout() {
private function errorLogToStdout()
{
// Add your initialization code here.
// WP error log to stdout
add_action('init', function () {
ini_set ('error_log', '/dev/stdout'); // phpcs:ignore
}, 10);
}
private function s3_uploads_endpoint() {
private function s3UploadsEndpoint()
{
// Filter S3 Uploads params.
add_filter('s3_uploads_s3_client_params', function ($params) {
$params['endpoint'] = defined('S3_UPLOADS_ENDPOINT') ? S3_UPLOADS_ENDPOINT : "";
@@ -87,33 +90,36 @@ class AppMuPlugin
});
}
private function header_security() {
private function headerSecurity()
{
// Add Security headers.
add_filter('wp_headers',
function ($headers) {
$headers['X-Frame-Options'] = 'SAMEORIGIN';
$headers['X-Content-Type-Options'] = 'nosniff';
$headers['X-XSS-Protection'] = '1; mode=block';
$headers['Strict-Transport-Security'] = 'max-age=31536000; includeSubDomains';
$headers['Referrer-Policy'] = 'same-origin';
$headers['Permissions-Policy'] = 'geolocation=()';
$headers['Content-Security-Policy'] = 'upgrade-insecure-requests';
add_filter(
'wp_headers',
function ($headers) {
$headers['X-Frame-Options'] = 'SAMEORIGIN';
$headers['X-Content-Type-Options'] = 'nosniff';
$headers['X-XSS-Protection'] = '1; mode=block';
$headers['Strict-Transport-Security'] = 'max-age=31536000; includeSubDomains';
$headers['Referrer-Policy'] = 'same-origin';
$headers['Permissions-Policy'] = 'geolocation=()';
$headers['Content-Security-Policy'] = 'upgrade-insecure-requests';
return $headers;
});
return $headers;
}
);
}
private function no_wordpress_errors()
private function noWordpressErrors()
{
add_filter('login_errors', function () {
return 'Hiba történt a belépés során!';
});
}
private function sanitize_file_name()
private function sanitizeFileName()
{
// Clean file name when uploading files in WordPress.
add_filter('sanitize_file_name', function ($filename){
add_filter('sanitize_file_name', function ($filename) {
$extension = substr($filename, strrpos($filename, '.') + 1);
$filename = substr($filename, 0, strrpos($filename, '.'));
@@ -121,21 +127,23 @@ class AppMuPlugin
});
}
private function remove_wp_version() {
private function removeWpVersion()
{
// Remove WordPress version from HTML source.
add_filter('the_generator', '__return_empty_string');
}
private function cc_mime_types() {
private function ccMimeTypes()
{
// Add SVG to mime_types.
add_filter('upload_mimes', function ($mimes)
{
add_filter('upload_mimes', function ($mimes) {
$mimes['svg'] = 'image/svg+xml';
return $mimes;
});
}
private function setup_phpmailer() {
private function setupPhpMailer()
{
add_action('phpmailer_init', function ($phpmailer) {
$phpmailer->Host = SMTP_SERVER;
$phpmailer->Port = SMTP_PORT;
@@ -161,10 +169,9 @@ class AppMuPlugin
$phpmailer->SMTPSecure = false; // Disable encryption
}
if(defined('SMTP_DOMAIN')) {
if (defined('SMTP_DOMAIN')) {
$phpmailer->From = BLOG_SLUG . '@' . SMTP_DOMAIN;
}
else {
} else {
$dsn = (object) parse_url(get_bloginfo('url'));
$phpmailer->From = BLOG_SLUG . '@' . $dsn->host;
}
@@ -175,9 +182,9 @@ class AppMuPlugin
});
}
private function two_factor_default() {
add_filter('two_factor_providers', function ($providers)
{
private function twoFactorDefault()
{
add_filter('two_factor_providers', function ($providers) {
// Disable FIDO U2F by default
// ISSUE https://wordpress.org/support/topic/i-cant-add-my-yubikey/
$providers['Two_Factor_FIDO_U2F'] = '';
@@ -188,21 +195,19 @@ class AppMuPlugin
// Enable Two Factor Email by default
// force email two factor authentication
add_filter('two_factor_enabled_providers_for_user', function ($providers)
{
if (! in_array('Two_Factor_Email', $providers))
{
add_filter('two_factor_enabled_providers_for_user', function ($providers) {
if (! in_array('Two_Factor_Email', $providers)) {
array_push($providers, 'Two_Factor_Email');
}
return $providers;
});
}
private function on_logout_redirect() {
add_action('wp_logout', function ()
{
private function onLogoutRedirect()
{
add_action('wp_logout', function () {
if (defined('LOGOUT_REDIRECT_URL')) {
wp_redirect( LOGOUT_REDIRECT_URL );
wp_redirect(LOGOUT_REDIRECT_URL);
exit;
}
});