mituu / acf-default-value-initializer
ACF plugin to automatically initialize default values for existing posts and users
Installs: 5
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:wordpress-plugin
pkg:composer/mituu/acf-default-value-initializer
Requires
- php: >=8.1
README
A WordPress plugin that automatically initializes default values for Advanced Custom Fields (ACF) on existing posts and users.
Description
When you add new ACF fields with default values to existing content, WordPress typically only applies these defaults to new posts/users created after the field was added. This plugin solves that problem by automatically applying default values to existing content that doesn't have a value for the field.
Features
- 🔄 Automatic Default Value Application: Applies default values to existing posts/users when fields are saved
- ⚙️ Field-Level Control: Enable/disable default value initialization per field
- 🎯 Selective Processing: Only processes content that doesn't already have a value for the field
- 🔧 Manual Processing: Admin interface button for manual initialization
- 📝 Multiple Post Types: Works with posts, pages, custom post types, and users
- 🛡️ Safe Processing: Only updates empty fields, preserves existing data
- 🎨 Clean Admin UI: Seamless integration with ACF field settings
Requirements
- WordPress: 6.4 or higher
- PHP: 8.1 or higher
- ACF: Advanced Custom Fields (free or Pro version)
Installation
Via Composer
composer require mituu/acf-default-value-initializer
Manual Installation
- Download the plugin
- Upload to
/wp-content/plugins/acf-default-value-initializer/ - Activate through the WordPress admin
Enabling Default Value Initialization
- Go to Custom Fields > Field Groups in your WordPress admin
- Edit any field group
- For each field you want to initialize defaults:
- Open the field settings
- Enable the "Initialize Default Values" checkbox
- Set your desired default value for the field
- Save the field group
Supported Field Types
The plugin supports default value initialization for:
- Text, Textarea, Number, Email, URL, Password
- Select, Checkbox, Radio, Button Group, True/False
- Date Picker, Date Time Picker, Time Picker, Color Picker
- Range, WYSIWYG, oEmbed
- User, Post Object, Page Link, Relationship, Taxonomy
- Image, File, Gallery
Manual Processing
If you need to manually trigger default value initialization:
- Edit a field group in the ACF admin
- Look for the "🔄 Initialize Default Values" button
- Click the button to manually process all existing content for this field group
How It Works
Automatic Processing
When you save a field group with fields that have "Initialize Default Values" enabled:
- The plugin identifies all posts/users that match the field group's location rules
- For each field with initialization enabled, it checks if the post/user has a value
- If no value exists, it applies the field's default value
- Existing values are never overwritten
Processing Flow
Field Group Save → Check Enabled Fields → Find Target Content → Apply Defaults
Technical Details
Plugin Structure
acf-default-value-initializer/
├── acf-default-value-initializer.php # Main plugin file
├── composer.json # Composer configuration
├── assets/js/ # JavaScript files
│ └── field-settings.js # Admin UI enhancements
└── src/ # PHP classes
├── Plugin.php # Main plugin class
├── Hooks.php # WordPress hooks
├── FieldSettings.php # ACF field settings
└── DefaultValueProcessor.php # Core processing logic
Key Classes
Plugin: Main plugin initialization and coordinationHooks: WordPress action/filter hooks managementFieldSettings: ACF field settings modificationsDefaultValueProcessor: Core logic for applying default values
Hooks and Filters
The plugin uses these WordPress hooks:
acf/save_post- Triggers default value processingacf/render_field_settings- Adds the initialization checkboxwp_ajax_acf_dvi_process_field_group- Handles manual processing
Configuration
Field-Level Settings
Each ACF field can be individually configured:
// Field setting added by the plugin 'init_default_values' => 1 // Enable default value initialization
Location Rules
The plugin respects ACF location rules, so default values are only applied to content that matches the field group's location conditions.
Development
Local Development Setup
# Clone the repository git clone https://github.com/mituu-rs/acf-default-value-initializer.git # Install dependencies (if using Composer) composer install
Code Standards
- PHP 8.1+ with strict types
- PSR-4 autoloading
- WordPress coding standards
- Comprehensive error handling
Changelog
Version 1.0.0
- Initial release
- Automatic default value initialization
- Field-level control settings
- Manual processing interface
- Support for all major ACF field types
Support
For issues, feature requests, or contributions:
License
This project is licensed under the GPL v2 or later - see the LICENSE for details.
Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request