'GET', 'callback' => [__CLASS__, 'get_settings'], 'permission_callback' => function () { return current_user_can('manage_options'); } ], [ 'methods' => 'POST', 'callback' => [__CLASS__, 'save_settings'], 'permission_callback' => function () { return current_user_can('manage_options'); } ] ]); } public static function get_settings(){ $settings = get_option('pl_access_control_settings', [ 'enable_access_control'=> true, 'enable_frontend_bar'=> true ]); return new WP_REST_Response($settings, 200); } public static function save_settings(WP_REST_Request $request){ $settings = $request->get_params(); // Check nonce for security if (!isset($settings['_wpnonce']) || !wp_verify_nonce($settings['_wpnonce'], 'pl_access_control_wp_rest')) { return new WP_REST_Response([ 'message' => 'Invalid nonce' ], 403); } // Remove nonce from settings to avoid saving it unset($settings['_wpnonce']); // Validate and sanitize the settings $sanitized_settings = [ 'enable_access_control' => isset($settings['enable_access_control']) ? (bool) $settings['enable_access_control'] : false , 'enable_frontend_bar' => isset($settings['enable_frontend_bar']) ? (bool) $settings['enable_frontend_bar'] : false ]; // Save the settings update_option('pl_access_control_settings', $sanitized_settings); return new WP_REST_Response([ 'message' => 'Settings saved successfully', 'settings' => $sanitized_settings ], 200); } }