Title: Code improvement
Last modified: July 18, 2019

---

# Code improvement

 *  [Kevin van Hengst](https://wordpress.org/support/users/kevinvhengst/)
 * (@kevinvhengst)
 * [7 years, 7 months ago](https://wordpress.org/support/topic/code-improvement/)
 * Hi,
 * When installing the plugin it gives me a lot of warnings regarding:
 * `Invalid argument supplied for foreach() in /home/kevin/hoppinger/fc-corporate/
   web/app/plugins/hreflang-tags-by-dcgws/includes/functions.php on line 463`
 * It does this because if assumes the post type settings have been set.
 * Since I don’t like using SVN and can’t be arsed to see how to create a pull request
   I’ll add the updated code here that prevents this error:
 *     ```
       function hreflang_taxonomy_forms() {
       	$types = get_option('hreflang_post_types');
       	if(!empty($types)) {
       		foreach($types as $type) {
       			if ( !post_type_exists($type) ) {
       				add_action($type.'_add_form_fields','add_hreflang_to_category_form',99);
       				add_action($type.'_edit_form_fields','add_hreflang_to_category_edit_form',10,1);
       			}
       		}
       	}
       }
       ```
   
 * I first check if $types is empty before trying to loop over it. This makes sure
   it only goes into the foreach if the post type settings have actually been set.
 * Kind regards,
 * Kevin van Hengst
    -  This topic was modified 7 years, 7 months ago by [Kevin van Hengst](https://wordpress.org/support/users/kevinvhengst/).

Viewing 1 replies (of 1 total)

 *  [David Davis](https://wordpress.org/support/users/dcgws/)
 * (@dcgws)
 * [7 years, 6 months ago](https://wordpress.org/support/topic/code-improvement/#post-11151593)
 * Hi Kevin
 * Sorry, I’ve just seen this. I’ve been very busy with other projects/life outside
   of plugin development.
 * First of all, please try and edit your post. Please use x’s in place of your 
   name and account details in your file path. 1) it doesn’t help me address the
   issue and 2) it could be a serious security breach for you.
 * I’ll try to issue an update in the next couple of weeks.
 * Best
    David

Viewing 1 replies (of 1 total)

The topic ‘Code improvement’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/hreflang-tags-by-dcgws_91a8a0.svg)
 * [HREFLANG Tags Lite](https://wordpress.org/plugins/hreflang-tags-by-dcgws/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/hreflang-tags-by-dcgws/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/hreflang-tags-by-dcgws/)
 * [Active Topics](https://wordpress.org/support/plugin/hreflang-tags-by-dcgws/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/hreflang-tags-by-dcgws/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/hreflang-tags-by-dcgws/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [David Davis](https://wordpress.org/support/users/dcgws/)
 * Last activity: [7 years, 6 months ago](https://wordpress.org/support/topic/code-improvement/#post-11151593)
 * Status: not a support question