Skip to content

How to Use the New Shortcodes and Blocks

Michel edited this page Dec 6, 2024 · 2 revisions

Shortcodes:

  1. Forgot License: [slm_forgot_license]

    • Displays a form where users can enter their email to retrieve license information.
    • Can be added to any page or post manually.
  2. List Licenses: [slm_list_licenses]

    • Dynamically displays a table of licenses associated with the logged-in user.
    • Useful for pages where users manage their licenses.

Blocks:

  1. Forgot License Block:
    • Found under the "SLM Plus" category in the block editor.
    • Provides an interactive form preview in the editor.
    • On the frontend, renders the [slm_forgot_license] shortcode.

Custom Hooks for SLM Plus

The following hooks allow developers to customize various aspects of the plugin's functionality, such as error messages, email content, and form labels. These hooks provide flexibility while maintaining the core functionality.

1. slm_invalid_email_message

Purpose: Customize the error message displayed when the user enters an invalid email address in the "Forgot License" form.

Default Message:

"Invalid email address."

Example Usage:

add_filter('slm_invalid_email_message', function($message) {`
    `return '<p style="color: red;">The email address you entered is not valid. Please try again.</p>';`
`});

2. slm_success_message

Purpose:

Modify the success message displayed after the user successfully submits the "Forgot License" form and licenses are emailed.

Default Message:

"Your licenses have been sent to your email."

Example Usage:

add_filter('slm_success_message', function($message) {`
    `return '<p style="color: green;">Check your inbox! We have sent your licenses to your registered email address.</p>';`
`});

3. slm_no_license_message

Purpose:

Change the message displayed when no licenses are found for the provided email address.

Default Message:

"No licenses found for the provided email."

Example Usage:

add_filter('slm_no_license_message', function($message) {`
    `return '<p style="color: orange;">Sorry, we couldn’t find any licenses associated with this email. Please check and try again.</p>';`
`});

4. slm_license_email_message

Purpose:

Modify the body of the email sent to users after they request their licenses.

Default Message:

A list of licenses formatted as plain text.

Example Usage:

add_filter('slm_license_email_message', function($message, $licenses) {`
    `$customMessage = "Here are your licenses:\n\n";`
    `foreach ($licenses as $license) {`
        `$customMessage .= "License Key: {$license['license_key']}\n";`
        `$customMessage .= "Product: {$license['product_ref']}\n";`
        `$customMessage .= "Status: {$license['lic_status']}\n";`
        `$customMessage .= "Expiry Date: {$license['date_expiry']}\n\n";`
    `}`
    `return $customMessage;`
`}, 10, 2);

5. slm_license_email_subject

Purpose:

Customize the subject line of the email sent to users after they request their licenses.

Default Subject:

"Your Licenses"

Example Usage:

add_filter('slm_license_email_subject', function($subject) {`
    `return 'Your Requested License Keys';`
`});

6. slm_form_label

Purpose: Customize the label text for the email input field in the "Forgot License" form.

Default Label:

"Enter your email address:"

Example Usage:

add_filter('slm_form_label', function($label) {
    return 'Please provide your registered email to retrieve licenses:';
});

7. slm_form_button_text

Purpose: Customize the text displayed on the submit button in the "Forgot License" form.

Default Text:

"Retrieve License"

Example Usage:

add_filter('slm_form_button_text', function($buttonText) {
    return 'Send License Information';
});

Usage Notes

Add the examples to your theme’s functions.php file or a custom plugin to apply these customizations. Each hook has been designed to be simple and easy to use, allowing you to adapt the plugin to specific requirements without modifying the core plugin files. By leveraging these hooks, you can fully customize the "Forgot License" form and email messages to match your branding and user experience needs.