PluginProbe
Tag Groups is the Advanced Way to Display Your Taxonomy Terms / trunk
Tag Groups is the Advanced Way to Display Your Taxonomy Terms vtrunk
2.2.2 2.2.1 2.2.0 trunk 1.40.0 1.40.2 1.41.0 1.42.1 1.43.0 1.43.1 1.43.10 1.43.10.1 1.43.2 1.43.3 1.43.4 1.43.5 1.43.6 1.43.7 1.43.9 1.44.0 1.44.1 1.44.3 1.44.3.1 2.0.0 2.0.1 All 36 releases
tag-groups / include / helpers / class.activation_deactivation.php

class.activation_deactivation.php in Tag Groups is the Advanced Way to Display Your Taxonomy Terms trunk, at include/helpers/class.activation_deactivation.php

152 lines 5.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * @package Tag Groups
5 * @author Christoph Amthor
6 * @copyright 2019 Christoph Amthor (@ Chatty Mango, chattymango.com)
7 * @license GPL-3.0+
8 */
9
10 // phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace, Squiz.Classes.ValidClassName.NotCamelCaps, PSR1.Methods.CamelCapsMethodName.NotCamelCaps, WordPressVIPMinimum.Functions.RestrictedFunctions
11 if (! class_exists('TagGroups_Activation_Deactivation')) {
12 /**
13 *
14 */
15 class TagGroups_Activation_Deactivation
16 {
17 /**
18 * Initializes values and prevents errors that stem from wrong values, e.g. based on earlier bugs.
19 * Runs when plugin is activated.
20 *
21 * @param void
22 * @return void
23 */
24 public static function on_activation()
25 {
26
27 if (! current_user_can('activate_plugins')) {
28 TagGroups_Error::log('[Tag Groups] Insufficient permissions to activate plugin.');
29 return;
30 }
31
32 if (TAG_GROUPS_PLUGIN_IS_KERNL) {
33 register_uninstall_hook(TAG_GROUPS_PLUGIN_ABSOLUTE_PATH, array( 'TagGroups_Activation_Deactivation', 'on_uninstall' ));
34 }
35
36
37 $tag_groups_loader = new TagGroups_Loader(__FILE__);
38 $tag_groups_loader->set_version();
39 $tag_groups_loader->register_CRON();
40 if ($tag_groups_loader->is_version_update()) {
41 TagGroups_Error::verbose_log('[Tag Groups] Version update from %s to %s detected', $tag_groups_loader->get_saved_version(), $tag_groups_loader->get_version());
42 $update_scripts = new TagGroups_Update($tag_groups_loader->get_saved_version(), $tag_groups_loader->get_version());
43 $update_scripts->update_version_number();
44 // update early so that parallel thread will not run this again (anyway cron jobs avoid overlaps)
45
46 $update_scripts->run_specific_scripts();
47 $update_scripts->run_general_scripts();
48 }
49 }
50
51
52 /**
53 * This script is executed when the (inactive) plugin is deleted through the admin backend.
54 *
55 *It removes the plugin settings from the option table and all tag groups. It does not change the term_group field of the taxonomies.
56 *
57 * @param void
58 * @return void
59 */
60 public static function on_uninstall()
61 {
62
63 if (! current_user_can('install_plugins')) {
64 TagGroups_Error::log('[Tag Groups] Insufficient permissions to uninstall plugin.');
65 return;
66 }
67
68 // Referrer is wrong when triggered via Freemius
69 // check_admin_referer( 'bulk-plugins' );
70
71 /**
72 * Delete options only if requested
73 */
74 // Note: WP_UNINSTALL_PLUGIN is not defined when using the deinstallation hook
75
76 TagGroups_Error::log('[Tag Groups] Starting uninstall routine.');
77 if (! file_exists(dirname(__FILE__) . '/class.options.php')) {
78 TagGroups_Error::log('[Tag Groups] Options class not available.');
79 return;
80 }
81
82 require_once dirname(__FILE__) . '/class.options.php';
83 if (! file_exists(dirname(__FILE__) . '/cache/class.object_cache.php')) {
84 TagGroups_Error::log('[Tag Groups] Cache class not available.');
85 return;
86 }
87
88 require_once dirname(__FILE__) . '/cache/class.object_cache.php';
89 /**
90 * Purge cache
91 */
92 if (class_exists('TagGroups_Object_Cache')) {
93 $cache = new TagGroups_Object_Cache();
94 $cache
95 ->type(TagGroups_Options::get_option('tag_group_object_cache', TagGroups_Object_Cache::WP_TRANSIENTS))
96 ->path(WP_CONTENT_DIR . '/chatty-mango/cache/')
97 ->purge_all();
98 }
99
100 /**
101 * Erase /chatty-mango/cache/ directory
102 */
103 if (file_exists(WP_CONTENT_DIR . '/chatty-mango/cache') && is_dir(WP_CONTENT_DIR . '/chatty-mango/cache')) {
104 /**
105 * Attempt to empty and remove chatty-mango/cache directory
106 * (Different from purging cache because the previous one can be database.)
107 */
108 foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator(WP_CONTENT_DIR . '/chatty-mango/cache/')) as $file) {
109 // filter out "." and ".."
110 if ($file->isDir()) {
111 continue;
112 }
113
114 wp_delete_file($file->getPathname());
115 }
116
117 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_rmdir -- Removes a known empty local cache directory during deactivation; filesystem credentials cannot be requested here.
118 @rmdir(WP_CONTENT_DIR . '/chatty-mango/cache');
119 }
120
121
122 /**
123 * Remove transients
124 *
125 * Do this before deleting options, because we need to know the array in 'tag_group_used_transient_names'
126 * Don't call the method clear_term_cache since we don't know if it is still available.
127 */
128 TagGroups_Error::log('[Tag Groups] Removing transients.');
129 TagGroups_Transients::delete_all_transients();
130 /**
131 * Maybe delete options
132 */
133 $tag_group_reset_when_uninstall = TagGroups_Options::get_option('tag_group_reset_when_uninstall', 0);
134 $option_count = 0;
135 if ($tag_group_reset_when_uninstall) {
136 $option_count = TagGroups_Options::delete_all();
137 TagGroups_Error::log('[Tag Groups] %d options deleted.', $option_count);
138 }
139
140
141 /**
142 * Remove regular crons
143 */
144 wp_clear_scheduled_hook('tag_groups_check_tag_migration');
145 wp_clear_scheduled_hook('tag_groups_purge_expired_transients');
146 TagGroups_Error::log('[Tag Groups] Finished uninstall routine.');
147 }
148 }
149
150
151 }
152