PluginProbe
Database Reset / 3.15
Database Reset v3.15
2.3.2 3.0 3.0.1 3.0.2 3.1 3.15 3.16 3.17 3.18 3.19 3.20 3.21 3.22 3.23 3.24 3.25 trunk 1.0 1.2 1.2.1 1.2.2 1.3 1.4 2.0 2.1 All 27 releases
← All changes | class-db-reset-admin.php +68 -23 trunk3.15 View file →
@@ -18,9 +18,9 @@
18 18 {
19 19 $this->resetter = new DB_Resetter();
20 20 $this->version = $version;
21 21
22 - $this->set_request($_REQUEST); //phpcs:ignore
22 + $this->set_request($_REQUEST);
23 23 $this->set_view_variables();
24 24 }
25 25
26 26 private function set_request(array $request)
@@ -60,30 +60,15 @@
60 60 add_action('admin_init', array($this, 'reset'));
61 61 add_action('admin_menu', array($this, 'add_tools_menu'));
62 62 add_action('admin_action_install_wpr', array($this, 'install_wpr'));
63 63
64 + add_filter('install_plugins_table_api_args_featured', array($this, 'featured_plugins_tab'));
64 65 add_filter('plugin_action_links_' . plugin_basename(DB_RESET_FILE), array($this, 'plugin_action_links'));
65 66 add_filter('plugin_row_meta', array($this, 'plugin_meta_links'), 10, 2);
66 67 add_filter('admin_footer_text', array($this, 'admin_footer_text'));
67 - add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
68 68 }
69 69
70 - public function admin_enqueue_scripts() {
71 - $current_screen = get_current_screen();
72 - if ($current_screen->id != 'plugins') {
73 - return;
74 - }
75 70
76 - wp_enqueue_script('db-reset', plugins_url('assets/js/database-reset-plugins.js', __FILE__), array('jquery'), $this->version, true);
77 -
78 - $vars = array();
79 - $vars['info_link'] = admin_url('plugin-install.php?tab=plugin-information&plugin=wp-reset&TB_iframe=true&width=600&height=800');
80 - $vars['install_link'] = wp_nonce_url(add_query_arg(array('action' => 'install-plugin', 'plugin' => 'wp-reset'), admin_url('update.php')), 'install-plugin_wp-reset');
81 -
82 - wp_localize_script('db-reset', 'db_reset', $vars);
83 - } // admin_enqueue
84 -
85 -
86 71 // additional powered by text in admin footer; only on plugin's page
87 72 static function admin_footer_text($text)
88 73 {
89 74 $current_screen = get_current_screen();
@@ -122,13 +107,73 @@
122 107 return $links;
123 108 } // plugin_meta_links
124 109
125 110
111 + // helper function for adding plugins to fav list
112 + function featured_plugins_tab($args)
113 + {
114 + add_filter('plugins_api_result', array($this, 'plugins_api_result'), 10, 3);
115 +
116 + return $args;
117 + } // featured_plugins_tab
118 +
119 +
120 + // add our plugins to recommended list
121 + function plugins_api_result($res, $action, $args)
122 + {
123 + remove_filter('plugins_api_result', array($this, 'plugins_api_result'), 10, 3);
124 +
125 + $res = $this->add_plugin_favs('eps-301-redirects', $res);
126 + $res = $this->add_plugin_favs('wp-htaccess-editor', $res);
127 + $res = $this->add_plugin_favs('under-construction-page', $res);
128 + $res = $this->add_plugin_favs('simple-author-box', $res);
129 +
130 + return $res;
131 + } // plugins_api_result
132 +
133 +
134 + function add_plugin_favs($plugin_slug, $res)
135 + {
136 + // check if plugin is already on the list
137 + if (!empty($res->plugins) && is_array($res->plugins)) {
138 + foreach ($res->plugins as $plugin) {
139 + if (is_object($plugin) && !empty($plugin->slug) && $plugin->slug == $plugin_slug) {
140 + return $res;
141 + }
142 + } // foreach
143 + }
144 +
145 + $plugin_info = get_transient('wf-plugin-info-' . $plugin_slug);
146 +
147 + if (!$plugin_info) {
148 + $plugin_info = plugins_api('plugin_information', array(
149 + 'slug' => $plugin_slug,
150 + 'is_ssl' => is_ssl(),
151 + 'fields' => array(
152 + 'banners' => true,
153 + 'reviews' => true,
154 + 'downloaded' => true,
155 + 'active_installs' => true,
156 + 'icons' => true,
157 + 'short_description' => true,
158 + )
159 + ));
160 + if (!is_wp_error($plugin_info)) {
161 + set_transient('wf-plugin-info-' . $plugin_slug, $plugin_info, DAY_IN_SECONDS * 7);
162 + }
163 + }
164 +
165 + if (!empty($res->plugins) && is_array($res->plugins) && $plugin_info && is_object($plugin_info)) {
166 + array_unshift($res->plugins, $plugin_info);
167 + }
168 +
169 + return $res;
170 + } // add_plugin_featured
171 +
172 +
126 173 // auto download / install / activate WPR plugin
127 174 function install_wpr()
128 175 {
129 - check_ajax_referer('install_wpr');
130 -
131 176 if (false === current_user_can('administrator')) {
132 177 wp_die('Sorry, you have to be an admin to run this action.');
133 178 }
134 179
@@ -149,9 +194,9 @@
149 194 }
150 195 </style>';
151 196
152 197 echo '<div style="margin: 20px; color:#444;">';
153 - echo 'If things are not done in a minute <a target="_parent" href="' . esc_url(admin_url('plugin-install.php?s=wp-reset&tab=search&type=term')) . '">install the plugin manually via Plugins page</a><br><br>';
198 + echo 'If things are not done in a minute <a target="_parent" href="' . admin_url('plugin-install.php?s=wp-reset&tab=search&type=term') . '">install the plugin manually via Plugins page</a><br><br>';
154 199 echo 'Starting ...<br><br>';
155 200
156 201 wp_cache_flush();
157 202 $upgrader = new Plugin_Upgrader();
@@ -176,9 +221,9 @@
176 221 echo '<script>setTimeout(function() { top.location = "tools.php?page=wp-reset"; }, 1000);</script>';
177 222 echo '<br>If you are not redirected in a few seconds - <a href="tools.php?page=wp-reset" target="_parent">click here</a>.';
178 223 }
179 224 } else {
180 - echo 'Could not install WP Reset. You\'ll have to <a target="_parent" href="' . esc_url(admin_url('plugin-install.php?s=wp-reset&tab=search&type=term')) . '">download and install manually</a>.';
225 + echo 'Could not install WP Reset. You\'ll have to <a target="_parent" href="' . admin_url('plugin-install.php?s=wp-reset&tab=search&type=term') . '">download and install manually</a>.';
181 226 }
182 227
183 228 echo '</div>';
184 229 } // install_wpr
@@ -221,9 +266,9 @@
221 266
222 267 private function handle_after_reset()
223 268 {
224 269 if (empty($this->request['db-reset-reactivate-theme-data'])) {
225 - wp_safe_redirect(admin_url());
270 + wp_redirect(admin_url());
226 271 exit;
227 272 }
228 273
229 274 $this->notice_success = __('The selected tables were reset', 'wordpress-database-reset');
@@ -340,9 +385,9 @@
340 385 return array(
341 386 'confirmAlert' => __('Are you sure you want to continue? There is NO UNDO!', 'wordpress-database-reset'),
342 387 'selectTable' => __('Select Tables', 'wordpress-database-reset'),
343 388 'selectOneTable' => __('Please select at least one table to reset.', 'wordpress-database-reset'),
344 - 'wprInstallUrl' => add_query_arg(array('action' => 'install_wpr', '_wpnonce' => wp_create_nonce('install_wpr')), admin_url('admin.php')),
389 + 'wprInstallUrl' => add_query_arg(array('action' => 'install_wpr'), admin_url('admin.php')),
345 390 'wprDialogTitle' => '<img alt="WP Reset" title="WP Reset" src="' . plugins_url('assets/images/wp-reset-logo.png', DB_RESET_FILE) . '">',
346 391 );
347 392 }
348 393 }