settings = SettingsManager::get_instance(); $this->init_hooks(); } private function get_setting($key, $default = '') { return $this->settings->get('feature_toggle', $key, $default); } private function init_hooks() { if ($this->get_setting('disable_gutenberg')) { add_filter('use_block_editor_for_post', '__return_false', 10); // Disable Gutenberg stylesheet add_action('wp_enqueue_scripts', function() { wp_dequeue_style('wp-block-library'); wp_dequeue_style('wp-block-library-theme'); }, 100); } if ($this->get_setting('disable_comments')) { add_action('admin_init', function() { $post_types = get_post_types(); foreach ($post_types as $post_type) { if (post_type_supports($post_type, 'comments')) { remove_post_type_support($post_type, 'comments'); remove_post_type_support($post_type, 'trackbacks'); } } }); // Close comments on frontend add_filter('comments_open', '__return_false', 20, 2); add_filter('pings_open', '__return_false', 20, 2); // Hide existing comments add_filter('comments_array', '__return_empty_array', 10, 2); // Remove comments page in menu add_action('admin_menu', function() { remove_menu_page('edit-comments.php'); }); } } public function render_settings() { $settings = [ 'disable_gutenberg' => ['type' => 'checkbox', 'label' => __('Disable Gutenberg Editor', 'admin-menu-optimizer')], 'disable_comments' => ['type' => 'checkbox', 'label' => __('Disable Comments Globally', 'admin-menu-optimizer')], ]; echo ''; foreach ($settings as $key => $field) { $value = $this->get_setting($key); echo ''; echo ''; echo ''; echo ''; } echo ''; } }