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 action hook can be used to add the HTML code for your custom fields. This hook is triggered by the core plugin just above the “Save Record” button.
slm_add_edit_interface_above_submit
Code Example:
add_action('slm_add_edit_interface_above_submit', 'my_custom_output'); function my_custom_output($data){ $row_id = $data['row_id']; $key = $data['key']; //TODO - echo something here echo 'My Custom Field: <input type="text" name="my_test_field" value="...." />'; }
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.
slm_add_edit_interface_save_submission
or
slm_add_edit_interface_save_record_processed
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.
@Rodrigo Souza, Thank you for pointing this out. The code was changed in the plugin but this page didn’t get updated. I have just updated it.
The example for ‘slm_add_edit_interface_above_submit’ is wrong. The action in plugin dispatch only 1 parameter, not 2 (only $data) and the hook is an action not a filter.
This should be:
//hook
add_action(‘slm_add_edit_interface_above_submit’, ‘my_custom_output’, 10, 1);
//funcion
function my_custom_output($data){
…
echo “something”
}
Checked in 4.5.3 slm plugin version
@Michel, Thank you. I have corrected it.
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);