1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
|
<?php namespace Elementor;
use Elementor\Core\Base\Base_Object; use Elementor\Core\DynamicTags\Manager; use Elementor\Core\Breakpoints\Manager as Breakpoints_Manager; use Elementor\Core\Frontend\Performance;
if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. }
/** * Elementor controls stack. * * An abstract class that provides the needed properties and methods to * manage and handle controls in the editor panel to inheriting classes. * * @since 1.4.0 * @abstract */ abstract class Controls_Stack extends Base_Object {
/** * Responsive 'desktop' device name. * * @deprecated 3.4.0 */ const RESPONSIVE_DESKTOP = 'desktop';
/** * Responsive 'tablet' device name. * * @deprecated 3.4.0 */ const RESPONSIVE_TABLET = 'tablet';
/** * Responsive 'mobile' device name. * * @deprecated 3.4.0 */ const RESPONSIVE_MOBILE = 'mobile';
/** * Generic ID. * * Holds the unique ID. * * @access private * * @var string */ private $id;
private $active_settings;
private $parsed_active_settings;
/** * Parsed Dynamic Settings. * * @access private * * @var null|array */ private $parsed_dynamic_settings;
/** * Raw Data. * * Holds all the raw data including the element type, the child elements, * the user data. * * @access private * * @var null|array */ private $data;
/** * The configuration. * * Holds the configuration used to generate the Elementor editor. It includes * the element name, icon, categories, etc. * * @access private * * @var null|array */ private $config;
/** * The additional configuration. * * Holds additional configuration that has been set using `set_config` method. * The `config` property is not modified directly while using the method because * it's used to check whether the initial config already loaded (in `get_config`). * After the initial config loaded, the additional config is merged into it. * * @access private * * @var null|array */ private $additional_config = [];
/** * Current section. * * Holds the current section while inserting a set of controls sections. * * @access private * * @var null|array */ private $current_section;
/** * Current tab. * * Holds the current tab while inserting a set of controls tabs. * * @access private * * @var null|array */ private $current_tab;
/** * Current popover. * * Holds the current popover while inserting a set of controls. * * @access private * * @var null|array */ private $current_popover;
/** * Injection point. * * Holds the injection point in the stack where the control will be inserted. * * @access private * * @var null|array */ private $injection_point;
/** * Data sanitized. * * @access private * * @var bool */ private $settings_sanitized = false;
/** * Element render attributes. * * Holds all the render attributes of the element. Used to store data like * the HTML class name and the class value, or HTML element ID name and value. * * @access private * * @var array */ private $render_attributes = [];
/** * Get element name. * * Retrieve the element name. * * @since 1.4.0 * @access public * @abstract * * @return string The name. */ abstract public function get_name();
/** * Get unique name. * * Some classes need to use unique names, this method allows you to create * them. By default it retrieves the regular name. * * @since 1.6.0 * @access public * * @return string Unique name. */ public function get_unique_name() { return $this->get_name(); }
/** * Get element ID. * * Retrieve the element generic ID. * * @since 1.4.0 * @access public * * @return string The ID. */ public function get_id() { return $this->id; }
/** * Get element ID. * * Retrieve the element generic ID as integer. * * @since 1.8.0 * @access public * * @return string The converted ID. */ public function get_id_int() { /** We ignore possible notices, in order to support elements created prior to v1.8.0 and might include * non-base 16 characters as part of their ID. */ return @hexdec( $this->id ); }
/** * Get widget number. * * Get the first three numbers of the element converted ID. * * @since 3.16 * @access public * * @return string The widget number. */ public function get_widget_number(): string { return substr( $this->get_id_int(), 0, 3 ); }
/** * Get the type. * * Retrieve the type, e.g. 'stack', 'section', 'widget' etc. * * @since 1.4.0 * @access public * @static * * @return string The type. */ public static function get_type() { return 'stack'; }
/** * @since 2.9.0 * @access public * * @return bool */ public function is_editable() { return true; }
/** * Get current section. * * When inserting new controls, this method will retrieve the current section. * * @since 1.7.1 * @access public * * @return null|array Current section. */ public function get_current_section() { return $this->current_section; }
/** * Get current tab. * * When inserting new controls, this method will retrieve the current tab. * * @since 1.7.1 * @access public * * @return null|array Current tab. */ public function get_current_tab() { return $this->current_tab; }
/** * Get controls. * * Retrieve all the controls or, when requested, a specific control. * * @since 1.4.0 * @access public * * @param string $control_id The ID of the requested control. Optional field, * when set it will return a specific control. * Default is null. * * @return mixed Controls list. */ public function get_controls( $control_id = null ) { $stack = $this->get_stack();
if ( null !== $control_id ) { $control_data = self::get_items( $stack['controls'], $control_id ); if ( null === $control_data && ! empty( $stack['style_controls'] ) ) { $control_data = self::get_items( $stack['style_controls'], $control_id ); }
return $control_data; }
$controls = $stack['controls'];
if ( Performance::is_use_style_controls() && ! empty( $stack['style_controls'] ) ) { $controls += $stack['style_controls']; }
return self::get_items( $controls, $control_id ); }
/** * Get active controls. * * Retrieve an array of active controls that meet the condition field. * * If specific controls was given as a parameter, retrieve active controls * from that list, otherwise check for all the controls available. * * @since 1.4.0 * @since 2.0.9 Added the `controls` and the `settings` parameters. * @access public * @deprecated 3.0.0 * * @param array $controls Optional. An array of controls. Default is null. * @param array $settings Optional. Controls settings. Default is null. * * @return array Active controls. */ public function get_active_controls( array $controls = null, array $settings = null ) { Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.0.0' );
if ( ! $controls ) { $controls = $this->get_controls(); }
if ( ! $settings ) { $settings = $this->get_controls_settings(); }
$active_controls = array_reduce( array_keys( $controls ), function( $active_controls, $control_key ) use ( $controls, $settings ) { $control = $controls[ $control_key ];
if ( $this->is_control_visible( $control, $settings, $controls ) ) { $active_controls[ $control_key ] = $control; }
return $active_controls; }, [] );
return $active_controls; }
/** * Get controls settings. * * Retrieve the settings for all the controls that represent them. * * @since 1.5.0 * @access public * * @return array Controls settings. */ public function get_controls_settings() { return array_intersect_key( $this->get_settings(), $this->get_controls() ); }
/** * Add new control to stack. * * Register a single control to allow the user to set/update data. * * This method should be used inside `register_controls()`. * * @since 1.4.0 * @access public * * @param string $id Control ID. * @param array $args Control arguments. * @param array $options Optional. Control options. Default is an empty array. * * @return bool True if control added, False otherwise. */ public function add_control( $id, array $args, $options = [] ) { $default_options = [ 'overwrite' => false, 'position' => null, ];
if ( isset( $args['scheme'] ) ) { $args['global'] = [ 'default' => Plugin::$instance->kits_manager->convert_scheme_to_global( $args['scheme'] ), ];
unset( $args['scheme'] ); }
$options = array_merge( $default_options, $options );
if ( $options['position'] ) { $this->start_injection( $options['position'] ); }
if ( $this->injection_point ) { $options['index'] = $this->injection_point['index']++; }
if ( empty( $args['type'] ) || ! in_array( $args['type'], [ Controls_Manager::SECTION, Controls_Manager::WP_WIDGET ], true ) ) { $args = $this->handle_control_position( $args, $id, $options['overwrite'] ); }
if ( $options['position'] ) { $this->end_injection(); }
unset( $options['position'] );
if ( $this->current_popover ) { $args['popover'] = [];
if ( ! $this->current_popover['initialized'] ) { $args['popover']['start'] = true;
$this->current_popover['initialized'] = true; } }
if ( Performance::should_optimize_controls() ) { $ui_controls = [ Controls_Manager::RAW_HTML, Controls_Manager::DIVIDER, Controls_Manager::HEADING, Controls_Manager::BUTTON, Controls_Manager::ALERT, Controls_Manager::NOTICE, Controls_Manager::DEPRECATED_NOTICE, ];
if ( ! empty( $args['type'] ) && ! empty( $args['section'] ) && in_array( $args['type'], $ui_controls ) ) { $args = [ 'type' => $args['type'], 'section' => $args['section'], ]; }
unset( $args['label_block'], $args['label'], $args['title'], $args['tab'], $args['options'], $args['placeholder'], $args['separator'], $args['size_units'], $args['range'], $args['toggle'], $args['ai'], $args['classes'], $args['style_transfer'], $args['show_label'], $args['description'], $args['label_on'], $args['label_off'], $args['labels'], $args['handles'], $args['editor_available'], ); }
return Plugin::$instance->controls_manager->add_control_to_stack( $this, $id, $args, $options ); }
/** * Remove control from stack. * * Unregister an existing control and remove it from the stack. * * @since 1.4.0 * @access public * * @param string $control_id Control ID. * * @return bool|\WP_Error */ public function remove_control( $control_id ) { return Plugin::$instance->controls_manager->remove_control_from_stack( $this->get_unique_name(), $control_id ); }
/** * Update control in stack. * * Change the value of an existing control in the stack. When you add new * control you set the `$args` parameter, this method allows you to update * the arguments by passing new data. * * @since 1.4.0 * @since 1.8.1 New `$options` parameter added. * * @access public * * @param string $control_id Control ID. * @param array $args Control arguments. Only the new fields you want * to update. * @param array $options Optional. Some additional options. Default is * an empty array. * * @return bool */ public function update_control( $control_id, array $args, array $options = [] ) { $is_updated = Plugin::$instance->controls_manager->update_control_in_stack( $this, $control_id, $args, $options );
if ( ! $is_updated ) { return false; }
$control = $this->get_controls( $control_id );
if ( Controls_Manager::SECTION === $control['type'] ) { $section_args = $this->get_section_args( $control_id );
$section_controls = $this->get_section_controls( $control_id );
foreach ( $section_controls as $section_control_id => $section_control ) { $this->update_control( $section_control_id, $section_args, $options ); } }
return true; }
/** * Get stack. * * Retrieve the stack of controls. * * @since 1.9.2 * @access public * * @return array Stack of controls. */ public function get_stack() { $stack = Plugin::$instance->controls_manager->get_element_stack( $this );
if ( null === $stack ) { $this->init_controls();
return Plugin::$instance->controls_manager->get_element_stack( $this ); }
return $stack; }
/** * Get position information. * * Retrieve the position while injecting data, based on the element type. * * @since 1.7.0 * @access public * * @param array $position { * The injection position. * * @type string $type Injection type, either `control` or `section`. * Default is `control`. * @type string $at Where to inject. If `$type` is `control` accepts * `before` and `after`. If `$type` is `section` * accepts `start` and `end`. Default values based on * the `type`. * @type string $of Control/Section ID. * @type array $fallback Fallback injection position. When the position is * not found it will try to fetch the fallback * position. * } * * @return bool|array Position info. */ final public function get_position_info( array $position ) { $default_position = [ 'type' => 'control', 'at' => 'after', ];
if ( ! empty( $position['type'] ) && 'section' === $position['type'] ) { $default_position['at'] = 'end'; }
$position = array_merge( $default_position, $position );
if ( 'control' === $position['type'] && in_array( $position['at'], [ 'start', 'end' ], true ) || 'section' === $position['type'] && in_array( $position['at'], [ 'before', 'after' ], true ) ) { _doing_it_wrong( sprintf( '%s::%s', get_called_class(), __FUNCTION__ ), 'Invalid position arguments. Use `before` / `after` for control or `start` / `end` for section.', '1.7.0' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
return false; }
$target_control_index = $this->get_control_index( $position['of'] );
if ( false === $target_control_index ) { if ( ! empty( $position['fallback'] ) ) { return $this->get_position_info( $position['fallback'] ); }
return false; }
$target_section_index = $target_control_index;
$registered_controls = $this->get_controls();
$controls_keys = array_keys( $registered_controls );
while ( Controls_Manager::SECTION !== $registered_controls[ $controls_keys[ $target_section_index ] ]['type'] ) { $target_section_index--; }
if ( 'section' === $position['type'] ) { $target_control_index++;
if ( 'end' === $position['at'] ) { while ( Controls_Manager::SECTION !== $registered_controls[ $controls_keys[ $target_control_index ] ]['type'] ) { if ( ++$target_control_index >= count( $registered_controls ) ) { break; } } } }
$target_control = $registered_controls[ $controls_keys[ $target_control_index ] ];
if ( 'after' === $position['at'] ) { $target_control_index++; }
$section_id = $registered_controls[ $controls_keys[ $target_section_index ] ]['name'];
$position_info = [ 'index' => $target_control_index, 'section' => $this->get_section_args( $section_id ), ];
if ( ! empty( $target_control['tabs_wrapper'] ) ) { $position_info['tab'] = [ 'tabs_wrapper' => $target_control['tabs_wrapper'], 'inner_tab' => $target_control['inner_tab'], ]; }
return $position_info; }
/** * Get control key. * * Retrieve the key of the control based on a given index of the control. * * @since 1.9.2 * @access public * * @param string $control_index Control index. * * @return int Control key. */ final public function get_control_key( $control_index ) { $registered_controls = $this->get_controls();
$controls_keys = array_keys( $registered_controls );
return $controls_keys[ $control_index ]; }
/** * Get control index. * * Retrieve the index of the control based on a given key of the control. * * @since 1.7.6 * @access public * * @param string $control_key Control key. * * @return false|int Control index. */ final public function get_control_index( $control_key ) { $controls = $this->get_controls();
$controls_keys = array_keys( $controls );
return array_search( $control_key, $controls_keys ); }
/** * Get section controls. * * Retrieve all controls under a specific section. * * @since 1.7.6 * @access public * * @param string $section_id Section ID. * * @return array Section controls */ final public function get_section_controls( $section_id ) { $section_index = $this->get_control_index( $section_id );
$section_controls = [];
$registered_controls = $this->get_controls();
$controls_keys = array_keys( $registered_controls );
while ( true ) { $section_index++;
if ( ! isset( $controls_keys[ $section_index ] ) ) { break; }
$control_key = $controls_keys[ $section_index ];
if ( Controls_Manager::SECTION === $registered_controls[ $control_key ]['type'] ) { break; }
$section_controls[ $control_key ] = $registered_controls[ $control_key ]; };
return $section_controls; }
/** * Add new group control to stack. * * Register a set of related controls grouped together as a single unified * control. For example grouping together like typography controls into a * single, easy-to-use control. * * @since 1.4.0 * @access public * * @param string $group_name Group control name. * @param array $args Group control arguments. Default is an empty array. * @param array $options Optional. Group control options. Default is an * empty array. */ final public function add_group_control( $group_name, array $args = [], array $options = [] ) { $group = Plugin::$instance->controls_manager->get_control_groups( $group_name );
if ( ! $group ) { wp_die( sprintf( '%s::%s: Group "%s" not found.', get_called_class(), __FUNCTION__, $group_name ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped }
$group->add_controls( $this, $args, $options ); }
/** * Get style controls. * * Retrieve style controls for all active controls or, when requested, from * a specific set of controls. * * @since 1.4.0 * @since 2.0.9 Added the `settings` parameter. * @access public * @deprecated 3.0.0 * * @param array $controls Optional. Controls list. Default is null. * @param array $settings Optional. Controls settings. Default is null. * * @return array Style controls. */ final public function get_style_controls( array $controls = null, array $settings = null ) { Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.0.0' );
$controls = $this->get_active_controls( $controls, $settings );
$style_controls = [];
foreach ( $controls as $control_name => $control ) { $control_obj = Plugin::$instance->controls_manager->get_control( $control['type'] );
if ( ! $control_obj instanceof Base_Data_Control ) { continue; }
$control = array_merge( $control_obj->get_settings(), $control );
if ( $control_obj instanceof Control_Repeater ) { $style_fields = [];
foreach ( $this->get_settings( $control_name ) as $item ) { $style_fields[] = $this->get_style_controls( $control['fields'], $item ); }
$control['style_fields'] = $style_fields; }
if ( ! empty( $control['selectors'] ) || ! empty( $control['dynamic'] ) || ! empty( $control['style_fields'] ) ) { $style_controls[ $control_name ] = $control; } }
return $style_controls; }
/** * Get tabs controls. * * Retrieve all the tabs assigned to the control. * * @since 1.4.0 * @access public * * @return array Tabs controls. */ final public function get_tabs_controls() { return $this->get_stack()['tabs']; }
/** * Add new responsive control to stack. * * Register a set of controls to allow editing based on user screen size. * This method registers one or more controls per screen size/device, depending on the current Responsive Control * Duplication Mode. There are 3 control duplication modes: * * 'off' - Only a single control is generated. In the Editor, this control is duplicated in JS. * * 'on' - Multiple controls are generated, one control per enabled device/breakpoint + a default/desktop control. * * 'dynamic' - If the control includes the `'dynamic' => 'active' => true` property - the control is duplicated, * once for each device/breakpoint + default/desktop. * If the control doesn't include the `'dynamic' => 'active' => true` property - the control is not duplicated. * * @since 1.4.0 * @access public * * @param string $id Responsive control ID. * @param array $args Responsive control arguments. * @param array $options Optional. Responsive control options. Default is * an empty array. */ final public function add_responsive_control( $id, array $args, $options = [] ) { $args['responsive'] = [];
$active_breakpoints = Plugin::$instance->breakpoints->get_active_breakpoints();
$devices = Plugin::$instance->breakpoints->get_active_devices_list( [ 'reverse' => true, 'desktop_first' => true, ] );
if ( isset( $args['devices'] ) ) { $devices = array_intersect( $devices, $args['devices'] );
$args['responsive']['devices'] = $devices;
unset( $args['devices'] ); }
$control_to_check = $args;
if ( ! empty( $options['overwrite'] ) ) { $existing_control = Plugin::$instance->controls_manager->get_control_from_stack( $this->get_unique_name(), $id );
if ( ! is_wp_error( $existing_control ) ) { $control_to_check = $existing_control; } }
$responsive_duplication_mode = Plugin::$instance->breakpoints->get_responsive_control_duplication_mode(); $additional_breakpoints_active = Plugin::$instance->experiments->is_feature_active( 'additional_custom_breakpoints' ); $control_is_dynamic = ! empty( $control_to_check['dynamic']['active'] ); $is_frontend_available = ! empty( $control_to_check['frontend_available'] ); $has_prefix_class = ! empty( $control_to_check['prefix_class'] );
// If the new responsive controls experiment is active, create only one control - duplicates per device will // be created in JS in the Editor. if ( $additional_breakpoints_active && ( 'off' === $responsive_duplication_mode || ( 'dynamic' === $responsive_duplication_mode && ! $control_is_dynamic ) ) // Some responsive controls need responsive settings to be available to the widget handler, even when empty. && ! $is_frontend_available && ! $has_prefix_class ) { $args['is_responsive'] = true;
if ( ! empty( $options['overwrite'] ) ) { $this->update_control( $id, $args, [ 'recursive' => ! empty( $options['recursive'] ), ] ); } else { $this->add_control( $id, $args, $options ); }
return; }
if ( isset( $args['default'] ) ) { $args['desktop_default'] = $args['default'];
unset( $args['default'] ); }
foreach ( $devices as $device_name ) { $control_args = $args;
// Set parent using the name from previous iteration. if ( isset( $control_name ) ) { // If $control_name end with _widescreen use desktop name instead $control_args['parent'] = '_widescreen' === substr( $control_name, -strlen( '_widescreen' ) ) ? $id : $control_name; } else { $control_args['parent'] = null; }
if ( isset( $control_args['device_args'] ) ) { if ( ! empty( $control_args['device_args'][ $device_name ] ) ) { $control_args = array_merge( $control_args, $control_args['device_args'][ $device_name ] ); }
unset( $control_args['device_args'] ); }
if ( ! empty( $args['prefix_class'] ) ) { $device_to_replace = Breakpoints_Manager::BREAKPOINT_KEY_DESKTOP === $device_name ? '' : '-' . $device_name;
$control_args['prefix_class'] = sprintf( $args['prefix_class'], $device_to_replace ); }
$direction = 'max';
if ( Breakpoints_Manager::BREAKPOINT_KEY_DESKTOP !== $device_name ) { $direction = $active_breakpoints[ $device_name ]->get_direction(); }
$control_args['responsive'][ $direction ] = $device_name;
if ( isset( $control_args['min_affected_device'] ) ) { if ( ! empty( $control_args['min_affected_device'][ $device_name ] ) ) { $control_args['responsive']['min'] = $control_args['min_affected_device'][ $device_name ]; }
unset( $control_args['min_affected_device'] ); }
if ( isset( $control_args[ $device_name . '_default' ] ) ) { $control_args['default'] = $control_args[ $device_name . '_default' ]; }
foreach ( $devices as $device ) { unset( $control_args[ $device . '_default' ] ); }
$id_suffix = Breakpoints_Manager::BREAKPOINT_KEY_DESKTOP === $device_name ? '' : '_' . $device_name; $control_name = $id . $id_suffix;
// Set this control as child of previous iteration control. if ( ! empty( $control_args['parent'] ) ) { $this->update_control( $control_args['parent'], [ 'inheritors' => [ $control_name ] ] ); }
if ( ! empty( $options['overwrite'] ) ) { $this->update_control( $control_name, $control_args, [ 'recursive' => ! empty( $options['recursive'] ), ] ); } else { $this->add_control( $control_name, $control_args, $options ); } } }
/** * Update responsive control in stack. * * Change the value of an existing responsive control in the stack. When you * add new control you set the `$args` parameter, this method allows you to * update the arguments by passing new data. * * @since 1.4.0 * @access public * * @param string $id Responsive control ID. * @param array $args Responsive control arguments. * @param array $options Optional. Additional options. */ final public function update_responsive_control( $id, array $args, array $options = [] ) { $this->add_responsive_control( $id, $args, [ 'overwrite' => true, 'recursive' => ! empty( $options['recursive'] ), ] ); }
/** * Remove responsive control from stack. * * Unregister an existing responsive control and remove it from the stack. * * @since 1.4.0 * @access public * * @param string $id Responsive control ID. */ final public function remove_responsive_control( $id ) { $devices = Plugin::$instance->breakpoints->get_active_devices_list( [ 'reverse' => true ] );
foreach ( $devices as $device_name ) { $id_suffix = Breakpoints_Manager::BREAKPOINT_KEY_DESKTOP === $device_name ? '' : '_' . $device_name;
$this->remove_control( $id . $id_suffix ); } }
/** * Get class name. * * Retrieve the name of the current class. * * @since 1.4.0 * @access public * * @return string Class name. */ final public function get_class_name() { return get_called_class(); }
/** * Get the config. * * Retrieve the config or, if non set, use the initial config. * * @since 1.4.0 * @access public * * @return array|null The config. */ final public function get_config() { if ( null === $this->config ) { // TODO: This is for backwards compatibility starting from 2.9.0 // This if statement should be removed when the method is hard-deprecated if ( $this->has_own_method( '_get_initial_config', self::class ) ) { Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( '_get_initial_config', '2.9.0', __CLASS__ . '::get_initial_config()' );
$this->config = $this->_get_initial_config(); } else { $this->config = $this->get_initial_config(); }
foreach ( $this->additional_config as $key => $value ) { if ( isset( $this->config[ $key ] ) ) { $this->config[ $key ] = wp_parse_args( $value, $this->config[ $key ] ); } else { $this->config[ $key ] = $value; } } }
return $this->config; }
/** * Set a config property. * * Set a specific property of the config list for this controls-stack. * * @since 3.5.0 * @access public */ public function set_config( $key, $value ) { if ( isset( $this->additional_config[ $key ] ) ) { $this->additional_config[ $key ] = wp_parse_args( $value, $this->additional_config[ $key ] ); } else { $this->additional_config[ $key ] = $value; } }
/** * Get frontend settings keys. * * Retrieve settings keys for all frontend controls. * * @since 1.6.0 * @access public * * @return array Settings keys for each control. */ final public function get_frontend_settings_keys() { $controls = [];
foreach ( $this->get_controls() as $control ) { if ( ! empty( $control['frontend_available'] ) ) { $controls[] = $control['name']; } }
return $controls; }
/** * Get controls pointer index. * * Retrieve pointer index where the next control should be added. * * While using injection point, it will return the injection point index. * Otherwise index of the last control plus one. * * @since 1.9.2 * @access public * * @return int Controls pointer index. */ public function get_pointer_index() { if ( null !== $this->injection_point ) { return $this->injection_point['index']; }
return count( $this->get_controls() ); }
/** * Get the raw data. * * Retrieve all the items or, when requested, a specific item. * * @since 1.4.0 * @access public * * @param string $item Optional. The requested item. Default is null. * * @return mixed The raw data. */ public function get_data( $item = null ) { if ( ! $this->settings_sanitized && ( ! $item || 'settings' === $item ) ) { $this->data['settings'] = $this->sanitize_settings( $this->data['settings'] );
$this->settings_sanitized = true; }
return self::get_items( $this->data, $item ); }
/** * @since 2.0.14 * @access public */ public function get_parsed_dynamic_settings( $setting = null, $settings = null ) { if ( null === $settings ) { $settings = $this->get_settings(); }
if ( null === $this->parsed_dynamic_settings ) { $this->parsed_dynamic_settings = $this->parse_dynamic_settings( $settings ); }
return self::get_items( $this->parsed_dynamic_settings, $setting ); }
/** * Get active settings. * * Retrieve the settings from all the active controls. * * @since 1.4.0 * @since 2.1.0 Added the `controls` and the `settings` parameters. * @access public * * @param array $controls Optional. An array of controls. Default is null. * @param array $settings Optional. Controls settings. Default is null. * * @return array Active settings. */ public function get_active_settings( $settings = null, $controls = null ) { $is_first_request = ! $settings && ! $this->active_settings;
if ( ! $settings ) { if ( $this->active_settings ) { return $this->active_settings; }
$settings = $this->get_controls_settings();
$controls = $this->get_controls(); }
$active_settings = [];
$controls_objs = Plugin::$instance->controls_manager->get_controls();
foreach ( $settings as $setting_key => $setting ) { if ( ! isset( $controls[ $setting_key ] ) ) { $active_settings[ $setting_key ] = $setting;
continue; }
$control = $controls[ $setting_key ];
if ( $this->is_control_visible( $control, $settings, $controls ) ) { $control_obj = $controls_objs[ $control['type'] ] ?? null;
if ( $control_obj instanceof Control_Repeater ) { foreach ( $setting as & $item ) { $item = $this->get_active_settings( $item, $control['fields'] ); } }
$active_settings[ $setting_key ] = $setting; } else { $active_settings[ $setting_key ] = null; } }
if ( $is_first_request ) { $this->active_settings = $active_settings; }
return $active_settings; }
/** * Get settings for display. * * Retrieve all the settings or, when requested, a specific setting for display. * * Unlike `get_settings()` method, this method retrieves only active settings * that passed all the conditions, rendered all the shortcodes and all the dynamic * tags. * * @since 2.0.0 * @access public * * @param string $setting_key Optional. The key of the requested setting. * Default is null. * * @return mixed The settings. */ public function get_settings_for_display( $setting_key = null ) { if ( ! $this->parsed_active_settings ) { $this->parsed_active_settings = $this->get_active_settings( $this->get_parsed_dynamic_settings(), $this->get_controls() ); }
return self::get_items( $this->parsed_active_settings, $setting_key ); }
/** * Parse dynamic settings. * * Retrieve the settings with rendered dynamic tags. * * @since 2.0.0 * @access public * * @param array $settings Optional. The requested setting. Default is null. * @param array $controls Optional. The controls array. Default is null. * @param array $all_settings Optional. All the settings. Default is null. * * @return array The settings with rendered dynamic tags. */ public function parse_dynamic_settings( $settings, $controls = null, $all_settings = null ) { if ( null === $all_settings ) { $all_settings = $this->get_settings(); }
if ( null === $controls ) { $controls = $this->get_controls(); }
$controls_objs = Plugin::$instance->controls_manager->get_controls();
foreach ( $controls as $control ) { $control_name = $control['name']; $control_obj = $controls_objs[ $control['type'] ] ?? null;
if ( ! $control_obj instanceof Base_Data_Control ) { continue; }
if ( $control_obj instanceof Control_Repeater ) { if ( ! isset( $settings[ $control_name ] ) ) { continue; }
foreach ( $settings[ $control_name ] as & $field ) { $field = $this->parse_dynamic_settings( $field, $control['fields'], $field ); }
continue; }
$dynamic_settings = $control_obj->get_settings( 'dynamic' );
if ( ! $dynamic_settings ) { $dynamic_settings = []; }
if ( ! empty( $control['dynamic'] ) ) { $dynamic_settings = array_merge( $dynamic_settings, $control['dynamic'] ); }
if ( empty( $dynamic_settings ) || ! isset( $all_settings[ Manager::DYNAMIC_SETTING_KEY ][ $control_name ] ) ) { continue; }
if ( ! empty( $dynamic_settings['active'] ) && ! empty( $all_settings[ Manager::DYNAMIC_SETTING_KEY ][ $control_name ] ) ) { $parsed_value = $control_obj->parse_tags( $all_settings[ Manager::DYNAMIC_SETTING_KEY ][ $control_name ], $dynamic_settings );
$dynamic_property = ! empty( $dynamic_settings['property'] ) ? $dynamic_settings['property'] : null;
if ( $dynamic_property ) { $settings[ $control_name ][ $dynamic_property ] = $parsed_value; } else { $settings[ $control_name ] = $parsed_value; } } }
return $settings; }
/** * Get frontend settings. * * Retrieve the settings for all frontend controls. * * @since 1.6.0 * @access public * * @return array Frontend settings. */ public function get_frontend_settings() { $frontend_settings = array_intersect_key( $this->get_settings_for_display(), array_flip( $this->get_frontend_settings_keys() ) );
foreach ( $frontend_settings as $key => $setting ) { if ( in_array( $setting, [ null, '' ], true ) ) { unset( $frontend_settings[ $key ] ); } }
return $frontend_settings; }
/** * Filter controls settings. * * Receives controls, settings and a callback function to filter the settings by * and returns filtered settings. * * @since 1.5.0 * @access public * * @param callable $callback The callback function. * @param array $settings Optional. Control settings. Default is an empty * array. * @param array $controls Optional. Controls list. Default is an empty * array. * * @return array Filtered settings. */ public function filter_controls_settings( callable $callback, array $settings = [], array $controls = [] ) { if ( ! $settings ) { $settings = $this->get_settings(); }
if ( ! $controls ) { $controls = $this->get_controls(); }
return array_reduce( array_keys( $settings ), function( $filtered_settings, $setting_key ) use ( $controls, $settings, $callback ) { if ( isset( $controls[ $setting_key ] ) ) { $result = $callback( $settings[ $setting_key ], $controls[ $setting_key ] );
if ( null !== $result ) { $filtered_settings[ $setting_key ] = $result; } }
return $filtered_settings; }, [] ); }
/** * Get Responsive Control Device Suffix * * @deprecated 3.7.6 Use `Elementor\Controls_Manager::get_responsive_control_device_suffix()` instead. * @param array $control * @return string $device suffix */ protected function get_responsive_control_device_suffix( $control ) { Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.7.6', 'Elementor\Controls_Manager::get_responsive_control_device_suffix()' );
return Controls_Manager::get_responsive_control_device_suffix( $control ); }
/** * Whether the control is visible or not. * * Used to determine whether the control is visible or not. * * @since 1.4.0 * @access public * * @param array $control The control. * @param array $values Optional. Condition values. Default is null. * * @return bool Whether the control is visible. */ public function is_control_visible( $control, $values = null, $controls = null ) { if ( null === $values ) { $values = $this->get_settings(); }
if ( ! empty( $control['conditions'] ) && ! Conditions::check( $control['conditions'], $values ) ) { return false; }
if ( empty( $control['condition'] ) ) { return true; }
if ( ! $controls ) { $controls = $this->get_controls(); }
foreach ( $control['condition'] as $condition_key => $condition_value ) { preg_match( '/([a-z_\-0-9]+)(?:\[([a-z_]+)])?(!?)$/i', $condition_key, $condition_key_parts );
$pure_condition_key = $condition_key_parts[1]; $condition_sub_key = $condition_key_parts[2]; $is_negative_condition = ! ! $condition_key_parts[3];
if ( ! isset( $values[ $pure_condition_key ] ) || null === $values[ $pure_condition_key ] ) { return false; }
$are_control_and_condition_responsive = isset( $control['responsive'] ) && ! empty( $controls[ $pure_condition_key ]['responsive'] ); $condition_name_to_check = $pure_condition_key;
if ( $are_control_and_condition_responsive ) { $device_suffix = Controls_Manager::get_responsive_control_device_suffix( $control );
$condition_name_to_check = $pure_condition_key . $device_suffix;
// If the control is not desktop, and a conditioning control for the corresponding device exists, use it. $instance_value = $values[ $pure_condition_key . $device_suffix ] ?? $values[ $pure_condition_key ]; } else { $instance_value = $values[ $pure_condition_key ]; }
if ( $condition_sub_key && is_array( $instance_value ) ) { if ( ! isset( $instance_value[ $condition_sub_key ] ) ) { return false; }
$instance_value = $instance_value[ $condition_sub_key ]; }
if ( ! $instance_value ) { $parent = isset( $controls[ $condition_name_to_check ]['parent'] ) ? $controls[ $condition_name_to_check ]['parent'] : false;
while ( $parent ) { $instance_value = $values[ $parent ];
if ( $instance_value ) { if ( ! is_array( $instance_value ) ) { break; }
if ( $condition_sub_key && isset( $instance_value[ $condition_sub_key ] ) ) { $instance_value = $instance_value[ $condition_sub_key ];
if ( '' !== $instance_value ) { break; } } }
$parent = isset( $controls[ $parent ]['parent'] ) ? $controls[ $parent ]['parent'] : false; } }
/** * If the $condition_value is a non empty array - check if the $condition_value contains the $instance_value, * If the $instance_value is a non empty array - check if the $instance_value contains the $condition_value * otherwise check if they are equal. ( and give the ability to check if the value is an empty array ) */ if ( is_array( $condition_value ) && ! empty( $condition_value ) ) { $is_contains = in_array( $instance_value, $condition_value, true ); } elseif ( is_array( $instance_value ) && ! empty( $instance_value ) ) { $is_contains = in_array( $condition_value, $instance_value, true ); } else { $is_contains = $instance_value === $condition_value; }
if ( $is_negative_condition && $is_contains || ! $is_negative_condition && ! $is_contains ) { return false; } }
return true; }
/** * Start controls section. * * Used to add a new section of controls. When you use this method, all the * registered controls from this point will be assigned to this section, * until you close the section using `end_controls_section()` method. * * This method should be used inside `register_controls()`. * * @since 1.4.0 * @access public * * @param string $section_id Section ID. * @param array $args Section arguments Optional. */ public function start_controls_section( $section_id, array $args = [] ) { $stack_name = $this->get_name();
/** * Before section start. * * Fires before Elementor section starts in the editor panel. * * @since 1.4.0 * * @param Controls_Stack $this The control. * @param string $section_id Section ID. * @param array $args Section arguments. */ do_action( 'elementor/element/before_section_start', $this, $section_id, $args );
/** * Before section start. * * Fires before Elementor section starts in the editor panel. * * The dynamic portions of the hook name, `$stack_name` and `$section_id`, refers to the stack name and section ID, respectively. * * @since 1.4.0 * * @param Controls_Stack $this The control. * @param array $args Section arguments. */ do_action( "elementor/element/{$stack_name}/{$section_id}/before_section_start", $this, $args );
if ( $this->should_manually_trigger_common_action( $stack_name ) ) { do_action( "elementor/element/common/{$section_id}/before_section_start", $this, $args ); }
$args['type'] = Controls_Manager::SECTION;
$this->add_control( $section_id, $args );
if ( null !== $this->current_section ) { wp_die( sprintf( 'Elementor: You can\'t start a section before the end of the previous section "%s".', $this->current_section['section'] ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped }
$this->current_section = $this->get_section_args( $section_id );
if ( $this->injection_point ) { $this->injection_point['section'] = $this->current_section; }
/** * After section start. * * Fires after Elementor section starts in the editor panel. * * @since 1.4.0 * * @param Controls_Stack $this The control. * @param string $section_id Section ID. * @param array $args Section arguments. */ do_action( 'elementor/element/after_section_start', $this, $section_id, $args );
/** * After section start. * * Fires after Elementor section starts in the editor panel. * * The dynamic portions of the hook name, `$stack_name` and `$section_id`, refers to the stack name and section ID, respectively. * * @since 1.4.0 * * @param Controls_Stack $this The control. * @param array $args Section arguments. */ do_action( "elementor/element/{$stack_name}/{$section_id}/after_section_start", $this, $args );
if ( $this->should_manually_trigger_common_action( $stack_name ) ) { do_action( "elementor/element/common/{$section_id}/after_section_start", $this, $args ); } }
/** * End controls section. * * Used to close an existing open controls section. When you use this method * it stops adding new controls to this section. * * This method should be used inside `register_controls()`. * * @since 1.4.0 * @access public */ public function end_controls_section() { $stack_name = $this->get_name();
// Save the current section for the action. $current_section = $this->current_section; $section_id = $current_section['section']; $args = [ 'tab' => $current_section['tab'], ];
/** * Before section end. * * Fires before Elementor section ends in the editor panel. * * @since 1.4.0 * * @param Controls_Stack $this The control. * @param string $section_id Section ID. * @param array $args Section arguments. */ do_action( 'elementor/element/before_section_end', $this, $section_id, $args );
/** * Before section end. * * Fires before Elementor section ends in the editor panel. * * The dynamic portions of the hook name, `$stack_name` and `$section_id`, refers to the stack name and section ID, respectively. * * @since 1.4.0 * * @param Controls_Stack $this The control. * @param array $args Section arguments. */ do_action( "elementor/element/{$stack_name}/{$section_id}/before_section_end", $this, $args );
if ( $this->should_manually_trigger_common_action( $stack_name ) ) { do_action( "elementor/element/common/{$section_id}/before_section_end", $this, $args ); }
$this->current_section = null;
/** * After section end. * * Fires after Elementor section ends in the editor panel. * * @since 1.4.0 * * @param Controls_Stack $this The control. * @param string $section_id Section ID. * @param array $args Section arguments. */ do_action( 'elementor/element/after_section_end', $this, $section_id, $args );
/** * After section end. * * Fires after Elementor section ends in the editor panel. * * The dynamic portions of the hook name, `$stack_name` and `$section_id`, refers to the stack name and section ID, respectively. * * @since 1.4.0 * * @param Controls_Stack $this The control. * @param array $args Section arguments. */ do_action( "elementor/element/{$stack_name}/{$section_id}/after_section_end", $this, $args );
if ( $this->should_manually_trigger_common_action( $stack_name ) ) { do_action( "elementor/element/common/{$section_id}/after_section_end", $this, $args ); } }
/** * Should manually trigger common action. * * With the Optimized Markup experiment, the Advanced Tab has been split to maintain backward compatibility: * - 'common' refers to the existing Advanced Tab. * - 'common-optimized' refers to the new Advanced Tab for optimized widgets. * * Third-party developers may have used hooks like 'elementor/element/common/_section_background/before_section_end' * to add controls to the Advanced Tab. However, this hook will now only work on widgets that are not optimized. * * This method checks whether the 'elementor/element/common/...' hooks should be manually executed * to prevent third parties from needing to add equivalent hooks for 'elementor/element/common-optimized/...'. * * @todo Remove this method and the manual execution of 'common' hooks when the feature is merged. * * @access private * * @param string $stack_name Stack name. * * @return bool */ private function should_manually_trigger_common_action( $stack_name ): bool { return 'common-optimized' === $stack_name && Plugin::$instance->experiments->is_feature_active( 'e_optimized_markup' ); }
/** * Start controls tabs. * * Used to add a new set of tabs inside a section. You should use this * method before adding new individual tabs using `start_controls_tab()`. * Each tab added after this point will be assigned to this group of tabs, * until you close it using `end_controls_tabs()` method. * * This method should be used inside `register_controls()`. * * @since 1.4.0 * @access public * * @param string $tabs_id Tabs ID. * @param array $args Tabs arguments. */ public function start_controls_tabs( $tabs_id, array $args = [] ) { if ( null !== $this->current_tab ) { wp_die( sprintf( 'Elementor: You can\'t start tabs before the end of the previous tabs "%s".', $this->current_tab['tabs_wrapper'] ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped }
$args['type'] = Controls_Manager::TABS;
$this->add_control( $tabs_id, $args );
$this->current_tab = [ 'tabs_wrapper' => $tabs_id, ];
foreach ( [ 'condition', 'conditions' ] as $key ) { if ( ! empty( $args[ $key ] ) ) { $this->current_tab[ $key ] = $args[ $key ]; } }
if ( $this->injection_point ) { $this->injection_point['tab'] = $this->current_tab; } }
/** * End controls tabs. * * Used to close an existing open controls tabs. When you use this method it * stops adding new controls to this tabs. * * This method should be used inside `register_controls()`. * * @since 1.4.0 * @access public */ public function end_controls_tabs() { $this->current_tab = null; }
/** * Start controls tab. * * Used to add a new tab inside a group of tabs. Use this method before * adding new individual tabs using `start_controls_tab()`. * Each tab added after this point will be assigned to this group of tabs, * until you close it using `end_controls_tab()` method. * * This method should be used inside `register_controls()`. * * @since 1.4.0 * @access public * * @param string $tab_id Tab ID. * @param array $args Tab arguments. */ public function start_controls_tab( $tab_id, $args ) { if ( ! empty( $this->current_tab['inner_tab'] ) ) { wp_die( sprintf( 'Elementor: You can\'t start a tab before the end of the previous tab "%s".', $this->current_tab['inner_tab'] ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped }
$args['type'] = Controls_Manager::TAB; $args['tabs_wrapper'] = $this->current_tab['tabs_wrapper'];
$this->add_control( $tab_id, $args );
$this->current_tab['inner_tab'] = $tab_id;
if ( $this->injection_point ) { $this->injection_point['tab']['inner_tab'] = $this->current_tab['inner_tab']; } }
/** * End controls tab. * * Used to close an existing open controls tab. When you use this method it * stops adding new controls to this tab. * * This method should be used inside `register_controls()`. * * @since 1.4.0 * @access public */ public function end_controls_tab() { unset( $this->current_tab['inner_tab'] ); }
/** * Start popover. * * Used to add a new set of controls in a popover. When you use this method, * all the registered controls from this point will be assigned to this * popover, until you close the popover using `end_popover()` method. * * This method should be used inside `register_controls()`. * * @since 1.9.0 * @access public */ final public function start_popover() { $this->current_popover = [ 'initialized' => false, ]; }
/** * End popover. * * Used to close an existing open popover. When you use this method it stops * adding new controls to this popover. * * This method should be used inside `register_controls()`. * * @since 1.9.0 * @access public */ final public function end_popover() { $this->current_popover = null;
$last_control_key = $this->get_control_key( $this->get_pointer_index() - 1 );
$args = [ 'popover' => [ 'end' => true, ], ];
$options = [ 'recursive' => true, ];
$this->update_control( $last_control_key, $args, $options ); }
/** * Add render attribute. * * Used to add attributes to a specific HTML element. * * The HTML tag is represented by the element parameter, then you need to * define the attribute key and the attribute key. The final result will be: * `<element attribute_key="attribute_value">`. * * Example usage: * * `$this->add_render_attribute( 'wrapper', 'class', 'custom-widget-wrapper-class' );` * `$this->add_render_attribute( 'widget', 'id', 'custom-widget-id' );` * `$this->add_render_attribute( 'button', [ 'class' => 'custom-button-class', 'id' => 'custom-button-id' ] );` * * @since 1.0.0 * @access public * * @param array|string $element The HTML element. * @param array|string $key Optional. Attribute key. Default is null. * @param array|string $value Optional. Attribute value. Default is null. * @param bool $overwrite Optional. Whether to overwrite existing * attribute. Default is false, not to overwrite. * * @return self Current instance of the element. */ public function add_render_attribute( $element, $key = null, $value = null, $overwrite = false ) { if ( is_array( $element ) ) { foreach ( $element as $element_key => $attributes ) { $this->add_render_attribute( $element_key, $attributes, null, $overwrite ); }
return $this; }
if ( is_array( $key ) ) { foreach ( $key as $attribute_key => $attributes ) { $this->add_render_attribute( $element, $attribute_key, $attributes, $overwrite ); }
return $this; }
if ( empty( $this->render_attributes[ $element ][ $key ] ) ) { $this->render_attributes[ $element ][ $key ] = []; }
settype( $value, 'array' );
if ( $overwrite ) { $this->render_attributes[ $element ][ $key ] = $value; } else { $this->render_attributes[ $element ][ $key ] = array_merge( $this->render_attributes[ $element ][ $key ], $value ); }
return $this; }
/** * Get Render Attributes * * Used to retrieve render attribute. * * The returned array is either all elements and their attributes if no `$element` is specified, an array of all * attributes of a specific element or a specific attribute properties if `$key` is specified. * * Returns null if one of the requested parameters isn't set. * * @since 2.2.6 * @access public * @param string $element * @param string $key * * @return array */ public function get_render_attributes( $element = '', $key = '' ) { $attributes = $this->render_attributes;
if ( $element ) { if ( ! isset( $attributes[ $element ] ) ) { return null; }
$attributes = $attributes[ $element ];
if ( $key ) { if ( ! isset( $attributes[ $key ] ) ) { return null; }
$attributes = $attributes[ $key ]; } }
return $attributes; }
/** * Set render attribute. * * Used to set the value of the HTML element render attribute or to update * an existing render attribute. * * @since 1.0.0 * @access public * * @param array|string $element The HTML element. * @param array|string $key Optional. Attribute key. Default is null. * @param array|string $value Optional. Attribute value. Default is null. * * @return self Current instance of the element. */ public function set_render_attribute( $element, $key = null, $value = null ) { return $this->add_render_attribute( $element, $key, $value, true ); }
/** * Remove render attribute. * * Used to remove an element (with its keys and their values), key (with its values), * or value/s from an HTML element's render attribute. * * @since 2.7.0 * @access public * * @param string $element The HTML element. * @param string $key Optional. Attribute key. Default is null. * @param array|string $values Optional. Attribute value/s. Default is null. */ public function remove_render_attribute( $element, $key = null, $values = null ) { if ( $key && ! isset( $this->render_attributes[ $element ][ $key ] ) ) { return; }
if ( $values ) { $values = (array) $values;
$this->render_attributes[ $element ][ $key ] = array_diff( $this->render_attributes[ $element ][ $key ], $values );
return; }
if ( $key ) { unset( $this->render_attributes[ $element ][ $key ] );
return; }
if ( isset( $this->render_attributes[ $element ] ) ) { unset( $this->render_attributes[ $element ] ); } }
/** * Get render attribute string. * * Used to retrieve the value of the render attribute. * * @since 1.0.0 * @access public * * @param string $element The element. * * @return string Render attribute string, or an empty string if the attribute * is empty or not exist. */ public function get_render_attribute_string( $element ) { if ( empty( $this->render_attributes[ $element ] ) ) { return ''; }
return Utils::render_html_attributes( $this->render_attributes[ $element ] ); }
/** * Print render attribute string. * * Used to output the rendered attribute. * * @since 2.0.0 * @access public * * @param array|string $element The element. */ public function print_render_attribute_string( $element ) { echo $this->get_render_attribute_string( $element ); // XSS ok. }
/** * Print element template. * * Used to generate the element template on the editor. * * @since 2.0.0 * @access public */ public function print_template() { ob_start();
// TODO: This is for backwards compatibility starting from 2.9.0 // This `if` statement should be removed when the method is removed if ( $this->has_own_method( '_content_template', self::class ) ) { Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( '_content_template', '2.9.0', __CLASS__ . '::content_template()' );
$this->_content_template(); } else { $this->content_template(); }
$template_content = ob_get_clean();
$element_type = $this->get_type();
/** * Template content. * * Filters the controls stack template content before it's printed in the editor. * * The dynamic portion of the hook name, `$element_type`, refers to the element type. * * @since 1.0.0 * * @param string $content_template The controls stack template in the editor. * @param Controls_Stack $this The controls stack. */ $template_content = apply_filters( "elementor/{$element_type}/print_template", $template_content, $this );
if ( empty( $template_content ) ) { return; } ?> <script type="text/html" id="tmpl-elementor-<?php echo esc_attr( $this->get_name() ); ?>-content"> <?php $this->print_template_content( $template_content ); ?> </script> <?php }
/** * On import update dynamic content (e.g. post and term IDs). * * @since 3.8.0 * * @param array $config The config of the passed element. * @param array $data The data that requires updating/replacement when imported. * @param array|null $controls The available controls. * * @return array Element data. */ public static function on_import_update_dynamic_content( array $config, array $data, $controls = null ) : array { return $config; }
/** * Start injection. * * Used to inject controls and sections to a specific position in the stack. * * When you use this method, all the registered controls and sections will * be injected to a specific position in the stack, until you stop the * injection using `end_injection()` method. * * @since 1.7.1 * @access public * * @param array $position { * The position where to start the injection. * * @type string $type Injection type, either `control` or `section`. * Default is `control`. * @type string $at Where to inject. If `$type` is `control` accepts * `before` and `after`. If `$type` is `section` * accepts `start` and `end`. Default values based on * the `type`. * @type string $of Control/Section ID. * } */ final public function start_injection( array $position ) { if ( $this->injection_point ) { wp_die( 'A controls injection is already opened. Please close current injection before starting a new one (use `end_injection`).' ); }
$this->injection_point = $this->get_position_info( $position ); }
/** * End injection. * * Used to close an existing opened injection point. * * When you use this method it stops adding new controls and sections to * this point and continue to add controls to the regular position in the * stack. * * @since 1.7.1 * @access public */ final public function end_injection() { $this->injection_point = null; }
/** * Get injection point. * * Retrieve the injection point in the stack where new controls and sections * will be inserted. * * @since 1.9.2 * @access public * * @return array|null An array when an injection point is defined, null * otherwise. */ final public function get_injection_point() { return $this->injection_point; }
/** * Register controls. * * Used to add new controls to any element type. For example, external * developers use this method to register controls in a widget. * * Should be inherited and register new controls using `add_control()`, * `add_responsive_control()` and `add_group_control()`, inside control * wrappers like `start_controls_section()`, `start_controls_tabs()` and * `start_controls_tab()`. * * @since 1.4.0 * @access protected * @deprecated 3.1.0 Use `register_controls()` method instead. */ protected function _register_controls() { Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.1.0', 'register_controls()' );
$this->register_controls(); }
/** * Register controls. * * Used to add new controls to any element type. For example, external * developers use this method to register controls in a widget. * * Should be inherited and register new controls using `add_control()`, * `add_responsive_control()` and `add_group_control()`, inside control * wrappers like `start_controls_section()`, `start_controls_tabs()` and * `start_controls_tab()`. * * @since 3.1.0 * @access protected */ protected function register_controls() {}
/** * Get default data. * * Retrieve the default data. Used to reset the data on initialization. * * @since 1.4.0 * @access protected * * @return array Default data. */ protected function get_default_data() { return [ 'id' => 0, 'settings' => [], ]; }
/** * @since 2.3.0 * @access protected */ protected function get_init_settings() { $settings = $this->get_data( 'settings' );
$controls_objs = Plugin::$instance->controls_manager->get_controls();
foreach ( $this->get_controls() as $control ) { $control_obj = $controls_objs[ $control['type'] ] ?? null;
if ( ! $control_obj instanceof Base_Data_Control ) { continue; }
$control = array_merge_recursive( $control_obj->get_settings(), $control );
$settings[ $control['name'] ] = $control_obj->get_value( $control, $settings ); }
return $settings; }
/** * Get initial config. * * Retrieve the current element initial configuration - controls list and * the tabs assigned to the control. * * @since 2.9.0 * @access protected * * @return array The initial config. */ protected function get_initial_config() { return [ 'controls' => $this->get_controls(), ]; }
/** * Get initial config. * * Retrieve the current element initial configuration - controls list and * the tabs assigned to the control. * * @since 1.4.0 * @deprecated 2.9.0 Use `get_initial_config()` method instead. * @access protected * * @return array The initial config. */ protected function _get_initial_config() { Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '2.9.0', 'get_initial_config()' );
return $this->get_initial_config(); }
/** * Get section arguments. * * Retrieve the section arguments based on section ID. * * @since 1.4.0 * @access protected * * @param string $section_id Section ID. * * @return array Section arguments. */ protected function get_section_args( $section_id ) { $section_control = $this->get_controls( $section_id );
$section_args_keys = [ 'tab', 'condition' ];
$args = array_intersect_key( $section_control, array_flip( $section_args_keys ) );
$args['section'] = $section_id;
return $args; }
/** * Render element. * * Generates the final HTML on the frontend. * * @since 2.0.0 * @access protected */ protected function render() {}
/** * Render element in static mode. * * If not inherent will call the base render. */ protected function render_static() { $this->render(); }
/** * Determine the render logic. */ protected function render_by_mode() { if ( Plugin::$instance->frontend->is_static_render_mode() ) { $this->render_static();
return; }
$this->render(); }
/** * Print content template. * * Used to generate the content template on the editor, using a * Backbone JavaScript template. * * @access protected * @since 2.0.0 * * @param string $template_content Template content. */ protected function print_template_content( $template_content ) { echo $template_content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped }
/** * Render element output in the editor. * * Used to generate the live preview, using a Backbone JavaScript template. * * @since 2.9.0 * @access protected */ protected function content_template() {}
/** * Render element output in the editor. * * Used to generate the live preview, using a Backbone JavaScript template. * * @since 2.0.0 * @deprecated 2.9.0 Use `content_template()` method instead. * @access protected */ protected function _content_template() { Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '2.9.0', 'content_template()' );
$this->content_template(); }
/** * Initialize controls. * * Register the all controls added by `register_controls()`. * * @since 2.0.0 * @access protected */ protected function init_controls() { Plugin::$instance->controls_manager->open_stack( $this );
// TODO: This is for backwards compatibility starting from 2.9.0 // This `if` statement should be removed when the method is removed if ( $this->has_own_method( '_register_controls', self::class ) ) { Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( '_register_controls', '3.1.0', __CLASS__ . '::register_controls()' );
$this->_register_controls(); } else { $this->register_controls(); } }
protected function handle_control_position( array $args, $control_id, $overwrite ) { if ( isset( $args['type'] ) && in_array( $args['type'], [ Controls_Manager::SECTION, Controls_Manager::WP_WIDGET ], true ) ) { return $args; }
$target_section_args = $this->current_section;
$target_tab = $this->current_tab;
if ( $this->injection_point ) { $target_section_args = $this->injection_point['section'];
if ( ! empty( $this->injection_point['tab'] ) ) { $target_tab = $this->injection_point['tab']; } }
if ( null !== $target_section_args ) { if ( ! empty( $args['section'] ) || ! empty( $args['tab'] ) ) { _doing_it_wrong( sprintf( '%s::%s', get_called_class(), __FUNCTION__ ), sprintf( 'Cannot redeclare control with `tab` or `section` args inside section "%s".', $control_id ), '1.0.0' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped }
$args = array_replace_recursive( $target_section_args, $args );
if ( null !== $target_tab ) { $args = array_replace_recursive( $target_tab, $args ); } } elseif ( empty( $args['section'] ) && ( ! $overwrite || is_wp_error( Plugin::$instance->controls_manager->get_control_from_stack( $this->get_unique_name(), $control_id ) ) ) ) { if ( ! Performance::should_optimize_controls() ) { wp_die( sprintf( '%s::%s: Cannot add a control outside of a section (use `start_controls_section`).', get_called_class(), __FUNCTION__ ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } }
return $args; }
/** * Initialize the class. * * Set the raw data, the ID and the parsed settings. * * @since 2.9.0 * @access protected * * @param array $data Initial data. */ protected function init( $data ) { $this->data = array_merge( $this->get_default_data(), $data );
$this->id = $data['id']; }
/** * Initialize the class. * * Set the raw data, the ID and the parsed settings. * * @since 1.4.0 * @deprecated 2.9.0 Use `init()` method instead. * @access protected * * @param array $data Initial data. */ protected function _init( $data ) { Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '2.9.0', 'init()' );
$this->init( $data ); }
/** * Sanitize initial data. * * Performs settings cleaning and sanitization. * * @since 2.1.5 * @access private * * @param array $settings Settings to sanitize. * @param array $controls Optional. An array of controls. Default is an * empty array. * * @return array Sanitized settings. */ private function sanitize_settings( array $settings, array $controls = [] ) { if ( ! $controls ) { $controls = $this->get_controls(); }
foreach ( $controls as $control ) { $control_obj = Plugin::$instance->controls_manager->get_control( $control['type'] );
if ( $control_obj instanceof Control_Repeater ) { if ( empty( $settings[ $control['name'] ] ) ) { continue; }
foreach ( $settings[ $control['name'] ] as $index => $repeater_row_data ) { $sanitized_row_data = $this->sanitize_settings( $repeater_row_data, $control['fields'] );
$settings[ $control['name'] ][ $index ] = $sanitized_row_data; }
continue; }
$is_dynamic = isset( $settings[ Manager::DYNAMIC_SETTING_KEY ][ $control['name'] ] );
if ( ! $is_dynamic ) { continue; }
$value_to_check = $settings[ Manager::DYNAMIC_SETTING_KEY ][ $control['name'] ];
$tag_text_data = Plugin::$instance->dynamic_tags->tag_text_to_tag_data( $value_to_check );
if ( ! Plugin::$instance->dynamic_tags->get_tag_info( $tag_text_data['name'] ) ) { unset( $settings[ Manager::DYNAMIC_SETTING_KEY ][ $control['name'] ] ); } }
return $settings; }
/** * Controls stack constructor. * * Initializing the control stack class using `$data`. The `$data` is required * for a normal instance. It is optional only for internal `type instance`. * * @since 1.4.0 * @access public * * @param array $data Optional. Control stack data. Default is an empty array. */ public function __construct( array $data = [] ) { if ( $data ) { // TODO: This is for backwards compatibility starting from 2.9.0 // This if statement should be removed when the method is hard-deprecated if ( $this->has_own_method( '_init', self::class ) ) { Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( '_init', '2.9.0', __CLASS__ . '::init()' );
$this->_init( $data ); } else { $this->init( $data ); } } } }
|