validate_page() ) { return; } // vars $screen = get_current_screen(); $taxonomy = $screen->taxonomy; // load acf scripts acf_enqueue_scripts(); // actions add_action( 'admin_footer', array( $this, 'admin_footer' ), 10, 1 ); add_action( "{$taxonomy}_add_form_fields", array( $this, 'add_term' ), 10, 1 ); add_action( "{$taxonomy}_edit_form", array( $this, 'edit_term' ), 10, 2 ); } /** * description * * @type function * @date 8/10/13 * @since 5.0.0 * * @param $post_id (int) * @return $post_id (int) */ function add_term( $taxonomy ) { // vars $post_id = 'term_0'; // update vars $this->view = 'add'; // get field groups $field_groups = acf_get_field_groups( array( 'taxonomy' => $taxonomy, ) ); // render if ( ! empty( $field_groups ) ) { // data acf_form_data( array( 'screen' => 'taxonomy', 'post_id' => $post_id, ) ); // wrap echo '
'; // loop foreach ( $field_groups as $field_group ) { $fields = acf_get_fields( $field_group ); acf_render_fields( $fields, $post_id, 'div', 'field', array( 'render_id' => $post_id . '/' . $taxonomy ) ); } // wrap echo '
'; } } /** * description * * @type function * @date 8/10/13 * @since 5.0.0 * * @param $post_id (int) * @return $post_id (int) */ function edit_term( $term, $taxonomy ) { // vars $post_id = 'term_' . $term->term_id; // update vars $this->view = 'edit'; // get field groups $field_groups = acf_get_field_groups( array( 'taxonomy' => $taxonomy, ) ); // render if ( ! empty( $field_groups ) ) { acf_form_data( array( 'screen' => 'taxonomy', 'post_id' => $post_id, ) ); foreach ( $field_groups as $field_group ) { // title if ( $field_group['style'] === 'default' ) { echo '

' . acf_esc_html( acf_get_field_group_title( $field_group ) ) . '

'; } // fields echo ''; $fields = acf_get_fields( $field_group ); acf_render_fields( $fields, $post_id, 'tr', 'field' ); echo '
'; } } } /** * description * * @type function * @date 27/03/2015 * @since 5.1.5 * * @param $post_id (int) * @return $post_id (int) */ function admin_footer() { ?> 'taxonomy', 'post_id' => $post_id, 'render_ids' => array( current_action() === 'create_term' ? 'term_0/' . $taxonomy : $post_id ), 'screen' => array( 'taxonomy' => $taxonomy ), ) ); // valied and show errors acf_validate_save_post( true ); // save acf_save_post( $post_id ); } /** * description * * @type function * @date 15/10/13 * @since 5.0.0 * * @param $post_id (int) * @return $post_id (int) */ function delete_term( $term, $tt_id, $taxonomy, $deleted_term ) { // bail early if termmeta table exists if ( acf_isset_termmeta() ) { return $term; } // globals global $wpdb; // vars $search = $wpdb->esc_like( $taxonomy . '_' . $term . '_' ) . '%'; $_search = $wpdb->esc_like( '_' . $taxonomy . '_' . $term . '_' ) . '%'; // delete $result = $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->options WHERE option_name LIKE %s OR option_name LIKE %s", $search, $_search ) ); } } new acf_form_taxonomy(); endif; ?>