| 1 |
<?php |
| 2 |
/** |
| 3 |
* Handle installation functions. |
| 4 |
* |
| 5 |
* @package UpStream. |
| 6 |
*/ |
| 7 |
|
| 8 |
// Exit if accessed directly. |
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; |
| 11 |
} |
| 12 |
|
| 13 |
/** |
| 14 |
* Install |
| 15 |
* |
| 16 |
* Runs on plugin install by setting up the post types, custom taxonomies, |
| 17 |
* flushing rewrite rules to initiate the new 'downloads' slug and also |
| 18 |
* creates the plugin and populates the settings fields for those plugin |
| 19 |
* pages. After successful install, the user is redirected to the UpStream Welcome |
| 20 |
* screen. |
| 21 |
* |
| 22 |
* @param bool $network_side If the plugin is being network-activated |
| 23 |
* |
| 24 |
* @return void |
| 25 |
* @global $upstream_options |
| 26 |
* @global $wp_version |
| 27 |
* |
| 28 |
* @since 1.0 |
| 29 |
* @global $wpdb |
| 30 |
*/ |
| 31 |
|
| 32 |
/** |
| 33 |
* Check UpStream minimum requirements: PHP and WordPress versions. |
| 34 |
* This function calls wp_die() if any of the minimum requirements is not satisfied. |
| 35 |
* |
| 36 |
* @since 1.10.1 |
| 37 |
* |
| 38 |
* @uses wp_die() |
| 39 |
*/ |
| 40 |
function upstream_check_min_requirements() { |
| 41 |
global $wp_version; |
| 42 |
|
| 43 |
$min_wpversion_required = '4.5'; |
| 44 |
$min_phpversion_required = '5.6.20'; |
| 45 |
|
| 46 |
// Check PHP version. |
| 47 |
if ( version_compare( PHP_VERSION, $min_phpversion_required, '<' ) ) { |
| 48 |
$error_message = sprintf( |
| 49 |
'<p>' . |
| 50 |
// translators: %s: PHP_VERSION. |
| 51 |
__( 'It seems you are running an outdated version of PHP: <code>%s</code>.', 'upstream' ) . |
| 52 |
'</p>' . |
| 53 |
'<p>' . |
| 54 |
// translators: $s: min php version required. |
| 55 |
__( |
| 56 |
'For security reasons, UpStream requires at least PHP version <code>%s</code> to run.', |
| 57 |
'upstream' |
| 58 |
) . '</p>' . |
| 59 |
'<p>' . __( 'Please, consider upgrading your PHP version.', 'upstream' ) . '</p><br /><br />', |
| 60 |
PHP_VERSION, |
| 61 |
$min_phpversion_required |
| 62 |
); |
| 63 |
} elseif ( version_compare( $wp_version, $min_wpversion_required, '<' ) ) { // Check WordPress version. |
| 64 |
$error_message = sprintf( |
| 65 |
'<p>' . |
| 66 |
// translators: %s: wp_version. |
| 67 |
__( |
| 68 |
'It seems you are running an outdated version of WordPress: <code>%s</code>.', |
| 69 |
'upstream' |
| 70 |
) . '</p>' . |
| 71 |
'<p>' . |
| 72 |
// translators: %s: min wp_version required. |
| 73 |
__( |
| 74 |
'For security reasons, UpStream requires at least version <code>%s</code> to run.', |
| 75 |
'upstream' |
| 76 |
) . '</p>' . |
| 77 |
'<p>' . __( 'Please, consider upgrading your WordPress.', 'upstream' ) . '</p><br /><br />', |
| 78 |
$wp_version, |
| 79 |
$min_wpversion_required |
| 80 |
); |
| 81 |
} |
| 82 |
|
| 83 |
if ( isset( $error_message ) ) { |
| 84 |
$error_message .= '<a class="button" href="javascript:history.back();">' . __( 'Go Back', 'upstream' ) . '</a>'; |
| 85 |
|
| 86 |
wp_die( wp_kses_post( $error_message ) ); |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
/** |
| 91 |
* Upstream_install_debug |
| 92 |
* |
| 93 |
* @param string $message Error message. |
| 94 |
*/ |
| 95 |
function upstream_install_debug( $message ) { |
| 96 |
$message = sprintf( '[%s] %s', gmdate( 'Y-m-d H:i:s T O' ), $message ) . "\n"; |
| 97 |
error_log( $message, 3, str_replace( '//', '/', WP_CONTENT_DIR . '/debug-upstream.log' ) ); |
| 98 |
} |
| 99 |
|
| 100 |
/** |
| 101 |
* Upstream_install |
| 102 |
* |
| 103 |
* @param bool $network_wide Is network wide. |
| 104 |
*/ |
| 105 |
function upstream_install( $network_wide = false ) { |
| 106 |
global $wpdb; |
| 107 |
|
| 108 |
upstream_install_debug( 'upstream_check_min_requirements' ); |
| 109 |
upstream_check_min_requirements(); |
| 110 |
|
| 111 |
if ( is_multisite() && $network_wide ) { |
| 112 |
upstream_install_debug( 'is_multisite/network wide' ); |
| 113 |
|
| 114 |
foreach ( $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs LIMIT 100" ) as $blog_id ) { |
| 115 |
upstream_install_debug( 'handling blog' . $blog_id ); |
| 116 |
switch_to_blog( $blog_id ); |
| 117 |
|
| 118 |
upstream_install_debug( 'upstream_run_install' ); |
| 119 |
upstream_run_install(); |
| 120 |
|
| 121 |
upstream_install_debug( 'restore_current_blog' ); |
| 122 |
restore_current_blog(); |
| 123 |
} |
| 124 |
} else { |
| 125 |
upstream_install_debug( 'upstream_run_install' ); |
| 126 |
upstream_run_install(); |
| 127 |
} |
| 128 |
|
| 129 |
upstream_install_debug( 'flush_rewrite_rules' ); |
| 130 |
flush_rewrite_rules(); |
| 131 |
} |
| 132 |
|
| 133 |
register_activation_hook( UPSTREAM_PLUGIN_FILE, 'upstream_install' ); |
| 134 |
register_deactivation_hook( UPSTREAM_PLUGIN_FILE, 'upstream_uninstall' ); |
| 135 |
add_action( 'upstream_update_data', 'upstream_update_data', 10, 2 ); |
| 136 |
|
| 137 |
/** |
| 138 |
* Run the UpStream Install process |
| 139 |
* |
| 140 |
* @return void |
| 141 |
* @since 2.5 |
| 142 |
*/ |
| 143 |
function upstream_run_install() { |
| 144 |
upstream_install_debug( 'wp_get_current_user' ); |
| 145 |
$user = wp_get_current_user(); |
| 146 |
|
| 147 |
upstream_install_debug( 'user->add_cap' ); |
| 148 |
$user->add_cap( 'manage_upstream' ); |
| 149 |
|
| 150 |
// Setup the Downloads Custom Post Type. |
| 151 |
upstream_install_debug( 'upstream_setup_post_types' ); |
| 152 |
upstream_setup_post_types(); |
| 153 |
|
| 154 |
// Setup the Download Taxonomies. |
| 155 |
upstream_install_debug( 'upstream_setup_taxonomies' ); |
| 156 |
upstream_setup_taxonomies(); |
| 157 |
|
| 158 |
// Add the default options. |
| 159 |
upstream_install_debug( 'upstream_add_default_options' ); |
| 160 |
upstream_add_default_options(); |
| 161 |
|
| 162 |
// Clear the permalinks. |
| 163 |
upstream_install_debug( 'flush_rewrite_rules' ); |
| 164 |
flush_rewrite_rules( false ); |
| 165 |
|
| 166 |
// Add upgraded_from option. |
| 167 |
upstream_install_debug( 'current_version = get_option' ); |
| 168 |
$current_version = get_option( 'upstream_version', false ); |
| 169 |
$fresh_install = empty( $current_version ); |
| 170 |
|
| 171 |
if ( ! $fresh_install ) { |
| 172 |
update_option( 'upstream_version_upgraded_from', $current_version ); |
| 173 |
} |
| 174 |
|
| 175 |
upstream_install_debug( 'update_option' ); |
| 176 |
update_option( 'upstream_version', UPSTREAM_VERSION ); |
| 177 |
|
| 178 |
// Create UpStream roles. |
| 179 |
upstream_install_debug( 'roles = new UpStream_Roles' ); |
| 180 |
$roles = new UpStream_Roles(); |
| 181 |
|
| 182 |
upstream_install_debug( 'roles->add_roles' ); |
| 183 |
$roles->add_roles(); |
| 184 |
|
| 185 |
if ( $fresh_install ) { |
| 186 |
upstream_install_debug( 'upstream_run_fresh_install' ); |
| 187 |
upstream_run_fresh_install(); |
| 188 |
|
| 189 |
// Make sure we don't redirect if activating from network, or bulk. |
| 190 |
if ( ! is_network_admin() && ! isset( $_GET['activate-multi'] ) ) { |
| 191 |
// Add the transient to redirect. |
| 192 |
upstream_install_debug( 'set_transient' ); |
| 193 |
set_transient( '_upstream_activation_redirect', true, 30 ); |
| 194 |
} |
| 195 |
} else { |
| 196 |
upstream_install_debug( 'upstream_run_reinstall' ); |
| 197 |
upstream_run_reinstall(); |
| 198 |
|
| 199 |
upstream_install_debug( 'do_action' ); |
| 200 |
do_action( 'upstream_update_data', $current_version, UPSTREAM_VERSION ); |
| 201 |
} |
| 202 |
} |
| 203 |
|
| 204 |
/** |
| 205 |
* Run the fresh UpStream Install process |
| 206 |
* |
| 207 |
* @return void |
| 208 |
* @since 2.5 |
| 209 |
*/ |
| 210 |
function upstream_run_fresh_install() { |
| 211 |
// Add default capabilities for roles. |
| 212 |
$roles = new UpStream_Roles(); |
| 213 |
$roles->add_default_caps(); |
| 214 |
} |
| 215 |
|
| 216 |
/** |
| 217 |
* Run the UpStream Reinstall process |
| 218 |
* |
| 219 |
* @return void |
| 220 |
* @since 2.5 |
| 221 |
*/ |
| 222 |
function upstream_run_reinstall() { |
| 223 |
} |
| 224 |
|
| 225 |
/** |
| 226 |
* Runs the UpStream uninstall process. |
| 227 |
*/ |
| 228 |
function upstream_uninstall() { |
| 229 |
flush_rewrite_rules(); |
| 230 |
|
| 231 |
// RSD: deactivate any child plugins. |
| 232 |
if ( is_plugin_active( 'UpStream-Reports-PDF/upstream-reports-pdf.php' ) || |
| 233 |
is_plugin_active( 'upstream-reports-pdf/upstream-reports-pdf.php' ) |
| 234 |
) { |
| 235 |
add_action( 'update_option_active_plugins', 'upstream_deactivate_dependency_reports_pdf' ); |
| 236 |
} |
| 237 |
if ( is_plugin_active( 'UpStream-Reports/upstream-reports.php' ) || |
| 238 |
is_plugin_active( 'upstream-reports/upstream-reports.php' ) |
| 239 |
) { |
| 240 |
add_action( 'update_option_active_plugins', 'upstream_deactivate_dependency_reports' ); |
| 241 |
} |
| 242 |
if ( is_plugin_active( 'UpStream-Copy-Project/upstream-copy-project.php' ) || |
| 243 |
is_plugin_active( 'upstream-copy-project/upstream-copy-project.php' ) |
| 244 |
) { |
| 245 |
add_action( 'update_option_active_plugins', 'upstream_deactivate_dependency_copy_project' ); |
| 246 |
} |
| 247 |
if ( is_plugin_active( 'UpStream-Custom-Fields/upstream-custom-fields.php' ) || |
| 248 |
is_plugin_active( 'upstream-custom-fields/upstream-custom-fields.php' ) |
| 249 |
) { |
| 250 |
add_action( 'update_option_active_plugins', 'upstream_deactivate_dependency_custom_fields' ); |
| 251 |
} |
| 252 |
if ( is_plugin_active( 'UpStream-Customizer/upstream-customizer.php' ) || |
| 253 |
is_plugin_active( 'upstream-customizer/upstream-customizer.php' ) |
| 254 |
) { |
| 255 |
add_action( 'update_option_active_plugins', 'upstream_deactivate_dependency_customizer' ); |
| 256 |
} |
| 257 |
if ( is_plugin_active( 'UpStream-Email-Notifications/upstream-email-notifications.php' ) || |
| 258 |
is_plugin_active( 'upstream-email-notifications/upstream-email-notifications.php' ) |
| 259 |
) { |
| 260 |
add_action( 'update_option_active_plugins', 'upstream_deactivate_dependency_email_notifications' ); |
| 261 |
} |
| 262 |
if ( is_plugin_active( 'UpStream-Calendar-View/upstream-calendar-view.php' ) || |
| 263 |
is_plugin_active( 'upstream-calendar-view/upstream-calendar-view.php' ) |
| 264 |
) { |
| 265 |
add_action( 'update_option_active_plugins', 'upstream_deactivate_dependency_calendar_view' ); |
| 266 |
} |
| 267 |
if ( is_plugin_active( 'UpStream-Frontend-Edit/upstream-frontend-edit.php' ) || |
| 268 |
is_plugin_active( 'upstream-frontend-edit/upstream-frontend-edit.php' ) |
| 269 |
) { |
| 270 |
add_action( 'update_option_active_plugins', 'upstream_deactivate_dependency_frontend_edit' ); |
| 271 |
} |
| 272 |
if ( is_plugin_active( 'UpStream-Project-Timeline/upstream-project-timeline.php' ) || |
| 273 |
is_plugin_active( 'upstream-project-timeline/upstream-project-timeline.php' ) |
| 274 |
) { |
| 275 |
add_action( 'update_option_active_plugins', 'upstream_deactivate_dependency_project_timeline' ); |
| 276 |
} |
| 277 |
|
| 278 |
if ( is_plugin_active( 'UpStream-Advanced-Permissions/upstream-advanced-permissions.php' ) || |
| 279 |
is_plugin_active( 'upstream-advanced-permissions/upstream-advanced-permissions.php' ) |
| 280 |
) { |
| 281 |
add_action( 'update_option_active_plugins', 'upstream_deactivate_dependency_advanced_permissions' ); |
| 282 |
} |
| 283 |
|
| 284 |
if ( is_plugin_active( 'UpStream-API/upstream-api.php' ) || |
| 285 |
is_plugin_active( 'upstream-api/upstream-api.php' ) |
| 286 |
) { |
| 287 |
add_action( 'update_option_active_plugins', 'upstream_deactivate_dependency_api' ); |
| 288 |
} |
| 289 |
|
| 290 |
if ( is_plugin_active( 'UpStream-Forms/upstream-forms.php' ) || |
| 291 |
is_plugin_active( 'upstream-forms/upstream-forms.php' ) |
| 292 |
) { |
| 293 |
add_action( 'update_option_active_plugins', 'upstream_deactivate_dependency_forms' ); |
| 294 |
} |
| 295 |
|
| 296 |
if ( is_plugin_active( 'UpStream-Shortcodes/upstream-shortcodes.php' ) || |
| 297 |
is_plugin_active( 'upstream-shortcodes/upstream-shortcodes.php' ) |
| 298 |
) { |
| 299 |
add_action( 'update_option_active_plugins', 'upstream_deactivate_dependency_shortcodes' ); |
| 300 |
} |
| 301 |
|
| 302 |
if ( is_plugin_active( 'UpStream-Naming/upstream-name-replacement.php' ) || |
| 303 |
is_plugin_active( 'upstream-name-replacement/upstream-name-replacement.php' ) |
| 304 |
) { |
| 305 |
add_action( 'update_option_active_plugins', 'upstream_deactivate_dependency_name_replacement' ); |
| 306 |
} |
| 307 |
|
| 308 |
if ( is_plugin_active( 'UpStream-Reporting/upstream-reporting.php' ) || |
| 309 |
is_plugin_active( 'upstream-reporting/upstream-reporting.php' ) |
| 310 |
) { |
| 311 |
add_action( 'update_option_active_plugins', 'upstream_deactivate_dependency_reporting' ); |
| 312 |
} |
| 313 |
|
| 314 |
if ( is_plugin_active( 'UpStream-Time-Tracking-and-Budgeting/upstream-time-tracking.php' ) || |
| 315 |
is_plugin_active( 'upstream-time-tracking/upstream-time-tracking.php' ) |
| 316 |
) { |
| 317 |
add_action( 'update_option_active_plugins', 'upstream_deactivate_dependency_time_tracking_budgeting' ); |
| 318 |
} |
| 319 |
} |
| 320 |
|
| 321 |
|
| 322 |
/** |
| 323 |
* Upstream_deactivate_dependency_shortcodes. |
| 324 |
*/ |
| 325 |
function upstream_deactivate_dependency_shortcodes() { |
| 326 |
deactivate_plugins( |
| 327 |
array( |
| 328 |
'UpStream-Shortcodes/upstream-shortcodes.php', |
| 329 |
'upstream-shortcodes/upstream-shortcodes.php', |
| 330 |
) |
| 331 |
); |
| 332 |
} |
| 333 |
|
| 334 |
/** |
| 335 |
* Upstream_deactivate_dependency_forms. |
| 336 |
*/ |
| 337 |
function upstream_deactivate_dependency_forms() { |
| 338 |
deactivate_plugins( |
| 339 |
array( |
| 340 |
'UpStream-Forms/upstream-forms.php', |
| 341 |
'upstream-forms/upstream-forms.php', |
| 342 |
) |
| 343 |
); |
| 344 |
} |
| 345 |
|
| 346 |
/** |
| 347 |
* Upstream_deactivate_dependency_api. |
| 348 |
*/ |
| 349 |
function upstream_deactivate_dependency_api() { |
| 350 |
deactivate_plugins( |
| 351 |
array( |
| 352 |
'UpStream-API/upstream-api.php', |
| 353 |
'upstream-api/upstream-api.php', |
| 354 |
) |
| 355 |
); |
| 356 |
} |
| 357 |
|
| 358 |
|
| 359 |
/** |
| 360 |
* Upstream_deactivate_dependency_advanced_permissions. |
| 361 |
*/ |
| 362 |
function upstream_deactivate_dependency_advanced_permissions() { |
| 363 |
deactivate_plugins( |
| 364 |
array( |
| 365 |
'UpStream-Advanced-Permissions/upstream-advanced-permissions.php', |
| 366 |
'upstream-advanced-permissions/upstream-advanced-permissions.php', |
| 367 |
) |
| 368 |
); |
| 369 |
} |
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
/** |
| 375 |
* Upstream_deactivate_dependency_calendar_view. |
| 376 |
*/ |
| 377 |
function upstream_deactivate_dependency_calendar_view() { |
| 378 |
deactivate_plugins( |
| 379 |
array( |
| 380 |
'UpStream-Calendar-View/upstream-calendar-view.php', |
| 381 |
'upstream-calendar-view/upstream-calendar-view.php', |
| 382 |
) |
| 383 |
); |
| 384 |
} |
| 385 |
|
| 386 |
/** |
| 387 |
* Upstream_deactivate_dependency_reports_pdf. |
| 388 |
*/ |
| 389 |
function upstream_deactivate_dependency_reports_pdf() { |
| 390 |
deactivate_plugins( |
| 391 |
array( |
| 392 |
'UpStream-Reports-PDF/upstream-reports-pdf.php', |
| 393 |
'upstream-reports-pdf/upstream-reports-pdf.php', |
| 394 |
) |
| 395 |
); |
| 396 |
} |
| 397 |
|
| 398 |
/** |
| 399 |
* Upstream_deactivate_dependency_reports. |
| 400 |
*/ |
| 401 |
function upstream_deactivate_dependency_reports() { |
| 402 |
deactivate_plugins( |
| 403 |
array( |
| 404 |
'UpStream-Reports/upstream-reports.php', |
| 405 |
'upstream-reports/upstream-reports.php', |
| 406 |
) |
| 407 |
); |
| 408 |
} |
| 409 |
|
| 410 |
/** |
| 411 |
* Upstream_deactivate_dependency_copy_project. |
| 412 |
*/ |
| 413 |
function upstream_deactivate_dependency_copy_project() { |
| 414 |
deactivate_plugins( |
| 415 |
array( |
| 416 |
'UpStream-Copy-Project/upstream-copy-project.php', |
| 417 |
'upstream-copy-project/upstream-copy-project.php', |
| 418 |
) |
| 419 |
); |
| 420 |
} |
| 421 |
|
| 422 |
/** |
| 423 |
* Upstream_deactivate_dependency_project_timeline. |
| 424 |
*/ |
| 425 |
function upstream_deactivate_dependency_project_timeline() { |
| 426 |
deactivate_plugins( |
| 427 |
array( |
| 428 |
'UpStream-Project-Timeline/upstream-project-timeline.php', |
| 429 |
'upstream-project-timeline/upstream-project-timeline.php', |
| 430 |
) |
| 431 |
); |
| 432 |
} |
| 433 |
|
| 434 |
/** |
| 435 |
* Upstream_deactivate_dependency_frontend_edit. |
| 436 |
*/ |
| 437 |
function upstream_deactivate_dependency_frontend_edit() { |
| 438 |
deactivate_plugins( |
| 439 |
array( |
| 440 |
'UpStream-Frontend-Edit/upstream-frontend-edit.php', |
| 441 |
'upstream-frontend-edit/upstream-frontend-edit.php', |
| 442 |
) |
| 443 |
); |
| 444 |
} |
| 445 |
|
| 446 |
/** |
| 447 |
* Upstream_deactivate_dependency_email_notifications. |
| 448 |
*/ |
| 449 |
function upstream_deactivate_dependency_email_notifications() { |
| 450 |
deactivate_plugins( |
| 451 |
array( |
| 452 |
'UpStream-Email-Notifications/upstream-email-notifications.php', |
| 453 |
'upstream-email-notifications/upstream-email-notifications.php', |
| 454 |
) |
| 455 |
); |
| 456 |
} |
| 457 |
|
| 458 |
/** |
| 459 |
* Upstream_deactivate_dependency_customizer. |
| 460 |
*/ |
| 461 |
function upstream_deactivate_dependency_customizer() { |
| 462 |
deactivate_plugins( |
| 463 |
array( |
| 464 |
'UpStream-Customizer/upstream-customizer.php', |
| 465 |
'upstream-customizer/upstream-customizer.php', |
| 466 |
) |
| 467 |
); |
| 468 |
} |
| 469 |
|
| 470 |
/** |
| 471 |
* Upstream_deactivate_dependency_custom_fields. |
| 472 |
*/ |
| 473 |
function upstream_deactivate_dependency_custom_fields() { |
| 474 |
deactivate_plugins( |
| 475 |
array( |
| 476 |
'UpStream-Custom-Fields/upstream-custom-fields.php', |
| 477 |
'upstream-custom-fields/upstream-custom-fields.php', |
| 478 |
) |
| 479 |
); |
| 480 |
} |
| 481 |
|
| 482 |
/** |
| 483 |
* Upstream_deactivate_dependency_name_replacement. |
| 484 |
*/ |
| 485 |
function upstream_deactivate_dependency_name_replacement() { |
| 486 |
deactivate_plugins( |
| 487 |
array( |
| 488 |
'UpStream-Naming/upstream-name-replacement.php', |
| 489 |
'upstream-name-replacement/upstream-name-replacement.php', |
| 490 |
) |
| 491 |
); |
| 492 |
} |
| 493 |
|
| 494 |
/** |
| 495 |
* Upstream_deactivate_dependency_reporting. |
| 496 |
*/ |
| 497 |
function upstream_deactivate_dependency_reporting() { |
| 498 |
deactivate_plugins( |
| 499 |
array( |
| 500 |
'UpStream-Reporting/upstream-reporting.php', |
| 501 |
'upstream-reporting/upstream-reporting.php', |
| 502 |
) |
| 503 |
); |
| 504 |
} |
| 505 |
|
| 506 |
/** |
| 507 |
* Upstream_deactivate_dependency_time_tracking_budgeting. |
| 508 |
*/ |
| 509 |
function upstream_deactivate_dependency_time_tracking_budgeting() { |
| 510 |
deactivate_plugins( |
| 511 |
array( |
| 512 |
'UpStream-Time-Tracking-and-Budgeting/upstream-time-tracking.php', |
| 513 |
'upstream-time-tracking/upstream-time-tracking.php', |
| 514 |
) |
| 515 |
); |
| 516 |
} |
| 517 |
|
| 518 |
/** |
| 519 |
* Upstream_add_default_options. |
| 520 |
*/ |
| 521 |
function upstream_add_default_options() { |
| 522 |
// general options. |
| 523 |
$general = get_option( 'upstream_general' ); |
| 524 |
if ( ! $general || empty( $general ) ) { |
| 525 |
$general['project']['single'] = 'Project'; |
| 526 |
$general['project']['plural'] = 'Projects'; |
| 527 |
$general['client']['single'] = 'Client'; |
| 528 |
$general['client']['plural'] = 'Clients'; |
| 529 |
$general['milestone']['single'] = 'Milestone'; |
| 530 |
$general['milestone']['plural'] = 'Milestones'; |
| 531 |
$general['milestone_category']['single'] = 'Milestone Category'; |
| 532 |
$general['milestone_category']['plural'] = 'Milestone Categories'; |
| 533 |
$general['task']['single'] = 'Task'; |
| 534 |
$general['task']['plural'] = 'Tasks'; |
| 535 |
$general['bug']['single'] = 'Bug'; |
| 536 |
$general['bug']['plural'] = 'Bugs'; |
| 537 |
$general['file']['single'] = 'File'; |
| 538 |
$general['file']['plural'] = 'Files'; |
| 539 |
|
| 540 |
$general['login_heading'] = 'Project Login'; |
| 541 |
$general['admin_email'] = get_bloginfo( 'admin_email' ); |
| 542 |
|
| 543 |
update_option( 'upstream_general', $general ); |
| 544 |
} |
| 545 |
|
| 546 |
$cached_ids = array(); |
| 547 |
$generate_random_id = function () use ( &$cached_ids ) { |
| 548 |
do { |
| 549 |
$random_id = upstream_generate_random_string( 5, 'abcdefghijklmnopqrstuvwxyz0123456789' ); |
| 550 |
} while ( isset( $cached_ids[ $random_id ] ) ); // Isset is faster than in_array in this case. |
| 551 |
|
| 552 |
$cached_ids[ $random_id ] = null; |
| 553 |
|
| 554 |
return $random_id; |
| 555 |
}; |
| 556 |
|
| 557 |
// project options. |
| 558 |
$projects = get_option( 'upstream_projects' ); |
| 559 |
if ( ! $projects || empty( $projects ) ) { |
| 560 |
$projects['statuses'][0]['name'] = 'In Progress'; |
| 561 |
$projects['statuses'][0]['color'] = '#5cbfd1'; |
| 562 |
$projects['statuses'][0]['type'] = 'open'; |
| 563 |
$projects['statuses'][0]['id'] = $generate_random_id(); |
| 564 |
|
| 565 |
$projects['statuses'][1]['name'] = 'Overdue'; |
| 566 |
$projects['statuses'][1]['color'] = '#d15d5c'; |
| 567 |
$projects['statuses'][1]['type'] = 'open'; |
| 568 |
$projects['statuses'][1]['id'] = $generate_random_id(); |
| 569 |
|
| 570 |
$projects['statuses'][2]['name'] = 'Closed'; |
| 571 |
$projects['statuses'][2]['color'] = '#6b6b6b'; |
| 572 |
$projects['statuses'][2]['type'] = 'closed'; |
| 573 |
$projects['statuses'][2]['id'] = $generate_random_id(); |
| 574 |
|
| 575 |
update_option( 'upstream_projects', $projects ); |
| 576 |
} |
| 577 |
|
| 578 |
// task options. |
| 579 |
$tasks = get_option( 'upstream_tasks' ); |
| 580 |
if ( ! $tasks || empty( $tasks ) ) { |
| 581 |
$tasks['statuses'][0]['name'] = 'In Progress'; |
| 582 |
$tasks['statuses'][0]['color'] = '#5cbfd1'; |
| 583 |
$tasks['statuses'][0]['type'] = 'open'; |
| 584 |
$tasks['statuses'][0]['id'] = $generate_random_id(); |
| 585 |
|
| 586 |
$tasks['statuses'][1]['name'] = 'Overdue'; |
| 587 |
$tasks['statuses'][1]['color'] = '#d15d5c'; |
| 588 |
$tasks['statuses'][1]['type'] = 'open'; |
| 589 |
$tasks['statuses'][1]['id'] = $generate_random_id(); |
| 590 |
|
| 591 |
$tasks['statuses'][2]['name'] = 'Completed'; |
| 592 |
$tasks['statuses'][2]['color'] = '#5cd165'; |
| 593 |
$tasks['statuses'][2]['type'] = 'closed'; |
| 594 |
$tasks['statuses'][2]['id'] = $generate_random_id(); |
| 595 |
|
| 596 |
$tasks['statuses'][3]['name'] = 'Closed'; |
| 597 |
$tasks['statuses'][3]['color'] = '#6b6b6b'; |
| 598 |
$tasks['statuses'][3]['type'] = 'closed'; |
| 599 |
$tasks['statuses'][3]['id'] = $generate_random_id(); |
| 600 |
|
| 601 |
update_option( 'upstream_tasks', $tasks ); |
| 602 |
} |
| 603 |
|
| 604 |
// bug options. |
| 605 |
$bugs = get_option( 'upstream_bugs' ); |
| 606 |
if ( ! $bugs || empty( $bugs ) ) { |
| 607 |
$bugs['statuses'][0]['name'] = 'In Progress'; |
| 608 |
$bugs['statuses'][0]['color'] = '#5cbfd1'; |
| 609 |
$bugs['statuses'][0]['type'] = 'open'; |
| 610 |
$bugs['statuses'][0]['id'] = $generate_random_id(); |
| 611 |
|
| 612 |
$bugs['statuses'][1]['name'] = 'Overdue'; |
| 613 |
$bugs['statuses'][1]['color'] = '#d15d5c'; |
| 614 |
$bugs['statuses'][1]['type'] = 'open'; |
| 615 |
$bugs['statuses'][1]['id'] = $generate_random_id(); |
| 616 |
|
| 617 |
$bugs['statuses'][2]['name'] = 'Completed'; |
| 618 |
$bugs['statuses'][2]['color'] = '#5cd165'; |
| 619 |
$bugs['statuses'][2]['type'] = 'closed'; |
| 620 |
$bugs['statuses'][2]['id'] = $generate_random_id(); |
| 621 |
|
| 622 |
$bugs['statuses'][3]['name'] = 'Closed'; |
| 623 |
$bugs['statuses'][3]['color'] = '#6b6b6b'; |
| 624 |
$bugs['statuses'][3]['type'] = 'closed'; |
| 625 |
$bugs['statuses'][3]['id'] = $generate_random_id(); |
| 626 |
|
| 627 |
$bugs['severities'][0]['name'] = 'Critical'; |
| 628 |
$bugs['severities'][0]['color'] = '#d15d5c'; |
| 629 |
$bugs['severities'][0]['id'] = $generate_random_id(); |
| 630 |
|
| 631 |
$bugs['severities'][1]['name'] = 'Standard'; |
| 632 |
$bugs['severities'][1]['color'] = '#d17f5c'; |
| 633 |
$bugs['severities'][1]['id'] = $generate_random_id(); |
| 634 |
|
| 635 |
$bugs['severities'][2]['name'] = 'Minor'; |
| 636 |
$bugs['severities'][2]['color'] = '#d1a65c'; |
| 637 |
$bugs['severities'][2]['id'] = $generate_random_id(); |
| 638 |
|
| 639 |
update_option( 'upstream_bugs', $bugs ); |
| 640 |
} |
| 641 |
} |
| 642 |
|
| 643 |
|
| 644 |
if ( version_compare( get_bloginfo( 'version' ), '5.1', '>=' ) ) { |
| 645 |
|
| 646 |
/** |
| 647 |
* Upstream_new_blog_created |
| 648 |
* |
| 649 |
* @param string $site Site name. |
| 650 |
*/ |
| 651 |
function upstream_new_blog_created( $site ) { |
| 652 |
upstream_install_debug( 'upstream_new_blog_created ' . $site ); |
| 653 |
|
| 654 |
$blog_id = $site->blog_id; |
| 655 |
|
| 656 |
if ( is_plugin_active_for_network( plugin_basename( UPSTREAM_PLUGIN_FILE ) ) ) { |
| 657 |
|
| 658 |
upstream_install_debug( 'switch_to_blog' ); |
| 659 |
switch_to_blog( $blog_id ); |
| 660 |
|
| 661 |
upstream_install_debug( 'upstream_install' ); |
| 662 |
upstream_install(); |
| 663 |
|
| 664 |
upstream_install_debug( 'restore_current_blog' ); |
| 665 |
restore_current_blog(); |
| 666 |
} |
| 667 |
} |
| 668 |
|
| 669 |
add_action( 'wp_insert_site', 'upstream_new_blog_created', 10, 6 ); |
| 670 |
|
| 671 |
} else { |
| 672 |
|
| 673 |
/** |
| 674 |
* When a new Blog is created in multisite, see if UpStream is network activated, and run the installer |
| 675 |
* |
| 676 |
* @param int $blog_id The Blog ID created. |
| 677 |
* @param int $user_id The User ID set as the admin. |
| 678 |
* @param string $domain The URL. |
| 679 |
* @param string $path Site Path. |
| 680 |
* @param int $site_id The Site ID. |
| 681 |
* @param array $meta Blog Meta. |
| 682 |
* |
| 683 |
* @return void |
| 684 |
* @since 1.0.0 |
| 685 |
*/ |
| 686 |
function upstream_new_blog_created( $blog_id, $user_id, $domain, $path, $site_id, $meta ) { |
| 687 |
up_debug(); |
| 688 |
|
| 689 |
if ( is_plugin_active_for_network( plugin_basename( UPSTREAM_PLUGIN_FILE ) ) ) { |
| 690 |
switch_to_blog( $blog_id ); |
| 691 |
upstream_install(); |
| 692 |
restore_current_blog(); |
| 693 |
} |
| 694 |
} |
| 695 |
|
| 696 |
add_action( 'wpmu_new_blog', 'upstream_new_blog_created', 10, 6 ); |
| 697 |
|
| 698 |
} |
| 699 |
|
| 700 |
/** |
| 701 |
* Post-installation |
| 702 |
* |
| 703 |
* Runs just after plugin installation and exposes the |
| 704 |
* upstream_after_install hook. |
| 705 |
* |
| 706 |
* @return void |
| 707 |
* @since 1.0.0 |
| 708 |
*/ |
| 709 |
function upstream_after_install() { |
| 710 |
up_debug(); |
| 711 |
|
| 712 |
if ( ! is_admin() ) { |
| 713 |
return; |
| 714 |
} |
| 715 |
|
| 716 |
$activated = get_transient( '_upstream_activation_redirect' ); |
| 717 |
|
| 718 |
if ( false !== $activated ) { |
| 719 |
|
| 720 |
// add the default options. |
| 721 |
// upstream_add_default_project(). |
| 722 |
delete_transient( '_upstream_activation_redirect' ); |
| 723 |
|
| 724 |
if ( ! isset( $_GET['activate-multi'] ) ) { |
| 725 |
set_transient( '_upstream_redirected', true, 360 ); |
| 726 |
wp_redirect( admin_url( 'post-new.php?post_type=project' ) ); |
| 727 |
exit; |
| 728 |
} |
| 729 |
} |
| 730 |
} |
| 731 |
|
| 732 |
add_action( 'admin_init', 'upstream_after_install', 100 ); |
| 733 |
|
| 734 |
|
| 735 |
/** |
| 736 |
* Show a success notice after install and redirect. |
| 737 |
*/ |
| 738 |
function upstream_install_success_notice() { |
| 739 |
up_debug(); |
| 740 |
|
| 741 |
$redirected = get_transient( '_upstream_redirected' ); |
| 742 |
$get_data = isset( $_GET ) ? wp_unslash( $_GET ) : array(); |
| 743 |
|
| 744 |
if ( false !== $redirected && isset( $get_data['page'] ) && sanitize_text_field( $get_data['page'] ) == 'upstream_general' ) { |
| 745 |
// Delete the transient. |
| 746 |
// delete_transient( '_upstream_redirected' ). |
| 747 |
|
| 748 |
$class = 'notice notice-info is-dismissible'; |
| 749 |
$message = '<strong>' . __( 'Success! UpStream is up and running.', 'upstream' ) . '</strong><br>'; |
| 750 |
$message .= __( |
| 751 |
'Step 1. Please go through each settings tab below and configure the options.', |
| 752 |
'upstream' |
| 753 |
) . '<br>'; |
| 754 |
$message .= __( |
| 755 |
'Step 2. Add a new Client by navigating to <strong>Projects > New Client</strong>', |
| 756 |
'upstream' |
| 757 |
) . '<br>'; |
| 758 |
$message .= __( |
| 759 |
'Step 3. Add your first Project by navigating to <strong>Projects > New Project</strong>', |
| 760 |
'upstream' |
| 761 |
) . '<br>'; |
| 762 |
|
| 763 |
printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), esc_html( $message ) ); |
| 764 |
} |
| 765 |
} |
| 766 |
|
| 767 |
add_action( 'admin_notices', 'upstream_install_success_notice' ); |
| 768 |
|
| 769 |
|
| 770 |
/** |
| 771 |
* The original data update function. This is superceded by rev2 as of version 1.27. |
| 772 |
* |
| 773 |
* @param string $old_version The old_version. |
| 774 |
* @param string $new_version The new_version. |
| 775 |
* @throws Exception Exception. |
| 776 |
*/ |
| 777 |
function upstream_update_data( $old_version, $new_version ) { |
| 778 |
up_debug(); |
| 779 |
|
| 780 |
// Ignore if we are on the same version. |
| 781 |
if ( $old_version === $new_version ) { |
| 782 |
return; |
| 783 |
} |
| 784 |
|
| 785 |
if ( version_compare( $new_version, '1.22.0', '=' ) ) { |
| 786 |
// Make sure administrator and managers are able to. |
| 787 |
$roles = array( |
| 788 |
'upstream_manager', |
| 789 |
'administrator', |
| 790 |
'upstream_user', |
| 791 |
); |
| 792 |
|
| 793 |
foreach ( $roles as $role ) { |
| 794 |
$role = get_role( $role ); |
| 795 |
|
| 796 |
if ( is_object( $role ) ) { |
| 797 |
$role->add_cap( 'project_title_field', true ); |
| 798 |
$role->add_cap( 'project_status_field', true ); |
| 799 |
$role->add_cap( 'project_owner_field', true ); |
| 800 |
$role->add_cap( 'project_client_field', true ); |
| 801 |
$role->add_cap( 'project_users_field', true ); |
| 802 |
$role->add_cap( 'project_start_date_field', true ); |
| 803 |
$role->add_cap( 'project_end_date_field', true ); |
| 804 |
} |
| 805 |
} |
| 806 |
} |
| 807 |
|
| 808 |
if ( version_compare( $old_version, '1.22.1', '<' ) ) { |
| 809 |
// Force to fix bug statuses and severities with empty ID. |
| 810 |
delete_option( 'upstream:created_bugs_args_ids' ); |
| 811 |
|
| 812 |
UpStream_Options_Bugs::create_bugs_statuses_ids(); |
| 813 |
} |
| 814 |
|
| 815 |
$has_finished_migration = get_option( '_upstream_migration_finished_1.24.0', null ); |
| 816 |
if ( empty( $has_finished_migration ) && version_compare( $old_version, '1.24.0', '<' ) ) { |
| 817 |
$this->upstreamMilestoneTags(); |
| 818 |
|
| 819 |
// Default labels for Milestone Categories. |
| 820 |
$general = get_option( 'upstream_general' ); |
| 821 |
|
| 822 |
$general['milestone_category']['single'] = 'Milestone Category'; |
| 823 |
$general['milestone_category']['plural'] = 'Milestone Categories'; |
| 824 |
|
| 825 |
update_option( 'upstream_general', $general ); |
| 826 |
|
| 827 |
// Make sure administrator and managers are able to work with the new milestones. |
| 828 |
$roles = array( |
| 829 |
'upstream_manager', |
| 830 |
'administrator', |
| 831 |
'upstream_user', |
| 832 |
); |
| 833 |
|
| 834 |
foreach ( $roles as $role ) { |
| 835 |
$role = get_role( $role ); |
| 836 |
|
| 837 |
if ( is_object( $role ) ) { |
| 838 |
$capabilities = array( |
| 839 |
// Post type. |
| 840 |
'edit_milestone', |
| 841 |
'read_milestone', |
| 842 |
'delete_milestone', |
| 843 |
'edit_milestones', |
| 844 |
'edit_others_milestones', |
| 845 |
'publish_milestones', |
| 846 |
'read_private_milestones', |
| 847 |
'delete_milestones', |
| 848 |
'delete_private_milestones', |
| 849 |
'delete_published_milestones', |
| 850 |
'delete_others_milestones', |
| 851 |
'edit_private_milestones', |
| 852 |
'edit_published_milestones', |
| 853 |
|
| 854 |
// Terms. |
| 855 |
'manage_milestone_terms', |
| 856 |
'edit_milestone_terms', |
| 857 |
'delete_milestone_terms', |
| 858 |
'assign_milestone_terms', |
| 859 |
); |
| 860 |
|
| 861 |
foreach ( $capabilities as $capability ) { |
| 862 |
$role->add_cap( $capability, true ); |
| 863 |
} |
| 864 |
} |
| 865 |
} |
| 866 |
|
| 867 |
// If we have projects, create new milestones based on current ones. |
| 868 |
$projects = get_posts( |
| 869 |
array( |
| 870 |
'post_type' => 'project', |
| 871 |
'post_status' => 'any', |
| 872 |
'posts_per_page' => -1, |
| 873 |
'meta_query' => array( |
| 874 |
'relation' => 'OR', |
| 875 |
array( |
| 876 |
'key' => '_upstream_milestones_migrated', |
| 877 |
'compare' => 'NOT EXISTS', |
| 878 |
), |
| 879 |
array( |
| 880 |
'key' => '_upstream_milestones_migrated', |
| 881 |
'value' => 1, |
| 882 |
'compare' => '!=', |
| 883 |
), |
| 884 |
), |
| 885 |
) |
| 886 |
); |
| 887 |
|
| 888 |
if ( ! empty( $projects ) ) { |
| 889 |
// Migrate the milestones. |
| 890 |
$default_milestones = get_option( 'upstream_milestones', array() ); |
| 891 |
|
| 892 |
if ( ! empty( $default_milestones ) ) { |
| 893 |
foreach ( $projects as $project ) { |
| 894 |
\UpStream\Milestones::migrate_legacy_milestones_for_project( $project->ID ); |
| 895 |
} |
| 896 |
} |
| 897 |
} |
| 898 |
|
| 899 |
update_option( '_upstream_migration_finished_1.24.0', true ); |
| 900 |
} |
| 901 |
|
| 902 |
$has_finished_migration = get_option( '_upstream_migration_finished_1.24.1', null ); |
| 903 |
if ( empty( $has_finished_migration ) && version_compare( $old_version, '1.24.1', '<' ) ) { |
| 904 |
// If we have unpublished projects, create new milestones based on current ones. |
| 905 |
$projects = get_posts( |
| 906 |
array( |
| 907 |
'post_type' => 'project', |
| 908 |
'post_status' => 'any', |
| 909 |
'posts_per_page' => -1, |
| 910 |
'meta_query' => array( |
| 911 |
'relation' => 'OR', |
| 912 |
array( |
| 913 |
'key' => '_upstream_milestones_migrated', |
| 914 |
'compare' => 'NOT EXISTS', |
| 915 |
), |
| 916 |
array( |
| 917 |
'key' => '_upstream_milestones_migrated', |
| 918 |
'value' => 1, |
| 919 |
'compare' => '!=', |
| 920 |
), |
| 921 |
), |
| 922 |
) |
| 923 |
); |
| 924 |
|
| 925 |
if ( ! empty( $projects ) ) { |
| 926 |
// Migrate the milestones. |
| 927 |
$default_milestones = get_option( 'upstream_milestones', array() ); |
| 928 |
|
| 929 |
if ( ! empty( $default_milestones ) ) { |
| 930 |
foreach ( $projects as $project ) { |
| 931 |
\UpStream\Milestones::migrate_legacy_milestones_for_project( $project->ID ); |
| 932 |
} |
| 933 |
} |
| 934 |
} |
| 935 |
|
| 936 |
update_option( '_upstream_migration_finished_1.24.1', true ); |
| 937 |
} |
| 938 |
|
| 939 |
$version = '1.24.2'; |
| 940 |
$migration_option = '_upstream_migration_finished_' . $version; |
| 941 |
$has_finished_migration = get_option( $migration_option, null ); |
| 942 |
if ( empty( $has_finished_migration ) && version_compare( $old_version, $version, '<' ) ) { |
| 943 |
// If we have unpublished projects, create new milestones based on current ones. |
| 944 |
$projects = get_posts( |
| 945 |
array( |
| 946 |
'post_type' => 'project', |
| 947 |
'post_status' => 'any', |
| 948 |
'posts_per_page' => -1, |
| 949 |
) |
| 950 |
); |
| 951 |
|
| 952 |
if ( ! empty( $projects ) ) { |
| 953 |
foreach ( $projects as $project ) { |
| 954 |
\UpStream\Milestones::fix_milestone_orders_on_project( $project->ID ); |
| 955 |
} |
| 956 |
} |
| 957 |
|
| 958 |
update_option( $migration_option, true ); |
| 959 |
} |
| 960 |
|
| 961 |
// do the first new migration to get everything to 1.27. |
| 962 |
|
| 963 |
$migration_id = 'M0000001'; |
| 964 |
$migration_option = '_upstream_migration_finished_' . $migration_id; |
| 965 |
$has_finished_migration = get_option( $migration_option, null ); |
| 966 |
if ( empty( $has_finished_migration ) ) { |
| 967 |
|
| 968 |
if ( ! class_exists( 'Upstream_Counts' ) ) { |
| 969 |
include_once UPSTREAM_PLUGIN_DIR . '/includes/class-upstream-counts.php'; |
| 970 |
} |
| 971 |
|
| 972 |
$counts = new Upstream_Counts( 0 ); |
| 973 |
$projects = $counts->projects; |
| 974 |
|
| 975 |
if ( ! empty( $projects ) ) { |
| 976 |
foreach ( $projects as $project ) { |
| 977 |
$project_object = new UpStream_Project( $project->ID ); |
| 978 |
$project_object->update_project_meta(); |
| 979 |
} |
| 980 |
} |
| 981 |
|
| 982 |
update_option( $migration_option, true ); |
| 983 |
} |
| 984 |
|
| 985 |
} |
| 986 |
|
| 987 |
/** |
| 988 |
* Show a message if the plugin needs to be reactivated |
| 989 |
*/ |
| 990 |
function upstream_reactivate_notice() { |
| 991 |
up_debug(); |
| 992 |
|
| 993 |
$class = 'notice notice-info is-dismissible'; |
| 994 |
$message = '<strong>' . __( 'UpStream needs to be reactivated.', 'upstream' ) . '</strong><br>'; |
| 995 |
$message .= __( |
| 996 |
'In order to complete the upgrade to this version, you will need to deactivate and re-activate Upstream. Make sure Remove Data under the UpStream menu is unchecked so you do not lose any data.', |
| 997 |
'upstream' |
| 998 |
) . '<br>'; |
| 999 |
|
| 1000 |
printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), esc_html( $message ) ); |
| 1001 |
} |
| 1002 |
|
| 1003 |
|
| 1004 |
/** |
| 1005 |
* This is a replacement for upstream_update_data(). It is used to update any data from the |
| 1006 |
* 1.27 release and after. |
| 1007 |
* |
| 1008 |
* @since 1.27 |
| 1009 |
*/ |
| 1010 |
function upstream_update_data_rev_2() { |
| 1011 |
if ( ! is_admin() || ! current_user_can( 'activate_plugins' ) ) { |
| 1012 |
return; |
| 1013 |
} |
| 1014 |
|
| 1015 |
$current_version = get_option( 'upstream_version', false ); |
| 1016 |
|
| 1017 |
if ( empty( $current_version ) ) { |
| 1018 |
|
| 1019 |
// if current version is not set, this is a new install. |
| 1020 |
return; |
| 1021 |
|
| 1022 |
} elseif ( UPSTREAM_VERSION === $current_version ) { |
| 1023 |
|
| 1024 |
// already at current verison... check if last migration was done |
| 1025 |
// (meaning all should have been done) otherwise return. |
| 1026 |
|
| 1027 |
$migration_id = 'M0000002'; |
| 1028 |
$migration_option = '_upstream_migration_finished_' . $migration_id; |
| 1029 |
$has_finished_migration = get_option( $migration_option, null ); |
| 1030 |
|
| 1031 |
if ( $has_finished_migration ) { |
| 1032 |
return; |
| 1033 |
} else { |
| 1034 |
$has_finished_migration = false; |
| 1035 |
} |
| 1036 |
} elseif ( version_compare( $current_version, '1.26.0', '<' ) ) { |
| 1037 |
|
| 1038 |
// if current version is less than 1.26 don't use this function at all |
| 1039 |
// wait until someone reactivates the plugin and then this function can run. |
| 1040 |
add_action( 'admin_notices', 'upstream_reactivate_notice' ); |
| 1041 |
|
| 1042 |
return; |
| 1043 |
} |
| 1044 |
|
| 1045 |
$migration_id = 'M0000001'; |
| 1046 |
$migration_option = '_upstream_migration_finished_' . $migration_id; |
| 1047 |
$has_finished_migration = get_option( $migration_option, null ); |
| 1048 |
if ( empty( $has_finished_migration ) ) { |
| 1049 |
|
| 1050 |
if ( ! class_exists( 'Upstream_Counts' ) ) { |
| 1051 |
include_once UPSTREAM_PLUGIN_DIR . '/includes/class-upstream-counts.php'; |
| 1052 |
} |
| 1053 |
|
| 1054 |
$counts = new Upstream_Counts( 0 ); |
| 1055 |
$projects = $counts->projects; |
| 1056 |
|
| 1057 |
if ( ! empty( $projects ) ) { |
| 1058 |
foreach ( $projects as $project ) { |
| 1059 |
$project_object = new UpStream_Project( $project->ID ); |
| 1060 |
$project_object->update_project_meta(); |
| 1061 |
} |
| 1062 |
} |
| 1063 |
|
| 1064 |
update_option( $migration_option, true ); |
| 1065 |
} |
| 1066 |
|
| 1067 |
$migration_id = 'M0000002'; |
| 1068 |
$migration_option = '_upstream_migration_finished_' . $migration_id; |
| 1069 |
$has_finished_migration = get_option( $migration_option, null ); |
| 1070 |
if ( empty( $has_finished_migration ) ) { |
| 1071 |
|
| 1072 |
global $wpdb; |
| 1073 |
|
| 1074 |
require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
| 1075 |
|
| 1076 |
if ( function_exists( 'maybe_create_table' ) ) { |
| 1077 |
$sql = 'CREATE TABLE ' . $wpdb->prefix . 'upfs_files ( upfsid VARCHAR(60), orig_filename VARCHAR(255), saved_filename VARCHAR(255), mime_type VARCHAR(255), file_size INT, access_rules TEXT, PRIMARY KEY (upfsid) )'; |
| 1078 |
$r = maybe_create_table( $wpdb->prefix . 'upfs_files', $sql ); |
| 1079 |
} |
| 1080 |
|
| 1081 |
update_option( $migration_option, true ); |
| 1082 |
} |
| 1083 |
|
| 1084 |
// if we made any migrations, update the upstream version to the current one. |
| 1085 |
update_option( 'upstream_version_upgraded_from', $current_version ); |
| 1086 |
update_option( 'upstream_version', UPSTREAM_VERSION ); |
| 1087 |
|
| 1088 |
} |
| 1089 |
|
| 1090 |
add_action( 'admin_init', 'upstream_update_data_rev_2', 90 ); |
| 1091 |
|
| 1092 |
|
| 1093 |
/** |
| 1094 |
* Upstream_change_role_name |
| 1095 |
*/ |
| 1096 |
function upstream_change_role_name() { |
| 1097 |
global $wp_roles; |
| 1098 |
|
| 1099 |
if ( ! isset( $wp_roles ) ) { |
| 1100 |
$wp_roles_obj = new WP_Roles(); |
| 1101 |
} else { |
| 1102 |
$wp_roles_obj = $wp_roles; |
| 1103 |
} |
| 1104 |
|
| 1105 |
$wp_roles_obj->roles['upstream_client_user']['name'] = __( 'UpStream Client User', 'upstream' ); |
| 1106 |
$wp_roles_obj->role_names['upstream_client_user'] = __( 'UpStream Client User', 'upstream' ); |
| 1107 |
|
| 1108 |
} |
| 1109 |
add_action( 'init', 'upstream_change_role_name' ); |
| 1110 |
|