Skip to content

Add configurable Altmetric badge type via show_altmetric_type parameter#278

Merged
winkm89 merged 3 commits intowinkm89:masterfrom
epikentros:feature/altmetric-badge-type
Apr 11, 2026
Merged

Add configurable Altmetric badge type via show_altmetric_type parameter#278
winkm89 merged 3 commits intowinkm89:masterfrom
epikentros:feature/altmetric-badge-type

Conversation

@epikentros
Copy link
Copy Markdown
Contributor

@epikentros epikentros commented Mar 20, 2026

Summary

This PR adds a new shortcode parameter show_altmetric_type to all publication list shortcodes (tplist, tpcloud, tpsearch), allowing users to choose which Altmetric badge type to display instead of being
limited to a hardcoded type.

Problem

The Altmetric embed API supports multiple badge types (donut, medium-donut, large-donut, bar, medium-bar, large-bar, 1, 4), as documented at https://badge-docs.altmetric.com/customizations.html#badge-types

Previously, teachPress had the badge type hardcoded (large-donut and medium-donut), with no way to change it without modifying the plugin core directly.

Changes

core/publications/templates.php

  • prepare_altmetric(): added $altm_type parameter with default value 'large-donut' for backward compatibility; applied esc_attr() to both $doi and $altm_type for consistency with WordPress coding
    standards; removed unused $doi_url variable (dead code)
  • get_infocontainer(): badge type now resolved from show_altmetric_type setting, with fallback to 'large-donut' when not set
  • get_images(): same badge type logic applied to the donut/image-area rendering path; removed unused $altmetric_type variable

core/shortcodes.php

  • show_altmetric_type parameter added to all shortcode definitions (tp_publist_shortcode, tp_cloud_shortcode, tp_list_shortcode, tp_search_shortcode)
  • Parameter sanitised with sanitize_key(), appropriate for the accepted values (lowercase strings and hyphens)
  • Docblock updated to document the new parameter; fixed a pre-existing typo show_altmetric_entrxshow_altmetric_entry
  • Removed an incorrect $count++ block that referenced a non-existent show_dimensions_type setting, which was incorrectly inflating the colspan calculation

Backward Compatibility

Fully backward compatible. When show_altmetric_type is not set, behaviour is identical to the previous version.

Usage example

[tplist show_altmetric_entry="1" show_altmetric_type="large-donut"]
[tplist show_altmetric_donut="1" show_altmetric_type="medium-donut"]

@winkm89 winkm89 merged commit d990d5b into winkm89:master Apr 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants