options = $options; $this->init(); } /** * Start the engine running * * @return void */ private function init() { add_filter( 'adminoptimizer_settings_navtab', [ $this, 'add_settings_navtab' ] ); add_filter( 'adminoptimizer_settings_sections', [ $this, 'settings_fields' ] ); if ( ! empty( $this->options['enable_block_login'] ) ) { $this->modules['block_login'] = new Block_Login(); } if ( ! empty( $this->options['enable_2fa'] ) ) { $this->modules['2fa'] = new Two_Factor_Authentication(); } if ( ! empty( $this->options['enable_custom_login_url'] ) ) { $this->modules['custom_login_url'] = new Custom_Login_Url(); } if ( ! empty( $this->options['disable_xmlrpc'] ) ) { add_filter( 'xmlrpc_enabled', '__return_false' ); add_filter( 'wp_xmlrpc_server_class', function () { header( 'HTTP/1.1 403 Forbidden' ); exit( 'You don\'t have permission to access this file.' ); } ); } if ( ! empty( $this->options['hide_wp_version'] ) ) { remove_action( 'wp_head', 'wp_generator' ); } add_action( 'wp', [ $this, 'configure_http_header' ] ); if ( ! empty( $this->options['remove_rest_api_link'] ) ) { remove_action( 'xmlrpc_rsd_apis', 'rest_output_rsd' ); remove_action( 'wp_head', 'rest_output_link_wp_head' ); remove_action( 'template_redirect', 'rest_output_link_header', 11 ); } if ( ! empty( $this->options['remove_rsd'] ) ) { remove_action( 'wp_head', 'rsd_link' ); } if ( ! empty( $this->options['remove_shortlink'] ) ) { remove_action( 'wp_head', 'wp_shortlink_wp_head' ); remove_action( 'template_redirect', 'wp_shortlink_header', 11 ); } } /** * Add settings navtab * * @param array $nav_tab List of nav tabs. * * @return array */ public function add_settings_navtab( $nav_tab ) { if ( empty( $nav_tab['security'] ) ) { $nav_tab['security'] = [ 'title' => __( 'Security', 'admin-optimizer' ), 'slug' => 'adminoptim-security-settings', ]; } return $nav_tab; } /** * List of Settings fields * * @param array $fields Settings fields. * * @return array */ public function settings_fields( $fields ) { if ( empty( $fields['security-module'] ) ) { $fields['security-module'] = [ 'id' => 'adminoptimizer-security-modules-settings', 'title' => __( 'Modules', 'admin-optimizer' ), 'description' => '', 'menu_slug' => 'adminoptim-security-settings', 'option_name' => MODULES_OPTION, 'args' => [ 'before_section' => '
', 'after_section' => '
', 'section_class' => 'module', ], 'fields' => [ [ 'type' => 'slider-checkbox', 'title' => __( 'Block Failed Login (Pro option)', 'admin-optimizer' ), 'id' => 'enable-block-login', 'name' => 'enable_block_login', // translators: %1$s is the line break tag. %2$s is the anchor tag. %3$s is the anchor closure tag. 'label' => sprintf( __( 'Block the user from login after repeated failed login attempt. (comes with Pro options) %1$s%2$sLearn more%3$s', 'admin-optimizer' ), '
', '', '' ), ], [ 'type' => 'slider-checkbox', 'title' => __( 'Two Factor Authentication (2FA) (Pro option)', 'admin-optimizer' ), 'id' => 'enable-2fa', 'name' => 'enable_2fa', // translators: %1$s is the line break tag. %2$s is the anchor tag. %3$s is the anchor closure tag. 'label' => sprintf( __( 'Enable two factor authentication for all users. (comes with Pro options)%1$s%2$sLearn more%3$s', 'admin-optimizer' ), '
', '', '' ), ], [ 'type' => 'slider-checkbox', 'title' => __( 'Custom Login URL', 'admin-optimizer' ), 'id' => 'enable-custom-login-url', 'name' => 'enable_custom_login_url', // translators: %1$s is the line break tag. %2$s is the anchor tag. %3$s is the anchor closure tag. 'label' => sprintf( __( 'Hide the wp-login page and create a custom login URL for all users.%1$s%2$sLearn more%3$s', 'admin-optimizer' ), '
', '', '' ), ], ], ]; } if ( empty( $fields['security-tweaks'] ) ) { $fields['security-tweaks'] = [ 'id' => 'adminoptimizer-security-tweaks-settings', 'title' => __( 'Tweaks', 'admin-optimizer' ), 'description' => __( 'Activate with a single click. No additional configuration required.', 'admin-optimizer' ), 'menu_slug' => 'adminoptim-security-settings', 'option_name' => MODULES_OPTION, 'args' => [ 'before_section' => '
', 'after_section' => '
', 'section_class' => 'tweaks', ], 'fields' => [ [ 'type' => 'slider-checkbox', 'title' => __( 'Disable XML-RPC', 'admin-optimizer' ), 'id' => 'disable-xmlrpc', 'name' => 'disable_xmlrpc', // translators: %1$s is the line break tag. %2$s is the anchor tag. %3$s is the anchor closure tag. 'label' => sprintf( __( 'Disable XML-RPC for the whole site.%1$s%2$sLearn more%3$s', 'admin-optimizer' ), '
', '', '' ), ], [ 'type' => 'slider-checkbox', 'title' => __( 'Hide WP version', 'admin-optimizer' ), 'id' => 'hide-wp-version', 'name' => 'hide_wp_version', // translators: %1$s is the line break tag. %2$s is the anchor tag. %3$s is the anchor closure tag. 'label' => sprintf( __( 'Remove WP version from the header.%1$s%2$sLearn more%3$s', 'admin-optimizer' ), '
', '', '' ), ], [ 'type' => 'slider-checkbox', 'title' => __( 'Remove Pingback HTTP header', 'admin-optimizer' ), 'id' => 'remove-pingback-header', 'name' => 'remove_pingback_header', // translators: %1$s is the line break tag. %2$s is the anchor tag. %3$s is the anchor closure tag. 'label' => sprintf( __( 'Remove \'X-Pingback\' from the HTTP header. This will prevent others sites from pinging yours when they link to you.%1$s%2$sLearn more%3$s', 'admin-optimizer' ), '
', '', '' ), ], [ 'type' => 'slider-checkbox', 'title' => __( 'Remove Powered By HTTP header', 'admin-optimizer' ), 'id' => 'remove-powered-by-header', 'name' => 'remove_powered_by_header', // translators: %1$s is the line break tag. %2$s is the anchor tag. %3$s is the anchor closure tag. 'label' => sprintf( __( 'Remove \'X-Powered-By\' from the HTTP header. This will remove information about the plugins and software used by your site.%1$s%2$sLearn more%3$s', 'admin-optimizer' ), '
', '', '' ), ], [ 'type' => 'slider-checkbox', 'title' => __( 'Remove REST API link', 'admin-optimizer' ), 'id' => 'remove-rest-api-link', 'name' => 'remove_rest_api_link', // translators: %1$s is the line break tag. %2$s is the anchor tag. %3$s is the anchor closure tag. 'label' => sprintf( __( 'Remove the REST API link from the header.%1$s%2$sLearn more%3$s', 'admin-optimizer' ), '
', '', '' ), ], [ 'type' => 'slider-checkbox', 'title' => __( 'Remove Really Simple Discovery (RSD) Link', 'admin-optimizer' ), 'id' => 'remove-rsd', 'name' => 'remove_rsd', // translators: %1$s is the line break tag. %2$s is the anchor tag. %3$s is the anchor closure tag. 'label' => sprintf( __( 'Remove Really Simple Discovery (RSD) <link> tag from the header.%1$s%2$sLearn more%3$s', 'admin-optimizer' ), '
', '', '' ), ], [ 'type' => 'slider-checkbox', 'title' => __( 'Remove shortlink', 'admin-optimizer' ), 'id' => 'remove-shortlink', 'name' => 'remove_shortlink', // translators: %1$s is the line break tag. %2$s is the anchor tag. %3$s is the anchor closure tag. 'label' => sprintf( __( 'Remove shortlink from the header.%1$s%2$sLearn more%3$s', 'admin-optimizer' ), '
', '', '' ), ], ], ]; } return $fields; } /** * Remove entries from the HTTP header * * @return void */ public function configure_http_header() { if ( headers_sent() ) { return; } if ( ! empty( $this->options['remove_pingback_header'] ) ) { header_remove( 'X-Pingback' ); } if ( ! empty( $this->options['remove_powered_by_header'] ) ) { header_remove( 'X-Powered-By' ); } } }