PluginProbe
Friends / 2.8.1
Friends v2.8.1
4.3.2 4.3.1 4.3.0 4.2.2 4.2.1 4.2.0 4.1.0 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.8.0 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9.0 2.9.1 All 88 releases
friends / blocks / block-visibility / src / index.js

index.js in Friends 2.8.1, at blocks/block-visibility/src/index.js

53 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { __ } from '@wordpress/i18n';
2 import { addFilter } from '@wordpress/hooks';
3 import { createHigherOrderComponent } from '@wordpress/compose';
4 import { InspectorControls } from '@wordpress/block-editor';
5 import { PanelBody, SelectControl } from '@wordpress/components';
6
7 const friendsBlockVisibility = createHigherOrderComponent( ( BlockEdit ) => {
8 return ( props ) => {
9 const { attributes, setAttributes } = props;
10 let friendsVisibility = '';
11 if ( typeof attributes.className !== 'undefined' ) {
12 if ( /\bonly-friends\b/.test( attributes.className ) ) {
13 friendsVisibility = 'only-friends';
14 } else if ( /\bnot-friends\b/.test( attributes.className ) ) {
15 friendsVisibility = 'not-friends';
16 }
17 }
18 return (
19 <>
20 <BlockEdit { ...props } />
21 <InspectorControls>
22 <PanelBody className="friends-block-visibility" title={ __( 'Friends Visibility', 'friends' ) }>
23 <SelectControl
24 label={ __( 'Block visibility', 'friends' ) }
25 onChange={ friendsVisibility => {
26 const className = ((attributes.className || '').replace( /\b(only|not)-friends\b/g, '' ) + ' ' + friendsVisibility).replace(/^\s+|\s+$/, '' );
27 setAttributes( { className } ) }
28 }
29 value={ friendsVisibility }
30 options={ [
31 {
32 label: __( 'For everyone', 'friends' ),
33 value: '',
34 },
35 {
36 label: __( 'Only friends', 'friends' ),
37 value: 'only-friends',
38 },
39 {
40 label: __( 'Everyone except friends', 'friends' ),
41 value: 'not-friends',
42 },
43 ] }
44 />
45 </PanelBody>
46 </InspectorControls>
47 </>
48 );
49 };
50 }, 'withFriendsBlockVisibility' );
51
52 addFilter( 'editor.BlockEdit', 'friends/block-visibility', friendsBlockVisibility );
53