added ability to open social links in new tab

development
Michael Ochmann 2 weeks ago
parent 51d6a5057a
commit be836d1b49
  1. 6
      javascript/blocks/wpsi-menu/build/block.json
  2. 2
      javascript/blocks/wpsi-menu/build/index.asset.php
  3. 23
      javascript/blocks/wpsi-menu/build/index.js
  4. 2
      javascript/blocks/wpsi-menu/build/index.js.map
  5. 3
      javascript/blocks/wpsi-menu/build/render.php
  6. 6
      javascript/blocks/wpsi-menu/src/block.json
  7. 9
      javascript/blocks/wpsi-menu/src/edit.js
  8. 3
      javascript/blocks/wpsi-menu/src/render.php
  9. 2
      javascript/blocks/wpsi-menu/src/save.js
  10. 7
      src/Frontend.php
  11. 2
      wp-social-icons.php

@ -2,7 +2,7 @@
"$schema": "https://schemas.wp.org/trunk/block.json", "$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 3, "apiVersion": 3,
"name": "massivedynamic/wpsi-menu", "name": "massivedynamic/wpsi-menu",
"version": "0.0.1", "version": "0.1.0",
"title": "WP Social Icons Menu", "title": "WP Social Icons Menu",
"category": "widgets", "category": "widgets",
"icon": "networking", "icon": "networking",
@ -32,6 +32,10 @@
"exclude": { "exclude": {
"type": "array", "type": "array",
"default": [] "default": []
},
"openInNewTab": {
"type": "boolean",
"default": false
} }
}, },
"textdomain": "wpsi-menu", "textdomain": "wpsi-menu",

@ -1 +1 @@
<?php return array('dependencies' => array('react-jsx-runtime', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '0f8272dc7fc5d65bc4e2'); <?php return array('dependencies' => array('react-jsx-runtime', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '620ad439ae4501db362c');

@ -163,7 +163,7 @@ const justifyCenter = /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE
\************************/ \************************/
/***/ ((module) => { /***/ ((module) => {
module.exports = /*#__PURE__*/JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":3,"name":"massivedynamic/wpsi-menu","version":"0.0.1","title":"WP Social Icons Menu","category":"widgets","icon":"networking","description":"WP Social Icons Menu Block for Gutenberg","example":{},"supports":{"html":false},"attributes":{"orientation":{"type":"string","enum":["horizontal","vertical"],"default":"horizontal"},"alignment":{"type":"string","enum":["left","center","right"],"default":"center"},"exclude":{"type":"array","default":[]}},"textdomain":"wpsi-menu","editorScript":"file:./index.js","editorStyle":"file:./index.css","style":"file:./style-index.css","render":"file:./render.php"}'); module.exports = /*#__PURE__*/JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":3,"name":"massivedynamic/wpsi-menu","version":"0.0.1","title":"WP Social Icons Menu","category":"widgets","icon":"networking","description":"WP Social Icons Menu Block for Gutenberg","example":{},"supports":{"html":false},"attributes":{"orientation":{"type":"string","enum":["horizontal","vertical"],"default":"horizontal"},"alignment":{"type":"string","enum":["left","center","right"],"default":"center"},"exclude":{"type":"array","default":[]},"openInNewTab":{"type":"boolean","default":false}},"textdomain":"wpsi-menu","editorScript":"file:./index.js","editorStyle":"file:./index.css","style":"file:./style-index.css","render":"file:./render.php"}');
/***/ }), /***/ }),
@ -211,7 +211,8 @@ const Edit = ({
const { const {
alignment, alignment,
orientation, orientation,
exclude exclude,
openInNewTab
} = attributes; } = attributes;
const iterator = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_2__.useMemo)(() => { const iterator = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_2__.useMemo)(() => {
const out = []; const out = [];
@ -238,8 +239,8 @@ const Edit = ({
}, []); }, []);
return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsxs)("section", { return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsxs)("section", {
...(0,_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_1__.useBlockProps)(), ...(0,_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_1__.useBlockProps)(),
children: [/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsx)(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_1__.InspectorControls, { children: [/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsxs)(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_1__.InspectorControls, {
children: /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_4__.PanelBody, { children: [/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_4__.PanelBody, {
title: "Active Services", title: "Active Services",
initialOpen: true, initialOpen: true,
children: iterator.map(item => /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_4__.PanelRow, { children: iterator.map(item => /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_4__.PanelRow, {
@ -263,7 +264,19 @@ const Edit = ({
onChange: () => excludeService(item.key) onChange: () => excludeService(item.key)
}) })
})) }))
}) }), /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_4__.PanelBody, {
title: "Link Behavior",
initialOpen: true,
children: /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_4__.PanelRow, {
children: /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_4__.ToggleControl, {
label: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)("Open links in new tab", "wpsi-menu"),
checked: openInNewTab,
onChange: value => setAttributes({
openInNewTab: value
})
})
})
})]
}), /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsxs)(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_1__.BlockControls, { }), /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsxs)(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_1__.BlockControls, {
children: [/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsxs)(_wordpress_components__WEBPACK_IMPORTED_MODULE_4__.ToolbarGroup, { children: [/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsxs)(_wordpress_components__WEBPACK_IMPORTED_MODULE_4__.ToolbarGroup, {
children: [/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_4__.ToolbarButton, { children: [/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_4__.ToolbarButton, {

File diff suppressed because one or more lines are too long

@ -2,10 +2,11 @@
use wpsocialicons\Settings; use wpsocialicons\Settings;
["exclude" => $exclude, "orientation" => $orientation, "alignment" => $alignment] = $attributes ?? []; ["exclude" => $exclude, "orientation" => $orientation, "alignment" => $alignment, "openInNewTab" => $openInNewTab] = $attributes ?? [];
$services = array_filter((array) Settings::Services(), fn ($value, $key) => !in_array($key, $exclude), ARRAY_FILTER_USE_BOTH); $services = array_filter((array) Settings::Services(), fn ($value, $key) => !in_array($key, $exclude), ARRAY_FILTER_USE_BOTH);
the_wp_social_icons([ the_wp_social_icons([
"exclude" => $exclude, "exclude" => $exclude,
"container_class" => "wp-social-icons $orientation align-$alignment", "container_class" => "wp-social-icons $orientation align-$alignment",
"openInNewTab" => $openInNewTab
]); ]);

@ -2,7 +2,7 @@
"$schema" : "https://schemas.wp.org/trunk/block.json", "$schema" : "https://schemas.wp.org/trunk/block.json",
"apiVersion" : 3, "apiVersion" : 3,
"name" : "massivedynamic/wpsi-menu", "name" : "massivedynamic/wpsi-menu",
"version" : "0.0.1", "version" : "0.1.0",
"title" : "WP Social Icons Menu", "title" : "WP Social Icons Menu",
"category" : "widgets", "category" : "widgets",
"icon" : "networking", "icon" : "networking",
@ -25,6 +25,10 @@
"exclude" : { "exclude" : {
"type" : "array", "type" : "array",
"default" : [] "default" : []
},
"openInNewTab" : {
"type" : "boolean",
"default" : false
} }
}, },
"textdomain" : "wpsi-menu", "textdomain" : "wpsi-menu",

@ -34,7 +34,7 @@ import "./editor.scss";
const Edit = ({attributes, setAttributes}) => { const Edit = ({attributes, setAttributes}) => {
const [items, setItems] = useState([]); const [items, setItems] = useState([]);
const {alignment, orientation, exclude} = attributes; const {alignment, orientation, exclude, openInNewTab} = attributes;
const iterator = useMemo(() => { const iterator = useMemo(() => {
const out = []; const out = [];
@ -68,7 +68,12 @@ const Edit = ({attributes, setAttributes}) => {
<ToggleControl label={<><span className={`wpsi-${item.key}`} style={{fontSize : "1.2rem", verticalAlign : "middle", marginRight : "0.5rem"}}></span> <span style={{verticalAlign : "middle"}}>{item.key}</span></>} checked={!exclude.includes(item.key)} onChange={() => excludeService(item.key)} /> <ToggleControl label={<><span className={`wpsi-${item.key}`} style={{fontSize : "1.2rem", verticalAlign : "middle", marginRight : "0.5rem"}}></span> <span style={{verticalAlign : "middle"}}>{item.key}</span></>} checked={!exclude.includes(item.key)} onChange={() => excludeService(item.key)} />
</PanelRow> </PanelRow>
))} ))}
</PanelBody> </PanelBody>
<PanelBody title="Link Behavior" initialOpen={true}>
<PanelRow>
<ToggleControl label={__("Open links in new tab", "wpsi-menu")} checked={openInNewTab} onChange={value => setAttributes({openInNewTab : value})} />
</PanelRow>
</PanelBody>
</InspectorControls> </InspectorControls>
<BlockControls> <BlockControls>
<ToolbarGroup> <ToolbarGroup>

@ -2,10 +2,11 @@
use wpsocialicons\Settings; use wpsocialicons\Settings;
["exclude" => $exclude, "orientation" => $orientation, "alignment" => $alignment] = $attributes ?? []; ["exclude" => $exclude, "orientation" => $orientation, "alignment" => $alignment, "openInNewTab" => $openInNewTab] = $attributes ?? [];
$services = array_filter((array) Settings::Services(), fn ($value, $key) => !in_array($key, $exclude), ARRAY_FILTER_USE_BOTH); $services = array_filter((array) Settings::Services(), fn ($value, $key) => !in_array($key, $exclude), ARRAY_FILTER_USE_BOTH);
the_wp_social_icons([ the_wp_social_icons([
"exclude" => $exclude, "exclude" => $exclude,
"container_class" => "wp-social-icons $orientation align-$alignment", "container_class" => "wp-social-icons $orientation align-$alignment",
"openInNewTab" => $openInNewTab
]); ]);

@ -15,7 +15,7 @@ export default function save({attributes}) {
}).catch(error => console.error("ERR", error)); }).catch(error => console.error("ERR", error));
}, []); }, []);
*/ */
const {orientation, alignment} = attributes; const {orientation, alignment, openInNewTab} = attributes;
const props = useBlockProps.save(); const props = useBlockProps.save();
console.log("SAVE PROPS", attributes); console.log("SAVE PROPS", attributes);

@ -10,7 +10,8 @@ class Frontend {
"after" => "", "after" => "",
"icon_before" => "", "icon_before" => "",
"icon_after" => "", "icon_after" => "",
"exclude" => [] "exclude" => [],
"openInNewTab" => false
]; ];
public function __construct(private Settings $settings) { public function __construct(private Settings $settings) {
add_action("wp_enqueue_scripts", [$this, "enqueueFont"]); add_action("wp_enqueue_scripts", [$this, "enqueueFont"]);
@ -29,7 +30,9 @@ class Frontend {
$iconBefore = $args["icon_before"]; $iconBefore = $args["icon_before"];
$iconAfter = $args["icon_after"]; $iconAfter = $args["icon_after"];
$exclude = $args["exclude"]; $exclude = $args["exclude"];
$openInNewTab = $args["openInNewTab"];
$newTab = $openInNewTab ? " target='_blank'" : "";
$out = "<$container class='$containerClass'>"; $out = "<$container class='$containerClass'>";
$services = Settings::Services(); $services = Settings::Services();
@ -38,7 +41,7 @@ class Frontend {
continue; continue;
$out .= sprintf( $out .= sprintf(
"$before<a href='%s' class='wp-social-icon-link'>$iconBefore<span class='wpsi wpsi-%s'></span>$iconAfter</a>$after\n", "$before<a href='%s' class='wp-social-icon-link'$newTab>$iconBefore<span class='wpsi wpsi-%s'></span>$iconAfter</a>$after\n",
$url, $url,
$service $service
); );

@ -7,7 +7,7 @@
* License: MIT * License: MIT
* Text Domain: wpsocialicons * Text Domain: wpsocialicons
* Domain Path: /lang * Domain Path: /lang
* Version: 0.0.1 * Version: 0.1.0
*/ */
require_once("src/Plugin.php"); require_once("src/Plugin.php");

Loading…
Cancel
Save