Skip to content

Instantly share code, notes, and snippets.

@lelandf
Last active August 25, 2021 22:28
Show Gist options
  • Save lelandf/6cc632393c8885141be1578d2234bc9f to your computer and use it in GitHub Desktop.
Save lelandf/6cc632393c8885141be1578d2234bc9f to your computer and use it in GitHub Desktop.
obscure LearnDash license key (no jQuery)
<?php
/*
* Snippet provided as-is with no warranty and no support.
* Not an ironclad way of preventing license key exposure. Note word "obscure."
* Test on staging/development environment to ensure needs are met prior to applying to production
* Inspired by https://gist.github.com/rali14/3407a1b3efe149cfa3f17caff8743eda
*/
function leland_learndash_obscure_license_key() {
?>
<script>
function lelandLearnDashObscureLicenseKey() {
const ldLicenseKeyInputs = document.querySelectorAll('input[name="nss_plugin_license_sfwd_lms"]');
if ( ! ldLicenseKeyInputs ) {
// Go away if no license keys detected
return;
}
for ( const input of ldLicenseKeyInputs ) {
// Obscuring of license key occurs here.
// Do NOT submit license key form again otherwise a bunch of asterisks will be submitted instead of a valid license key
input.value = '*********';
}
}
lelandLearnDashObscureLicenseKey();
</script>
<?php
}
add_action( 'admin_footer', 'leland_learndash_obscure_license_key' );
@lelandf
Copy link
Author

lelandf commented Aug 25, 2021

Consider altering line 13 if ProPanel license is applicable...

const ldLicenseKeyInputs = document.querySelectorAll('input[name="nss_plugin_license_sfwd_lms"], input[name="nss_plugin_license_learndash_propanel"]');

Can't imagine how it could hurt to add that even if ProPanel is not active on the site although haven't tested yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment