lseif ( $this->is_term_edit ) { $term_id = Param::request( 'tag_ID', 0, FILTER_VALIDATE_INT ); $metas = get_metadata( 'term', $term_id ); } if ( empty( $metas ) ) { return []; } $json = []; foreach ( $metas as $meta_key => $meta_value ) { if ( Str::starts_with( '_', $meta_key ) || Str::starts_with( 'rank_math_', $meta_key ) ) { continue; } $json[ $meta_key ] = $meta_value[0]; } return $json; } /** * Get custom taxonomies. * * @return array */ private function get_custom_taxonomies() { $taxonomies = get_post_taxonomies( $this->args->ID ); if ( empty( $taxonomies ) ) { return []; } $json = []; foreach ( $taxonomies as $taxonomy ) { if ( in_array( $taxonomy, [ 'category', 'post_tag' ], true ) ) { continue; } $name = ucwords( str_replace( [ '_', '-' ], ' ', $taxonomy ) ); /* translators: Taxonomy name. */ $title = sprintf( __( '%s Title', 'seo-by-rank-math' ), $name ); /* translators: Taxonomy name. */ $desc = sprintf( __( '%s Description', 'seo-by-rank-math' ), $name ); $this->register_replacement( "term_{$taxonomy}", [ 'name' => $title, 'description' => esc_html__( 'Custom Term title.', 'seo-by-rank-math' ), 'variable' => "customterm({$taxonomy})", 'example' => $title, ], [ $this, 'get_custom_term' ] ); $this->register_replacement( "term_{$taxonomy}_desc", [ 'name' => $desc, 'description' => esc_html__( 'Custom Term description.', 'seo-by-rank-math' ), 'variable' => "customterm_desc({$taxonomy})", 'example' => $desc, ], [ $this, 'get_custom_term_desc' ] ); $term = $this->get_custom_term( $taxonomy ); $term_desc = $this->get_custom_term_desc( $taxonomy ); $json[ $taxonomy ] = $term ? $term : $title; $json[ "{$taxonomy}_desc" ] = $term_desc ? $term_desc : $desc; } return $json; } }