Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ node_modules/

# dotenv environment variables file
.env

# Composer
composer.lock
14 changes: 5 additions & 9 deletions .wordpress-org/blueprints/blueprint.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://playground.wordpress.net/blueprint-schema.json",
"landingPage": "/blockparty-modal-demo/",
"landingPage": "/blockparty-post-sharing-demo/",
"preferredVersions": {
"php": "8.1",
"wp": "latest"
Expand All @@ -10,13 +10,13 @@
"step": "installPlugin",
"pluginData": {
"resource": "git:directory",
"url": "https://github.com/BeAPI/blockparty-modal",
"ref": "1.0.8",
"url": "https://github.com/BeAPI/blockparty-post-sharing",
"ref": "1.0.0",
"refType": "tag"
},
"options": {
"activate": true,
"targetFolderName": "blockparty-modal"
"targetFolderName": "blockparty-post-sharing"
}
},
{
Expand All @@ -26,11 +26,7 @@
},
{
"step": "runPHP",
"code": "<?php\nrequire_once 'wordpress/wp-load.php';\n$dir = WP_CONTENT_DIR . '/mu-plugins';\nif ( ! is_dir( $dir ) ) {\n\twp_mkdir_p( $dir );\n}\n$file = $dir . '/blockparty-modal-playground-svg-kses.php';\n$lines = array(\n\t'<?php',\n\t'add_filter( \\'wp_kses_allowed_html\\', function( $tags, $context ) {',\n\t'\tif ( \\'post\\' !== $context ) {',\n\t'\t\treturn $tags;',\n\t'\t}',\n\t'\t$tags[\\'dialog\\'] = array(',\n\t'\t\t\\'aria-modal\\' => true,',\n\t'\t\t\\'class\\' => true,',\n\t'\t\t\\'style\\' => true,',\n\t'\t\t\\'id\\' => true,',\n\t'\t\t\\'closedby\\' => true,',\n\t'\t);',\n\t'\t$tags[\\'svg\\'] = array(',\n\t'\t\t\\'xmlns\\' => true,',\n\t'\t\t\\'viewbox\\' => true,',\n\t'\t\t\\'width\\' => true,',\n\t'\t\t\\'height\\' => true,',\n\t'\t\t\\'fill\\' => true,',\n\t'\t\t\\'class\\' => true,',\n\t'\t\t\\'aria-hidden\\' => true,',\n\t'\t\t\\'role\\' => true,',\n\t'\t\t\\'focusable\\' => true,',\n\t'\t);',\n\t'\t$tags[\\'path\\'] = array(',\n\t'\t\t\\'d\\' => true,',\n\t'\t\t\\'fill\\' => true,',\n\t'\t\t\\'class\\' => true,',\n\t'\t);',\n\t'\treturn $tags;',\n\t'}, 10, 2 );',\n);\nfile_put_contents( $file, implode( \"\\n\", $lines ) . \"\\n\" );\necho file_exists( $file ) ? 'mu-plugin installed' : 'mu-plugin failed';\n?>"
},
{
"step": "runPHP",
"code": "<?php require_once 'wordpress/wp-load.php'; $page_content = '<!-- wp:group {\"style\":{\"spacing\":{\"margin\":{\"top\":\"0\",\"bottom\":\"0\"},\"blockGap\":\"var:preset|spacing|40\"}},\"layout\":{\"type\":\"constrained\"}} -->\n<div class=\"wp-block-group\" style=\"margin-top:0;margin-bottom:0\"><!-- wp:paragraph -->\n<p>Click on the button below to reveal a dialog window.</p>\n<!-- /wp:paragraph -->\n\n<!-- wp:buttons {\"layout\":{\"type\":\"flex\",\"justifyContent\":\"center\"}} -->\n<div class=\"wp-block-buttons\"><!-- wp:button {\"linkedModalId\":\"m-4dc3f7ac0a14\"} -->\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link wp-element-button\">About Gutenberg</a></div>\n<!-- /wp:button --></div>\n<!-- /wp:buttons --></div>\n<!-- /wp:group -->\n\n<!-- wp:blockparty/modal {\"title\":\"Johannes Gutenberg\",\"modalId\":\"m-4dc3f7ac0a14\",\"displayIconOnly\":true,\"style\":{\"spacing\":{\"padding\":{\"right\":\"var:preset|spacing|40\",\"left\":\"var:preset|spacing|40\",\"top\":\"var:preset|spacing|40\",\"bottom\":\"var:preset|spacing|40\"}}}} -->\n<dialog class=\"wp-block-blockparty-modal\" style=\"padding-top:var(--wp--preset--spacing--40);padding-right:var(--wp--preset--spacing--40);padding-bottom:var(--wp--preset--spacing--40);padding-left:var(--wp--preset--spacing--40)\" id=\"modal-m-4dc3f7ac0a14\" aria-modal=\"true\" closedby=\"any\"><div class=\"wp-block-blockparty-modal__header\"><h2 class=\"wp-block-blockparty-modal__title\">Johannes Gutenberg</h2></div><div class=\"wp-block-blockparty-modal__content\"><!-- wp:quote -->\n<blockquote class=\"wp-block-quote\"><!-- wp:paragraph -->\n<p><em>\"Gutenberg\" redirects here. For the Bible, see </em><a href=\"https://en.wikipedia.org/wiki/Gutenberg_Bible\">Gutenberg Bible</a><em>. For other uses, see </em><a href=\"https://en.wikipedia.org/wiki/Gutenberg_(disambiguation)\">Gutenberg (disambiguation)</a><em>.</em></p>\n<!-- /wp:paragraph --></blockquote>\n<!-- /wp:quote -->\n\n<!-- wp:paragraph -->\n<p><strong>Johannes Gensfleisch zur Laden zum Gutenberg</strong> (c. 1393–1406 – 3 February 1468) was a German inventor and <a href=\"https://en.wikipedia.org/wiki/Artisan\">craftsman</a> who invented the movable-type <a href=\"https://en.wikipedia.org/wiki/Printing_press\">printing press</a>. Though <a href=\"https://en.wikipedia.org/wiki/Movable_type\">movable type</a> was already in use in East Asia, Gutenberg\\'s invention of the printing press enabled a much faster rate of <a href=\"https://en.wikipedia.org/wiki/Printing\">printing</a>. The printing press later <a href=\"https://en.wikipedia.org/wiki/Global_spread_of_the_printing_press\">spread across the world</a>, and led to an <a href=\"https://en.wikipedia.org/wiki/Information_revolution\">information revolution</a> and the unprecedented mass-spread of literature throughout Europe. It had a profound impact on the development of the <a href=\"https://en.wikipedia.org/wiki/Renaissance\">Renaissance</a>, <a href=\"https://en.wikipedia.org/wiki/Reformation\">Reformation</a>, and <a href=\"https://en.wikipedia.org/wiki/Humanist\">humanist</a> movements.</p>\n<!-- /wp:paragraph -->\n\n<!-- wp:paragraph {\"align\":\"right\",\"fontSize\":\"small\"} -->\n<p class=\"has-text-align-right has-small-font-size\">Source : <a href=\"https://en.wikipedia.org/wiki/Johannes_Gutenberg\">Wikipedia</a></p>\n<!-- /wp:paragraph --></div><button type=\"button\" class=\"wp-block-blockparty-modal__close-button\"><span class=\"sr-only\">Close this dialog window</span><svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" width=\"24\" height=\"24\" aria-hidden=\"true\"><path d=\"m13.06 12 6.47-6.47-1.06-1.06L12 10.94 5.53 4.47 4.47 5.53 10.94 12l-6.47 6.47 1.06 1.06L12 13.06l6.47 6.47 1.06-1.06L13.06 12Z\"></path></svg></button></dialog>\n<!-- /wp:blockparty/modal -->'; $page_id = wp_insert_post( array( 'post_title' => 'Blockparty Modal', 'post_name' => 'blockparty-modal-demo', 'post_content' => $page_content, 'post_status' => 'publish', 'post_type' => 'page' ) ); echo 'Page created with ID: ' . $page_id; ?>"
"code": "<?php\nrequire_once 'wordpress/wp-load.php';\n$post_content = <<<'BLOCKPARTY_POST_SHARING_MARKUP_EOF'\n<!-- wp:paragraph -->\n<p>Use the buttons below to copy this article URL or share it with your device.</p>\n<!-- /wp:paragraph -->\n\n<!-- wp:spacer {\"height\":\"var:preset|spacing|40\"} -->\n<div style=\"height:var(--wp--preset--spacing--40)\" aria-hidden=\"true\" class=\"wp-block-spacer\"></div>\n<!-- /wp:spacer -->\n\n<!-- wp:blockparty/post-sharing-button /-->\n\n<!-- wp:paragraph -->\n<p>Johannes Gensfleisch zur Laden zum Gutenberg (c. 1393–1406 – 3 February 1468) was a German inventor and craftsman who invented the movable-type printing press. His invention enabled a much faster rate of printing and later spread across the world, leading to an information revolution and the unprecedented mass-spread of literature throughout Europe.</p>\n<!-- /wp:paragraph -->\n\n<!-- wp:paragraph {\"align\":\"right\",\"fontSize\":\"small\"} -->\n<p class=\"has-text-align-right has-small-font-size\">Source : <a href=\"https://en.wikipedia.org/wiki/Johannes_Gutenberg\">Wikipedia</a></p>\n<!-- /wp:paragraph -->\nBLOCKPARTY_POST_SHARING_MARKUP_EOF;\n\n$post_id = wp_insert_post(\n\tarray(\n\t\t'post_title' => 'Blockparty Post Sharing',\n\t\t'post_name' => 'blockparty-post-sharing-demo',\n\t\t'post_content' => $post_content,\n\t\t'post_status' => 'publish',\n\t\t'post_type' => 'post',\n\t)\n);\necho 'Post created with ID: ' . $post_id;\n?>"
}
]
}
2 changes: 1 addition & 1 deletion .wp-env.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"plugins": [
"./"
"."
]
}
274 changes: 274 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,274 @@
# Blockparty — Post Sharing

[![Test with WordPress Playground](https://img.shields.io/badge/Test%20with-WordPress%20Playground-0073aa?style=for-the-badge&logo=wordpress&logoColor=white)](https://playground.wordpress.net/?blueprint-url=https://raw.githubusercontent.com/BeAPI/blockparty-post-sharing/refs/heads/develop/.wordpress-org/blueprints/blueprint.json)

[![License: GPL v2](https://img.shields.io/badge/License-GPL%20v2-blue.svg)](https://www.gnu.org/licenses/gpl-2.0)
[![WordPress: 6.8+](https://img.shields.io/badge/WordPress-6.8+-green.svg)](https://wordpress.org/)
[![PHP: 8.1+](https://img.shields.io/badge/PHP-8.1+-purple.svg)](https://php.net/)

A WordPress plugin that adds a Gutenberg block to copy and share the current post URL in one click.

## 📋 Description

Blockparty Post Sharing is a WordPress plugin that lets editors add sharing actions to posts via the block editor. Visitors can copy the article link to the clipboard or open the native share sheet of their device when supported.

### ✨ Features

- **Native Gutenberg block**: Full integration with the WordPress block editor
- **Copy link**: Copies the current post permalink to the clipboard with visual and screen reader feedback
- **Native share**: Uses the [Web Share API](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/share) when available
- **Editable labels**: Customize button text inline with `RichText`
- **Copied state label**: Configure the label shown after a successful copy
- **Icons**: Default icons rendered with CSS `mask-image`, overridable via CSS custom properties
- **Icon settings**: Show or hide icons and position them left or right
- **Responsive display**: Show or hide each button independently on desktop and mobile
- **Dynamic rendering**: Server-side output with post URL and title context
- **Internationalized**: Multilingual support with translation files
- **View script**: Frontend script handles copy, share, and copied-state UI

## 🔧 Requirements

- **WordPress**: Version 6.8 or higher
- **PHP**: Version 8.1 or higher
- **PHP Extension**: ext-json

## 📦 Installation

### Installation via Composer

```bash
composer require beapi/blockparty-post-sharing
```

### Manual Installation

1. Download the latest version of the plugin
2. Extract the archive to the `/wp-content/plugins/` folder
3. Activate the plugin from the WordPress "Plugins" menu

### Development Installation

```bash
# Clone the repository
git clone https://github.com/BeAPI/blockparty-post-sharing.git
cd blockparty-post-sharing

# Install PHP dependencies
composer install

# Install JavaScript dependencies
npm install

# Build the assets
npm run build
```

## 🚀 Usage

1. Open the Gutenberg block editor on a post
2. Add a **Post Sharing Button** block (search for "Post Sharing" in the Widgets category)
3. Customize the block:
- **Copy link** and **Share** button labels directly in the editor
- **Display**: choose desktop or mobile viewport and toggle each button visibility
- **Copy Button**: set the label displayed after the link is copied
- **Icon**: show or hide icons and choose left or right position
4. On the frontend:
- **Copy link** copies the current post URL
- **Share** opens the native share dialog when the browser supports it

### Responsive breakpoint

The desktop/mobile breakpoint defaults to `600px`. Themes and plugins can override it with:

```php
add_filter( 'blockparty_post_sharing_breakpoint', function () {
return 782;
} );
```

- **Filter name:** `blockparty_post_sharing_breakpoint`
- **Parameters:** `int` — Breakpoint width in pixels.
- **Default:** `600`

### Icon customization

Default icons are exposed as CSS custom properties on `.wp-block-blockparty-post-sharing-button`:

```css
.wp-block-blockparty-post-sharing-button {
--wp-block-blockparty-post-sharing-button-copy-icon: url( '/path/to/link.svg' );
--wp-block-blockparty-post-sharing-button-share-icon: url( '/path/to/share.svg' );
--wp-block-blockparty-post-sharing-button-check-icon: url( '/path/to/check.svg' );
--wp-block-blockparty-post-sharing-button-icon-size: 1.25rem;
--wp-block-blockparty-post-sharing-button-icon-color: currentColor;
}
```

## 🛠️ Development

### Project Structure

```
blockparty-post-sharing/
├── src/ # Block sources
│ └── blockparty-post-sharing/
│ ├── block.json # Block configuration
│ ├── edit.js # Edit component
│ ├── index.js # Entry point
│ ├── view.js # Frontend copy/share logic
│ ├── img/ # Default SVG icons
│ ├── editor.scss # Editor styles
│ └── style.scss # Frontend and editor styles
├── includes/ # PHP classes
│ ├── BlockRenderer.php # Dynamic block rendering
│ └── ResponsiveDisplay.php # Responsive visibility rules
├── build/ # Compiled assets (blocks-manifest.php, etc.)
├── languages/ # Translation files
├── .wordpress-org/blueprints/ # WordPress Playground blueprint
├── blockparty-post-sharing.php # Main plugin file
├── composer.json # PHP dependencies
└── package.json # JavaScript dependencies
```

### Available Scripts

#### JavaScript

```bash
# Development with hot reload
npm start

# Production build
npm run build

# JavaScript linter
npm run lint:js

# CSS linter
npm run lint:css

# Code formatting
npm run format

# Generate POT file
npm run make-pot

# Generate JSON translation files
npm run make-json

# Create plugin ZIP archive
npm run plugin-zip

# Start local development environment
npm run start:env

# Stop local development environment
npm run stop:env
```

#### PHP

```bash
# Check code with PHP_CodeSniffer
composer cs

# Automatically fix code
composer cb

# Run unit tests
composer phpunit
```

### Coding Standards

The project follows WordPress coding standards:

- **WPCS** (WordPress Coding Standards) for PHP
- **ESLint** with WordPress rules for JavaScript
- **GrumPHP** to automate pre-commit checks

### Development Environment Setup

The plugin uses `@wordpress/env` to create a local WordPress development environment:

```bash
# Start the environment
npm run start:env

# Access WordPress
# URL: http://localhost:8888
# Default credentials: admin / password

# Stop the environment
npm run stop:env
```

## 🔍 Code Quality

The project integrates several quality tools:

- **PHP_CodeSniffer**: PHP coding standards verification
- **PHPCompatibility**: PHP compatibility verification
- **PHP Parallel Lint**: PHP syntax error detection
- **GrumPHP**: Pre-commit checks automation

## 🌍 Internationalization

The plugin is fully internationalized (text domain: `blockparty-post-sharing`). Translation files are available in the `languages/` folder.

### Available Languages

- English (default)
- French (when translation files are provided)

### Adding a Translation

1. Use the `languages/blockparty-post-sharing.pot` file as a base
2. Create your `.po` and `.mo` files
3. Place them in the `languages/` folder

## 🤝 Contributing

Contributions are welcome! To contribute:

1. Fork the project
2. Create a branch for your feature (`git checkout -b feature/AmazingFeature`)
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request

Make sure your code:

- Follows WordPress coding standards
- Passes all quality tests (PHPCS, ESLint)
- Is properly documented
- Includes translations if necessary

## 📄 License

This plugin is distributed under the GPL-2.0-or-later license.

## 👥 Authors

**Be API Technical Team**

- Email: <technical@beapi.fr>
- Website: [https://beapi.fr](https://beapi.fr)

## 🔗 Useful Links

- [WordPress Block Editor Documentation](https://developer.wordpress.org/block-editor/)
- [WordPress Coding Standards](https://developer.wordpress.org/coding-standards/)
- [Block API Reference](https://developer.wordpress.org/block-editor/reference-guides/block-api/)
- [Web Share API (MDN)](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/share)

## 📝 Changelog

See [readme.txt](readme.txt) for the full version history. Recent highlights:

- **1.0.0**
- Initial release with copy and share buttons, editable labels, icons, responsive display settings, and WordPress Playground blueprint.

---

Developed with ❤️ by [Be API](https://beapi.fr)
Loading
Loading