@@ -182,17 +182,46 @@ public function export_pod( $pod_name ) {
182
182
}
183
183
184
184
// 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 ) );
186
186
$ output .= "\tpods_register_type( \$pod[ 'type' ], \$pod[ 'name' ], \$pod ); \n\n" ;
187
187
188
188
// Output a pods_register_field() call for each field
189
189
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 ) ) );
191
191
$ output .= "\tpods_register_field( \$pod[ 'name' ], \$field[ 'name' ], \$field ); \n\n" ;
192
192
}
193
193
194
194
return $ output ;
195
195
196
196
}
197
197
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
+
198
227
}
0 commit comments