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
2 changes: 1 addition & 1 deletion .plugin-data
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"version": "1.0.0",
"version": "1.1.0",
"slug": "blockparty-post-sharing"
}
2 changes: 1 addition & 1 deletion .wordpress-org/blueprints/blueprint.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"pluginData": {
"resource": "git:directory",
"url": "https://github.com/BeAPI/blockparty-post-sharing",
"ref": "1.0.0",
"ref": "1.1.0",
"refType": "tag"
},
"options": {
Expand Down
3 changes: 2 additions & 1 deletion .wp-env.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"plugins": [
"."
]
],
"testsEnvironment": false
}
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Changelog

All notable changes to this project are documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.1.0] - 2026-08-07

### Added

- Social share fallback menu when the Web Share API is unavailable (Facebook, X, Bluesky, LinkedIn, WhatsApp).
- `blockparty_post_sharing_networks` filter to customize share networks from PHP.
- CSS custom properties and network icons for the fallback menu.
- Manual class loading fallback when Composer autoload is unavailable.

## [1.0.0] - 2026-06-19

### Added

- Initial release with copy and share buttons, editable labels, icons, responsive display settings, and WordPress Playground blueprint.
71 changes: 64 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,44 @@ add_filter( 'blockparty_post_sharing_breakpoint', function () {
- **Parameters:** `int` — Breakpoint width in pixels.
- **Default:** `600`

### Icon customization
### Share networks (fallback menu)

Default icons are exposed as CSS custom properties on `.wp-block-blockparty-post-sharing-button`:
When the Web Share API is unavailable, the Share button opens a menu of social networks. Themes and plugins can customize the list with:

```php
add_filter( 'blockparty_post_sharing_networks', function ( $networks, $url, $title, $post_id ) {
// Remove WhatsApp.
$networks = array_values(
array_filter(
$networks,
static function ( $network ) {
return ( $network['id'] ?? '' ) !== 'whatsapp';
}
)
);

// Add Mastodon.
$networks[] = [
'id' => 'mastodon',
'label' => 'Mastodon',
'url' => 'https://mastodon.social/share?text=' . rawurlencode( $title . ' ' . $url ),
];

return $networks;
}, 10, 4 );
```

- **Filter name:** `blockparty_post_sharing_networks`
- **Parameters:**
- `array $networks` — List of networks (`id`, `label`, `url`)
- `string $url` — Post permalink
- `string $title` — Post title
- `int $post_id` — Post ID
- **Default:** Facebook, X, Bluesky, LinkedIn, WhatsApp

### Icon and menu customization

Default icons and the share fallback menu are exposed as CSS custom properties on `.wp-block-blockparty-post-sharing-button`:

```css
.wp-block-blockparty-post-sharing-button {
Expand All @@ -101,6 +136,30 @@ Default icons are exposed as CSS custom properties on `.wp-block-blockparty-post
--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;

/* Share fallback menu */
--wp-block-blockparty-post-sharing-button-menu-offset: 0.5rem;
--wp-block-blockparty-post-sharing-button-menu-min-width: 12rem;
--wp-block-blockparty-post-sharing-button-menu-padding: 0.5rem;
--wp-block-blockparty-post-sharing-button-menu-gap: 0.25rem;
--wp-block-blockparty-post-sharing-button-menu-border-width: 1px;
--wp-block-blockparty-post-sharing-button-menu-border-style: solid;
--wp-block-blockparty-post-sharing-button-menu-border-color: currentColor;
--wp-block-blockparty-post-sharing-button-menu-border-radius: 0.25rem;
--wp-block-blockparty-post-sharing-button-menu-bg: #fff;
--wp-block-blockparty-post-sharing-button-menu-color: currentColor;
--wp-block-blockparty-post-sharing-button-menu-shadow: 0 0.25rem 0.75rem rgba(0, 0, 0, 0.12);
--wp-block-blockparty-post-sharing-button-menu-link-padding: 0.5rem 0.75rem;
--wp-block-blockparty-post-sharing-button-menu-link-border-radius: 0.125rem;
--wp-block-blockparty-post-sharing-button-menu-link-hover-bg: rgba(0, 0, 0, 0.06);
--wp-block-blockparty-post-sharing-button-menu-link-gap: 0.5rem;
--wp-block-blockparty-post-sharing-button-menu-icon-size: 1.25rem;
--wp-block-blockparty-post-sharing-button-menu-icon-color: currentColor;
--wp-block-blockparty-post-sharing-button-menu-facebook-icon: url( '/path/to/facebook.svg' );
--wp-block-blockparty-post-sharing-button-menu-x-icon: url( '/path/to/x.svg' );
--wp-block-blockparty-post-sharing-button-menu-bluesky-icon: url( '/path/to/bluesky.svg' );
--wp-block-blockparty-post-sharing-button-menu-linkedin-icon: url( '/path/to/linkedin.svg' );
--wp-block-blockparty-post-sharing-button-menu-whatsapp-icon: url( '/path/to/whatsapp.svg' );
}
```

Expand All @@ -121,7 +180,8 @@ blockparty-post-sharing/
│ └── style.scss # Frontend and editor styles
├── includes/ # PHP classes
│ ├── BlockRenderer.php # Dynamic block rendering
│ └── ResponsiveDisplay.php # Responsive visibility rules
│ ├── ResponsiveDisplay.php # Responsive visibility rules
│ └── ShareNetworks.php # Share fallback networks (filterable)
├── build/ # Compiled assets (blocks-manifest.php, etc.)
├── languages/ # Translation files
├── .wordpress-org/blueprints/ # WordPress Playground blueprint
Expand Down Expand Up @@ -264,10 +324,7 @@ This plugin is distributed under the GPL-2.0-or-later license.

## 📝 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.
See [CHANGELOG.md](CHANGELOG.md) for the full version history.

---

Expand Down
10 changes: 7 additions & 3 deletions blockparty-post-sharing.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Plugin Name: Blockparty Post Sharing
* Description: Add a block to copy and share the current post URL.
* Version: 1.0.0
* Version: 1.1.0
* Requires at least: 6.8
* Requires PHP: 8.1
* Author: Be API Technical Team
Expand All @@ -22,10 +22,14 @@
}

if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) {
include_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/vendor/autoload.php';
} else {
require_once __DIR__ . '/includes/BlockRenderer.php';
require_once __DIR__ . '/includes/ResponsiveDisplay.php';
require_once __DIR__ . '/includes/ShareNetworks.php';
}

define( 'BLOCKPARTY_POST_SHARING_VERSION', '1.0.0' );
define( 'BLOCKPARTY_POST_SHARING_VERSION', '1.1.0' );
define( 'BLOCKPARTY_POST_SHARING_URL', plugin_dir_url( __FILE__ ) );
define( 'BLOCKPARTY_POST_SHARING_DIR', plugin_dir_path( __FILE__ ) );
define( 'BLOCKPARTY_POST_SHARING_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
Expand Down
3 changes: 3 additions & 0 deletions includes/BlockRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public static function render( $attributes ) {
'data-url' => esc_url( $url ),
'data-title' => esc_attr( $title ),
'data-copied-label' => esc_attr( $copied_label ),
'data-networks' => wp_json_encode(
ShareNetworks::get_networks( $url, $title, (int) $post_id )
),
];

if ( ! empty( $wrapper_classes ) ) {
Expand Down
107 changes: 107 additions & 0 deletions includes/ShareNetworks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php

namespace Blockparty\PostSharing;

class ShareNetworks {

/**
* Get social networks for the share fallback menu.
*
* @param string $url Post permalink.
* @param string $title Post title.
* @param int $post_id Post ID.
*
* @return array<int, array{id: string, label: string, url: string}>
*/
public static function get_networks( string $url, string $title = '', int $post_id = 0 ): array {
$encoded_url = rawurlencode( $url );
$encoded_title = rawurlencode( $title );
$encoded_text = rawurlencode( '' !== $title ? $title . ' ' . $url : $url );

$networks = [
[
'id' => 'facebook',
'label' => 'Facebook',
'url' => 'https://www.facebook.com/sharer/sharer.php?u=' . $encoded_url,
],
[
'id' => 'x',
'label' => 'X',
'url' => 'https://x.com/intent/post?url=' . $encoded_url . '&text=' . $encoded_title,
],
[
'id' => 'bluesky',
'label' => 'Bluesky',
'url' => 'https://bsky.app/intent/compose?text=' . $encoded_text,
],
[
'id' => 'linkedin',
'label' => 'LinkedIn',
'url' => 'https://www.linkedin.com/sharing/share-offsite/?url=' . $encoded_url,
],
[
'id' => 'whatsapp',
'label' => 'WhatsApp',
'url' => 'https://api.whatsapp.com/send?text=' . $encoded_text,
],
];

/**
* Filter social networks used in the share fallback menu.
*
* Each network should provide:
* - id (string): Network slug used as a CSS modifier.
* - label (string): Visible network name.
* - url (string): Absolute share URL for the current post.
*
* @param array $networks Social network definitions.
* @param string $url Post permalink.
* @param string $title Post title.
* @param int $post_id Post ID.
*/
$networks = apply_filters(
'blockparty_post_sharing_networks',
$networks,
$url,
$title,
$post_id
);

if ( ! is_array( $networks ) ) {
return [];
}

return array_values(
array_filter(
array_map( [ self::class, 'sanitize_network' ], $networks )
)
);
}

/**
* Sanitize a single network definition.
*
* @param mixed $network Network definition.
*
* @return array{id: string, label: string, url: string}|null
*/
private static function sanitize_network( $network ): ?array {
if ( ! is_array( $network ) ) {
return null;
}

$id = isset( $network['id'] ) ? sanitize_key( (string) $network['id'] ) : '';
$label = isset( $network['label'] ) ? sanitize_text_field( (string) $network['label'] ) : '';
$url = isset( $network['url'] ) ? esc_url_raw( (string) $network['url'] ) : '';

if ( '' === $id || '' === $label || '' === $url ) {
return null;
}

return [
'id' => $id,
'label' => $label,
'url' => $url,
];
}
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"translation-revision-date":"2026-06-19 15:34+0200","generator":"WP-CLI\/2.11.0","source":"build\/blockparty-post-sharing\/view.js","domain":"messages","locale_data":{"messages":{"":{"domain":"messages","lang":"fr_FR","plural-forms":"nplurals=2; plural=(n != 1);"},"Link copied":["Lien copi\u00e9"],"Unable to copy link":["Impossible de copier le lien"],"Unable to share":["Impossible de partager"]}}}
{"translation-revision-date":"2026-08-07 16:19+0200","generator":"WP-CLI\/2.11.0","source":"build\/blockparty-post-sharing\/view.js","domain":"messages","locale_data":{"messages":{"":{"domain":"messages","lang":"fr_FR","plural-forms":"nplurals=2; plural=(n != 1);"},"Link copied":["Lien copi\u00e9"],"Unable to copy link":["Impossible de copier le lien"],"Unable to share":["Impossible de partager"],"Share on social networks":["Partager sur les r\u00e9seaux sociaux"],"Share on %s":["Partager sur %s"]}}}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"translation-revision-date":"2026-06-19 15:34+0200","generator":"WP-CLI\/2.11.0","source":"build\/blockparty-post-sharing\/index.js","domain":"messages","locale_data":{"messages":{"":{"domain":"messages","lang":"fr_FR","plural-forms":"nplurals=2; plural=(n != 1);"},"Copy link":["Copier le lien"],"Share":["Partager"],"Link copied":["Lien copi\u00e9"],"Display":["Affichage"],"Viewport":["Appareil"],"Desktop":["Ordinateur"],"Mobile":["Mobile"],"Display copy button":["Afficher le bouton de copie"],"Display share button":["Afficher le bouton de partage"],"Copy Button":["Bouton de copie"],"Copied link label":["Libell\u00e9 du bouton de copie"],"Text displayed on the copy button after the link is copied.":["Texte du bouton de copie qui s\u2019affiche apr\u00e8s que le lien soit copi\u00e9."],"Icon":["Ic\u00f4ne"],"Show icon":["Afficher l\u2019ic\u00f4ne"],"Icon position":["Position de l\u2019ic\u00f4ne"],"Left":["Gauche"],"Right":["Droite"],"Copy action is available on the front end only.":["Les actions de copie sont uniquement disponibles sur l\u2019interface publique."],"Share action is available on the front end only.":["Les actions de partage sont uniquement disponibles sur l\u2019interface publique."]}}}
{"translation-revision-date":"2026-08-07 16:19+0200","generator":"WP-CLI\/2.11.0","source":"build\/blockparty-post-sharing\/index.js","domain":"messages","locale_data":{"messages":{"":{"domain":"messages","lang":"fr_FR","plural-forms":"nplurals=2; plural=(n != 1);"},"Copy link":["Copier le lien"],"Share":["Partager"],"Link copied":["Lien copi\u00e9"],"Display":["Affichage"],"Viewport":["Appareil"],"Desktop":["Ordinateur"],"Mobile":["Mobile"],"Display copy button":["Afficher le bouton de copie"],"Display share button":["Afficher le bouton de partage"],"Copy Button":["Bouton de copie"],"Copied link label":["Libell\u00e9 du bouton de copie"],"Text displayed on the copy button after the link is copied.":["Texte du bouton de copie qui s\u2019affiche apr\u00e8s que le lien soit copi\u00e9."],"Icon":["Ic\u00f4ne"],"Show icon":["Afficher l\u2019ic\u00f4ne"],"Icon position":["Position de l\u2019ic\u00f4ne"],"Left":["Gauche"],"Right":["Droite"],"Copy action is available on the front end only.":["Les actions de copie sont uniquement disponibles sur l\u2019interface publique."],"Share action is available on the front end only.":["Les actions de partage sont uniquement disponibles sur l\u2019interface publique."]}}}
Binary file modified languages/blockparty-post-sharing-fr_FR.mo
Binary file not shown.
13 changes: 11 additions & 2 deletions languages/blockparty-post-sharing-fr_FR.po
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ msgstr ""
"Project-Id-Version: Blockparty Post Sharing 1.0.0\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/blockparty-post-"
"sharing\n"
"POT-Creation-Date: 2026-06-19T13:34:14+00:00\n"
"PO-Revision-Date: 2026-06-19 15:34+0200\n"
"POT-Creation-Date: 2026-08-07T14:19:19+00:00\n"
"PO-Revision-Date: 2026-08-07 16:19+0200\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: fr_FR\n"
Expand Down Expand Up @@ -124,6 +124,15 @@ msgstr "Impossible de copier le lien"
msgid "Unable to share"
msgstr "Impossible de partager"

#: build/blockparty-post-sharing/view.js:1
msgid "Share on social networks"
msgstr "Partager sur les réseaux sociaux"

#. translators: %s: social network name
#: build/blockparty-post-sharing/view.js:2
msgid "Share on %s"
msgstr "Partager sur %s"

#: build/blockparty-post-sharing/block.json
msgctxt "block title"
msgid "Post Sharing Button"
Expand Down
13 changes: 11 additions & 2 deletions languages/blockparty-post-sharing.pot
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
# This file is distributed under the GPL-2.0-or-later.
msgid ""
msgstr ""
"Project-Id-Version: Blockparty Post Sharing 1.0.0\n"
"Project-Id-Version: Blockparty Post Sharing 1.1.0\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/blockparty-post-sharing\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"POT-Creation-Date: 2026-06-19T13:34:14+00:00\n"
"POT-Creation-Date: 2026-08-07T14:19:19+00:00\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"X-Generator: WP-CLI 2.11.0\n"
"X-Domain: blockparty-post-sharing\n"
Expand Down Expand Up @@ -122,6 +122,15 @@ msgstr ""
msgid "Unable to share"
msgstr ""

#: build/blockparty-post-sharing/view.js:1
msgid "Share on social networks"
msgstr ""

#. translators: %s: social network name
#: build/blockparty-post-sharing/view.js:2
msgid "Share on %s"
msgstr ""

#: build/blockparty-post-sharing/block.json
msgctxt "block title"
msgid "Post Sharing Button"
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "blockparty-post-sharing",
"version": "1.0.0",
"version": "1.1.0",
"description": "Example block scaffolded with Create Block tool.",
"author": "The WordPress Contributors",
"license": "GPL-2.0-or-later",
Expand All @@ -15,8 +15,8 @@
"make-pot": "wp i18n make-pot . languages/blockparty-post-sharing.pot --exclude=\"src\" --domain=blockparty-post-sharing",
"make-json": "wp i18n make-json languages/blockparty-post-sharing-fr_FR.po languages/ --no-purge",
"start": "wp-scripts start --blocks-manifest",
"start:env": "wp-env start",
"stop:env": "wp-env stop"
"env:start": "wp-env start",
"env:stop": "wp-env stop"
},
"dependencies": {
"@wordpress/block-editor": "latest",
Expand Down
Loading
Loading