PluginProbe
Faust.js / 1.0.2
Faust.js v1.0.2
1.8.12 1.8.11 1.4.1 1.8.0 1.8.8 1.8.9 trunk 0.7.0 0.7.1 0.7.10 0.7.11 0.7.3 0.7.4 0.7.5 0.7.6 0.7.7 0.7.8 0.7.9 0.8.0 0.8.1 0.8.3 0.8.4 0.8.5 0.8.6 0.8.7 All 40 releases
faustwp / includes / utilities / callbacks.php

callbacks.php in Faust.js 1.0.2, at includes/utilities/callbacks.php

95 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Utility callbacks.
4 *
5 * @package FaustWP
6 */
7
8 namespace WPE\FaustWP\Utilities;
9
10 use function WPE\FaustWP\Detect_Conflicts\delete_conflicts_dismissed;
11 use function WPE\FaustWP\Settings\{
12 get_secret_key,
13 faustwp_get_settings,
14 faustwp_update_setting,
15 maybe_set_default_settings
16 };
17
18 if ( ! defined( 'ABSPATH' ) ) {
19 exit;
20 }
21
22 register_activation_hook( FAUSTWP_FILE, __NAMESPACE__ . '\\handle_activation' );
23 /**
24 * Callback for WordPress register_activation_hook() function.
25 *
26 * 1. Deactivate the WPE Headless plugin if it's active.
27 * 2. Set default settings if no settings exist.
28 * 3. Set secret_key if does not exist.
29 * 4. Flush rewrite rules.
30 *
31 * @todo is flush_rewrite_rules() needed?
32 *
33 * @link https://developer.wordpress.org/reference/functions/register_activation_hook/
34 *
35 * @param bool $network_active True if plugin is network activated.
36 *
37 * @return void
38 */
39 function handle_activation( $network_active ) {
40 if ( is_plugin_active( 'wpe-headless/wpe-headless.php' ) ) {
41 deactivate_plugins( 'wpe-headless/wpe-headless.php', true );
42 }
43
44 // Handle network activation of plugin within multisite.
45 if ( $network_active ) {
46 $args = array(
47 'fields' => 'ids',
48 );
49 $sites = get_sites( $args );
50
51 foreach ( $sites as $site ) {
52 switch_to_blog( $site );
53 maybe_set_default_settings();
54 restore_current_blog();
55 }
56
57 return;
58 }
59
60 maybe_set_default_settings();
61 }
62
63 register_deactivation_hook( FAUSTWP_FILE, __NAMESPACE__ . '\\handle_deactivation' );
64 /**
65 * Callback for WordPress register_deactivation_hook() function.
66 *
67 * Clear conflict dismissals and flush rewrites on plugin deactivation.
68 *
69 * @todo is flush_rewrite_rules() needed?
70 *
71 * @link https://developer.wordpress.org/reference/functions/register_deactivation_hook/
72 *
73 * @return void
74 */
75 function handle_deactivation() {
76 delete_conflicts_dismissed();
77 flush_rewrite_rules();
78 }
79
80 add_action( 'wp_initialize_site', __NAMESPACE__ . '\\handle_new_site_creation' );
81 /**
82 * Fires when a site's initialization routine should be executed.
83 *
84 * @link https://developer.wordpress.org/reference/hooks/wp_initialize_site/
85 *
86 * @param WP_Site $new_site New site object.
87 *
88 * @return void
89 */
90 function handle_new_site_creation( $new_site ) {
91 switch_to_blog( $new_site->blog_id );
92 maybe_set_default_settings();
93 restore_current_blog();
94 }
95