@ideasonpurpose/wp-theme-addons 0.3.1 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CssLocalProps/css-local-props.js +1 -1
- package/README.md +54 -20
- package/editor/Block/Extension/Button/button-icon-picker.js +125 -0
- package/editor/Block/Extension/Button/button-icon-picker.scss +65 -0
- package/editor/Block/Variation/Group/LinkedGroup/LinkedGroup.php +22 -7
- package/editor/Block/Variation/Group/LinkedGroup/linked-group.js +5 -6
- package/editor/Block/Variation/Query/RelatedPostsQuery/RelatedPostsQuery.php +1 -1
- package/editor/Block/Variation/Query/RelatedPostsQuery/related-posts-query.js +10 -14
- package/index.d.ts +8 -2
- package/index.js +4 -5
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
# WordPress Theme Addons
|
|
2
2
|
|
|
3
|
-
#### Version 0.
|
|
3
|
+
#### Version 0.4.1
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/@ideasonpurpose/wp-theme-addons)
|
|
6
6
|
[](https://packagist.org/packages/ideasonpurpose/wp-theme-addons)
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
This repository contains JavaScript and PHP add-ons for the WordPress Block Editor and Hybrid themes. The project is used in production, but is under active development and implementations are likely to change.
|
|
8
|
+
This repository contains JavaScript and PHP add-ons for the WordPress Block Editor and Hybrid themes. The project is used in production, but is under active development and implementations are likely to change.
|
|
10
9
|
|
|
11
10
|
## What's in here
|
|
12
11
|
|
|
@@ -16,15 +15,44 @@ This repository contains JavaScript and PHP add-ons for the WordPress Block Edit
|
|
|
16
15
|
|
|
17
16
|
A variation on the Group block which adds standard Link controls. The link implementation uses ideas from [Accessible cards](https://kittygiraudel.com/2022/04/02/accessible-cards/) and [Inclusive Components: Cards](https://inclusive-components.design/cards/).
|
|
18
17
|
|
|
18
|
+
`new LinkedGroup()` wraps the `core/group` render callback and, when the variation has a URL, appends an empty overlay link inside the group. The stretch-link rules live in `editor/Block/Variation/Group/LinkedGroup/linked-group.css`. The editor script imports that file. PHP reads the same file and inlines it on the `iop-linked-group` handle from `wp_enqueue_scripts`, so the rules print in the head. No theme copy is required.
|
|
19
|
+
|
|
19
20
|
#### Related Posts Query
|
|
20
21
|
|
|
21
|
-
A variation on the Query Loop block which replaces the query with ranked related posts. Ranking lives in `lib/RelatedPosts` (`IdeasOnPurpose\WP\RelatedPosts`) — weighted shared taxonomies, post type, and recency, with optional REST at `GET /wp-json/ideasonpurpose/v1/related_posts/{id}
|
|
22
|
+
A variation on the Query Loop block which replaces the query with ranked related posts. Ranking lives in `lib/RelatedPosts` (`IdeasOnPurpose\WP\RelatedPosts`) — weighted shared taxonomies, post type, and recency, with optional REST at `GET /wp-json/ideasonpurpose/v1/related_posts/{id}` (see [PHP usage](#php) to enable it).
|
|
23
|
+
|
|
24
|
+
### Block Extensions
|
|
25
|
+
|
|
26
|
+
#### Button Icons
|
|
27
|
+
|
|
28
|
+
This extension adds an icon-picker to the `core/button` block. Markup is unchanged, icons are specified by adding classes. Classes are added in the Block Editor as well as the front end, so authors can work with a true representation of the final button.
|
|
29
|
+
|
|
30
|
+
```javascript
|
|
31
|
+
import { initButtonIconPicker } from "@ideasonpurpose/wp-theme-addons";
|
|
32
|
+
|
|
33
|
+
initButtonIconPicker(
|
|
34
|
+
[
|
|
35
|
+
{ label: "Arrow Right", value: "arrow-right" },
|
|
36
|
+
{ label: "Mail", value: "mail" },
|
|
37
|
+
{ label: "Download", value: "download" },
|
|
38
|
+
],
|
|
39
|
+
"arrow-right", // optional default icon, defaults to ""
|
|
40
|
+
);
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Icons are displayed using CSS in the theme. Each icon maps to a mask variable the theme defines:
|
|
44
|
+
|
|
45
|
+
```css
|
|
46
|
+
.wp-block-button.iop-button-icon.icon-arrow-right .wp-block-button__link::before {
|
|
47
|
+
mask-image: var(--i-arrow-right);
|
|
48
|
+
}
|
|
49
|
+
```
|
|
22
50
|
|
|
23
51
|
### CSS Local Props
|
|
24
52
|
|
|
25
53
|
Injects block color attributes as CSS custom properties (`--local-text-color`, `--local-bg-color`, `--local-border-color`) so theme styles can use them.
|
|
26
54
|
|
|
27
|
-
This feature
|
|
55
|
+
This feature includes a pair of front-end and block editor files:
|
|
28
56
|
|
|
29
57
|
| File | Runtime | Role |
|
|
30
58
|
| ---------------------------------- | --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
@@ -41,9 +69,11 @@ add_filter('iop/add_css_local_props_allowed_blocks', fn() => ['core/button', 'co
|
|
|
41
69
|
|
|
42
70
|
Both sides must stay in sync: enable PHP for frontend output and call `initCssLocalProps()` in the editor bundle so the canvas matches the saved markup.
|
|
43
71
|
|
|
72
|
+
The PHP block list is localized to the script handle `{stylesheet}-editor` (from `get_stylesheet()`). If the theme's editor script uses a different handle, or is enqueued after `enqueue_block_editor_assets` priority 10, the editor falls back to `core/button`. Pass the list to `initCssLocalProps(['core/button', 'core/group'])` directly in that case.
|
|
73
|
+
|
|
44
74
|
### Utilities
|
|
45
75
|
|
|
46
|
-
A few utility
|
|
76
|
+
A few utility hooks are exported. `usePublicPostTypes` and `usePublicTaxonomies` are direct lifts from the [WordPress Gutenberg source code](https://github.com/WordPress/gutenberg/blob/e90c88fee31120e0091e044c149f8b4f5f947f4a/packages/edit-site/src/components/add-new-template/utils.js#L91-L125). These functions are useful for pre-populating a WordPress data-store with all PostType and Taxonomy data for use in interfaces or block rendering.
|
|
47
77
|
|
|
48
78
|
## Installation
|
|
49
79
|
|
|
@@ -63,7 +93,7 @@ Or in `package.json`:
|
|
|
63
93
|
```json
|
|
64
94
|
{
|
|
65
95
|
"dependencies": {
|
|
66
|
-
"@ideasonpurpose/wp-theme-addons": "^0.
|
|
96
|
+
"@ideasonpurpose/wp-theme-addons": "^0.4.1"
|
|
67
97
|
}
|
|
68
98
|
}
|
|
69
99
|
```
|
|
@@ -90,24 +120,24 @@ Add the VCS repository and require the package in your project's `composer.json`
|
|
|
90
120
|
|
|
91
121
|
### JavaScript
|
|
92
122
|
|
|
93
|
-
Import
|
|
123
|
+
Import into **editor.js**. Minimal required styles are bundled with the JS:
|
|
94
124
|
|
|
95
125
|
```javascript
|
|
96
126
|
// @link https://github.com/ideasonpurpose/wp-theme-addons
|
|
97
|
-
import {
|
|
127
|
+
import {
|
|
128
|
+
initButtonIconPicker,
|
|
129
|
+
initCssLocalProps,
|
|
130
|
+
initLinkedGroupBlock,
|
|
131
|
+
initRelatedPostsQueryBlock,
|
|
132
|
+
} from "@ideasonpurpose/wp-theme-addons";
|
|
98
133
|
|
|
99
|
-
// Instantiate the function
|
|
100
134
|
initLinkedGroupBlock();
|
|
135
|
+
initRelatedPostsQueryBlock();
|
|
101
136
|
initCssLocalProps();
|
|
137
|
+
initButtonIconPicker([...]);
|
|
102
138
|
```
|
|
103
139
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
```scss
|
|
107
|
-
// Import linked-group-front-end styles
|
|
108
|
-
// @link https://github.com/ideasonpurpose/wp-theme-addons
|
|
109
|
-
@use "@ideasonpurpose/wp-theme-addons/editor/block/variation/group-linked-group/linked-group-front-end";
|
|
110
|
-
```
|
|
140
|
+
The package ships untranspiled source: `.js` files contain JSX and import `.scss` files. The theme's build must transpile JSX and compile Sass for this package inside `node_modules`. `@wordpress/*` packages are expected to be provided as externals by the theme's build (for example `@wordpress/scripts`).
|
|
111
141
|
|
|
112
142
|
### PHP
|
|
113
143
|
|
|
@@ -118,13 +148,18 @@ use IdeasOnPurpose\WP\Theme\Addons\Block\Variation\Query\RelatedPostsQuery\Relat
|
|
|
118
148
|
use IdeasOnPurpose\WP\Theme\Addons\CssLocalProps\CssLocalProps;
|
|
119
149
|
|
|
120
150
|
new LinkedGroup();
|
|
121
|
-
new RelatedPostsQuery(); //
|
|
151
|
+
new RelatedPostsQuery(); // uses RelatedPosts for ranking
|
|
122
152
|
new CssLocalProps();
|
|
123
153
|
|
|
154
|
+
// Optional: enables the REST endpoint. Must run before `rest_api_init`, e.g. in functions.php
|
|
155
|
+
new RelatedPosts();
|
|
156
|
+
|
|
124
157
|
// Optional: use the ranker directly
|
|
125
158
|
// $posts = (new RelatedPosts())->get(['post' => $id, 'posts_per_page' => 4]);
|
|
126
159
|
```
|
|
127
160
|
|
|
161
|
+
PHP components require WordPress 6.2 or later (`WP_HTML_Tag_Processor`).
|
|
162
|
+
|
|
128
163
|
## Coexistence
|
|
129
164
|
|
|
130
165
|
npm and Composer operate independently in the same repository:
|
|
@@ -171,7 +206,6 @@ graph TD
|
|
|
171
206
|
- **Composer** reads `composer.json` → installs to `vendor/` → PHP classes autoload via PSR-4
|
|
172
207
|
- No conflicts: separate config files, separate dependency directories, separate language ecosystems.
|
|
173
208
|
|
|
174
|
-
|
|
175
209
|
<!-- START IOP CREDIT BLURB 2026-07-->
|
|
176
210
|
|
|
177
211
|
##
|
|
@@ -179,6 +213,6 @@ graph TD
|
|
|
179
213
|
#### Brought to you by IOP
|
|
180
214
|
|
|
181
215
|
| <a href="https://www.ideasonpurpose.com"><img src="https://raw.githubusercontent.com/ideasonpurpose/ideasonpurpose/master/iop-logo-white-on-black-88px.png" width="44" height="44" align="top" alt="IOP Logo"></a> <br> | This project is actively developed and used in production at <a href="https://www.ideasonpurpose.com">Ideas On Purpose</a>. <br> |
|
|
182
|
-
|
|
|
216
|
+
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
|
|
183
217
|
|
|
184
218
|
<!-- END IOP CREDIT BLURB -->
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import "./button-icon-picker.scss";
|
|
4
|
+
import { InspectorControls } from "@wordpress/block-editor";
|
|
5
|
+
import { PanelBody, SelectControl } from "@wordpress/components";
|
|
6
|
+
import { createHigherOrderComponent } from "@wordpress/compose";
|
|
7
|
+
import { addFilter } from "@wordpress/hooks";
|
|
8
|
+
|
|
9
|
+
/** @type {{ label?: string; value: string }[]} */
|
|
10
|
+
let _icons = [];
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @param {{ label?: string; value: string }[]} [icons]
|
|
14
|
+
* @param {string} [defaultIcon]
|
|
15
|
+
*/
|
|
16
|
+
export function initButtonIconPicker(icons = [], defaultIcon = "") {
|
|
17
|
+
// No icons, do nothing
|
|
18
|
+
if (icons.length === 0) return;
|
|
19
|
+
|
|
20
|
+
_icons = [{ label: "None", value: "" }, ...icons];
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Add attributes to core/button
|
|
24
|
+
*/
|
|
25
|
+
addFilter(
|
|
26
|
+
"blocks.registerBlockType",
|
|
27
|
+
"ideasonpurpose.buttonIconPicker",
|
|
28
|
+
(/** @type {any} */ settings, /** @type {string} */ name) => {
|
|
29
|
+
if (name !== "core/button") return settings;
|
|
30
|
+
const newSettings = { ...settings };
|
|
31
|
+
newSettings.attributes = {
|
|
32
|
+
...newSettings.attributes,
|
|
33
|
+
buttonIcon: { type: "string", default: defaultIcon },
|
|
34
|
+
};
|
|
35
|
+
return newSettings;
|
|
36
|
+
},
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const buttonIconPickerInterface = createHigherOrderComponent(
|
|
41
|
+
(/** @type {any} */ BlockEdit) => {
|
|
42
|
+
return (/** @type {any} */ props) => {
|
|
43
|
+
if (props.name !== "core/button") {
|
|
44
|
+
return <BlockEdit {...props} />;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const { attributes, setAttributes } = props;
|
|
48
|
+
const { buttonIcon } = attributes;
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<>
|
|
52
|
+
<BlockEdit {...props} />
|
|
53
|
+
<InspectorControls group="styles">
|
|
54
|
+
<PanelBody title="IOP Button Icon" initialOpen={true}>
|
|
55
|
+
<SelectControl
|
|
56
|
+
label="Select an icon"
|
|
57
|
+
value={buttonIcon}
|
|
58
|
+
__next40pxDefaultSize={true}
|
|
59
|
+
options={_icons}
|
|
60
|
+
onChange={(/** @type {any} */ value) =>
|
|
61
|
+
setAttributes({ buttonIcon: value })
|
|
62
|
+
}
|
|
63
|
+
/>
|
|
64
|
+
</PanelBody>
|
|
65
|
+
</InspectorControls>
|
|
66
|
+
</>
|
|
67
|
+
);
|
|
68
|
+
};
|
|
69
|
+
},
|
|
70
|
+
"buttonIconPickerInterface",
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
addFilter(
|
|
74
|
+
"editor.BlockEdit",
|
|
75
|
+
"ideasonpurpose.buttonIconPicker.BlockEdit",
|
|
76
|
+
buttonIconPickerInterface,
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Add icon class to the button wrapper for both save and editor preview
|
|
81
|
+
*/
|
|
82
|
+
addFilter(
|
|
83
|
+
"blocks.getSaveContent.extraProps",
|
|
84
|
+
"ideasonpurpose.buttonIconPicker.extraProps",
|
|
85
|
+
(
|
|
86
|
+
/** @type {any} */ extraProps,
|
|
87
|
+
/** @type {any} */ blockType,
|
|
88
|
+
/** @type {any} */ attributes,
|
|
89
|
+
) => {
|
|
90
|
+
if (blockType.name !== "core/button") return extraProps;
|
|
91
|
+
const { buttonIcon } = attributes;
|
|
92
|
+
if (buttonIcon) {
|
|
93
|
+
extraProps.className = [
|
|
94
|
+
extraProps.className,
|
|
95
|
+
"iop-button-icon",
|
|
96
|
+
`icon-${buttonIcon}`,
|
|
97
|
+
]
|
|
98
|
+
.filter(Boolean)
|
|
99
|
+
.join(" ");
|
|
100
|
+
}
|
|
101
|
+
return extraProps;
|
|
102
|
+
},
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
const buttonIconClass = createHigherOrderComponent(
|
|
106
|
+
(/** @type {any} */ BlockListBlock) => {
|
|
107
|
+
return (/** @type {any} */ props) => {
|
|
108
|
+
if (props.name !== "core/button") {
|
|
109
|
+
return <BlockListBlock {...props} />;
|
|
110
|
+
}
|
|
111
|
+
const { attributes, className } = props;
|
|
112
|
+
const { buttonIcon } = attributes;
|
|
113
|
+
const iconClass = buttonIcon ? `iop-button-icon icon-${buttonIcon}` : "";
|
|
114
|
+
const newClassName = [className, iconClass].filter(Boolean).join(" ");
|
|
115
|
+
return <BlockListBlock {...props} className={newClassName} />;
|
|
116
|
+
};
|
|
117
|
+
},
|
|
118
|
+
"buttonIconClass",
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
addFilter(
|
|
122
|
+
"editor.BlockListBlock",
|
|
123
|
+
"ideasonpurpose.buttonIconPicker.BlockListBlock",
|
|
124
|
+
buttonIconClass,
|
|
125
|
+
);
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// Button Icon Picker — generic front-end + editor boilerplate.
|
|
2
|
+
//
|
|
3
|
+
// Pairs with editor/Block/Extension/Button/button-icon-picker.js, which writes
|
|
4
|
+
// `iop-button-icon icon-{name}` classes onto the core/button wrapper.
|
|
5
|
+
//
|
|
6
|
+
// The ::before element renders the glyph via `mask-image`. Each icon needs a
|
|
7
|
+
// corresponding mask variable (usually a `url("data:image/svg+xml,...")`
|
|
8
|
+
// defined by the theme), e.g.:
|
|
9
|
+
//
|
|
10
|
+
// .wp-block-button.iop-button-icon.icon-arrow-right .wp-block-button__link::before {
|
|
11
|
+
// mask-image: var(--i-arrow-right);
|
|
12
|
+
// }
|
|
13
|
+
//
|
|
14
|
+
// Icon sizing uses `1.2em` so the glyph scales with the button's font-size.
|
|
15
|
+
// Override width/height per project as needed.
|
|
16
|
+
|
|
17
|
+
.wp-block-button {
|
|
18
|
+
&.iop-button-icon .wp-block-button__link {
|
|
19
|
+
display: flex;
|
|
20
|
+
flex-direction: row;
|
|
21
|
+
gap: 0.5em;
|
|
22
|
+
align-items: center;
|
|
23
|
+
|
|
24
|
+
&.has-text-align-right {
|
|
25
|
+
flex-direction: row-reverse;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
&::before {
|
|
29
|
+
content: "";
|
|
30
|
+
|
|
31
|
+
display: block;
|
|
32
|
+
flex-shrink: 0;
|
|
33
|
+
width: 1.2em;
|
|
34
|
+
height: 1.2em;
|
|
35
|
+
|
|
36
|
+
background: currentColor;
|
|
37
|
+
|
|
38
|
+
mask-repeat: no-repeat;
|
|
39
|
+
mask-size: contain;
|
|
40
|
+
mask-position: center;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Example icon rules, add these to the active theme.
|
|
46
|
+
// vars represent SVG files loaded with url() like this
|
|
47
|
+
// :root {
|
|
48
|
+
// --i-arrow-right: url("../svg/arrow-right.svg");
|
|
49
|
+
// }
|
|
50
|
+
//
|
|
51
|
+
// .wp-block-button {
|
|
52
|
+
// &.iop-button-icon {
|
|
53
|
+
// &.icon-arrow-right .wp-block-button__link::before {
|
|
54
|
+
// mask-image: var(--i-arrow-right);
|
|
55
|
+
// }
|
|
56
|
+
//
|
|
57
|
+
// &.icon-mail .wp-block-button__link::before {
|
|
58
|
+
// mask-image: var(--i-mail);
|
|
59
|
+
// }
|
|
60
|
+
//
|
|
61
|
+
// &.icon-download .wp-block-button__link::before {
|
|
62
|
+
// mask-image: var(--i-download);
|
|
63
|
+
// }
|
|
64
|
+
// }
|
|
65
|
+
// }
|
|
@@ -23,13 +23,6 @@ class LinkedGroup
|
|
|
23
23
|
add_action('wp_enqueue_scripts', [$this, 'enqueue_styles']);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
public function enqueue_styles()
|
|
27
|
-
{
|
|
28
|
-
$css_file = __DIR__ . '/linked-group.css';
|
|
29
|
-
$css_url = home_url(str_replace(ABSPATH, '', $css_file));
|
|
30
|
-
wp_enqueue_style('iop-linked-group', $css_url, [], filemtime($css_file));
|
|
31
|
-
}
|
|
32
|
-
|
|
33
26
|
public function wrap_render_callback($args, $block_type)
|
|
34
27
|
{
|
|
35
28
|
if ($block_type === $this->src_block_name) {
|
|
@@ -81,4 +74,26 @@ class LinkedGroup
|
|
|
81
74
|
|
|
82
75
|
return $blockHTML;
|
|
83
76
|
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Inline the same CSS the editor imports. Construction is the opt-in,
|
|
80
|
+
* so this runs on wp_enqueue_scripts and prints in the head.
|
|
81
|
+
*/
|
|
82
|
+
public function enqueue_styles()
|
|
83
|
+
{
|
|
84
|
+
static $done = false;
|
|
85
|
+
if ($done) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
$done = true;
|
|
89
|
+
|
|
90
|
+
$css = file_get_contents(__DIR__ . '/linked-group.css');
|
|
91
|
+
if (!$css) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
wp_register_style('iop-linked-group', false);
|
|
96
|
+
wp_add_inline_style('iop-linked-group', $css);
|
|
97
|
+
wp_enqueue_style('iop-linked-group');
|
|
98
|
+
}
|
|
84
99
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
|
+
import "./linked-group.css";
|
|
3
4
|
import {
|
|
4
5
|
BlockControls,
|
|
5
6
|
InspectorControls,
|
|
6
7
|
LinkControl,
|
|
7
8
|
} from "@wordpress/block-editor";
|
|
8
|
-
import {
|
|
9
|
+
import { createBlock, registerBlockVariation } from "@wordpress/blocks";
|
|
9
10
|
import {
|
|
10
11
|
ExternalLink,
|
|
11
12
|
Popover,
|
|
@@ -17,12 +18,11 @@ import {
|
|
|
17
18
|
__experimentalToolsPanelItem as ToolsPanelItem,
|
|
18
19
|
} from "@wordpress/components";
|
|
19
20
|
import { createHigherOrderComponent } from "@wordpress/compose";
|
|
20
|
-
import {
|
|
21
|
+
// import { select, useSelect, withSelect } from "@wordpress/data";
|
|
22
|
+
import { createInterpolateElement, useState } from "@wordpress/element";
|
|
21
23
|
import { addFilter } from "@wordpress/hooks";
|
|
22
|
-
import { SVG, Path } from "@wordpress/primitives";
|
|
23
24
|
import { __ } from "@wordpress/i18n";
|
|
24
|
-
|
|
25
|
-
import { createInterpolateElement } from "@wordpress/element";
|
|
25
|
+
import { Path, SVG } from "@wordpress/primitives";
|
|
26
26
|
|
|
27
27
|
export default {};
|
|
28
28
|
|
|
@@ -271,7 +271,6 @@ const makeSaveElement = (element, blockType, attributes) => {
|
|
|
271
271
|
|
|
272
272
|
const href = linkToSelf ? "#__LINKED_GROUP_PLACEHOLDER__" : url;
|
|
273
273
|
|
|
274
|
-
|
|
275
274
|
const link = (
|
|
276
275
|
<a
|
|
277
276
|
href={href}
|
|
@@ -74,7 +74,7 @@ class RelatedPostsQuery
|
|
|
74
74
|
global $post;
|
|
75
75
|
$postTypes = $request->get_param('postTypes') ?? [];
|
|
76
76
|
$weights = $request->get_param('weights') ?? [];
|
|
77
|
-
$relatedPost = $request->get_param('relatedPost') ??
|
|
77
|
+
$relatedPost = $request->get_param('relatedPost') ?? $post->ID ?? 0;
|
|
78
78
|
|
|
79
79
|
if ($weights) {
|
|
80
80
|
$rpArgs = [
|
|
@@ -1,24 +1,20 @@
|
|
|
1
|
-
import { registerBlockVariation } from "@wordpress/blocks";
|
|
2
|
-
import { addFilter } from "@wordpress/hooks";
|
|
3
|
-
import { SVG, Path } from "@wordpress/primitives";
|
|
4
|
-
|
|
5
|
-
import { usePublicPostTypes } from "../../../../../lib/use-public-post-types.js";
|
|
6
|
-
import { usePublicTaxonomies } from "../../../../../lib/use-public-taxonomies.js";
|
|
7
|
-
|
|
8
|
-
import { createHigherOrderComponent } from "@wordpress/compose";
|
|
9
|
-
|
|
10
|
-
import { store as coreStore } from "@wordpress/core-data";
|
|
11
|
-
import { store as editorStore } from "@wordpress/editor";
|
|
12
|
-
|
|
13
1
|
import { InspectorControls } from "@wordpress/block-editor";
|
|
14
|
-
import {
|
|
2
|
+
import { registerBlockVariation } from "@wordpress/blocks";
|
|
15
3
|
import {
|
|
4
|
+
PanelBody,
|
|
16
5
|
RangeControl,
|
|
17
6
|
SelectControl,
|
|
18
7
|
Spinner,
|
|
19
8
|
Tip,
|
|
20
|
-
PanelBody,
|
|
21
9
|
} from "@wordpress/components";
|
|
10
|
+
import { createHigherOrderComponent } from "@wordpress/compose";
|
|
11
|
+
import { store as coreStore } from "@wordpress/core-data";
|
|
12
|
+
import { select } from "@wordpress/data";
|
|
13
|
+
import { store as editorStore } from "@wordpress/editor";
|
|
14
|
+
import { addFilter } from "@wordpress/hooks";
|
|
15
|
+
import { Path, SVG } from "@wordpress/primitives";
|
|
16
|
+
import { usePublicPostTypes } from "../../../../../lib/use-public-post-types.js";
|
|
17
|
+
import { usePublicTaxonomies } from "../../../../../lib/use-public-taxonomies.js";
|
|
22
18
|
|
|
23
19
|
const icon = (
|
|
24
20
|
<SVG
|
package/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
declare module "*.scss" {}
|
|
2
|
+
|
|
1
3
|
declare module "@ideasonpurpose/wp-theme-addons" {
|
|
2
4
|
interface WP_Post_Type {
|
|
3
5
|
slug: string;
|
|
@@ -24,7 +26,11 @@ declare module "@ideasonpurpose/wp-theme-addons" {
|
|
|
24
26
|
export function usePublicPostTypes(): WP_Post_Type[] | undefined;
|
|
25
27
|
export function usePublicTaxonomies(): WP_Taxonomy[] | undefined;
|
|
26
28
|
|
|
29
|
+
export function initButtonIconPicker(
|
|
30
|
+
icons?: { label?: string; value: string }[],
|
|
31
|
+
defaultIcon?: string,
|
|
32
|
+
): void;
|
|
33
|
+
export function initCssLocalProps(blockNames?: string[]): void;
|
|
27
34
|
export function initLinkedGroupBlock(): void;
|
|
28
35
|
export function initRelatedPostsQueryBlock(): void;
|
|
29
|
-
|
|
30
|
-
}
|
|
36
|
+
}
|
package/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
|
|
1
|
+
export { initCssLocalProps } from "./CssLocalProps/css-local-props.js";
|
|
2
|
+
export { initButtonIconPicker } from "./editor/Block/Extension/Button/button-icon-picker.js";
|
|
4
3
|
export { initLinkedGroupBlock } from "./editor/Block/Variation/Group/LinkedGroup/linked-group.js";
|
|
5
4
|
export { initRelatedPostsQueryBlock } from "./editor/Block/Variation/Query/RelatedPostsQuery/related-posts-query.js";
|
|
6
|
-
|
|
7
|
-
export {
|
|
5
|
+
export { usePublicPostTypes } from "./lib/use-public-post-types.js";
|
|
6
|
+
export { usePublicTaxonomies } from "./lib/use-public-taxonomies.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ideasonpurpose/wp-theme-addons",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "WordPress Block Editor add-ons — JavaScript blocks, utilities, and PHP components",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"wordpress",
|
|
@@ -60,6 +60,7 @@
|
|
|
60
60
|
"version-everything": {
|
|
61
61
|
"files": [
|
|
62
62
|
"README.md"
|
|
63
|
-
]
|
|
63
|
+
],
|
|
64
|
+
"prefix": "\"@ideasonpurpose/wp-theme-addons\": \"\\^"
|
|
64
65
|
}
|
|
65
66
|
}
|