PluginProbe
Database Reset / 3.25
Database Reset v3.25
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 +23 -68 3.163.25 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);
22 + $this->set_request($_REQUEST); //phpcs:ignore
23 23 $this->set_view_variables();
24 24 }
25 25
26 26 private function set_request(array $request)
@@ -60,16 +60,30 @@
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'));
65 - add_filter('install_plugins_table_api_args_recommended', array($this, 'featured_plugins_tab'));
66 64 add_filter('plugin_action_links_' . plugin_basename(DB_RESET_FILE), array($this, 'plugin_action_links'));
67 65 add_filter('plugin_row_meta', array($this, 'plugin_meta_links'), 10, 2);
68 66 add_filter('admin_footer_text', array($this, 'admin_footer_text'));
67 + add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
69 68 }
70 69
70 + public function admin_enqueue_scripts() {
71 + $current_screen = get_current_screen();
72 + if ($current_screen->id != 'plugins') {
73 + return;
74 + }
71 75
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 +
72 86 // additional powered by text in admin footer; only on plugin's page
73 87 static function admin_footer_text($text)
74 88 {
75 89 $current_screen = get_current_screen();
@@ -108,72 +122,13 @@
108 122 return $links;
109 123 } // plugin_meta_links
110 124
111 125
112 - // helper function for adding plugins to fav list
113 - function featured_plugins_tab($args)
114 - {
115 - add_filter('plugins_api_result', array($this, 'plugins_api_result'), 10, 3);
116 -
117 - return $args;
118 - } // featured_plugins_tab
119 -
120 -
121 - // add our plugins to recommended list
122 - function plugins_api_result($res, $action, $args)
123 - {
124 - remove_filter('plugins_api_result', array($this, 'plugins_api_result'), 10, 3);
125 -
126 - $res = $this->add_plugin_favs('under-construction-page', $res);
127 - $res = $this->add_plugin_favs('simple-author-box', $res);
128 - $res = $this->add_plugin_favs('eps-301-redirects', $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 -
173 126 // auto download / install / activate WPR plugin
174 127 function install_wpr()
175 128 {
129 + check_ajax_referer('install_wpr');
130 +
176 131 if (false === current_user_can('administrator')) {
177 132 wp_die('Sorry, you have to be an admin to run this action.');
178 133 }
179 134
@@ -194,9 +149,9 @@
194 149 }
195 150 </style>';
196 151
197 152 echo '<div style="margin: 20px; color:#444;">';
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>';
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>';
199 154 echo 'Starting ...<br><br>';
200 155
201 156 wp_cache_flush();
202 157 $upgrader = new Plugin_Upgrader();
@@ -221,9 +176,9 @@
221 176 echo '<script>setTimeout(function() { top.location = "tools.php?page=wp-reset"; }, 1000);</script>';
222 177 echo '<br>If you are not redirected in a few seconds - <a href="tools.php?page=wp-reset" target="_parent">click here</a>.';
223 178 }
224 179 } else {
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>.';
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>.';
226 181 }
227 182
228 183 echo '</div>';
229 184 } // install_wpr
@@ -266,9 +221,9 @@
266 221
267 222 private function handle_after_reset()
268 223 {
269 224 if (empty($this->request['db-reset-reactivate-theme-data'])) {
270 - wp_redirect(admin_url());
225 + wp_safe_redirect(admin_url());
271 226 exit;
272 227 }
273 228
274 229 $this->notice_success = __('The selected tables were reset', 'wordpress-database-reset');
@@ -385,9 +340,9 @@
385 340 return array(
386 341 'confirmAlert' => __('Are you sure you want to continue? There is NO UNDO!', 'wordpress-database-reset'),
387 342 'selectTable' => __('Select Tables', 'wordpress-database-reset'),
388 343 'selectOneTable' => __('Please select at least one table to reset.', 'wordpress-database-reset'),
389 - 'wprInstallUrl' => add_query_arg(array('action' => 'install_wpr'), admin_url('admin.php')),
344 + 'wprInstallUrl' => add_query_arg(array('action' => 'install_wpr', '_wpnonce' => wp_create_nonce('install_wpr')), admin_url('admin.php')),
390 345 'wprDialogTitle' => '<img alt="WP Reset" title="WP Reset" src="' . plugins_url('assets/images/wp-reset-logo.png', DB_RESET_FILE) . '">',
391 346 );
392 347 }
393 348 }