-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathuninstall.php
More file actions
62 lines (50 loc) · 1.61 KB
/
Copy pathuninstall.php
File metadata and controls
62 lines (50 loc) · 1.61 KB
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
59
60
61
62
<?php
/**
* Note Uninstall
*
* @author Slocum Studio
* @version 1.0.0
* @since 1.0.0
*/
// Bail if not actually uninstalling
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) )
exit;
/**
* Includes
*/
include_once 'note.php'; // Note Plugin
include_once 'includes/class-note-options.php'; // Note Options
include_once 'includes/class-note-sidebars.php'; // Note Template Functions
include_once 'includes/widgets/class-note-widget.php'; // Note Widget
/**
* Uninstall
*/
// Fetch Note options
$note_options = Note_Options::get_options();
// Remove Note data upon uninstall
if ( $note_options['uninstall']['data'] ) {
// Widgets grouped by sidebar
$sidebars_widgets = wp_get_sidebars_widgets();
if ( empty( $sidebars_widgets ) )
$sidebars_widgets = wp_get_widget_defaults();
// Unregister Note Sidebars
if ( is_array( $note_options['sidebars'] ) ) {
// Loop through posts
foreach ( $note_options['sidebars'] as $post_id => $note_sidebar_ids )
// Loop through Note Sidebar IDs
foreach ( $note_sidebar_ids as $sidebar_id ) {
// Find the Note Sidebar ID for this sidebar
$note_sidebar_id = Note_Sidebars::get_sidebar_id( $sidebar_id, $post_id );
// Remove this sidebar if it was found in sidebars widgets
if ( isset( $sidebars_widgets[$note_sidebar_id] ) )
unset( $sidebars_widgets[$note_sidebar_id] );
}
// Update the sidebars/widgets
wp_set_sidebars_widgets( $sidebars_widgets );
}
// Grab an instance of the Note Widget and remove the settings
$note_widget = Note_Widget();
delete_option( $note_widget->option_name );
// Delete the Note option
delete_option( Note_Options::$option_name );
}