Skip to content

Commit f7f25ae

Browse files
committed
Add activation and deactivation routines.
1 parent 6a3177a commit f7f25ae

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

inc/namespace.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,27 @@ function bootstrap() {
4848
}
4949
}
5050

51+
/**
52+
* Activation hook for the plugin.
53+
*
54+
* Ensures the key is created, adds and flushes rewrite rules.
55+
*/
56+
function activation_routine() {
57+
get_indexnow_key();
58+
add_key_rewrite_rule();
59+
flush_rewrite_rules();
60+
}
61+
62+
/**
63+
* Deactivation hook for the plugin.
64+
*
65+
* Removes the key from the database.
66+
*/
67+
function deactivation_routine() {
68+
delete_option( 'simple_search_submission_key' );
69+
flush_rewrite_rules();
70+
}
71+
5172
/**
5273
* Register query vars.
5374
*

simple-search-submission.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,6 @@
4242

4343
// Run late to give themes and plugins a chance to set up asynchronous pings.
4444
add_action( 'after_setup_theme', __NAMESPACE__ . '\\bootstrap', 20 );
45+
46+
register_activation_hook( __FILE__, __NAMESPACE__ . '\\activation_routine' );
47+
register_deactivation_hook( __FILE__, __NAMESPACE__ . '\\deactivation_routine' );

0 commit comments

Comments
 (0)