@@ -182,17 +182,46 @@ public function export_pod( $pod_name ) {
182182 }
183183
184184 // Output the pods_register_type() call
185- $ output .= sprintf ( "\t\$pod = %s; \n\n" , preg_replace ( ' /\d+ => / ' , '' , var_export ( $ pod , true ) ) );
185+ $ output .= sprintf ( "\t\$pod = %s; \n\n" , $ this -> var_export_format ( $ pod , 1 ) );
186186 $ output .= "\tpods_register_type( \$pod[ 'type' ], \$pod[ 'name' ], \$pod ); \n\n" ;
187187
188188 // Output a pods_register_field() call for each field
189189 foreach ( $ fields as $ this_field ) {
190- $ output .= sprintf ( "\t\$field = %s; \n\n" , preg_replace ( '/\d+ => / ' , '' , var_export ( $ this_field , true ) ) );
190+ $ output .= sprintf ( "\t\$field = %s; \n\n" , preg_replace ( '/\d+ => / ' , '' , $ this -> var_export_format ( $ this_field , 1 ) ) );
191191 $ output .= "\tpods_register_field( \$pod[ 'name' ], \$field[ 'name' ], \$field ); \n\n" ;
192192 }
193193
194194 return $ output ;
195195
196196 }
197197
198+ /**
199+ * @param mixed $var
200+ * @param int $leading_tabs
201+ *
202+ * @return string
203+ */
204+ private function var_export_format ( $ var , $ leading_tabs = 0 ) {
205+ $ var = var_export ( $ var , true );
206+ $ leading_tabs = str_repeat ( "\t" , $ leading_tabs );
207+
208+ // Convert params like 0 => 'Option 1' to just 'Option 1'
209+ $ var = preg_replace ( '/\d+ => / ' , '' , $ var );
210+
211+ $ output = '' ;
212+ foreach ( preg_split ('~[\r\n]+~ ' , $ var ) as $ line ){
213+
214+ // Skip blank lines
215+ if ( empty ($ line ) || ctype_space ( $ line ) ) {
216+ continue ;
217+ }
218+
219+ // Leading tabs plus replace double spaces with tabs
220+ $ output .= sprintf ( "%s%s \n" , $ leading_tabs , preg_replace ( "/ {2}/ " , "\t" , $ line ) );
221+ }
222+
223+ // Trim the leading tab and the final newline
224+ return ltrim ( rtrim ( $ output , "\n" ), "\t" );
225+ }
226+
198227}
0 commit comments