Created
February 13, 2019 06:48
-
-
Save asharirfan/e9f05786421850562af4dd0752a52c02 to your computer and use it in GitHub Desktop.
Custom Freemius Opt-in/out Code Snippet.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// $choice contains the user's input to opt-in or out. | |
if ( 'yes' === $choice ) { | |
if ( ! is_multisite() ) { | |
my_freemius()->opt_in(); // Opt in. | |
} else { | |
// Get all sites on the WP multisite network. | |
$sites = Freemius::get_sites(); | |
$sites_data = array(); | |
if ( ! empty( $sites ) ) { | |
foreach ( $sites as $site ) { | |
$sites_data[] = my_freemius()->get_site_info( $site ); // Get site info from Freemius. | |
} | |
} | |
my_freemius()->opt_in( false, false, false, false, false, false, false, false, $sites_data ); // Opt-in with all sites data. | |
} | |
} elseif ( 'no' === $choice ) { | |
if ( ! is_multisite() ) { | |
my_freemius()->skip_connection(); // Opt out. | |
} else { | |
my_freemius()->skip_connection( null, true ); // Opt out for all websites on multisite. | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment