| 1 |
<?php |
| 2 |
/** |
| 3 |
* Main Upgrade class. |
| 4 |
* |
| 5 |
* @package RadiusTheme\SB |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace RadiusTheme\SB\Controllers\Admin\Notice; |
| 9 |
|
| 10 |
use RadiusTheme\SB\Traits\SingletonTrait; |
| 11 |
|
| 12 |
// Do not allow directly accessing this file. |
| 13 |
if ( ! defined( 'ABSPATH' ) ) { |
| 14 |
exit( 'This script cannot be accessed directly.' ); |
| 15 |
} |
| 16 |
|
| 17 |
/** |
| 18 |
* Main Upgrade class. |
| 19 |
*/ |
| 20 |
class Upgrade { |
| 21 |
/** |
| 22 |
* Singleton Trait. |
| 23 |
*/ |
| 24 |
use SingletonTrait; |
| 25 |
|
| 26 |
/** |
| 27 |
* Class Constructor. |
| 28 |
*/ |
| 29 |
private function __construct() { |
| 30 |
add_action( 'admin_head', [ $this, 'upgrade_styles' ] ); |
| 31 |
add_action( |
| 32 |
'in_plugin_update_message-' . RTSB_ACTIVE_FILE_NAME, |
| 33 |
function ( $plugin_data ) { |
| 34 |
$this->version_update_warning( RTSB_VERSION, $plugin_data['new_version'] ); |
| 35 |
} |
| 36 |
); |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Update message |
| 41 |
* |
| 42 |
* @param int $current_version Current Version. |
| 43 |
* @param int $new_version New Version. |
| 44 |
* |
| 45 |
* @return void |
| 46 |
*/ |
| 47 |
public function version_update_warning( $current_version, $new_version ) { |
| 48 |
$current_version_crit = explode( '.', $current_version )[0]; |
| 49 |
$new_version_crit = explode( '.', $new_version )[0]; |
| 50 |
$current_version_major = explode( '.', $current_version )[1]; |
| 51 |
$new_version_major = explode( '.', $new_version )[1]; |
| 52 |
|
| 53 |
if ( $current_version_crit === $new_version_crit ) { |
| 54 |
if ( $current_version_major === $new_version_major ) { |
| 55 |
return; |
| 56 |
} |
| 57 |
} |
| 58 |
?> |
| 59 |
<div class="rtsb-major-update-warning"> |
| 60 |
<div class="rtsb-major-update-icon"> |
| 61 |
<i class="dashicons dashicons-info"></i> |
| 62 |
</div> |
| 63 |
<div> |
| 64 |
<div class="rtsb-major-update-title"> |
| 65 |
<?php |
| 66 |
printf( |
| 67 |
'%s%s.', |
| 68 |
esc_html__( 'Heads up, Please backup before upgrade to version ', 'shopbuilder' ), |
| 69 |
esc_html( $new_version ) |
| 70 |
); |
| 71 |
?> |
| 72 |
</div> |
| 73 |
<div class="rtsb-major-update-message"> |
| 74 |
The latest update includes some substantial changes across different areas of the plugin. <br/>We |
| 75 |
highly recommend you to <b>backup your site before upgrading</b>, and make sure you first update in a staging environment. |
| 76 |
</div> |
| 77 |
</div> |
| 78 |
</div> |
| 79 |
<?php |
| 80 |
} |
| 81 |
|
| 82 |
/** |
| 83 |
* Admin styles. |
| 84 |
* |
| 85 |
* @return void |
| 86 |
*/ |
| 87 |
public function upgrade_styles() { |
| 88 |
global $pagenow; |
| 89 |
|
| 90 |
if ( 'plugins.php' !== $pagenow ) { |
| 91 |
return; |
| 92 |
} |
| 93 |
|
| 94 |
echo '<style> |
| 95 |
.rtsb-major-update-warning { |
| 96 |
border-top: 2px solid #d63638; |
| 97 |
padding-top: 15px; |
| 98 |
margin-top: 15px; |
| 99 |
margin-bottom: 15px; |
| 100 |
display: flex; |
| 101 |
} |
| 102 |
|
| 103 |
.rtsb-major-update-icon i { |
| 104 |
color: #d63638; |
| 105 |
margin-right: 8px; |
| 106 |
} |
| 107 |
|
| 108 |
.rtsb-major-update-warning + p { |
| 109 |
display: none; |
| 110 |
} |
| 111 |
|
| 112 |
.rtsb-major-update-title { |
| 113 |
font-weight: 600; |
| 114 |
margin-bottom: 10px; |
| 115 |
} |
| 116 |
|
| 117 |
.notice-success .rtsb-major-update-warning { |
| 118 |
border-color: #46b450; |
| 119 |
} |
| 120 |
|
| 121 |
.notice-success .rtsb-major-update-icon i { |
| 122 |
color: #79ba49; |
| 123 |
} |
| 124 |
</style>'; |
| 125 |
} |
| 126 |
} |
| 127 |
|