save custom term – hook create_term doesn’t work

Question

i’m trying to save a custom term with my own informations.

i tried the hooks:
– create_term
– created_term
– create_{my_taxonomy}

but nothing seems to work.

when I save the term, it’s only getting saved with the default wordpress informations.
When I then edit the term, the hook
– edit_term
works finde!

actually I have no idea, why the create_term is not fired.
is there anything else to do or any other hook.
or is it a problem, that wordpress saves the term by ajax?

here a code snipped of how i use the hook

if ( ! defined ( 'ABSPATH' ) ) {
    exit;
}

class my_term_class {
    public function __construct() {
        add_action( 'create_term', array( $this, 'save_my_fields' ), 10, 3 ); 
        add_action( 'edit_term', array( $this, 'save_my_fields' ), 10, 3 );
        //...
    }

    public function save_my_fields( $term_id, $tt_id = '', $taxonomy = '' ) {
        write_log("this log is only written by edit_term!");
        //...
    }
}
new my_term_class();

Edit:
I created a brand new taxonomie to my post type. but still the same problem.

here the Code I create the taxonomie:

        register_taxonomy("cstesttaxonomy", 
        array('myposttype'),
        array(
            "label"             => _n('Testtaxonomie', 'Testtaxonomies', 2, 'cs-poedit'),
            'public'            => false,
            'labels' => array(
                'name'          => _n('Testtaxonomie', 'Testtaxonomies', 2, 'cs-poedit'),
                'sigular_name'  => _n('Testtaxonomie', 'Testtaxonomies', 1, 'cs-poedit'),
                'menu_name'     => _n('Testtaxonomie', 'Testtaxonomies', 1, 'cs-poedit'),
                'edit_item'     => __('Edit testtax', 'cs-poedit'),
                'view_item'     => __('View testtax', 'cs-poedit'),
                'update_item'   => __('Update testtax', 'cs-poedit'),
                'add_new_item'  => __('Add new testtax', 'cs-poedit'),
                //                     'new_item_name' => 'Optionsbezeichnung',
                'popular_items' => NULL,
            ),
            "hierarchical"      => false,
            "singular_label"    => _n('Testtaxonomie', 'Testtaxonomies', 1, 'cs-poedit'),
            'rewrite'           => true,
            'show_ui'           => true,

            'show_in_nav_menus'  => true,
            'show_admin_column' => true,
        )
    ); 

than I add the administration view for this taxonomie to my admin menu:

private function initAdminHooks() {
    add_action( 'admin_menu', array($this, 'initAdminMenu'));
}

public function initAdminMenu() {
    add_menu_page('MyMenu', 'MyMenu', 'edit_posts', 'cs_mymenu', 'show', plugins_url('myplugin/myicon_16x16.ico'), 3);
    //...
    add_submenu_page('cs_mymenu', _n('TestTax', 'TestTax', 2, 'cs-poedit'),_n('TestTax', 'TestTaxes', 2, 'cs-poedit'), 'manage_options', 'edit-tags.php?taxonomy=cstesttaxonomy&post_type=myposttype', false);
}   

and then in the administration view I want to add a new taxonomie and when the taxonomie is beeing saved, i want to write a log (if that works, i want to add own fields to the taxonomie and save custom values to a custom database table)

and my class to do that and handle the save method is:

if ( ! defined ( 'ABSPATH' ) ) {
    exit;
}

class RS_IB_MyTest {

public function mytest1( $term_id = 0, $tt_id ='') {
    write_log("Stest1");
}
public function mytest2( $term_id, $tt_id ='',$asd = '' ) {
    write_log("Stest2");
}        

public function __construct() {
    write_log("construct");
    add_action( 'create_cstesttaxonomy', array($this, 'mytest1'), 10, 2 );        

    add_action( 'edit_term', array( $this, 'mytest2' ), 10, 3 );
}
}
new RS_IB_MyTest();

but still, only the method from the “edit_term” hook is fired correctly.

0
, Carsten Schmitt 4 years 2020-03-25T08:51:00-05:00 0 Answers 103 views 0

Leave an answer

Browse
Browse