=== Greensites ===

Requires at least: 6.3
Tested up to: 6.8
Stable tag: 1.0
License: GPLv3 or later
License URI: https://www.gnu.org/licenses/gpl-3.0.html
Contributors: fruilova, etorres, romanow, devgreenpow
Requires PHP: 7.4

Measure your WordPress site’s carbon footprint per visit and offset emissions with GreenPow integration.

== Description ==

Estimate your website’s carbon footprint and offset it via GreenPow.

== Installation ==

1. Upload `greensites` to the `/wp-content/plugins/` directory
2. Activate the plugin through the 'Plugins' menu in WordPress

== how it works ==
Using CO2.js, GreenSites is responsible for collecting all the necessary information to calculate the carbon footprint of your WordPress sites.

1. When the GreenSites plugin is activated, our bot will visit your homepage, retrieve the number of bytes used per visit, and store this data in the database.
2. GreenSites installs a tracker that increments each time a user visits the page, updating the greensites_visitors_count table.
3. Using the collected data and the CO2.js API, we calculate the CO2 emissions per visit as well as the total emissions for all visits in the month.
4. When the plugin is activated, a cron task is also created, which stores the monthly calculation in the greensites_monthly_report_event table.

== Changelog ==

= 1.0 =
* Initial Release.


== Frequently Asked Questions ==

= How do I activate my Greensites plugin? =

Register or log in to your Greenpow account and purchase your plugin. Follow the prompts to obtain your token.

== Upgrade Notice ==

= 1.0 =
* Initial Release.

== Screenshots ==

1. The Greensites dashboard includes four cards:

Carbon Rating Card displays your website’s carbon footprint rating.

Greeninsight Dashboard Card shows the estimated footprint per visit, the total monthly footprint from your site traffic, and the offset value required to compensate for it. This card also features the Offset Now button, which allows you to offset your carbon footprint directly.

Offset & Compensation Card provides a calculator where you can estimate your offset costs based on different monthly visit volumes.

Compensation Reports Card presents a table summarizing the carbon offset contributions Greensites has made each month.

2. The Greensites activation form is straightforward:
You simply need to create or log in to your Greenpow account, purchase the Greensite plugin, and enter the provided token into the Greensites form.

== Dependency: CO2.js ==

This plugin includes the CO2.js library created by The Greenweb Foundation, licensed under the **Apache License, Version 2.0**.

- The original version has been included, with its NOTICE file intact.  
- The full license text is available in the `LICENSE` file at the root of the plugin.  
- Original repository: https://github.com/thegreenwebfoundation/co2.js 

== Third-Party Licenses ==
- CO2.js – Apache License 2.0 (includes on /js/greenweb/LICENSE)

## External Services (Greenpow API – Authentication and Report.)

Integration with the Greenpow API

This plugin connects with the private Greenpow API, developed by the same company behind this plugin: https://greenpow.io. 

Token validation
When a user purchases a subscription on our platform, they receive a Greensites Token. The plugin requires this token to work properly and validates it through the following endpoint:

POST https://api.greenpow.cloud/api/greensites/validate-token

During the initial setup, the plugin will request the token from the user.

On every subsequent use, the plugin will continue validating the token using the same endpoint to ensure authenticity and valid access.

Carbon footprint report
The plugin also uses the following Greenpow API endpoint:

POST https://api.greenpow.cloud/api/greensites/carbon-report

This is where carbon footprint reports are sent so Greenpow can run its calculations and issue an official offset certificate.


### Data Sent to the API

1. greensites_validate_token()
   - Data sent:
     - domain → the current WordPress site domain.
     - token → the site’s GreenSites authentication token.
   - When:
     - Every time the plugin needs to validate the token stored in the database or received via POST.
   - Why:
     - To confirm that the token is valid and authorized for API usage.
   - Endpoint:
     - https://api.greenpow.cloud/api/greensites/validate-token

2. greensites_generate_and_send_monthly_report()
   - Data sent:
     - month → the previous month (first day as YYYY-MM-DD).
     - visits → total visits registered in the WordPress visitors counter table.
     - carbon_grams → estimated CO₂ emissions for the month.
     - compensation_usd → calculated monetary compensation required to offset emissions.
     - token → the site’s GreenSites authentication token.
     - domain → the current WordPress site domain.
   - When:
     - Automatically after a new monthly report is generated (first day of the following month).
   - Why:
     - To report monthly visit and CO₂ data to GreenPow for tracking and carbon offset calculation.
   - Endpoint:
     - https://api.greenpow.cloud/api/greensites/carbon-report

### Purpose of Data Transmission

The plugin sends only the necessary data for:
- Token validation (authentication).
- Monthly reporting of visits and carbon footprint.

### Terms of Service and Privacy Policies

- GreenPow Terms of Service: https://greenpow.network/terms
- GreenPow Privacy Policy: https://greenpow.network/privacy

## External Services (CO2.js – Green Hosting Checks)

This plugin/library uses the public APIs operated by **The Green Web Foundation** *only* when the hosting check feature is called.

Service:
- https://api.thegreenwebfoundation.org

### When Calls Happen

- **Only when `hosting.check(...)` is invoked** (directly or via wrappers `b.check` / `v.check`):
  - If you pass a **single domain** (string), the code performs a GET request to:
    - `https://api.thegreenwebfoundation.org/greencheck/{domain}`
  - If you pass **multiple domains** (array), the code performs a GET request to:
    - `https://api.thegreenwebfoundation.org/v2/greencheckmulti/{jsonEncodedArray}`

> Note: Other CO2.js methods (`perByte`, `perVisit`, etc.) run locally and **do not** contact external APIs.

### Data Sent

- For **single-domain check**:
  - `domain` → included in the URL path (no request body).
- For **multi-domain check**:
  - `domains[]` → the array of domains is JSON-encoded and included in the URL path as part of the endpoint.
- **No tokens, cookies, or personal identifiers** are added by this code.

### Why the Data Is Sent

- To query The Green Web Foundation’s dataset and determine if a domain is served by a verified green hosting provider.
- The response contains a boolean flag (e.g., `green: true/false`) and related metadata used to label the domain as “green” or not.

### Endpoints (Documentation)

- Greencheck API (single domain): https://developers.thegreenwebfoundation.org/api/greencheck/v3/check-single-domain/
- Developer portal (APIs overview): https://developers.thegreenwebfoundation.org/

### Terms of Service and Privacy Policies

- Privacy Policy (The Green Web Foundation): https://www.thegreenwebfoundation.org/privacy-statement/
- Notes on Terms:
  - As of this writing, The Green Web Foundation does not publish a dedicated Greencheck API “Terms of Service” page. Usage guidance and constraints are covered in the developer docs above and site-wide policies. If formal Terms are introduced later, link them here.

### Additional Notes

- Requests use HTTP **GET** and include only the queried domain name(s).
- You are responsible for obtaining consent before transmitting any domain names that could be considered personal data in your jurisdiction.
- CO2 intensity data tables embedded in CO2.js are local constants; looking up grid intensities **does not** trigger network calls.