Skip to content

Instantly share code, notes, and snippets.

@soderlind
Last active April 22, 2019 21:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soderlind/9c07d6e7d785a09592b64c5ce278cc6c to your computer and use it in GitHub Desktop.
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
<?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