├── css ├── input.css └── README.md ├── js ├── README.md └── input.js ├── images └── README.md ├── lang └── README.md ├── composer.json ├── .gitignore ├── README.md ├── readme.txt ├── acf-reusable_field_group.php ├── acf-reusable_field_group-v4.php └── acf-reusable_field_group-v5.php /css/input.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /css/README.md: -------------------------------------------------------------------------------- 1 | # CSS directory 2 | 3 | Use this directory to store CSS files. 4 | 5 | This directory can be removed if not used. 6 | -------------------------------------------------------------------------------- /js/README.md: -------------------------------------------------------------------------------- 1 | # JS directory 2 | 3 | Use this directory to store JS files. 4 | 5 | This directory can be removed if not used. 6 | -------------------------------------------------------------------------------- /images/README.md: -------------------------------------------------------------------------------- 1 | # Images directory 2 | 3 | Use this directory to store images. 4 | 5 | This directory can be removed if not used. 6 | -------------------------------------------------------------------------------- /lang/README.md: -------------------------------------------------------------------------------- 1 | # Translations directory 2 | 3 | Use this directory to store .po and .mo files. 4 | 5 | This directory can be removed if not used. 6 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mvpdesign/acf-reusable-field-group", 3 | "description": "ACF Reusable Field Group", 4 | "type": "wordpress-plugin" 5 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .htaccess 2 | wp-content/uploads/ 3 | wp-content/blogs.dir/ 4 | wp-content/upgrade/ 5 | wp-content/backup-db/ 6 | wp-content/advanced-cache.php 7 | wp-content/wp-cache-config.php 8 | sitemap.xml 9 | *.log 10 | wp-content/cache/ 11 | wp-content/backups/ 12 | sitemap.xml.gz 13 | wp-config.php 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ACF Reusable Field Group 1.0.2 2 | 3 | This is a plugin which adds a Reusable Field Group type to the Advanced Custom Fields WordPress Plugins. This allows you to create a group of fields once, and reuse it within any other field group. 4 | 5 | This plugins was created using the [Advanced Custom Fields field type template repository](https://github.com/elliotcondon/acf-field-type-template). As such, there is a bunch of boilerplate code that is not currently used. 6 | 7 | For more information about that process a new field type, please read [this article](http://www.advancedcustomfields.com/resources/tutorials/creating-a-new-field-type/). -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- 1 | === Advanced Custom Fields: Reusable Field Group Field === 2 | Contributors: Tyler Bruffy 3 | Tags: Advanced Custom Fields, ACF 4 | Requires at least: 3.5 5 | Tested up to: 3.9.2 6 | Stable tag: trunk 7 | License: GPLv2 or later 8 | License URI: http://www.gnu.org/licenses/gpl-2.0.html 9 | 10 | Include an existing ACF Field Group in the template for another Field Group 11 | 12 | == Include an existing ACF Field Group in the template for another Field Group == 13 | 14 | EXTENDED_Include an existing ACF Field Group in the template for another Field Group 15 | 16 | = Compatibility = 17 | 18 | This ACF field type is compatible with: 19 | * ACF 5 20 | 21 | == Installation == 22 | 23 | 1. Copy the `acf-reusable_field_group` folder into your `wp-content/plugins` folder 24 | 2. Activate the Reusable Field Group plugin via the plugins admin page 25 | 3. Create a new field via ACF and select the Reusable Field Group type 26 | 4. Please refer to the Include an existing ACF Field Group in the template for another Field Group for more info regarding the field type settings 27 | 28 | == Changelog == 29 | 30 | = 1.0.2 = 31 | * Fixed notices appearing on certain posts pages. 32 | * Fixed typo in category. 33 | 34 | = 1.0.1 = 35 | * Fix for rendering these fields on options pages. 36 | 37 | = 1.0.0 = 38 | * Initial Release. -------------------------------------------------------------------------------- /acf-reusable_field_group.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /js/input.js: -------------------------------------------------------------------------------- 1 | (function($){ 2 | 3 | 4 | function initialize_field( $el ) { 5 | 6 | //$el.doStuff(); 7 | 8 | } 9 | 10 | 11 | if( typeof acf.add_action !== 'undefined' ) { 12 | 13 | /* 14 | * ready append (ACF5) 15 | * 16 | * These are 2 events which are fired during the page load 17 | * ready = on page load similar to $(document).ready() 18 | * append = on new DOM elements appended via repeater field 19 | * 20 | * @type event 21 | * @date 20/07/13 22 | * 23 | * @param $el (jQuery selection) the jQuery element which contains the ACF fields 24 | * @return n/a 25 | */ 26 | 27 | acf.add_action('ready append', function( $el ){ 28 | 29 | // search $el for fields of type 'reusable_field_group' 30 | acf.get_fields({ type : 'reusable_field_group'}, $el).each(function(){ 31 | 32 | initialize_field( $(this) ); 33 | 34 | }); 35 | 36 | }); 37 | 38 | 39 | } else { 40 | 41 | 42 | /* 43 | * acf/setup_fields (ACF4) 44 | * 45 | * This event is triggered when ACF adds any new elements to the DOM. 46 | * 47 | * @type function 48 | * @since 1.0.0 49 | * @date 01/01/12 50 | * 51 | * @param event e: an event object. This can be ignored 52 | * @param Element postbox: An element which contains the new HTML 53 | * 54 | * @return n/a 55 | */ 56 | 57 | $(document).live('acf/setup_fields', function(e, postbox){ 58 | 59 | $(postbox).find('.field[data-field_type="reusable_field_group"]').each(function(){ 60 | 61 | initialize_field( $(this) ); 62 | 63 | }); 64 | 65 | }); 66 | 67 | 68 | } 69 | 70 | 71 | })(jQuery); 72 | -------------------------------------------------------------------------------- /acf-reusable_field_group-v4.php: -------------------------------------------------------------------------------- 1 | name = 'reusable_field_group'; 23 | $this->label = __('Reusable Field Group'); 24 | $this->category = __("Basic",'acf'); // Basic, Content, Choice, etc 25 | $this->defaults = array( 26 | // add default here to merge into your field. 27 | // This makes life easy when creating the field options as you don't need to use any if( isset('') ) logic. eg: 28 | //'preview_size' => 'thumbnail' 29 | ); 30 | 31 | 32 | // do not delete! 33 | parent::__construct(); 34 | 35 | 36 | // settings 37 | $this->settings = array( 38 | 'path' => apply_filters('acf/helpers/get_path', __FILE__), 39 | 'dir' => apply_filters('acf/helpers/get_dir', __FILE__), 40 | 'version' => '1.0.0' 41 | ); 42 | 43 | } 44 | 45 | 46 | /* 47 | * create_options() 48 | * 49 | * Create extra options for your field. This is rendered when editing a field. 50 | * The value of $field['name'] can be used (like below) to save extra data to the $field 51 | * 52 | * @type action 53 | * @since 3.6 54 | * @date 23/01/13 55 | * 56 | * @param $field - an array holding all the field's data 57 | */ 58 | 59 | function create_options( $field ) 60 | { 61 | // defaults? 62 | /* 63 | $field = array_merge($this->defaults, $field); 64 | */ 65 | 66 | // key is needed in the field names to correctly save the data 67 | $key = $field['name']; 68 | 69 | 70 | // Create Field Options HTML 71 | ?> 72 | 73 | 74 | 75 |

76 | 77 | 78 | 'radio', 82 | 'name' => 'fields['.$key.'][preview_size]', 83 | 'value' => $field['preview_size'], 84 | 'layout' => 'horizontal', 85 | 'choices' => array( 86 | 'thumbnail' => __('Thumbnail'), 87 | 'something_else' => __('Something Else'), 88 | ) 89 | )); 90 | 91 | ?> 92 | 93 | 94 | defaults, $field); 116 | */ 117 | 118 | // perhaps use $field['preview_size'] to alter the markup? 119 | 120 | 121 | // create Field HTML 122 | ?> 123 |
124 | 125 |
126 | settings['dir'] . 'js/input.js', array('acf-input'), $this->settings['version'] ); 149 | wp_register_style( 'acf-input-reusable_field_group', $this->settings['dir'] . 'css/input.css', array('acf-input'), $this->settings['version'] ); 150 | 151 | 152 | // scripts 153 | wp_enqueue_script(array( 154 | 'acf-input-reusable_field_group', 155 | )); 156 | 157 | // styles 158 | wp_enqueue_style(array( 159 | 'acf-input-reusable_field_group', 160 | )); 161 | 162 | 163 | } 164 | 165 | 166 | /* 167 | * input_admin_head() 168 | * 169 | * This action is called in the admin_head action on the edit screen where your field is created. 170 | * Use this action to add CSS and JavaScript to assist your create_field() action. 171 | * 172 | * @info http://codex.wordpress.org/Plugin_API/Action_Reference/admin_head 173 | * @type action 174 | * @since 3.6 175 | * @date 23/01/13 176 | */ 177 | 178 | function input_admin_head() 179 | { 180 | // Note: This function can be removed if not used 181 | } 182 | 183 | 184 | /* 185 | * field_group_admin_enqueue_scripts() 186 | * 187 | * This action is called in the admin_enqueue_scripts action on the edit screen where your field is edited. 188 | * Use this action to add CSS + JavaScript to assist your create_field_options() action. 189 | * 190 | * $info http://codex.wordpress.org/Plugin_API/Action_Reference/admin_enqueue_scripts 191 | * @type action 192 | * @since 3.6 193 | * @date 23/01/13 194 | */ 195 | 196 | function field_group_admin_enqueue_scripts() 197 | { 198 | // Note: This function can be removed if not used 199 | } 200 | 201 | 202 | /* 203 | * field_group_admin_head() 204 | * 205 | * This action is called in the admin_head action on the edit screen where your field is edited. 206 | * Use this action to add CSS and JavaScript to assist your create_field_options() action. 207 | * 208 | * @info http://codex.wordpress.org/Plugin_API/Action_Reference/admin_head 209 | * @type action 210 | * @since 3.6 211 | * @date 23/01/13 212 | */ 213 | 214 | function field_group_admin_head() 215 | { 216 | // Note: This function can be removed if not used 217 | } 218 | 219 | 220 | /* 221 | * load_value() 222 | * 223 | * This filter is applied to the $value after it is loaded from the db 224 | * 225 | * @type filter 226 | * @since 3.6 227 | * @date 23/01/13 228 | * 229 | * @param $value - the value found in the database 230 | * @param $post_id - the $post_id from which the value was loaded 231 | * @param $field - the field array holding all the field options 232 | * 233 | * @return $value - the value to be saved in the database 234 | */ 235 | 236 | function load_value( $value, $post_id, $field ) 237 | { 238 | // Note: This function can be removed if not used 239 | return $value; 240 | } 241 | 242 | 243 | /* 244 | * update_value() 245 | * 246 | * This filter is applied to the $value before it is updated in the db 247 | * 248 | * @type filter 249 | * @since 3.6 250 | * @date 23/01/13 251 | * 252 | * @param $value - the value which will be saved in the database 253 | * @param $post_id - the $post_id of which the value will be saved 254 | * @param $field - the field array holding all the field options 255 | * 256 | * @return $value - the modified value 257 | */ 258 | 259 | function update_value( $value, $post_id, $field ) 260 | { 261 | // Note: This function can be removed if not used 262 | return $value; 263 | } 264 | 265 | 266 | /* 267 | * format_value() 268 | * 269 | * This filter is applied to the $value after it is loaded from the db and before it is passed to the create_field action 270 | * 271 | * @type filter 272 | * @since 3.6 273 | * @date 23/01/13 274 | * 275 | * @param $value - the value which was loaded from the database 276 | * @param $post_id - the $post_id from which the value was loaded 277 | * @param $field - the field array holding all the field options 278 | * 279 | * @return $value - the modified value 280 | */ 281 | 282 | function format_value( $value, $post_id, $field ) 283 | { 284 | // defaults? 285 | /* 286 | $field = array_merge($this->defaults, $field); 287 | */ 288 | 289 | // perhaps use $field['preview_size'] to alter the $value? 290 | 291 | 292 | // Note: This function can be removed if not used 293 | return $value; 294 | } 295 | 296 | 297 | /* 298 | * format_value_for_api() 299 | * 300 | * This filter is applied to the $value after it is loaded from the db and before it is passed back to the API functions such as the_field 301 | * 302 | * @type filter 303 | * @since 3.6 304 | * @date 23/01/13 305 | * 306 | * @param $value - the value which was loaded from the database 307 | * @param $post_id - the $post_id from which the value was loaded 308 | * @param $field - the field array holding all the field options 309 | * 310 | * @return $value - the modified value 311 | */ 312 | 313 | function format_value_for_api( $value, $post_id, $field ) 314 | { 315 | // defaults? 316 | /* 317 | $field = array_merge($this->defaults, $field); 318 | */ 319 | 320 | // perhaps use $field['preview_size'] to alter the $value? 321 | 322 | 323 | // Note: This function can be removed if not used 324 | return $value; 325 | } 326 | 327 | 328 | /* 329 | * load_field() 330 | * 331 | * This filter is applied to the $field after it is loaded from the database 332 | * 333 | * @type filter 334 | * @since 3.6 335 | * @date 23/01/13 336 | * 337 | * @param $field - the field array holding all the field options 338 | * 339 | * @return $field - the field array holding all the field options 340 | */ 341 | 342 | function load_field( $field ) 343 | { 344 | // Note: This function can be removed if not used 345 | return $field; 346 | } 347 | 348 | 349 | /* 350 | * update_field() 351 | * 352 | * This filter is applied to the $field before it is saved to the database 353 | * 354 | * @type filter 355 | * @since 3.6 356 | * @date 23/01/13 357 | * 358 | * @param $field - the field array holding all the field options 359 | * @param $post_id - the field group ID (post_type = acf) 360 | * 361 | * @return $field - the modified field 362 | */ 363 | 364 | function update_field( $field, $post_id ) 365 | { 366 | // Note: This function can be removed if not used 367 | return $field; 368 | } 369 | 370 | 371 | } 372 | 373 | 374 | // create field 375 | new acf_field_reusable_field_group(); 376 | 377 | ?> 378 | -------------------------------------------------------------------------------- /acf-reusable_field_group-v5.php: -------------------------------------------------------------------------------- 1 | name = 'reusable_field_group'; 27 | 28 | 29 | /* 30 | * label (string) Multiple words, can include spaces, visible when selecting a field type 31 | */ 32 | 33 | $this->label = __('Reusable Field Group', 'acf-reusable_field_group'); 34 | 35 | 36 | /* 37 | * category (string) basic | content | choice | relational | jquery | layout | CUSTOM GROUP NAME 38 | */ 39 | 40 | $this->category = 'relational'; 41 | 42 | 43 | /* 44 | * defaults (array) Array of default settings which are merged into the field object. These are used later in settings 45 | */ 46 | 47 | $this->defaults = array( 48 | 'group_key' => 0, 49 | ); 50 | 51 | 52 | /* 53 | * l10n (array) Array of strings that are used in JavaScript. This allows JS strings to be translated in PHP and loaded via: 54 | * var message = acf._e('reusable_field_group', 'error'); 55 | */ 56 | 57 | $this->l10n = array( 58 | 'error' => __('Error! Please select a field group', 'acf-reusable_field_group'), 59 | ); 60 | 61 | add_filter("acf/get_field_types", array($this, 'get_field_types'), 10, 1); 62 | add_filter("acf/prepare_field_for_export", array($this, 'prepare_fields_for_export'), 10, 1); 63 | 64 | 65 | // do not delete! 66 | parent::__construct(); 67 | 68 | } 69 | 70 | 71 | /* 72 | * render_field_settings() 73 | * 74 | * Create extra settings for your field. These are visible when editing a field 75 | * 76 | * @type action 77 | * @since 3.6 78 | * @date 23/01/13 79 | * 80 | * @param $field (array) the $field being edited 81 | * @return n/a 82 | */ 83 | 84 | function render_field_settings( $field ) { 85 | acf_render_field_setting( $field, array( 86 | 'label' => __('Field Group','acf'), 87 | 'instructions' => '', 88 | 'type' => 'select', 89 | 'name' => 'group_key', 90 | 'choices' => $this->pretty_field_groups($field), 91 | 'multiple' => 0, 92 | 'ui' => 1, 93 | 'allow_null' => 0, 94 | 'placeholder' => __("No Field Group",'acf'), 95 | )); 96 | } 97 | 98 | 99 | function pretty_field_groups($field) { 100 | global $post; 101 | 102 | $groups = acf_get_field_groups(); 103 | $r = array(); 104 | 105 | $current_id = is_object( $post ) ? $post->ID : $_POST['parent']; 106 | $current_group = _acf_get_field_group_by_id($current_id); 107 | 108 | foreach( $groups as $group ) { 109 | $key = $group["key"]; 110 | 111 | // don't show the current field group. 112 | if ($key == $current_group["key"]) { 113 | continue; 114 | } 115 | 116 | $r[$key] = $group["title"]; 117 | } 118 | 119 | return $r; 120 | } 121 | 122 | 123 | function prepare_fields_for_export( $field ) { 124 | if ($field['type'] == $this->name) { 125 | unset($field['sub_fields']); 126 | } 127 | 128 | return $field; 129 | } 130 | 131 | 132 | /* 133 | * render_field() 134 | * 135 | * Create the HTML interface for your field 136 | * 137 | * @param $field (array) the $field being rendered 138 | * 139 | * @type action 140 | * @since 3.6 141 | * @date 23/01/13 142 | * 143 | * @param $field (array) the $field being edited 144 | * @return n/a 145 | */ 146 | 147 | function render_field( $field ) { 148 | global $post, $self; 149 | 150 | if (is_object($post)) { 151 | $current_id = $post->ID; 152 | } elseif ($self === "profile.php") { 153 | $current_id = "user_" . $_GET["user_id"]; 154 | } elseif ($self === "comment.php") { 155 | $current_id = "comment_" . $_GET["c"]; 156 | } else { 157 | $current_id = "options"; 158 | } 159 | 160 | $name_prefix = ''; 161 | 162 | if (isset($field['parent'])) { 163 | preg_match_all('/\[(field_\w+)\](\[(\d+)\])?/', $field['prefix'], $parent_fields); 164 | 165 | 166 | if (isset($parent_fields[0])) { 167 | foreach ($parent_fields[0] as $parent_field_index => $parent_field) { 168 | $field_name = $parent_fields[1][$parent_field_index]; 169 | $index = $parent_fields[3][$parent_field_index]; 170 | $parent_field_object = acf_get_field($field_name); 171 | $parent_prefix = $parent_field_object['name']; 172 | 173 | if ($index !== '') { 174 | $parent_prefix .= '_' . $index; 175 | } 176 | 177 | $name_prefix .= $parent_prefix . '_'; 178 | } 179 | } 180 | 181 | $name_prefix .= $field['_name'] . '_'; 182 | } 183 | 184 | foreach ( $field['sub_fields'] as $sub_field ) { 185 | $sub_name_prefix = $name_prefix; 186 | $sub_field_name = $sub_field['name']; 187 | 188 | // update prefix to allow for nested values 189 | $sub_field['prefix'] = $field["name"]; 190 | 191 | $sub_field['name'] = "{$name_prefix}{$sub_field_name}"; 192 | 193 | // load value 194 | if( $sub_field['value'] === null ) { 195 | $sub_field['value'] = acf_get_value( $current_id, $sub_field ); 196 | } 197 | 198 | // render input 199 | acf_render_field_wrap( $sub_field ); 200 | } 201 | } 202 | 203 | 204 | /* 205 | * input_admin_enqueue_scripts() 206 | * 207 | * This action is called in the admin_enqueue_scripts action on the edit screen where your field is created. 208 | * Use this action to add CSS + JavaScript to assist your render_field() action. 209 | * 210 | * @type action (admin_enqueue_scripts) 211 | * @since 3.6 212 | * @date 23/01/13 213 | * 214 | * @param n/a 215 | * @return n/a 216 | */ 217 | 218 | /* 219 | 220 | function input_admin_enqueue_scripts() { 221 | 222 | $dir = plugin_dir_url( __FILE__ ); 223 | 224 | 225 | // register & include JS 226 | wp_register_script( 'acf-input-reusable_field_group', "{$dir}js/input.js" ); 227 | wp_enqueue_script('acf-input-reusable_field_group'); 228 | 229 | 230 | // register & include CSS 231 | wp_register_style( 'acf-input-reusable_field_group', "{$dir}css/input.css" ); 232 | wp_enqueue_style('acf-input-reusable_field_group'); 233 | 234 | 235 | } 236 | 237 | */ 238 | 239 | 240 | /* 241 | * input_admin_head() 242 | * 243 | * This action is called in the admin_head action on the edit screen where your field is created. 244 | * Use this action to add CSS and JavaScript to assist your render_field() action. 245 | * 246 | * @type action (admin_head) 247 | * @since 3.6 248 | * @date 23/01/13 249 | * 250 | * @param n/a 251 | * @return n/a 252 | */ 253 | 254 | /* 255 | 256 | function input_admin_head() { 257 | 258 | 259 | 260 | } 261 | 262 | */ 263 | 264 | 265 | /* 266 | * input_form_data() 267 | * 268 | * This function is called once on the 'input' page between the head and footer 269 | * There are 2 situations where ACF did not load during the 'acf/input_admin_enqueue_scripts' and 270 | * 'acf/input_admin_head' actions because ACF did not know it was going to be used. These situations are 271 | * seen on comments / user edit forms on the front end. This function will always be called, and includes 272 | * $args that related to the current screen such as $args['post_id'] 273 | * 274 | * @type function 275 | * @date 6/03/2014 276 | * @since 5.0.0 277 | * 278 | * @param $args (array) 279 | * @return n/a 280 | */ 281 | 282 | /* 283 | 284 | function input_form_data( $args ) { 285 | 286 | 287 | 288 | } 289 | 290 | */ 291 | 292 | 293 | /* 294 | * input_admin_footer() 295 | * 296 | * This action is called in the admin_footer action on the edit screen where your field is created. 297 | * Use this action to add CSS and JavaScript to assist your render_field() action. 298 | * 299 | * @type action (admin_footer) 300 | * @since 3.6 301 | * @date 23/01/13 302 | * 303 | * @param n/a 304 | * @return n/a 305 | */ 306 | 307 | /* 308 | 309 | function input_admin_footer() { 310 | 311 | 312 | 313 | } 314 | 315 | */ 316 | 317 | 318 | /* 319 | * field_group_admin_enqueue_scripts() 320 | * 321 | * This action is called in the admin_enqueue_scripts action on the edit screen where your field is edited. 322 | * Use this action to add CSS + JavaScript to assist your render_field_options() action. 323 | * 324 | * @type action (admin_enqueue_scripts) 325 | * @since 3.6 326 | * @date 23/01/13 327 | * 328 | * @param n/a 329 | * @return n/a 330 | */ 331 | 332 | /* 333 | 334 | function field_group_admin_enqueue_scripts() { 335 | 336 | } 337 | 338 | */ 339 | 340 | 341 | /* 342 | * field_group_admin_head() 343 | * 344 | * This action is called in the admin_head action on the edit screen where your field is edited. 345 | * Use this action to add CSS and JavaScript to assist your render_field_options() action. 346 | * 347 | * @type action (admin_head) 348 | * @since 3.6 349 | * @date 23/01/13 350 | * 351 | * @param n/a 352 | * @return n/a 353 | */ 354 | 355 | 356 | 357 | function field_group_admin_head() { 358 | ?> 359 | 371 | $field_value) { 441 | foreach ( $field['sub_fields'] as $sub_field ) { 442 | if ($field_key == $sub_field['key']) { 443 | // update field 444 | $sub_field_name = $sub_field['name']; 445 | 446 | $sub_field['name'] = "{$field['name']}_{$sub_field_name}"; 447 | 448 | acf_update_value( $field_value, $post_id, $sub_field ); 449 | 450 | break; 451 | } 452 | } 453 | } 454 | } 455 | 456 | return null; 457 | } 458 | 459 | 460 | 461 | /* 462 | * format_value() 463 | * 464 | * This filter is appied to the $value after it is loaded from the db and before it is returned to the template 465 | * 466 | * @type filter 467 | * @since 3.6 468 | * @date 23/01/13 469 | * 470 | * @param $value (mixed) the value which was loaded from the database 471 | * @param $post_id (mixed) the $post_id from which the value was loaded 472 | * @param $field (array) the field array holding all the field options 473 | * 474 | * @return $value (mixed) the modified value 475 | */ 476 | 477 | /* 478 | 479 | function format_value( $value, $post_id, $field ) { 480 | 481 | // bail early if no value 482 | if( empty($value) ) { 483 | 484 | return $value; 485 | 486 | } 487 | 488 | 489 | // apply setting 490 | if( $field['font_size'] > 12 ) { 491 | 492 | // format the value 493 | // $value = 'something'; 494 | 495 | } 496 | 497 | 498 | // return 499 | return $value; 500 | } 501 | 502 | */ 503 | 504 | 505 | /* 506 | * validate_value() 507 | * 508 | * This filter is used to perform validation on the value prior to saving. 509 | * All values are validated regardless of the field's required setting. This allows you to validate and return 510 | * messages to the user if the value is not correct 511 | * 512 | * @type filter 513 | * @date 11/02/2014 514 | * @since 5.0.0 515 | * 516 | * @param $valid (boolean) validation status based on the value and the field's required setting 517 | * @param $value (mixed) the $_POST value 518 | * @param $field (array) the field array holding all the field options 519 | * @param $input (string) the corresponding input name for $_POST value 520 | * @return $valid 521 | */ 522 | 523 | /* 524 | 525 | function validate_value( $valid, $value, $field, $input ){ 526 | 527 | // Basic usage 528 | if( $value < $field['custom_minimum_setting'] ) 529 | { 530 | $valid = false; 531 | } 532 | 533 | 534 | // Advanced usage 535 | if( $value < $field['custom_minimum_setting'] ) 536 | { 537 | $valid = __('The value is too little!','acf-reusable_field_group'), 538 | } 539 | 540 | 541 | // return 542 | return $valid; 543 | 544 | } 545 | 546 | */ 547 | 548 | 549 | /* 550 | * delete_value() 551 | * 552 | * This action is fired after a value has been deleted from the db. 553 | * Please note that saving a blank value is treated as an update, not a delete 554 | * 555 | * @type action 556 | * @date 6/03/2014 557 | * @since 5.0.0 558 | * 559 | * @param $post_id (mixed) the $post_id from which the value was deleted 560 | * @param $key (string) the $meta_key which the value was deleted 561 | * @return n/a 562 | */ 563 | 564 | /* 565 | 566 | function delete_value( $post_id, $key ) { 567 | 568 | 569 | 570 | } 571 | 572 | */ 573 | 574 | 575 | /* 576 | * load_field() 577 | * 578 | * This filter is applied to the $field after it is loaded from the database 579 | * 580 | * @type filter 581 | * @date 23/01/2013 582 | * @since 3.6.0 583 | * 584 | * @param $field (array) the field array holding all the field options 585 | * @return $field 586 | */ 587 | 588 | 589 | 590 | function load_field( $field ) { 591 | 592 | $group = _acf_get_field_group_by_key($field["group_key"]); 593 | $fields = acf_get_fields($group); 594 | $field['sub_fields'] = $fields; 595 | 596 | return $field; 597 | 598 | } 599 | 600 | 601 | 602 | 603 | /* 604 | * update_field() 605 | * 606 | * This filter is applied to the $field before it is saved to the database 607 | * 608 | * @type filter 609 | * @date 23/01/2013 610 | * @since 3.6.0 611 | * 612 | * @param $field (array) the field array holding all the field options 613 | * @return $field 614 | */ 615 | 616 | 617 | 618 | function update_field( $field ) { 619 | 620 | // remove sub fields 621 | unset($field['sub_fields']); 622 | 623 | return $field; 624 | 625 | } 626 | 627 | 628 | 629 | 630 | /* 631 | * delete_field() 632 | * 633 | * This action is fired after a field is deleted from the database 634 | * 635 | * @type action 636 | * @date 11/02/2014 637 | * @since 5.0.0 638 | * 639 | * @param $field (array) the field array holding all the field options 640 | * @return n/a 641 | */ 642 | 643 | 644 | 645 | function delete_field( $field ) { 646 | 647 | // loop through sub fields 648 | if( !empty($field['sub_fields']) ) { 649 | 650 | foreach( $field['sub_fields'] as $sub_field ) { 651 | 652 | acf_delete_field( $sub_field['ID'] ); 653 | 654 | } 655 | 656 | } 657 | 658 | } 659 | 660 | 661 | 662 | 663 | } 664 | 665 | 666 | // create field 667 | new acf_field_reusable_field_group(); 668 | 669 | endif; 670 | 671 | ?> 672 | --------------------------------------------------------------------------------