term_meta = $term_meta; } public function register(): void { // Priority 25: after taxonomies (10) and our meta registrars (20), // so Taxonomies::supported() sees every registered taxonomy. add_action( 'init', array( $this, 'register_taxonomy_hooks' ), 25 ); add_action( 'edited_term', array( $this, 'save' ), 10, 3 ); } public function register_taxonomy_hooks(): void { foreach ( Taxonomies::supported() as $taxonomy ) { add_action( "{$taxonomy}_edit_form_fields", array( $this, 'render' ) ); } } public function render( \WP_Term $term ): void { wp_nonce_field( self::NONCE_ACTION, self::NONCE_FIELD ); $title = (string) $this->term_meta->get( $term->term_id, TermMetaFields::TITLE ); $description = (string) $this->term_meta->get( $term->term_id, TermMetaFields::DESCRIPTION ); printf( '

%3$s

', esc_html__( 'SEO title (Acez SEO AI)', 'acez-seo' ), esc_attr( $title ), esc_html__( 'The title of this term\'s archive page in search results. Leave blank to use the default.', 'acez-seo' ) ); printf( '

%3$s

', esc_html__( 'Meta description (Acez SEO AI)', 'acez-seo' ), esc_textarea( $description ), esc_html__( 'The meta description of this term\'s archive page. Leave blank to use the term description.', 'acez-seo' ) ); } public function save( int $term_id, int $tt_id, string $taxonomy ): void { if ( ! isset( $_POST[ self::NONCE_FIELD ] ) ) { return; } $nonce = sanitize_text_field( wp_unslash( $_POST[ self::NONCE_FIELD ] ) ); if ( ! wp_verify_nonce( $nonce, self::NONCE_ACTION ) ) { return; } if ( ! in_array( $taxonomy, Taxonomies::supported(), true ) ) { return; } $taxonomy_object = get_taxonomy( $taxonomy ); if ( false === $taxonomy_object || ! current_user_can( $taxonomy_object->cap->edit_terms ) ) { return; } $this->term_meta->update( $term_id, TermMetaFields::TITLE, isset( $_POST['acez_seo_term_title'] ) ? sanitize_text_field( wp_unslash( $_POST['acez_seo_term_title'] ) ) : '' ); $this->term_meta->update( $term_id, TermMetaFields::DESCRIPTION, isset( $_POST['acez_seo_term_description'] ) ? sanitize_textarea_field( wp_unslash( $_POST['acez_seo_term_description'] ) ) : '' ); } }