Customising Roll Tables with Filters


The Roll Tables that you can create with this plugin come with some handy features for customisation, so you can modify their display or other features as much as you need.

Firstly, the plugin comes with minimal CSS just to get the layout working, but all of the elements have their own classes and IDs so you can easily add your own CSS styles. Here's a tutorial on creating a responsive 2-column layout for your roll tables.

Secondly, and more importantly, the plugin comes with many filters that allow you to make changes to the text or display on the fly. Filters are the way that WordPress allows people to make changes to code without having to edit the actual plugin files.

Available Filters

All of the filters in TTRPG Roll Tables are prefixed with 'trt_'. Here is a complete list of the available filters and what they each do:

Do not use the plugin's CSS:

trt_use_plugin_css

Return: boolean
This is a boolean filter that defaults to true - simply force it to return false and the plugin's minimal CSS will not be used.

Modify the Roll Table title:

trt_roll_table_title 

Parameters: $table_id
Return: string
This filter allows you to modify the title of your Roll Tables on the fly. The ID of the table is passed as a parameter.

Modify the Roll Table description:

trt_roll_table_description 

Parameters: $table_id
Return: string
This filter allows you to modify the description of your Roll Tables on the fly. The ID of the table is passed as a parameter.

Modify the results as they are displayed:

trt_table_option 

Parameters: $table_id
Return: string
This filter runs on each table option after it has been fetched from the database. The option has already been processed and escaped, and you can use this to make changes like prepending or appending custom text or anything else you like. The ID of the table is passed as a parameter.

Modify the possible Roll Table dice notation options:

trt_dice_notation_options 

Return: array
This filter allows you to modify the array of dice notation options for Roll Tables. It only runs if a dice notation has not been specified in the Roll Table settings.

Modify the Roll Table dice notation display:

trt_roll_table_dice_notation 

Parameters: $table_id
Return: string
This filter runs after the dice notation for the Roll Table has been determined - either from the table settings or based on an automatic calculation. You can use it to modify the display of the dice notation on the fly. The ID of the table is passed as a parameter.

Do not show the Roll Table dice notation:

trt_show_dice_notation 

Parameters: $table_id
Return: boolean
You can use this filter to hide the dice notation on a Roll Table. It takes the table ID as a parameter.

Modify the Roll Table button text:

trt_roll_table_button_text 

Parameters: $table_id, $dice_notation
Return: string
This filter allows you to modify the text displayed on the Roll Table button - this will usually be something like "Roll d6". It takes the table ID and the dice notation as parameters.

Modify the "Rolling..." text:

trt_rolling_text

Return: string
This is the text that is briefly displayed after clicking the 'roll button', but before the result is displayed. You can use this filter to change the content of that text from "Rolling..." to anything you like.

Modify the error text:

trt_roll_error_text

Return: string
This is the text that is displayed if there is an error in the roll and no result can be displayed - unless something goes horribly wrong, this text is unlikely to show up for users. You can use this filter to change the content of that text from "Error - reload the page and roll again." to anything you like.


To use these filters you will need to use WordPress' add_filter() function, documented here. If there are additional filters you would like to see in the plugin please comment below and I'll see what I can do.

Files

ttrpg-roll-tables-complete-edition.zip 29 kB
Sep 03, 2023
ttrpg-roll-tables-starter-edition.zip 29 kB
Sep 03, 2023

Get TTRPG Roll Tables: WordPress Plugin

Download NowName your own price

Leave a comment

Log in with itch.io to leave a comment.