Inventory_Presser_Addon_Updater::show_update_notification( string $file, array $plugin )

show update nofication row — needed for multisite subsites, because WP won’t tell you otherwise!


Parameters Parameters

$file

(string) (Required)

$plugin

(array) (Required)


Top ↑

Source Source

File: includes/addon/class-addon-updater.php

		public function show_update_notification( $file, $plugin ) {
			/**
			 * If this is a multi-site install, only show the update on the
			 * network plugins page.
			 */
			if ( is_multisite() && ! is_network_admin() ) {
				return;
			}

			if ( ! current_user_can( 'update_plugins' ) ) {
				return;
			}

			if ( $this->name != $file ) {
				return;
			}

			// Remove our filter on the site transient.
			remove_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ), 10 );
			$update_cache = get_site_transient( 'update_plugins' );
			$update_cache = is_object( $update_cache ) ? $update_cache : new stdClass();
			if ( empty( $update_cache->response ) || empty( $update_cache->response[ $this->name ] ) ) {

				$version_info = $this->get_repo_api_data();

				if ( false === $version_info ) {
					$version_info = $this->api_request(
						'plugin_latest_version',
						array(
							'slug' => $this->slug,
							'beta' => $this->beta,
						)
					);

					// Since we disabled our filter for the transient, we aren't running our object conversion on banners, sections, or icons. Do this now:
					if ( isset( $version_info->banners ) && ! is_array( $version_info->banners ) ) {
						$version_info->banners = $this->convert_object_to_array( $version_info->banners );
					}

					if ( isset( $version_info->sections ) && ! is_array( $version_info->sections ) ) {
						$version_info->sections = $this->convert_object_to_array( $version_info->sections );
					}

					if ( isset( $version_info->icons ) && ! is_array( $version_info->icons ) ) {
						$version_info->icons = $this->convert_object_to_array( $version_info->icons );
					}

					if ( isset( $version_info->contributors ) && ! is_array( $version_info->contributors ) ) {
						$version_info->contributors = $this->convert_object_to_array( $version_info->contributors );
					}

					$this->set_version_info_cache( $version_info );
				}

				if ( ! is_object( $version_info ) ) {
					return;
				}

				if ( version_compare( $this->version, $version_info->new_version, '<' ) ) {
					$update_cache->response[ $this->name ] = $version_info;
				} else {
					$update_cache->no_update[ $this->name ] = $version_info;
				}

				$update_cache->last_checked           = time();
				$update_cache->checked[ $this->name ] = $this->version;

				set_site_transient( 'update_plugins', $update_cache );
			} else {
				$version_info = $update_cache->response[ $this->name ];
			}

			// Restore our filter.
			add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) );

			if ( ! empty( $update_cache->response[ $this->name ] )
				&& version_compare( $this->version, $version_info->new_version, '<' )
			) {
				// build a plugin list row, with update notification.
				printf(
					'<tr class="plugin-update-tr active" id="%1$s-update" data-slug="%1$s" data-plugin="%2$s">'
					. '<td colspan="4" class="plugin-update colspanchange">'
					. '<div class="update-message notice inline notice-warning notice-alt"><p>',
					esc_attr( $this->slug ),
					esc_attr( $file )
				);

				$changelog_link = self_admin_url(
					sprintf(
						'index.php?edd_sl_action=view_plugin_changelog&plugin=%s&slug=%s&TB_iframe=true&width=772&height=911',
						$this->name,
						$this->slug
					)
				);

				printf(
					'%s %s %s <a href="%s" class="thickbox open-plugin-details-modal" aria-label="%s %s %s %s %s">%s %s %s</a>',
					esc_html__( 'There is a new version of', 'inventory-presser' ),
					esc_html( $version_info->name ),
					esc_html__( 'available.', 'inventory-presser' ),
					esc_url( $changelog_link ),
					esc_html__( 'View', 'inventory-presser' ),
					esc_html( $version_info->name ),
					esc_html__( 'version', 'inventory-presser' ),
					esc_html( $version_info->new_version ),
					esc_html__( 'details', 'inventory-presser' ),
					esc_html__( ' View version', 'inventory-presser' ),
					esc_html( $version_info->new_version ),
					esc_html__( 'details', 'inventory-presser' )
				);

				// Do we have a license key? Include "update now" link if so.
				if ( ! empty( $this->api_data['license'] ) ) {
					printf(
						' %s <a href="%s" class="update-link" aria-label="%s %s %s">%s</a>.',
						esc_html__( 'or', 'inventory-presser' ),
						esc_url( wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $this->name, 'upgrade-plugin_' . $this->name ) ),
						esc_attr__( 'Update', 'inventory-presser' ),
						esc_html( $version_info->name ),
						esc_attr__( 'now', 'inventory-presser' ),
						esc_html__( 'update now', 'inventory-presser' )
					);
				} else {
					echo '.';
				}

				do_action( "in_plugin_update_message-{$file}", $plugin, $version_info );
				echo ' <em></em></p></div></td></tr>';
			}
		}