Code Duplication    Length = 25-31 lines in 4 locations

classes/PodsMeta.php 4 locations

@@ 1141-1166 (lines=26) @@
1138
		$id = $post_id;
1139
		$pod = null;
1140
1141
		foreach ( $groups as $group ) {
1142
			if ( empty( $group[ 'fields' ] ) )
1143
				continue;
1144
1145
			if ( null === $pod || ( is_object( $pod ) && $pod->id() != $id ) ) {
1146
				if ( !is_object( self::$current_pod ) || self::$current_pod->pod != $group[ 'pod' ][ 'name' ] )
1147
					self::$current_pod = pods( $group[ 'pod' ][ 'name' ], $id, true );
1148
				elseif ( self::$current_pod->id() != $id )
1149
					self::$current_pod->fetch( $id );
1150
1151
				$pod = self::$current_pod;
1152
			}
1153
1154
			foreach ( $group[ 'fields' ] as $field ) {
1155
1156
				if ( false === PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field, $group[ 'fields' ], $pod, $id ) ) {
1157
					if ( !pods_var( 'hidden', $field[ 'options' ], false ) )
1158
						continue;
1159
				}
1160
1161
				$data[ $field[ 'name' ] ] = '';
1162
1163
				if ( isset( $_POST[ 'pods_meta_' . $field[ 'name' ] ] ) )
1164
					$data[ $field[ 'name' ] ] = $_POST[ 'pods_meta_' . $field[ 'name' ] ];
1165
			}
1166
		}
1167
1168
		if ( $is_new_item ) {
1169
			do_action( 'pods_meta_create_pre_post', $data, $pod, $id, $groups, $post, $post->post_type );
@@ 1301-1326 (lines=26) @@
1298
        $id = $post_id;
1299
        $pod = null;
1300
1301
        foreach ( $groups as $group ) {
1302
            if ( empty( $group[ 'fields' ] ) )
1303
                continue;
1304
1305
			if ( null === $pod || ( is_object( $pod ) && $pod->id() != $id ) ) {
1306
				if ( !is_object( self::$current_pod ) || self::$current_pod->pod != $group[ 'pod' ][ 'name' ] )
1307
					self::$current_pod = pods( $group[ 'pod' ][ 'name' ], $id, true );
1308
				elseif ( self::$current_pod->id() != $id )
1309
					self::$current_pod->fetch( $id );
1310
1311
				$pod = self::$current_pod;
1312
			}
1313
1314
            foreach ( $group[ 'fields' ] as $field ) {
1315
1316
                if ( false === PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field, $group[ 'fields' ], $pod, $id ) ) {
1317
                    if ( !pods_var( 'hidden', $field[ 'options' ], false ) )
1318
                        continue;
1319
                }
1320
1321
                $data[ $field[ 'name' ] ] = '';
1322
1323
                if ( isset( $_POST[ 'pods_meta_' . $field[ 'name' ] ] ) )
1324
                    $data[ $field[ 'name' ] ] = $_POST[ 'pods_meta_' . $field[ 'name' ] ];
1325
            }
1326
        }
1327
1328
        do_action( 'pods_meta_save_pre_media', $data, $pod, $id, $groups, $post, $attachment );
1329
@@ 1694-1724 (lines=31) @@
1691
		$id = $user_id;
1692
		$pod = null;
1693
1694
		foreach ( $groups as $group ) {
1695
			if ( empty( $group[ 'fields' ] ) ) {
1696
				continue;
1697
			}
1698
1699
			if ( null === $pod || ( is_object( $pod ) && $pod->id() != $id ) ) {
1700
				if ( !is_object( self::$current_pod ) || self::$current_pod->pod != $group[ 'pod' ][ 'name' ] ) {
1701
					self::$current_pod = pods( $group[ 'pod' ][ 'name' ], $id, true );
1702
				}
1703
				elseif ( self::$current_pod->id() != $id ) {
1704
					self::$current_pod->fetch( $id );
1705
				}
1706
1707
				$pod = self::$current_pod;
1708
			}
1709
1710
			foreach ( $group[ 'fields' ] as $field ) {
1711
1712
				if ( false === PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field, $group[ 'fields' ], $pod, $id ) ) {
1713
					if ( !pods_var( 'hidden', $field[ 'options' ], false ) ) {
1714
						continue;
1715
					}
1716
				}
1717
1718
				$data[ $field[ 'name' ] ] = '';
1719
1720
				if ( isset( $_POST[ 'pods_meta_' . $field[ 'name' ] ] ) ) {
1721
					$data[ $field[ 'name' ] ] = $_POST[ 'pods_meta_' . $field[ 'name' ] ];
1722
				}
1723
			}
1724
		}
1725
1726
		if ( $is_new_item ) {
1727
			do_action( 'pods_meta_create_pre_user', $data, $pod, $id, $groups );
@@ 2095-2119 (lines=25) @@
2092
        $id = $comment_id;
2093
        $pod = null;
2094
2095
        foreach ( $groups as $group ) {
2096
            if ( empty( $group[ 'fields' ] ) )
2097
                continue;
2098
2099
			if ( null === $pod || ( is_object( $pod ) && $pod->id() != $id ) ) {
2100
				if ( !is_object( self::$current_pod ) || self::$current_pod->pod != $group[ 'pod' ][ 'name' ] )
2101
					self::$current_pod = pods( $group[ 'pod' ][ 'name' ], $id, true );
2102
				elseif ( self::$current_pod->id() != $id )
2103
					self::$current_pod->fetch( $id );
2104
2105
				$pod = self::$current_pod;
2106
			}
2107
2108
            foreach ( $group[ 'fields' ] as $field ) {
2109
                if ( false === PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field, $group[ 'fields' ], $pod, $id ) ) {
2110
                    if ( !pods_var( 'hidden', $field[ 'options' ], false ) )
2111
                        continue;
2112
                }
2113
2114
                $data[ $field[ 'name' ] ] = '';
2115
2116
                if ( isset( $_POST[ 'pods_meta_' . $field[ 'name' ] ] ) )
2117
                    $data[ $field[ 'name' ] ] = $_POST[ 'pods_meta_' . $field[ 'name' ] ];
2118
            }
2119
        }
2120
2121
        do_action( 'pods_meta_save_pre_comment', $data, $pod, $id, $groups );
2122