# BDC Dynamic Content Manager Pro (WordPress Plugin)
A production-grade WordPress plugin for managing dynamic content across a website. Provides centralized content management with advanced field types, Elementor integration, revision history, and REST API access.
Purpose
Modern WordPress sites need flexible content management beyond standard posts and pages. This plugin provides:
- Centralized content blocks
- Advanced field types (Color, Date, Code, etc.)
- Revision history for content
- REST API access for headless setups
- Elementor widget integration
- Import/Export functionality
Core Architecture
php
class BDC_Dynamic_Content_Manager {
private $option_name = 'bdc_dynamic_content';
private $revisions_option_name = 'bdc_dynamic_content_revisions';
private $max_revisions = 20;
// Singleton pattern
public static function get_instance() { /* ... */ }
// Admin menu
public function add_admin_menu() { /* ... */ }
// Content management
public function save_content($key, $value) { /* ... */ }
// Revisions
public function save_revision($key, $value) { /* ... */ }
// REST API
public function register_routes() { /* ... */ }
}Advanced Field Types
php
// Field type definitions
function bdc_render_field($field, $value) {
switch ($field['type']) {
case 'text':
return '<input type="text" value="' . esc_attr($value) . '" />';
case 'textarea':
return '<textarea>' . esc_textarea($value) . '</textarea>';
case 'color':
return '<input type="color" value="' . esc_attr($value) . '" />';
case 'date':
return '<input type="date" value="' . esc_attr($value) . '" />';
case 'code':
return '<textarea class="code-editor">' . esc_textarea($value) . '</textarea>';
case 'select':
$options = $field['options'] ?? [];
$html = '<select>';
foreach ($options as $opt => $label) {
$selected = ($value === $opt) ? 'selected' : '';
$html .= '<option value="' . $opt . '" ' . $selected . '>' . $label . '</option>';
}
$html .= '</select>';
return $html;
case 'image':
return bdc_render_image_upload($value);
case ' repeater':
return bdc_render_repeater($field, $value);
}
}Revision System
php
function save_revision($key, $value) {
$revisions = get_option($this->revisions_option_name, []);
if (!isset($revisions[$key])) {
$revisions[$key] = [];
}
// Add new revision
$revisions[$key][] = [
'content' => $value,
'timestamp' => current_time('mysql'),
'author' => get_current_user_id()
];
// Keep only max revisions
if (count($revisions[$key]) > $this->max_revisions) {
$revisions[$key] = array_slice($revisions[$key], -$this->max_revisions);
}
update_option($this->revisions_option_name, $revisions);
}REST API Integration
php
function register_routes() {
register_rest_route('bdc/v1', '/content', [
'methods' => 'GET',
'callback' => [$this, 'get_content'],
'permission_callback' => '__return_true'
]);
register_rest_route('bdc/v1', '/content/(?P<key>\w+)', [
'methods' => 'GET',
'callback' => [$this, 'get_content_by_key'],
'permission_callback' => '__return_true'
]);
register_rest_route('bdc/v1', '/content/(?P<key>\w+)', [
'methods' => 'POST',
'callback' => [$this, 'update_content'],
'permission_callback' => function() {
return current_user_can('manage_options');
}
]);
}
function get_content(WP_REST_Request $request) {
$content = get_option($this->option_name, []);
return rest_ensure_response($content);
}Elementor Integration
php
function register_elementor_widgets($widgets_manager) {
require_once dirname(__FILE__) . '/widgets/dynamic-content-widget.php';
$widgets_manager->register(new \BDC_Elementor_Widget());
}
function bdc_elementor_render($settings) {
$content_key = $settings['bdc_content_key'];
$content = get_option($this->option_name, []);
if (isset($content[$content_key])) {
return do_shortcode($content[$content_key]);
}
return '';
}Import/Export
php
function export_content() {
$content = get_option($this->option_name, []);
$revisions = get_option($this->revisions_option_name, []);
$export_data = [
'content' => $content,
'revisions' => $revisions,
'exported' => current_time('mysql'),
'version' => BDC_VERSION
];
header('Content-Type: application/json');
header('Content-Disposition: attachment; filename="bdc-export.json"');
echo json_encode($export_data);
exit;
}
function import_content($file) {
$data = json_decode(file_get_contents($file), true);
if (isset($data['content'])) {
update_option($this->option_name, $data['content']);
}
if (isset($data['revisions'])) {
update_option($this->revisions_option_name, $data['revisions']);
}
}Version
- 3.2.1 - Pro version with advanced features
- Advanced field types
- Elementor integration
- REST API
- Revision system
- Import/Export
Architecture Feedback
Spotted a potential optimization or antipattern? Let me know.