PluginProbe ʕ •ᴥ•ʔ
Widget Options – Advanced Conditional Visibility for Gutenberg Blocks & Classic Widgets / 4.0.5
Widget Options – Advanced Conditional Visibility for Gutenberg Blocks & Classic Widgets v4.0.5
4.2.5 4.2.4 trunk 3.7.10 3.7.11 3.7.12 3.7.13 3.7.14 3.7.2 3.7.5 3.7.6 3.7.7 3.7.8 3.7.9 3.8 3.8.1 3.8.10 3.8.2 3.8.3 3.8.4 3.8.5 3.8.6 3.8.7 3.8.8 3.8.9 3.8.9.1 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.0.5.1 4.0.6 4.0.6.1 4.0.7 4.0.8 4.0.9 4.1.0 4.1.1 4.1.2 4.1.3 4.2.0 4.2.1 4.2.2 4.2.3
widget-options / includes / widgets / gutenberg / src / index.js
widget-options / includes / widgets / gutenberg / src Last commit date
attributes 2 years ago index.js 2 years ago
index.js
125 lines
1 import "./attributes/sidebar";
2 import "./attributes/post-sidebar";
3 import "./attributes/customize-sidebar";
4
5 function addWidgetOptionAttributes(settings, name) {
6 if (settings.attributes) {
7 let isWidgetBlockEditor = document.body?.classList.contains("widgets-php");
8 let isWpCustomizer = typeof wp.customize !== "undefined";
9
10 //add here the blocks that are serversiderender
11 const originalRenderCallback = settings.edit;
12 settings.edit = function (props) {
13 // Modify or extend the props.attributes here
14 if (name == "luckywp/tableofcontents") {
15 //if block type is luckywp/tableofcontents use type string
16 if (isWidgetBlockEditor || isWpCustomizer) {
17 if (props.attributes.extended_widget_opts_block == undefined) {
18 props.attributes.extended_widget_opts_block = JSON.stringify({});
19 }
20
21 if (isWpCustomizer) {
22 if (props.attributes.extended_widget_opts == undefined) {
23 props.attributes.extended_widget_opts = JSON.stringify({});
24 }
25 }
26 } else {
27 if (props.attributes.extended_widget_opts == undefined) {
28 props.attributes.extended_widget_opts = JSON.stringify({});
29 }
30 }
31 } else {
32 //if block type is not luckywp/tableofcontents use type object
33 if (isWidgetBlockEditor || isWpCustomizer) {
34 if (props.attributes.extended_widget_opts_block == undefined) {
35 props.attributes.extended_widget_opts_block = {};
36 }
37
38 if (isWpCustomizer) {
39 if (props.attributes.extended_widget_opts == undefined) {
40 props.attributes.extended_widget_opts = {};
41 }
42 }
43 } else {
44 if (props.attributes.extended_widget_opts == undefined) {
45 props.attributes.extended_widget_opts = {};
46 }
47 }
48 }
49
50 if (props.attributes.extended_widget_opts_state == undefined) {
51 props.attributes.extended_widget_opts_state = 0;
52 }
53
54 if (props.attributes.extended_widget_opts_clientid == undefined) {
55 props.attributes.extended_widget_opts_clientid = "";
56 }
57
58 if (props.attributes.dateUpdated == undefined) {
59 props.attributes.dateUpdated = "";
60 }
61
62 try {
63 // Now, call the original render callback with the modified props
64 return originalRenderCallback(props);
65 } catch (error) {
66 return new originalRenderCallback(props);
67 }
68 };
69
70 if (name == "luckywp/tableofcontents") {
71 //if block type is luckywp/tableofcontents use type string
72 settings.attributes.extended_widget_opts_block = {
73 type: "object",
74 default: JSON.stringify({}),
75 };
76 settings.attributes.extended_widget_opts = isWidgetBlockEditor
77 ? {
78 type: "object",
79 }
80 : {
81 type: "object",
82 default: JSON.stringify({}),
83 };
84 } else {
85 //if block type is not luckywp/tableofcontents use type object
86 settings.attributes.extended_widget_opts_block = {
87 type: "object",
88 default: {},
89 };
90 settings.attributes.extended_widget_opts = isWidgetBlockEditor
91 ? {
92 type: "object",
93 }
94 : {
95 type: "object",
96 default: {},
97 };
98 }
99
100 settings.attributes.extended_widget_opts_state = {
101 type: "string",
102 default: "",
103 };
104
105 settings.attributes.extended_widget_opts_clientid = {
106 type: "string",
107 default: "",
108 };
109
110 settings.attributes.dateUpdated = {
111 type: "string",
112 default: "",
113 };
114 }
115 return settings;
116 }
117
118 wp.domReady(function () {
119 wp.hooks.addFilter(
120 "blocks.registerBlockType",
121 "extended-widget-options/sidebar-component",
122 addWidgetOptionAttributes
123 );
124 });
125