| @@ -3,8 +3,9 @@ | ||
| 3 | 3 | |
| 4 | 4 | class Install { |
| 5 | 5 | /** |
| 6 | 6 | * Hold Plugin class |
| 7 | + * | |
| 7 | 8 | * @var Plugin |
| 8 | 9 | */ |
| 9 | 10 | public $plugin; |
| 10 | 11 | |
| @@ -81,9 +82,8 @@ | ||
| 81 | 82 | } |
| 82 | 83 | |
| 83 | 84 | if ( empty( $this->db_version ) ) { |
| 84 | 85 | $this->install( $this->plugin->get_version() ); |
| 85 | - | |
| 86 | 86 | return; |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | if ( $this->plugin->get_version() === $this->db_version ) { |
| @@ -89,17 +89,32 @@ | ||
| 89 | 89 | if ( $this->plugin->get_version() === $this->db_version ) { |
| 90 | 90 | return; |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - $update = isset( $_REQUEST['wp_stream_update'] ) ? $_REQUEST['wp_stream_update'] : null; | |
| 93 | + $update = null; | |
| 94 | + if ( isset( $_REQUEST['wp_stream_update'] ) && wp_verify_nonce( 'wp_stream_update_db' ) ) { | |
| 95 | + $update = esc_attr( $_REQUEST['wp_stream_update'] ); | |
| 96 | + } | |
| 94 | 97 | |
| 95 | 98 | if ( ! $update ) { |
| 96 | 99 | $this->update_required = true; |
| 97 | - $this->success_db = $this->update( $this->db_version, $this->plugin->get_version(), array( 'type' => 'auto' ) ); | |
| 100 | + $this->success_db = $this->update( | |
| 101 | + $this->db_version, | |
| 102 | + $this->plugin->get_version(), | |
| 103 | + array( | |
| 104 | + 'type' => 'auto', | |
| 105 | + ) | |
| 106 | + ); | |
| 98 | 107 | } |
| 99 | 108 | |
| 100 | 109 | if ( 'update_and_continue' === $update ) { |
| 101 | - $this->success_db = $this->update( $this->db_version, $this->plugin->get_version(), array( 'type' => 'user' ) ); | |
| 110 | + $this->success_db = $this->update( | |
| 111 | + $this->db_version, | |
| 112 | + $this->plugin->get_version(), | |
| 113 | + array( | |
| 114 | + 'type' => 'user', | |
| 115 | + ) | |
| 116 | + ); | |
| 102 | 117 | } |
| 103 | 118 | |
| 104 | 119 | $versions = $this->db_update_versions(); |
| 105 | 120 | |
| @@ -128,9 +143,9 @@ | ||
| 128 | 143 | return; |
| 129 | 144 | } |
| 130 | 145 | |
| 131 | 146 | if ( ! function_exists( 'is_plugin_active_for_network' ) ) { |
| 132 | - require_once( ABSPATH . '/wp-admin/includes/plugin.php' ); | |
| 147 | + require_once ABSPATH . '/wp-admin/includes/plugin.php'; | |
| 133 | 148 | } |
| 134 | 149 | |
| 135 | 150 | /** |
| 136 | 151 | * Fires before admin notices are triggered for missing database tables. |
| @@ -166,12 +181,22 @@ | ||
| 166 | 181 | esc_html( implode( ', ', $missing_tables ) ) |
| 167 | 182 | ); |
| 168 | 183 | } |
| 169 | 184 | |
| 170 | - if ( is_plugin_active_for_network( $this->plugin->locations['plugin'] ) && current_user_can( 'manage_network_plugins' ) ) { | |
| 171 | - $uninstall_message = sprintf( __( 'Please <a href="%s">uninstall</a> the Stream plugin and activate it again.', 'stream' ), network_admin_url( 'plugins.php#stream' ) ); | |
| 185 | + if ( $this->plugin->is_network_activated() && current_user_can( 'manage_network_plugins' ) ) { | |
| 186 | + $uninstall_message = sprintf( | |
| 187 | + // translators: Placeholders refer to HTML Link tags (e.g. "<a href="https://foo.com/wp-admin/">") | |
| 188 | + __( 'Please %1$suninstall%2$s the Stream plugin and activate it again.', 'stream' ), | |
| 189 | + '<a href="' . network_admin_url( 'plugins.php#stream' ) . '">', | |
| 190 | + '</a>' | |
| 191 | + ); | |
| 172 | 192 | } elseif ( current_user_can( 'activate_plugins' ) ) { |
| 173 | - $uninstall_message = sprintf( __( 'Please <a href="%s">uninstall</a> the Stream plugin and activate it again.', 'stream' ), admin_url( 'plugins.php#stream' ) ); | |
| 193 | + $uninstall_message = sprintf( | |
| 194 | + // translators: Placeholders refer to HTML Link tags (e.g. "<a href="https://foo.com/wp-admin/">") | |
| 195 | + __( 'Please %1$suninstall%2$s the Stream plugin and activate it again.', 'stream' ), | |
| 196 | + '<a href="' . admin_url( 'plugins.php#stream' ) . '">', | |
| 197 | + '</a>' | |
| 198 | + ); | |
| 174 | 199 | } |
| 175 | 200 | |
| 176 | 201 | if ( ! empty( $database_message ) ) { |
| 177 | 202 | $this->plugin->admin->notice( $database_message ); |
| @@ -198,9 +223,9 @@ | ||
| 198 | 223 | } |
| 199 | 224 | |
| 200 | 225 | $plugin = plugin_basename( $file ); |
| 201 | 226 | |
| 202 | - if ( is_plugin_active_for_network( $plugin ) ) { | |
| 227 | + if ( $this->plugin->is_network_activated() ) { | |
| 203 | 228 | $current_versions = get_site_option( $this->option_key . '_connectors', array() ); |
| 204 | 229 | $network = true; |
| 205 | 230 | } elseif ( is_plugin_active( $plugin ) ) { |
| 206 | 231 | $current_versions = get_option( $this->option_key . '_connectors', array() ); |
| @@ -219,10 +244,8 @@ | ||
| 219 | 244 | update_site_option( $this->option_key . '_registered_connectors', $current_versions ); |
| 220 | 245 | } else { |
| 221 | 246 | update_option( $this->option_key . '_registered_connectors', $current_versions ); |
| 222 | 247 | } |
| 223 | - | |
| 224 | - return; | |
| 225 | 248 | } |
| 226 | 249 | |
| 227 | 250 | /** |
| 228 | 251 | * @return string |
| @@ -264,9 +287,12 @@ | ||
| 264 | 287 | if ( ! current_user_can( $this->plugin->admin->view_cap ) ) { |
| 265 | 288 | return; |
| 266 | 289 | } |
| 267 | 290 | |
| 268 | - $update = isset( $_REQUEST['wp_stream_update'] ) ? $_REQUEST['wp_stream_update'] : null; | |
| 291 | + $update = null; | |
| 292 | + if ( isset( $_REQUEST['wp_stream_update'] ) && wp_verify_nonce( 'wp_stream_update_db' ) ) { | |
| 293 | + $update = esc_attr( $_REQUEST['wp_stream_update'] ); | |
| 294 | + } | |
| 269 | 295 | |
| 270 | 296 | if ( ! $update ) { |
| 271 | 297 | $this->prompt_update(); |
| 272 | 298 | |
| @@ -288,15 +314,15 @@ | ||
| 288 | 314 | */ |
| 289 | 315 | public function prompt_update() { |
| 290 | 316 | ?> |
| 291 | 317 | <div class="error"> |
| 292 | - <form method="post" action="<?php echo esc_url( remove_query_arg( 'wp_stream_update' ) ) ?>"> | |
| 293 | - <?php wp_nonce_field( 'wp_stream_update_db' ) ?> | |
| 318 | + <form method="post" action="<?php echo esc_url( remove_query_arg( 'wp_stream_update' ) ); ?>"> | |
| 319 | + <?php wp_nonce_field( 'wp_stream_update_db' ); ?> | |
| 294 | 320 | <input type="hidden" name="wp_stream_update" value="update_and_continue"/> |
| 295 | - <p><strong><?php esc_html_e( 'Stream Database Update Required', 'stream' ) ?></strong></p> | |
| 296 | - <p><?php esc_html_e( 'Stream has updated! Before we send you on your way, we need to update your database to the newest version.', 'stream' ) ?></p> | |
| 297 | - <p><?php esc_html_e( 'This process could take a little while, so please be patient.', 'stream' ) ?></p> | |
| 298 | - <?php submit_button( esc_html__( 'Update Database', 'stream' ), 'primary', 'stream-update-db-submit' ) ?> | |
| 321 | + <p><strong><?php esc_html_e( 'Stream Database Update Required', 'stream' ); ?></strong></p> | |
| 322 | + <p><?php esc_html_e( 'Stream has updated! Before we send you on your way, we need to update your database to the newest version.', 'stream' ); ?></p> | |
| 323 | + <p><?php esc_html_e( 'This process could take a little while, so please be patient.', 'stream' ); ?></p> | |
| 324 | + <?php submit_button( esc_html__( 'Update Database', 'stream' ), 'primary', 'stream-update-db-submit' ); ?> | |
| 299 | 325 | </form> |
| 300 | 326 | </div> |
| 301 | 327 | <?php |
| 302 | 328 | } |
| @@ -312,12 +338,21 @@ | ||
| 312 | 338 | |
| 313 | 339 | $this->update_db_option(); |
| 314 | 340 | ?> |
| 315 | 341 | <div class="updated"> |
| 316 | - <form method="post" action="<?php echo esc_url( remove_query_arg( 'wp_stream_update' ) ) ?>" style="display:inline;"> | |
| 317 | - <p><strong><?php esc_html_e( 'Update Complete', 'stream' ) ?></strong></p> | |
| 318 | - <p><?php printf( esc_html__( 'Your Stream database has been successfully updated from %1$s to %2$s!', 'stream' ), esc_html( $this->db_version ), esc_html( $this->plugin->get_version() ) ); ?></p> | |
| 319 | - <?php submit_button( esc_html__( 'Continue', 'stream' ), 'secondary', false ) ?> | |
| 342 | + <form method="post" action="<?php echo esc_url( remove_query_arg( 'wp_stream_update' ) ); ?>" style="display:inline;"> | |
| 343 | + <p><strong><?php esc_html_e( 'Update Complete', 'stream' ); ?></strong></p> | |
| 344 | + <p> | |
| 345 | + <?php | |
| 346 | + printf( | |
| 347 | + // translators: Placeholders refer to version numbers (e.g. "4.2") | |
| 348 | + esc_html__( 'Your Stream database has been successfully updated from %1$s to %2$s!', 'stream' ), | |
| 349 | + esc_html( $this->db_version ), | |
| 350 | + esc_html( $this->plugin->get_version() ) | |
| 351 | + ); | |
| 352 | + ?> | |
| 353 | + </p> | |
| 354 | + <?php submit_button( esc_html__( 'Continue', 'stream' ), 'secondary', false ); ?> | |
| 320 | 355 | </form> |
| 321 | 356 | </div> |
| 322 | 357 | <?php |
| 323 | 358 | } |
| @@ -333,11 +368,11 @@ | ||
| 333 | 368 | * @return array |
| 334 | 369 | */ |
| 335 | 370 | public function db_update_versions() { |
| 336 | 371 | $db_update_versions = array( |
| 337 | - '3.0.0' /* @version 3.0.0 Drop the stream_context table, changes to stream table */, | |
| 338 | - '3.0.2' /* @version 3.0.2 Fix uppercase values in stream table, connector column */, | |
| 339 | - '3.0.8' /* @version 3.0.8 Increase size of user role IDs, user_roll column */, | |
| 372 | + '3.0.0', /* @version 3.0.0 Drop the stream_context table, changes to stream table */ | |
| 373 | + '3.0.2', /* @version 3.0.2 Fix uppercase values in stream table, connector column */ | |
| 374 | + '3.0.8', /* @version 3.0.8 Increase size of user role IDs, user_roll column */ | |
| 340 | 375 | ); |
| 341 | 376 | |
| 342 | 377 | /** |
| 343 | 378 | * Filter to alter the DB update versions array |
| @@ -359,9 +394,9 @@ | ||
| 359 | 394 | * @return mixed Version number on success, true on no update needed, mysql error message on error |
| 360 | 395 | */ |
| 361 | 396 | public function update( $db_version, $current_version, $update_args ) { |
| 362 | 397 | $versions = $this->db_update_versions(); |
| 363 | - include_once( $this->plugin->locations['inc_dir'] . 'db-updates.php' ); | |
| 398 | + include_once $this->plugin->locations['inc_dir'] . 'db-updates.php'; | |
| 364 | 399 | |
| 365 | 400 | foreach ( $versions as $version ) { |
| 366 | 401 | if ( ! isset( $update_args['type'] ) ) { |
| 367 | 402 | $update_args['type'] = 'user'; |