定制 mituu/acf-default-value-initializer 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mituu/acf-default-value-initializer

Composer 安装命令:

composer require mituu/acf-default-value-initializer

包简介

ACF plugin to automatically initialize default values for existing posts and users

README 文档

README

Latest Stable Version Total Downloads License PHP Version Require Monthly Downloads

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

  1. Download the plugin
  2. Upload to /wp-content/plugins/acf-default-value-initializer/
  3. Activate through the WordPress admin

Enabling Default Value Initialization

  1. Go to Custom Fields > Field Groups in your WordPress admin
  2. Edit any field group
  3. 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
  4. 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:

  1. Edit a field group in the ACF admin
  2. Look for the "🔄 Initialize Default Values" button
  3. 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:

  1. The plugin identifies all posts/users that match the field group's location rules
  2. For each field with initialization enabled, it checks if the post/user has a value
  3. If no value exists, it applies the field's default value
  4. 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 coordination
  • Hooks: WordPress action/filter hooks management
  • FieldSettings: ACF field settings modifications
  • DefaultValueProcessor: Core logic for applying default values

Hooks and Filters

The plugin uses these WordPress hooks:

  • acf/save_post - Triggers default value processing
  • acf/render_field_settings - Adds the initialization checkbox
  • wp_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

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

mituu/acf-default-value-initializer 适用场景与选型建议

mituu/acf-default-value-initializer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 05 月 26 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 mituu/acf-default-value-initializer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 mituu/acf-default-value-initializer 我们能提供哪些服务?
定制开发 / 二次开发

基于 mituu/acf-default-value-initializer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 7
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 22
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2025-05-26