kompass/bdp-kompass.php

146 lines
4.5 KiB
PHP

<?php
/**
* Plugin Name: BdP Kompass
* Description: Wordpress-Plugin zur Unterstützung von Stämmen im Bund der Pfadfinderinnen und Pfadfinder e.V. zur optimalen Verwaltung eurer Webseite
* Version: 4.6.2
* Tags: bdp, utility, helper
* Requires at least: 6.0
* Requires PHP: 8.2
* Author: Thomas Günther
* Author URI: https://www.sachsen.pfadfinden.de
* Update URI: http://lv-sachsen-main.bdp.mein-verein.online/wordpress/
* Text Domain: bdp-kompass
*/
use Bdp\Modules\EventParticipants\Controllers\MainController as EventsMain;
use Bdp\Modules\KompassSettings\Controllers\SettingsPage as KomnpassSettings;
use Bdp\Modules\LimitLoginAttempts\Controllers\OptionsPage as OptionsPageAlias;
use Bdp\Modules\Mail\Controllers\MailController;
use Bdp\Modules\Mail\Controllers\MailSettingsController;
use Bdp\Modules\Security\Security;
use Bdp\Modules\Seo\Seo;
require_once dirname(__FILE__) . '/includes/setup.php';
function bdp_plugin_install() {
}
function bdp_plugin_init() {
bdp_kompass_load_plugin_textdomain();
Security::ProhibitBots();
Security::SetPageFilters();
if (null == get_option('kompass_already_installed', null)) {
Seo::setup();
Calendar::setup();
Security::setup();
update_option('kompass_already_installed', true);
wp_redirect( 'site-health.php?tab=bdp_enhanced_security');
}
Seo::importVerificationKeys();
}
add_action('admin_menu', function () {
bdp_kompass_load_plugin_textdomain();
new OptionsPageAlias();
new KomnpassSettings();
new EventsMain();
new MailController();
});
add_action('wp_ajax_kompass_show_ajax', 'kompass_load_ajax_content');
add_action('wp_ajax_nopriv_kompass_show_ajax', 'kompass_load_ajax_content');
function register_custom_theme_directory() {
if (is_dir(ABSPATH . '/wp-content/themes/mareike-theme/')) {
return;
}
$file = ABSPATH . '/wp-content/plugins/bdp-kompass/lib/mareike-theme/' ;
system('mkdir ' . ABSPATH . '/wp-content/themes/mareike-theme/');
system('cp -r ' . $file . '* ' . ABSPATH . '/wp-content/themes/mareike-theme/');
}
function enqueue_custom_password_js() {
wp_enqueue_script( 'kompass-ajax', BDP_LV_PLUGIN_URL . '/assets/ajax.js');
wp_enqueue_script( 'searchable-table', BDP_LV_PLUGIN_URL . '/assets/searchtable.js');
wp_enqueue_script( 'custom-password-js', BDP_LV_PLUGIN_URL . 'assets/password.js');
wp_localize_script( 'custom-password-js', 'php_vars', [
'allowed_strengths' => kompass_get_minimal_password_strength(),
'password_too_short_text' => 'Dass Passwort entspricht nicht den Anforderungen.'
]);
}
add_action( 'after_setup_theme', 'kompass_after_setup_theme' );
add_action( 'admin_menu', ['Bdp\Modules\KompassSettings\Controllers\SettingsPage', 'add_menu'] );
function crp_custom_register_form() {
}
add_action('register_form', ['Bdp\Modules\Registration\Controllers\ExtendRegistrationForm', 'execute']);
// Validate registration form fields
add_filter('registration_errors', ['Bdp\Modules\Registration\Controllers\ExtendRegistrationForm', 'error_messages'], 10, 3);
// Save custom user meta data
add_action('user_register', ['\Bdp\Modules\Registration\Controllers\SaveRegistration', 'execute']);
// Handle account activation
add_action('init', ['Bdp\Modules\Registration\Controllers\SaveRegistration', 'activate_user']);
// Prevent login if account is not activated
add_filter('authenticate', ['Bdp\Modules\Registration\Controllers\SaveRegistration', 'check_user_activation'], 30, 3);
function crp_allow_umlauts_in_usernames($username, $raw_username, $strict) {
if (!$strict) {
return $username;
}
// Allow letters, numbers, underscores, spaces, periods, hyphens, and umlauts
$username = preg_replace('/[^a-zA-Z0-9 _.\-äöüÄÖÜß]/', '', $raw_username);
return $username;
}
add_filter('sanitize_user', 'crp_allow_umlauts_in_usernames', 10, 3);
add_action('login_message', ['Bdp\Modules\Registration\Controllers\SaveRegistration','display_custom_message']);
if (false === (bool)get_option('user_can_register', false)) {
add_filter('registration_errors', 'kompass_disable_user_registration', 10, 3);
function kompass_disable_user_registration($errors, $sanitized_user_login, $user_email) {
$errors->add('registration_disabled', __('Die Registrierung ist derzeit deaktiviert.'));
return $errors;
}
add_action('login_enqueue_scripts', 'kompass_remove_register_link');
function kompass_remove_register_link() {
?>
<style>
#registerform {
display: none !important;
}
</style>
<?php
}
}
MailSettingsController::set_smtp_if_required();