Code Duplication    Length = 25-31 lines in 4 locations

classes/PodsMeta.php 4 locations

@@ 2132-2156 (lines=25) @@
2129
        $id = $comment_id;
2130
        $pod = null;
2131
2132
        foreach ( $groups as $group ) {
2133
            if ( empty( $group[ 'fields' ] ) )
2134
                continue;
2135
2136
			if ( null === $pod || ( is_object( $pod ) && $pod->id() != $id ) ) {
2137
				if ( !is_object( self::$current_pod ) || self::$current_pod->pod != $group[ 'pod' ][ 'name' ] )
2138
					self::$current_pod = pods( $group[ 'pod' ][ 'name' ], $id, true );
2139
				elseif ( self::$current_pod->id() != $id )
2140
					self::$current_pod->fetch( $id );
2141
2142
				$pod = self::$current_pod;
2143
			}
2144
2145
            foreach ( $group[ 'fields' ] as $field ) {
2146
                if ( false === PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field, $group[ 'fields' ], $pod, $id ) ) {
2147
                    if ( !pods_var( 'hidden', $field[ 'options' ], false ) )
2148
                        continue;
2149
                }
2150
2151
                $data[ $field[ 'name' ] ] = '';
2152
2153
                if ( isset( $_POST[ 'pods_meta_' . $field[ 'name' ] ] ) )
2154
                    $data[ $field[ 'name' ] ] = $_POST[ 'pods_meta_' . $field[ 'name' ] ];
2155
            }
2156
        }
2157
2158
        do_action( 'pods_meta_save_pre_comment', $data, $pod, $id, $groups );
2159
@@ 1178-1203 (lines=26) @@
1175
		$id = $post_id;
1176
		$pod = null;
1177
1178
		foreach ( $groups as $group ) {
1179
			if ( empty( $group[ 'fields' ] ) )
1180
				continue;
1181
1182
			if ( null === $pod || ( is_object( $pod ) && $pod->id() != $id ) ) {
1183
				if ( !is_object( self::$current_pod ) || self::$current_pod->pod != $group[ 'pod' ][ 'name' ] )
1184
					self::$current_pod = pods( $group[ 'pod' ][ 'name' ], $id, true );
1185
				elseif ( self::$current_pod->id() != $id )
1186
					self::$current_pod->fetch( $id );
1187
1188
				$pod = self::$current_pod;
1189
			}
1190
1191
			foreach ( $group[ 'fields' ] as $field ) {
1192
1193
				if ( false === PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field, $group[ 'fields' ], $pod, $id ) ) {
1194
					if ( !pods_var( 'hidden', $field[ 'options' ], false ) )
1195
						continue;
1196
				}
1197
1198
				$data[ $field[ 'name' ] ] = '';
1199
1200
				if ( isset( $_POST[ 'pods_meta_' . $field[ 'name' ] ] ) )
1201
					$data[ $field[ 'name' ] ] = $_POST[ 'pods_meta_' . $field[ 'name' ] ];
1202
			}
1203
		}
1204
1205
		if ( $is_new_item ) {
1206
			do_action( 'pods_meta_create_pre_post', $data, $pod, $id, $groups, $post, $post->post_type );
@@ 1338-1363 (lines=26) @@
1335
        $id = $post_id;
1336
        $pod = null;
1337
1338
        foreach ( $groups as $group ) {
1339
            if ( empty( $group[ 'fields' ] ) )
1340
                continue;
1341
1342
			if ( null === $pod || ( is_object( $pod ) && $pod->id() != $id ) ) {
1343
				if ( !is_object( self::$current_pod ) || self::$current_pod->pod != $group[ 'pod' ][ 'name' ] )
1344
					self::$current_pod = pods( $group[ 'pod' ][ 'name' ], $id, true );
1345
				elseif ( self::$current_pod->id() != $id )
1346
					self::$current_pod->fetch( $id );
1347
1348
				$pod = self::$current_pod;
1349
			}
1350
1351
            foreach ( $group[ 'fields' ] as $field ) {
1352
1353
                if ( false === PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field, $group[ 'fields' ], $pod, $id ) ) {
1354
                    if ( !pods_var( 'hidden', $field[ 'options' ], false ) )
1355
                        continue;
1356
                }
1357
1358
                $data[ $field[ 'name' ] ] = '';
1359
1360
                if ( isset( $_POST[ 'pods_meta_' . $field[ 'name' ] ] ) )
1361
                    $data[ $field[ 'name' ] ] = $_POST[ 'pods_meta_' . $field[ 'name' ] ];
1362
            }
1363
        }
1364
1365
        do_action( 'pods_meta_save_pre_media', $data, $pod, $id, $groups, $post, $attachment );
1366
@@ 1731-1761 (lines=31) @@
1728
		$id = $user_id;
1729
		$pod = null;
1730
1731
		foreach ( $groups as $group ) {
1732
			if ( empty( $group[ 'fields' ] ) ) {
1733
				continue;
1734
			}
1735
1736
			if ( null === $pod || ( is_object( $pod ) && $pod->id() != $id ) ) {
1737
				if ( !is_object( self::$current_pod ) || self::$current_pod->pod != $group[ 'pod' ][ 'name' ] ) {
1738
					self::$current_pod = pods( $group[ 'pod' ][ 'name' ], $id, true );
1739
				}
1740
				elseif ( self::$current_pod->id() != $id ) {
1741
					self::$current_pod->fetch( $id );
1742
				}
1743
1744
				$pod = self::$current_pod;
1745
			}
1746
1747
			foreach ( $group[ 'fields' ] as $field ) {
1748
1749
				if ( false === PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field, $group[ 'fields' ], $pod, $id ) ) {
1750
					if ( !pods_var( 'hidden', $field[ 'options' ], false ) ) {
1751
						continue;
1752
					}
1753
				}
1754
1755
				$data[ $field[ 'name' ] ] = '';
1756
1757
				if ( isset( $_POST[ 'pods_meta_' . $field[ 'name' ] ] ) ) {
1758
					$data[ $field[ 'name' ] ] = $_POST[ 'pods_meta_' . $field[ 'name' ] ];
1759
				}
1760
			}
1761
		}
1762
1763
		if ( $is_new_item ) {
1764
			do_action( 'pods_meta_create_pre_user', $data, $pod, $id, $groups );