PluginProbe
Genesis Blocks / trunk
Genesis Blocks vtrunk
3.1.11 trunk 1.0.0 1.1.0 1.1.1 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 1.4.0 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 3.0.0 3.0.1 3.1.0 3.1.1 3.1.10 All 32 releases
genesis-blocks / src / utils / components / settings / renderSettingControl.js

renderSettingControl.js in Genesis Blocks trunk, at src/utils/components/settings/renderSettingControl.js

66 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 const { Component } = wp.element;
2 const { applyFilters } = wp.hooks;
3
4 import getCurrentUserData from './../data-providers/currentUserData';
5
6 /**
7 * A wrapper that contains user data for making decisions when rendering block setting controls.
8 */
9 export default class RenderSettingControl extends Component {
10 render() {
11 if ('undefined' === typeof this.props.children) {
12 return null;
13 }
14
15 /**
16 * Let the temporary hacks begin.
17 * Get the block name this setting is associated with.
18 */
19 let fallback = false;
20
21 if (
22 'undefined' === typeof this.props.children.props ||
23 'undefined' === typeof this.props.children.props.name
24 ) {
25 fallback = true;
26 }
27
28 if (
29 fallback &&
30 ('undefined' === typeof this.props.children._owner ||
31 'undefined' ===
32 typeof this.props.children._owner.memoizedProps ||
33 'undefined' ===
34 typeof this.props.children._owner.memoizedProps.name)
35 ) {
36 return this.props.children;
37 }
38
39 const blockName = fallback
40 ? this.props.children._owner.memoizedProps.name
41 : this.props.children.props.name;
42
43 /**
44 * A filter for determining whether or not a setting should be rendered.
45 *
46 * @param {boolean} Whether or not the setting control should be rendered. Default true.
47 * @param {string} The block name.
48 * @param {string} The setting control's ID.
49 * @param {Object} The current user's data.
50 */
51 if (
52 applyFilters(
53 'gb_should_render_block_setting',
54 true,
55 blockName,
56 this.props.id,
57 getCurrentUserData()
58 )
59 ) {
60 return this.props.children;
61 }
62
63 return null;
64 }
65 }
66