Skip to content

Commit 211c014

Browse files
authored
Merge pull request #1 from humanmade/hm-modal-plugin-creation
HM Modal plugin creation
2 parents e217688 + cd3fa7e commit 211c014

File tree

22 files changed

+17694
-0
lines changed

22 files changed

+17694
-0
lines changed

.github/workflows/release.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Build to "release" branch
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.ref_name }}
10+
cancel-in-progress: true
11+
12+
jobs:
13+
release:
14+
name: "Update release branch"
15+
uses: humanmade/hm-github-actions/.github/workflows/build-and-release-node.yml@a9a243d6c42fbff4a967d7ce0a6b307bc77251b7 # v0.1.0
16+
with:
17+
node_version: 20
18+
source_branch: main
19+
release_branch: release
20+
built_asset_paths: build

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
**/build
2+
3+
/vendor/
4+
/node_modules/

README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# HM Modal Block
2+
3+
Simple modal block for the WordPress block editor.
4+
5+
## Description
6+
7+
This plugin provides a modal component with two blocks:
8+
- **Modal Trigger**: Container block where you add your trigger element (button, image, etc.)
9+
- **Modal Content**: Renders the modal overlay with your content
10+
11+
## Features
12+
13+
- Accessible keyboard navigation with focus trapping
14+
- Auto-pause videos/iframes when modal closes
15+
- Overlay click and Escape key to close
16+
- Customizable trigger and content using any WordPress blocks
17+
18+
## Installation
19+
20+
### For Development
21+
1. Clone or download to `/wp-content/plugins/hm-modal-block/`
22+
2. Run `npm install && npm run build`
23+
3. Activate the plugin in WordPress
24+
25+
### For Production
26+
1. Download from the `dist` branch or release
27+
2. Upload to `/wp-content/plugins/hm-modal-block/`
28+
3. Activate the plugin in WordPress
29+
30+
## Usage
31+
32+
1. Add the **Modal Trigger** block to your page
33+
2. Inside it, you'll see:
34+
- A placeholder paragraph (replace this with your trigger: button, image, text, etc.)
35+
- A **Modal Content** block (automatically added)
36+
3. Add your modal content inside the "Modal Content" block
37+
4. On the front-end, clicking the trigger opens the modal overlay
38+
39+
**Tip:** Add the class `modal-trigger` to your trigger element for explicit targeting, or the first block before Modal Content will automatically become the trigger.
40+
41+
## Development
42+
43+
### Setup
44+
```bash
45+
npm install
46+
composer install
47+
```
48+
49+
### Build
50+
```bash
51+
npm run build
52+
```
53+
54+
### Development Mode
55+
```bash
56+
npm start
57+
```
58+
59+
## Requirements
60+
61+
- WordPress 5.8+
62+
- PHP 7.4+
63+
- Node.js 20.10+
64+
65+
## License
66+
67+
GPL-2.0-or-later
68+
69+
## Author
70+
71+
Human Made Limited - https://humanmade.com

composer.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "humanmade/modal-block",
3+
"description": "Simple modal block for WordPress block editor",
4+
"type": "wordpress-plugin",
5+
"license": "GPL-2.0-or-later",
6+
"authors": [
7+
{
8+
"name": "Human Made Limited",
9+
"email": "[email protected]"
10+
}
11+
],
12+
"require": {
13+
"php": ">=8.2"
14+
},
15+
"require-dev": {
16+
"humanmade/coding-standards": "dev-upgrade-wpcs"
17+
},
18+
"scripts": {
19+
"lint": [
20+
"phpcs --standard=phpcs.xml.dist"
21+
]
22+
}
23+
}

hm-modal-block.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
/**
3+
* HM Modal Block Plugin.
4+
**
5+
* @link https://humanmade.com
6+
* @since 1.0.0
7+
* @package modal-block
8+
*
9+
* Plugin Name: HM Modal Block
10+
* Plugin URI: https://humanmade.com
11+
* Description: Simple modal block for WordPress block editor.
12+
* Version: 1.0.0
13+
* Author: Human Made Limited
14+
* Author URI: https://humanmade.com/
15+
* License: GPL-2.0+
16+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
17+
* Text Domain: hm-modal
18+
* Domain Path: /languages
19+
*/
20+
21+
namespace HM_Modal_Block;
22+
23+
// If this file is called directly, abort.
24+
if ( ! defined( 'WPINC' ) ) {
25+
die;
26+
}
27+
28+
// Check if build files exist.
29+
if ( ! is_readable( __DIR__ . '/build/modal-content/block.json' ) ) {
30+
trigger_error( 'Build files missing', E_USER_WARNING );
31+
return;
32+
}
33+
34+
// Setup custom blocks.
35+
add_action( 'init', function() {
36+
register_block_type( __DIR__ . '/build/modal-trigger' );
37+
register_block_type( __DIR__ . '/build/modal-content' );
38+
} );
39+
40+
add_action( 'wp_enqueue_scripts', function() {
41+
wp_script_add_data( 'hm-modal-trigger-view-script', 'strategy', 'async' );
42+
} );

0 commit comments

Comments
 (0)