Title: BUG: Plugin overwrite cf7 hidden fields
Last modified: April 19, 2018

---

# BUG: Plugin overwrite cf7 hidden fields

 *  Resolved [Aurovrata Venet](https://wordpress.org/support/users/aurovrata/)
 * (@aurovrata)
 * [8 years, 1 month ago](https://wordpress.org/support/topic/bug-plugin-overwrite-cf7-hidden-fields/)
 * The file cf7cf.php hooks the cf7 filter ‘wpcf7_form_hidden_fields’ on line 290,
   but instead of returning an updated set of hiddend fields, overwrites it completly,
   breaking other plugins using the same functionality,
 *     ```
       add_action('wpcf7_form_hidden_fields', 'wpcf7cf_form_hidden_fields',10,1);
   
       function wpcf7cf_form_hidden_fields($hidden_fields) {
   
           $current_form = wpcf7_get_current_contact_form();
           $current_form_id = $current_form->id();
   
           $options = array(
               'form_id' => $current_form_id,
               'conditions' => get_post_meta($current_form_id,'wpcf7cf_options', true),
               'settings' => get_option(WPCF7CF_OPTIONS)
           );
   
           return array(
               '_wpcf7cf_hidden_group_fields' => '',
               '_wpcf7cf_hidden_groups' => '',
               '_wpcf7cf_visible_groups' => '',
               '_wpcf7cf_options' => ''.json_encode($options),
           );
       }
       ```
   
 * it should return instead,
 *     ```
       return array_merge($hidden_fields, array(
               '_wpcf7cf_hidden_group_fields' => '',
               '_wpcf7cf_hidden_groups' => '',
               '_wpcf7cf_visible_groups' => '',
               '_wpcf7cf_options' => ''.json_encode($options),
           ));
       ```
   

Viewing 11 replies - 1 through 11 (of 11 total)

 *  Plugin Author [Jules Colle](https://wordpress.org/support/users/jules-colle/)
 * (@jules-colle)
 * [8 years, 1 month ago](https://wordpress.org/support/topic/bug-plugin-overwrite-cf7-hidden-fields/#post-10199928)
 * that looks like a bad bug indeed. thanks for reporting it. will fix it ASAP.
 *  Plugin Author [Jules Colle](https://wordpress.org/support/users/jules-colle/)
 * (@jules-colle)
 * [8 years, 1 month ago](https://wordpress.org/support/topic/bug-plugin-overwrite-cf7-hidden-fields/#post-10200006)
 * I just checked, but it looks like it’s okay. Contact Form 7 is calling the filter
   like this in includes/contact-form.php line 428:
 * `$hidden_fields += (array) apply_filters('wpcf7_form_hidden_fields', array() );`
 * As you can see it passes an empty array as parameter, making it kind of obsolete,
   and merges the returned array with the hidden fields anyway. So I don’t see the
   difference with merging the results-array with an empty array, or simply returning
   the array like I do now.
 * Correct me if you think I’m wrong.
 *  Thread Starter [Aurovrata Venet](https://wordpress.org/support/users/aurovrata/)
 * (@aurovrata)
 * [8 years, 1 month ago](https://wordpress.org/support/topic/bug-plugin-overwrite-cf7-hidden-fields/#post-10200816)
 * Hi Jules, thank you for the prompt reply
 * >  it passes an empty array as parameter, making it kind of obsolete, and merges
   > the returned array with the hidden fields anyway.
 * that is true, but CF7 does this in order to prevent such kind of coding overwriting
   its hidden fields
 * > I don’t see the difference with merging the results-array with an empty array,
   > or simply returning the array like I do now
 * well since your function is hooked on the default priority, this means that any
   other plugin that uses this hook to include some custom hidden fields runs the
   risk of either having its hidden fields wiped (if hooked prior to your function),
   or potentially even worse for your plugin, wiping your plugin’s fields if its
   hooked after your function and assumes a similar logic.
 * I have 2 plugins that use this hook on the default priority, both of which simply
   appends custom fields to the end of the array. In one installation my plugin’s
   function happened to be hooked after yours (although they both have priority 
   10, it all depends on when the registration is executed) and therefore my custom
   fields were being systematically overwritten.
 * Generally it is always best to return the *modified* value of a filter hook in
   WordPress, rather than overwriting it, as there may be several plugins/theme 
   functions that hook onto it.
 *  Plugin Author [Jules Colle](https://wordpress.org/support/users/jules-colle/)
 * (@jules-colle)
 * [8 years, 1 month ago](https://wordpress.org/support/topic/bug-plugin-overwrite-cf7-hidden-fields/#post-10201350)
 * You’re right. I wasn’t thinking clearly. Thanks again for pointing this out and
   taking your time to explain. the code will be updated in the next version.
 *  Thread Starter [Aurovrata Venet](https://wordpress.org/support/users/aurovrata/)
 * (@aurovrata)
 * [8 years, 1 month ago](https://wordpress.org/support/topic/bug-plugin-overwrite-cf7-hidden-fields/#post-10212046)
 * hey, no worries! thanks for the udpate 🙂
 *  Plugin Author [Jules Colle](https://wordpress.org/support/users/jules-colle/)
 * (@jules-colle)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/bug-plugin-overwrite-cf7-hidden-fields/#post-10563899)
 * Will follow up here: [https://github.com/pwkip/contact-form-7-conditional-fields/issues](https://github.com/pwkip/contact-form-7-conditional-fields/issues)
 *  Thread Starter [Aurovrata Venet](https://wordpress.org/support/users/aurovrata/)
 * (@aurovrata)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/bug-plugin-overwrite-cf7-hidden-fields/#post-10577782)
 * do u want me to raise the same issue on your github repo?
 *  Plugin Author [Jules Colle](https://wordpress.org/support/users/jules-colle/)
 * (@jules-colle)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/bug-plugin-overwrite-cf7-hidden-fields/#post-10577797)
 * no, I already did. I just posted the wrong link here. The post is: [https://github.com/pwkip/contact-form-7-conditional-fields/issues/20](https://github.com/pwkip/contact-form-7-conditional-fields/issues/20)
 *  Thread Starter [Aurovrata Venet](https://wordpress.org/support/users/aurovrata/)
 * (@aurovrata)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/bug-plugin-overwrite-cf7-hidden-fields/#post-10577846)
 * ok, got it. thanks. Did you get a chance to take a look at this [issue](https://wordpress.org/support/topic/does-not-play-with-cf7-smart-grid-design-extension/)?
   Am happy to give you some suggestions on Github if you want to look at this.
 *  Plugin Author [Jules Colle](https://wordpress.org/support/users/jules-colle/)
 * (@jules-colle)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/bug-plugin-overwrite-cf7-hidden-fields/#post-10577851)
 * No, it’s okay. I know what to do. Working on a major update, but I need to do
   some more proper testing, so the release keeps getting postponed 🙁
 *  Thread Starter [Aurovrata Venet](https://wordpress.org/support/users/aurovrata/)
 * (@aurovrata)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/bug-plugin-overwrite-cf7-hidden-fields/#post-10577856)
 * ok great! Feel free to ping me on my mail if you need any clarification.

Viewing 11 replies - 1 through 11 (of 11 total)

The topic ‘BUG: Plugin overwrite cf7 hidden fields’ is closed to new replies.

 * ![](https://ps.w.org/cf7-conditional-fields/assets/icon-256x256.png?rev=2072595)
 * [Conditional Fields for Contact Form 7](https://wordpress.org/plugins/cf7-conditional-fields/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/cf7-conditional-fields/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/cf7-conditional-fields/)
 * [Active Topics](https://wordpress.org/support/plugin/cf7-conditional-fields/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/cf7-conditional-fields/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/cf7-conditional-fields/reviews/)

 * 11 replies
 * 2 participants
 * Last reply from: [Aurovrata Venet](https://wordpress.org/support/users/aurovrata/)
 * Last activity: [7 years, 10 months ago](https://wordpress.org/support/topic/bug-plugin-overwrite-cf7-hidden-fields/#post-10577856)
 * Status: resolved