# Monetize Me

A flexible advertisement management plugin for WordPress with Multisite support, raw ad-code output, and centralized taxonomy and Ad post synchronization across subsites.

## Description

**Monetize Me** lets you manage advertisement snippets as WordPress Ads and display them using shortcodes, PHP functions, widgets, or a Gutenberg block.

The plugin is suitable for Google AdSense, affiliate banners, custom HTML, JavaScript, iframe embeds, and other monetization code. Ad content is rendered from the editor without WordPress automatic paragraph injection, so raw ad markup is not wrapped in unwanted `<p>` tags.

For WordPress Multisite, Network Administrators can copy `adcategory` and `adsponsor` taxonomy terms, and copy all `ad` CPT posts from one site to selected destination subsites.

## Features

- Custom `ad` post type for advertisement snippets.
- `adcategory` and `adsponsor` taxonomies.
- Shortcode, PHP function, widget, and Gutenberg block support.
- Raw editor output for advertisement snippets without automatic `<p>` tag injection.
- Provider-managed ad-code rendering without plugin-controlled JavaScript initialization or delayed execution.
- Enqueued frontend styles that keep responsive ad containers full-width, with optional alignment classes controlled by the shortcode, block, or widget.
- Random ad display by category/group.
- Admin-only Ad CPT management using plugin-specific capabilities.
- Multisite Network Admin tools for copying terms and Ad posts.
- Slug-based duplicate detection when copying Ads across subsites.

## Shortcode Usage

The main shortcode is:

```text
[mmps]
```

Display a specific ad by slug:

```text
[mmps id="homepage-leaderboard"]
```

Display one random ad from category ID `12`:

```text
[mmps adcategory="12"]
```

Display one random ad from the ad category slug `in-article-ad`:

```text
[mmps adcategory="in-article-ad"]
```

Display two random ads from category ID `12`:

```text
[mmps adcategory="12" limit="2"]
```

Display an ad without wrapper markup:

```text
[mmps id="sidebar-ad-1" wrapper="0"]
```

The outer wrapper uses only the `monetize-me` class by default. Add an alignment class explicitly when required:

```text
[mmps id="homepage-leaderboard" adAlignment="center-align"]
```

Display an ad from a specific sponsor slug:

```text
[mmps adsponsor="adsense" adcategory="horizontal-adv"]
```

Display ads from multiple sponsor IDs or slugs:

```text
[mmps adsponsor="3,7,adsterra" adcategory="vertical-adv"]
```

## Raw Ad Code Output

For Google AdSense or other third-party advertisement snippets, paste the provider code into an Ad post using a Custom HTML block or the code editor.

Monetize Me renders Ad content without `wpautop()`, so the saved markup is not automatically wrapped in extra paragraph tags.

Monetize Me does not initialize, delay, rewrite, or otherwise manage third-party advertising JavaScript. The complete advertisement snippet saved in the Ad post is rendered on the frontend as supplied. Any required loader or initialization code must therefore be included in the saved ad code or loaded separately by the website.

## PHP Usage

```php
<?php echo monetize_me_display_ad( array( 'adcategory' => 'homepage' ) ); ?>
```

## Multisite Usage

When network activated:

1. Go to **Network Admin → Settings → Monetize Me**.
2. Use **Copy Ad Taxonomy Terms** to copy `adcategory` and `adsponsor` terms.
3. Use **Copy Ads** to copy `ad` posts from one source site to selected destination subsites.

The Ad copy tool preserves title, slug, content, excerpt, status, menu order, custom fields, and assigned Monetize Me taxonomy terms. Existing destination Ads with the same slug are skipped.

## Changelog

### 2.0.6

- Removed plugin-controlled delayed AdSense initialization and footer JavaScript output.
- Preserved complete provider ad snippets exactly as saved, including their own loader and initialization code.
- Moved frontend ad-container styles to a stylesheet loaded through the WordPress style enqueue system.
- Kept alignment classes opt-in so the base `monetize-me` wrapper does not apply `center-align` unless explicitly configured.
- Updated plugin and block release metadata and refreshed documentation.

### 2.0.3

- Fixed raw Ad post rendering to prevent unwanted `<p>` tags around advertisement snippets.
- Preserved raw Google AdSense, iframe, script, and custom HTML output while still supporting Gutenberg blocks and shortcodes.
- Preserved complete third-party advertising snippets without plugin-controlled JavaScript initialization.
- Added full-width frontend wrapper styling for rendered ad containers and AdSense slots.
- Updated documentation for raw ad-code rendering and provider-managed initialization.

### 2.0.2

- Added Network Admin tool to copy all `ad` CPT posts from one site to selected destination subsites.
- Skips destination Ads when the same slug already exists.
- Preserves content, excerpt, status, menu order, custom fields, and assigned Monetize Me taxonomy terms.

### 2.0.1

- Added Network Admin settings page for Multisite environments.
- Added taxonomy term synchronization for `adcategory` and `adsponsor`.

## License

GPL-2.0-or-later.
