| 1 |
<?php |
| 2 |
/** |
| 3 |
* Utility callbacks. |
| 4 |
* |
| 5 |
* @package FaustWP |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace WPE\FaustWP\Utilities; |
| 9 |
|
| 10 |
use function WPE\FaustWP\Settings\{ |
| 11 |
get_secret_key, |
| 12 |
faustwp_get_settings, |
| 13 |
faustwp_update_setting |
| 14 |
}; |
| 15 |
|
| 16 |
if ( ! defined( 'ABSPATH' ) ) { |
| 17 |
exit; |
| 18 |
} |
| 19 |
|
| 20 |
register_activation_hook( FAUSTWP_FILE, __NAMESPACE__ . '\\handle_activation' ); |
| 21 |
/** |
| 22 |
* Callback for WordPress register_activation_hook() function. |
| 23 |
* |
| 24 |
* 1. Deactivate the WPE Headless plugin if it's active. |
| 25 |
* 2. Set default settings if no settings exist. |
| 26 |
* 3. Set secret_key if does not exist. |
| 27 |
* 4. Flush rewrite rules. |
| 28 |
* |
| 29 |
* @todo is flush_rewrite_rules() needed? |
| 30 |
* |
| 31 |
* @link https://developer.wordpress.org/reference/functions/register_activation_hook/ |
| 32 |
* |
| 33 |
* @return void |
| 34 |
*/ |
| 35 |
function handle_activation() { |
| 36 |
if ( is_plugin_active( 'wpe-headless/wpe-headless.php' ) ) { |
| 37 |
deactivate_plugins( 'wpe-headless/wpe-headless.php', true ); |
| 38 |
} |
| 39 |
|
| 40 |
$secret_key = get_secret_key(); |
| 41 |
$settings = faustwp_get_settings(); |
| 42 |
|
| 43 |
if ( empty( $settings ) ) { |
| 44 |
faustwp_update_setting( 'disable_theme', '1' ); |
| 45 |
faustwp_update_setting( 'enable_rewrites', '1' ); |
| 46 |
faustwp_update_setting( 'enable_redirects', '1' ); |
| 47 |
} |
| 48 |
|
| 49 |
if ( ! $secret_key ) { |
| 50 |
faustwp_update_setting( 'secret_key', wp_generate_uuid4() ); |
| 51 |
} |
| 52 |
|
| 53 |
flush_rewrite_rules(); |
| 54 |
} |
| 55 |
|
| 56 |
register_deactivation_hook( FAUSTWP_FILE, __NAMESPACE__ . '\\handle_deactivation' ); |
| 57 |
/** |
| 58 |
* Callback for WordPress register_deactivation_hook() function. |
| 59 |
* |
| 60 |
* Flush rewrite rules on plugin deactivation. |
| 61 |
* |
| 62 |
* @todo is flush_rewrite_rules() needed? |
| 63 |
* |
| 64 |
* @link https://developer.wordpress.org/reference/functions/register_deactivation_hook/ |
| 65 |
* |
| 66 |
* @return void |
| 67 |
*/ |
| 68 |
function handle_deactivation() { |
| 69 |
flush_rewrite_rules(); |
| 70 |
} |
| 71 |
|