Conditions | 8 |
Paths | 16 |
Total Lines | 115 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
18 | function geodir_uninstall(){ |
||
19 | global $wpdb; |
||
20 | |||
21 | // Pages. |
||
22 | wp_delete_post( get_option('geodir_location_page'), true ); |
||
23 | wp_delete_post( get_option('geodir_success_page'), true ); |
||
24 | wp_delete_post( get_option('geodir_preview_page'), true ); |
||
25 | wp_delete_post( get_option('geodir_add_listing_page'), true ); |
||
26 | wp_delete_post( get_option('geodir_home_page'), true ); |
||
27 | wp_delete_post( get_option('geodir_info_page'), true ); |
||
28 | wp_delete_post( get_option('geodir_login_page'), true ); |
||
29 | |||
30 | // Delete usermeta. |
||
31 | $wpdb->query( "DELETE FROM $wpdb->usermeta WHERE meta_key LIKE 'gd\_user\_favourite\_post%';" ); |
||
32 | |||
33 | // remove post types |
||
34 | $post_types = get_option('geodir_post_types'); |
||
35 | |||
36 | // Delete posts. |
||
37 | if ( ! empty( $post_types ) ) { |
||
38 | foreach ( $post_types as $post_type => $data ) { |
||
39 | $wpdb->query( "DELETE FROM {$wpdb->posts} WHERE post_type LIKE '{$post_type}';" ); |
||
40 | |||
41 | // Delete post menu |
||
42 | $wpdb->query( "DELETE posts FROM {$wpdb->posts} posts LEFT JOIN {$wpdb->postmeta} meta ON posts.ID = meta.post_id WHERE posts.post_type= 'nav_menu_item' AND meta.meta_key = '_menu_item_object' AND meta.meta_value = '{$post_type}';" ); |
||
43 | $wpdb->query( "DELETE posts FROM {$wpdb->posts} posts LEFT JOIN {$wpdb->postmeta} meta ON posts.ID = meta.post_id WHERE posts.post_type= 'nav_menu_item' AND meta.meta_key = '_menu_item_url' AND meta.meta_value LIKE '%listing_type={$post_type}%';" ); |
||
44 | } |
||
45 | } |
||
46 | |||
47 | // Delete post meta. |
||
48 | $wpdb->query( "DELETE meta FROM {$wpdb->postmeta} meta LEFT JOIN {$wpdb->posts} posts ON posts.ID = meta.post_id WHERE posts.ID IS NULL;" ); |
||
49 | |||
50 | // Delete orphan attachment. |
||
51 | $wpdb->query( "DELETE post1 FROM {$wpdb->posts} post1 LEFT JOIN {$wpdb->posts} post2 ON post1.post_parent = post2.ID WHERE post1.post_parent > 0 AND post1.post_type = 'attachment' AND post2.ID IS NULL;" ); |
||
52 | |||
53 | // Delete term taxonomies. |
||
54 | if ( ! empty( $post_types ) ) { |
||
55 | foreach ( $post_types as $post_type => $data ) { |
||
56 | $wpdb->query( "DELETE FROM {$wpdb->term_taxonomy} WHERE taxonomy LIKE '{$post_type}category' OR taxonomy LIKE '{$post_type}_tags';" ); |
||
57 | } |
||
58 | } |
||
59 | |||
60 | // Delete orphan relationships. |
||
61 | $wpdb->query( "DELETE tr FROM {$wpdb->term_relationships} tr LEFT JOIN {$wpdb->posts} posts ON posts.ID = tr.object_id WHERE posts.ID IS NULL;" ); |
||
62 | |||
63 | // Delete orphan terms. |
||
64 | $wpdb->query( "DELETE t FROM {$wpdb->terms} t LEFT JOIN {$wpdb->term_taxonomy} tt ON t.term_id = tt.term_id WHERE tt.term_id IS NULL;" ); |
||
65 | |||
66 | // Delete orphan term meta. |
||
67 | $wpdb->query( "DELETE tm FROM {$wpdb->termmeta} tm LEFT JOIN {$wpdb->term_taxonomy} tt ON tm.term_id = tt.term_id WHERE tt.term_id IS NULL;" ); |
||
68 | |||
69 | // Comments |
||
70 | $wpdb->query( "DELETE comments FROM {$wpdb->comments} AS comments LEFT JOIN {$wpdb->posts} AS posts ON posts.ID = comments.comment_post_ID WHERE posts.ID IS NULL;" ); |
||
71 | $wpdb->query( "DELETE meta FROM {$wpdb->commentmeta} meta LEFT JOIN {$wpdb->comments} comments ON comments.comment_ID = meta.comment_id WHERE comments.comment_ID IS NULL;" ); |
||
72 | |||
73 | // Options |
||
74 | // Delete settings |
||
75 | $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'geodir_settings' OR option_name LIKE 'geodirectory\_%' OR option_name LIKE 'geodir\_%' OR option_name LIKE 'tax_meta_gd\_%' OR option_name LIKE 'gd\_%' AND option_name LIKE '%category\_installed' ;" ); |
||
76 | |||
77 | // Extra options |
||
78 | $extra_options = array( |
||
79 | "widget_popular_post_category", |
||
80 | "widget_popular_post_view", |
||
81 | "gd_theme_compats", |
||
82 | "gd_theme_compats", |
||
83 | "theme_compatibility_setting", |
||
84 | "skip_install_geodir_pages", |
||
85 | "widget_social_like_widget", |
||
86 | "widget_widget_subscribewidget", |
||
87 | "widget_advtwidget", |
||
88 | "widget_widget_flickrwidget", |
||
89 | "widget_widget_twidget", |
||
90 | "widget_listing_slider_view", |
||
91 | "widget_geodir_recent_reviews", |
||
92 | "widget_post_related_listing", |
||
93 | "widget_bestof_widget", |
||
94 | "gd_place_dummy_data_type", |
||
95 | "gd_theme_compat", |
||
96 | "gd_term_icons", |
||
97 | ); |
||
98 | |||
99 | foreach( $extra_options as $option){ |
||
100 | $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name= '$option';" ); |
||
101 | } |
||
102 | |||
103 | $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'widget\_gd\_%' OR option_name LIKE 'widget\_geodir\_%' ;" ); |
||
104 | |||
105 | // Delete transients |
||
106 | $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient__gd_activation_redirect' OR option_name LIKE '\_transient\_geodir\_%' OR option_name LIKE '\_transient\_gd_addons_section\_%' OR option_name LIKE '\_transient\_gd_avg\_%'" ); |
||
107 | $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_timeout__gd_activation_redirect' OR option_name LIKE '\_timeout\_transient\_geodir\_%' OR option_name LIKE '\_timeout\_transient\_gd_addons_section\_%' OR option_name LIKE '\_timeout\_transient\_gd_avg\_%'" ); |
||
108 | $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE '_site_transient__gd_activation_redirect' OR option_name LIKE '\_site\_transient\_geodir\_%' OR option_name LIKE '\_site\_transient\_gd_addons_section\_%' OR option_name LIKE '\_site\_transient\_gd_avg\_%'" ); |
||
109 | $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE '_site_transient_timeout__gd_activation_redirect' OR option_name LIKE '\_site\_transient\_timeout\_geodir\_%' OR option_name LIKE '\_site\_transient\_timeout\_gd_addons_section\_%' OR option_name LIKE '\_site\_transient\_timeout\_gd_avg\_%'" ); |
||
110 | |||
111 | // Drop tables |
||
112 | $plugin_prefix = $wpdb->prefix . 'geodir_'; |
||
113 | $wpdb->query( "DROP TABLE IF EXISTS ". $plugin_prefix . 'countries' ); |
||
114 | $wpdb->query( "DROP TABLE IF EXISTS ". $plugin_prefix . 'custom_fields' ); |
||
115 | $wpdb->query( "DROP TABLE IF EXISTS ". $plugin_prefix . 'post_icon' ); |
||
116 | $wpdb->query( "DROP TABLE IF EXISTS ". $plugin_prefix . 'attachments' ); |
||
117 | $wpdb->query( "DROP TABLE IF EXISTS ". $plugin_prefix . 'post_review' ); |
||
118 | $wpdb->query( "DROP TABLE IF EXISTS ". $plugin_prefix . 'custom_sort_fields' ); |
||
119 | |||
120 | |||
121 | // Delete term taxonomies. |
||
122 | if ( ! empty( $post_types ) ) { |
||
123 | foreach ( $post_types as $post_type => $data ) { |
||
124 | $wpdb->query( "DROP TABLE IF EXISTS ". $plugin_prefix . $post_type . '_detail' ); |
||
125 | |||
126 | } |
||
127 | } |
||
128 | |||
129 | // Clear any cached data that has been removed. |
||
130 | wp_cache_flush(); |
||
131 | |||
132 | } |
||
133 | |||
150 |