Skip to content

Commit

Permalink
Ignore files from coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan0sz committed Mar 26, 2024
1 parent d893b01 commit 741b58c
Showing 1 changed file with 38 additions and 24 deletions.
62 changes: 38 additions & 24 deletions src/Admin/Updates.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace OMGF\Admin;

defined( 'ABSPATH' ) || exit;
Expand All @@ -13,6 +14,10 @@
*
* @package Daan/Updates
*/

/**
* @codeCoverageIgnore
*/
class Updates {
/** @var string $plugin_text_domain */
private $plugin_text_domain = '';
Expand All @@ -38,6 +43,7 @@ public function __construct( $premium_plugins, $plugin_text_domain, $transient_l

/**
* Action & Filter hooks.
*
* @return void
*/
private function init() {
Expand All @@ -61,21 +67,21 @@ public function maybe_display_premium_update_notice( $installed_plugins ) {
$plugin_slugs = array_keys( $installed_plugins );

foreach ( $this->premium_plugins as $id => $premium_plugin ) {
if ( ! in_array( $premium_plugin['basename'], $plugin_slugs ) ) {
if ( ! in_array( $premium_plugin[ 'basename' ], $plugin_slugs ) ) {
continue;
}

if ( $this->update_already_displayed( $premium_plugin['basename'] ) ) {
if ( $this->update_already_displayed( $premium_plugin[ 'basename' ] ) ) {
continue;
}

$latest_version = $this->get_latest_version( $id, $premium_plugin['transient_label'] );
$current_version = get_plugin_data( WP_PLUGIN_DIR . '/' . $premium_plugin['basename'] )['Version'] ?? '';
$latest_version = $this->get_latest_version( $id, $premium_plugin[ 'transient_label' ] );
$current_version = get_plugin_data( WP_PLUGIN_DIR . '/' . $premium_plugin[ 'basename' ] )[ 'Version' ] ?? '';

if ( version_compare( $current_version, $latest_version, '<' ) ) {
$installed_plugins[ $premium_plugin['basename'] ]['update'] = true;
$installed_plugins[ $premium_plugin[ 'basename' ] ][ 'update' ] = true;

add_action( 'after_plugin_row_' . $premium_plugin['basename'], [ $this, 'display_premium_update_notice' ], 10, 2 );
add_action( 'after_plugin_row_' . $premium_plugin[ 'basename' ], [ $this, 'display_premium_update_notice' ], 10, 2 );
}
}

Expand Down Expand Up @@ -171,14 +177,22 @@ private function get_latest_version( $id ) {
* @return void
*/
public function display_premium_update_notice( $file, $plugin_data ) {
$slug = explode( '/', $file )[0] ?? '';
$label = $plugin_data['Name'] ?? $plugin_data['name'] ?? 'this plugin';
$notice = sprintf( __( 'An update for %1$s is available, but we\'re having trouble retrieving it. Download it from <a href=\'%2$s\' target=\'_blank\'>your account area</a> and install it manually. <a href=\'%3$s\' target=\'_blank\'>Need help</a>?', $this->plugin_text_domain ), $label, 'https://daan.dev/account/files/', 'https://daan.dev/docs/pre-sales/download-files/' );
$slug = explode( '/', $file )[ 0 ] ?? '';
$label = $plugin_data[ 'Name' ] ?? $plugin_data[ 'name' ] ?? 'this plugin';
$notice =
sprintf(
__(
'An update for %1$s is available, but we\'re having trouble retrieving it. Download it from <a href=\'%2$s\' target=\'_blank\'>your account area</a> and install it manually. <a href=\'%3$s\' target=\'_blank\'>Need help</a>?',
$this->plugin_text_domain
),
$label,
'https://daan.dev/account/files/',
'https://daan.dev/docs/pre-sales/download-files/'
);

/**
* This snippet of JS either overwrites the contents of the update message.
*/
?>
*/ ?>
<script>
window.addEventListener('DOMContentLoaded', function () {
var row = document.getElementById('<?php echo esc_attr( $slug ); ?>-update');
Expand Down Expand Up @@ -213,25 +227,25 @@ public function display_premium_update_notice( $file, $plugin_data ) {
*/
public function maybe_add_update_count( $update_data ) {
// phpcs:ignore
if ( isset( $_GET['plugin_status'] ) && $_GET['plugin_status'] === 'upgrade' ) {
if ( isset( $_GET[ 'plugin_status' ] ) && $_GET[ 'plugin_status' ] === 'upgrade' ) {
return $update_data;
}

foreach ( $this->premium_plugins as $id => $plugin ) {
if ( ! is_plugin_active( WP_PLUGIN_DIR . '/' . $plugin['basename'] ) ) {
if ( ! is_plugin_active( WP_PLUGIN_DIR . '/' . $plugin[ 'basename' ] ) ) {
continue;
}

if ( $this->update_already_displayed( $plugin['basename'] ) ) {
if ( $this->update_already_displayed( $plugin[ 'basename' ] ) ) {
continue;
}

$latest_version = $this->get_latest_version( $id, $plugin['transient_label'] );
$plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin['basename'] );
$current_version = $plugin_data['Version'] ?? '';
$latest_version = $this->get_latest_version( $id, $plugin[ 'transient_label' ] );
$plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin[ 'basename' ] );
$current_version = $plugin_data[ 'Version' ] ?? '';

if ( version_compare( $current_version, $latest_version, '<' ) ) {
++$update_data['counts']['plugins'];
++ $update_data[ 'counts' ][ 'plugins' ];
}
}

Expand Down Expand Up @@ -260,25 +274,25 @@ public function maybe_add_to_update_list( $transient ) {
}

foreach ( $this->premium_plugins as $id => $plugin ) {
if ( ! is_plugin_active( $plugin['basename'] ) ) {
if ( ! is_plugin_active( $plugin[ 'basename' ] ) ) {
continue;
}

$latest_version = $this->get_latest_version( $id, $plugin['transient_label'] );
$plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin['basename'] );
$current_version = $plugin_data['Version'] ?? '';
$latest_version = $this->get_latest_version( $id, $plugin[ 'transient_label' ] );
$plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin[ 'basename' ] );
$current_version = $plugin_data[ 'Version' ] ?? '';

// Due to stored, non-expired transients, it might be possible that the latest version is lower than the current version.
if ( version_compare( $current_version, $latest_version, '>=' ) ) {
continue;
}

$plugin_file = $plugin['basename'];
$plugin_file = $plugin[ 'basename' ];

// If an update is already displayed, there's no need for us to recreate this object.
if ( is_object( $transient ) && isset( $transient->response ) && ! isset( $transient->response[ $plugin_file ] ) ) {
$transient->response[ $plugin_file ] = (object) [
'slug' => explode( '/', $plugin_file )[0],
'slug' => explode( '/', $plugin_file )[ 0 ],
'plugin' => $plugin_file,
'new_version' => '',
];
Expand Down

0 comments on commit 741b58c

Please sign in to comment.