Salary Calculator
WordPress plugin: cross-country salary comparison widget with custom tables, REST API and CSV import
by Alex Mochulskyi · github.com/alexskybrain/wp-salary-calculator
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/alexskybrain/wp-salary-calculator/archive/refs/heads/main.zipA WordPress plugin that compares salaries for a role across countries against a base region, and renders the comparison as an interactive widget on the front end.
Built as a production plugin: it owns its own database schema, exposes a small read-only REST API for the front end, and keeps all editing behind a nonce-protected admin screen.
What it does
- Stores roles, countries and the salary matrix in three custom tables instead of overloading options or post meta.
- Renders on any page or post through the
[salary_calculator]shortcode. - Serves data to the front end over REST, so the widget updates without a page reload.
- Lets an administrator manage roles, seniority levels, countries and the salary matrix from a single admin screen.
- Imports the salary matrix from CSV for bulk updates.
- Calculates the saving percentage between the selected country and the base region on the server side.
Requirements
- WordPress 6.0+
- PHP 8.0+
Installation
- Copy the plugin folder into
wp-content/plugins/. - Activate it in Plugins. Activation creates the tables and seeds the default options.
- Open Salary Calculator in the admin menu and add roles, countries and salary rows, or import a CSV.
- Place
[salary_calculator]on a page.
Database schema
Created with dbDelta() on activation and re-checked on admin_init through a stored schema version, so updates do not require deactivating the plugin.
| Table | Purpose |
|---|---|
{prefix}salary_roles |
Role name and role type, unique by name |
{prefix}salary_countries |
Country list with sort order, unique by name |
{prefix}salary_data |
Salary matrix, unique by role + seniority + country |
REST API
Namespace salary-calculator/v1, read-only and public because the widget is public. Responses are sent with a one-hour Cache-Control header.
GET /wp-json/salary-calculator/v1/options
GET /wp-json/salary-calculator/v1/salary?role=…&seniority=…&country=…
/options returns roles, role types, seniority levels, countries, the base region label and the "updated" date. /salary returns both salaries and the calculated saving percentage, or a 404 payload when the combination has no data.
Notes on implementation
- Every REST argument is declared with
sanitize_callback, and the salary lookup runs through$wpdb->prepare(). - Every admin write goes through
check_admin_referer(), delete links are built withwp_nonce_url()and verified before running, and the screens are gated behindcurrent_user_can('manage_options'). uninstall.phpremoves the tables and options, so the plugin does not leave rows behind.- The "updated" label can follow the current month, the last data change, or a manually set string.
CSV format
role,seniority,country,country_salary,base_salary,role_type
Facebook Ads Manager,Middle,US,85000,32000,standard
sample-data.csv in the repository is an illustrative sample, not real market data.
License
MIT — see LICENSE.