> $plugins Registered plugins. * @return array> */ function nnax_sce_localize_plugin_card_data( $plugins ) { if ( isset( $plugins[ plugin_basename( __FILE__ ) ] ) ) { $plugins[ plugin_basename( __FILE__ ) ]['Description'] = __( 'Provides the essential features for building and administering WordPress webpages.', 'nnax-web-essentials' ); $plugins[ plugin_basename( __FILE__ ) ]['Author'] = 'S. Heinrich - nnax IT-Lösungen'; $plugins[ plugin_basename( __FILE__ ) ]['AuthorName'] = 'S. Heinrich - nnax IT-Lösungen'; } return $plugins; } add_filter( 'all_plugins', 'nnax_sce_localize_plugin_card_data' ); /** * Check whether the premium add-on is active. * * Uses the active plugin options so the host plugin can detect the add-on * before the premium bootstrap has fully run. * * @return bool */ function nnax_sce_is_premium_plugin_active() { if ( defined( 'NNAX_SCE_PREMIUM_ACTIVE' ) && NNAX_SCE_PREMIUM_ACTIVE ) { return true; } // During WordPress activation sandbox scraping, avoid treating the add-on as // active purely based on the option list before its bootstrap has completed. if ( defined( 'WP_SANDBOX_SCRAPING' ) && WP_SANDBOX_SCRAPING ) { return false; } $premium_basename = NNAX_SCE_PREMIUM_PLUGIN_BASENAME; $active_plugins = (array) get_option( 'active_plugins', array() ); if ( in_array( $premium_basename, $active_plugins, true ) ) { return true; } if ( is_multisite() ) { $network_active_plugins = (array) get_site_option( 'active_sitewide_plugins', array() ); return isset( $network_active_plugins[ $premium_basename ] ); } return false; } if ( nnax_sce_is_premium_plugin_active() && ! defined( 'NNAX_SCE_PREMIUM_ACTIVE' ) ) { define( 'NNAX_SCE_PREMIUM_ACTIVE', true ); } /** * Check if user can manage plugin access settings. * * @return bool */ function nnax_user_can_manage_plugin_access() { return current_user_can( 'manage_options' ); } /** * Check if user can view the plugin. * * @return bool */ function nnax_user_can_view_plugin() { return current_user_can( 'manage_options' ) || current_user_can( NNAX_CAP_VIEW ) || current_user_can( NNAX_CAP ); } /** * Check if user can edit plugin settings. * * @return bool */ function nnax_user_can_edit_plugin() { return current_user_can( 'manage_options' ) || current_user_can( NNAX_CAP ); } /** * Check if user is in readonly mode for this plugin. * * @return bool */ function nnax_is_plugin_readonly_user() { return nnax_user_can_view_plugin() && ! nnax_user_can_edit_plugin(); } /** * Render readonly banner. * * @return void */ function nnax_sce_render_readonly_banner() { ?>

add_cap( NNAX_CAP_VIEW ); $admin_role->add_cap( NNAX_CAP ); } // Include-Statements für die Settings. require_once plugin_dir_path( __FILE__ ) . 'includes/settings-handler.php'; require_once plugin_dir_path( __FILE__ ) . 'includes/class-helper.php'; // Include-Statements für die Unterdateien (Basis zuerst, damit Helper/DB-Funktionen verfügbar sind). require_once plugin_dir_path( __FILE__ ) . 'includes/basic-functions.php'; require_once plugin_dir_path( __FILE__ ) . 'includes/administration-functions.php'; require_once plugin_dir_path( __FILE__ ) . 'includes/security-functions.php'; // Include-Statements für die Unterseiten. require_once plugin_dir_path( __FILE__ ) . 'templates/admin/menu-callback.php'; require_once plugin_dir_path( __FILE__ ) . 'templates/admin/backend-administration.php'; require_once plugin_dir_path( __FILE__ ) . 'templates/admin/security-features.php'; require_once plugin_dir_path( __FILE__ ) . 'templates/admin/server-performance.php'; /** * Register plugin menu and submenus. * * @return void */ function nnax_add_menu() { global $nnax_admin_hooks; $nnax_admin_hooks = array(); $nnax_admin_hooks[] = add_menu_page( __( 'nnax Essentials', 'nnax-web-essentials' ), __( 'nnax Essentials', 'nnax-web-essentials' ), NNAX_CAP_VIEW, 'nnax-web-essentials', 'nnax_menu_callback', plugin_dir_url( __FILE__ ) . 'assets/img/nnax-web-logo.png', 99 ); $nnax_admin_hooks[] = add_submenu_page( 'nnax-web-essentials', __( 'General', 'nnax-web-essentials' ), __( 'General', 'nnax-web-essentials' ), NNAX_CAP_VIEW, 'nnax-web-essentials', 'nnax_menu_callback' ); $nnax_admin_hooks[] = add_submenu_page( 'nnax-web-essentials', __( 'Administration', 'nnax-web-essentials' ), __( 'Administration', 'nnax-web-essentials' ), NNAX_CAP_VIEW, 'nnax-sce-administration', 'nnax_custom_administration_options_page_html' ); $nnax_admin_hooks[] = add_submenu_page( 'nnax-web-essentials', __( 'Security', 'nnax-web-essentials' ), __( 'Security', 'nnax-web-essentials' ), NNAX_CAP_VIEW, 'nnax-sce-securityfeatures', 'nnax_custom_security_features_options_page_html' ); $nnax_admin_hooks[] = add_submenu_page( 'nnax-web-essentials', __( 'Server Performance', 'nnax-web-essentials' ), __( 'Server Performance', 'nnax-web-essentials' ), NNAX_CAP_VIEW, 'nnax-sce-server-performance', 'nnax_spi_display_admin_page' ); } add_action( 'admin_menu', 'nnax_add_menu' ); /** * Enqueue admin assets. * * Keeps the nnax menu icon styling available throughout wp-admin and loads * plugin-specific assets only on the relevant settings pages. * * @param string $hook Current admin hook suffix. * @return void */ function nnax_admin_enqueue_assets( $hook ) { // The icon is visible in the admin menu on every screen, but this handle has // no external stylesheet URL, so the small inline rule adds no extra request. wp_register_style( 'nnax-global-admin', false, array(), '1.0.2' ); wp_enqueue_style( 'nnax-global-admin' ); wp_add_inline_style( 'nnax-global-admin', '#adminmenu .toplevel_page_nnax-web-essentials .wp-menu-image {' . 'display: flex;' . 'align-items: center;' . 'justify-content: center;' . '}' . '#adminmenu .toplevel_page_nnax-web-essentials .wp-menu-image img {' . 'width: 16px !important;' . 'height: 16px !important;' . 'max-width: 16px !important;' . 'max-height: 16px !important;' . 'object-fit: contain;' . 'padding: 0 !important;' . '}' ); global $nnax_admin_hooks; if ( empty( $nnax_admin_hooks ) || ! in_array( $hook, $nnax_admin_hooks, true ) ) { return; } wp_enqueue_style( 'nnax-admin-ui', plugin_dir_url( __FILE__ ) . 'assets/css/nnax-admin-ui.css', array(), '1.0.0' ); wp_enqueue_style( 'nnax-admin-settings', plugin_dir_url( __FILE__ ) . 'assets/css/admin-settings.css', array( 'nnax-admin-ui' ), '1.0.3' ); wp_enqueue_script( 'nnax-sce-admin', plugin_dir_url( __FILE__ ) . 'assets/js/admin-settings.js', array( 'jquery' ), '1.0.0', array( 'in_footer' => true ) ); wp_add_inline_script( 'nnax-sce-admin', 'window.nnaxSceAdminI18n = ' . wp_json_encode( array( 'note' => __( 'Note', 'nnax-web-essentials' ), 'pleaseWait' => __( 'Please wait…', 'nnax-web-essentials' ), 'success' => __( 'Success', 'nnax-web-essentials' ), 'error' => __( 'Error', 'nnax-web-essentials' ), 'unknownError' => __( 'Error: Unknown response.', 'nnax-web-essentials' ), 'savingFailed' => __( 'Saving failed.', 'nnax-web-essentials' ), 'ajaxFailed' => __( 'Error: AJAX request failed.', 'nnax-web-essentials' ), 'networkError' => __( 'AJAX error:', 'nnax-web-essentials' ), ) ) . ';', 'before' ); } add_action( 'admin_enqueue_scripts', 'nnax_admin_enqueue_assets' ); /** * Activation routine for plugin setup. * * @return void */ function nnax_on_activate() { // 0) Version Check (WP 5.3+, PHP 7.4+). if ( version_compare( get_bloginfo( 'version' ), '5.3', '<' ) ) { wp_die( esc_html__( 'This plugin requires WordPress version 5.3 or higher.', 'nnax-web-essentials' ) ); } if ( version_compare( PHP_VERSION, '7.4', '<' ) ) { wp_die( esc_html__( 'This plugin requires PHP version 7.4 or higher.', 'nnax-web-essentials' ) ); } // Initialize every site on network activation, not only the current blog. $blog_ids = is_multisite() ? get_sites( array( 'fields' => 'ids', 'number' => 0 ) ) : array( get_current_blog_id() ); foreach ( $blog_ids as $blog_id ) { if ( is_multisite() ) { switch_to_blog( (int) $blog_id ); } if ( function_exists( 'nnax_create_database_table' ) ) { if ( ! nnax_create_database_table() ) { wp_die( esc_html__( 'nnax Web Essentials could not create or update its settings table. Check the database connection and permissions, then try activating the plugin again.', 'nnax-web-essentials' ) ); } } nnax_sce_ensure_admin_caps(); if ( is_multisite() ) { restore_current_blog(); } } // 6) Login-Rename-Komponente (falls vorhanden) aktivieren/Rewrite flushen. if ( class_exists( 'NNAX_Rename_WP_Admin_Login' ) && method_exists( 'NNAX_Rename_WP_Admin_Login', 'activate_static' ) ) { NNAX_Rename_WP_Admin_Login::activate_static(); } elseif ( class_exists( 'NNAX_Rename_WP_Admin_Login' ) && method_exists( 'NNAX_Rename_WP_Admin_Login', 'activate' ) ) { // Fallback, falls kein static wrapper vorhanden ist. $obj = new NNAX_Rename_WP_Admin_Login(); $obj->activate(); } if ( function_exists( 'flush_rewrite_rules' ) ) { flush_rewrite_rules(); } } register_activation_hook( NNAX_SCE_PLUGIN_FILE, 'nnax_on_activate' ); add_action( 'admin_init', 'nnax_sce_ensure_admin_caps', 5 ); /** * Output a readonly notice on plugin pages. * * @return void */ function nnax_plugin_readonly_notice() { if ( ! nnax_is_plugin_admin_page() || ! nnax_is_plugin_readonly_user() ) { return; } echo '

' . esc_html__( 'Read-only mode: You can view settings, but not save them.', 'nnax-web-essentials' ) . '

'; } /** * Disable edit controls in readonly mode. * * @return void */ function nnax_plugin_readonly_lockdown() { if ( ! nnax_is_plugin_admin_page() || ! nnax_is_plugin_readonly_user() ) { return; } } add_action( 'admin_footer', 'nnax_plugin_readonly_lockdown' ); // Backend-Login ändern (Konstanten). if ( ! defined( 'NNAX_RWAL_VERSION' ) ) { define( 'NNAX_RWAL_VERSION', '1.0.0' ); } if ( ! defined( 'NNAX_RWAL_NAME' ) ) { define( 'NNAX_RWAL_NAME', 'Rename wp-admin login' ); } if ( ! defined( 'NNAX_RWAL_PATH' ) ) { define( 'NNAX_RWAL_PATH', plugin_dir_path( __FILE__ ) ); } if ( ! defined( 'NNAX_RWAL_BASE_URI' ) ) { define( 'NNAX_RWAL_BASE_URI', plugin_dir_url( __FILE__ ) ); }