15, 'headers' => [ 'Content-Type' => 'application/json', 'Accept' => 'application/json' ], 'body' => wp_json_encode( [ 'key' => $lic['key'], 'product' => CB_PRODUCT_SLUG, 'domain' => CB_License::domain(), 'version' => CB_VERSION, ] ), ] ); if ( is_wp_error( $response ) ) { return null; } $data = json_decode( wp_remote_retrieve_body( $response ), true ); if ( ! is_array( $data ) || empty( $data['ok'] ) ) { return null; } set_transient( self::TRANSIENT, $data, self::CACHE_TTL ); return $data; } /** Inject the update into the plugins update transient. */ public static function inject( mixed $transient ): mixed { if ( ! is_object( $transient ) ) { return $transient; } $info = self::fetch_info(); if ( ! $info || empty( $info['update_available'] ) || empty( $info['package'] ) ) { return $transient; } // Only offer if the backend's version is actually newer than ours. if ( version_compare( $info['version'] ?? '0', CB_VERSION, '<=' ) ) { return $transient; } $item = [ 'slug' => self::slug(), 'plugin' => self::basename(), 'new_version' => (string) $info['version'], 'package' => esc_url_raw( $info['package'] ), 'url' => 'https://lucas-orth.de', 'tested' => (string) ( $info['tested'] ?? '' ), 'requires' => (string) ( $info['requires'] ?? '' ), 'requires_php'=> (string) ( $info['requires_php'] ?? '' ), 'icons' => [], 'banners' => [], ]; $transient->response[ self::basename() ] = (object) $item; return $transient; } /** * Provide the "View version details" popup content. */ public static function plugin_info( mixed $result, string $action, object $args ): mixed { if ( $action !== 'plugin_information' ) { return $result; } if ( empty( $args->slug ) || $args->slug !== self::slug() ) { return $result; } $info = self::fetch_info(); if ( ! $info ) { return $result; } return (object) [ 'name' => 'GDPR Content Blocker', 'slug' => self::slug(), 'version' => (string) ( $info['version'] ?? CB_VERSION ), 'author' => 'Lucas Orth', 'homepage' => 'https://lucas-orth.de', 'requires' => (string) ( $info['requires'] ?? '' ), 'tested' => (string) ( $info['tested'] ?? '' ), 'requires_php' => (string) ( $info['requires_php'] ?? '' ), 'download_link' => esc_url_raw( $info['package'] ?? '' ), 'sections' => [ 'changelog' => wp_kses_post( $info['changelog'] ?? '' ), ], ]; } }