-
Notifications
You must be signed in to change notification settings - Fork 82
/
uninstall.php
79 lines (72 loc) · 1.89 KB
/
uninstall.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
/*
* Uninstall plugin
*/
if ( !defined( 'WP_UNINSTALL_PLUGIN' ) )
exit ();
$option_names = array(
'postratings_image'
, 'postratings_max'
, 'postratings_template_vote'
, 'postratings_template_text'
, 'postratings_template_none'
, 'postratings_logging_method'
, 'postratings_allowtorate'
, 'postratings_ratingstext'
, 'postratings_template_highestrated'
, 'postratings_ajax_style'
, 'widget_ratings_highest_rated'
, 'widget_ratings_most_rated'
, 'postratings_customrating'
, 'postratings_ratingsvalue'
, 'postratings_template_permission'
, 'postratings_template_mostrated'
, 'postratings_options'
, 'widget_ratings'
, 'widget_ratings-widget'
);
if ( is_multisite() ) {
$ms_sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites();
if ( 0 < count( $ms_sites ) ) {
foreach ( $ms_sites as $ms_site ) {
$blog_id = class_exists( 'WP_Site' ) ? $ms_site->blog_id : $ms_site['blog_id'];
switch_to_blog( $blog_id );
if ( count( $option_names ) > 0 ) {
foreach ( $option_names as $option_name ) {
delete_option( $option_name );
plugin_uninstalled();
restore_current_blog();
}
}
}
}
} else {
if ( count( $option_names ) > 0 ) {
foreach ( $option_names as $option_name ) {
delete_option( $option_name );
plugin_uninstalled();
}
}
}
/**
* Delete plugin table when uninstalled
*
* @access public
* @return void
*/
function plugin_uninstalled() {
global $wpdb;
$table_names = array( 'ratings' );
if( sizeof( $table_names ) > 0 ) {
foreach( $table_names as $table_name ) {
$table = $wpdb->prefix . $table_name;
$wpdb->query( "DROP TABLE IF EXISTS $table" );
}
}
$post_meta_names = array( 'ratings_users', 'ratings_score', 'ratings_average' );
if( sizeof( $post_meta_names ) > 0 ) {
foreach( $post_meta_names as $post_meta_name ) {
$wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_key = '$post_meta_name'" );
}
}
}