ACF_Taxonomy::export_post_as_php
Returns a string that can be used to create a taxonomy in PHP.
Method of the class: ACF_Taxonomy{}
No Hooks.
Returns
String.
Usage
$ACF_Taxonomy = new ACF_Taxonomy(); $ACF_Taxonomy->export_post_as_php( $post );
- $post(array)
- The main taxonomy array.
Default:array()
Changelog
| Since 6.1 | Introduced. |
ACF_Taxonomy::export_post_as_php() ACF Taxonomy::export post as php code ACF 6.8.8
public function export_post_as_php( $post = array() ) {
$return = '';
if ( empty( $post ) ) {
return $return;
}
$post = $this->validate_post( $post );
$taxonomy_key = $post['taxonomy'];
$objects = (array) $post['object_type'];
$objects = var_export( $objects, true ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions -- Used for PHP export.
$args = $this->get_taxonomy_args( $post, false );
// Restore original metabox callback.
if ( ! empty( $args['meta_box_cb'] ) && ! empty( $post['meta_box_cb'] ) ) {
$args['meta_box_cb'] = $post['meta_box_cb'];
}
$args = var_export( $args, true ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions -- Used for PHP export.
if ( ! $args ) {
return $return;
}
$args = $this->format_code_for_export( $args );
$objects = $this->format_code_for_export( $objects );
$return .= "register_taxonomy( '{$taxonomy_key}', {$objects}, {$args} );\r\n";
return esc_textarea( $return );
}