: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
var $primaryCta = $('.fs-actions .button.button-primary'),
primaryCtaLabel = $primaryCta.html(),
$form = $('.fs-actions form'),
isNetworkActive = <?php echo $is_network_level_activation ? 'true' : 'false' ?>,
requireLicenseKey = <?php echo $require_license_key ? 'true' : 'false' ?>,
hasContextUser = <?php echo $activate_with_current_user ? 'true' : 'false' ?>,
isNetworkUpgradeMode = <?php echo $is_network_upgrade_mode ? 'true' : 'false' ?>,
$licenseKeyInput = $('#fs_license_key'),
pauseCtaLabelUpdate = false,
isNetworkDelegating = false,
* @author Leo Fajardo (@leorw)
resetLoadingMode = function() {
$primaryCta.html(primaryCtaLabel);
$primaryCta.prop('disabled', false);
$( '.fs-loading' ).removeClass( 'fs-loading' );
console.log('resetLoadingMode - Primary button was enabled');
setLoadingMode = function () {
$( document.body ).addClass( 'fs-loading' );
$('.fs-actions .button').on('click', function () {
if ( ! requireLicenseKey || ! $marketingOptin.hasClass( 'error' ) ) {
$this.attr('disabled', 'disabled');
$multisiteOptionsContainer = $( '.fs-multisite-options-container' ),
$allSitesOptions = $( '.fs-all-sites-options' ),
$applyOnAllSites = $( '.fs-apply-on-all-sites-checkbox' ),
$sitesListContainer = $( '.fs-sites-list-container' ),
totalSites = <?php echo count( $sites ) ?>,
maxSitesListHeight = null,
$skipActivationButton = $( '#skip_activation' ),
$delegateToSiteAdminsButton = $( '#delegate_to_site_admins' ),
hasAnyInstall = <?php echo ! is_null( $fs->find_first_install() ) ? 'true' : 'false' ?>;
$applyOnAllSites.click(function() {
var isChecked = $( this ).is( ':checked' );
$multisiteOptionsContainer.find( '.action' ).removeClass( 'selected' );
updatePrimaryCtaText( 'allow' );
$multisiteOptionsContainer.find( '.action-allow' ).addClass( 'selected' );
$skipActivationButton.toggle();
$delegateToSiteAdminsButton.toggle();
$multisiteOptionsContainer.toggleClass( 'fs-apply-on-all-sites', isChecked );
$sitesListContainer.toggle( ! isChecked );
if ( ! isChecked && null === maxSitesListHeight ) {
* Set the visible number of rows to 5 (5 * height of the first row).
* @author Leo Fajardo (@leorw)
maxSitesListHeight = ( 5 * $sitesListContainer.find( 'tr:first' ).height() );
$sitesListContainer.css( 'max-height', maxSitesListHeight );
$allSitesOptions.find( '.action' ).click(function( evt ) {
var actionType = $( evt.target ).data( 'action-type' );
$multisiteOptionsContainer.find( '.action' ).removeClass( 'selected' );
$multisiteOptionsContainer.find( '.action-' + actionType ).toggleClass( 'selected' );
updatePrimaryCtaText( actionType );
$sitesListContainer.delegate( 'td:not(:first-child)', 'click', function() {
// If a site row is clicked, trigger a click on the checkbox.
$( this ).parent().find( 'td:first-child input' ).click();
$sitesListContainer.delegate( '.action', 'click', function( evt ) {
var $this = $( evt.target );
if ( $this.hasClass( 'selected' ) ) {
$this.parents( 'tr:first' ).find( '.action' ).removeClass( 'selected' );
$this.toggleClass( 'selected' );
singleSiteActionType = $this.data( 'action-type' ),
totalSelected = $sitesListContainer.find( '.action-' + singleSiteActionType + '.selected' ).length;
$allSitesOptions.find( '.action.selected' ).removeClass( 'selected' );
if ( totalSelected === totalSites ) {
$allSitesOptions.find( '.action-' + singleSiteActionType ).addClass( 'selected' );
updatePrimaryCtaText( singleSiteActionType );
updatePrimaryCtaText( 'mixed' );
if ( isNetworkUpgradeMode || hasAnyInstall ) {
$skipActivationButton.click(function(){
$delegateToSiteAdminsButton.hide();
$skipActivationButton.html('<?php fs_esc_js_echo_inline( 'Skipping, please wait', 'skipping-wait', $slug ) ?>...');
pauseCtaLabelUpdate = true;
// Check all sites to be skipped.
$allSitesOptions.find('.action.action-skip').click();
pauseCtaLabelUpdate = false;
$delegateToSiteAdminsButton.click(function(){
$delegateToSiteAdminsButton.html('<?php fs_esc_js_echo_inline( 'Delegating, please wait', 'delegating-wait', $slug ) ?>...');
pauseCtaLabelUpdate = true;
* Set to true so that the form submission handler can differentiate delegation from license
* activation and the proper AJAX action will be used (when delegating, the action should be
* `network_activate` and not `activate_license`).
* @author Leo Fajardo (@leorw)
isNetworkDelegating = true;
// Check all sites to be skipped.
$allSitesOptions.find('.action.action-delegate').click();
pauseCtaLabelUpdate = false;
* Set to false so that in case the previous AJAX request has failed, the form submission handler
* can differentiate license activation from delegation and the proper AJAX action will be used
* (when activating a license, the action should be `activate_license` and not `network_activate`).
* @author Leo Fajardo (@leorw)
isNetworkDelegating = false;
* @author Leo Fajardo (@leorw)
function updatePrimaryCtaText( actionType ) {
var text = '<?php fs_esc_js_echo_inline( 'Continue', 'continue', $slug ) ?>';
text = '<?php fs_esc_js_echo_inline( 'Allow & Continue', 'opt-in-connect', $slug ) ?>';
text = '<?php fs_esc_js_echo_inline( 'Delegate to Site Admins & Continue', 'delegate-to-site-admins-and-continue', $slug ) ?>';
text = '<?php fs_esc_js_echo_x_inline( 'Skip', 'verb', 'skip', $slug ) ?>';
$primaryCta.html( text );
var ajaxOptin = ( requireLicenseKey || isNetworkActive );
$form.on('submit', function () {
var $extensionsPermission = $( '#fs_permission_extensions .fs-switch' ),
isExtensionsTrackingAllowed = ( $extensionsPermission.length > 0 ) ?
$extensionsPermission.hasClass( 'fs-on' ) :
var $diagnosticPermission = $( '#fs_permission_diagnostic .fs-switch' ),
isDiagnosticTrackingAllowed = ( $diagnosticPermission.length > 0 ) ?
$diagnosticPermission.hasClass( 'fs-on' ) :
if ( null === isExtensionsTrackingAllowed ) {
$( 'input[name=is_extensions_tracking_allowed]' ).remove();
$( 'input[name=is_extensions_tracking_allowed]' ).val( isExtensionsTrackingAllowed ? 1 : 0 );
// We are not showing switch to enable/disable diagnostic tracking while activating free version. So, don't remove hidden `is_diagnostic_tracking_allowed` element from DOM and change the value only if switch is available.
if ( null !== isDiagnosticTrackingAllowed ) {
$( 'input[name=is_diagnostic_tracking_allowed]' ).val( isDiagnosticTrackingAllowed ? 1 : 0 );
* @author Vova Feldman (@svovaf)
if (!hasContextUser || isNetworkUpgradeMode) {
if ( requireLicenseKey && ! isNetworkDelegating ) {
action = '<?php echo $fs->get_ajax_action( 'activate_license' ) ?>';
security = '<?php echo $fs->get_ajax_security( 'activate_license' ) ?>';
action = '<?php echo $fs->get_ajax_action( 'network_activate' ) ?>';
security = '<?php echo $fs->get_ajax_security( 'network_activate' ) ?>';
licenseKey = $licenseKeyInput.val(),
module_id : '<?php echo $fs->get_id() ?>'
isMarketingAllowedByLicense.hasOwnProperty(licenseKey)
isMarketingAllowed = null,
$isMarketingAllowed = $marketingOptin.find( 'input[type="radio"][name="allow-marketing"]:checked');
if ($isMarketingAllowed.length > 0)
isMarketingAllowed = ('true' == $isMarketingAllowed.val());
if ( null == isMarketingAllowedByLicense[ licenseKey ] &&
null == isMarketingAllowed
$marketingOptin.addClass( 'error' ).show();
} else if ( null == isMarketingAllowed ) {
isMarketingAllowed = isMarketingAllowedByLicense[ licenseKey ];
data.is_marketing_allowed = isMarketingAllowed;
data.is_extensions_tracking_allowed = isExtensionsTrackingAllowed;
data.is_diagnostic_tracking_allowed = isDiagnosticTrackingAllowed;
$marketingOptin.removeClass( 'error' );
applyOnAllSites = $applyOnAllSites.is( ':checked' );
$sitesListContainer.find( 'tr' ).each(function() {
includeSite = ( ! requireLicenseKey || applyOnAllSites || $this.find( 'input' ).is( ':checked' ) );
uid : $this.find( '.uid' ).val(),
url : $this.find( '.url' ).val(),
title : $this.find( '.title' ).val(),
language: $this.find( '.language' ).val(),
blog_id : $this.find( '.blog-id' ).find( 'span' ).text()
if ( ! requireLicenseKey) {
site.action = $this.find('.action.selected').data('action-type');
} else if ( isNetworkDelegating ) {
site.action = 'delegate';
data.has_any_install = hasAnyInstall;
* Use the AJAX opt-in when license key is required to potentially
* process the after install failure hook.
* @author Vova Feldman (@svovaf)
url : <?php echo Freemius::ajax_url() ?>,
success: function (result) {
var resultObj = $.parseJSON(result);
// Redirect to the "Account" page and sync the license.
window.location.href = resultObj.next_page;
$('.fs-content').prepend('<div class="fs-error">' + (resultObj.error.message ? resultObj.error.message : resultObj.error) + '</div>');
if (null == $licenseSecret) {
$licenseSecret = $('<input type="hidden" name="license_secret_key" value="" />');
$form.append($licenseSecret);
// Update secret key if premium only plugin.
$licenseSecret.val($licenseKeyInput.val());
$( '#fs_connect .fs-permissions .fs-switch' ).on( 'click', function () {
.toggleClass( 'fs-off' );
$( this ).closest( '.fs-permission' )
.toggleClass( 'fs-disabled' );
$primaryCta.on('click', function () {
console.log('Primary button was clicked');
$(this).addClass('fs-loading');
$(this).html('<?php echo esc_js( $is_pending_activation ?
fs_text_x_inline( 'Sending email', 'as in the process of sending an email', 'sending-email', $slug ) :
fs_text_x_inline( 'Activating', 'as activating plugin', 'activating', $slug )
$('.fs-permissions .fs-trigger').on('click', function () {
$('.fs-permissions').toggleClass('fs-open');
* Submit license key on enter.
* @author Vova Feldman (@svovaf)
$licenseKeyInput.keypress(function (e) {
if ('' !== $(this).val()) {
* Disable activation button when empty license key.
* @author Vova Feldman (@svovaf)
$licenseKeyInput.on('keyup paste delete cut', function () {
var key = $licenseKeyInput.val();
if (key == previousLicenseKey){
$primaryCta.attr('disabled', 'disabled');
$primaryCta.prop('disabled', false);
fetchIsMarketingAllowedFlagAndToggleOptin();
previousLicenseKey = key;
* Set license mode trigger URL.
* @author Vova Feldman (@svovaf)
$connectLicenseModeTrigger = $('#fs_connect .fs-freemium-licensing a'),
href = window.location.href;
if (href.indexOf('?') > 0) {
if ($connectLicenseModeTrigger.length > 0) {
$connectLicenseModeTrigger.attr(
href + 'require_license=' + $connectLicenseModeTrigger.attr('data-require-license')
//--------------------------------------------------------------------------------
//--------------------------------------------------------------------------------
var isMarketingAllowedByLicense = {},
$marketingOptin = $('#fs_marketing_optin'),
previousLicenseKey = null;
afterMarketingFlagLoaded = function () {
var licenseKey = $licenseKeyInput.val();
if (null == isMarketingAllowedByLicense[licenseKey]) {
if ($marketingOptin.find('input[type=radio]:checked').length > 0){
// Focus on button if GDPR opt-in already selected is already selected.
// Focus on the GDPR opt-in radio button.
$($marketingOptin.find('input[type=radio]')[0]).focus();
* @author Leo Fajardo (@leorw)
fetchIsMarketingAllowedFlagAndToggleOptin = function () {
var licenseKey = $licenseKeyInput.val();
if (licenseKey.length < 32) {
if (isMarketingAllowedByLicense.hasOwnProperty(licenseKey)) {
afterMarketingFlagLoaded();