Code Duplication    Length = 25-31 lines in 4 locations

classes/PodsMeta.php 4 locations

@@ 1135-1160 (lines=26) @@
1132
		$id = $post_id;
1133
		$pod = null;
1134
1135
		foreach ( $groups as $group ) {
1136
			if ( empty( $group[ 'fields' ] ) )
1137
				continue;
1138
1139
			if ( null === $pod || ( is_object( $pod ) && $pod->id() != $id ) ) {
1140
				if ( !is_object( self::$current_pod ) || self::$current_pod->pod != $group[ 'pod' ][ 'name' ] )
1141
					self::$current_pod = pods( $group[ 'pod' ][ 'name' ], $id, true );
1142
				elseif ( self::$current_pod->id() != $id )
1143
					self::$current_pod->fetch( $id );
1144
1145
				$pod = self::$current_pod;
1146
			}
1147
1148
			foreach ( $group[ 'fields' ] as $field ) {
1149
1150
				if ( false === PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field, $group[ 'fields' ], $pod, $id ) ) {
1151
					if ( !pods_var( 'hidden', $field[ 'options' ], false ) )
1152
						continue;
1153
				}
1154
1155
				$data[ $field[ 'name' ] ] = '';
1156
1157
				if ( isset( $_POST[ 'pods_meta_' . $field[ 'name' ] ] ) )
1158
					$data[ $field[ 'name' ] ] = $_POST[ 'pods_meta_' . $field[ 'name' ] ];
1159
			}
1160
		}
1161
1162
		if ( $is_new_item ) {
1163
			do_action( 'pods_meta_create_pre_post', $data, $pod, $id, $groups, $post, $post->post_type );
@@ 1295-1320 (lines=26) @@
1292
        $id = $post_id;
1293
        $pod = null;
1294
1295
        foreach ( $groups as $group ) {
1296
            if ( empty( $group[ 'fields' ] ) )
1297
                continue;
1298
1299
			if ( null === $pod || ( is_object( $pod ) && $pod->id() != $id ) ) {
1300
				if ( !is_object( self::$current_pod ) || self::$current_pod->pod != $group[ 'pod' ][ 'name' ] )
1301
					self::$current_pod = pods( $group[ 'pod' ][ 'name' ], $id, true );
1302
				elseif ( self::$current_pod->id() != $id )
1303
					self::$current_pod->fetch( $id );
1304
1305
				$pod = self::$current_pod;
1306
			}
1307
1308
            foreach ( $group[ 'fields' ] as $field ) {
1309
1310
                if ( false === PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field, $group[ 'fields' ], $pod, $id ) ) {
1311
                    if ( !pods_var( 'hidden', $field[ 'options' ], false ) )
1312
                        continue;
1313
                }
1314
1315
                $data[ $field[ 'name' ] ] = '';
1316
1317
                if ( isset( $_POST[ 'pods_meta_' . $field[ 'name' ] ] ) )
1318
                    $data[ $field[ 'name' ] ] = $_POST[ 'pods_meta_' . $field[ 'name' ] ];
1319
            }
1320
        }
1321
1322
        do_action( 'pods_meta_save_pre_media', $data, $pod, $id, $groups, $post, $attachment );
1323
@@ 1688-1718 (lines=31) @@
1685
		$id = $user_id;
1686
		$pod = null;
1687
1688
		foreach ( $groups as $group ) {
1689
			if ( empty( $group[ 'fields' ] ) ) {
1690
				continue;
1691
			}
1692
1693
			if ( null === $pod || ( is_object( $pod ) && $pod->id() != $id ) ) {
1694
				if ( !is_object( self::$current_pod ) || self::$current_pod->pod != $group[ 'pod' ][ 'name' ] ) {
1695
					self::$current_pod = pods( $group[ 'pod' ][ 'name' ], $id, true );
1696
				}
1697
				elseif ( self::$current_pod->id() != $id ) {
1698
					self::$current_pod->fetch( $id );
1699
				}
1700
1701
				$pod = self::$current_pod;
1702
			}
1703
1704
			foreach ( $group[ 'fields' ] as $field ) {
1705
1706
				if ( false === PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field, $group[ 'fields' ], $pod, $id ) ) {
1707
					if ( !pods_var( 'hidden', $field[ 'options' ], false ) ) {
1708
						continue;
1709
					}
1710
				}
1711
1712
				$data[ $field[ 'name' ] ] = '';
1713
1714
				if ( isset( $_POST[ 'pods_meta_' . $field[ 'name' ] ] ) ) {
1715
					$data[ $field[ 'name' ] ] = $_POST[ 'pods_meta_' . $field[ 'name' ] ];
1716
				}
1717
			}
1718
		}
1719
1720
		if ( $is_new_item ) {
1721
			do_action( 'pods_meta_create_pre_user', $data, $pod, $id, $groups );
@@ 2089-2113 (lines=25) @@
2086
        $id = $comment_id;
2087
        $pod = null;
2088
2089
        foreach ( $groups as $group ) {
2090
            if ( empty( $group[ 'fields' ] ) )
2091
                continue;
2092
2093
			if ( null === $pod || ( is_object( $pod ) && $pod->id() != $id ) ) {
2094
				if ( !is_object( self::$current_pod ) || self::$current_pod->pod != $group[ 'pod' ][ 'name' ] )
2095
					self::$current_pod = pods( $group[ 'pod' ][ 'name' ], $id, true );
2096
				elseif ( self::$current_pod->id() != $id )
2097
					self::$current_pod->fetch( $id );
2098
2099
				$pod = self::$current_pod;
2100
			}
2101
2102
            foreach ( $group[ 'fields' ] as $field ) {
2103
                if ( false === PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field, $group[ 'fields' ], $pod, $id ) ) {
2104
                    if ( !pods_var( 'hidden', $field[ 'options' ], false ) )
2105
                        continue;
2106
                }
2107
2108
                $data[ $field[ 'name' ] ] = '';
2109
2110
                if ( isset( $_POST[ 'pods_meta_' . $field[ 'name' ] ] ) )
2111
                    $data[ $field[ 'name' ] ] = $_POST[ 'pods_meta_' . $field[ 'name' ] ];
2112
            }
2113
        }
2114
2115
        do_action( 'pods_meta_save_pre_comment', $data, $pod, $id, $groups );
2116