* @since x.x.x */ namespace AdvancedAds\Updater; use AdvancedAds\Utilities\Addons; use AdvancedAds\Framework\Interfaces\Integration_Interface; defined( 'ABSPATH' ) || exit; /** * Update guard. */ class Update_Guard implements Integration_Interface { /** * Hook into WordPress. * * @return void */ public function hooks(): void { add_action( 'in_plugin_update_message-' . ADVADS_PLUGIN_BASENAME, [ $this, 'update_message' ], 10, 2 ); } /** * Add the upgrade notice from the WordPress.org readme and the add-on warning to the update row of Advanced Ads. * * @param array $plugin_data Plugin headers. * @param object $response Update data from WordPress.org. * * @return void */ public function update_message( $plugin_data, $response ): void { $notice = trim( wp_strip_all_tags( (string) ( $response->upgrade_notice ?? '' ) ) ); if ( '' !== $notice ) { echo ' ' . esc_html( $notice ) . ''; } if ( $this->is_major_update_with_addons( (string) ( $response->new_version ?? '' ) ) ) { echo ' ' . esc_html__( 'This is a major update. Update your Advanced Ads add-ons to their latest versions first, and back up your site.', 'advanced-ads' ) . ''; } } /** * Whether a version is a major step up from the installed one on a site with add-ons — add-ons do not declare which versions of Advanced Ads they were tested with, so the first version number is the signal. * * @param string $new_version The offered version. * * @return bool */ private function is_major_update_with_addons( string $new_version ): bool { return (int) $new_version > (int) ADVADS_VERSION && [] !== Addons::get_installed_addons(); } }