-
Notifications
You must be signed in to change notification settings - Fork 1
/
genesis-octs-redirect.php
58 lines (48 loc) · 1.46 KB
/
genesis-octs-redirect.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
/**
* Plugin Name: Genesis One-Click Theme Setup Redirector
* Plugin Description: Redirects users to the Genesis OCTS page the first time they log into wp-admin after using the Site Templates feature in Portal.
* Version: 1.0
*/
namespace wpengine\genesis\octs_redirect;
defined( 'WPINC' ) or die;
add_action( 'admin_init', __NAMESPACE__ . '\load' );
/**
* Loads up the plugin to handle the redirect
* and then uninstalls itself.
*/
function load() {
if ( wp_doing_ajax() ) {
return;
}
/** A compatible theme not active. Stop now and remove the plugin. */
if ( ! function_exists( 'genesis_onboarding_active' ) || ! genesis_onboarding_active() ) {
schedule_plugin_for_removal();
return;
}
/** The redirect has already happened. Stop now and remove the plugin. */
if ( get_option( 'genesis_octs_redirect_complete', false ) ) {
schedule_plugin_for_removal();
return;
}
add_option( 'genesis_octs_redirect_complete', true );
schedule_plugin_for_removal();
wp_safe_redirect( esc_url( admin_url( 'admin.php?page=genesis-getting-started' ) ) );
exit;
}
/**
* Deletes the plugin on the shutdown hook.
*/
function schedule_plugin_for_removal() {
add_action( 'shutdown', function() {
delete_plugins( [ main_plugin_file_basename() ] );
} );
}
/**
* Returns the plugin's directory name and main plugin file.
*
* @return string Plugin directory name and plugin filename.
*/
function main_plugin_file_basename() {
return plugin_basename(__FILE__);
}