Adding Your Own Custom Fields in the Software License Manager Plugin

This is a tutorial for the Software License Manger plugin. This tutorial is aimed at advanced WordPress Plugin developers.

Lets say, you want to create an extension or a custom plugin to add couple of extra fields to save some info with each of the license keys. Below is a guideline on how to do it.

Decide Where You Will Save the Data

You need to first decide where this extra data will be saved. There are 3 choices:

1) Alter the License Key Table

When your custom plugin/extension is activated, you would alter the core plugin’s license key database table (wp_lic_key_tbl) and add the new columns.

2) Create Your Own Custom Table

You can create your own custom database table to store the values. Each license key has a unique ID that identifies the key in the license keys table of the core plugin. In your new table, you need to have a column to store that unique ID of the license key. That will allow you to connect each row of your table to a license key.

3) Use Custom Post Types

You can also create your own Custom Post Types and store the custom values there.

The key element to understand is that you need to use the unique ID of the keys to connect your custom data to a license key.

Show the Fields in the Add/Edit Licenses Interface

The following filter can be used to add the HTML code for your custom fields. This filter is triggered by the core plugin just above the “Save Record” button.


Code Example:

add_filter('slm_add_edit_interface_above_submit', 'my_custom_output', 10, 2);
function my_custom_output($output, $data){
    $row_id = $data['row_id'];
    $key = $data['key'];
    //TODO - query to retrieve your extra data so you can create the HTML output here.
    $output .= 'My Custom Field: <input type="text" name="my_test_field" value="...." />';

    return $output;

Save the Custom Data When a License Key is Saved

You can use any of the following two action hooks to listen for the form submission then read the values from the REQUEST parameter and save the custom data.




Code Example:

add_action('slm_add_edit_interface_save_record_processed', 'save_my_custom_data');
function save_my_custom_data($data){
    $row_id = $data['row_id'];
    $key = $data['key'];
    //TODO - read your custom data from the REQUEST parameter and save it.

That should do it. Your custom plugin/extension can now add, edit and show extra custom fields for each license key.

Comments (2 responses)

  1. admin says:

    @Michel, Thank you. I have corrected it.

  2. Michel Velis says:

    there is a syntax error on:

    add_filter(‘slm_add_edit_interface_above_submit, ‘my_custom_output’, 10, 2);

    missing ‘ after slm_add_edit_interface_above_submit. should be

    add_filter(‘slm_add_edit_interface_above_submit’, ‘my_custom_output’, 10, 2);

Speak Your Mind