Last active
April 22, 2019 21:42
-
-
Save soderlind/9c07d6e7d785a09592b64c5ce278cc6c to your computer and use it in GitHub Desktop.
Activate SearchWP using code. Also available as a plugin for WordPress Multisite: https://github.com/soderlind/ms-searchwp-subsite-activate
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 | |
// Define the license key e.g. in wp-config.php | |
define( 'SEARCHWP_LICENSE_KEY', 'my-license-key-goes-here' ); | |
// Programmatically activate the license and enable SearchWP. | |
add_action( 'admin_init', 'searchwp_activate' ); | |
function searchwp_activate() { | |
if ( defined( 'SEARCHWP_LICENSE_KEY' ) && class_exists( '\SearchWP_License' ) && false === get_option( 'soderlind_searchwp_license_activated', false ) ) { | |
$swp_license = new \SearchWP_License(); | |
$swp_license->activate( SEARCHWP_LICENSE_KEY ); | |
searchwp_set_setting( 'initial_settings', true ); // tell SearchWP to work with the default generated config on install. | |
\SWP()->trigger_index(); // Run the SearchWP indexer | |
update_option( 'soderlind_searchwp_license_activated', true ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment