Extensibility Overview
Orbem Studio is designed to be extended and customized. This guide covers the various ways developers can modify, enhance, and integrate with the plugin.
Extension Methods
1. WordPress Hooks and Filters
Use standard WordPress actions and filters to modify plugin behavior.
Use Cases:
- Add custom meta fields to game objects
- Modify game data before rendering
- Integrate with other plugins
- Add custom post processing
Documentation: Hooks and Filters Reference
2. REST API Integration
Build custom frontends or external tools using the REST API.
Use Cases:
- Mobile game clients
- External admin dashboards
- Third-party integrations
- Analytics and monitoring
Documentation: Custom Integrations
3. Custom Post Types and Taxonomies
Leverage WordPress CPT system to extend game object types.
Use Cases:
- Add new game object categories
- Create custom taxonomies for organization
- Extend existing object types
4. JavaScript Extensions
Extend the frontend game engine with custom JavaScript.
Use Cases:
- Custom gameplay mechanics
- Additional UI elements
- Enhanced visual effects
- Custom mini-games
Common Extension Patterns
Adding Custom Meta Fields
add_filter('orbem_meta_fields_explore-character', function($fields) {
$fields['custom-stat'] = [
'number',
'Custom stat for this character'
];
return $fields;
});Modifying Game Data
add_filter('orbem_area_data', function($data, $area) {
// Add custom data to area response
$data['custom_info'] = get_option('area_' . $area . '_custom');
return $data;
}, 10, 2);Custom REST Endpoints
add_action('rest_api_init', function() {
register_rest_route('mygame/v1', '/custom-action/', [
'methods' => 'POST',
'callback' => 'my_custom_action',
'permission_callback' => function() {
return current_user_can('read');
}
]);
});Development Best Practices
Use Child Themes or Custom Plugins
Never modify Orbem Studio files directly. Instead:
- Create a custom plugin for your extensions
- Use child theme for template modifications
- Version control your customizations
Namespace Your Code
namespace MyGame;
class CustomExtension {
// Your code here
}Check Plugin Exists
if (class_exists('OrbemStudio\\Plugin')) {
// Your integration code
}Follow WordPress Coding Standards
- Use WordPress coding standards
- Sanitize all input
- Escape all output
- Use prepared statements for database queries
Extension Examples
Example: Custom Achievement System
// Register custom achievement post type
add_action('init', function() {
register_post_type('game-achievement', [
'label' => 'Achievements',
'public' => true,
'supports' => ['title', 'editor', 'thumbnail']
]);
});
// Add REST endpoint to unlock achievements
add_action('rest_api_init', function() {
register_rest_route('mygame/v1', '/unlock-achievement/', [
'methods' => 'POST',
'callback' => function($request) {
$achievement = $request->get_param('achievement');
$user_id = get_current_user_id();
$unlocked = get_user_meta($user_id, 'unlocked_achievements', true) ?: [];
$unlocked[] = $achievement;
update_user_meta($user_id, 'unlocked_achievements', $unlocked);
return ['success' => true];
},
'permission_callback' => function() {
return is_user_logged_in();
}
]);
});Example: Custom Game Stat
// Add custom stat to HUD
add_filter('orbem_hud_stats', function($stats) {
$stats['energy'] = [
'label' => 'Energy',
'max' => 100,
'current' => get_user_meta(get_current_user_id(), 'energy', true) ?: 100
];
return $stats;
});Testing Your Extensions
Local Development
- Use
@wordpress/envfor local WordPress environment - Enable
WP_DEBUGandSCRIPT_DEBUG - Test with multiple user roles
- Verify compatibility with latest WordPress version
Code Quality
# Install dependencies
composer require --dev phpunit/phpunit
composer require --dev wp-coding-standards/wpcs
# Run tests
vendor/bin/phpunit
# Check coding standards
vendor/bin/phpcs --standard=WordPress your-extension.phpResources
- Hooks and Filters - Complete reference
- Custom Integrations - REST API usage
- API Documentation - REST API reference
- WordPress Plugin Handbook - WordPress plugin development
Support
For extension questions:
- Check existing hooks and filters
- Review example code in documentation
- Test in a development environment first
- Consider performance implications
Next Steps
- Review available hooks and filters
- Learn about custom integrations
- Explore the REST API
- Build your extension!