| 1 |
<?php |
| 2 |
/** |
| 3 |
* MainWP WP Updates Page. |
| 4 |
* |
| 5 |
* @package MainWP/Dashboard |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace MainWP\Dashboard; |
| 9 |
|
| 10 |
// Exit if accessed directly. |
| 11 |
if ( ! defined( 'ABSPATH' ) ) { |
| 12 |
exit; |
| 13 |
} |
| 14 |
|
| 15 |
/** |
| 16 |
* Class MainWP_WP_Updates |
| 17 |
* |
| 18 |
* @package MainWP\Dashboard\ |
| 19 |
*/ |
| 20 |
class MainWP_WP_Updates { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR. |
| 21 |
|
| 22 |
/** |
| 23 |
* Private static variable to hold the single instance of the class. |
| 24 |
* |
| 25 |
* @static |
| 26 |
* |
| 27 |
* @var mixed Default null |
| 28 |
*/ |
| 29 |
private static $instance = null; |
| 30 |
|
| 31 |
/** |
| 32 |
* Method instance() |
| 33 |
* |
| 34 |
* Create public static instance. |
| 35 |
* |
| 36 |
* @static |
| 37 |
* @return MainWP_Utility |
| 38 |
*/ |
| 39 |
public static function instance() { |
| 40 |
if ( null === static::$instance ) { |
| 41 |
static::$instance = new self(); |
| 42 |
} |
| 43 |
|
| 44 |
return static::$instance; |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Get Class Name. |
| 49 |
* |
| 50 |
* @return string __CLASS__ |
| 51 |
*/ |
| 52 |
public static function get_class_name() { |
| 53 |
return __CLASS__; |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Render Ignore Subpage. |
| 58 |
* |
| 59 |
* @param array $websites Object containing child sites info. |
| 60 |
* @param object $userExtension User extension. |
| 61 |
*/ |
| 62 |
public function render_ignore( $websites, $userExtension ) { |
| 63 |
|
| 64 |
$decodedIgnoredCores = ! empty( $userExtension->ignored_wp_upgrades ) ? json_decode( $userExtension->ignored_wp_upgrades, true ) : array(); |
| 65 |
|
| 66 |
if ( ! is_array( $decodedIgnoredCores ) ) { |
| 67 |
$decodedIgnoredCores = array(); |
| 68 |
} |
| 69 |
|
| 70 |
?> |
| 71 |
<div id="mainwp-ignored-cores" class="ui segment"> |
| 72 |
<?php if ( MainWP_Utility::show_mainwp_message( 'notice', 'mainwp-ignored-cores-info-message' ) ) : ?> |
| 73 |
<div class="ui info message"> |
| 74 |
<i class="close icon mainwp-notice-dismiss" notice-id="mainwp-ignored-cores-info-message"></i> |
| 75 |
<?php /* translators: 1: opening anchor tag, 2: closing anchor tag */ printf( esc_html__( 'Manage WordPress you have told your MainWP Dashboard to ignore updates on global or per site level. For additional help, please check this %1$shelp documentation%2$s.', 'mainwp' ), '<a href="https://docs.mainwp.com/sites/updates/manage-updates/" target="_blank">', '</a> <i class="external alternate icon"></i>' ); ?> |
| 76 |
</div> |
| 77 |
<?php endif; ?> |
| 78 |
<?php |
| 79 |
/** |
| 80 |
* Action: mainwp_cores_before_ignored_updates |
| 81 |
* |
| 82 |
* Fires on the top of the Ignored Plugin Updates page. |
| 83 |
* |
| 84 |
* @since 5.2 |
| 85 |
*/ |
| 86 |
do_action( 'mainwp_cores_before_ignored_updates', $websites ); |
| 87 |
?> |
| 88 |
<h3 class="ui header"> |
| 89 |
<?php esc_html_e( 'Globally Ignored WordPress', 'mainwp' ); ?> |
| 90 |
<div class="sub header"><?php esc_html_e( 'These are WordPress you have told your MainWP Dashboard to ignore updates on global level and not notify you about pending updates.', 'mainwp' ); ?></div> |
| 91 |
</h3> |
| 92 |
<?php static::render_global_ignored( $decodedIgnoredCores ); ?> |
| 93 |
<div class="ui hidden divider"></div> |
| 94 |
<h3 class="ui header"> |
| 95 |
<?php esc_html_e( 'Per Site Ignored WordPress', 'mainwp' ); ?> |
| 96 |
<div class="sub header"><?php esc_html_e( 'These are WordPress you have told your MainWP Dashboard to ignore updates per site level and not notify you about pending updates.', 'mainwp' ); ?></div> |
| 97 |
</h3> |
| 98 |
<?php static::render_sites_ignored( $websites ); ?> |
| 99 |
<?php |
| 100 |
/** |
| 101 |
* Action: mainwp_cores_after_ignored_updates |
| 102 |
* |
| 103 |
* Fires on the bottom of the Ignored Plugin Updates page. |
| 104 |
* |
| 105 |
* @since 4.1 |
| 106 |
*/ |
| 107 |
do_action( 'mainwp_cores_after_ignored_updates', $websites ); |
| 108 |
?> |
| 109 |
</div> |
| 110 |
<?php |
| 111 |
} |
| 112 |
|
| 113 |
/** |
| 114 |
* Method render_global_ignored() |
| 115 |
* |
| 116 |
* Render Global Ignored cores list. |
| 117 |
* |
| 118 |
* @param array $decodedIgnoredCores Decoded ignored cores array. |
| 119 |
*/ |
| 120 |
public function render_global_ignored( $decodedIgnoredCores ) { //phpcs:ignore -- NOSONAR - complex. |
| 121 |
?> |
| 122 |
<table id="mainwp-globally-ignored-cores" class="ui compact selectable table unstackable"> |
| 123 |
<thead> |
| 124 |
<tr> |
| 125 |
<th scope="col" ><?php esc_html_e( 'Ignored version', 'mainwp' ); ?></th> |
| 126 |
<th scope="col" ></th> |
| 127 |
</tr> |
| 128 |
</thead> |
| 129 |
<tbody id="globally-ignored-cores-list"> |
| 130 |
<?php if ( $decodedIgnoredCores ) : ?> |
| 131 |
<?php // phpcs:disable WordPress.Security.EscapeOutput ?> |
| 132 |
<?php |
| 133 |
$ignored_vers = array(); |
| 134 |
$ig_vers = ! empty( $decodedIgnoredCores['ignored_versions'] ) ? $decodedIgnoredCores['ignored_versions'] : ''; |
| 135 |
if ( ! empty( $ig_vers ) && is_array( $ig_vers ) ) { |
| 136 |
$ignored_vers = $ig_vers; |
| 137 |
} |
| 138 |
?> |
| 139 |
<?php foreach ( $ignored_vers as $ignored_ver ) { ?> |
| 140 |
<tr ignored-ver="<?php echo esc_attr( $ignored_ver ); ?>"> |
| 141 |
<td><?php echo 'all_versions' === $ignored_ver ? esc_html__( 'All', 'mainwp' ) : esc_html( $ignored_ver ); ?></td> |
| 142 |
<td class="right aligned"> |
| 143 |
<?php if ( \mainwp_current_user_can( 'dashboard', 'ignore_unignore_updates' ) ) : ?> |
| 144 |
<a href="#" class="ui mini button" onClick="return updatesoverview_cores_unignore_globally( '<?php echo esc_js( rawurlencode( $ignored_ver ) ); ?>' )"><?php esc_html_e( 'Unignore', 'mainwp' ); ?></a> |
| 145 |
<?php endif; ?> |
| 146 |
</td> |
| 147 |
</tr> |
| 148 |
<?php } ?> |
| 149 |
<?php // phpcs:enable ?> |
| 150 |
<?php endif; ?> |
| 151 |
</tbody> |
| 152 |
<?php if ( \mainwp_current_user_can( 'dashboard', 'ignore_unignore_updates' ) ) : ?> |
| 153 |
<?php if ( $ig_vers ) : ?> |
| 154 |
<tfoot class="full-width"> |
| 155 |
<tr> |
| 156 |
<th scope="col" colspan="2"> |
| 157 |
<a class="ui right floated small green labeled icon button" onClick="return updatesoverview_cores_unignore_globally_all();" id="mainwp-unignore-globally-all"> |
| 158 |
<i class="check icon"></i> <?php esc_html_e( 'Unignore All', 'mainwp' ); ?> |
| 159 |
</a> |
| 160 |
</th> |
| 161 |
</tr> |
| 162 |
</tfoot> |
| 163 |
<?php endif; ?> |
| 164 |
<?php endif; ?> |
| 165 |
</table> |
| 166 |
|
| 167 |
<script type="text/javascript"> |
| 168 |
jQuery( document ).ready( function() { |
| 169 |
jQuery( '#mainwp-globally-ignored-cores' ).DataTable( { |
| 170 |
"searching": false, |
| 171 |
"paging": false, |
| 172 |
"info": false, |
| 173 |
"responsive": true, |
| 174 |
"columnDefs": [ { |
| 175 |
"targets": 'no-sort', |
| 176 |
"orderable": false |
| 177 |
} ], |
| 178 |
"language": { |
| 179 |
"emptyTable": "<?php esc_html_e( 'No ignored WordPress.', 'mainwp' ); ?>" |
| 180 |
} |
| 181 |
} ); |
| 182 |
} ); |
| 183 |
</script> |
| 184 |
<?php |
| 185 |
} |
| 186 |
|
| 187 |
/** |
| 188 |
* Render Per Site Ignored table. |
| 189 |
* |
| 190 |
* @param mixed $websites Child Sites. |
| 191 |
* |
| 192 |
* @return void |
| 193 |
* |
| 194 |
* @uses \MainWP\Dashboard\MainWP_DB::data_seek() |
| 195 |
* @uses \MainWP\Dashboard\MainWP_DB::fetch_object() |
| 196 |
* @uses \MainWP\Dashboard\MainWP_DB::free_result() |
| 197 |
*/ |
| 198 |
public function render_sites_ignored( $websites ) { // phpcs:ignore -- NOSONAR - complex. |
| 199 |
?> |
| 200 |
<table id="mainwp-per-site-ignored-cores" class="ui unstackable compact selectable table "> |
| 201 |
<thead> |
| 202 |
<tr> |
| 203 |
<th scope="col" ><?php esc_html_e( 'Website', 'mainwp' ); ?></th> |
| 204 |
<th scope="col" ><?php esc_html_e( 'Ignored version', 'mainwp' ); ?></th> |
| 205 |
<th scope="col" ><?php esc_html_e( 'Client', 'mainwp' ); ?></th> |
| 206 |
<th scope="col" ></th> |
| 207 |
</tr> |
| 208 |
</thead> |
| 209 |
<tbody id="ignored-cores-list"> |
| 210 |
<?php |
| 211 |
MainWP_DB::data_seek( $websites, 0 ); |
| 212 |
$count = 0; |
| 213 |
while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) { |
| 214 |
|
| 215 |
if ( $website->is_ignoreCoreUpdates ) { |
| 216 |
continue; |
| 217 |
} |
| 218 |
|
| 219 |
$decodedIgnoredCores = ! empty( $website->ignored_wp_upgrades ) ? json_decode( $website->ignored_wp_upgrades, true ) : array(); |
| 220 |
|
| 221 |
if ( ! is_array( $decodedIgnoredCores ) || empty( $decodedIgnoredCores ) ) { |
| 222 |
continue; |
| 223 |
} |
| 224 |
|
| 225 |
$first = true; |
| 226 |
// phpcs:disable WordPress.Security.EscapeOutput |
| 227 |
$ignored_vers = ! empty( $decodedIgnoredCores['ignored_versions'] ) ? $decodedIgnoredCores['ignored_versions'] : ''; |
| 228 |
if ( ! is_array( $ignored_vers ) ) { |
| 229 |
$ignored_vers = array(); |
| 230 |
} |
| 231 |
|
| 232 |
if ( count( $ignored_vers ) ) { |
| 233 |
++$count; |
| 234 |
} |
| 235 |
foreach ( $ignored_vers as $ignored_ver ) { |
| 236 |
?> |
| 237 |
<tr site-id="<?php echo intval( $website->id ); ?>" ignored-ver="<?php echo esc_attr( $ignored_ver ); ?>"> |
| 238 |
<?php if ( $first ) : ?> |
| 239 |
<td><div><a href="<?php echo esc_url( admin_url( 'admin.php?page=managesites&dashboard=' . $website->id ) ); ?>"><?php echo esc_html( stripslashes( $website->name ) ); ?></a></div></td> |
| 240 |
<?php $first = false; ?> |
| 241 |
<?php else : ?> |
| 242 |
<td><div style="display:none;"><a href="<?php echo esc_url( admin_url( 'admin.php?page=managesites&dashboard=' . $website->id ) ); ?>"><?php echo esc_html( stripslashes( $website->name ) ); ?></a></div></td> |
| 243 |
<?php endif; ?> |
| 244 |
<td><?php echo 'all_versions' === $ignored_ver ? esc_html__( 'All', 'mainwp' ) : esc_html( $ignored_ver ); ?></td> |
| 245 |
<td><a href="<?php echo 'admin.php?page=ManageClients&client_id=' . intval( $website->client_id ); ?>" data-tooltip="<?php esc_attr_e( 'Jump to the client', 'mainwp' ); ?>" data-position="right center" data-inverted="" ><?php echo esc_html( $website->client_name ); ?></a></td> |
| 246 |
<td class="right aligned"> |
| 247 |
<?php |
| 248 |
if ( \mainwp_current_user_can( 'dashboard', 'ignore_unignore_updates' ) ) : |
| 249 |
?> |
| 250 |
<a href="#" class="ui mini button" onClick="return updatesoverview_unignore_cores_by_site( <?php echo intval( $website->id ); ?>, '<?php echo esc_js( rawurlencode( $ignored_ver ) ); ?>' )"> <?php esc_html_e( 'Unignore', 'mainwp' ); ?></a> |
| 251 |
<?php endif; ?> |
| 252 |
</td> |
| 253 |
</tr> |
| 254 |
<?php } ?> |
| 255 |
<?php |
| 256 |
} |
| 257 |
// phpcs:enable |
| 258 |
if ( $websites ) { |
| 259 |
MainWP_DB::free_result( $websites ); |
| 260 |
} |
| 261 |
?> |
| 262 |
</tbody> |
| 263 |
<?php if ( \mainwp_current_user_can( 'dashboard', 'ignore_unignore_updates' ) && $count ) : ?> |
| 264 |
<tfoot class="full-width"> |
| 265 |
<tr> |
| 266 |
<th scope="col" colspan="5"> |
| 267 |
<a class="ui right floated small green labeled icon button" onClick="return updatesoverview_unignore_cores_by_site_all();" id="mainwp-unignore-cores-detail-all"> |
| 268 |
<i class="check icon"></i> <?php esc_html_e( 'Unignore All', 'mainwp' ); ?> |
| 269 |
</a> |
| 270 |
</th> |
| 271 |
</tr> |
| 272 |
</tfoot> |
| 273 |
<?php endif; ?> |
| 274 |
</table> |
| 275 |
<script type="text/javascript"> |
| 276 |
jQuery( document ).ready( function() { |
| 277 |
jQuery( '#mainwp-per-site-ignored-cores' ).DataTable( { |
| 278 |
"responsive": true, |
| 279 |
"searching": false, |
| 280 |
"paging": false, |
| 281 |
"info": false, |
| 282 |
"columnDefs": [ { |
| 283 |
"targets": 'no-sort', |
| 284 |
"orderable": false |
| 285 |
} ], |
| 286 |
"language": { |
| 287 |
"emptyTable": "<?php esc_html_e( 'No ignored WordPress', 'mainwp' ); ?>" |
| 288 |
} |
| 289 |
} ); |
| 290 |
} ); |
| 291 |
</script> |
| 292 |
<?php |
| 293 |
} |
| 294 |
} |
| 295 |
|