# 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.
- Google AdSense-friendly rendering with guarded responsive slot initialization.
- 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"]
```

Display an ad from specific sponsor by sponsor slug:

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

Or,

```text
[mmps adsponsor="adsterra" adcategory="verticle-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.

For AdSense responsive ads, the plugin keeps the AdSense loader script and delays the slot push until the slot has visible width. This helps avoid this browser console error:

```text
adsbygoogle.push() error: No slot size for availableWidth=0
```

## 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.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.
- Added guarded AdSense frontend initialization to avoid `adsbygoogle.push() error: No slot size for availableWidth=0`.
- Added full-width frontend wrapper styling for rendered ad containers and AdSense slots.
- Updated documentation for raw ad-code rendering and AdSense responsive slot behavior.

### 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.
