PHP Templates
PaidCommunities gives you the ability to modify the templates provided in the PHP SDK used to render UI elements like the license activation screen.
Available Templates
Currently, PaidCommunities offers one customizable template:
- license.php - Controls the license activation form that appears in your plugin's admin area
Creating a Custom License Template
Step 1: Create a template directory
First, create a dedicated directory within your plugin to store your customized template:
# Navigate to your plugin directory
cd /path/to/your-plugin
# Create a custom templates directory
mkdir -p custom-templates
Step 2: Copy the license template
Copy the license template from the PaidCommunities SDK to your custom templates directory:
# Copy just the license template
cp vendor/paidcommunities/wordpress-sdk/src/WordPress/src/Admin/Views/license.php custom-templates/
This copies only the license.php file, which is currently the only customizable template.
Step 3: Modify the license template
Open the template file in your code editor and make your desired changes. Here's an example of customizing the license.php template:
<div class="PaidCommunitiesLicense-settings">
<div class="PaidCommunitiesGrid-root">
<div class="PaidCommunitiesGrid-item">
<div class="PaidCommunitiesStack-root LicenseKeyOptionGroup">
<label class="PaidCommunitiesLabel-root"><?php esc_html_e( 'License Key', 'paidcommunities' ) ?></label>
<!-- Added custom description -->
<p class="license-description">
<?php esc_html_e('This is the license key from your order. Enter it below to activate premium features and updates.', 'awesome-seo')?>
</p>
<div class="PaidCommunitiesInputBase-root LicenseStatus-<?php echo esc_attr($license->getStatus()) ?>">
<?php if ( $license->isRegistered() ): ?>
<input id="<?php echo esc_attr( $name ) ?>-license_key"
class="PaidCommunitiesInput-text LicenseKey"
type="text"
disabled
value="<?php echo esc_attr( $license->getLicenseKey() ) ?>"/>
<?php else: ?>
<input id="<?php echo esc_attr( $name ) ?>-license_key"
class="PaidCommunitiesInput-text LicenseKey"
type="text"
placeholder="<?php esc_attr_e('Enter your license key here', 'awesome-seo') ?>"/>
<?php endif ?>
</div>
<?php if ( $license->isRegistered() ): ?>
<button class="button PaidCommunitiesButton-root DeactivateLicense"
data-paidcommunities-props="<?php echo $data ?>">
<?php esc_html_e( 'Deactivate License', 'paidcommunities' ) ?>
</button>
<?php else: ?>
<button class="button PaidCommunitiesButton-root ActivateLicense"
data-paidcommunities-props="<?php echo $data ?>">
<?php esc_html_e( 'Activate License', 'paidcommunities' ) ?>
</button>
<?php endif ?>
</div>
</div>
</div>
</div>
In this example, we've added a descriptive paragraph below the license key label to help users understand the purpose of the license key field.
Step 4: Register your custom templates path
To use your custom template, you need to tell PaidCommunities where to find it. Add the template_path parameter when initializing the PluginConfig class:
// Initialize PaidCommunities with custom templates
new \PaidCommunities\WordPress\PluginConfig(
__FILE__,
'prd_80y2N3N2L11O2ee1', // Your product ID
[
'template_path' => plugin_dir_path( __FILE__ ) . 'custom-templates',
// Other configuration options...
]
);
Understanding License Template Variables
The license.php template has access to these specific variables:
| Variable | Type | Description |
|---|---|---|
$license | License | License object with methods like getStatus(), isRegistered(), getLicenseKey() |
$name | string | Field name identifier used for form inputs |
$data | string | JSON-encoded data for JavaScript interactions |
Common Customizations
Here are some typical modifications you might want to make to the license template:
Adding descriptive text
<label class="PaidCommunitiesLabel-root"><?php esc_html_e( 'License Key', 'paidcommunities' ) ?></label>
<p class="license-description"><?php esc_html_e('Enter your license key to unlock premium features', 'awesome-seo')?></p>
Customizing the input placeholder
<input id="<?php echo esc_attr( $name ) ?>-license_key"
class="PaidCommunitiesInput-text LicenseKey"
type="text"
placeholder="<?php esc_attr_e('XXXX-XXXX-XXXX-XXXX', 'awesome-seo') ?>"/>
Changing button text
<button class="button PaidCommunitiesButton-root ActivateLicense"
data-paidcommunities-props="<?php echo $data ?>">
<?php esc_html_e( 'Unlock Premium Features', 'awesome-seo' ) ?>
</button>
Adding license status information
<?php if ( $license->isRegistered() ): ?>
<div class="license-status-info">
<p>
<strong><?php esc_html_e('Status:', 'awesome-seo') ?></strong>
<span class="license-status-<?php echo esc_attr($license->getStatus()) ?>">
<?php echo esc_html(ucfirst($license->getStatus())) ?>
</span>
</p>
</div>
<?php endif; ?>
Adding Custom CSS for the License Form
You can enhance your license form with custom CSS:
add_action('admin_enqueue_scripts', function($hook) {
wp_enqueue_style(
'awesome-seo-license-styles',
plugin_dir_url(__FILE__) . 'assets/css/license-form.css',
[],
'1.0.0'
);
});
Example CSS in your license-form.css file:
.PaidCommunitiesLabel-root {
font-weight: 600;
font-size: 16px;
}
.license-description {
margin-top: 5px;
margin-bottom: 15px;
color: #666;
font-style: italic;
}
.PaidCommunitiesButton-root {
background-color: #0073aa !important;
color: white !important;
border-color: #0073aa !important;
}
.PaidCommunitiesButton-root:hover {
background-color: #005177 !important;
}
.LicenseStatus-active .PaidCommunitiesInput-text {
border-color: #46b450 !important;
background-color: rgba(70, 180, 80, 0.05) !important;
}
Best Practices for Template Customization
-
Version Control: Keep track of your modified template in version control to manage changes over time.
-
Proper Escaping: Always use WordPress escaping functions (
esc_html_e(),esc_attr(), etc.) for security. -
Internationalization: Ensure all user-facing text is properly internationalized with translation functions.
-
Testing: Test your template changes across different WordPress versions, themes, and with different license statuses (active, inactive, etc.).
Troubleshooting
If your custom license template isn't being loaded:
- Verify the path is correct in your configuration
- Check file permissions (the template should be readable)
- Ensure the template filename is exactly
license.php(case-sensitive)
Complete Integration Example
For a complete example of integrating the PHP SDK including template customization, check out our WordPress plugin example. This tutorial shows you how to integrate the PHP SDK, render the license activation field, and implement custom templates.