XML-RPC Access Manager
A single-file WordPress plugin for fine-grained control over XML-RPC and REST API endpoints. Toggle XML-RPC globally or per-user role, disable specific REST routes, and log blocked requests for security monitoring.
YT XML-RPC Access Manager
A single-file WordPress plugin for fine-grained control over XML-RPC and REST API endpoints. Toggle XML-RPC globally or per-user role, disable specific REST routes, and log blocked requests for security monitoring.
Features
- XML-RPC Control: Disable XML-RPC globally or restrict by user roles
- REST API Management: Require authentication for REST API access
- Role-Based Permissions: Fine-grained access control per user role
- Route Blocking: Disable specific REST API endpoints
- Request Logging: Track and monitor blocked requests
- Security Focused: Protect your WordPress site from unauthorized API access
- Single File Architecture: All code in one PHP file for simplicity
- WPCS Compliant: Follows WordPress Coding Standards
- Translation Ready: i18n/l10n support
- Admin Dashboard: User-friendly settings interface with tabbed layout
Quick Start
- Upload the plugin to your WordPress plugins directory
- Activate the plugin through the WordPress admin panel
- Configure settings at Settings > XML-RPC Manager
- Enable logging (optional) to monitor blocked requests
Installation
- Download
class-yt-xml-rpc-access-manager.php - Upload to
/wp-content/plugins/yt-xml-rpc-access-manager/ - Activate through the WordPress 'Plugins' menu
- Configure via Settings > XML-RPC Manager
File Structure
class-yt-xml-rpc-access-manager.php # Main plugin file
assets/css/yt-xml-rpc-access-manager-admin.css # Admin styles
assets/js/yt-xml-rpc-access-manager-admin.js # Admin scripts
README.md # This file
Plugin Architecture
Constants Defined
YT_XML_RPC_ACCESS_MANAGER_VERSION // Plugin version number
YT_XML_RPC_ACCESS_MANAGER_BASENAME // Plugin base name
YT_XML_RPC_ACCESS_MANAGER_PATH // Plugin directory path
YT_XML_RPC_ACCESS_MANAGER_URL // Plugin directory URL
Main Class Methods
Core Methods
get_instance()- Singleton instance retrieval__construct()- Initialize plugin and load optionsxram_init_hooks()- Register WordPress hooksxram_load_textdomain()- Load translations
Admin Methods
xram_add_admin_menu()- Add settings page to admin menuxram_register_settings()- Register plugin settings and fieldsxram_sanitize_options()- Sanitize user inputxram_render_settings_page()- Display tabbed settings interfacexram_render_logs_tab()- Display request logsxram_admin_enqueue_scripts()- Load admin CSS/JSxram_add_action_links()- Add settings link to plugins page
Security Control Methods
xram_control_xmlrpc()- Control XML-RPC access globally and by rolexram_filter_xmlrpc_methods()- Filter available XML-RPC methodsxram_control_rest_api()- Control REST API access and authenticationxram_filter_rest_endpoints()- Remove disabled REST routes
Logging Methods
xram_log_blocked_request()- Log blocked XML-RPC and REST requestsxram_log_xmlrpc_call()- Hook for XML-RPC call loggingxram_ajax_clear_logs()- Clear all request logsxram_ajax_export_logs()- Export logs to CSV format
Utility Methods
xram_get_option()- Get option value with defaultactivate()- Run on plugin activationdeactivate()- Run on plugin deactivationyt_xml_rpc_access_manager_uninstall()- Run on plugin deletion
Usage Examples
Disable XML-RPC Completely
- Go to Settings > XML-RPC Manager
- Check "Disable XML-RPC completely"
- Save changes
This blocks all XML-RPC requests, overriding any role permissions.
Allow XML-RPC for Specific Roles
- Go to Settings > XML-RPC Manager
- Uncheck "Disable XML-RPC completely"
- Select user roles allowed to use XML-RPC (e.g., Administrator, Editor)
- Save changes
Only selected roles will have XML-RPC access.
Restrict REST API Access
- Go to Settings > XML-RPC Manager
- Switch to "REST API Settings" section
- Check "Disable REST API for non-authenticated users"
- Select allowed user roles
- Save changes
Block Specific REST API Routes
- Go to Settings > XML-RPC Manager
- Find "Disabled Routes" field
- Enter routes to block (one per line):
/wp/v2/users /wp/v2/users/(?P<id>[d]+) - Save changes
Enable Request Logging
- Go to Settings > XML-RPC Manager
- Check "Log blocked requests" in Logging Settings
- Save changes
- View logs in "Request Logs" tab
Export Logs
- Go to Request Logs tab
- Click "Export CSV" button
- CSV file will be downloaded automatically
Programmatic Access
// Get plugin instance
$plugin = YT_XML_RPC_Access_Manager::get_instance();
// Check if XML-RPC is disabled
$xmlrpc_disabled = $plugin->xram_get_option( 'disable_xmlrpc', false );
// Get allowed roles
$allowed_roles = $plugin->xram_get_option( 'xmlrpc_allowed_roles', array() );
Configuration Options
XML-RPC Settings
- Disable XML-RPC: Completely blocks all XML-RPC requests
- Allowed User Roles: Select which roles can use XML-RPC (Administrator, Editor, Author, etc.)
REST API Settings
- Disable REST API: Requires authentication for all REST API requests
- Allowed User Roles: Select which authenticated roles can use REST API
- Disabled Routes: List of REST API routes to block (one per line)
Logging Settings
- Enable Logging: Keep a log of blocked XML-RPC and REST API requests (last 500 entries)
Security Best Practices
✅ Already Implemented:
- Direct file access prevention
- Capability checks (
current_user_can('manage_options')) - Input sanitization (
sanitize_text_field(),sanitize_key()) - Output escaping (
esc_html(),esc_attr(),esc_url()) - AJAX nonce verification
- Role-based access control
- IP address logging for security monitoring
⚠️ Recommendations:
- Enable logging to monitor unauthorized access attempts
- Regularly review logs for suspicious activity
- Disable XML-RPC if you don't use third-party apps
- Restrict REST API access to authenticated users only
- Block sensitive REST routes like
/wp/v2/users - Keep the plugin updated
Use Cases
1. Complete Security Lockdown
- Disable XML-RPC completely
- Disable REST API for non-authenticated users
- Block
/wp/v2/usersendpoint - Enable logging
2. Allow Mobile App Access
- Keep XML-RPC enabled for Administrator role only
- Allow REST API for authenticated users
- Enable logging to monitor usage
3. Public REST API with Restrictions
- Allow public REST API access
- Block sensitive routes (users, settings)
- Enable logging for security monitoring
4. Development Environment
- Enable all access
- Enable logging to debug API requests
- Export logs for analysis
Troubleshooting
XML-RPC Still Accessible
- Ensure "Disable XML-RPC" is checked
- Clear WordPress cache
- Check for conflicting plugins
- Verify plugin is activated
REST API Returns 401 Error
- Check if "Disable REST API" is enabled
- Verify user is logged in
- Check user role permissions
- Review allowed roles list
Logs Not Recording
- Ensure "Enable Logging" is checked
- Save settings after enabling
- Trigger a blocked request to test
- Check WordPress database options table
Settings Not Saving
- Verify user has
manage_optionscapability - Check for JavaScript errors in browser console
- Disable other plugins temporarily
- Check file permissions
Development Tips
- Test thoroughly: Test with different user roles and scenarios
- Monitor logs: Enable logging during initial setup
- Start restrictive: Begin with stricter settings, then relax as needed
- Document changes: Keep track of disabled routes for maintenance
- Regular reviews: Periodically review logs and settings
- Backup first: Always backup before making security changes
Testing Checklist
- [ ] Plugin activates without errors
- [ ] Settings page displays correctly
- [ ] All settings save properly
- [ ] XML-RPC can be disabled globally
- [ ] Role-based XML-RPC access works
- [ ] REST API authentication works
- [ ] Specific REST routes can be blocked
- [ ] Request logging works correctly
- [ ] Logs can be viewed in admin
- [ ] Logs can be exported to CSV
- [ ] Logs can be cleared
- [ ] Plugin deactivates cleanly
- [ ] Plugin uninstalls and removes all data
- [ ] No PHP warnings or notices
- [ ] Compatible with latest WordPress version
- [ ] Works with PHP 7.4+
- [ ] Settings link appears on plugins page
- [ ] Tab switching works in admin interface
- [ ] AJAX operations work correctly
WPCS Validation
Run PHP_CodeSniffer with WordPress standards:
phpcs --standard=WordPress class-yt-xml-rpc-access-manager.php
Performance
- Minimal overhead: Hooks only fire when API requests are made
- Efficient logging: Automatically limits to last 500 entries
- Cached options: Plugin options loaded once per request
- No database queries on frontend: Only admin interface queries database
Compatibility
- WordPress: 5.8 or higher
- PHP: 7.4 or higher
- Multisite: Compatible (network activation not required)
- Page Builders: Compatible with all major page builders
- Themes: Theme-independent
License
GPL v2 or later
Credits
Built following WordPress Plugin Handbook and WPCS guidelines.
Support
For issues, feature requests, or contributions:
Resources
For WordPress security best practices, visit:
- WordPress Plugin Handbook
- WordPress Coding Standards
- WordPress REST API Handbook
- WordPress XML-RPC Support
Changelog
1.0.0
- Initial release
- XML-RPC global disable
- XML-RPC role-based access control
- REST API authentication requirements
- REST API role-based access control
- REST API route blocking
- Request logging system
- CSV log export
- Tabbed admin interface
- Translation ready