Clanbite Since 1.6.3
class Player_MediaLets a player choose which part of their avatar and cover image is shown, and go back to the defaults.
The position is a focal point (x, y, 0 to 1, the same meaning as CSS object-position percentages and the Cover block's focal point) and a zoom (1 to 4).
- **Cover:** the full image is kept; the position and zoom are stored (
cp_player_cover_position_x/y,cp_player_cover_zoom) and applied when the cover is drawn (object-positionplus a scale around the focal point). - **Avatar:** avatars are drawn in many places from a plain image address, so the chosen part is cut out of the original as a square and saved as the avatar (
cp_player_avatar_id). The original stays ascp_player_avatar_source_idso the position can be changed later.
Both are saved by the normal player settings save (clanbite_save_player_settings) through these form fields: profile_avatar_focal_x, profile_avatar_focal_y, profile_avatar_zoom, profile_avatar_remove, profile_cover_position_x, profile_cover_position_y, profile_cover_zoom and profile_cover_remove.
class final
- Full name
Kernowdev\Clanbite\Extensions\Players\Player_Media
Constants
| Name | Value | Description |
|---|---|---|
MAX_ZOOM | 4.0 | Largest zoom a player can choose. |
AVATAR_SIZE | 512 | Edge length in pixels of the avatar square that is cut from the original. |
Methods
add_success_data()State of the media editor after a save, so the page can update its previews.bake_avatar()Cut the chosen square out of the original avatar and make it the avatar.clamp_focal()Clamp a focal coordinate to 0..1.clamp_zoom()Clamp a zoom to 1..MAX_ZOOM.crop_square()The square, in source pixels, that is shown for a focal point and zoom.editor_state()Everything the position editor needs to know about a player's images.register_meta()Register the user meta this class stores.register_new_avatar_source()Called by the Players extension right after a new avatar file was stored: it is the original, so keep it and reset the position.register()Register hooks.remove_avatar()Remove the player's avatar (original and cut-out) and go back to the default.remove_cover()Remove the player's cover image and its position, and go back to the default.save_media_settings()Save handler: remove flags, avatar position, cover zoom.version_avatar_url()Add the avatar's attachment ID to its address as ver, so a browser or cache never shows a previous cut-out of the same picture.
Defined in inc/extensions/players/class-player-media.php
Changelog
| Version | Description |
|---|---|
| 1.6.3 | Introduced. |